/usr/share/IlohaMail/include/data_manager.FS.inc is in ilohamail 0.8.14-0rc3sid6.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | <?php
/////////////////////////////////////////////////////////
//
// include/data_manager.FS.inc
//
// (C)Copyright 2003 Ryo Chijiiwa <Ryo@IlohaMail.org>
//
// This file is part of IlohaMail. IlohaMail is free software released
// under the GPL license. See enclosed file COPYING for details, or
// see http://www.fsf.org/copyleft/gpl.html
//
/////////////////////////////////////////////////////////
/********************************************************
PURPOSE:
Data handling abstraction class.
PRE-CONDITIONS:
$USER_DIR - Where user directories reside (e.g. "../users/")
POST-CONDITIONS:
COMMENTS:
For FS based backend, $data will contain all data.
********************************************************/
include_once("../include/sort2darray.inc");
class DataManager_obj{
var $user;
var $host;
var $storage; //directory for FS backend, table nmae for DB
var $location; //file name for FS backend, user's ID for DB backend
var $path;
var $data; //actually contains
var $error;
var $id_counter;
function initialize($user, $host, $location, $backend){
global $USER_DIR;
$this->error = "";
$storage = $USER_DIR;
$location = $location.".dat";
if (!file_exists(realpath($storage))){
$this->error = "Folder: $storage does not exist\n";
return false;
}
$storage = $storage.ereg_replace("[\\/]", "", $user.".".$host);
if (!file_exists(realpath($storage))){
$this->error = "Folder: $storage does not exist\n";
return false;
}
$this->storage = $storage;
$this->location = $location;
$this->path = $storage."/".$location;
$this->user = $user;
$this->host = $host;
$this->data = false;
$this->id_counter = 0;
return true;
}
function read(){
$filePath = $this->path;
$this->data = false;
$fp = fopen($filePath, "a"); //force create file
if ($fp) fclose($fp);
$lines = file($filePath);
if (is_array($lines)){
$i=1;
while ( list($key, $line) = each ($lines) ){
$a = explode(",", chop($line));
while ( list($k2, $data) = each($a) ){
list($type, $string) = explode(":", $data);
if ($type!="id") $string = base64_decode($string);
//$string = base64_decode($string);
$this->data[$i][$type] = $string;
}
$this->data[$i]["id"] = $i;
$i++;
}
}else{
$this->error.= "Failed to read from: $filePath.\n";
$this->data = array();
}
return $this->data;
}
function save(){
$filePath = $this->path;
$fp = fopen($filePath, "w+");
if ($fp){
reset($this->data);
$i=1;
while ( list($key, $foo) = each($this->data)){
$line="id:".$i;
$this->data[$key]["id"] = $i;
while ( list($k2, $val) = each($this->data[$key]))
if ($k2!="id") $line .= ",".$k2.":".base64_encode($val);
fputs($fp, $line."\n");
$i++;
}
fclose($fp);
return true;
}else{
$this->error = "Couldn't open file \"$filePath\" for writing\n";
return false;
}
}
function delete($id){
if (!$this->data) $this->read();
$result = array();
$deleted = false;
reset($this->data);
while ( list($k,$v) = each($this->data) ){
if ($this->data[$k]["id"] != $id) $result[$k] = $this->data[$k];
else $deleted = true;
}
if ($deleted){
$this->data = $result;
$this->save();
}else{
$this->error = "Delete failed: $id not found\n";
}
return $deleted;
}
function update($id, $array){
if (!$this->data) $this->read();
$updated = false;
reset($this->data);
while ( list($k,$v) = each($this->data) ){
if ($this->data[$k]["id"]==$id){
$this->data[$k] = $array;
$updated = true;
}
}
if ($updated) $this->save();
else $this->error = "Update failed: $id not found\n";
return $updated;
}
function insert($array){
if (!$this->data) $this->read();
$array["id"] = $this->unique_id();
$this->data[] = $array;
return $this->save();
}
function sort($field, $order){
if (!$this->data) $this->read();
$sort_a = explode(",", $field);
$num_fields = count($sort_a);
for ($i=$num_fields;$i>0;$i--){
$this->data = sort2darray($this->data, $sort_a[$i-1], $order);
}
return $this->data;
}
function getDistinct($field, $order){
$this->sort($field, $order);
$index = array();
$result = array();
while ( list($k,$v) = each($this->data) ){
$value = $this->data[$k][$field];
if (empty($index[$value])){
$index[$value] = 1;
$result[] = $value;
}
}
return $result;
}
function search($array){
}
function showError(){
echo nl2br($this->error);
}
function unique_id(){
$this->id_counter++;
return time().".".$this->id_counter;
}
}
|