summaryrefslogtreecommitdiff
path: root/backend/php
Unidiff
Diffstat (limited to 'backend/php') (more/less context) (ignore whitespace changes)
-rw-r--r--backend/php/src/index.php7
-rw-r--r--backend/php/src/objects/class.record.php13
-rw-r--r--backend/php/src/objects/class.recordversion.php4
3 files changed, 19 insertions, 5 deletions
diff --git a/backend/php/src/index.php b/backend/php/src/index.php
index 58c10a9..3d23e7a 100644
--- a/backend/php/src/index.php
+++ b/backend/php/src/index.php
@@ -330,96 +330,103 @@ error_log("oneTimePassword");
330 //"parameters":{ 330 //"parameters":{
331 // "oneTimePasswordKey":"06dfa7f428081f8b2af98b0895e14e18af90b0ef2ff32828e55cc2ac6b24d29b", 331 // "oneTimePasswordKey":"06dfa7f428081f8b2af98b0895e14e18af90b0ef2ff32828e55cc2ac6b24d29b",
332 // "oneTimePasswordKeyChecksum":"60bcba3f72e56f6bb3f0ff88509b9a0e5ec730dfa71daa4c1e892dbd1b0c360d" 332 // "oneTimePasswordKeyChecksum":"60bcba3f72e56f6bb3f0ff88509b9a0e5ec730dfa71daa4c1e892dbd1b0c360d"
333 //} 333 //}
334//} 334//}
335 $otp = new onetimepassword(); 335 $otp = new onetimepassword();
336 $otpList = $otp->GetList(array(array("key", "=", $parameters["parameters"]["oneTimePasswordKey"]))); 336 $otpList = $otp->GetList(array(array("key", "=", $parameters["parameters"]["oneTimePasswordKey"])));
337 337
338 if (count($otpList) == 1) { 338 if (count($otpList) == 1) {
339 $currentOtp = $otpList[0]; 339 $currentOtp = $otpList[0];
340 340
341 if ($currentOtp->GetOnetimepasswordstatus()->code == "ACTIVE") { 341 if ($currentOtp->GetOnetimepasswordstatus()->code == "ACTIVE") {
342 if ($currentOtp->key_checksum == $parameters["parameters"]["oneTimePasswordKeyChecksum"]) { 342 if ($currentOtp->key_checksum == $parameters["parameters"]["oneTimePasswordKeyChecksum"]) {
343 $_SESSION["userId"] = $currentOtp->GetUser()->userId; 343 $_SESSION["userId"] = $currentOtp->GetUser()->userId;
344 $_SESSION["otpId"]= $currentOtp->onetimepasswordId; 344 $_SESSION["otpId"]= $currentOtp->onetimepasswordId;
345 345
346 $result["data"] = $currentOtp->data; 346 $result["data"] = $currentOtp->data;
347 $result["version"] = $currentOtp->version; 347 $result["version"] = $currentOtp->version;
348 348
349 resetOTP($currentOtp, "REQUESTED"); 349 resetOTP($currentOtp, "REQUESTED");
350 } else { 350 } else {
351 resetOTP($currentOtp, "DISABLED"); 351 resetOTP($currentOtp, "DISABLED");
352 throw new Exception("The requested One Time Password has been disabled, due to a wrong keyChecksum"); 352 throw new Exception("The requested One Time Password has been disabled, due to a wrong keyChecksum");
353 } 353 }
354 } else { 354 } else {
355 throw new Exception("The requested One Time Password was not active"); 355 throw new Exception("The requested One Time Password was not active");
356 } 356 }
357 } else { 357 } else {
358 throw new Exception("The requested One Time Password has not been found"); 358 throw new Exception("The requested One Time Password has not been found");
359 } 359 }
360 360
361 //============================================================= 361 //=============================================================
362 } 362 }
363 363
364 break; 364 break;
365 365
366 case "message": 366 case "message":
367error_log("message"); 367error_log("message");
368 if ($parameters["srpSharedSecret"] == $_SESSION["K"]) { 368 if ($parameters["srpSharedSecret"] == $_SESSION["K"]) {
369 $message = $parameters["message"]; 369 $message = $parameters["message"];
370 370
371 //============================================================= 371 //=============================================================
372 if ($message == "getUserDetails") { 372 if ($message == "getUserDetails") {
373//{"message":"getUserDetails", "srpSharedSecret":"f18e5cf7c3a83b67d4db9444af813ee48c13daf4f8f6635397d593e52ba89a08", "parameters":{}} 373//{"message":"getUserDetails", "srpSharedSecret":"f18e5cf7c3a83b67d4db9444af813ee48c13daf4f8f6635397d593e52ba89a08", "parameters":{}}
374 $user = new user(); 374 $user = new user();
375 $user = $user->Get($_SESSION["userId"]); 375 $user = $user->Get($_SESSION["userId"]);
376 376
377 $result["header"] = $user->header; 377 $result["header"] = $user->header;
378 $records = $user->GetRecordList();
379 foreach ($records as $record)
380 {
381 $recordStats["updateDate"] = $record->update_date;
382 $recordsStats[$record->reference] = $recordStats;
383 }
384 $result["recordsStats"] = $recordsStats;
378 $result["statistics"] =$user->statistics; 385 $result["statistics"] =$user->statistics;
379 $result["version"] =$user->version; 386 $result["version"] =$user->version;
380 387
381 //============================================================= 388 //=============================================================
382 } else if ($message == "addNewRecords") { 389 } else if ($message == "addNewRecords") {
383/* 390/*
384//{ 391//{
385 //"message":"addNewRecords", 392 //"message":"addNewRecords",
386 //"srpSharedSecret":"b58fdf62acebbcb67f63d28c0437f166069f45690c648cd4376a792ae7a325f7", 393 //"srpSharedSecret":"b58fdf62acebbcb67f63d28c0437f166069f45690c648cd4376a792ae7a325f7",
387 //"parameters":{ 394 //"parameters":{
388 // "records":[ 395 // "records":[
389 // { 396 // {
390 // "record":{ 397 // "record":{
391 // "reference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610", 398 // "reference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610",
392 // "data":"OBSGtcb6blXq/xaYG.....4EqlQqgAvITN", 399 // "data":"OBSGtcb6blXq/xaYG.....4EqlQqgAvITN",
393 // "version":"0.3" 400 // "version":"0.3"
394 // }, 401 // },
395 // "currentRecordVersion":{ 402 // "currentRecordVersion":{
396 // "reference":"83ad301525c18f2afd72b6ac82c0a713382e1ef70ac69935ca7e2869dd4ff980", 403 // "reference":"83ad301525c18f2afd72b6ac82c0a713382e1ef70ac69935ca7e2869dd4ff980",
397 // "recordReference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610", 404 // "recordReference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610",
398 // "data":"NXJ5jiZhkd0CMiwwntAq....1TjjF+SGfE=", 405 // "data":"NXJ5jiZhkd0CMiwwntAq....1TjjF+SGfE=",
399 // "version":"0.3", 406 // "version":"0.3",
400 // "previousVersion":"3e174a86afc322271d8af28bc062b0f1bfd7344fad01212cd08b2757c4b199c4", 407 // "previousVersion":"3e174a86afc322271d8af28bc062b0f1bfd7344fad01212cd08b2757c4b199c4",
401 // "previousVersionKey":"kozaaGCzXWr71LbOKu6Z3nz520V..5U85tSBvb+u44twttv54Kw==" 408 // "previousVersionKey":"kozaaGCzXWr71LbOKu6Z3nz520V..5U85tSBvb+u44twttv54Kw=="
402 // } 409 // }
403 // } 410 // }
404 // ], 411 // ],
405 // "user":{ 412 // "user":{
406 // "header":"{\"reco...ersion\":\"0.1\"}", 413 // "header":"{\"reco...ersion\":\"0.1\"}",
407 // "statistics":"rKI6nR6iqggygQJ3SQ58bFUX", 414 // "statistics":"rKI6nR6iqggygQJ3SQ58bFUX",
408 // "version":"0.3", 415 // "version":"0.3",
409 // "lock":"----" 416 // "lock":"----"
410 // } 417 // }
411 //} 418 //}
412//} 419//}
413*/ 420*/
414 $user = new user(); 421 $user = new user();
415 $record = new record(); 422 $record = new record();
416 $recordVersion = new recordversion(); 423 $recordVersion = new recordversion();
417 424
418 $user = $user->Get($_SESSION["userId"]); 425 $user = $user->Get($_SESSION["userId"]);
419 updateUserData($parameters["parameters"]["user"], $user); 426 updateUserData($parameters["parameters"]["user"], $user);
420 427
421 $recordParameterList = $parameters["parameters"]["records"]; 428 $recordParameterList = $parameters["parameters"]["records"];
422 $c = count($recordParameterList); 429 $c = count($recordParameterList);
423 for ($i=0; $i<$c; $i++) { 430 for ($i=0; $i<$c; $i++) {
424 updateRecordData($recordParameterList[$i], $record, $recordVersion); 431 updateRecordData($recordParameterList[$i], $record, $recordVersion);
425 432
diff --git a/backend/php/src/objects/class.record.php b/backend/php/src/objects/class.record.php
index a269e75..37a9702 100644
--- a/backend/php/src/objects/class.record.php
+++ b/backend/php/src/objects/class.record.php
@@ -1,60 +1,60 @@
1<?php 1<?php
2/* 2/*
3 This SQL query will create the table to store your object. 3 This SQL query will create the table to store your object.
4 4
5 CREATE TABLE `record` ( 5 CREATE TABLE `record` (
6 `recordid` int(11) NOT NULL auto_increment, 6 `recordid` int(11) NOT NULL auto_increment,
7 `userid` int(11) NOT NULL, 7 `userid` int(11) NOT NULL,
8 `reference` VARCHAR(255) NOT NULL, 8 `reference` VARCHAR(255) NOT NULL,
9 `data` LONGTEXT NOT NULL, 9 `data` LONGTEXT NOT NULL,
10 `version` VARCHAR(255) NOT NULL, 10 `version` VARCHAR(255) NOT NULL,
11 `creation_date` TIMESTAMP NOT NULL, 11 `creation_date` TIMESTAMP NOT NULL,
12 `update_date` TIMESTAMP NOT NULL, 12 `update_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
13 `access_date` TIMESTAMP NOT NULL, INDEX(`userid`), PRIMARY KEY (`recordid`)) ENGINE=MyISAM; 13 `access_date` TIMESTAMP NOT NULL, INDEX(`userid`), PRIMARY KEY (`recordid`)) ENGINE=MyISAM;
14*/ 14*/
15 15
16/** 16/**
17* <b>record</b> class with integrated CRUD methods. 17* <b>record</b> class with integrated CRUD methods.
18* @author Php Object Generator 18* @author Php Object Generator
19* @version POG 3.0e / PHP5.1 MYSQL 19* @version POG 3.0e / PHP5.1 MYSQL
20* @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql 20* @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql
21* @copyright Free for personal & commercial use. (Offered under the BSD license) 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 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*/ 23*/
24include_once('class.pog_base.php'); 24include_once('class.pog_base.php');
25class record extends POG_Base 25class record extends POG_Base
26{ 26{
27 public $recordId = ''; 27 public $recordId = '';
28 28
29 /** 29 /**
30 * @var INT(11) 30 * @var INT(11)
31 */ 31 */
32 public $userId; 32 public $userId;
33 33
34 /** 34 /**
35 * @var private array of recordversion objects 35 * @var private array of recordversion objects
36 */ 36 */
37 private $_recordversionList = array(); 37 private $_recordversionList = array();
38 38
39 /** 39 /**
40 * @var VARCHAR(255) 40 * @var VARCHAR(255)
41 */ 41 */
42 public $reference; 42 public $reference;
43 43
44 /** 44 /**
45 * @var LONGTEXT 45 * @var LONGTEXT
46 */ 46 */
47 public $data; 47 public $data;
48 48
49 /** 49 /**
50 * @var VARCHAR(255) 50 * @var VARCHAR(255)
51 */ 51 */
52 public $version; 52 public $version;
53 53
54 /** 54 /**
55 * @var TIMESTAMP 55 * @var TIMESTAMP
56 */ 56 */
57 public $creation_date; 57 public $creation_date;
58 58
59 /** 59 /**
60 * @var TIMESTAMP 60 * @var TIMESTAMP
@@ -81,251 +81,256 @@ class record extends POG_Base
81 81
82 82
83 /** 83 /**
84 * Getter for some private attributes 84 * Getter for some private attributes
85 * @return mixed $attribute 85 * @return mixed $attribute
86 */ 86 */
87 public function __get($attribute) 87 public function __get($attribute)
88 { 88 {
89 if (isset($this->{"_".$attribute})) 89 if (isset($this->{"_".$attribute}))
90 { 90 {
91 return $this->{"_".$attribute}; 91 return $this->{"_".$attribute};
92 } 92 }
93 else 93 else
94 { 94 {
95 return false; 95 return false;
96 } 96 }
97 } 97 }
98 98
99 function record($reference='', $data='', $version='', $creation_date='', $update_date='', $access_date='') 99 function record($reference='', $data='', $version='', $creation_date='', $update_date='', $access_date='')
100 { 100 {
101 $this->_recordversionList = array(); 101 $this->_recordversionList = array();
102 $this->reference = $reference; 102 $this->reference = $reference;
103 $this->data = $data; 103 $this->data = $data;
104 $this->version = $version; 104 $this->version = $version;
105 $this->creation_date = $creation_date; 105 $this->creation_date = $creation_date;
106 $this->update_date = $update_date; 106 $this->update_date = $update_date;
107 $this->access_date = $access_date; 107 $this->access_date = $access_date;
108 } 108 }
109 109
110 110
111 /** 111 /**
112 * Gets object from database 112 * Gets object from database
113 * @param integer $recordId 113 * @param integer $recordId
114 * @return object $record 114 * @return object $record
115 */ 115 */
116 function Get($recordId) 116 function Get($recordId)
117 { 117 {
118 $connection = Database::Connect(); 118 $connection = Database::Connect();
119 $this->pog_query = "select * from `record` where `recordid`='".intval($recordId)."' LIMIT 1"; 119 $this->pog_query = "select * from `record` where `recordid`='".intval($recordId)."' LIMIT 1";
120 $cursor = Database::Reader($this->pog_query, $connection); 120 $cursor = Database::Reader($this->pog_query, $connection);
121 while ($row = Database::Read($cursor)) 121 while ($row = Database::Read($cursor))
122 { 122 {
123 $this->recordId = $row['recordid']; 123 $this->recordId = $row['recordid'];
124 $this->userId = $row['userid']; 124 $this->userId = $row['userid'];
125 $this->reference = $this->Unescape($row['reference']); 125 $this->reference = $this->Unescape($row['reference']);
126 $this->data = $this->Unescape($row['data']); 126 $this->data = $this->Unescape($row['data']);
127 $this->version = $this->Unescape($row['version']); 127 $this->version = $this->Unescape($row['version']);
128 $this->creation_date = $row['creation_date']; 128 $this->creation_date = $row['creation_date'];
129 $this->update_date = $row['update_date']; 129 $oDate = strtotime($row['update_date']);
130 $this->update_date = date('r', $oDate);
130 $this->access_date = $row['access_date']; 131 $this->access_date = $row['access_date'];
131 } 132 }
132 return $this; 133 return $this;
133 } 134 }
134 135
135 136
136 /** 137 /**
137 * Returns a sorted array of objects that match given conditions 138 * Returns a sorted array of objects that match given conditions
138 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 139 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
139 * @param string $sortBy 140 * @param string $sortBy
140 * @param boolean $ascending 141 * @param boolean $ascending
141 * @param int limit 142 * @param int limit
142 * @return array $recordList 143 * @return array $recordList
143 */ 144 */
144 function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') 145 function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
145 { 146 {
146 $connection = Database::Connect(); 147 $connection = Database::Connect();
147 $sqlLimit = ($limit != '' ? "LIMIT $limit" : ''); 148 $sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
148 $this->pog_query = "select * from `record` "; 149 $this->pog_query = "select * from `record` ";
149 $recordList = Array(); 150 $recordList = Array();
150 if (sizeof($fcv_array) > 0) 151 if (sizeof($fcv_array) > 0)
151 { 152 {
152 $this->pog_query .= " where "; 153 $this->pog_query .= " where ";
153 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) 154 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
154 { 155 {
155 if (sizeof($fcv_array[$i]) == 1) 156 if (sizeof($fcv_array[$i]) == 1)
156 { 157 {
157 $this->pog_query .= " ".$fcv_array[$i][0]." "; 158 $this->pog_query .= " ".$fcv_array[$i][0]." ";
158 continue; 159 continue;
159 } 160 }
160 else 161 else
161 { 162 {
162 if ($i > 0 && sizeof($fcv_array[$i-1]) != 1) 163 if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
163 { 164 {
164 $this->pog_query .= " AND "; 165 $this->pog_query .= " AND ";
165 } 166 }
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 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 {
168 if ($GLOBALS['configuration']['db_encoding'] == 1) 169 if ($GLOBALS['configuration']['db_encoding'] == 1)
169 { 170 {
170 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'"; 171 $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 $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
172 } 173 }
173 else 174 else
174 { 175 {
175 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'"; 176 $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 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
177 } 178 }
178 } 179 }
179 else 180 else
180 { 181 {
181 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'"; 182 $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 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
183 } 184 }
184 } 185 }
185 } 186 }
186 } 187 }
187 if ($sortBy != '') 188 if ($sortBy != '')
188 { 189 {
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 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 {
191 if ($GLOBALS['configuration']['db_encoding'] == 1) 192 if ($GLOBALS['configuration']['db_encoding'] == 1)
192 { 193 {
193 $sortBy = "BASE64_DECODE($sortBy) "; 194 $sortBy = "BASE64_DECODE($sortBy) ";
194 } 195 }
195 else 196 else
196 { 197 {
197 $sortBy = "$sortBy "; 198 $sortBy = "$sortBy ";
198 } 199 }
199 } 200 }
200 else 201 else
201 { 202 {
202 $sortBy = "$sortBy "; 203 $sortBy = "$sortBy ";
203 } 204 }
204 } 205 }
205 else 206 else
206 { 207 {
207 $sortBy = "recordid"; 208 $sortBy = "recordid";
208 } 209 }
209 $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit"; 210 $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
210 $thisObjectName = get_class($this); 211 $thisObjectName = get_class($this);
211 $cursor = Database::Reader($this->pog_query, $connection); 212 $cursor = Database::Reader($this->pog_query, $connection);
212 while ($row = Database::Read($cursor)) 213 while ($row = Database::Read($cursor))
213 { 214 {
214 $record = new $thisObjectName(); 215 $record = new $thisObjectName();
215 $record->recordId = $row['recordid']; 216 $record->recordId = $row['recordid'];
216 $record->userId = $row['userid']; 217 $record->userId = $row['userid'];
217 $record->reference = $this->Unescape($row['reference']); 218 $record->reference = $this->Unescape($row['reference']);
218 $record->data = $this->Unescape($row['data']); 219 $record->data = $this->Unescape($row['data']);
219 $record->version = $this->Unescape($row['version']); 220 $record->version = $this->Unescape($row['version']);
220 $record->creation_date = $row['creation_date']; 221 $record->creation_date = $row['creation_date'];
221 $record->update_date = $row['update_date']; 222 $oDate = strtotime($row['update_date']);
223 $record->update_date = date('r', $oDate);
222 $record->access_date = $row['access_date']; 224 $record->access_date = $row['access_date'];
223 $recordList[] = $record; 225 $recordList[] = $record;
224 } 226 }
225 return $recordList; 227 return $recordList;
226 } 228 }
227 229
228 230
229 /** 231 /**
230 * Saves the object to the database 232 * Saves the object to the database
231 * @return integer $recordId 233 * @return integer $recordId
232 */ 234 */
233 function Save($deep = true) 235 function Save($deep = true)
234 { 236 {
235 $connection = Database::Connect(); 237 $connection = Database::Connect();
238 $this->update_date = date( 'r');
239 $this->access_date = date( 'r');
236 $this->pog_query = "select `recordid` from `record` where `recordid`='".$this->recordId."' LIMIT 1"; 240 $this->pog_query = "select `recordid` from `record` where `recordid`='".$this->recordId."' LIMIT 1";
237 $rows = Database::Query($this->pog_query, $connection); 241 $rows = Database::Query($this->pog_query, $connection);
238 if ($rows > 0) 242 if ($rows > 0)
239 { 243 {
240 $this->pog_query = "update `record` set 244 $this->pog_query = "update `record` set
241 `userid`='".$this->userId."', 245 `userid`='".$this->userId."',
242 `reference`='".$this->Escape($this->reference)."', 246 `reference`='".$this->Escape($this->reference)."',
243 `data`='".$this->Escape($this->data)."', 247 `data`='".$this->Escape($this->data)."',
244 `version`='".$this->Escape($this->version)."', 248 `version`='".$this->Escape($this->version)."',
245 `creation_date`='".$this->creation_date."', 249 `creation_date`='".$this->creation_date."',
246 `update_date`='".$this->update_date."', 250 `update_date`='".$this->update_date."',
247 `access_date`='".$this->access_date."' where `recordid`='".$this->recordId."'"; 251 `access_date`='".$this->access_date."' where `recordid`='".$this->recordId."'";
248 } 252 }
249 else 253 else
250 { 254 {
251 $this->pog_query = "insert into `record` (`userid`, `reference`, `data`, `version`, `creation_date`, `update_date`, `access_date` ) values ( 255 $this->pog_query = "insert into `record` (`userid`, `reference`, `data`, `version`, `creation_date`, `update_date`, `access_date` ) values (
252 '".$this->userId."', 256 '".$this->userId."',
253 '".$this->Escape($this->reference)."', 257 '".$this->Escape($this->reference)."',
254 '".$this->Escape($this->data)."', 258 '".$this->Escape($this->data)."',
255 '".$this->Escape($this->version)."', 259 '".$this->Escape($this->version)."',
256 '".$this->creation_date."', 260 '".$this->creation_date."',
257 '".$this->update_date."', 261 '".$this->update_date."',
258 '".$this->access_date."' )"; 262 '".$this->access_date."' )";
259 } 263 }
260 $insertId = Database::InsertOrUpdate($this->pog_query, $connection); 264 $insertId = Database::InsertOrUpdate($this->pog_query, $connection);
261 if ($this->recordId == "") 265 if ($this->recordId == "")
262 { 266 {
263 $this->recordId = $insertId; 267 $this->recordId = $insertId;
264 } 268 }
265 if ($deep) 269 if ($deep)
266 { 270 {
267 foreach ($this->_recordversionList as $recordversion) 271 foreach ($this->_recordversionList as $recordversion)
268 { 272 {
269 $recordversion->recordId = $this->recordId; 273 $recordversion->recordId = $this->recordId;
270 $recordversion->Save($deep); 274 $recordversion->Save($deep);
271 } 275 }
272 } 276 }
273 return $this->recordId; 277 return $this->recordId;
274 } 278 }
275 279
276 280
277 /** 281 /**
278 * Clones the object and saves it to the database 282 * Clones the object and saves it to the database
279 * @return integer $recordId 283 * @return integer $recordId
280 */ 284 */
281 function SaveNew($deep = false) 285 function SaveNew($deep = false)
282 { 286 {
283 $this->recordId = ''; 287 $this->recordId = '';
288 $this->creation_date = date( 'Y-m-d H:i:s');
284 return $this->Save($deep); 289 return $this->Save($deep);
285 } 290 }
286 291
287 292
288 /** 293 /**
289 * Deletes the object from the database 294 * Deletes the object from the database
290 * @return boolean 295 * @return boolean
291 */ 296 */
292 function Delete($deep = false, $across = false) 297 function Delete($deep = false, $across = false)
293 { 298 {
294 if ($deep) 299 if ($deep)
295 { 300 {
296 $recordversionList = $this->GetRecordversionList(); 301 $recordversionList = $this->GetRecordversionList();
297 foreach ($recordversionList as $recordversion) 302 foreach ($recordversionList as $recordversion)
298 { 303 {
299 $recordversion->Delete($deep, $across); 304 $recordversion->Delete($deep, $across);
300 } 305 }
301 } 306 }
302 $connection = Database::Connect(); 307 $connection = Database::Connect();
303 $this->pog_query = "delete from `record` where `recordid`='".$this->recordId."'"; 308 $this->pog_query = "delete from `record` where `recordid`='".$this->recordId."'";
304 return Database::NonQuery($this->pog_query, $connection); 309 return Database::NonQuery($this->pog_query, $connection);
305 } 310 }
306 311
307 312
308 /** 313 /**
309 * Deletes a list of objects that match given conditions 314 * Deletes a list of objects that match given conditions
310 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 315 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
311 * @param bool $deep 316 * @param bool $deep
312 * @return 317 * @return
313 */ 318 */
314 function DeleteList($fcv_array, $deep = false, $across = false) 319 function DeleteList($fcv_array, $deep = false, $across = false)
315 { 320 {
316 if (sizeof($fcv_array) > 0) 321 if (sizeof($fcv_array) > 0)
317 { 322 {
318 if ($deep || $across) 323 if ($deep || $across)
319 { 324 {
320 $objectList = $this->GetList($fcv_array); 325 $objectList = $this->GetList($fcv_array);
321 foreach ($objectList as $object) 326 foreach ($objectList as $object)
322 { 327 {
323 $object->Delete($deep, $across); 328 $object->Delete($deep, $across);
324 } 329 }
325 } 330 }
326 else 331 else
327 { 332 {
328 $connection = Database::Connect(); 333 $connection = Database::Connect();
329 $pog_query = "delete from `record` where "; 334 $pog_query = "delete from `record` where ";
330 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) 335 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
331 { 336 {
@@ -388,49 +393,49 @@ class record extends POG_Base
388 function GetRecordversionList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') 393 function GetRecordversionList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
389 { 394 {
390 $recordversion = new recordversion(); 395 $recordversion = new recordversion();
391 $fcv_array[] = array("recordId", "=", $this->recordId); 396 $fcv_array[] = array("recordId", "=", $this->recordId);
392 $dbObjects = $recordversion->GetList($fcv_array, $sortBy, $ascending, $limit); 397 $dbObjects = $recordversion->GetList($fcv_array, $sortBy, $ascending, $limit);
393 return $dbObjects; 398 return $dbObjects;
394 } 399 }
395 400
396 401
397 /** 402 /**
398 * Makes this the parent of all recordversion objects in the recordversion List array. Any existing recordversion will become orphan(s) 403 * Makes this the parent of all recordversion objects in the recordversion List array. Any existing recordversion will become orphan(s)
399 * @return null 404 * @return null
400 */ 405 */
401 function SetRecordversionList(&$list) 406 function SetRecordversionList(&$list)
402 { 407 {
403 $this->_recordversionList = array(); 408 $this->_recordversionList = array();
404 $existingRecordversionList = $this->GetRecordversionList(); 409 $existingRecordversionList = $this->GetRecordversionList();
405 foreach ($existingRecordversionList as $recordversion) 410 foreach ($existingRecordversionList as $recordversion)
406 { 411 {
407 $recordversion->recordId = ''; 412 $recordversion->recordId = '';
408 $recordversion->Save(false); 413 $recordversion->Save(false);
409 } 414 }
410 $this->_recordversionList = $list; 415 $this->_recordversionList = $list;
411 } 416 }
412 417
413 418
414 /** 419 /**
415 * Associates the recordversion object to this one 420 * Associates the recordversion object to this one
416 * @return 421 * @return
417 */ 422 */
418 function AddRecordversion(&$recordversion) 423 function AddRecordversion(&$recordversion)
419 { 424 {
420 $recordversion->recordId = $this->recordId; 425 $recordversion->recordId = $this->recordId;
421 $found = false; 426 $found = false;
422 foreach($this->_recordversionList as $recordversion2) 427 foreach($this->_recordversionList as $recordversion2)
423 { 428 {
424 if ($recordversion->recordversionId > 0 && $recordversion->recordversionId == $recordversion2->recordversionId) 429 if ($recordversion->recordversionId > 0 && $recordversion->recordversionId == $recordversion2->recordversionId)
425 { 430 {
426 $found = true; 431 $found = true;
427 break; 432 break;
428 } 433 }
429 } 434 }
430 if (!$found) 435 if (!$found)
431 { 436 {
432 $this->_recordversionList[] = $recordversion; 437 $this->_recordversionList[] = $recordversion;
433 } 438 }
434 } 439 }
435} 440}
436?> \ No newline at end of file 441?>
diff --git a/backend/php/src/objects/class.recordversion.php b/backend/php/src/objects/class.recordversion.php
index 3fbc436..f2de14a 100644
--- a/backend/php/src/objects/class.recordversion.php
+++ b/backend/php/src/objects/class.recordversion.php
@@ -211,96 +211,98 @@ class recordversion extends POG_Base
211 if ($GLOBALS['configuration']['db_encoding'] == 1) 211 if ($GLOBALS['configuration']['db_encoding'] == 1)
212 { 212 {
213 $sortBy = "BASE64_DECODE($sortBy) "; 213 $sortBy = "BASE64_DECODE($sortBy) ";
214 } 214 }
215 else 215 else
216 { 216 {
217 $sortBy = "$sortBy "; 217 $sortBy = "$sortBy ";
218 } 218 }
219 } 219 }
220 else 220 else
221 { 221 {
222 $sortBy = "$sortBy "; 222 $sortBy = "$sortBy ";
223 } 223 }
224 } 224 }
225 else 225 else
226 { 226 {
227 $sortBy = "recordversionid"; 227 $sortBy = "recordversionid";
228 } 228 }
229 $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit"; 229 $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
230 $thisObjectName = get_class($this); 230 $thisObjectName = get_class($this);
231 $cursor = Database::Reader($this->pog_query, $connection); 231 $cursor = Database::Reader($this->pog_query, $connection);
232 while ($row = Database::Read($cursor)) 232 while ($row = Database::Read($cursor))
233 { 233 {
234 $recordversion = new $thisObjectName(); 234 $recordversion = new $thisObjectName();
235 $recordversion->recordversionId = $row['recordversionid']; 235 $recordversion->recordversionId = $row['recordversionid'];
236 $recordversion->recordId = $row['recordid']; 236 $recordversion->recordId = $row['recordid'];
237 $recordversion->reference = $this->Unescape($row['reference']); 237 $recordversion->reference = $this->Unescape($row['reference']);
238 $recordversion->header = $this->Unescape($row['header']); 238 $recordversion->header = $this->Unescape($row['header']);
239 $recordversion->data = $this->Unescape($row['data']); 239 $recordversion->data = $this->Unescape($row['data']);
240 $recordversion->version = $this->Unescape($row['version']); 240 $recordversion->version = $this->Unescape($row['version']);
241 $recordversion->previous_version_key = $this->Unescape($row['previous_version_key']); 241 $recordversion->previous_version_key = $this->Unescape($row['previous_version_key']);
242 $recordversion->previous_version_id = $this->Unescape($row['previous_version_id']); 242 $recordversion->previous_version_id = $this->Unescape($row['previous_version_id']);
243 $recordversion->creation_date = $row['creation_date']; 243 $recordversion->creation_date = $row['creation_date'];
244 $recordversion->update_date = $row['update_date']; 244 $recordversion->update_date = $row['update_date'];
245 $recordversion->access_date = $row['access_date']; 245 $recordversion->access_date = $row['access_date'];
246 $recordversionList[] = $recordversion; 246 $recordversionList[] = $recordversion;
247 } 247 }
248 return $recordversionList; 248 return $recordversionList;
249 } 249 }
250 250
251 251
252 /** 252 /**
253 * Saves the object to the database 253 * Saves the object to the database
254 * @return integer $recordversionId 254 * @return integer $recordversionId
255 */ 255 */
256 function Save() 256 function Save()
257 { 257 {
258 $connection = Database::Connect(); 258 $connection = Database::Connect();
259 $this->update_date = date( 'Y-m-d H:i:s');
260 $this->access_date = date( 'Y-m-d H:i:s');
259 $this->pog_query = "select `recordversionid` from `recordversion` where `recordversionid`='".$this->recordversionId."' LIMIT 1"; 261 $this->pog_query = "select `recordversionid` from `recordversion` where `recordversionid`='".$this->recordversionId."' LIMIT 1";
260 $rows = Database::Query($this->pog_query, $connection); 262 $rows = Database::Query($this->pog_query, $connection);
261 if ($rows > 0) 263 if ($rows > 0)
262 { 264 {
263 $this->pog_query = "update `recordversion` set 265 $this->pog_query = "update `recordversion` set
264 `recordid`='".$this->recordId."', 266 `recordid`='".$this->recordId."',
265 `reference`='".$this->Escape($this->reference)."', 267 `reference`='".$this->Escape($this->reference)."',
266 `header`='".$this->Escape($this->header)."', 268 `header`='".$this->Escape($this->header)."',
267 `data`='".$this->Escape($this->data)."', 269 `data`='".$this->Escape($this->data)."',
268 `version`='".$this->Escape($this->version)."', 270 `version`='".$this->Escape($this->version)."',
269 `previous_version_key`='".$this->Escape($this->previous_version_key)."', 271 `previous_version_key`='".$this->Escape($this->previous_version_key)."',
270 `previous_version_id`='".$this->Escape($this->previous_version_id)."', 272 `previous_version_id`='".$this->Escape($this->previous_version_id)."',
271 `creation_date`='".$this->creation_date."', 273 `creation_date`='".$this->creation_date."',
272 `update_date`='".$this->update_date."', 274 `update_date`='".$this->update_date."',
273 `access_date`='".$this->access_date."' where `recordversionid`='".$this->recordversionId."'"; 275 `access_date`='".$this->access_date."' where `recordversionid`='".$this->recordversionId."'";
274 } 276 }
275 else 277 else
276 { 278 {
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 ( 279 $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."', 280 '".$this->recordId."',
279 '".$this->Escape($this->reference)."', 281 '".$this->Escape($this->reference)."',
280 '".$this->Escape($this->header)."', 282 '".$this->Escape($this->header)."',
281 '".$this->Escape($this->data)."', 283 '".$this->Escape($this->data)."',
282 '".$this->Escape($this->version)."', 284 '".$this->Escape($this->version)."',
283 '".$this->Escape($this->previous_version_key)."', 285 '".$this->Escape($this->previous_version_key)."',
284 '".$this->Escape($this->previous_version_id)."', 286 '".$this->Escape($this->previous_version_id)."',
285 '".$this->creation_date."', 287 '".$this->creation_date."',
286 '".$this->update_date."', 288 '".$this->update_date."',
287 '".$this->access_date."' )"; 289 '".$this->access_date."' )";
288 } 290 }
289 $insertId = Database::InsertOrUpdate($this->pog_query, $connection); 291 $insertId = Database::InsertOrUpdate($this->pog_query, $connection);
290 if ($this->recordversionId == "") 292 if ($this->recordversionId == "")
291 { 293 {
292 $this->recordversionId = $insertId; 294 $this->recordversionId = $insertId;
293 } 295 }
294 return $this->recordversionId; 296 return $this->recordversionId;
295 } 297 }
296 298
297 299
298 /** 300 /**
299 * Clones the object and saves it to the database 301 * Clones the object and saves it to the database
300 * @return integer $recordversionId 302 * @return integer $recordversionId
301 */ 303 */
302 function SaveNew() 304 function SaveNew()
303 { 305 {
304 $this->recordversionId = ''; 306 $this->recordversionId = '';
305 return $this->Save(); 307 return $this->Save();
306 } 308 }
@@ -333,49 +335,49 @@ class recordversion extends POG_Base
333 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) 335 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
334 { 336 {
335 if (sizeof($fcv_array[$i]) == 1) 337 if (sizeof($fcv_array[$i]) == 1)
336 { 338 {
337 $pog_query .= " ".$fcv_array[$i][0]." "; 339 $pog_query .= " ".$fcv_array[$i][0]." ";
338 continue; 340 continue;
339 } 341 }
340 else 342 else
341 { 343 {
342 if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1) 344 if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
343 { 345 {
344 $pog_query .= " AND "; 346 $pog_query .= " AND ";
345 } 347 }
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') 348 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 { 349 {
348 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'"; 350 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
349 } 351 }
350 else 352 else
351 { 353 {
352 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'"; 354 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
353 } 355 }
354 } 356 }
355 } 357 }
356 return Database::NonQuery($pog_query, $connection); 358 return Database::NonQuery($pog_query, $connection);
357 } 359 }
358 } 360 }
359 361
360 362
361 /** 363 /**
362 * Associates the record object to this one 364 * Associates the record object to this one
363 * @return boolean 365 * @return boolean
364 */ 366 */
365 function GetRecord() 367 function GetRecord()
366 { 368 {
367 $record = new record(); 369 $record = new record();
368 return $record->Get($this->recordId); 370 return $record->Get($this->recordId);
369 } 371 }
370 372
371 373
372 /** 374 /**
373 * Associates the record object to this one 375 * Associates the record object to this one
374 * @return 376 * @return
375 */ 377 */
376 function SetRecord(&$record) 378 function SetRecord(&$record)
377 { 379 {
378 $this->recordId = $record->recordId; 380 $this->recordId = $record->recordId;
379 } 381 }
380} 382}
381?> \ No newline at end of file 383?>