summaryrefslogtreecommitdiff
path: root/backend/php/src/objects
authorGiulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-02 23:56:18 (UTC)
committer Giulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-02 23:56:18 (UTC)
commitef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff)
treec403752d66a2c4775f00affd4fa8431b29c5b68c /backend/php/src/objects
parent597ecfbc0249d83e1b856cbd558340c01237a360 (diff)
downloadclipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip
clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz
clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2
First version of the newly restructured repository
Diffstat (limited to 'backend/php/src/objects') (more/less context) (ignore whitespace changes)
-rw-r--r--backend/php/src/objects/class.database.php79
-rw-r--r--backend/php/src/objects/class.onetimepassword.php400
-rw-r--r--backend/php/src/objects/class.onetimepasswordstatus.php368
-rw-r--r--backend/php/src/objects/class.pog_base.php143
-rw-r--r--backend/php/src/objects/class.record.php436
-rw-r--r--backend/php/src/objects/class.recordversion.php381
-rw-r--r--backend/php/src/objects/class.user.php502
-rw-r--r--backend/php/src/objects/ignore_objects.txt0
8 files changed, 2309 insertions, 0 deletions
diff --git a/backend/php/src/objects/class.database.php b/backend/php/src/objects/class.database.php
new file mode 100644
index 0000000..e8a13f7
--- a/dev/null
+++ b/backend/php/src/objects/class.database.php
@@ -0,0 +1,79 @@
1<?php
2/**
3* <b>Database Connection</b> class.
4* @author Php Object Generator
5* @version 3.0d / PHP5.1
6* @see http://www.phpobjectgenerator.com/
7* @copyright Free for personal & commercial use. (Offered under the BSD license)
8*/
9 Class Database
10{
11 public $connection;
12
13 private function Database()
14 {
15 $databaseName = $GLOBALS['configuration']['db'];
16 $serverName = $GLOBALS['configuration']['host'];
17 $databaseUser = $GLOBALS['configuration']['user'];
18 $databasePassword = $GLOBALS['configuration']['pass'];
19 $databasePort = $GLOBALS['configuration']['port'];
20 $this->connection = mysql_connect ($serverName.":".$databasePort, $databaseUser, $databasePassword);
21 if ($this->connection)
22 {
23 if (!mysql_select_db ($databaseName))
24 {
25 throw new Exception('I cannot find the specified database "'.$databaseName.'". Please edit configuration.php.');
26 }
27 }
28 else
29 {
30 throw new Exception('I cannot connect to the database. Please edit configuration.php with your database configuration.');
31 }
32 }
33
34 public static function Connect()
35 {
36 static $database = null;
37 if (!isset($database))
38 {
39 $database = new Database();
40 }
41 return $database->connection;
42 }
43
44 public static function Reader($query, $connection)
45 {
46 $cursor = mysql_query($query, $connection);
47 return $cursor;
48 }
49
50 public static function Read($cursor)
51 {
52 return mysql_fetch_assoc($cursor);
53 }
54
55 public static function NonQuery($query, $connection)
56 {
57 mysql_query($query, $connection);
58 $result = mysql_affected_rows($connection);
59 if ($result == -1)
60 {
61 return false;
62 }
63 return $result;
64
65 }
66
67 public static function Query($query, $connection)
68 {
69 $result = mysql_query($query, $connection);
70 return mysql_num_rows($result);
71 }
72
73 public static function InsertOrUpdate($query, $connection)
74 {
75 $result = mysql_query($query, $connection);
76 return intval(mysql_insert_id($connection));
77 }
78}
79?>
diff --git a/backend/php/src/objects/class.onetimepassword.php b/backend/php/src/objects/class.onetimepassword.php
new file mode 100644
index 0000000..90d5f1d
--- a/dev/null
+++ b/backend/php/src/objects/class.onetimepassword.php
@@ -0,0 +1,400 @@
1<?php
2/*
3 This SQL query will create the table to store your object.
4
5 CREATE TABLE `onetimepassword` (
6 `onetimepasswordid` int(11) NOT NULL auto_increment,
7 `userid` int(11) NOT NULL,
8 `onetimepasswordstatusid` int(11) NOT NULL,
9 `reference` VARCHAR(255) NOT NULL,
10 `key` VARCHAR(255) NOT NULL,
11 `key_checksum` VARCHAR(255) NOT NULL,
12 `data` TEXT NOT NULL,
13 `version` VARCHAR(255) NOT NULL,
14 `creation_date` TIMESTAMP NOT NULL,
15 `request_date` TIMESTAMP NOT NULL,
16 `usage_date` TIMESTAMP NOT NULL, INDEX(`userid`,`onetimepasswordstatusid`), PRIMARY KEY (`onetimepasswordid`)) ENGINE=MyISAM;
17*/
18
19/**
20* <b>onetimepassword</b> class with integrated CRUD methods.
21* @author Php Object Generator
22* @version POG 3.0d / PHP5.1
23* @copyright Free for personal & commercial use. (Offered under the BSD license)
24* @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pog&objectName=onetimepassword&attributeList=array+%28%0A++0+%3D%3E+%27user%27%2C%0A++1+%3D%3E+%27onetimepasswordstatus%27%2C%0A++2+%3D%3E+%27reference%27%2C%0A++3+%3D%3E+%27key%27%2C%0A++4+%3D%3E+%27key_checksum%27%2C%0A++5+%3D%3E+%27data%27%2C%0A++6+%3D%3E+%27version%27%2C%0A++7+%3D%3E+%27creation_date%27%2C%0A++8+%3D%3E+%27request_date%27%2C%0A++9+%3D%3E+%27usage_date%27%2C%0A%29&typeList=array+%28%0A++0+%3D%3E+%27BELONGSTO%27%2C%0A++1+%3D%3E+%27BELONGSTO%27%2C%0A++2+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++3+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++4+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++5+%3D%3E+%27TEXT%27%2C%0A++6+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++7+%3D%3E+%27TIMESTAMP%27%2C%0A++8+%3D%3E+%27TIMESTAMP%27%2C%0A++9+%3D%3E+%27TIMESTAMP%27%2C%0A%29
25*/
26include_once('class.pog_base.php');
27class onetimepassword extends POG_Base
28{
29 public $onetimepasswordId = '';
30
31 /**
32 * @var INT(11)
33 */
34 public $userId;
35
36 /**
37 * @var INT(11)
38 */
39 public $onetimepasswordstatusId;
40
41 /**
42 * @var VARCHAR(255)
43 */
44 public $reference;
45
46 /**
47 * @var VARCHAR(255)
48 */
49 public $key;
50
51 /**
52 * @var VARCHAR(255)
53 */
54 public $key_checksum;
55
56 /**
57 * @var TEXT
58 */
59 public $data;
60
61 /**
62 * @var VARCHAR(255)
63 */
64 public $version;
65
66 /**
67 * @var TIMESTAMP
68 */
69 public $creation_date;
70
71 /**
72 * @var TIMESTAMP
73 */
74 public $request_date;
75
76 /**
77 * @var TIMESTAMP
78 */
79 public $usage_date;
80
81 public $pog_attribute_type = array(
82 "onetimepasswordId" => array('db_attributes' => array("NUMERIC", "INT")),
83 "user" => array('db_attributes' => array("OBJECT", "BELONGSTO")),
84 "onetimepasswordstatus" => array('db_attributes' => array("OBJECT", "BELONGSTO")),
85 "reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
86 "key" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
87 "key_checksum" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
88 "data" => array('db_attributes' => array("TEXT", "TEXT")),
89 "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
90 "creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
91 "request_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
92 "usage_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
93 );
94 public $pog_query;
95
96
97 /**
98 * Getter for some private attributes
99 * @return mixed $attribute
100 */
101 public function __get($attribute)
102 {
103 if (isset($this->{"_".$attribute}))
104 {
105 return $this->{"_".$attribute};
106 }
107 else
108 {
109 return false;
110 }
111 }
112
113 function onetimepassword($reference='', $key='', $key_checksum='', $data='', $version='', $creation_date='', $request_date='', $usage_date='')
114 {
115 $this->reference = $reference;
116 $this->key = $key;
117 $this->key_checksum = $key_checksum;
118 $this->data = $data;
119 $this->version = $version;
120 $this->creation_date = $creation_date;
121 $this->request_date = $request_date;
122 $this->usage_date = $usage_date;
123 }
124
125
126 /**
127 * Gets object from database
128 * @param integer $onetimepasswordId
129 * @return object $onetimepassword
130 */
131 function Get($onetimepasswordId)
132 {
133 $connection = Database::Connect();
134 $this->pog_query = "select * from `onetimepassword` where `onetimepasswordid`='".intval($onetimepasswordId)."' LIMIT 1";
135 $cursor = Database::Reader($this->pog_query, $connection);
136 while ($row = Database::Read($cursor))
137 {
138 $this->onetimepasswordId = $row['onetimepasswordid'];
139 $this->userId = $row['userid'];
140 $this->onetimepasswordstatusId = $row['onetimepasswordstatusid'];
141 $this->reference = $this->Unescape($row['reference']);
142 $this->key = $this->Unescape($row['key']);
143 $this->key_checksum = $this->Unescape($row['key_checksum']);
144 $this->data = $this->Unescape($row['data']);
145 $this->version = $this->Unescape($row['version']);
146 $this->creation_date = $row['creation_date'];
147 $this->request_date = $row['request_date'];
148 $this->usage_date = $row['usage_date'];
149 }
150 return $this;
151 }
152
153
154 /**
155 * Returns a sorted array of objects that match given conditions
156 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
157 * @param string $sortBy
158 * @param boolean $ascending
159 * @param int limit
160 * @return array $onetimepasswordList
161 */
162 function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
163 {
164 $connection = Database::Connect();
165 $sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
166 $this->pog_query = "select * from `onetimepassword` ";
167 $onetimepasswordList = Array();
168 if (sizeof($fcv_array) > 0)
169 {
170 $this->pog_query .= " where ";
171 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
172 {
173 if (sizeof($fcv_array[$i]) == 1)
174 {
175 $this->pog_query .= " ".$fcv_array[$i][0]." ";
176 continue;
177 }
178 else
179 {
180 if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
181 {
182 $this->pog_query .= " AND ";
183 }
184 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
185 {
186 if ($GLOBALS['configuration']['db_encoding'] == 1)
187 {
188 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
189 $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
190 }
191 else
192 {
193 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
194 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
195 }
196 }
197 else
198 {
199 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
200 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
201 }
202 }
203 }
204 }
205 if ($sortBy != '')
206 {
207 if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
208 {
209 if ($GLOBALS['configuration']['db_encoding'] == 1)
210 {
211 $sortBy = "BASE64_DECODE($sortBy) ";
212 }
213 else
214 {
215 $sortBy = "$sortBy ";
216 }
217 }
218 else
219 {
220 $sortBy = "$sortBy ";
221 }
222 }
223 else
224 {
225 $sortBy = "onetimepasswordid";
226 }
227 $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
228 $thisObjectName = get_class($this);
229 $cursor = Database::Reader($this->pog_query, $connection);
230 while ($row = Database::Read($cursor))
231 {
232 $onetimepassword = new $thisObjectName();
233 $onetimepassword->onetimepasswordId = $row['onetimepasswordid'];
234 $onetimepassword->userId = $row['userid'];
235 $onetimepassword->onetimepasswordstatusId = $row['onetimepasswordstatusid'];
236 $onetimepassword->reference = $this->Unescape($row['reference']);
237 $onetimepassword->key = $this->Unescape($row['key']);
238 $onetimepassword->key_checksum = $this->Unescape($row['key_checksum']);
239 $onetimepassword->data = $this->Unescape($row['data']);
240 $onetimepassword->version = $this->Unescape($row['version']);
241 $onetimepassword->creation_date = $row['creation_date'];
242 $onetimepassword->request_date = $row['request_date'];
243 $onetimepassword->usage_date = $row['usage_date'];
244 $onetimepasswordList[] = $onetimepassword;
245 }
246 return $onetimepasswordList;
247 }
248
249
250 /**
251 * Saves the object to the database
252 * @return integer $onetimepasswordId
253 */
254 function Save()
255 {
256 $connection = Database::Connect();
257 $this->pog_query = "select `onetimepasswordid` from `onetimepassword` where `onetimepasswordid`='".$this->onetimepasswordId."' LIMIT 1";
258 $rows = Database::Query($this->pog_query, $connection);
259 if ($rows > 0)
260 {
261 $this->pog_query = "update `onetimepassword` set
262 `userid`='".$this->userId."',
263 `onetimepasswordstatusid`='".$this->onetimepasswordstatusId."',
264 `reference`='".$this->Escape($this->reference)."',
265 `key`='".$this->Escape($this->key)."',
266 `key_checksum`='".$this->Escape($this->key_checksum)."',
267 `data`='".$this->Escape($this->data)."',
268 `version`='".$this->Escape($this->version)."',
269 `creation_date`='".$this->creation_date."',
270 `request_date`='".$this->request_date."',
271 `usage_date`='".$this->usage_date."' where `onetimepasswordid`='".$this->onetimepasswordId."'";
272 }
273 else
274 {
275 $this->pog_query = "insert into `onetimepassword` (`userid`, `onetimepasswordstatusid`, `reference`, `key`, `key_checksum`, `data`, `version`, `creation_date`, `request_date`, `usage_date` ) values (
276 '".$this->userId."',
277 '".$this->onetimepasswordstatusId."',
278 '".$this->Escape($this->reference)."',
279 '".$this->Escape($this->key)."',
280 '".$this->Escape($this->key_checksum)."',
281 '".$this->Escape($this->data)."',
282 '".$this->Escape($this->version)."',
283 '".$this->creation_date."',
284 '".$this->request_date."',
285 '".$this->usage_date."' )";
286 }
287 $insertId = Database::InsertOrUpdate($this->pog_query, $connection);
288 if ($this->onetimepasswordId == "")
289 {
290 $this->onetimepasswordId = $insertId;
291 }
292 return $this->onetimepasswordId;
293 }
294
295
296 /**
297 * Clones the object and saves it to the database
298 * @return integer $onetimepasswordId
299 */
300 function SaveNew()
301 {
302 $this->onetimepasswordId = '';
303 return $this->Save();
304 }
305
306
307 /**
308 * Deletes the object from the database
309 * @return boolean
310 */
311 function Delete()
312 {
313 $connection = Database::Connect();
314 $this->pog_query = "delete from `onetimepassword` where `onetimepasswordid`='".$this->onetimepasswordId."'";
315 return Database::NonQuery($this->pog_query, $connection);
316 }
317
318
319 /**
320 * Deletes a list of objects that match given conditions
321 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
322 * @param bool $deep
323 * @return
324 */
325 function DeleteList($fcv_array)
326 {
327 if (sizeof($fcv_array) > 0)
328 {
329 $connection = Database::Connect();
330 $pog_query = "delete from `onetimepassword` where ";
331 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
332 {
333 if (sizeof($fcv_array[$i]) == 1)
334 {
335 $pog_query .= " ".$fcv_array[$i][0]." ";
336 continue;
337 }
338 else
339 {
340 if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
341 {
342 $pog_query .= " AND ";
343 }
344 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
345 {
346 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
347 }
348 else
349 {
350 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
351 }
352 }
353 }
354 return Database::NonQuery($pog_query, $connection);
355 }
356 }
357
358
359 /**
360 * Associates the user object to this one
361 * @return boolean
362 */
363 function GetUser()
364 {
365 $user = new user();
366 return $user->Get($this->userId);
367 }
368
369
370 /**
371 * Associates the user object to this one
372 * @return
373 */
374 function SetUser(&$user)
375 {
376 $this->userId = $user->userId;
377 }
378
379
380 /**
381 * Associates the onetimepasswordstatus object to this one
382 * @return boolean
383 */
384 function GetOnetimepasswordstatus()
385 {
386 $onetimepasswordstatus = new onetimepasswordstatus();
387 return $onetimepasswordstatus->Get($this->onetimepasswordstatusId);
388 }
389
390
391 /**
392 * Associates the onetimepasswordstatus object to this one
393 * @return
394 */
395 function SetOnetimepasswordstatus(&$onetimepasswordstatus)
396 {
397 $this->onetimepasswordstatusId = $onetimepasswordstatus->onetimepasswordstatusId;
398 }
399}
400?> \ No newline at end of file
diff --git a/backend/php/src/objects/class.onetimepasswordstatus.php b/backend/php/src/objects/class.onetimepasswordstatus.php
new file mode 100644
index 0000000..f0ef08a
--- a/dev/null
+++ b/backend/php/src/objects/class.onetimepasswordstatus.php
@@ -0,0 +1,368 @@
1<?php
2/*
3 This SQL query will create the table to store your object.
4
5 CREATE TABLE `onetimepasswordstatus` (
6 `onetimepasswordstatusid` int(11) NOT NULL auto_increment,
7 `code` VARCHAR(255) NOT NULL,
8 `name` VARCHAR(255) NOT NULL,
9 `description` TEXT NOT NULL, PRIMARY KEY (`onetimepasswordstatusid`)) ENGINE=MyISAM;
10*/
11
12/**
13* <b>onetimepasswordstatus</b> class with integrated CRUD methods.
14* @author Php Object Generator
15* @version POG 3.0d / PHP5.1 MYSQL
16* @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql
17* @copyright Free for personal & commercial use. (Offered under the BSD license)
18* @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pdo&pdoDriver=mysql&objectName=onetimepasswordstatus&attributeList=array+%28%0A++0+%3D%3E+%27onetimepassword%27%2C%0A++1+%3D%3E+%27code%27%2C%0A++2+%3D%3E+%27name%27%2C%0A++3+%3D%3E+%27description%27%2C%0A%29&typeList=array%2B%2528%250A%2B%2B0%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2B%2B1%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B2%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B3%2B%253D%253E%2B%2527TEXT%2527%252C%250A%2529
19*/
20include_once('class.pog_base.php');
21class onetimepasswordstatus extends POG_Base
22{
23 public $onetimepasswordstatusId = '';
24
25 /**
26 * @var private array of onetimepassword objects
27 */
28 private $_onetimepasswordList = array();
29
30 /**
31 * @var VARCHAR(255)
32 */
33 public $code;
34
35 /**
36 * @var VARCHAR(255)
37 */
38 public $name;
39
40 /**
41 * @var TEXT
42 */
43 public $description;
44
45 public $pog_attribute_type = array(
46 "onetimepasswordstatusId" => array('db_attributes' => array("NUMERIC", "INT")),
47 "onetimepassword" => array('db_attributes' => array("OBJECT", "HASMANY")),
48 "code" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
49 "name" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
50 "description" => array('db_attributes' => array("TEXT", "TEXT")),
51 );
52 public $pog_query;
53
54
55 /**
56 * Getter for some private attributes
57 * @return mixed $attribute
58 */
59 public function __get($attribute)
60 {
61 if (isset($this->{"_".$attribute}))
62 {
63 return $this->{"_".$attribute};
64 }
65 else
66 {
67 return false;
68 }
69 }
70
71 function onetimepasswordstatus($code='', $name='', $description='')
72 {
73 $this->_onetimepasswordList = array();
74 $this->code = $code;
75 $this->name = $name;
76 $this->description = $description;
77 }
78
79
80 /**
81 * Gets object from database
82 * @param integer $onetimepasswordstatusId
83 * @return object $onetimepasswordstatus
84 */
85 function Get($onetimepasswordstatusId)
86 {
87 $connection = Database::Connect();
88 $this->pog_query = "select * from `onetimepasswordstatus` where `onetimepasswordstatusid`='".intval($onetimepasswordstatusId)."' LIMIT 1";
89 $cursor = Database::Reader($this->pog_query, $connection);
90 while ($row = Database::Read($cursor))
91 {
92 $this->onetimepasswordstatusId = $row['onetimepasswordstatusid'];
93 $this->code = $this->Unescape($row['code']);
94 $this->name = $this->Unescape($row['name']);
95 $this->description = $this->Unescape($row['description']);
96 }
97 return $this;
98 }
99
100
101 /**
102 * Returns a sorted array of objects that match given conditions
103 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
104 * @param string $sortBy
105 * @param boolean $ascending
106 * @param int limit
107 * @return array $onetimepasswordstatusList
108 */
109 function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
110 {
111 $connection = Database::Connect();
112 $sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
113 $this->pog_query = "select * from `onetimepasswordstatus` ";
114 $onetimepasswordstatusList = Array();
115 if (sizeof($fcv_array) > 0)
116 {
117 $this->pog_query .= " where ";
118 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
119 {
120 if (sizeof($fcv_array[$i]) == 1)
121 {
122 $this->pog_query .= " ".$fcv_array[$i][0]." ";
123 continue;
124 }
125 else
126 {
127 if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
128 {
129 $this->pog_query .= " AND ";
130 }
131 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
132 {
133 if ($GLOBALS['configuration']['db_encoding'] == 1)
134 {
135 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
136 $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
137 }
138 else
139 {
140 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
141 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
142 }
143 }
144 else
145 {
146 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
147 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
148 }
149 }
150 }
151 }
152 if ($sortBy != '')
153 {
154 if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
155 {
156 if ($GLOBALS['configuration']['db_encoding'] == 1)
157 {
158 $sortBy = "BASE64_DECODE($sortBy) ";
159 }
160 else
161 {
162 $sortBy = "$sortBy ";
163 }
164 }
165 else
166 {
167 $sortBy = "$sortBy ";
168 }
169 }
170 else
171 {
172 $sortBy = "onetimepasswordstatusid";
173 }
174 $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
175 $thisObjectName = get_class($this);
176 $cursor = Database::Reader($this->pog_query, $connection);
177 while ($row = Database::Read($cursor))
178 {
179 $onetimepasswordstatus = new $thisObjectName();
180 $onetimepasswordstatus->onetimepasswordstatusId = $row['onetimepasswordstatusid'];
181 $onetimepasswordstatus->code = $this->Unescape($row['code']);
182 $onetimepasswordstatus->name = $this->Unescape($row['name']);
183 $onetimepasswordstatus->description = $this->Unescape($row['description']);
184 $onetimepasswordstatusList[] = $onetimepasswordstatus;
185 }
186 return $onetimepasswordstatusList;
187 }
188
189
190 /**
191 * Saves the object to the database
192 * @return integer $onetimepasswordstatusId
193 */
194 function Save($deep = true)
195 {
196 $connection = Database::Connect();
197 $this->pog_query = "select `onetimepasswordstatusid` from `onetimepasswordstatus` where `onetimepasswordstatusid`='".$this->onetimepasswordstatusId."' LIMIT 1";
198 $rows = Database::Query($this->pog_query, $connection);
199 if ($rows > 0)
200 {
201 $this->pog_query = "update `onetimepasswordstatus` set
202 `code`='".$this->Escape($this->code)."',
203 `name`='".$this->Escape($this->name)."',
204 `description`='".$this->Escape($this->description)."' where `onetimepasswordstatusid`='".$this->onetimepasswordstatusId."'";
205 }
206 else
207 {
208 $this->pog_query = "insert into `onetimepasswordstatus` (`code`, `name`, `description` ) values (
209 '".$this->Escape($this->code)."',
210 '".$this->Escape($this->name)."',
211 '".$this->Escape($this->description)."' )";
212 }
213 $insertId = Database::InsertOrUpdate($this->pog_query, $connection);
214 if ($this->onetimepasswordstatusId == "")
215 {
216 $this->onetimepasswordstatusId = $insertId;
217 }
218 if ($deep)
219 {
220 foreach ($this->_onetimepasswordList as $onetimepassword)
221 {
222 $onetimepassword->onetimepasswordstatusId = $this->onetimepasswordstatusId;
223 $onetimepassword->Save($deep);
224 }
225 }
226 return $this->onetimepasswordstatusId;
227 }
228
229
230 /**
231 * Clones the object and saves it to the database
232 * @return integer $onetimepasswordstatusId
233 */
234 function SaveNew($deep = false)
235 {
236 $this->onetimepasswordstatusId = '';
237 return $this->Save($deep);
238 }
239
240
241 /**
242 * Deletes the object from the database
243 * @return boolean
244 */
245 function Delete($deep = false, $across = false)
246 {
247 if ($deep)
248 {
249 $onetimepasswordList = $this->GetOnetimepasswordList();
250 foreach ($onetimepasswordList as $onetimepassword)
251 {
252 $onetimepassword->Delete($deep, $across);
253 }
254 }
255 $connection = Database::Connect();
256 $this->pog_query = "delete from `onetimepasswordstatus` where `onetimepasswordstatusid`='".$this->onetimepasswordstatusId."'";
257 return Database::NonQuery($this->pog_query, $connection);
258 }
259
260
261 /**
262 * Deletes a list of objects that match given conditions
263 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
264 * @param bool $deep
265 * @return
266 */
267 function DeleteList($fcv_array, $deep = false, $across = false)
268 {
269 if (sizeof($fcv_array) > 0)
270 {
271 if ($deep || $across)
272 {
273 $objectList = $this->GetList($fcv_array);
274 foreach ($objectList as $object)
275 {
276 $object->Delete($deep, $across);
277 }
278 }
279 else
280 {
281 $connection = Database::Connect();
282 $pog_query = "delete from `onetimepasswordstatus` where ";
283 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
284 {
285 if (sizeof($fcv_array[$i]) == 1)
286 {
287 $pog_query .= " ".$fcv_array[$i][0]." ";
288 continue;
289 }
290 else
291 {
292 if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
293 {
294 $pog_query .= " AND ";
295 }
296 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
297 {
298 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
299 }
300 else
301 {
302 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
303 }
304 }
305 }
306 return Database::NonQuery($pog_query, $connection);
307 }
308 }
309 }
310
311
312 /**
313 * Gets a list of onetimepassword objects associated to this one
314 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
315 * @param string $sortBy
316 * @param boolean $ascending
317 * @param int limit
318 * @return array of onetimepassword objects
319 */
320 function GetOnetimepasswordList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
321 {
322 $onetimepassword = new onetimepassword();
323 $fcv_array[] = array("onetimepasswordstatusId", "=", $this->onetimepasswordstatusId);
324 $dbObjects = $onetimepassword->GetList($fcv_array, $sortBy, $ascending, $limit);
325 return $dbObjects;
326 }
327
328
329 /**
330 * Makes this the parent of all onetimepassword objects in the onetimepassword List array. Any existing onetimepassword will become orphan(s)
331 * @return null
332 */
333 function SetOnetimepasswordList(&$list)
334 {
335 $this->_onetimepasswordList = array();
336 $existingOnetimepasswordList = $this->GetOnetimepasswordList();
337 foreach ($existingOnetimepasswordList as $onetimepassword)
338 {
339 $onetimepassword->onetimepasswordstatusId = '';
340 $onetimepassword->Save(false);
341 }
342 $this->_onetimepasswordList = $list;
343 }
344
345
346 /**
347 * Associates the onetimepassword object to this one
348 * @return
349 */
350 function AddOnetimepassword(&$onetimepassword)
351 {
352 $onetimepassword->onetimepasswordstatusId = $this->onetimepasswordstatusId;
353 $found = false;
354 foreach($this->_onetimepasswordList as $onetimepassword2)
355 {
356 if ($onetimepassword->onetimepasswordId > 0 && $onetimepassword->onetimepasswordId == $onetimepassword2->onetimepasswordId)
357 {
358 $found = true;
359 break;
360 }
361 }
362 if (!$found)
363 {
364 $this->_onetimepasswordList[] = $onetimepassword;
365 }
366 }
367}
368?> \ No newline at end of file
diff --git a/backend/php/src/objects/class.pog_base.php b/backend/php/src/objects/class.pog_base.php
new file mode 100644
index 0000000..6a8f570
--- a/dev/null
+++ b/backend/php/src/objects/class.pog_base.php
@@ -0,0 +1,143 @@
1<?php
2class POG_Base
3{
4 /**
5 * Overloading
6 */
7 function __call($method, $argv)
8 {
9 include_once($GLOBALS['configuration']['plugins_path']."/IPlugin.php");
10 include_once($GLOBALS['configuration']['plugins_path']."/plugin.".strtolower($method).".php");
11 eval('$plugin = new $method($this,$argv);');
12 return $plugin->Execute();
13 }
14
15 /**
16 * constructor
17 *
18 * @return POG_Base
19 */
20 private function POG_Base()
21 {
22 }
23
24
25 function SetFieldAttribute($fieldName, $attributeName, $attributeValue)
26 {
27 if (isset($this->pog_attribute_type[$fieldName]) && isset($this->pog_attribute_type[$fieldName][$attributeName]))
28 {
29 $this->pog_attribute_type[$fieldName][$attributeName] = $attributeValue;
30 }
31 }
32
33 function GetFieldAttribute($fieldName, $attributeName)
34 {
35 if (isset($this->pog_attribute_type[$fieldName]) && isset($this->pog_attribute_type[$fieldName][$attributeName]))
36 {
37 return $this->pog_attribute_type[$fieldName][$attributeName];
38 }
39 return null;
40 }
41
42 ///////////////////////////
43 // Data manipulation
44 ///////////////////////////
45
46 /**
47 * This function will try to encode $text to base64, except when $text is a number. This allows us to Escape all data before they're inserted in the database, regardless of attribute type.
48 * @param string $text
49 * @return string encoded to base64
50 */
51 public function Escape($text)
52 {
53 if ($GLOBALS['configuration']['db_encoding'] && !is_numeric($text))
54 {
55 return base64_encode($text);
56 }
57 return addslashes($text);
58 }
59
60 /**
61 * Enter description here...
62 *
63 * @param unknown_type $text
64 * @return unknown
65 */
66 public function Unescape($text)
67 {
68 if ($GLOBALS['configuration']['db_encoding'] && !is_numeric($text))
69 {
70 return base64_decode($text);
71 }
72 return stripcslashes($text);
73 }
74
75
76 ////////////////////////////////
77 // Table -> Object Mapping
78 ////////////////////////////////
79
80 /**
81 * Executes $query against database and returns the result set as an array of POG objects
82 *
83 * @param string $query. SQL query to execute against database
84 * @param string $objectClass. POG Object type to return
85 * @param bool $lazy. If true, will also load all children/sibling
86 */
87 public function FetchObjects($query, $objectClass, $lazy = true)
88 {
89 $databaseConnection = Database::Connect();
90 $result = Database::Query($query, $databaseConnection);
91 $objectList = $this->CreateObjects($result, $objectClass, $lazy);
92 return $objectList;
93 }
94
95 private function CreateObjects($mysql_result, $objectClass, $lazyLoad = true)
96 {
97 $objectList = array();
98 while ($row = mysql_fetch_assoc($mysql_result))
99 {
100 $pog_object = new $objectClass();
101 $this->PopulateObjectAttributes($row, $pog_object);
102 $objectList[] = $pog_object;
103 }
104 return $objectList;
105 }
106
107 private function PopulateObjectAttributes($fetched_row, $pog_object)
108 {
109 foreach ($this->GetAttributes($pog_object) as $column)
110 {
111 $pog_object->{$column} = $this->Unescape($fetched_row[strtolower($column)]);
112 }
113 return $pog_object;
114 }
115
116 private function GetAttributes($object)
117 {
118 $columns = array();
119 foreach ($object->pog_attribute_type as $att => $properties)
120 {
121 if ($properties['db_attributes'][0] != 'OBJECT')
122 {
123 $columns[] = $att;
124 }
125 }
126 return $columns;
127 }
128
129 //misc
130 public static function IsColumn($value)
131 {
132 if (strlen($value) > 2)
133 {
134 if (substr($value, 0, 1) == '`' && substr($value, strlen($value) - 1, 1) == '`')
135 {
136 return true;
137 }
138 return false;
139 }
140 return false;
141 }
142}
143?> \ No newline at end of file
diff --git a/backend/php/src/objects/class.record.php b/backend/php/src/objects/class.record.php
new file mode 100644
index 0000000..a269e75
--- a/dev/null
+++ b/backend/php/src/objects/class.record.php
@@ -0,0 +1,436 @@
1<?php
2/*
3 This SQL query will create the table to store your object.
4
5 CREATE TABLE `record` (
6 `recordid` int(11) NOT NULL auto_increment,
7 `userid` int(11) NOT NULL,
8 `reference` VARCHAR(255) NOT NULL,
9 `data` LONGTEXT NOT NULL,
10 `version` VARCHAR(255) NOT NULL,
11 `creation_date` TIMESTAMP NOT NULL,
12 `update_date` TIMESTAMP NOT NULL,
13 `access_date` TIMESTAMP NOT NULL, INDEX(`userid`), PRIMARY KEY (`recordid`)) ENGINE=MyISAM;
14*/
15
16/**
17* <b>record</b> class with integrated CRUD methods.
18* @author Php Object Generator
19* @version POG 3.0e / PHP5.1 MYSQL
20* @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql
21* @copyright Free for personal & commercial use. (Offered under the BSD license)
22* @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pdo&pdoDriver=mysql&objectName=record&attributeList=array+%28%0A++0+%3D%3E+%27user%27%2C%0A++1+%3D%3E+%27recordversion%27%2C%0A++2+%3D%3E+%27reference%27%2C%0A++3+%3D%3E+%27data%27%2C%0A++4+%3D%3E+%27version%27%2C%0A++5+%3D%3E+%27creation_date%27%2C%0A++6+%3D%3E+%27update_date%27%2C%0A++7+%3D%3E+%27access_date%27%2C%0A%29&typeList=array%2B%2528%250A%2B%2B0%2B%253D%253E%2B%2527BELONGSTO%2527%252C%250A%2B%2B1%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2B%2B2%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B3%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B4%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B5%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B6%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B7%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2529
23*/
24include_once('class.pog_base.php');
25class record extends POG_Base
26{
27 public $recordId = '';
28
29 /**
30 * @var INT(11)
31 */
32 public $userId;
33
34 /**
35 * @var private array of recordversion objects
36 */
37 private $_recordversionList = array();
38
39 /**
40 * @var VARCHAR(255)
41 */
42 public $reference;
43
44 /**
45 * @var LONGTEXT
46 */
47 public $data;
48
49 /**
50 * @var VARCHAR(255)
51 */
52 public $version;
53
54 /**
55 * @var TIMESTAMP
56 */
57 public $creation_date;
58
59 /**
60 * @var TIMESTAMP
61 */
62 public $update_date;
63
64 /**
65 * @var TIMESTAMP
66 */
67 public $access_date;
68
69 public $pog_attribute_type = array(
70 "recordId" => array('db_attributes' => array("NUMERIC", "INT")),
71 "user" => array('db_attributes' => array("OBJECT", "BELONGSTO")),
72 "recordversion" => array('db_attributes' => array("OBJECT", "HASMANY")),
73 "reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
74 "data" => array('db_attributes' => array("TEXT", "LONGTEXT")),
75 "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
76 "creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
77 "update_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
78 "access_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
79 );
80 public $pog_query;
81
82
83 /**
84 * Getter for some private attributes
85 * @return mixed $attribute
86 */
87 public function __get($attribute)
88 {
89 if (isset($this->{"_".$attribute}))
90 {
91 return $this->{"_".$attribute};
92 }
93 else
94 {
95 return false;
96 }
97 }
98
99 function record($reference='', $data='', $version='', $creation_date='', $update_date='', $access_date='')
100 {
101 $this->_recordversionList = array();
102 $this->reference = $reference;
103 $this->data = $data;
104 $this->version = $version;
105 $this->creation_date = $creation_date;
106 $this->update_date = $update_date;
107 $this->access_date = $access_date;
108 }
109
110
111 /**
112 * Gets object from database
113 * @param integer $recordId
114 * @return object $record
115 */
116 function Get($recordId)
117 {
118 $connection = Database::Connect();
119 $this->pog_query = "select * from `record` where `recordid`='".intval($recordId)."' LIMIT 1";
120 $cursor = Database::Reader($this->pog_query, $connection);
121 while ($row = Database::Read($cursor))
122 {
123 $this->recordId = $row['recordid'];
124 $this->userId = $row['userid'];
125 $this->reference = $this->Unescape($row['reference']);
126 $this->data = $this->Unescape($row['data']);
127 $this->version = $this->Unescape($row['version']);
128 $this->creation_date = $row['creation_date'];
129 $this->update_date = $row['update_date'];
130 $this->access_date = $row['access_date'];
131 }
132 return $this;
133 }
134
135
136 /**
137 * Returns a sorted array of objects that match given conditions
138 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
139 * @param string $sortBy
140 * @param boolean $ascending
141 * @param int limit
142 * @return array $recordList
143 */
144 function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
145 {
146 $connection = Database::Connect();
147 $sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
148 $this->pog_query = "select * from `record` ";
149 $recordList = Array();
150 if (sizeof($fcv_array) > 0)
151 {
152 $this->pog_query .= " where ";
153 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
154 {
155 if (sizeof($fcv_array[$i]) == 1)
156 {
157 $this->pog_query .= " ".$fcv_array[$i][0]." ";
158 continue;
159 }
160 else
161 {
162 if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
163 {
164 $this->pog_query .= " AND ";
165 }
166 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
167 {
168 if ($GLOBALS['configuration']['db_encoding'] == 1)
169 {
170 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
171 $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
172 }
173 else
174 {
175 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
176 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
177 }
178 }
179 else
180 {
181 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
182 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
183 }
184 }
185 }
186 }
187 if ($sortBy != '')
188 {
189 if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
190 {
191 if ($GLOBALS['configuration']['db_encoding'] == 1)
192 {
193 $sortBy = "BASE64_DECODE($sortBy) ";
194 }
195 else
196 {
197 $sortBy = "$sortBy ";
198 }
199 }
200 else
201 {
202 $sortBy = "$sortBy ";
203 }
204 }
205 else
206 {
207 $sortBy = "recordid";
208 }
209 $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
210 $thisObjectName = get_class($this);
211 $cursor = Database::Reader($this->pog_query, $connection);
212 while ($row = Database::Read($cursor))
213 {
214 $record = new $thisObjectName();
215 $record->recordId = $row['recordid'];
216 $record->userId = $row['userid'];
217 $record->reference = $this->Unescape($row['reference']);
218 $record->data = $this->Unescape($row['data']);
219 $record->version = $this->Unescape($row['version']);
220 $record->creation_date = $row['creation_date'];
221 $record->update_date = $row['update_date'];
222 $record->access_date = $row['access_date'];
223 $recordList[] = $record;
224 }
225 return $recordList;
226 }
227
228
229 /**
230 * Saves the object to the database
231 * @return integer $recordId
232 */
233 function Save($deep = true)
234 {
235 $connection = Database::Connect();
236 $this->pog_query = "select `recordid` from `record` where `recordid`='".$this->recordId."' LIMIT 1";
237 $rows = Database::Query($this->pog_query, $connection);
238 if ($rows > 0)
239 {
240 $this->pog_query = "update `record` set
241 `userid`='".$this->userId."',
242 `reference`='".$this->Escape($this->reference)."',
243 `data`='".$this->Escape($this->data)."',
244 `version`='".$this->Escape($this->version)."',
245 `creation_date`='".$this->creation_date."',
246 `update_date`='".$this->update_date."',
247 `access_date`='".$this->access_date."' where `recordid`='".$this->recordId."'";
248 }
249 else
250 {
251 $this->pog_query = "insert into `record` (`userid`, `reference`, `data`, `version`, `creation_date`, `update_date`, `access_date` ) values (
252 '".$this->userId."',
253 '".$this->Escape($this->reference)."',
254 '".$this->Escape($this->data)."',
255 '".$this->Escape($this->version)."',
256 '".$this->creation_date."',
257 '".$this->update_date."',
258 '".$this->access_date."' )";
259 }
260 $insertId = Database::InsertOrUpdate($this->pog_query, $connection);
261 if ($this->recordId == "")
262 {
263 $this->recordId = $insertId;
264 }
265 if ($deep)
266 {
267 foreach ($this->_recordversionList as $recordversion)
268 {
269 $recordversion->recordId = $this->recordId;
270 $recordversion->Save($deep);
271 }
272 }
273 return $this->recordId;
274 }
275
276
277 /**
278 * Clones the object and saves it to the database
279 * @return integer $recordId
280 */
281 function SaveNew($deep = false)
282 {
283 $this->recordId = '';
284 return $this->Save($deep);
285 }
286
287
288 /**
289 * Deletes the object from the database
290 * @return boolean
291 */
292 function Delete($deep = false, $across = false)
293 {
294 if ($deep)
295 {
296 $recordversionList = $this->GetRecordversionList();
297 foreach ($recordversionList as $recordversion)
298 {
299 $recordversion->Delete($deep, $across);
300 }
301 }
302 $connection = Database::Connect();
303 $this->pog_query = "delete from `record` where `recordid`='".$this->recordId."'";
304 return Database::NonQuery($this->pog_query, $connection);
305 }
306
307
308 /**
309 * Deletes a list of objects that match given conditions
310 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
311 * @param bool $deep
312 * @return
313 */
314 function DeleteList($fcv_array, $deep = false, $across = false)
315 {
316 if (sizeof($fcv_array) > 0)
317 {
318 if ($deep || $across)
319 {
320 $objectList = $this->GetList($fcv_array);
321 foreach ($objectList as $object)
322 {
323 $object->Delete($deep, $across);
324 }
325 }
326 else
327 {
328 $connection = Database::Connect();
329 $pog_query = "delete from `record` where ";
330 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
331 {
332 if (sizeof($fcv_array[$i]) == 1)
333 {
334 $pog_query .= " ".$fcv_array[$i][0]." ";
335 continue;
336 }
337 else
338 {
339 if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
340 {
341 $pog_query .= " AND ";
342 }
343 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
344 {
345 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
346 }
347 else
348 {
349 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
350 }
351 }
352 }
353 return Database::NonQuery($pog_query, $connection);
354 }
355 }
356 }
357
358
359 /**
360 * Associates the user object to this one
361 * @return boolean
362 */
363 function GetUser()
364 {
365 $user = new user();
366 return $user->Get($this->userId);
367 }
368
369
370 /**
371 * Associates the user object to this one
372 * @return
373 */
374 function SetUser(&$user)
375 {
376 $this->userId = $user->userId;
377 }
378
379
380 /**
381 * Gets a list of recordversion objects associated to this one
382 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
383 * @param string $sortBy
384 * @param boolean $ascending
385 * @param int limit
386 * @return array of recordversion objects
387 */
388 function GetRecordversionList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
389 {
390 $recordversion = new recordversion();
391 $fcv_array[] = array("recordId", "=", $this->recordId);
392 $dbObjects = $recordversion->GetList($fcv_array, $sortBy, $ascending, $limit);
393 return $dbObjects;
394 }
395
396
397 /**
398 * Makes this the parent of all recordversion objects in the recordversion List array. Any existing recordversion will become orphan(s)
399 * @return null
400 */
401 function SetRecordversionList(&$list)
402 {
403 $this->_recordversionList = array();
404 $existingRecordversionList = $this->GetRecordversionList();
405 foreach ($existingRecordversionList as $recordversion)
406 {
407 $recordversion->recordId = '';
408 $recordversion->Save(false);
409 }
410 $this->_recordversionList = $list;
411 }
412
413
414 /**
415 * Associates the recordversion object to this one
416 * @return
417 */
418 function AddRecordversion(&$recordversion)
419 {
420 $recordversion->recordId = $this->recordId;
421 $found = false;
422 foreach($this->_recordversionList as $recordversion2)
423 {
424 if ($recordversion->recordversionId > 0 && $recordversion->recordversionId == $recordversion2->recordversionId)
425 {
426 $found = true;
427 break;
428 }
429 }
430 if (!$found)
431 {
432 $this->_recordversionList[] = $recordversion;
433 }
434 }
435}
436?> \ No newline at end of file
diff --git a/backend/php/src/objects/class.recordversion.php b/backend/php/src/objects/class.recordversion.php
new file mode 100644
index 0000000..3fbc436
--- a/dev/null
+++ b/backend/php/src/objects/class.recordversion.php
@@ -0,0 +1,381 @@
1<?php
2/*
3 This SQL query will create the table to store your object.
4
5 CREATE TABLE `recordversion` (
6 `recordversionid` int(11) NOT NULL auto_increment,
7 `recordid` int(11) NOT NULL,
8 `reference` VARCHAR(255) NOT NULL,
9 `header` LONGTEXT NOT NULL,
10 `data` LONGTEXT NOT NULL,
11 `version` VARCHAR(255) NOT NULL,
12 `previous_version_key` VARCHAR(255) NOT NULL,
13 `previous_version_id` INT NOT NULL,
14 `creation_date` TIMESTAMP NOT NULL,
15 `update_date` TIMESTAMP NOT NULL,
16 `access_date` TIMESTAMP NOT NULL, INDEX(`recordid`), PRIMARY KEY (`recordversionid`)) ENGINE=MyISAM;
17*/
18
19/**
20* <b>recordversion</b> class with integrated CRUD methods.
21* @author Php Object Generator
22* @version POG 3.0e / PHP5.1 MYSQL
23* @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql
24* @copyright Free for personal & commercial use. (Offered under the BSD license)
25* @link http://www.phpobjectgenerator.com/?language=php5.1=pdo&pdoDriver=mysql&objectName=recordversion&attributeList=array+%28%0A++0+%3D%3E+%27record%27%2C%0A++1+%3D%3E+%27reference%27%2C%0A++2+%3D%3E+%27header%27%2C%0A++3+%3D%3E+%27data%27%2C%0A++4+%3D%3E+%27version%27%2C%0A++5+%3D%3E+%27previous_version_key%27%2C%0A++6+%3D%3E+%27previous_version_id%27%2C%0A++7+%3D%3E+%27creation_date%27%2C%0A++8+%3D%3E+%27update_date%27%2C%0A++9+%3D%3E+%27access_date%27%2C%0A%29&typeList=array%2B%2528%250A%2B%2B0%2B%253D%253E%2B%2527BELONGSTO%2527%252C%250A%2B%2B1%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B2%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B3%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B4%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B5%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B6%2B%253D%253E%2B%2527INT%2527%252C%250A%2B%2B7%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B8%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B9%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2529
26*/
27include_once('class.pog_base.php');
28class recordversion extends POG_Base
29{
30 public $recordversionId = '';
31
32 /**
33 * @var INT(11)
34 */
35 public $recordId;
36
37 /**
38 * @var VARCHAR(255)
39 */
40 public $reference;
41
42 /**
43 * @var LONGTEXT
44 */
45 public $header;
46
47 /**
48 * @var LONGTEXT
49 */
50 public $data;
51
52 /**
53 * @var VARCHAR(255)
54 */
55 public $version;
56
57 /**
58 * @var VARCHAR(255)
59 */
60 public $previous_version_key;
61
62 /**
63 * @var INT
64 */
65 public $previous_version_id;
66
67 /**
68 * @var TIMESTAMP
69 */
70 public $creation_date;
71
72 /**
73 * @var TIMESTAMP
74 */
75 public $update_date;
76
77 /**
78 * @var TIMESTAMP
79 */
80 public $access_date;
81
82 public $pog_attribute_type = array(
83 "recordversionId" => array('db_attributes' => array("NUMERIC", "INT")),
84 "record" => array('db_attributes' => array("OBJECT", "BELONGSTO")),
85 "reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
86 "header" => array('db_attributes' => array("TEXT", "LONGTEXT")),
87 "data" => array('db_attributes' => array("TEXT", "LONGTEXT")),
88 "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
89 "previous_version_key" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
90 "previous_version_id" => array('db_attributes' => array("NUMERIC", "INT")),
91 "creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
92 "update_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
93 "access_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
94 );
95 public $pog_query;
96
97
98 /**
99 * Getter for some private attributes
100 * @return mixed $attribute
101 */
102 public function __get($attribute)
103 {
104 if (isset($this->{"_".$attribute}))
105 {
106 return $this->{"_".$attribute};
107 }
108 else
109 {
110 return false;
111 }
112 }
113
114 function recordversion($reference='', $header='', $data='', $version='', $previous_version_key='', $previous_version_id='', $creation_date='', $update_date='', $access_date='')
115 {
116 $this->reference = $reference;
117 $this->header = $header;
118 $this->data = $data;
119 $this->version = $version;
120 $this->previous_version_key = $previous_version_key;
121 $this->previous_version_id = $previous_version_id;
122 $this->creation_date = $creation_date;
123 $this->update_date = $update_date;
124 $this->access_date = $access_date;
125 }
126
127
128 /**
129 * Gets object from database
130 * @param integer $recordversionId
131 * @return object $recordversion
132 */
133 function Get($recordversionId)
134 {
135 $connection = Database::Connect();
136 $this->pog_query = "select * from `recordversion` where `recordversionid`='".intval($recordversionId)."' LIMIT 1";
137 $cursor = Database::Reader($this->pog_query, $connection);
138 while ($row = Database::Read($cursor))
139 {
140 $this->recordversionId = $row['recordversionid'];
141 $this->recordId = $row['recordid'];
142 $this->reference = $this->Unescape($row['reference']);
143 $this->header = $this->Unescape($row['header']);
144 $this->data = $this->Unescape($row['data']);
145 $this->version = $this->Unescape($row['version']);
146 $this->previous_version_key = $this->Unescape($row['previous_version_key']);
147 $this->previous_version_id = $this->Unescape($row['previous_version_id']);
148 $this->creation_date = $row['creation_date'];
149 $this->update_date = $row['update_date'];
150 $this->access_date = $row['access_date'];
151 }
152 return $this;
153 }
154
155
156 /**
157 * Returns a sorted array of objects that match given conditions
158 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
159 * @param string $sortBy
160 * @param boolean $ascending
161 * @param int limit
162 * @return array $recordversionList
163 */
164 function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
165 {
166 $connection = Database::Connect();
167 $sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
168 $this->pog_query = "select * from `recordversion` ";
169 $recordversionList = Array();
170 if (sizeof($fcv_array) > 0)
171 {
172 $this->pog_query .= " where ";
173 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
174 {
175 if (sizeof($fcv_array[$i]) == 1)
176 {
177 $this->pog_query .= " ".$fcv_array[$i][0]." ";
178 continue;
179 }
180 else
181 {
182 if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
183 {
184 $this->pog_query .= " AND ";
185 }
186 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
187 {
188 if ($GLOBALS['configuration']['db_encoding'] == 1)
189 {
190 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
191 $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
192 }
193 else
194 {
195 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
196 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
197 }
198 }
199 else
200 {
201 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
202 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
203 }
204 }
205 }
206 }
207 if ($sortBy != '')
208 {
209 if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
210 {
211 if ($GLOBALS['configuration']['db_encoding'] == 1)
212 {
213 $sortBy = "BASE64_DECODE($sortBy) ";
214 }
215 else
216 {
217 $sortBy = "$sortBy ";
218 }
219 }
220 else
221 {
222 $sortBy = "$sortBy ";
223 }
224 }
225 else
226 {
227 $sortBy = "recordversionid";
228 }
229 $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
230 $thisObjectName = get_class($this);
231 $cursor = Database::Reader($this->pog_query, $connection);
232 while ($row = Database::Read($cursor))
233 {
234 $recordversion = new $thisObjectName();
235 $recordversion->recordversionId = $row['recordversionid'];
236 $recordversion->recordId = $row['recordid'];
237 $recordversion->reference = $this->Unescape($row['reference']);
238 $recordversion->header = $this->Unescape($row['header']);
239 $recordversion->data = $this->Unescape($row['data']);
240 $recordversion->version = $this->Unescape($row['version']);
241 $recordversion->previous_version_key = $this->Unescape($row['previous_version_key']);
242 $recordversion->previous_version_id = $this->Unescape($row['previous_version_id']);
243 $recordversion->creation_date = $row['creation_date'];
244 $recordversion->update_date = $row['update_date'];
245 $recordversion->access_date = $row['access_date'];
246 $recordversionList[] = $recordversion;
247 }
248 return $recordversionList;
249 }
250
251
252 /**
253 * Saves the object to the database
254 * @return integer $recordversionId
255 */
256 function Save()
257 {
258 $connection = Database::Connect();
259 $this->pog_query = "select `recordversionid` from `recordversion` where `recordversionid`='".$this->recordversionId."' LIMIT 1";
260 $rows = Database::Query($this->pog_query, $connection);
261 if ($rows > 0)
262 {
263 $this->pog_query = "update `recordversion` set
264 `recordid`='".$this->recordId."',
265 `reference`='".$this->Escape($this->reference)."',
266 `header`='".$this->Escape($this->header)."',
267 `data`='".$this->Escape($this->data)."',
268 `version`='".$this->Escape($this->version)."',
269 `previous_version_key`='".$this->Escape($this->previous_version_key)."',
270 `previous_version_id`='".$this->Escape($this->previous_version_id)."',
271 `creation_date`='".$this->creation_date."',
272 `update_date`='".$this->update_date."',
273 `access_date`='".$this->access_date."' where `recordversionid`='".$this->recordversionId."'";
274 }
275 else
276 {
277 $this->pog_query = "insert into `recordversion` (`recordid`, `reference`, `header`, `data`, `version`, `previous_version_key`, `previous_version_id`, `creation_date`, `update_date`, `access_date` ) values (
278 '".$this->recordId."',
279 '".$this->Escape($this->reference)."',
280 '".$this->Escape($this->header)."',
281 '".$this->Escape($this->data)."',
282 '".$this->Escape($this->version)."',
283 '".$this->Escape($this->previous_version_key)."',
284 '".$this->Escape($this->previous_version_id)."',
285 '".$this->creation_date."',
286 '".$this->update_date."',
287 '".$this->access_date."' )";
288 }
289 $insertId = Database::InsertOrUpdate($this->pog_query, $connection);
290 if ($this->recordversionId == "")
291 {
292 $this->recordversionId = $insertId;
293 }
294 return $this->recordversionId;
295 }
296
297
298 /**
299 * Clones the object and saves it to the database
300 * @return integer $recordversionId
301 */
302 function SaveNew()
303 {
304 $this->recordversionId = '';
305 return $this->Save();
306 }
307
308
309 /**
310 * Deletes the object from the database
311 * @return boolean
312 */
313 function Delete()
314 {
315 $connection = Database::Connect();
316 $this->pog_query = "delete from `recordversion` where `recordversionid`='".$this->recordversionId."'";
317 return Database::NonQuery($this->pog_query, $connection);
318 }
319
320
321 /**
322 * Deletes a list of objects that match given conditions
323 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
324 * @param bool $deep
325 * @return
326 */
327 function DeleteList($fcv_array)
328 {
329 if (sizeof($fcv_array) > 0)
330 {
331 $connection = Database::Connect();
332 $pog_query = "delete from `recordversion` where ";
333 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
334 {
335 if (sizeof($fcv_array[$i]) == 1)
336 {
337 $pog_query .= " ".$fcv_array[$i][0]." ";
338 continue;
339 }
340 else
341 {
342 if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
343 {
344 $pog_query .= " AND ";
345 }
346 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
347 {
348 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
349 }
350 else
351 {
352 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
353 }
354 }
355 }
356 return Database::NonQuery($pog_query, $connection);
357 }
358 }
359
360
361 /**
362 * Associates the record object to this one
363 * @return boolean
364 */
365 function GetRecord()
366 {
367 $record = new record();
368 return $record->Get($this->recordId);
369 }
370
371
372 /**
373 * Associates the record object to this one
374 * @return
375 */
376 function SetRecord(&$record)
377 {
378 $this->recordId = $record->recordId;
379 }
380}
381?> \ No newline at end of file
diff --git a/backend/php/src/objects/class.user.php b/backend/php/src/objects/class.user.php
new file mode 100644
index 0000000..f92c7ac
--- a/dev/null
+++ b/backend/php/src/objects/class.user.php
@@ -0,0 +1,502 @@
1<?php
2/*
3 This SQL query will create the table to store your object.
4
5 CREATE TABLE `user` (
6 `userid` int(11) NOT NULL auto_increment,
7 `username` VARCHAR(255) NOT NULL,
8 `srp_s` VARCHAR(255) NOT NULL,
9 `srp_v` VARCHAR(255) NOT NULL,
10 `header` LONGTEXT NOT NULL,
11 `statistics` LONGTEXT NOT NULL,
12 `auth_version` VARCHAR(255) NOT NULL,
13 `version` VARCHAR(255) NOT NULL,
14 `lock` VARCHAR(255) NOT NULL, PRIMARY KEY (`userid`)) ENGINE=MyISAM;
15*/
16
17/**
18* <b>user</b> class with integrated CRUD methods.
19* @author Php Object Generator
20* @version POG 3.0e / PHP5.1 MYSQL
21* @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql
22* @copyright Free for personal & commercial use. (Offered under the BSD license)
23* @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pdo&pdoDriver=mysql&objectName=user&attributeList=array+%28%0A++0+%3D%3E+%27username%27%2C%0A++1+%3D%3E+%27srp_s%27%2C%0A++2+%3D%3E+%27srp_v%27%2C%0A++3+%3D%3E+%27header%27%2C%0A++4+%3D%3E+%27statistics%27%2C%0A++5+%3D%3E+%27auth_version%27%2C%0A++6+%3D%3E+%27version%27%2C%0A++7+%3D%3E+%27lock%27%2C%0A++8+%3D%3E+%27record%27%2C%0A++9+%3D%3E+%27onetimepassword%27%2C%0A%29&typeList=array%2B%2528%250A%2B%2B0%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B1%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B2%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B3%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B4%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B5%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B6%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B7%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B8%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2B%2B9%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2529
24*/
25include_once('class.pog_base.php');
26class user extends POG_Base
27{
28 public $userId = '';
29
30 /**
31 * @var VARCHAR(255)
32 */
33 public $username;
34
35 /**
36 * @var VARCHAR(255)
37 */
38 public $srp_s;
39
40 /**
41 * @var VARCHAR(255)
42 */
43 public $srp_v;
44
45 /**
46 * @var LONGTEXT
47 */
48 public $header;
49
50 /**
51 * @var LONGTEXT
52 */
53 public $statistics;
54
55 /**
56 * @var VARCHAR(255)
57 */
58 public $auth_version;
59
60 /**
61 * @var VARCHAR(255)
62 */
63 public $version;
64
65 /**
66 * @var VARCHAR(255)
67 */
68 public $lock;
69
70 /**
71 * @var private array of record objects
72 */
73 private $_recordList = array();
74
75 /**
76 * @var private array of onetimepassword objects
77 */
78 private $_onetimepasswordList = array();
79
80 public $pog_attribute_type = array(
81 "userId" => array('db_attributes' => array("NUMERIC", "INT")),
82 "username" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
83 "srp_s" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
84 "srp_v" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
85 "header" => array('db_attributes' => array("TEXT", "LONGTEXT")),
86 "statistics" => array('db_attributes' => array("TEXT", "LONGTEXT")),
87 "auth_version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
88 "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
89 "lock" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
90 "record" => array('db_attributes' => array("OBJECT", "HASMANY")),
91 "onetimepassword" => array('db_attributes' => array("OBJECT", "HASMANY")),
92 );
93 public $pog_query;
94
95
96 /**
97 * Getter for some private attributes
98 * @return mixed $attribute
99 */
100 public function __get($attribute)
101 {
102 if (isset($this->{"_".$attribute}))
103 {
104 return $this->{"_".$attribute};
105 }
106 else
107 {
108 return false;
109 }
110 }
111
112 function user($username='', $srp_s='', $srp_v='', $header='', $statistics='', $auth_version='', $version='', $lock='')
113 {
114 $this->username = $username;
115 $this->srp_s = $srp_s;
116 $this->srp_v = $srp_v;
117 $this->header = $header;
118 $this->statistics = $statistics;
119 $this->auth_version = $auth_version;
120 $this->version = $version;
121 $this->lock = $lock;
122 $this->_recordList = array();
123 $this->_onetimepasswordList = array();
124 }
125
126
127 /**
128 * Gets object from database
129 * @param integer $userId
130 * @return object $user
131 */
132 function Get($userId)
133 {
134 $connection = Database::Connect();
135 $this->pog_query = "select * from `user` where `userid`='".intval($userId)."' LIMIT 1";
136 $cursor = Database::Reader($this->pog_query, $connection);
137 while ($row = Database::Read($cursor))
138 {
139 $this->userId = $row['userid'];
140 $this->username = $this->Unescape($row['username']);
141 $this->srp_s = $this->Unescape($row['srp_s']);
142 $this->srp_v = $this->Unescape($row['srp_v']);
143 $this->header = $this->Unescape($row['header']);
144 $this->statistics = $this->Unescape($row['statistics']);
145 $this->auth_version = $this->Unescape($row['auth_version']);
146 $this->version = $this->Unescape($row['version']);
147 $this->lock = $this->Unescape($row['lock']);
148 }
149 return $this;
150 }
151
152
153 /**
154 * Returns a sorted array of objects that match given conditions
155 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
156 * @param string $sortBy
157 * @param boolean $ascending
158 * @param int limit
159 * @return array $userList
160 */
161 function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
162 {
163 $connection = Database::Connect();
164 $sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
165 $this->pog_query = "select * from `user` ";
166 $userList = Array();
167 if (sizeof($fcv_array) > 0)
168 {
169 $this->pog_query .= " where ";
170 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
171 {
172 if (sizeof($fcv_array[$i]) == 1)
173 {
174 $this->pog_query .= " ".$fcv_array[$i][0]." ";
175 continue;
176 }
177 else
178 {
179 if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
180 {
181 $this->pog_query .= " AND ";
182 }
183 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
184 {
185 if ($GLOBALS['configuration']['db_encoding'] == 1)
186 {
187 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
188 $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
189 }
190 else
191 {
192 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
193 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
194 }
195 }
196 else
197 {
198 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
199 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
200 }
201 }
202 }
203 }
204 if ($sortBy != '')
205 {
206 if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
207 {
208 if ($GLOBALS['configuration']['db_encoding'] == 1)
209 {
210 $sortBy = "BASE64_DECODE($sortBy) ";
211 }
212 else
213 {
214 $sortBy = "$sortBy ";
215 }
216 }
217 else
218 {
219 $sortBy = "$sortBy ";
220 }
221 }
222 else
223 {
224 $sortBy = "userid";
225 }
226 $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
227 $thisObjectName = get_class($this);
228 $cursor = Database::Reader($this->pog_query, $connection);
229 while ($row = Database::Read($cursor))
230 {
231 $user = new $thisObjectName();
232 $user->userId = $row['userid'];
233 $user->username = $this->Unescape($row['username']);
234 $user->srp_s = $this->Unescape($row['srp_s']);
235 $user->srp_v = $this->Unescape($row['srp_v']);
236 $user->header = $this->Unescape($row['header']);
237 $user->statistics = $this->Unescape($row['statistics']);
238 $user->auth_version = $this->Unescape($row['auth_version']);
239 $user->version = $this->Unescape($row['version']);
240 $user->lock = $this->Unescape($row['lock']);
241 $userList[] = $user;
242 }
243 return $userList;
244 }
245
246
247 /**
248 * Saves the object to the database
249 * @return integer $userId
250 */
251 function Save($deep = true)
252 {
253 $connection = Database::Connect();
254 $this->pog_query = "select `userid` from `user` where `userid`='".$this->userId."' LIMIT 1";
255 $rows = Database::Query($this->pog_query, $connection);
256 if ($rows > 0)
257 {
258 $this->pog_query = "update `user` set
259 `username`='".$this->Escape($this->username)."',
260 `srp_s`='".$this->Escape($this->srp_s)."',
261 `srp_v`='".$this->Escape($this->srp_v)."',
262 `header`='".$this->Escape($this->header)."',
263 `statistics`='".$this->Escape($this->statistics)."',
264 `auth_version`='".$this->Escape($this->auth_version)."',
265 `version`='".$this->Escape($this->version)."',
266 `lock`='".$this->Escape($this->lock)."'where `userid`='".$this->userId."'";
267 }
268 else
269 {
270 $this->pog_query = "insert into `user` (`username`, `srp_s`, `srp_v`, `header`, `statistics`, `auth_version`, `version`, `lock`) values (
271 '".$this->Escape($this->username)."',
272 '".$this->Escape($this->srp_s)."',
273 '".$this->Escape($this->srp_v)."',
274 '".$this->Escape($this->header)."',
275 '".$this->Escape($this->statistics)."',
276 '".$this->Escape($this->auth_version)."',
277 '".$this->Escape($this->version)."',
278 '".$this->Escape($this->lock)."')";
279 }
280 $insertId = Database::InsertOrUpdate($this->pog_query, $connection);
281 if ($this->userId == "")
282 {
283 $this->userId = $insertId;
284 }
285 if ($deep)
286 {
287 foreach ($this->_recordList as $record)
288 {
289 $record->userId = $this->userId;
290 $record->Save($deep);
291 }
292 foreach ($this->_onetimepasswordList as $onetimepassword)
293 {
294 $onetimepassword->userId = $this->userId;
295 $onetimepassword->Save($deep);
296 }
297 }
298 return $this->userId;
299 }
300
301
302 /**
303 * Clones the object and saves it to the database
304 * @return integer $userId
305 */
306 function SaveNew($deep = false)
307 {
308 $this->userId = '';
309 return $this->Save($deep);
310 }
311
312
313 /**
314 * Deletes the object from the database
315 * @return boolean
316 */
317 function Delete($deep = false, $across = false)
318 {
319 if ($deep)
320 {
321 $recordList = $this->GetRecordList();
322 foreach ($recordList as $record)
323 {
324 $record->Delete($deep, $across);
325 }
326 $onetimepasswordList = $this->GetOnetimepasswordList();
327 foreach ($onetimepasswordList as $onetimepassword)
328 {
329 $onetimepassword->Delete($deep, $across);
330 }
331 }
332 $connection = Database::Connect();
333 $this->pog_query = "delete from `user` where `userid`='".$this->userId."'";
334 return Database::NonQuery($this->pog_query, $connection);
335 }
336
337
338 /**
339 * Deletes a list of objects that match given conditions
340 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
341 * @param bool $deep
342 * @return
343 */
344 function DeleteList($fcv_array, $deep = false, $across = false)
345 {
346 if (sizeof($fcv_array) > 0)
347 {
348 if ($deep || $across)
349 {
350 $objectList = $this->GetList($fcv_array);
351 foreach ($objectList as $object)
352 {
353 $object->Delete($deep, $across);
354 }
355 }
356 else
357 {
358 $connection = Database::Connect();
359 $pog_query = "delete from `user` where ";
360 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
361 {
362 if (sizeof($fcv_array[$i]) == 1)
363 {
364 $pog_query .= " ".$fcv_array[$i][0]." ";
365 continue;
366 }
367 else
368 {
369 if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
370 {
371 $pog_query .= " AND ";
372 }
373 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
374 {
375 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
376 }
377 else
378 {
379 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
380 }
381 }
382 }
383 return Database::NonQuery($pog_query, $connection);
384 }
385 }
386 }
387
388
389 /**
390 * Gets a list of record objects associated to this one
391 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
392 * @param string $sortBy
393 * @param boolean $ascending
394 * @param int limit
395 * @return array of record objects
396 */
397 function GetRecordList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
398 {
399 $record = new record();
400 $fcv_array[] = array("userId", "=", $this->userId);
401 $dbObjects = $record->GetList($fcv_array, $sortBy, $ascending, $limit);
402 return $dbObjects;
403 }
404
405
406 /**
407 * Makes this the parent of all record objects in the record List array. Any existing record will become orphan(s)
408 * @return null
409 */
410 function SetRecordList(&$list)
411 {
412 $this->_recordList = array();
413 $existingRecordList = $this->GetRecordList();
414 foreach ($existingRecordList as $record)
415 {
416 $record->userId = '';
417 $record->Save(false);
418 }
419 $this->_recordList = $list;
420 }
421
422
423 /**
424 * Associates the record object to this one
425 * @return
426 */
427 function AddRecord(&$record)
428 {
429 $record->userId = $this->userId;
430 $found = false;
431 foreach($this->_recordList as $record2)
432 {
433 if ($record->recordId > 0 && $record->recordId == $record2->recordId)
434 {
435 $found = true;
436 break;
437 }
438 }
439 if (!$found)
440 {
441 $this->_recordList[] = $record;
442 }
443 }
444
445
446 /**
447 * Gets a list of onetimepassword objects associated to this one
448 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
449 * @param string $sortBy
450 * @param boolean $ascending
451 * @param int limit
452 * @return array of onetimepassword objects
453 */
454 function GetOnetimepasswordList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
455 {
456 $onetimepassword = new onetimepassword();
457 $fcv_array[] = array("userId", "=", $this->userId);
458 $dbObjects = $onetimepassword->GetList($fcv_array, $sortBy, $ascending, $limit);
459 return $dbObjects;
460 }
461
462
463 /**
464 * Makes this the parent of all onetimepassword objects in the onetimepassword List array. Any existing onetimepassword will become orphan(s)
465 * @return null
466 */
467 function SetOnetimepasswordList(&$list)
468 {
469 $this->_onetimepasswordList = array();
470 $existingOnetimepasswordList = $this->GetOnetimepasswordList();
471 foreach ($existingOnetimepasswordList as $onetimepassword)
472 {
473 $onetimepassword->userId = '';
474 $onetimepassword->Save(false);
475 }
476 $this->_onetimepasswordList = $list;
477 }
478
479
480 /**
481 * Associates the onetimepassword object to this one
482 * @return
483 */
484 function AddOnetimepassword(&$onetimepassword)
485 {
486 $onetimepassword->userId = $this->userId;
487 $found = false;
488 foreach($this->_onetimepasswordList as $onetimepassword2)
489 {
490 if ($onetimepassword->onetimepasswordId > 0 && $onetimepassword->onetimepasswordId == $onetimepassword2->onetimepasswordId)
491 {
492 $found = true;
493 break;
494 }
495 }
496 if (!$found)
497 {
498 $this->_onetimepasswordList[] = $onetimepassword;
499 }
500 }
501}
502?> \ No newline at end of file
diff --git a/backend/php/src/objects/ignore_objects.txt b/backend/php/src/objects/ignore_objects.txt
new file mode 100644
index 0000000..e69de29
--- a/dev/null
+++ b/backend/php/src/objects/ignore_objects.txt