summaryrefslogtreecommitdiff
authorJosh <jokajak@gmail.com>2011-10-05 20:40:29 (UTC)
committer Josh <jokajak@gmail.com>2011-10-06 01:58:00 (UTC)
commita26b219b6f4f3fee727d9b23d8cd374f6b32a4fa (patch) (unidiff)
tree3ca0b96e843f5820f0bee7dede1847b014bba1e6
parent6ba274c79e60e417132b260bd0117c5a68121387 (diff)
downloadclipperz-a26b219b6f4f3fee727d9b23d8cd374f6b32a4fa.zip
clipperz-a26b219b6f4f3fee727d9b23d8cd374f6b32a4fa.tar.gz
clipperz-a26b219b6f4f3fee727d9b23d8cd374f6b32a4fa.tar.bz2
Fix timestamps on records
- update the access and update date when a record is saved - set the creation date when a record is created
Diffstat (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
@@ -1,747 +1,754 @@
1<?php 1<?php
2 include "./configuration.php"; 2 include "./configuration.php";
3 include "./objects/class.database.php"; 3 include "./objects/class.database.php";
4 include "./objects/class.user.php"; 4 include "./objects/class.user.php";
5 include "./objects/class.record.php"; 5 include "./objects/class.record.php";
6 include "./objects/class.recordversion.php"; 6 include "./objects/class.recordversion.php";
7 include "./objects/class.onetimepassword.php"; 7 include "./objects/class.onetimepassword.php";
8 include "./objects/class.onetimepasswordstatus.php"; 8 include "./objects/class.onetimepasswordstatus.php";
9 9
10//----------------------------------------------------------------------------- 10//-----------------------------------------------------------------------------
11 11
12if ( !function_exists('json_decode') ) { 12if ( !function_exists('json_decode') ) {
13 function json_decode($content, $assoc=false) { 13 function json_decode($content, $assoc=false) {
14 require_once 'json/JSON.php'; 14 require_once 'json/JSON.php';
15 if ( $assoc ) { 15 if ( $assoc ) {
16 $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); 16 $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
17 } else { 17 } else {
18 $json = new Services_JSON; 18 $json = new Services_JSON;
19 } 19 }
20 20
21 return $json->decode($content); 21 return $json->decode($content);
22 } 22 }
23} 23}
24 24
25if ( !function_exists('json_encode') ) { 25if ( !function_exists('json_encode') ) {
26 function json_encode($content) { 26 function json_encode($content) {
27 require_once 'json/JSON.php'; 27 require_once 'json/JSON.php';
28 $json = new Services_JSON; 28 $json = new Services_JSON;
29 29
30 return $json->encode($content); 30 return $json->encode($content);
31 } 31 }
32} 32}
33 33
34//----------------------------------------------------------------------------- 34//-----------------------------------------------------------------------------
35 //'dec2base', 'base2dec' and 'digits' are functions found on the following 35 //'dec2base', 'base2dec' and 'digits' are functions found on the following
36 //PHP manual page: http://ch2.php.net/manual/en/ref.bc.php 36 //PHP manual page: http://ch2.php.net/manual/en/ref.bc.php
37// 37//
38 38
39function dec2base($dec, $base, $digits=FALSE) { 39function dec2base($dec, $base, $digits=FALSE) {
40 if ($base<2 or $base>256) { 40 if ($base<2 or $base>256) {
41 die("Invalid Base: ".$base); 41 die("Invalid Base: ".$base);
42 } 42 }
43 43
44 bcscale(0); 44 bcscale(0);
45 $value=""; 45 $value="";
46 if (!$digits) { 46 if (!$digits) {
47 $digits = digits($base); 47 $digits = digits($base);
48 } 48 }
49 49
50 while ($dec > $base-1) { 50 while ($dec > $base-1) {
51 $rest = bcmod($dec, $base); 51 $rest = bcmod($dec, $base);
52 $dec = bcdiv($dec, $base); 52 $dec = bcdiv($dec, $base);
53 $value = $digits[$rest].$value; 53 $value = $digits[$rest].$value;
54 } 54 }
55 55
56 $value=$digits[intval($dec)].$value; 56 $value=$digits[intval($dec)].$value;
57 57
58 return (string)$value; 58 return (string)$value;
59} 59}
60 60
61//............................................................................. 61//.............................................................................
62 62
63// convert another base value to its decimal value 63// convert another base value to its decimal value
64function base2dec($value, $base, $digits=FALSE) { 64function base2dec($value, $base, $digits=FALSE) {
65 if ($base<2 or $base>256) { 65 if ($base<2 or $base>256) {
66 die("Invalid Base: ".$base); 66 die("Invalid Base: ".$base);
67 } 67 }
68 68
69 bcscale(0); 69 bcscale(0);
70 if ($base<37) { 70 if ($base<37) {
71 $value=strtolower($value); 71 $value=strtolower($value);
72 } 72 }
73 73
74 if (!$digits) { 74 if (!$digits) {
75 $digits=digits($base); 75 $digits=digits($base);
76 } 76 }
77 77
78 $size = strlen($value); 78 $size = strlen($value);
79 $dec="0"; 79 $dec="0";
80 for ($loop=0; $loop<$size; $loop++) { 80 for ($loop=0; $loop<$size; $loop++) {
81 $element = strpos($digits, $value[$loop]); 81 $element = strpos($digits, $value[$loop]);
82 $power = bcpow($base, $size-$loop-1); 82 $power = bcpow($base, $size-$loop-1);
83 $dec = bcadd($dec, bcmul($element,$power)); 83 $dec = bcadd($dec, bcmul($element,$power));
84 } 84 }
85 85
86 return (string)$dec; 86 return (string)$dec;
87} 87}
88 88
89//............................................................................. 89//.............................................................................
90 90
91function digits($base) { 91function digits($base) {
92 if ($base>64) { 92 if ($base>64) {
93 $digits=""; 93 $digits="";
94 for ($loop=0; $loop<256; $loop++) { 94 for ($loop=0; $loop<256; $loop++) {
95 $digits.=chr($loop); 95 $digits.=chr($loop);
96 } 96 }
97 } else { 97 } else {
98 $digits ="0123456789abcdefghijklmnopqrstuvwxyz"; 98 $digits ="0123456789abcdefghijklmnopqrstuvwxyz";
99 $digits.="ABCDEFGHIJKLMNOPQRSTUVWXYZ-_"; 99 $digits.="ABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
100 } 100 }
101 101
102 $digits=substr($digits,0,$base); 102 $digits=substr($digits,0,$base);
103 103
104 return (string)$digits; 104 return (string)$digits;
105} 105}
106 106
107//----------------------------------------------------------------------------- 107//-----------------------------------------------------------------------------
108 108
109function clipperz_hash($value) { 109function clipperz_hash($value) {
110 return hash("sha256", hash("sha256", $value, true)); 110 return hash("sha256", hash("sha256", $value, true));
111} 111}
112 112
113//----------------------------------------------------------------------------- 113//-----------------------------------------------------------------------------
114 114
115function clipperz_randomSeed() { 115function clipperz_randomSeed() {
116 $result; 116 $result;
117 117
118 srand((double) microtime()*1000000); 118 srand((double) microtime()*1000000);
119 $result = ""; 119 $result = "";
120 120
121 while(strlen($result) < 64) { 121 while(strlen($result) < 64) {
122 $result = $result.dec2base(rand(), 16); 122 $result = $result.dec2base(rand(), 16);
123 } 123 }
124 124
125 $result = substr($result, 0, 64); 125 $result = substr($result, 0, 64);
126 126
127 return $result; 127 return $result;
128} 128}
129 129
130//----------------------------------------------------------------------------- 130//-----------------------------------------------------------------------------
131 131
132function updateUserCredentials($parameters, &$user) { 132function updateUserCredentials($parameters, &$user) {
133 $user->username = $parameters["C"]; 133 $user->username = $parameters["C"];
134 $user->srp_s = $parameters["s"]; 134 $user->srp_s = $parameters["s"];
135 $user->srp_v = $parameters["v"]; 135 $user->srp_v = $parameters["v"];
136 $user->auth_version =$parameters["version"]; 136 $user->auth_version =$parameters["version"];
137} 137}
138 138
139function updateUserData($parameters, &$user) { 139function updateUserData($parameters, &$user) {
140 $user->header = $parameters["header"]; 140 $user->header = $parameters["header"];
141 $user->statistics =$parameters["statistics"]; 141 $user->statistics =$parameters["statistics"];
142 $user->version =$parameters["version"]; 142 $user->version =$parameters["version"];
143 $user->lock = $parameters["lock"]; 143 $user->lock = $parameters["lock"];
144} 144}
145 145
146function updateRecordData($parameters, &$record, &$recordVersion) { 146function updateRecordData($parameters, &$record, &$recordVersion) {
147 $recordData = $parameters["record"]; 147 $recordData = $parameters["record"];
148 $record->reference =$recordData["reference"]; 148 $record->reference =$recordData["reference"];
149 $record->data = $recordData["data"]; 149 $record->data = $recordData["data"];
150 $record->version = $recordData["version"]; 150 $record->version = $recordData["version"];
151 151
152 $recordVersionData = $parameters["currentRecordVersion"]; 152 $recordVersionData = $parameters["currentRecordVersion"];
153 $recordVersion->reference = $recordVersionData ["reference"]; 153 $recordVersion->reference = $recordVersionData ["reference"];
154 $recordVersion->data = $recordVersionData ["data"]; 154 $recordVersion->data = $recordVersionData ["data"];
155 $recordVersion->version = $recordVersionData ["version"]; 155 $recordVersion->version = $recordVersionData ["version"];
156 $recordVersion->previous_version_id =$recordVersionData ["previousVersion"]; 156 $recordVersion->previous_version_id =$recordVersionData ["previousVersion"];
157 $recordVersion->previous_version_key =$recordVersionData ["previousVersionKey"]; 157 $recordVersion->previous_version_key =$recordVersionData ["previousVersionKey"];
158} 158}
159 159
160//----------------------------------------------------------------------------- 160//-----------------------------------------------------------------------------
161 161
162function updateOTPStatus(&$otp, $status) { 162function updateOTPStatus(&$otp, $status) {
163 $otpStatus = new onetimepasswordstatus(); 163 $otpStatus = new onetimepasswordstatus();
164 $selectedStatuses = $otpStatus->GetList(array(array("code", "=", $status))); 164 $selectedStatuses = $otpStatus->GetList(array(array("code", "=", $status)));
165 $otpStatus = $selectedStatuses[0]; 165 $otpStatus = $selectedStatuses[0];
166 $otp->SetOnetimepasswordstatus($otpStatus); 166 $otp->SetOnetimepasswordstatus($otpStatus);
167} 167}
168 168
169function updateOTP($parameters, &$otp, $status) { 169function updateOTP($parameters, &$otp, $status) {
170 $otp->reference = $parameters["reference"]; 170 $otp->reference = $parameters["reference"];
171 $otp->key = $parameters["key"]; 171 $otp->key = $parameters["key"];
172 $otp->key_checksum= $parameters["keyChecksum"]; 172 $otp->key_checksum= $parameters["keyChecksum"];
173 $otp->data = $parameters["data"]; 173 $otp->data = $parameters["data"];
174 $otp->version = $parameters["version"]; 174 $otp->version = $parameters["version"];
175 175
176 updateOTPStatus($otp, $status); 176 updateOTPStatus($otp, $status);
177} 177}
178 178
179function resetOTP(&$otp, $status) { 179function resetOTP(&$otp, $status) {
180 $otp->data = ""; 180 $otp->data = "";
181 updateOTPStatus($otp, $status); 181 updateOTPStatus($otp, $status);
182 $otp->Save(); 182 $otp->Save();
183} 183}
184 184
185//----------------------------------------------------------------------------- 185//-----------------------------------------------------------------------------
186 186
187function fixOTPStatusTable() { 187function fixOTPStatusTable() {
188 $otpStatus = new onetimepasswordstatus(); 188 $otpStatus = new onetimepasswordstatus();
189 $otpStatusList = $otpStatus->GetList(); 189 $otpStatusList = $otpStatus->GetList();
190 if (count($otpStatusList) != 4) { 190 if (count($otpStatusList) != 4) {
191 $otpStatus->DeleteList(); 191 $otpStatus->DeleteList();
192 192
193 $otpStatus->code = "ACTIVE"; $otpStatus->name = "Active"; $otpStatus->description = "Active"; $otpStatus->SaveNew(); 193 $otpStatus->code = "ACTIVE"; $otpStatus->name = "Active"; $otpStatus->description = "Active"; $otpStatus->SaveNew();
194 $otpStatus->code = "REQUESTED"; $otpStatus->name = "Requested"; $otpStatus->description = "Requested";$otpStatus->SaveNew(); 194 $otpStatus->code = "REQUESTED"; $otpStatus->name = "Requested"; $otpStatus->description = "Requested";$otpStatus->SaveNew();
195 $otpStatus->code = "USED"; $otpStatus->name = "Used"; $otpStatus->description = "Used"; $otpStatus->SaveNew(); 195 $otpStatus->code = "USED"; $otpStatus->name = "Used"; $otpStatus->description = "Used"; $otpStatus->SaveNew();
196 $otpStatus->code = "DISABLED"; $otpStatus->name = "Disabled"; $otpStatus->description = "Disabled";$otpStatus->SaveNew(); 196 $otpStatus->code = "DISABLED"; $otpStatus->name = "Disabled"; $otpStatus->description = "Disabled";$otpStatus->SaveNew();
197 } 197 }
198} 198}
199 199
200//----------------------------------------------------------------------------- 200//-----------------------------------------------------------------------------
201 201
202function arrayContainsValue($array, $value) { 202function arrayContainsValue($array, $value) {
203 $object = NULL; 203 $object = NULL;
204 for ($i=0; $i<count($array); $i++) { 204 for ($i=0; $i<count($array); $i++) {
205 if ($array[$i] == $value) { 205 if ($array[$i] == $value) {
206 $object = $value; 206 $object = $value;
207 } 207 }
208 } 208 }
209 209
210 return !is_null($object); 210 return !is_null($object);
211} 211}
212 212
213//----------------------------------------------------------------------------- 213//-----------------------------------------------------------------------------
214 214
215 $result = Array(); 215 $result = Array();
216 216
217 session_start(); 217 session_start();
218 218
219 $method = $_POST['method']; 219 $method = $_POST['method'];
220 220
221 if (get_magic_quotes_gpc()) { 221 if (get_magic_quotes_gpc()) {
222 $parameters = json_decode(stripslashes($_POST['parameters']), true); 222 $parameters = json_decode(stripslashes($_POST['parameters']), true);
223 } else { 223 } else {
224 $parameters = json_decode($_POST['parameters'], true); 224 $parameters = json_decode($_POST['parameters'], true);
225 } 225 }
226 226
227 $parameters = $parameters["parameters"]; 227 $parameters = $parameters["parameters"];
228 228
229 switch($method) { 229 switch($method) {
230 case "registration": 230 case "registration":
231error_log("registration"); 231error_log("registration");
232 $message = $parameters["message"]; 232 $message = $parameters["message"];
233 233
234 if ($message == "completeRegistration") { 234 if ($message == "completeRegistration") {
235 $user = new user(); 235 $user = new user();
236 236
237 updateUserCredentials($parameters["credentials"], $user); 237 updateUserCredentials($parameters["credentials"], $user);
238 updateUserData($parameters["user"], $user); 238 updateUserData($parameters["user"], $user);
239 $user->Save(); 239 $user->Save();
240 240
241 $result["lock"] = $user->lock; 241 $result["lock"] = $user->lock;
242 $result["result"] = "done"; 242 $result["result"] = "done";
243 } 243 }
244 break; 244 break;
245 245
246 case "handshake": 246 case "handshake":
247error_log("handshake"); 247error_log("handshake");
248 $srp_g = "2"; 248 $srp_g = "2";
249 $srp_n = base2dec("115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3", 16); 249 $srp_n = base2dec("115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3", 16);
250 250
251 $message = $parameters["message"]; 251 $message = $parameters["message"];
252 252
253 //============================================================= 253 //=============================================================
254 if ($message == "connect") { 254 if ($message == "connect") {
255 $user= new user(); 255 $user= new user();
256 $_SESSION["C"] = $parameters["parameters"]["C"]; 256 $_SESSION["C"] = $parameters["parameters"]["C"];
257 $_SESSION["A"] = $parameters["parameters"]["A"]; 257 $_SESSION["A"] = $parameters["parameters"]["A"];
258 258
259 $userList = $user->GetList(array(array("username", "=", $_SESSION["C"]))); 259 $userList = $user->GetList(array(array("username", "=", $_SESSION["C"])));
260 260
261 if (count($userList) == 1) { 261 if (count($userList) == 1) {
262 $currentUser = $userList[ 0 ]; 262 $currentUser = $userList[ 0 ];
263 263
264 if (array_key_exists("otpId", $_SESSION)) { 264 if (array_key_exists("otpId", $_SESSION)) {
265 $otp = new onetimepassword(); 265 $otp = new onetimepassword();
266 $otp = $otp->Get($_SESSION["otpId"]); 266 $otp = $otp->Get($_SESSION["otpId"]);
267 267
268 if ($otp->GetUser()->userId != $currentUser->userId) { 268 if ($otp->GetUser()->userId != $currentUser->userId) {
269 throw new Exception("User missmatch between the current session and 'One Time Password' user"); 269 throw new Exception("User missmatch between the current session and 'One Time Password' user");
270 } else if ($otp->GetOnetimepasswordstatus()->code != "REQUESTED") { 270 } else if ($otp->GetOnetimepasswordstatus()->code != "REQUESTED") {
271 throw new Exception("Tring to use an 'One Time Password' in the wrong state"); 271 throw new Exception("Tring to use an 'One Time Password' in the wrong state");
272 } 272 }
273 273
274 resetOTP($otp, "USED"); 274 resetOTP($otp, "USED");
275 $result["oneTimePassword"] = $otp->reference; 275 $result["oneTimePassword"] = $otp->reference;
276 } 276 }
277 277
278 $_SESSION["s"] = $currentUser->srp_s; 278 $_SESSION["s"] = $currentUser->srp_s;
279 $_SESSION["v"] = $currentUser->srp_v; 279 $_SESSION["v"] = $currentUser->srp_v;
280 $_SESSION["userId"] = $currentUser->userId; 280 $_SESSION["userId"] = $currentUser->userId;
281 } else { 281 } else {
282 $_SESSION["s"] = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"; 282 $_SESSION["s"] = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00";
283 $_SESSION["v"] = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"; 283 $_SESSION["v"] = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00";
284 } 284 }
285 285
286 $_SESSION["b"] = clipperz_randomSeed(); 286 $_SESSION["b"] = clipperz_randomSeed();
287 // $_SESSION["b"] = "5761e6c84d22ea3c5649de01702d60f674ccfe79238540eb34c61cd020230c53"; 287 // $_SESSION["b"] = "5761e6c84d22ea3c5649de01702d60f674ccfe79238540eb34c61cd020230c53";
288 $_SESSION["B"] = dec2base(bcadd(base2dec($_SESSION["v"], 16), bcpowmod($srp_g, base2dec($_SESSION["b"], 16), $srp_n)), 16); 288 $_SESSION["B"] = dec2base(bcadd(base2dec($_SESSION["v"], 16), bcpowmod($srp_g, base2dec($_SESSION["b"], 16), $srp_n)), 16);
289 289
290 $result["s"] = $_SESSION["s"]; 290 $result["s"] = $_SESSION["s"];
291 $result["B"] = $_SESSION["B"]; 291 $result["B"] = $_SESSION["B"];
292 292
293 //============================================================= 293 //=============================================================
294 } else if ($message == "credentialCheck") { 294 } else if ($message == "credentialCheck") {
295error_log("credentialCheck"); 295error_log("credentialCheck");
296 $u = clipperz_hash(base2dec($_SESSION["B"],16)); 296 $u = clipperz_hash(base2dec($_SESSION["B"],16));
297 $A = base2dec($_SESSION["A"], 16); 297 $A = base2dec($_SESSION["A"], 16);
298 $S = bcpowmod(bcmul($A, bcpowmod(base2dec($_SESSION["v"], 16), base2dec($u, 16), $srp_n)), base2dec($_SESSION["b"], 16), $srp_n); 298 $S = bcpowmod(bcmul($A, bcpowmod(base2dec($_SESSION["v"], 16), base2dec($u, 16), $srp_n)), base2dec($_SESSION["b"], 16), $srp_n);
299 $K = clipperz_hash($S); 299 $K = clipperz_hash($S);
300 $M1 = clipperz_hash($A.base2dec($_SESSION["B"],16).$K); 300 $M1 = clipperz_hash($A.base2dec($_SESSION["B"],16).$K);
301 301
302//$result["B"] = $_SESSION["B"]; 302//$result["B"] = $_SESSION["B"];
303//$result["u"] = $u; 303//$result["u"] = $u;
304//$result["A"] = $A; 304//$result["A"] = $A;
305//$result["S"] = $S; 305//$result["S"] = $S;
306//$result["K"] = $K; 306//$result["K"] = $K;
307//$result["M1"] = $M1; 307//$result["M1"] = $M1;
308//$result["_M1"] = $parameters["parameters"]["M1"]; 308//$result["_M1"] = $parameters["parameters"]["M1"];
309 309
310 if ($M1 == $parameters["parameters"]["M1"]) { 310 if ($M1 == $parameters["parameters"]["M1"]) {
311 $_SESSION["K"] = $K; 311 $_SESSION["K"] = $K;
312 $M2 = clipperz_hash($A.$M1.$K); 312 $M2 = clipperz_hash($A.$M1.$K);
313 313
314 $result["M2"] = $M2; 314 $result["M2"] = $M2;
315 $result["connectionId"] = ""; 315 $result["connectionId"] = "";
316 $result["loginInfo"] = array(); 316 $result["loginInfo"] = array();
317 $result["loginInfo"]["latest"] = array(); 317 $result["loginInfo"]["latest"] = array();
318 $result["loginInfo"]["current"] = array(); 318 $result["loginInfo"]["current"] = array();
319 $result["offlineCopyNeeded"] = "false"; 319 $result["offlineCopyNeeded"] = "false";
320 $result["lock"] = "----"; 320 $result["lock"] = "----";
321 } else { 321 } else {
322 $result["error"] = "?"; 322 $result["error"] = "?";
323 } 323 }
324 //============================================================= 324 //=============================================================
325 } else if ($message == "oneTimePassword") { 325 } else if ($message == "oneTimePassword") {
326error_log("oneTimePassword"); 326error_log("oneTimePassword");
327//{ 327//{
328 //"message":"oneTimePassword", 328 //"message":"oneTimePassword",
329 //"version":"0.2", 329 //"version":"0.2",
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
426 $record->SaveNew(); 433 $record->SaveNew();
427 $recordVersion->SaveNew(); 434 $recordVersion->SaveNew();
428 435
429 $record->AddRecordversion($recordVersion); 436 $record->AddRecordversion($recordVersion);
430 $user->AddRecord($record); 437 $user->AddRecord($record);
431 438
432 $record->Save(); 439 $record->Save();
433 $recordVersion->Save(); 440 $recordVersion->Save();
434 } 441 }
435 442
436 $user->Save(); 443 $user->Save();
437 444
438 $result["lock"] = $user->lock; 445 $result["lock"] = $user->lock;
439 $result["result"] = "done"; 446 $result["result"] = "done";
440 447
441 //============================================================= 448 //=============================================================
442 } else if ($message == "getRecordDetail") { 449 } else if ($message == "getRecordDetail") {
443//{ 450//{
444 //"message":"getRecordDetail", 451 //"message":"getRecordDetail",
445 //"srpSharedSecret":"4c00dcb66a9f2aea41a87e4707c526874e2eb29cc72d2c7086837e53d6bf2dfe", 452 //"srpSharedSecret":"4c00dcb66a9f2aea41a87e4707c526874e2eb29cc72d2c7086837e53d6bf2dfe",
446 //"parameters":{ 453 //"parameters":{
447 // "reference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50" 454 // "reference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50"
448 //} 455 //}
449//} 456//}
450// 457//
451 //result = { 458 //result = {
452 // currentVersion:{ 459 // currentVersion:{
453 // reference:"88943d709c3ea2442d4f58eaaec6409276037e5a37e0a6d167b9dad9e947e854", 460 // reference:"88943d709c3ea2442d4f58eaaec6409276037e5a37e0a6d167b9dad9e947e854",
454 // accessDate:"Wed, 13 February 2008 14:25:12 UTC", 461 // accessDate:"Wed, 13 February 2008 14:25:12 UTC",
455 // creationDate:"Tue, 17 April 2007 17:17:52 UTC", 462 // creationDate:"Tue, 17 April 2007 17:17:52 UTC",
456 // version:"0.2", 463 // version:"0.2",
457 // data:"xI3WXddQLFtL......EGyKnnAVik", 464 // data:"xI3WXddQLFtL......EGyKnnAVik",
458 // updateDate:"Tue, 17 April 2007 17:17:52 UTC", 465 // updateDate:"Tue, 17 April 2007 17:17:52 UTC",
459 // header:"####" 466 // header:"####"
460 // } 467 // }
461 // reference:"13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551", 468 // reference:"13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551",
462 // oldestUsedEncryptedVersion:"0.2", 469 // oldestUsedEncryptedVersion:"0.2",
463 // accessDate:"Wed, 13 February 2008 14:25:12 UTC", 470 // accessDate:"Wed, 13 February 2008 14:25:12 UTC",
464 // creationDate:"Wed, 14 March 2007 13:53:11 UTC", 471 // creationDate:"Wed, 14 March 2007 13:53:11 UTC",
465 // version:"0.2", 472 // version:"0.2",
466 // updatedDate:"Tue, 17 April 2007 17:17:52 UTC", 473 // updatedDate:"Tue, 17 April 2007 17:17:52 UTC",
467 // data:"0/BjzyY6jeh71h...pAw2++NEyylGhMC5C5f5m8pBApYziN84s4O3JQ3khW/1UttQl4=" 474 // data:"0/BjzyY6jeh71h...pAw2++NEyylGhMC5C5f5m8pBApYziN84s4O3JQ3khW/1UttQl4="
468 //} 475 //}
469 $record = new record(); 476 $record = new record();
470 477
471 $recordList = $record->GetList(array(array("reference", "=", $parameters["parameters"]["reference"]))); 478 $recordList = $record->GetList(array(array("reference", "=", $parameters["parameters"]["reference"])));
472 $currentRecord = $recordList[0]; 479 $currentRecord = $recordList[0];
473 $currentRecordVersions = $currentRecord->GetRecordversionList(); 480 $currentRecordVersions = $currentRecord->GetRecordversionList();
474 $currentVersion = $currentRecordVersions[0]; 481 $currentVersion = $currentRecordVersions[0];
475 482
476 $result["currentVersion"] = array(); 483 $result["currentVersion"] = array();
477 $result["currentVersion"]["reference"] =$currentVersion->reference; 484 $result["currentVersion"]["reference"] =$currentVersion->reference;
478 $result["currentVersion"]["data"] = $currentVersion->data; 485 $result["currentVersion"]["data"] = $currentVersion->data;
479 $result["currentVersion"]["header"] = $currentVersion->header; 486 $result["currentVersion"]["header"] = $currentVersion->header;
480 $result["currentVersion"]["version"] = $currentVersion->version; 487 $result["currentVersion"]["version"] = $currentVersion->version;
481 $result["currentVersion"]["creationDate"] =$currentVersion->creation_date; 488 $result["currentVersion"]["creationDate"] =$currentVersion->creation_date;
482 $result["currentVersion"]["updateDate"] =$currentVersion->update_date; 489 $result["currentVersion"]["updateDate"] =$currentVersion->update_date;
483 $result["currentVersion"]["accessDate"] =$currentVersion->access_date; 490 $result["currentVersion"]["accessDate"] =$currentVersion->access_date;
484 491
485 $result["reference"] = $currentRecord->reference; 492 $result["reference"] = $currentRecord->reference;
486 $result["data"] = $currentRecord->data; 493 $result["data"] = $currentRecord->data;
487 $result["version"] = $currentRecord->version; 494 $result["version"] = $currentRecord->version;
488 $result["creationDate"] =$currentRecord->creation_date; 495 $result["creationDate"] =$currentRecord->creation_date;
489 $result["updateDate"] = $currentRecord->update_date; 496 $result["updateDate"] = $currentRecord->update_date;
490 $result["accessDate"] = $currentRecord->access_date; 497 $result["accessDate"] = $currentRecord->access_date;
491 $result["oldestUsedEncryptedVersion"] ="---"; 498 $result["oldestUsedEncryptedVersion"] ="---";
492 499
493 //============================================================= 500 //=============================================================
494 } else if ($message == "updateData") { 501 } else if ($message == "updateData") {
495//{ 502//{
496 //"message":"updateData", 503 //"message":"updateData",
497 //"srpSharedSecret":"4e4aadb1d64513ec4dd42f5e8d5b2d4363de75e4424b6bcf178c9d6a246356c5", 504 //"srpSharedSecret":"4e4aadb1d64513ec4dd42f5e8d5b2d4363de75e4424b6bcf178c9d6a246356c5",
498 //"parameters":{ 505 //"parameters":{
499 // "records":[ 506 // "records":[
500 // { 507 // {
501 // "record":{ 508 // "record":{
502 // "reference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50", 509 // "reference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50",
503 // "data":"8hgR0Z+JDrUa812polDJ....JnZUKXNEqKI", 510 // "data":"8hgR0Z+JDrUa812polDJ....JnZUKXNEqKI",
504 // "version":"0.3" 511 // "version":"0.3"
505 // }, 512 // },
506 // "currentRecordVersion":{ 513 // "currentRecordVersion":{
507 // "reference":"b1d82aeb9a0c4f6584bea68ba80839f43dd6ede79791549e29a1860554b144ee", 514 // "reference":"b1d82aeb9a0c4f6584bea68ba80839f43dd6ede79791549e29a1860554b144ee",
508 // "recordReference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50", 515 // "recordReference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50",
509 // "data":"2d/UgKxxV+kBPV9GRUE.....VGonDoW0tqefxOJo=", 516 // "data":"2d/UgKxxV+kBPV9GRUE.....VGonDoW0tqefxOJo=",
510 // "version":"0.3", 517 // "version":"0.3",
511 // "previousVersion":"55904195249037394316d3be3f5e78f08073170103bf0e7ab49a911c159cb0be", 518 // "previousVersion":"55904195249037394316d3be3f5e78f08073170103bf0e7ab49a911c159cb0be",
512 // "previousVersionKey":"YWiaZeMIVHaIl96OWW+2e8....6d6nHbn6cr2NA/dbQRuC2w==" 519 // "previousVersionKey":"YWiaZeMIVHaIl96OWW+2e8....6d6nHbn6cr2NA/dbQRuC2w=="
513 // } 520 // }
514 // } 521 // }
515 // ], 522 // ],
516 // "user":{ 523 // "user":{
517 // "header":"{\"rec.....sion\":\"0.1\"}", 524 // "header":"{\"rec.....sion\":\"0.1\"}",
518 // "statistics":"tt3uU9hWBy8rNnMckgCnxMJh", 525 // "statistics":"tt3uU9hWBy8rNnMckgCnxMJh",
519 // "version":"0.3", 526 // "version":"0.3",
520 // "lock":"----" 527 // "lock":"----"
521 // } 528 // }
522 //} 529 //}
523//} 530//}
524 531
525 $user = new user(); 532 $user = new user();
526 $user = $user->Get($_SESSION["userId"]); 533 $user = $user->Get($_SESSION["userId"]);
527 updateUserData($parameters["parameters"]["user"], $user); 534 updateUserData($parameters["parameters"]["user"], $user);
528 $user->Save(); 535 $user->Save();
529 536
530 $recordParameterList = $parameters["parameters"]["records"]; 537 $recordParameterList = $parameters["parameters"]["records"];
531 $c = count($recordParameterList); 538 $c = count($recordParameterList);
532 for ($i=0; $i<$c; $i++) { 539 for ($i=0; $i<$c; $i++) {
533 $recordList = $user->GetRecordList(array(array("reference", "=", $recordParameterList[$i]["record"]["reference"]))); 540 $recordList = $user->GetRecordList(array(array("reference", "=", $recordParameterList[$i]["record"]["reference"])));
534 $currentRecord = $recordList[0]; 541 $currentRecord = $recordList[0];
535 $currentRecordVersions = $currentRecord->GetRecordversionList(); 542 $currentRecordVersions = $currentRecord->GetRecordversionList();
536 $currentVersion = $currentRecordVersions[0]; 543 $currentVersion = $currentRecordVersions[0];
537 544
538 updateRecordData($recordParameterList[$i], $currentRecord, $currentVersion); 545 updateRecordData($recordParameterList[$i], $currentRecord, $currentVersion);
539 546
540 547
541 $currentRecord->Save(); 548 $currentRecord->Save();
542 $currentVersion->Save(); 549 $currentVersion->Save();
543 } 550 }
544 551
545 552
546 $result["lock"] = $user->lock; 553 $result["lock"] = $user->lock;
547 $result["result"] = "done"; 554 $result["result"] = "done";
548 555
549 //============================================================= 556 //=============================================================
550 } else if ($message == "deleteRecords") { 557 } else if ($message == "deleteRecords") {
551//{ 558//{
552 //"message":"deleteRecords", 559 //"message":"deleteRecords",
553 //"srpSharedSecret":"4a64982f7ee366954ec50b9efea62a902a097ef111410c2aa7c4d5343bd1cdd1", 560 //"srpSharedSecret":"4a64982f7ee366954ec50b9efea62a902a097ef111410c2aa7c4d5343bd1cdd1",
554 //"parameters":{ 561 //"parameters":{
555 // "recordReferences":["46494c81d10b80ab190d41e6806ef63869cfcc7a0ab8fe98cc3f93de4729bb9a"], 562 // "recordReferences":["46494c81d10b80ab190d41e6806ef63869cfcc7a0ab8fe98cc3f93de4729bb9a"],
556 // "user":{ 563 // "user":{
557 // "header":"{\"rec...rsion\":\"0.1\"}", 564 // "header":"{\"rec...rsion\":\"0.1\"}",
558 // "statistics":"44kOOda0xYZjbcugJBdagBQx", 565 // "statistics":"44kOOda0xYZjbcugJBdagBQx",
559 // "version":"0.3", 566 // "version":"0.3",
560 // "lock":"----" 567 // "lock":"----"
561 // } 568 // }
562 //} 569 //}
563//} 570//}
564 $user = new user(); 571 $user = new user();
565 $user = $user->Get($_SESSION["userId"]); 572 $user = $user->Get($_SESSION["userId"]);
566 573
567 $recordReferenceList = $parameters["parameters"]["recordReferences"]; 574 $recordReferenceList = $parameters["parameters"]["recordReferences"];
568 $recordList = array(); 575 $recordList = array();
569 $c = count($recordReferenceList); 576 $c = count($recordReferenceList);
570 for ($i=0; $i<$c; $i++) { 577 for ($i=0; $i<$c; $i++) {
571 array_push($recordList, array("reference", "=", $recordReferenceList[$i])); 578 array_push($recordList, array("reference", "=", $recordReferenceList[$i]));
572 } 579 }
573 580
574 $record = new record(); 581 $record = new record();
575 $record->DeleteList($recordList, true); 582 $record->DeleteList($recordList, true);
576 583
577 updateUserData($parameters["parameters"]["user"], $user); 584 updateUserData($parameters["parameters"]["user"], $user);
578 $user->Save(); 585 $user->Save();
579 586
580 $result["recordList"] = $recordList; 587 $result["recordList"] = $recordList;
581 $result["lock"] = $user->lock; 588 $result["lock"] = $user->lock;
582 $result["result"] = "done"; 589 $result["result"] = "done";
583 590
584 //============================================================= 591 //=============================================================
585 } else if ($message == "deleteUser") { 592 } else if ($message == "deleteUser") {
586//{"message":"deleteUser", "srpSharedSecret":"e8e4ca6544dca49c95b3647d8358ad54c317048b74d2ac187ac25f719c9bac58", "parameters":{}} 593//{"message":"deleteUser", "srpSharedSecret":"e8e4ca6544dca49c95b3647d8358ad54c317048b74d2ac187ac25f719c9bac58", "parameters":{}}
587 $user = new user(); 594 $user = new user();
588 $user->Get($_SESSION["userId"]); 595 $user->Get($_SESSION["userId"]);
589 $user->Delete(true); 596 $user->Delete(true);
590 597
591 $result["result"] = "ok"; 598 $result["result"] = "ok";
592 599
593 //============================================================= 600 //=============================================================
594 } else if ($message == "addNewOneTimePassword") { 601 } else if ($message == "addNewOneTimePassword") {
595//{ 602//{
596 //"message":"addNewOneTimePassword", 603 //"message":"addNewOneTimePassword",
597 //"srpSharedSecret":"96fee4af06c09ce954fe7a9f87970e943449186bebf70bac0af1d6ebb818dabb", 604 //"srpSharedSecret":"96fee4af06c09ce954fe7a9f87970e943449186bebf70bac0af1d6ebb818dabb",
598 //"parameters":{ 605 //"parameters":{
599 // "user":{ 606 // "user":{
600 // "header":"{\"records\":{\"index\":{\"419ea6....rsion\":\"0.1\"}", 607 // "header":"{\"records\":{\"index\":{\"419ea6....rsion\":\"0.1\"}",
601 // "statistics":"rrlwNbDt83rpWT4S72upiVsC", 608 // "statistics":"rrlwNbDt83rpWT4S72upiVsC",
602 // "version":"0.3", 609 // "version":"0.3",
603 // "lock":"----" 610 // "lock":"----"
604 // }, 611 // },
605 // "oneTimePassword":{ 612 // "oneTimePassword":{
606 // "reference":"29e26f3a2aae61fe5cf58c45296c6df4f3dceafe067ea550b455be345f44123c", 613 // "reference":"29e26f3a2aae61fe5cf58c45296c6df4f3dceafe067ea550b455be345f44123c",
607 // "key":"afb848208758361a96a298b9db08995cf036011747809357a90645bc93fdfa03", 614 // "key":"afb848208758361a96a298b9db08995cf036011747809357a90645bc93fdfa03",
608 // "keyChecksum":"d1599ae443b5a566bfd93c0aeec4c81b42c0506ee09874dae050449580bb3486", 615 // "keyChecksum":"d1599ae443b5a566bfd93c0aeec4c81b42c0506ee09874dae050449580bb3486",
609 // "data":"hsyY8DHksgR52x6c4j7XAtIUeY.....dxsr3XWt7CbGg==", 616 // "data":"hsyY8DHksgR52x6c4j7XAtIUeY.....dxsr3XWt7CbGg==",
610 // "version":"0.3" 617 // "version":"0.3"
611 // } 618 // }
612 //} 619 //}
613//} 620//}
614 621
615 fixOTPStatusTable(); 622 fixOTPStatusTable();
616 623
617 $user = new user(); 624 $user = new user();
618 $user = $user->Get($_SESSION["userId"]); 625 $user = $user->Get($_SESSION["userId"]);
619 626
620 $otp = new onetimepassword(); 627 $otp = new onetimepassword();
621 updateOTP($parameters["parameters"]["oneTimePassword"], $otp, "ACTIVE"); 628 updateOTP($parameters["parameters"]["oneTimePassword"], $otp, "ACTIVE");
622 $user->AddOnetimepassword($otp); 629 $user->AddOnetimepassword($otp);
623 630
624 updateUserData($parameters["parameters"]["user"], $user); 631 updateUserData($parameters["parameters"]["user"], $user);
625 $user->Save(); 632 $user->Save();
626 633
627 $result["lock"] = $user->lock; 634 $result["lock"] = $user->lock;
628 $result["result"] = "done"; 635 $result["result"] = "done";
629 636
630 //============================================================= 637 //=============================================================
631 } else if ($message == "updateOneTimePasswords") { 638 } else if ($message == "updateOneTimePasswords") {
632//{ 639//{
633 //"message":"updateOneTimePasswords", 640 //"message":"updateOneTimePasswords",
634 //"srpSharedSecret":"c78f8ed099ea421f4dd0a4e02dbaf1f7da925f0088188d99399874ff064a3d27", 641 //"srpSharedSecret":"c78f8ed099ea421f4dd0a4e02dbaf1f7da925f0088188d99399874ff064a3d27",
635 //"parameters":{ 642 //"parameters":{
636 // "user":{ 643 // "user":{
637 // "header":"{\"reco...sion\":\"0.1\"}", 644 // "header":"{\"reco...sion\":\"0.1\"}",
638 // "statistics":"UeRq75RZHzDC7elzrh/+OB5d", 645 // "statistics":"UeRq75RZHzDC7elzrh/+OB5d",
639 // "version":"0.3", 646 // "version":"0.3",
640 // "lock":"----" 647 // "lock":"----"
641 // }, 648 // },
642 // "oneTimePasswords":["f5f44c232f239efe48ab81a6236deea1a840d52946f7d4d782dad52b4c5359ce"] 649 // "oneTimePasswords":["f5f44c232f239efe48ab81a6236deea1a840d52946f7d4d782dad52b4c5359ce"]
643 //} 650 //}
644//} 651//}
645 652
646 $user = new user(); 653 $user = new user();
647 $user = $user->Get($_SESSION["userId"]); 654 $user = $user->Get($_SESSION["userId"]);
648 655
649 $validOtpReferences = $parameters["parameters"]["oneTimePasswords"]; 656 $validOtpReferences = $parameters["parameters"]["oneTimePasswords"];
650 657
651 $otpList = $user->GetOnetimepasswordList(); 658 $otpList = $user->GetOnetimepasswordList();
652 $c = count($otpList); 659 $c = count($otpList);
653 for ($i=0; $i<$c; $i++) { 660 for ($i=0; $i<$c; $i++) {
654 $currentOtp = $otpList[$i]; 661 $currentOtp = $otpList[$i];
655 if (arrayContainsValue($validOtpReferences, $currentOtp->reference) == false) { 662 if (arrayContainsValue($validOtpReferences, $currentOtp->reference) == false) {
656 $currentOtp->Delete(); 663 $currentOtp->Delete();
657 } 664 }
658 } 665 }
659 666
660 updateUserData($parameters["parameters"]["user"], $user); 667 updateUserData($parameters["parameters"]["user"], $user);
661 $user->Save(); 668 $user->Save();
662 669
663 $result["result"] = $user->lock; 670 $result["result"] = $user->lock;
664 671
665 //============================================================= 672 //=============================================================
666 } else if ($message == "getOneTimePasswordsDetails") { 673 } else if ($message == "getOneTimePasswordsDetails") {
667 674
668 //============================================================= 675 //=============================================================
669 } else if ($message == "getLoginHistory") { 676 } else if ($message == "getLoginHistory") {
670 $result["result"] = array(); 677 $result["result"] = array();
671 678
672 //============================================================= 679 //=============================================================
673 } else if ($message == "upgradeUserCredentials") { 680 } else if ($message == "upgradeUserCredentials") {
674//{ 681//{
675 //"message":"upgradeUserCredentials", 682 //"message":"upgradeUserCredentials",
676 //"srpSharedSecret":"f1c25322e1478c8fb26063e9eef2f6fc25e0460065a31cb718f80bcff8f8a735", 683 //"srpSharedSecret":"f1c25322e1478c8fb26063e9eef2f6fc25e0460065a31cb718f80bcff8f8a735",
677 //"parameters":{ 684 //"parameters":{
678 // "user":{ 685 // "user":{
679 // "header":"{\"reco...sion\":\"0.1\"}", 686 // "header":"{\"reco...sion\":\"0.1\"}",
680 // "statistics":"s72Xva+w7CLgH+ihwqwXUbyu", 687 // "statistics":"s72Xva+w7CLgH+ihwqwXUbyu",
681 // "version":"0.3", 688 // "version":"0.3",
682 // "lock":"----" 689 // "lock":"----"
683 // }, 690 // },
684 // "credentials":{ 691 // "credentials":{
685 // "C":"57d15a8afbc1ae08103bd991d387ddfd8d26824276476fe709d754f098b6c26d", 692 // "C":"57d15a8afbc1ae08103bd991d387ddfd8d26824276476fe709d754f098b6c26d",
686 // "s":"d6735fc0486f391c4f3c947928f9e61a2418e7bed2bc9b25bb43f93acc52f636", 693 // "s":"d6735fc0486f391c4f3c947928f9e61a2418e7bed2bc9b25bb43f93acc52f636",
687 // "v":"540c2ebbf941a481b6b2c9026c07fb46e8202e4408ed96864a696deb622baece", 694 // "v":"540c2ebbf941a481b6b2c9026c07fb46e8202e4408ed96864a696deb622baece",
688 // "version":"0.2" 695 // "version":"0.2"
689 // }, 696 // },
690 // "oneTimePasswords":{ 697 // "oneTimePasswords":{
691 // "923cdc61c4b877b263236124c44d69b459d240453a461cce8ddf7518b423ca94": "1HD6Ta0xsifEDhDwE....9WDK6tvrS6w==", 698 // "923cdc61c4b877b263236124c44d69b459d240453a461cce8ddf7518b423ca94": "1HD6Ta0xsifEDhDwE....9WDK6tvrS6w==",
692 // "fb1573cb9497652a81688a099a524fb116e604c6fbc191cf33406eb8438efa5f": "CocN0cSxLmMRdgNF9....o3xhGUEY68Q==" 699 // "fb1573cb9497652a81688a099a524fb116e604c6fbc191cf33406eb8438efa5f": "CocN0cSxLmMRdgNF9....o3xhGUEY68Q=="
693 // } 700 // }
694 //} 701 //}
695//} 702//}
696 703
697 $user = new user(); 704 $user = new user();
698 $user->Get($_SESSION["userId"]); 705 $user->Get($_SESSION["userId"]);
699 706
700 $otp = new onetimepassword(); 707 $otp = new onetimepassword();
701 708
702 updateUserCredentials($parameters["parameters"]["credentials"], $user); 709 updateUserCredentials($parameters["parameters"]["credentials"], $user);
703 updateUserData($parameters["parameters"]["user"], $user); 710 updateUserData($parameters["parameters"]["user"], $user);
704 711
705 $otpList = $parameters["parameters"]["oneTimePasswords"]; 712 $otpList = $parameters["parameters"]["oneTimePasswords"];
706 foreach($otpList as $otpReference=>$otpData) { 713 foreach($otpList as $otpReference=>$otpData) {
707 $otpList = $otp->GetList(array(array("reference", "=", $otpReference))); 714 $otpList = $otp->GetList(array(array("reference", "=", $otpReference)));
708 $currentOtp = $otpList[0]; 715 $currentOtp = $otpList[0];
709 $currentOtp->data = $otpData; 716 $currentOtp->data = $otpData;
710 $currentOtp->Save(); 717 $currentOtp->Save();
711 } 718 }
712 719
713 $user->Save(); 720 $user->Save();
714 721
715 $result["lock"] = $user->lock; 722 $result["lock"] = $user->lock;
716 $result["result"] = "done"; 723 $result["result"] = "done";
717 724
718 //============================================================= 725 //=============================================================
719 } else if ($message == "echo") { 726 } else if ($message == "echo") {
720 $result["result"] = $parameters; 727 $result["result"] = $parameters;
721 } 728 }
722 729
723 //============================================================= 730 //=============================================================
724 } else if (isset($_SESSION['K'])) { 731 } else if (isset($_SESSION['K'])) {
725 $result["error"] = "Wrong shared secret!"; 732 $result["error"] = "Wrong shared secret!";
726 } else { 733 } else {
727 $result["result"] = "EXCEPTION"; 734 $result["result"] = "EXCEPTION";
728 $result["message"] = "Trying to communicate without an active connection"; 735 $result["message"] = "Trying to communicate without an active connection";
729 } 736 }
730 break; 737 break;
731 738
732 case "logout": 739 case "logout":
733error_log("logout"); 740error_log("logout");
734 session_destroy(); 741 session_destroy();
735 break; 742 break;
736 743
737 default: 744 default:
738error_log("default"); 745error_log("default");
739 $result["result"] = $parameters; 746 $result["result"] = $parameters;
740 break; 747 break;
741 } 748 }
742 749
743 session_write_close(); 750 session_write_close();
744 751
745 echo(json_encode($result)); 752 echo(json_encode($result));
746error_log("result: ".json_encode($result)); 753error_log("result: ".json_encode($result));
747?> 754?>
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,436 +1,441 @@
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
61 */ 61 */
62 public $update_date; 62 public $update_date;
63 63
64 /** 64 /**
65 * @var TIMESTAMP 65 * @var TIMESTAMP
66 */ 66 */
67 public $access_date; 67 public $access_date;
68 68
69 public $pog_attribute_type = array( 69 public $pog_attribute_type = array(
70 "recordId" => array('db_attributes' => array("NUMERIC", "INT")), 70 "recordId" => array('db_attributes' => array("NUMERIC", "INT")),
71 "user" => array('db_attributes' => array("OBJECT", "BELONGSTO")), 71 "user" => array('db_attributes' => array("OBJECT", "BELONGSTO")),
72 "recordversion" => array('db_attributes' => array("OBJECT", "HASMANY")), 72 "recordversion" => array('db_attributes' => array("OBJECT", "HASMANY")),
73 "reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), 73 "reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
74 "data" => array('db_attributes' => array("TEXT", "LONGTEXT")), 74 "data" => array('db_attributes' => array("TEXT", "LONGTEXT")),
75 "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), 75 "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
76 "creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), 76 "creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
77 "update_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")), 78 "access_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
79 ); 79 );
80 public $pog_query; 80 public $pog_query;
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 {
332 if (sizeof($fcv_array[$i]) == 1) 337 if (sizeof($fcv_array[$i]) == 1)
333 { 338 {
334 $pog_query .= " ".$fcv_array[$i][0]." "; 339 $pog_query .= " ".$fcv_array[$i][0]." ";
335 continue; 340 continue;
336 } 341 }
337 else 342 else
338 { 343 {
339 if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1) 344 if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
340 { 345 {
341 $pog_query .= " AND "; 346 $pog_query .= " AND ";
342 } 347 }
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') 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')
344 { 349 {
345 $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])."'";
346 } 351 }
347 else 352 else
348 { 353 {
349 $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]."'";
350 } 355 }
351 } 356 }
352 } 357 }
353 return Database::NonQuery($pog_query, $connection); 358 return Database::NonQuery($pog_query, $connection);
354 } 359 }
355 } 360 }
356 } 361 }
357 362
358 363
359 /** 364 /**
360 * Associates the user object to this one 365 * Associates the user object to this one
361 * @return boolean 366 * @return boolean
362 */ 367 */
363 function GetUser() 368 function GetUser()
364 { 369 {
365 $user = new user(); 370 $user = new user();
366 return $user->Get($this->userId); 371 return $user->Get($this->userId);
367 } 372 }
368 373
369 374
370 /** 375 /**
371 * Associates the user object to this one 376 * Associates the user object to this one
372 * @return 377 * @return
373 */ 378 */
374 function SetUser(&$user) 379 function SetUser(&$user)
375 { 380 {
376 $this->userId = $user->userId; 381 $this->userId = $user->userId;
377 } 382 }
378 383
379 384
380 /** 385 /**
381 * Gets a list of recordversion objects associated to this one 386 * Gets a list of recordversion objects associated to this one
382 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 387 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
383 * @param string $sortBy 388 * @param string $sortBy
384 * @param boolean $ascending 389 * @param boolean $ascending
385 * @param int limit 390 * @param int limit
386 * @return array of recordversion objects 391 * @return array of recordversion objects
387 */ 392 */
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
@@ -1,381 +1,383 @@
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 `recordversion` ( 5 CREATE TABLE `recordversion` (
6 `recordversionid` int(11) NOT NULL auto_increment, 6 `recordversionid` int(11) NOT NULL auto_increment,
7 `recordid` int(11) NOT NULL, 7 `recordid` int(11) NOT NULL,
8 `reference` VARCHAR(255) NOT NULL, 8 `reference` VARCHAR(255) NOT NULL,
9 `header` LONGTEXT NOT NULL, 9 `header` LONGTEXT NOT NULL,
10 `data` LONGTEXT NOT NULL, 10 `data` LONGTEXT NOT NULL,
11 `version` VARCHAR(255) NOT NULL, 11 `version` VARCHAR(255) NOT NULL,
12 `previous_version_key` VARCHAR(255) NOT NULL, 12 `previous_version_key` VARCHAR(255) NOT NULL,
13 `previous_version_id` INT NOT NULL, 13 `previous_version_id` INT NOT NULL,
14 `creation_date` TIMESTAMP NOT NULL, 14 `creation_date` TIMESTAMP NOT NULL,
15 `update_date` TIMESTAMP NOT NULL, 15 `update_date` TIMESTAMP NOT NULL,
16 `access_date` TIMESTAMP NOT NULL, INDEX(`recordid`), PRIMARY KEY (`recordversionid`)) ENGINE=MyISAM; 16 `access_date` TIMESTAMP NOT NULL, INDEX(`recordid`), PRIMARY KEY (`recordversionid`)) ENGINE=MyISAM;
17*/ 17*/
18 18
19/** 19/**
20* <b>recordversion</b> class with integrated CRUD methods. 20* <b>recordversion</b> class with integrated CRUD methods.
21* @author Php Object Generator 21* @author Php Object Generator
22* @version POG 3.0e / PHP5.1 MYSQL 22* @version POG 3.0e / PHP5.1 MYSQL
23* @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql 23* @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql
24* @copyright Free for personal & commercial use. (Offered under the BSD license) 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 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*/ 26*/
27include_once('class.pog_base.php'); 27include_once('class.pog_base.php');
28class recordversion extends POG_Base 28class recordversion extends POG_Base
29{ 29{
30 public $recordversionId = ''; 30 public $recordversionId = '';
31 31
32 /** 32 /**
33 * @var INT(11) 33 * @var INT(11)
34 */ 34 */
35 public $recordId; 35 public $recordId;
36 36
37 /** 37 /**
38 * @var VARCHAR(255) 38 * @var VARCHAR(255)
39 */ 39 */
40 public $reference; 40 public $reference;
41 41
42 /** 42 /**
43 * @var LONGTEXT 43 * @var LONGTEXT
44 */ 44 */
45 public $header; 45 public $header;
46 46
47 /** 47 /**
48 * @var LONGTEXT 48 * @var LONGTEXT
49 */ 49 */
50 public $data; 50 public $data;
51 51
52 /** 52 /**
53 * @var VARCHAR(255) 53 * @var VARCHAR(255)
54 */ 54 */
55 public $version; 55 public $version;
56 56
57 /** 57 /**
58 * @var VARCHAR(255) 58 * @var VARCHAR(255)
59 */ 59 */
60 public $previous_version_key; 60 public $previous_version_key;
61 61
62 /** 62 /**
63 * @var INT 63 * @var INT
64 */ 64 */
65 public $previous_version_id; 65 public $previous_version_id;
66 66
67 /** 67 /**
68 * @var TIMESTAMP 68 * @var TIMESTAMP
69 */ 69 */
70 public $creation_date; 70 public $creation_date;
71 71
72 /** 72 /**
73 * @var TIMESTAMP 73 * @var TIMESTAMP
74 */ 74 */
75 public $update_date; 75 public $update_date;
76 76
77 /** 77 /**
78 * @var TIMESTAMP 78 * @var TIMESTAMP
79 */ 79 */
80 public $access_date; 80 public $access_date;
81 81
82 public $pog_attribute_type = array( 82 public $pog_attribute_type = array(
83 "recordversionId" => array('db_attributes' => array("NUMERIC", "INT")), 83 "recordversionId" => array('db_attributes' => array("NUMERIC", "INT")),
84 "record" => array('db_attributes' => array("OBJECT", "BELONGSTO")), 84 "record" => array('db_attributes' => array("OBJECT", "BELONGSTO")),
85 "reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), 85 "reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
86 "header" => array('db_attributes' => array("TEXT", "LONGTEXT")), 86 "header" => array('db_attributes' => array("TEXT", "LONGTEXT")),
87 "data" => array('db_attributes' => array("TEXT", "LONGTEXT")), 87 "data" => array('db_attributes' => array("TEXT", "LONGTEXT")),
88 "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), 88 "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
89 "previous_version_key" => 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")), 90 "previous_version_id" => array('db_attributes' => array("NUMERIC", "INT")),
91 "creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), 91 "creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
92 "update_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")), 93 "access_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
94 ); 94 );
95 public $pog_query; 95 public $pog_query;
96 96
97 97
98 /** 98 /**
99 * Getter for some private attributes 99 * Getter for some private attributes
100 * @return mixed $attribute 100 * @return mixed $attribute
101 */ 101 */
102 public function __get($attribute) 102 public function __get($attribute)
103 { 103 {
104 if (isset($this->{"_".$attribute})) 104 if (isset($this->{"_".$attribute}))
105 { 105 {
106 return $this->{"_".$attribute}; 106 return $this->{"_".$attribute};
107 } 107 }
108 else 108 else
109 { 109 {
110 return false; 110 return false;
111 } 111 }
112 } 112 }
113 113
114 function recordversion($reference='', $header='', $data='', $version='', $previous_version_key='', $previous_version_id='', $creation_date='', $update_date='', $access_date='') 114 function recordversion($reference='', $header='', $data='', $version='', $previous_version_key='', $previous_version_id='', $creation_date='', $update_date='', $access_date='')
115 { 115 {
116 $this->reference = $reference; 116 $this->reference = $reference;
117 $this->header = $header; 117 $this->header = $header;
118 $this->data = $data; 118 $this->data = $data;
119 $this->version = $version; 119 $this->version = $version;
120 $this->previous_version_key = $previous_version_key; 120 $this->previous_version_key = $previous_version_key;
121 $this->previous_version_id = $previous_version_id; 121 $this->previous_version_id = $previous_version_id;
122 $this->creation_date = $creation_date; 122 $this->creation_date = $creation_date;
123 $this->update_date = $update_date; 123 $this->update_date = $update_date;
124 $this->access_date = $access_date; 124 $this->access_date = $access_date;
125 } 125 }
126 126
127 127
128 /** 128 /**
129 * Gets object from database 129 * Gets object from database
130 * @param integer $recordversionId 130 * @param integer $recordversionId
131 * @return object $recordversion 131 * @return object $recordversion
132 */ 132 */
133 function Get($recordversionId) 133 function Get($recordversionId)
134 { 134 {
135 $connection = Database::Connect(); 135 $connection = Database::Connect();
136 $this->pog_query = "select * from `recordversion` where `recordversionid`='".intval($recordversionId)."' LIMIT 1"; 136 $this->pog_query = "select * from `recordversion` where `recordversionid`='".intval($recordversionId)."' LIMIT 1";
137 $cursor = Database::Reader($this->pog_query, $connection); 137 $cursor = Database::Reader($this->pog_query, $connection);
138 while ($row = Database::Read($cursor)) 138 while ($row = Database::Read($cursor))
139 { 139 {
140 $this->recordversionId = $row['recordversionid']; 140 $this->recordversionId = $row['recordversionid'];
141 $this->recordId = $row['recordid']; 141 $this->recordId = $row['recordid'];
142 $this->reference = $this->Unescape($row['reference']); 142 $this->reference = $this->Unescape($row['reference']);
143 $this->header = $this->Unescape($row['header']); 143 $this->header = $this->Unescape($row['header']);
144 $this->data = $this->Unescape($row['data']); 144 $this->data = $this->Unescape($row['data']);
145 $this->version = $this->Unescape($row['version']); 145 $this->version = $this->Unescape($row['version']);
146 $this->previous_version_key = $this->Unescape($row['previous_version_key']); 146 $this->previous_version_key = $this->Unescape($row['previous_version_key']);
147 $this->previous_version_id = $this->Unescape($row['previous_version_id']); 147 $this->previous_version_id = $this->Unescape($row['previous_version_id']);
148 $this->creation_date = $row['creation_date']; 148 $this->creation_date = $row['creation_date'];
149 $this->update_date = $row['update_date']; 149 $this->update_date = $row['update_date'];
150 $this->access_date = $row['access_date']; 150 $this->access_date = $row['access_date'];
151 } 151 }
152 return $this; 152 return $this;
153 } 153 }
154 154
155 155
156 /** 156 /**
157 * Returns a sorted array of objects that match given conditions 157 * Returns a sorted array of objects that match given conditions
158 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 158 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
159 * @param string $sortBy 159 * @param string $sortBy
160 * @param boolean $ascending 160 * @param boolean $ascending
161 * @param int limit 161 * @param int limit
162 * @return array $recordversionList 162 * @return array $recordversionList
163 */ 163 */
164 function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') 164 function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
165 { 165 {
166 $connection = Database::Connect(); 166 $connection = Database::Connect();
167 $sqlLimit = ($limit != '' ? "LIMIT $limit" : ''); 167 $sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
168 $this->pog_query = "select * from `recordversion` "; 168 $this->pog_query = "select * from `recordversion` ";
169 $recordversionList = Array(); 169 $recordversionList = Array();
170 if (sizeof($fcv_array) > 0) 170 if (sizeof($fcv_array) > 0)
171 { 171 {
172 $this->pog_query .= " where "; 172 $this->pog_query .= " where ";
173 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) 173 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
174 { 174 {
175 if (sizeof($fcv_array[$i]) == 1) 175 if (sizeof($fcv_array[$i]) == 1)
176 { 176 {
177 $this->pog_query .= " ".$fcv_array[$i][0]." "; 177 $this->pog_query .= " ".$fcv_array[$i][0]." ";
178 continue; 178 continue;
179 } 179 }
180 else 180 else
181 { 181 {
182 if ($i > 0 && sizeof($fcv_array[$i-1]) != 1) 182 if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
183 { 183 {
184 $this->pog_query .= " AND "; 184 $this->pog_query .= " AND ";
185 } 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') 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 { 187 {
188 if ($GLOBALS['configuration']['db_encoding'] == 1) 188 if ($GLOBALS['configuration']['db_encoding'] == 1)
189 { 189 {
190 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'"; 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; 191 $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
192 } 192 }
193 else 193 else
194 { 194 {
195 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'"; 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; 196 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
197 } 197 }
198 } 198 }
199 else 199 else
200 { 200 {
201 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'"; 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; 202 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
203 } 203 }
204 } 204 }
205 } 205 }
206 } 206 }
207 if ($sortBy != '') 207 if ($sortBy != '')
208 { 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') 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 { 210 {
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 }
307 309
308 310
309 /** 311 /**
310 * Deletes the object from the database 312 * Deletes the object from the database
311 * @return boolean 313 * @return boolean
312 */ 314 */
313 function Delete() 315 function Delete()
314 { 316 {
315 $connection = Database::Connect(); 317 $connection = Database::Connect();
316 $this->pog_query = "delete from `recordversion` where `recordversionid`='".$this->recordversionId."'"; 318 $this->pog_query = "delete from `recordversion` where `recordversionid`='".$this->recordversionId."'";
317 return Database::NonQuery($this->pog_query, $connection); 319 return Database::NonQuery($this->pog_query, $connection);
318 } 320 }
319 321
320 322
321 /** 323 /**
322 * Deletes a list of objects that match given conditions 324 * Deletes a list of objects that match given conditions
323 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 325 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
324 * @param bool $deep 326 * @param bool $deep
325 * @return 327 * @return
326 */ 328 */
327 function DeleteList($fcv_array) 329 function DeleteList($fcv_array)
328 { 330 {
329 if (sizeof($fcv_array) > 0) 331 if (sizeof($fcv_array) > 0)
330 { 332 {
331 $connection = Database::Connect(); 333 $connection = Database::Connect();
332 $pog_query = "delete from `recordversion` where "; 334 $pog_query = "delete from `recordversion` where ";
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?>