author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /backend | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2 |
First version of the newly restructured repository
83 files changed, 9694 insertions, 0 deletions
diff --git a/backend/php/properties/php.properties.json b/backend/php/properties/php.properties.json new file mode 100644 index 0000000..32d5084 --- a/dev/null +++ b/backend/php/properties/php.properties.json | |||
@@ -0,0 +1,4 @@ | |||
1 | { | ||
2 | "request.path": "../index.php", | ||
3 | "should.pay.toll": "false" | ||
4 | } \ No newline at end of file | ||
diff --git a/backend/php/src/configuration.php b/backend/php/src/configuration.php new file mode 100644 index 0000000..291e3a1 --- a/dev/null +++ b/backend/php/src/configuration.php | |||
@@ -0,0 +1,36 @@ | |||
1 | <?php | ||
2 | global $configuration; | ||
3 | $configuration['soap'] = "http://www.phpobjectgenerator.com/services/soap.php?wsdl"; | ||
4 | $configuration['homepage'] = "http://www.phpobjectgenerator.com"; | ||
5 | $configuration['revisionNumber'] = ""; | ||
6 | $configuration['versionNumber'] = "3.0d"; | ||
7 | |||
8 | $configuration['setup_password'] = ''; | ||
9 | |||
10 | |||
11 | // to enable automatic data encoding, run setup, go to the manage plugins tab and install the base64 plugin. | ||
12 | // then set db_encoding = 1 below. | ||
13 | // when enabled, db_encoding transparently encodes and decodes data to and from the database without any | ||
14 | // programmatic effort on your part. | ||
15 | $configuration['db_encoding'] = 0; | ||
16 | |||
17 | // edit the information below to match your database settings | ||
18 | |||
19 | $configuration['db'] = 'clipperz'; //database name | ||
20 | $configuration['host'] = 'localhost'; //database host | ||
21 | $configuration['user'] = 'root'; //database user | ||
22 | $configuration['pass'] = 'pass'; //database password | ||
23 | $configuration['port'] = '3306'; //database port | ||
24 | |||
25 | |||
26 | //proxy settings - if you are behnd a proxy, change the settings below | ||
27 | $configuration['proxy_host'] = false; | ||
28 | $configuration['proxy_port'] = false; | ||
29 | $configuration['proxy_username'] = false; | ||
30 | $configuration['proxy_password'] = false; | ||
31 | |||
32 | |||
33 | //plugin settings | ||
34 | $configuration['plugins_path'] = dirname(__FILE__).'/plugins'; | ||
35 | |||
36 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/dump.php b/backend/php/src/dump.php new file mode 100644 index 0000000..d4e8544 --- a/dev/null +++ b/backend/php/src/dump.php | |||
@@ -0,0 +1,103 @@ | |||
1 | <?php | ||
2 | header('Content-Type: text/html'); | ||
3 | header('Content-Disposition: attachment; filename=Clipperz_'.date("Ymd").'.html'); | ||
4 | |||
5 | |||
6 | include "./configuration.php"; | ||
7 | include "./objects/class.database.php"; | ||
8 | include "./objects/class.user.php"; | ||
9 | include "./objects/class.record.php"; | ||
10 | include "./objects/class.recordversion.php"; | ||
11 | include "./objects/class.onetimepassword.php"; | ||
12 | include "./objects/class.onetimepasswordstatus.php"; | ||
13 | |||
14 | $htmlContent = file_get_contents("../index.html"); | ||
15 | |||
16 | session_start(); | ||
17 | |||
18 | $user = new user(); | ||
19 | $user = $user->Get($_SESSION["userId"]); | ||
20 | $records = $user->GetRecordList(); | ||
21 | |||
22 | $recordString = ""; | ||
23 | $isFirstRecord = true; | ||
24 | |||
25 | $c = count($records); | ||
26 | for ($i=0; $i<$c; $i++) { | ||
27 | $currentRecord = $records[$i]; | ||
28 | $recordVersions = $currentRecord->GetRecordversionList(); | ||
29 | |||
30 | |||
31 | if ($isFirstRecord == true) { | ||
32 | $isFirstRecord = false; | ||
33 | } else { | ||
34 | $recordString = $recordString . ",\n"; | ||
35 | } | ||
36 | |||
37 | $versionString = ""; | ||
38 | $isFirstVersion = true; | ||
39 | |||
40 | $cc = count($recordVersions); | ||
41 | for ($ii=0; $ii<$cc; $ii++) { | ||
42 | $currentVersion = $recordVersions[$ii]; | ||
43 | |||
44 | if ($isFirstVersion == true) { | ||
45 | $isFirstVersion = false; | ||
46 | } else { | ||
47 | $versionString = $versionString . ",\n"; | ||
48 | } | ||
49 | |||
50 | $versionsString = $versionString ."\t\t\t\t\t\t'" . $currentVersion->reference . "': {\n" . | ||
51 | "\t\t\t\t\t\t\theader: '" . $currentVersion->header . "',\n" . | ||
52 | "\t\t\t\t\t\t\tdata: '" . $currentVersion->data . "',\n" . | ||
53 | "\t\t\t\t\t\t\tversion: '" . $currentVersion->version . "',\n" . | ||
54 | "\t\t\t\t\t\t\tcreationDate: '". $currentVersion->creation_date . "',\n" . | ||
55 | "\t\t\t\t\t\t\tupdateDate: '". $currentVersion->update_date . "',\n" . | ||
56 | "\t\t\t\t\t\t\taccessDate: '". $currentVersion->access_date . "'\n" . | ||
57 | "\t\t\t\t\t\t}"; | ||
58 | } | ||
59 | |||
60 | $recordString = $recordString ."\t\t\t\t'" . $currentRecord->reference . "': {\n" . | ||
61 | "\t\t\t\t\tdata: '" . $currentRecord->data . "',\n" . | ||
62 | "\t\t\t\t\tversion: '" . $currentRecord->version . "',\n" . | ||
63 | "\t\t\t\t\tcreationDate: '" . $currentRecord->creation_date . "',\n" . | ||
64 | "\t\t\t\t\tupdateDate: '" . $currentRecord->update_date . "',\n" . | ||
65 | "\t\t\t\t\taccessDate: '" . $currentRecord->access_date . "',\n" . | ||
66 | "\t\t\t\t\tcurrentVersion: '". $currentVersion->reference . "',\n" . | ||
67 | "\t\t\t\t\tversions: {\n" . | ||
68 | $versionsString . "\n" . | ||
69 | "\t\t\t\t\t}\n" . | ||
70 | "\t\t\t\t}"; | ||
71 | } | ||
72 | |||
73 | |||
74 | $data = "_clipperz_dump_data_ = {\n" . | ||
75 | "\tusers:{\n" . | ||
76 | "\t\t'catchAllUser': {\n" . | ||
77 | "\t\t\t__masterkey_test_value__: 'masterkey',\n" . | ||
78 | "\t\t\ts: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00',\n" . | ||
79 | "\t\t\tv: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00'\n" . | ||
80 | "\t\t},\n" . | ||
81 | "\t\t'" . $user->username . "': {\n" . | ||
82 | "\t\t\ts: '" . $user->srp_s . "',\n" . | ||
83 | "\t\t\tv: '" . $user->srp_v . "',\n" . | ||
84 | "\t\t\tversion: '" . $user->auth_version . "',\n" . | ||
85 | "\t\t\tmaxNumberOfRecords: '" . "100" . "',\n" . | ||
86 | "\t\t\tuserDetails: '" . $user->header . "',\n" . | ||
87 | "\t\t\tstatistics: '" . $user->statistics . "',\n" . | ||
88 | "\t\t\tuserDetailsVersion: '" . $user->version . "',\n" . | ||
89 | "\t\t\trecords: {\n" . | ||
90 | $recordString . "\n" . | ||
91 | "\t\t\t}\n" . | ||
92 | "\t\t}\n" . | ||
93 | "\t}\n" . | ||
94 | "}\n" . | ||
95 | "\n" . | ||
96 | "Clipperz.PM.Proxy.defaultProxy = new Clipperz.PM.Proxy.Offline();\n" . | ||
97 | "Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();" . | ||
98 | "\n"; | ||
99 | |||
100 | session_write_close(); | ||
101 | |||
102 | echo str_replace("/*offline_data_placeholder*/", $data, $htmlContent); | ||
103 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/index.php b/backend/php/src/index.php new file mode 100644 index 0000000..eb3d75a --- a/dev/null +++ b/backend/php/src/index.php | |||
@@ -0,0 +1,744 @@ | |||
1 | <?php | ||
2 | include "./configuration.php"; | ||
3 | include "./objects/class.database.php"; | ||
4 | include "./objects/class.user.php"; | ||
5 | include "./objects/class.record.php"; | ||
6 | include "./objects/class.recordversion.php"; | ||
7 | include "./objects/class.onetimepassword.php"; | ||
8 | include "./objects/class.onetimepasswordstatus.php"; | ||
9 | |||
10 | //----------------------------------------------------------------------------- | ||
11 | |||
12 | if ( !function_exists('json_decode') ) { | ||
13 | function json_decode($content, $assoc=false) { | ||
14 | require_once 'json/JSON.php'; | ||
15 | if ( $assoc ) { | ||
16 | $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); | ||
17 | } else { | ||
18 | $json = new Services_JSON; | ||
19 | } | ||
20 | |||
21 | return $json->decode($content); | ||
22 | } | ||
23 | } | ||
24 | |||
25 | if ( !function_exists('json_encode') ) { | ||
26 | function json_encode($content) { | ||
27 | require_once 'json/JSON.php'; | ||
28 | $json = new Services_JSON; | ||
29 | |||
30 | return $json->encode($content); | ||
31 | } | ||
32 | } | ||
33 | |||
34 | //----------------------------------------------------------------------------- | ||
35 | //'dec2base', 'base2dec' and 'digits' are functions found on the following | ||
36 | //PHP manual page: http://ch2.php.net/manual/en/ref.bc.php | ||
37 | // | ||
38 | |||
39 | function dec2base($dec, $base, $digits=FALSE) { | ||
40 | if ($base<2 or $base>256) { | ||
41 | die("Invalid Base: ".$base); | ||
42 | } | ||
43 | |||
44 | bcscale(0); | ||
45 | $value=""; | ||
46 | if (!$digits) { | ||
47 | $digits = digits($base); | ||
48 | } | ||
49 | |||
50 | while ($dec > $base-1) { | ||
51 | $rest = bcmod($dec, $base); | ||
52 | $dec = bcdiv($dec, $base); | ||
53 | $value = $digits[$rest].$value; | ||
54 | } | ||
55 | |||
56 | $value=$digits[intval($dec)].$value; | ||
57 | |||
58 | return (string)$value; | ||
59 | } | ||
60 | |||
61 | //............................................................................. | ||
62 | |||
63 | // convert another base value to its decimal value | ||
64 | function base2dec($value, $base, $digits=FALSE) { | ||
65 | if ($base<2 or $base>256) { | ||
66 | die("Invalid Base: ".$base); | ||
67 | } | ||
68 | |||
69 | bcscale(0); | ||
70 | if ($base<37) { | ||
71 | $value=strtolower($value); | ||
72 | } | ||
73 | |||
74 | if (!$digits) { | ||
75 | $digits=digits($base); | ||
76 | } | ||
77 | |||
78 | $size = strlen($value); | ||
79 | $dec="0"; | ||
80 | for ($loop=0; $loop<$size; $loop++) { | ||
81 | $element = strpos($digits, $value[$loop]); | ||
82 | $power = bcpow($base, $size-$loop-1); | ||
83 | $dec = bcadd($dec, bcmul($element,$power)); | ||
84 | } | ||
85 | |||
86 | return (string)$dec; | ||
87 | } | ||
88 | |||
89 | //............................................................................. | ||
90 | |||
91 | function digits($base) { | ||
92 | if ($base>64) { | ||
93 | $digits=""; | ||
94 | for ($loop=0; $loop<256; $loop++) { | ||
95 | $digits.=chr($loop); | ||
96 | } | ||
97 | } else { | ||
98 | $digits ="0123456789abcdefghijklmnopqrstuvwxyz"; | ||
99 | $digits.="ABCDEFGHIJKLMNOPQRSTUVWXYZ-_"; | ||
100 | } | ||
101 | |||
102 | $digits=substr($digits,0,$base); | ||
103 | |||
104 | return (string)$digits; | ||
105 | } | ||
106 | |||
107 | //----------------------------------------------------------------------------- | ||
108 | |||
109 | function clipperz_hash($value) { | ||
110 | return hash("sha256", hash("sha256", $value, true)); | ||
111 | } | ||
112 | |||
113 | //----------------------------------------------------------------------------- | ||
114 | |||
115 | function clipperz_randomSeed() { | ||
116 | $result; | ||
117 | |||
118 | srand((double) microtime()*1000000); | ||
119 | $result = ""; | ||
120 | |||
121 | while(strlen($result) < 64) { | ||
122 | $result = $result.dec2base(rand(), 16); | ||
123 | } | ||
124 | |||
125 | $result = substr($result, 0, 64); | ||
126 | |||
127 | return $result; | ||
128 | } | ||
129 | |||
130 | //----------------------------------------------------------------------------- | ||
131 | |||
132 | function updateUserCredentials($parameters, &$user) { | ||
133 | $user->username = $parameters["C"]; | ||
134 | $user->srp_s = $parameters["s"]; | ||
135 | $user->srp_v = $parameters["v"]; | ||
136 | $user->auth_version =$parameters["version"]; | ||
137 | } | ||
138 | |||
139 | function updateUserData($parameters, &$user) { | ||
140 | $user->header = $parameters["header"]; | ||
141 | $user->statistics =$parameters["statistics"]; | ||
142 | $user->version =$parameters["version"]; | ||
143 | $user->lock = $parameters["lock"]; | ||
144 | } | ||
145 | |||
146 | function updateRecordData($parameters, &$record, &$recordVersion) { | ||
147 | $recordData = $parameters["record"]; | ||
148 | $record->reference =$recordData["reference"]; | ||
149 | $record->data = $recordData["data"]; | ||
150 | $record->version = $recordData["version"]; | ||
151 | |||
152 | $recordVersionData = $parameters["currentRecordVersion"]; | ||
153 | $recordVersion->reference = $recordVersionData ["reference"]; | ||
154 | $recordVersion->data = $recordVersionData ["data"]; | ||
155 | $recordVersion->version = $recordVersionData ["version"]; | ||
156 | $recordVersion->previous_version_id =$recordVersionData ["previousVersion"]; | ||
157 | $recordVersion->previous_version_key =$recordVersionData ["previousVersionKey"]; | ||
158 | } | ||
159 | |||
160 | //----------------------------------------------------------------------------- | ||
161 | |||
162 | function updateOTPStatus(&$otp, $status) { | ||
163 | $otpStatus = new onetimepasswordstatus(); | ||
164 | $selectedStatuses = $otpStatus->GetList(array(array("code", "=", $status))); | ||
165 | $otpStatus = $selectedStatuses[0]; | ||
166 | $otp->SetOnetimepasswordstatus($otpStatus); | ||
167 | } | ||
168 | |||
169 | function updateOTP($parameters, &$otp, $status) { | ||
170 | $otp->reference = $parameters["reference"]; | ||
171 | $otp->key = $parameters["key"]; | ||
172 | $otp->key_checksum= $parameters["keyChecksum"]; | ||
173 | $otp->data = $parameters["data"]; | ||
174 | $otp->version = $parameters["version"]; | ||
175 | |||
176 | updateOTPStatus($otp, $status); | ||
177 | } | ||
178 | |||
179 | function resetOTP(&$otp, $status) { | ||
180 | $otp->data = ""; | ||
181 | updateOTPStatus($otp, $status); | ||
182 | $otp->Save(); | ||
183 | } | ||
184 | |||
185 | //----------------------------------------------------------------------------- | ||
186 | |||
187 | function fixOTPStatusTable() { | ||
188 | $otpStatus = new onetimepasswordstatus(); | ||
189 | $otpStatusList = $otpStatus->GetList(); | ||
190 | if (count($otpStatusList) != 4) { | ||
191 | $otpStatus->DeleteList(); | ||
192 | |||
193 | $otpStatus->code = "ACTIVE"; $otpStatus->name = "Active"; $otpStatus->description = "Active"; $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(); | ||
196 | $otpStatus->code = "DISABLED"; $otpStatus->name = "Disabled"; $otpStatus->description = "Disabled";$otpStatus->SaveNew(); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | //----------------------------------------------------------------------------- | ||
201 | |||
202 | function arrayContainsValue($array, $value) { | ||
203 | $object = NULL; | ||
204 | for ($i=0; $i<count($array); $i++) { | ||
205 | if ($array[$i] == $value) { | ||
206 | $object = $value; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | return !is_null($object); | ||
211 | } | ||
212 | |||
213 | //----------------------------------------------------------------------------- | ||
214 | |||
215 | $result = Array(); | ||
216 | |||
217 | session_start(); | ||
218 | |||
219 | $method = $_POST['method']; | ||
220 | |||
221 | if (get_magic_quotes_gpc()) { | ||
222 | $parameters = json_decode(stripslashes($_POST['parameters']), true); | ||
223 | } else { | ||
224 | $parameters = json_decode($_POST['parameters'], true); | ||
225 | } | ||
226 | |||
227 | $parameters = $parameters["parameters"]; | ||
228 | |||
229 | switch($method) { | ||
230 | case "registration": | ||
231 | error_log("registration"); | ||
232 | $message = $parameters["message"]; | ||
233 | |||
234 | if ($message == "completeRegistration") { | ||
235 | $user = new user(); | ||
236 | |||
237 | updateUserCredentials($parameters["credentials"], $user); | ||
238 | updateUserData($parameters["user"], $user); | ||
239 | $user->Save(); | ||
240 | |||
241 | $result["lock"] = $user->lock; | ||
242 | $result["result"] = "done"; | ||
243 | } | ||
244 | break; | ||
245 | |||
246 | case "handshake": | ||
247 | error_log("handshake"); | ||
248 | $srp_g = "2"; | ||
249 | $srp_n = base2dec("115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3", 16); | ||
250 | |||
251 | $message = $parameters["message"]; | ||
252 | |||
253 | //============================================================= | ||
254 | if ($message == "connect") { | ||
255 | $user= new user(); | ||
256 | $_SESSION["C"] = $parameters["parameters"]["C"]; | ||
257 | $_SESSION["A"] = $parameters["parameters"]["A"]; | ||
258 | |||
259 | $userList = $user->GetList(array(array("username", "=", $_SESSION["C"]))); | ||
260 | |||
261 | if (count($userList) == 1) { | ||
262 | $currentUser = $userList[ 0 ]; | ||
263 | |||
264 | if (array_key_exists("otpId", $_SESSION)) { | ||
265 | $otp = new onetimepassword(); | ||
266 | $otp = $otp->Get($_SESSION["otpId"]); | ||
267 | |||
268 | if ($otp->GetUser()->userId != $currentUser->userId) { | ||
269 | throw new Exception("User missmatch between the current session and 'One Time Password' user"); | ||
270 | } else if ($otp->GetOnetimepasswordstatus()->code != "REQUESTED") { | ||
271 | throw new Exception("Tring to use an 'One Time Password' in the wrong state"); | ||
272 | } | ||
273 | |||
274 | resetOTP($otp, "USED"); | ||
275 | $result["oneTimePassword"] = $otp->reference; | ||
276 | } | ||
277 | |||
278 | $_SESSION["s"] = $currentUser->srp_s; | ||
279 | $_SESSION["v"] = $currentUser->srp_v; | ||
280 | $_SESSION["userId"] = $currentUser->userId; | ||
281 | } else { | ||
282 | $_SESSION["s"] = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"; | ||
283 | $_SESSION["v"] = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"; | ||
284 | } | ||
285 | |||
286 | $_SESSION["b"] = clipperz_randomSeed(); | ||
287 | // $_SESSION["b"] = "5761e6c84d22ea3c5649de01702d60f674ccfe79238540eb34c61cd020230c53"; | ||
288 | $_SESSION["B"] = dec2base(bcadd(base2dec($_SESSION["v"], 16), bcpowmod($srp_g, base2dec($_SESSION["b"], 16), $srp_n)), 16); | ||
289 | |||
290 | $result["s"] = $_SESSION["s"]; | ||
291 | $result["B"] = $_SESSION["B"]; | ||
292 | |||
293 | //============================================================= | ||
294 | } else if ($message == "credentialCheck") { | ||
295 | error_log("credentialCheck"); | ||
296 | $u = clipperz_hash(base2dec($_SESSION["B"],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); | ||
299 | $K = clipperz_hash($S); | ||
300 | $M1 = clipperz_hash($A.base2dec($_SESSION["B"],16).$K); | ||
301 | |||
302 | //$result["B"] = $_SESSION["B"]; | ||
303 | //$result["u"] = $u; | ||
304 | //$result["A"] = $A; | ||
305 | //$result["S"] = $S; | ||
306 | //$result["K"] = $K; | ||
307 | //$result["M1"] = $M1; | ||
308 | //$result["_M1"] = $parameters["parameters"]["M1"]; | ||
309 | |||
310 | if ($M1 == $parameters["parameters"]["M1"]) { | ||
311 | $_SESSION["K"] = $K; | ||
312 | $M2 = clipperz_hash($A.$M1.$K); | ||
313 | |||
314 | $result["M2"] = $M2; | ||
315 | $result["connectionId"] = ""; | ||
316 | $result["loginInfo"] = array(); | ||
317 | $result["loginInfo"]["latest"] = array(); | ||
318 | $result["loginInfo"]["current"] = array(); | ||
319 | $result["offlineCopyNeeded"] = "false"; | ||
320 | $result["lock"] = "----"; | ||
321 | } else { | ||
322 | $result["error"] = "?"; | ||
323 | } | ||
324 | //============================================================= | ||
325 | } else if ($message == "oneTimePassword") { | ||
326 | error_log("oneTimePassword"); | ||
327 | //{ | ||
328 | //"message":"oneTimePassword", | ||
329 | //"version":"0.2", | ||
330 | //"parameters":{ | ||
331 | // "oneTimePasswordKey":"06dfa7f428081f8b2af98b0895e14e18af90b0ef2ff32828e55cc2ac6b24d29b", | ||
332 | // "oneTimePasswordKeyChecksum":"60bcba3f72e56f6bb3f0ff88509b9a0e5ec730dfa71daa4c1e892dbd1b0c360d" | ||
333 | //} | ||
334 | //} | ||
335 | $otp = new onetimepassword(); | ||
336 | $otpList = $otp->GetList(array(array("key", "=", $parameters["parameters"]["oneTimePasswordKey"]))); | ||
337 | |||
338 | if (count($otpList) == 1) { | ||
339 | $currentOtp = $otpList[0]; | ||
340 | |||
341 | if ($currentOtp->GetOnetimepasswordstatus()->code == "ACTIVE") { | ||
342 | if ($currentOtp->key_checksum == $parameters["parameters"]["oneTimePasswordKeyChecksum"]) { | ||
343 | $_SESSION["userId"] = $currentOtp->GetUser()->userId; | ||
344 | $_SESSION["otpId"]= $currentOtp->onetimepasswordId; | ||
345 | |||
346 | $result["data"] = $currentOtp->data; | ||
347 | $result["version"] = $currentOtp->version; | ||
348 | |||
349 | resetOTP($currentOtp, "REQUESTED"); | ||
350 | } else { | ||
351 | resetOTP($currentOtp, "DISABLED"); | ||
352 | throw new Exception("The requested One Time Password has been disabled, due to a wrong keyChecksum"); | ||
353 | } | ||
354 | } else { | ||
355 | throw new Exception("The requested One Time Password was not active"); | ||
356 | } | ||
357 | } else { | ||
358 | throw new Exception("The requested One Time Password has not been found"); | ||
359 | } | ||
360 | |||
361 | //============================================================= | ||
362 | } | ||
363 | |||
364 | break; | ||
365 | |||
366 | case "message": | ||
367 | error_log("message"); | ||
368 | if ($parameters["srpSharedSecret"] == $_SESSION["K"]) { | ||
369 | $message = $parameters["message"]; | ||
370 | |||
371 | //============================================================= | ||
372 | if ($message == "getUserDetails") { | ||
373 | //{"message":"getUserDetails", "srpSharedSecret":"f18e5cf7c3a83b67d4db9444af813ee48c13daf4f8f6635397d593e52ba89a08", "parameters":{}} | ||
374 | $user = new user(); | ||
375 | $user = $user->Get($_SESSION["userId"]); | ||
376 | |||
377 | $result["header"] = $user->header; | ||
378 | $result["statistics"] =$user->statistics; | ||
379 | $result["version"] =$user->version; | ||
380 | |||
381 | //============================================================= | ||
382 | } else if ($message == "addNewRecords") { | ||
383 | /* | ||
384 | //{ | ||
385 | //"message":"addNewRecords", | ||
386 | //"srpSharedSecret":"b58fdf62acebbcb67f63d28c0437f166069f45690c648cd4376a792ae7a325f7", | ||
387 | //"parameters":{ | ||
388 | // "records":[ | ||
389 | // { | ||
390 | // "record":{ | ||
391 | // "reference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610", | ||
392 | // "data":"OBSGtcb6blXq/xaYG.....4EqlQqgAvITN", | ||
393 | // "version":"0.3" | ||
394 | // }, | ||
395 | // "currentRecordVersion":{ | ||
396 | // "reference":"83ad301525c18f2afd72b6ac82c0a713382e1ef70ac69935ca7e2869dd4ff980", | ||
397 | // "recordReference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610", | ||
398 | // "data":"NXJ5jiZhkd0CMiwwntAq....1TjjF+SGfE=", | ||
399 | // "version":"0.3", | ||
400 | // "previousVersion":"3e174a86afc322271d8af28bc062b0f1bfd7344fad01212cd08b2757c4b199c4", | ||
401 | // "previousVersionKey":"kozaaGCzXWr71LbOKu6Z3nz520V..5U85tSBvb+u44twttv54Kw==" | ||
402 | // } | ||
403 | // } | ||
404 | // ], | ||
405 | // "user":{ | ||
406 | // "header":"{\"reco...ersion\":\"0.1\"}", | ||
407 | // "statistics":"rKI6nR6iqggygQJ3SQ58bFUX", | ||
408 | // "version":"0.3", | ||
409 | // "lock":"----" | ||
410 | // } | ||
411 | //} | ||
412 | //} | ||
413 | */ | ||
414 | $user = new user(); | ||
415 | $record = new record(); | ||
416 | $recordVersion = new recordversion(); | ||
417 | |||
418 | $user = $user->Get($_SESSION["userId"]); | ||
419 | updateUserData($parameters["parameters"]["user"], $user); | ||
420 | |||
421 | $recordParameterList = $parameters["parameters"]["records"]; | ||
422 | $c = count($recordParameterList); | ||
423 | for ($i=0; $i<$c; $i++) { | ||
424 | updateRecordData($recordParameterList[$i], $record, $recordVersion); | ||
425 | |||
426 | $record->SaveNew(); | ||
427 | $recordVersion->SaveNew(); | ||
428 | |||
429 | $record->AddRecordversion($recordVersion); | ||
430 | $user->AddRecord($record); | ||
431 | |||
432 | $record->Save(); | ||
433 | $recordVersion->Save(); | ||
434 | } | ||
435 | |||
436 | $user->Save(); | ||
437 | |||
438 | $result["lock"] = $user->lock; | ||
439 | $result["result"] = "done"; | ||
440 | |||
441 | //============================================================= | ||
442 | } else if ($message == "getRecordDetail") { | ||
443 | //{ | ||
444 | //"message":"getRecordDetail", | ||
445 | //"srpSharedSecret":"4c00dcb66a9f2aea41a87e4707c526874e2eb29cc72d2c7086837e53d6bf2dfe", | ||
446 | //"parameters":{ | ||
447 | // "reference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50" | ||
448 | //} | ||
449 | //} | ||
450 | // | ||
451 | //result = { | ||
452 | // currentVersion:{ | ||
453 | // reference:"88943d709c3ea2442d4f58eaaec6409276037e5a37e0a6d167b9dad9e947e854", | ||
454 | // accessDate:"Wed, 13 February 2008 14:25:12 UTC", | ||
455 | // creationDate:"Tue, 17 April 2007 17:17:52 UTC", | ||
456 | // version:"0.2", | ||
457 | // data:"xI3WXddQLFtL......EGyKnnAVik", | ||
458 | // updateDate:"Tue, 17 April 2007 17:17:52 UTC", | ||
459 | // header:"####" | ||
460 | // } | ||
461 | // reference:"13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551", | ||
462 | // oldestUsedEncryptedVersion:"0.2", | ||
463 | // accessDate:"Wed, 13 February 2008 14:25:12 UTC", | ||
464 | // creationDate:"Wed, 14 March 2007 13:53:11 UTC", | ||
465 | // version:"0.2", | ||
466 | // updatedDate:"Tue, 17 April 2007 17:17:52 UTC", | ||
467 | // data:"0/BjzyY6jeh71h...pAw2++NEyylGhMC5C5f5m8pBApYziN84s4O3JQ3khW/1UttQl4=" | ||
468 | //} | ||
469 | $record = new record(); | ||
470 | |||
471 | $recordList = $record->GetList(array(array("reference", "=", $parameters["parameters"]["reference"]))); | ||
472 | $currentRecord = $recordList[0]; | ||
473 | $currentRecordVersions = $currentRecord->GetRecordversionList(); | ||
474 | $currentVersion = $currentRecordVersions[0]; | ||
475 | |||
476 | $result["currentVersion"] = array(); | ||
477 | $result["currentVersion"]["reference"] =$currentVersion->reference; | ||
478 | $result["currentVersion"]["data"] = $currentVersion->data; | ||
479 | $result["currentVersion"]["header"] = $currentVersion->header; | ||
480 | $result["currentVersion"]["version"] = $currentVersion->version; | ||
481 | $result["currentVersion"]["creationDate"] =$currentVersion->creation_date; | ||
482 | $result["currentVersion"]["updateDate"] =$currentVersion->update_date; | ||
483 | $result["currentVersion"]["accessDate"] =$currentVersion->access_date; | ||
484 | |||
485 | $result["reference"] = $currentRecord->reference; | ||
486 | $result["data"] = $currentRecord->data; | ||
487 | $result["version"] = $currentRecord->version; | ||
488 | $result["creationDate"] =$currentRecord->creation_date; | ||
489 | $result["updateDate"] = $currentRecord->update_date; | ||
490 | $result["accessDate"] = $currentRecord->access_date; | ||
491 | $result["oldestUsedEncryptedVersion"] ="---"; | ||
492 | |||
493 | //============================================================= | ||
494 | } else if ($message == "updateData") { | ||
495 | //{ | ||
496 | //"message":"updateData", | ||
497 | //"srpSharedSecret":"4e4aadb1d64513ec4dd42f5e8d5b2d4363de75e4424b6bcf178c9d6a246356c5", | ||
498 | //"parameters":{ | ||
499 | // "records":[ | ||
500 | // { | ||
501 | // "record":{ | ||
502 | // "reference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50", | ||
503 | // "data":"8hgR0Z+JDrUa812polDJ....JnZUKXNEqKI", | ||
504 | // "version":"0.3" | ||
505 | // }, | ||
506 | // "currentRecordVersion":{ | ||
507 | // "reference":"b1d82aeb9a0c4f6584bea68ba80839f43dd6ede79791549e29a1860554b144ee", | ||
508 | // "recordReference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50", | ||
509 | // "data":"2d/UgKxxV+kBPV9GRUE.....VGonDoW0tqefxOJo=", | ||
510 | // "version":"0.3", | ||
511 | // "previousVersion":"55904195249037394316d3be3f5e78f08073170103bf0e7ab49a911c159cb0be", | ||
512 | // "previousVersionKey":"YWiaZeMIVHaIl96OWW+2e8....6d6nHbn6cr2NA/dbQRuC2w==" | ||
513 | // } | ||
514 | // } | ||
515 | // ], | ||
516 | // "user":{ | ||
517 | // "header":"{\"rec.....sion\":\"0.1\"}", | ||
518 | // "statistics":"tt3uU9hWBy8rNnMckgCnxMJh", | ||
519 | // "version":"0.3", | ||
520 | // "lock":"----" | ||
521 | // } | ||
522 | //} | ||
523 | //} | ||
524 | |||
525 | $user = new user(); | ||
526 | $user = $user->Get($_SESSION["userId"]); | ||
527 | updateUserData($parameters["parameters"]["user"], $user); | ||
528 | $user->Save(); | ||
529 | |||
530 | $recordParameterList = $parameters["parameters"]["records"]; | ||
531 | $c = count($recordParameterList); | ||
532 | for ($i=0; $i<$c; $i++) { | ||
533 | $recordList = $user->GetRecordList(array(array("reference", "=", $recordParameterList[$i]["record"]["reference"]))); | ||
534 | $currentRecord = $recordList[0]; | ||
535 | $currentRecordVersions = $currentRecord->GetRecordversionList(); | ||
536 | $currentVersion = $currentRecordVersions[0]; | ||
537 | |||
538 | updateRecordData($recordParameterList[$i], $currentRecord, $currentVersion); | ||
539 | |||
540 | |||
541 | $currentRecord->Save(); | ||
542 | $currentVersion->Save(); | ||
543 | } | ||
544 | |||
545 | |||
546 | $result["lock"] = $user->lock; | ||
547 | $result["result"] = "done"; | ||
548 | |||
549 | //============================================================= | ||
550 | } else if ($message == "deleteRecords") { | ||
551 | //{ | ||
552 | //"message":"deleteRecords", | ||
553 | //"srpSharedSecret":"4a64982f7ee366954ec50b9efea62a902a097ef111410c2aa7c4d5343bd1cdd1", | ||
554 | //"parameters":{ | ||
555 | // "recordReferences":["46494c81d10b80ab190d41e6806ef63869cfcc7a0ab8fe98cc3f93de4729bb9a"], | ||
556 | // "user":{ | ||
557 | // "header":"{\"rec...rsion\":\"0.1\"}", | ||
558 | // "statistics":"44kOOda0xYZjbcugJBdagBQx", | ||
559 | // "version":"0.3", | ||
560 | // "lock":"----" | ||
561 | // } | ||
562 | //} | ||
563 | //} | ||
564 | $user = new user(); | ||
565 | $user = $user->Get($_SESSION["userId"]); | ||
566 | |||
567 | $recordReferenceList = $parameters["parameters"]["recordReferences"]; | ||
568 | $recordList = array(); | ||
569 | $c = count($recordReferenceList); | ||
570 | for ($i=0; $i<$c; $i++) { | ||
571 | array_push($recordList, array("reference", "=", $recordReferenceList[$i])); | ||
572 | } | ||
573 | |||
574 | $record = new record(); | ||
575 | $record->DeleteList($recordList, true); | ||
576 | |||
577 | updateUserData($parameters["parameters"]["user"], $user); | ||
578 | $user->Save(); | ||
579 | |||
580 | $result["recordList"] = $recordList; | ||
581 | $result["lock"] = $user->lock; | ||
582 | $result["result"] = "done"; | ||
583 | |||
584 | //============================================================= | ||
585 | } else if ($message == "deleteUser") { | ||
586 | //{"message":"deleteUser", "srpSharedSecret":"e8e4ca6544dca49c95b3647d8358ad54c317048b74d2ac187ac25f719c9bac58", "parameters":{}} | ||
587 | $user = new user(); | ||
588 | $user->Get($_SESSION["userId"]); | ||
589 | $user->Delete(true); | ||
590 | |||
591 | $result["result"] = "ok"; | ||
592 | |||
593 | //============================================================= | ||
594 | } else if ($message == "addNewOneTimePassword") { | ||
595 | //{ | ||
596 | //"message":"addNewOneTimePassword", | ||
597 | //"srpSharedSecret":"96fee4af06c09ce954fe7a9f87970e943449186bebf70bac0af1d6ebb818dabb", | ||
598 | //"parameters":{ | ||
599 | // "user":{ | ||
600 | // "header":"{\"records\":{\"index\":{\"419ea6....rsion\":\"0.1\"}", | ||
601 | // "statistics":"rrlwNbDt83rpWT4S72upiVsC", | ||
602 | // "version":"0.3", | ||
603 | // "lock":"----" | ||
604 | // }, | ||
605 | // "oneTimePassword":{ | ||
606 | // "reference":"29e26f3a2aae61fe5cf58c45296c6df4f3dceafe067ea550b455be345f44123c", | ||
607 | // "key":"afb848208758361a96a298b9db08995cf036011747809357a90645bc93fdfa03", | ||
608 | // "keyChecksum":"d1599ae443b5a566bfd93c0aeec4c81b42c0506ee09874dae050449580bb3486", | ||
609 | // "data":"hsyY8DHksgR52x6c4j7XAtIUeY.....dxsr3XWt7CbGg==", | ||
610 | // "version":"0.3" | ||
611 | // } | ||
612 | //} | ||
613 | //} | ||
614 | |||
615 | fixOTPStatusTable(); | ||
616 | |||
617 | $user = new user(); | ||
618 | $user = $user->Get($_SESSION["userId"]); | ||
619 | |||
620 | $otp = new onetimepassword(); | ||
621 | updateOTP($parameters["parameters"]["oneTimePassword"], $otp, "ACTIVE"); | ||
622 | $user->AddOnetimepassword($otp); | ||
623 | |||
624 | updateUserData($parameters["parameters"]["user"], $user); | ||
625 | $user->Save(); | ||
626 | |||
627 | $result["lock"] = $user->lock; | ||
628 | $result["result"] = "done"; | ||
629 | |||
630 | //============================================================= | ||
631 | } else if ($message == "updateOneTimePasswords") { | ||
632 | //{ | ||
633 | //"message":"updateOneTimePasswords", | ||
634 | //"srpSharedSecret":"c78f8ed099ea421f4dd0a4e02dbaf1f7da925f0088188d99399874ff064a3d27", | ||
635 | //"parameters":{ | ||
636 | // "user":{ | ||
637 | // "header":"{\"reco...sion\":\"0.1\"}", | ||
638 | // "statistics":"UeRq75RZHzDC7elzrh/+OB5d", | ||
639 | // "version":"0.3", | ||
640 | // "lock":"----" | ||
641 | // }, | ||
642 | // "oneTimePasswords":["f5f44c232f239efe48ab81a6236deea1a840d52946f7d4d782dad52b4c5359ce"] | ||
643 | //} | ||
644 | //} | ||
645 | |||
646 | $user = new user(); | ||
647 | $user = $user->Get($_SESSION["userId"]); | ||
648 | |||
649 | $validOtpReferences = $parameters["parameters"]["oneTimePasswords"]; | ||
650 | |||
651 | $otpList = $user->GetOnetimepasswordList(); | ||
652 | $c = count($otpList); | ||
653 | for ($i=0; $i<$c; $i++) { | ||
654 | $currentOtp = $otpList[$i]; | ||
655 | if (arrayContainsValue($validOtpReferences, $currentOtp->reference) == false) { | ||
656 | $currentOtp->Delete(); | ||
657 | } | ||
658 | } | ||
659 | |||
660 | updateUserData($parameters["parameters"]["user"], $user); | ||
661 | $user->Save(); | ||
662 | |||
663 | $result["result"] = $user->lock; | ||
664 | |||
665 | //============================================================= | ||
666 | } else if ($message == "getOneTimePasswordsDetails") { | ||
667 | |||
668 | //============================================================= | ||
669 | } else if ($message == "getLoginHistory") { | ||
670 | $result["result"] = array(); | ||
671 | |||
672 | //============================================================= | ||
673 | } else if ($message == "upgradeUserCredentials") { | ||
674 | //{ | ||
675 | //"message":"upgradeUserCredentials", | ||
676 | //"srpSharedSecret":"f1c25322e1478c8fb26063e9eef2f6fc25e0460065a31cb718f80bcff8f8a735", | ||
677 | //"parameters":{ | ||
678 | // "user":{ | ||
679 | // "header":"{\"reco...sion\":\"0.1\"}", | ||
680 | // "statistics":"s72Xva+w7CLgH+ihwqwXUbyu", | ||
681 | // "version":"0.3", | ||
682 | // "lock":"----" | ||
683 | // }, | ||
684 | // "credentials":{ | ||
685 | // "C":"57d15a8afbc1ae08103bd991d387ddfd8d26824276476fe709d754f098b6c26d", | ||
686 | // "s":"d6735fc0486f391c4f3c947928f9e61a2418e7bed2bc9b25bb43f93acc52f636", | ||
687 | // "v":"540c2ebbf941a481b6b2c9026c07fb46e8202e4408ed96864a696deb622baece", | ||
688 | // "version":"0.2" | ||
689 | // }, | ||
690 | // "oneTimePasswords":{ | ||
691 | // "923cdc61c4b877b263236124c44d69b459d240453a461cce8ddf7518b423ca94": "1HD6Ta0xsifEDhDwE....9WDK6tvrS6w==", | ||
692 | // "fb1573cb9497652a81688a099a524fb116e604c6fbc191cf33406eb8438efa5f": "CocN0cSxLmMRdgNF9....o3xhGUEY68Q==" | ||
693 | // } | ||
694 | //} | ||
695 | //} | ||
696 | |||
697 | $user = new user(); | ||
698 | $user->Get($_SESSION["userId"]); | ||
699 | |||
700 | $otp = new onetimepassword(); | ||
701 | |||
702 | updateUserCredentials($parameters["parameters"]["credentials"], $user); | ||
703 | updateUserData($parameters["parameters"]["user"], $user); | ||
704 | |||
705 | $otpList = $parameters["parameters"]["oneTimePasswords"]; | ||
706 | foreach($otpList as $otpReference=>$otpData) { | ||
707 | $otpList = $otp->GetList(array(array("reference", "=", $otpReference))); | ||
708 | $currentOtp = $otpList[0]; | ||
709 | $currentOtp->data = $otpData; | ||
710 | $currentOtp->Save(); | ||
711 | } | ||
712 | |||
713 | $user->Save(); | ||
714 | |||
715 | $result["lock"] = $user->lock; | ||
716 | $result["result"] = "done"; | ||
717 | |||
718 | //============================================================= | ||
719 | } else if ($message == "echo") { | ||
720 | $result["result"] = $parameters; | ||
721 | } | ||
722 | |||
723 | //============================================================= | ||
724 | } else { | ||
725 | $result["error"] = "Wrong shared secret!"; | ||
726 | } | ||
727 | break; | ||
728 | |||
729 | case "logout": | ||
730 | error_log("logout"); | ||
731 | session_destroy(); | ||
732 | break; | ||
733 | |||
734 | default: | ||
735 | error_log("default"); | ||
736 | $result["result"] = $parameters; | ||
737 | break; | ||
738 | } | ||
739 | |||
740 | session_write_close(); | ||
741 | |||
742 | echo(json_encode($result)); | ||
743 | error_log("result: ".json_encode($result)); | ||
744 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/json/JSON.php b/backend/php/src/json/JSON.php new file mode 100644 index 0000000..0cddbdd --- a/dev/null +++ b/backend/php/src/json/JSON.php | |||
@@ -0,0 +1,806 @@ | |||
1 | <?php | ||
2 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | ||
3 | |||
4 | /** | ||
5 | * Converts to and from JSON format. | ||
6 | * | ||
7 | * JSON (JavaScript Object Notation) is a lightweight data-interchange | ||
8 | * format. It is easy for humans to read and write. It is easy for machines | ||
9 | * to parse and generate. It is based on a subset of the JavaScript | ||
10 | * Programming Language, Standard ECMA-262 3rd Edition - December 1999. | ||
11 | * This feature can also be found in Python. JSON is a text format that is | ||
12 | * completely language independent but uses conventions that are familiar | ||
13 | * to programmers of the C-family of languages, including C, C++, C#, Java, | ||
14 | * JavaScript, Perl, TCL, and many others. These properties make JSON an | ||
15 | * ideal data-interchange language. | ||
16 | * | ||
17 | * This package provides a simple encoder and decoder for JSON notation. It | ||
18 | * is intended for use with client-side Javascript applications that make | ||
19 | * use of HTTPRequest to perform server communication functions - data can | ||
20 | * be encoded into JSON notation for use in a client-side javascript, or | ||
21 | * decoded from incoming Javascript requests. JSON format is native to | ||
22 | * Javascript, and can be directly eval()'ed with no further parsing | ||
23 | * overhead | ||
24 | * | ||
25 | * All strings should be in ASCII or UTF-8 format! | ||
26 | * | ||
27 | * LICENSE: Redistribution and use in source and binary forms, with or | ||
28 | * without modification, are permitted provided that the following | ||
29 | * conditions are met: Redistributions of source code must retain the | ||
30 | * above copyright notice, this list of conditions and the following | ||
31 | * disclaimer. Redistributions in binary form must reproduce the above | ||
32 | * copyright notice, this list of conditions and the following disclaimer | ||
33 | * in the documentation and/or other materials provided with the | ||
34 | * distribution. | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | ||
37 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
38 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN | ||
39 | * NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
41 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
42 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
44 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
45 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
46 | * DAMAGE. | ||
47 | * | ||
48 | * @category | ||
49 | * @package Services_JSON | ||
50 | * @author Michal Migurski <mike-json@teczno.com> | ||
51 | * @author Matt Knapp <mdknapp[at]gmail[dot]com> | ||
52 | * @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com> | ||
53 | * @copyright 2005 Michal Migurski | ||
54 | * @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $ | ||
55 | * @license http://www.opensource.org/licenses/bsd-license.php | ||
56 | * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198 | ||
57 | */ | ||
58 | |||
59 | /** | ||
60 | * Marker constant for Services_JSON::decode(), used to flag stack state | ||
61 | */ | ||
62 | define('SERVICES_JSON_SLICE', 1); | ||
63 | |||
64 | /** | ||
65 | * Marker constant for Services_JSON::decode(), used to flag stack state | ||
66 | */ | ||
67 | define('SERVICES_JSON_IN_STR', 2); | ||
68 | |||
69 | /** | ||
70 | * Marker constant for Services_JSON::decode(), used to flag stack state | ||
71 | */ | ||
72 | define('SERVICES_JSON_IN_ARR', 3); | ||
73 | |||
74 | /** | ||
75 | * Marker constant for Services_JSON::decode(), used to flag stack state | ||
76 | */ | ||
77 | define('SERVICES_JSON_IN_OBJ', 4); | ||
78 | |||
79 | /** | ||
80 | * Marker constant for Services_JSON::decode(), used to flag stack state | ||
81 | */ | ||
82 | define('SERVICES_JSON_IN_CMT', 5); | ||
83 | |||
84 | /** | ||
85 | * Behavior switch for Services_JSON::decode() | ||
86 | */ | ||
87 | define('SERVICES_JSON_LOOSE_TYPE', 16); | ||
88 | |||
89 | /** | ||
90 | * Behavior switch for Services_JSON::decode() | ||
91 | */ | ||
92 | define('SERVICES_JSON_SUPPRESS_ERRORS', 32); | ||
93 | |||
94 | /** | ||
95 | * Converts to and from JSON format. | ||
96 | * | ||
97 | * Brief example of use: | ||
98 | * | ||
99 | * <code> | ||
100 | * // create a new instance of Services_JSON | ||
101 | * $json = new Services_JSON(); | ||
102 | * | ||
103 | * // convert a complexe value to JSON notation, and send it to the browser | ||
104 | * $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4))); | ||
105 | * $output = $json->encode($value); | ||
106 | * | ||
107 | * print($output); | ||
108 | * // prints: ["foo","bar",[1,2,"baz"],[3,[4]]] | ||
109 | * | ||
110 | * // accept incoming POST data, assumed to be in JSON notation | ||
111 | * $input = file_get_contents('php://input', 1000000); | ||
112 | * $value = $json->decode($input); | ||
113 | * </code> | ||
114 | */ | ||
115 | class Services_JSON | ||
116 | { | ||
117 | /** | ||
118 | * constructs a new JSON instance | ||
119 | * | ||
120 | * @param int $use object behavior flags; combine with boolean-OR | ||
121 | * | ||
122 | * possible values: | ||
123 | * - SERVICES_JSON_LOOSE_TYPE: loose typing. | ||
124 | * "{...}" syntax creates associative arrays | ||
125 | * instead of objects in decode(). | ||
126 | * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression. | ||
127 | * Values which can't be encoded (e.g. resources) | ||
128 | * appear as NULL instead of throwing errors. | ||
129 | * By default, a deeply-nested resource will | ||
130 | * bubble up with an error, so all return values | ||
131 | * from encode() should be checked with isError() | ||
132 | */ | ||
133 | function Services_JSON($use = 0) | ||
134 | { | ||
135 | $this->use = $use; | ||
136 | } | ||
137 | |||
138 | /** | ||
139 | * convert a string from one UTF-16 char to one UTF-8 char | ||
140 | * | ||
141 | * Normally should be handled by mb_convert_encoding, but | ||
142 | * provides a slower PHP-only method for installations | ||
143 | * that lack the multibye string extension. | ||
144 | * | ||
145 | * @param string $utf16 UTF-16 character | ||
146 | * @return string UTF-8 character | ||
147 | * @access private | ||
148 | */ | ||
149 | function utf162utf8($utf16) | ||
150 | { | ||
151 | // oh please oh please oh please oh please oh please | ||
152 | if(function_exists('mb_convert_encoding')) { | ||
153 | return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); | ||
154 | } | ||
155 | |||
156 | $bytes = (ord($utf16{0}) << 8) | ord($utf16{1}); | ||
157 | |||
158 | switch(true) { | ||
159 | case ((0x7F & $bytes) == $bytes): | ||
160 | // this case should never be reached, because we are in ASCII range | ||
161 | // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
162 | return chr(0x7F & $bytes); | ||
163 | |||
164 | case (0x07FF & $bytes) == $bytes: | ||
165 | // return a 2-byte UTF-8 character | ||
166 | // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
167 | return chr(0xC0 | (($bytes >> 6) & 0x1F)) | ||
168 | . chr(0x80 | ($bytes & 0x3F)); | ||
169 | |||
170 | case (0xFFFF & $bytes) == $bytes: | ||
171 | // return a 3-byte UTF-8 character | ||
172 | // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
173 | return chr(0xE0 | (($bytes >> 12) & 0x0F)) | ||
174 | . chr(0x80 | (($bytes >> 6) & 0x3F)) | ||
175 | . chr(0x80 | ($bytes & 0x3F)); | ||
176 | } | ||
177 | |||
178 | // ignoring UTF-32 for now, sorry | ||
179 | return ''; | ||
180 | } | ||
181 | |||
182 | /** | ||
183 | * convert a string from one UTF-8 char to one UTF-16 char | ||
184 | * | ||
185 | * Normally should be handled by mb_convert_encoding, but | ||
186 | * provides a slower PHP-only method for installations | ||
187 | * that lack the multibye string extension. | ||
188 | * | ||
189 | * @param string $utf8 UTF-8 character | ||
190 | * @return string UTF-16 character | ||
191 | * @access private | ||
192 | */ | ||
193 | function utf82utf16($utf8) | ||
194 | { | ||
195 | // oh please oh please oh please oh please oh please | ||
196 | if(function_exists('mb_convert_encoding')) { | ||
197 | return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); | ||
198 | } | ||
199 | |||
200 | switch(strlen($utf8)) { | ||
201 | case 1: | ||
202 | // this case should never be reached, because we are in ASCII range | ||
203 | // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
204 | return $utf8; | ||
205 | |||
206 | case 2: | ||
207 | // return a UTF-16 character from a 2-byte UTF-8 char | ||
208 | // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
209 | return chr(0x07 & (ord($utf8{0}) >> 2)) | ||
210 | . chr((0xC0 & (ord($utf8{0}) << 6)) | ||
211 | | (0x3F & ord($utf8{1}))); | ||
212 | |||
213 | case 3: | ||
214 | // return a UTF-16 character from a 3-byte UTF-8 char | ||
215 | // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
216 | return chr((0xF0 & (ord($utf8{0}) << 4)) | ||
217 | | (0x0F & (ord($utf8{1}) >> 2))) | ||
218 | . chr((0xC0 & (ord($utf8{1}) << 6)) | ||
219 | | (0x7F & ord($utf8{2}))); | ||
220 | } | ||
221 | |||
222 | // ignoring UTF-32 for now, sorry | ||
223 | return ''; | ||
224 | } | ||
225 | |||
226 | /** | ||
227 | * encodes an arbitrary variable into JSON format | ||
228 | * | ||
229 | * @param mixed $var any number, boolean, string, array, or object to be encoded. | ||
230 | * see argument 1 to Services_JSON() above for array-parsing behavior. | ||
231 | * if var is a strng, note that encode() always expects it | ||
232 | * to be in ASCII or UTF-8 format! | ||
233 | * | ||
234 | * @return mixed JSON string representation of input var or an error if a problem occurs | ||
235 | * @access public | ||
236 | */ | ||
237 | function encode($var) | ||
238 | { | ||
239 | switch (gettype($var)) { | ||
240 | case 'boolean': | ||
241 | return $var ? 'true' : 'false'; | ||
242 | |||
243 | case 'NULL': | ||
244 | return 'null'; | ||
245 | |||
246 | case 'integer': | ||
247 | return (int) $var; | ||
248 | |||
249 | case 'double': | ||
250 | case 'float': | ||
251 | return (float) $var; | ||
252 | |||
253 | case 'string': | ||
254 | // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT | ||
255 | $ascii = ''; | ||
256 | $strlen_var = strlen($var); | ||
257 | |||
258 | /* | ||
259 | * Iterate over every character in the string, | ||
260 | * escaping with a slash or encoding to UTF-8 where necessary | ||
261 | */ | ||
262 | for ($c = 0; $c < $strlen_var; ++$c) { | ||
263 | |||
264 | $ord_var_c = ord($var{$c}); | ||
265 | |||
266 | switch (true) { | ||
267 | case $ord_var_c == 0x08: | ||
268 | $ascii .= '\b'; | ||
269 | break; | ||
270 | case $ord_var_c == 0x09: | ||
271 | $ascii .= '\t'; | ||
272 | break; | ||
273 | case $ord_var_c == 0x0A: | ||
274 | $ascii .= '\n'; | ||
275 | break; | ||
276 | case $ord_var_c == 0x0C: | ||
277 | $ascii .= '\f'; | ||
278 | break; | ||
279 | case $ord_var_c == 0x0D: | ||
280 | $ascii .= '\r'; | ||
281 | break; | ||
282 | |||
283 | case $ord_var_c == 0x22: | ||
284 | case $ord_var_c == 0x2F: | ||
285 | case $ord_var_c == 0x5C: | ||
286 | // double quote, slash, slosh | ||
287 | $ascii .= '\\'.$var{$c}; | ||
288 | break; | ||
289 | |||
290 | case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): | ||
291 | // characters U-00000000 - U-0000007F (same as ASCII) | ||
292 | $ascii .= $var{$c}; | ||
293 | break; | ||
294 | |||
295 | case (($ord_var_c & 0xE0) == 0xC0): | ||
296 | // characters U-00000080 - U-000007FF, mask 110XXXXX | ||
297 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
298 | $char = pack('C*', $ord_var_c, ord($var{$c + 1})); | ||
299 | $c += 1; | ||
300 | $utf16 = $this->utf82utf16($char); | ||
301 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); | ||
302 | break; | ||
303 | |||
304 | case (($ord_var_c & 0xF0) == 0xE0): | ||
305 | // characters U-00000800 - U-0000FFFF, mask 1110XXXX | ||
306 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
307 | $char = pack('C*', $ord_var_c, | ||
308 | ord($var{$c + 1}), | ||
309 | ord($var{$c + 2})); | ||
310 | $c += 2; | ||
311 | $utf16 = $this->utf82utf16($char); | ||
312 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); | ||
313 | break; | ||
314 | |||
315 | case (($ord_var_c & 0xF8) == 0xF0): | ||
316 | // characters U-00010000 - U-001FFFFF, mask 11110XXX | ||
317 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
318 | $char = pack('C*', $ord_var_c, | ||
319 | ord($var{$c + 1}), | ||
320 | ord($var{$c + 2}), | ||
321 | ord($var{$c + 3})); | ||
322 | $c += 3; | ||
323 | $utf16 = $this->utf82utf16($char); | ||
324 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); | ||
325 | break; | ||
326 | |||
327 | case (($ord_var_c & 0xFC) == 0xF8): | ||
328 | // characters U-00200000 - U-03FFFFFF, mask 111110XX | ||
329 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
330 | $char = pack('C*', $ord_var_c, | ||
331 | ord($var{$c + 1}), | ||
332 | ord($var{$c + 2}), | ||
333 | ord($var{$c + 3}), | ||
334 | ord($var{$c + 4})); | ||
335 | $c += 4; | ||
336 | $utf16 = $this->utf82utf16($char); | ||
337 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); | ||
338 | break; | ||
339 | |||
340 | case (($ord_var_c & 0xFE) == 0xFC): | ||
341 | // characters U-04000000 - U-7FFFFFFF, mask 1111110X | ||
342 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
343 | $char = pack('C*', $ord_var_c, | ||
344 | ord($var{$c + 1}), | ||
345 | ord($var{$c + 2}), | ||
346 | ord($var{$c + 3}), | ||
347 | ord($var{$c + 4}), | ||
348 | ord($var{$c + 5})); | ||
349 | $c += 5; | ||
350 | $utf16 = $this->utf82utf16($char); | ||
351 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); | ||
352 | break; | ||
353 | } | ||
354 | } | ||
355 | |||
356 | return '"'.$ascii.'"'; | ||
357 | |||
358 | case 'array': | ||
359 | /* | ||
360 | * As per JSON spec if any array key is not an integer | ||
361 | * we must treat the the whole array as an object. We | ||
362 | * also try to catch a sparsely populated associative | ||
363 | * array with numeric keys here because some JS engines | ||
364 | * will create an array with empty indexes up to | ||
365 | * max_index which can cause memory issues and because | ||
366 | * the keys, which may be relevant, will be remapped | ||
367 | * otherwise. | ||
368 | * | ||
369 | * As per the ECMA and JSON specification an object may | ||
370 | * have any string as a property. Unfortunately due to | ||
371 | * a hole in the ECMA specification if the key is a | ||
372 | * ECMA reserved word or starts with a digit the | ||
373 | * parameter is only accessible using ECMAScript's | ||
374 | * bracket notation. | ||
375 | */ | ||
376 | |||
377 | // treat as a JSON object | ||
378 | if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) { | ||
379 | $properties = array_map(array($this, 'name_value'), | ||
380 | array_keys($var), | ||
381 | array_values($var)); | ||
382 | |||
383 | foreach($properties as $property) { | ||
384 | if(Services_JSON::isError($property)) { | ||
385 | return $property; | ||
386 | } | ||
387 | } | ||
388 | |||
389 | return '{' . join(',', $properties) . '}'; | ||
390 | } | ||
391 | |||
392 | // treat it like a regular array | ||
393 | $elements = array_map(array($this, 'encode'), $var); | ||
394 | |||
395 | foreach($elements as $element) { | ||
396 | if(Services_JSON::isError($element)) { | ||
397 | return $element; | ||
398 | } | ||
399 | } | ||
400 | |||
401 | return '[' . join(',', $elements) . ']'; | ||
402 | |||
403 | case 'object': | ||
404 | $vars = get_object_vars($var); | ||
405 | |||
406 | $properties = array_map(array($this, 'name_value'), | ||
407 | array_keys($vars), | ||
408 | array_values($vars)); | ||
409 | |||
410 | foreach($properties as $property) { | ||
411 | if(Services_JSON::isError($property)) { | ||
412 | return $property; | ||
413 | } | ||
414 | } | ||
415 | |||
416 | return '{' . join(',', $properties) . '}'; | ||
417 | |||
418 | default: | ||
419 | return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) | ||
420 | ? 'null' | ||
421 | : new Services_JSON_Error(gettype($var)." can not be encoded as JSON string"); | ||
422 | } | ||
423 | } | ||
424 | |||
425 | /** | ||
426 | * array-walking function for use in generating JSON-formatted name-value pairs | ||
427 | * | ||
428 | * @param string $name name of key to use | ||
429 | * @param mixed $value reference to an array element to be encoded | ||
430 | * | ||
431 | * @return string JSON-formatted name-value pair, like '"name":value' | ||
432 | * @access private | ||
433 | */ | ||
434 | function name_value($name, $value) | ||
435 | { | ||
436 | $encoded_value = $this->encode($value); | ||
437 | |||
438 | if(Services_JSON::isError($encoded_value)) { | ||
439 | return $encoded_value; | ||
440 | } | ||
441 | |||
442 | return $this->encode(strval($name)) . ':' . $encoded_value; | ||
443 | } | ||
444 | |||
445 | /** | ||
446 | * reduce a string by removing leading and trailing comments and whitespace | ||
447 | * | ||
448 | * @param $str string string value to strip of comments and whitespace | ||
449 | * | ||
450 | * @return string string value stripped of comments and whitespace | ||
451 | * @access private | ||
452 | */ | ||
453 | function reduce_string($str) | ||
454 | { | ||
455 | $str = preg_replace(array( | ||
456 | |||
457 | // eliminate single line comments in '// ...' form | ||
458 | '#^\s*//(.+)$#m', | ||
459 | |||
460 | // eliminate multi-line comments in '/* ... */' form, at start of string | ||
461 | '#^\s*/\*(.+)\*/#Us', | ||
462 | |||
463 | // eliminate multi-line comments in '/* ... */' form, at end of string | ||
464 | '#/\*(.+)\*/\s*$#Us' | ||
465 | |||
466 | ), '', $str); | ||
467 | |||
468 | // eliminate extraneous space | ||
469 | return trim($str); | ||
470 | } | ||
471 | |||
472 | /** | ||
473 | * decodes a JSON string into appropriate variable | ||
474 | * | ||
475 | * @param string $str JSON-formatted string | ||
476 | * | ||
477 | * @return mixed number, boolean, string, array, or object | ||
478 | * corresponding to given JSON input string. | ||
479 | * See argument 1 to Services_JSON() above for object-output behavior. | ||
480 | * Note that decode() always returns strings | ||
481 | * in ASCII or UTF-8 format! | ||
482 | * @access public | ||
483 | */ | ||
484 | function decode($str) | ||
485 | { | ||
486 | $str = $this->reduce_string($str); | ||
487 | |||
488 | switch (strtolower($str)) { | ||
489 | case 'true': | ||
490 | return true; | ||
491 | |||
492 | case 'false': | ||
493 | return false; | ||
494 | |||
495 | case 'null': | ||
496 | return null; | ||
497 | |||
498 | default: | ||
499 | $m = array(); | ||
500 | |||
501 | if (is_numeric($str)) { | ||
502 | // Lookie-loo, it's a number | ||
503 | |||
504 | // This would work on its own, but I'm trying to be | ||
505 | // good about returning integers where appropriate: | ||
506 | // return (float)$str; | ||
507 | |||
508 | // Return float or int, as appropriate | ||
509 | return ((float)$str == (integer)$str) | ||
510 | ? (integer)$str | ||
511 | : (float)$str; | ||
512 | |||
513 | } elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) { | ||
514 | // STRINGS RETURNED IN UTF-8 FORMAT | ||
515 | $delim = substr($str, 0, 1); | ||
516 | $chrs = substr($str, 1, -1); | ||
517 | $utf8 = ''; | ||
518 | $strlen_chrs = strlen($chrs); | ||
519 | |||
520 | for ($c = 0; $c < $strlen_chrs; ++$c) { | ||
521 | |||
522 | $substr_chrs_c_2 = substr($chrs, $c, 2); | ||
523 | $ord_chrs_c = ord($chrs{$c}); | ||
524 | |||
525 | switch (true) { | ||
526 | case $substr_chrs_c_2 == '\b': | ||
527 | $utf8 .= chr(0x08); | ||
528 | ++$c; | ||
529 | break; | ||
530 | case $substr_chrs_c_2 == '\t': | ||
531 | $utf8 .= chr(0x09); | ||
532 | ++$c; | ||
533 | break; | ||
534 | case $substr_chrs_c_2 == '\n': | ||
535 | $utf8 .= chr(0x0A); | ||
536 | ++$c; | ||
537 | break; | ||
538 | case $substr_chrs_c_2 == '\f': | ||
539 | $utf8 .= chr(0x0C); | ||
540 | ++$c; | ||
541 | break; | ||
542 | case $substr_chrs_c_2 == '\r': | ||
543 | $utf8 .= chr(0x0D); | ||
544 | ++$c; | ||
545 | break; | ||
546 | |||
547 | case $substr_chrs_c_2 == '\\"': | ||
548 | case $substr_chrs_c_2 == '\\\'': | ||
549 | case $substr_chrs_c_2 == '\\\\': | ||
550 | case $substr_chrs_c_2 == '\\/': | ||
551 | if (($delim == '"' && $substr_chrs_c_2 != '\\\'') || | ||
552 | ($delim == "'" && $substr_chrs_c_2 != '\\"')) { | ||
553 | $utf8 .= $chrs{++$c}; | ||
554 | } | ||
555 | break; | ||
556 | |||
557 | case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)): | ||
558 | // single, escaped unicode character | ||
559 | $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2))) | ||
560 | . chr(hexdec(substr($chrs, ($c + 4), 2))); | ||
561 | $utf8 .= $this->utf162utf8($utf16); | ||
562 | $c += 5; | ||
563 | break; | ||
564 | |||
565 | case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): | ||
566 | $utf8 .= $chrs{$c}; | ||
567 | break; | ||
568 | |||
569 | case ($ord_chrs_c & 0xE0) == 0xC0: | ||
570 | // characters U-00000080 - U-000007FF, mask 110XXXXX | ||
571 | //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
572 | $utf8 .= substr($chrs, $c, 2); | ||
573 | ++$c; | ||
574 | break; | ||
575 | |||
576 | case ($ord_chrs_c & 0xF0) == 0xE0: | ||
577 | // characters U-00000800 - U-0000FFFF, mask 1110XXXX | ||
578 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
579 | $utf8 .= substr($chrs, $c, 3); | ||
580 | $c += 2; | ||
581 | break; | ||
582 | |||
583 | case ($ord_chrs_c & 0xF8) == 0xF0: | ||
584 | // characters U-00010000 - U-001FFFFF, mask 11110XXX | ||
585 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
586 | $utf8 .= substr($chrs, $c, 4); | ||
587 | $c += 3; | ||
588 | break; | ||
589 | |||
590 | case ($ord_chrs_c & 0xFC) == 0xF8: | ||
591 | // characters U-00200000 - U-03FFFFFF, mask 111110XX | ||
592 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
593 | $utf8 .= substr($chrs, $c, 5); | ||
594 | $c += 4; | ||
595 | break; | ||
596 | |||
597 | case ($ord_chrs_c & 0xFE) == 0xFC: | ||
598 | // characters U-04000000 - U-7FFFFFFF, mask 1111110X | ||
599 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 | ||
600 | $utf8 .= substr($chrs, $c, 6); | ||
601 | $c += 5; | ||
602 | break; | ||
603 | |||
604 | } | ||
605 | |||
606 | } | ||
607 | |||
608 | return $utf8; | ||
609 | |||
610 | } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { | ||
611 | // array, or object notation | ||
612 | |||
613 | if ($str{0} == '[') { | ||
614 | $stk = array(SERVICES_JSON_IN_ARR); | ||
615 | $arr = array(); | ||
616 | } else { | ||
617 | if ($this->use & SERVICES_JSON_LOOSE_TYPE) { | ||
618 | $stk = array(SERVICES_JSON_IN_OBJ); | ||
619 | $obj = array(); | ||
620 | } else { | ||
621 | $stk = array(SERVICES_JSON_IN_OBJ); | ||
622 | $obj = new stdClass(); | ||
623 | } | ||
624 | } | ||
625 | |||
626 | array_push($stk, array('what' => SERVICES_JSON_SLICE, | ||
627 | 'where' => 0, | ||
628 | 'delim' => false)); | ||
629 | |||
630 | $chrs = substr($str, 1, -1); | ||
631 | $chrs = $this->reduce_string($chrs); | ||
632 | |||
633 | if ($chrs == '') { | ||
634 | if (reset($stk) == SERVICES_JSON_IN_ARR) { | ||
635 | return $arr; | ||
636 | |||
637 | } else { | ||
638 | return $obj; | ||
639 | |||
640 | } | ||
641 | } | ||
642 | |||
643 | //print("\nparsing {$chrs}\n"); | ||
644 | |||
645 | $strlen_chrs = strlen($chrs); | ||
646 | |||
647 | for ($c = 0; $c <= $strlen_chrs; ++$c) { | ||
648 | |||
649 | $top = end($stk); | ||
650 | $substr_chrs_c_2 = substr($chrs, $c, 2); | ||
651 | |||
652 | if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) { | ||
653 | // found a comma that is not inside a string, array, etc., | ||
654 | // OR we've reached the end of the character list | ||
655 | $slice = substr($chrs, $top['where'], ($c - $top['where'])); | ||
656 | array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false)); | ||
657 | //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); | ||
658 | |||
659 | if (reset($stk) == SERVICES_JSON_IN_ARR) { | ||
660 | // we are in an array, so just push an element onto the stack | ||
661 | array_push($arr, $this->decode($slice)); | ||
662 | |||
663 | } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { | ||
664 | // we are in an object, so figure | ||
665 | // out the property name and set an | ||
666 | // element in an associative array, | ||
667 | // for now | ||
668 | $parts = array(); | ||
669 | |||
670 | if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { | ||
671 | // "name":value pair | ||
672 | $key = $this->decode($parts[1]); | ||
673 | $val = $this->decode($parts[2]); | ||
674 | |||
675 | if ($this->use & SERVICES_JSON_LOOSE_TYPE) { | ||
676 | $obj[$key] = $val; | ||
677 | } else { | ||
678 | $obj->$key = $val; | ||
679 | } | ||
680 | } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { | ||
681 | // name:value pair, where name is unquoted | ||
682 | $key = $parts[1]; | ||
683 | $val = $this->decode($parts[2]); | ||
684 | |||
685 | if ($this->use & SERVICES_JSON_LOOSE_TYPE) { | ||
686 | $obj[$key] = $val; | ||
687 | } else { | ||
688 | $obj->$key = $val; | ||
689 | } | ||
690 | } | ||
691 | |||
692 | } | ||
693 | |||
694 | } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) { | ||
695 | // found a quote, and we are not inside a string | ||
696 | array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c})); | ||
697 | //print("Found start of string at {$c}\n"); | ||
698 | |||
699 | } elseif (($chrs{$c} == $top['delim']) && | ||
700 | ($top['what'] == SERVICES_JSON_IN_STR) && | ||
701 | ((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) { | ||
702 | // found a quote, we're in a string, and it's not escaped | ||
703 | // we know that it's not escaped becase there is _not_ an | ||
704 | // odd number of backslashes at the end of the string so far | ||
705 | array_pop($stk); | ||
706 | //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); | ||
707 | |||
708 | } elseif (($chrs{$c} == '[') && | ||
709 | in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { | ||
710 | // found a left-bracket, and we are in an array, object, or slice | ||
711 | array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false)); | ||
712 | //print("Found start of array at {$c}\n"); | ||
713 | |||
714 | } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) { | ||
715 | // found a right-bracket, and we're in an array | ||
716 | array_pop($stk); | ||
717 | //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); | ||
718 | |||
719 | } elseif (($chrs{$c} == '{') && | ||
720 | in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { | ||
721 | // found a left-brace, and we are in an array, object, or slice | ||
722 | array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false)); | ||
723 | //print("Found start of object at {$c}\n"); | ||
724 | |||
725 | } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) { | ||
726 | // found a right-brace, and we're in an object | ||
727 | array_pop($stk); | ||
728 | //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); | ||
729 | |||
730 | } elseif (($substr_chrs_c_2 == '/*') && | ||
731 | in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { | ||
732 | // found a comment start, and we are in an array, object, or slice | ||
733 | array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false)); | ||
734 | $c++; | ||
735 | //print("Found start of comment at {$c}\n"); | ||
736 | |||
737 | } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) { | ||
738 | // found a comment end, and we're in one now | ||
739 | array_pop($stk); | ||
740 | $c++; | ||
741 | |||
742 | for ($i = $top['where']; $i <= $c; ++$i) | ||
743 | $chrs = substr_replace($chrs, ' ', $i, 1); | ||
744 | |||
745 | //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); | ||
746 | |||
747 | } | ||
748 | |||
749 | } | ||
750 | |||
751 | if (reset($stk) == SERVICES_JSON_IN_ARR) { | ||
752 | return $arr; | ||
753 | |||
754 | } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { | ||
755 | return $obj; | ||
756 | |||
757 | } | ||
758 | |||
759 | } | ||
760 | } | ||
761 | } | ||
762 | |||
763 | /** | ||
764 | * @todo Ultimately, this should just call PEAR::isError() | ||
765 | */ | ||
766 | function isError($data, $code = null) | ||
767 | { | ||
768 | if (class_exists('pear')) { | ||
769 | return PEAR::isError($data, $code); | ||
770 | } elseif (is_object($data) && (get_class($data) == 'services_json_error' || | ||
771 | is_subclass_of($data, 'services_json_error'))) { | ||
772 | return true; | ||
773 | } | ||
774 | |||
775 | return false; | ||
776 | } | ||
777 | } | ||
778 | |||
779 | if (class_exists('PEAR_Error')) { | ||
780 | |||
781 | class Services_JSON_Error extends PEAR_Error | ||
782 | { | ||
783 | function Services_JSON_Error($message = 'unknown error', $code = null, | ||
784 | $mode = null, $options = null, $userinfo = null) | ||
785 | { | ||
786 | parent::PEAR_Error($message, $code, $mode, $options, $userinfo); | ||
787 | } | ||
788 | } | ||
789 | |||
790 | } else { | ||
791 | |||
792 | /** | ||
793 | * @todo Ultimately, this class shall be descended from PEAR_Error | ||
794 | */ | ||
795 | class Services_JSON_Error | ||
796 | { | ||
797 | function Services_JSON_Error($message = 'unknown error', $code = null, | ||
798 | $mode = null, $options = null, $userinfo = null) | ||
799 | { | ||
800 | |||
801 | } | ||
802 | } | ||
803 | |||
804 | } | ||
805 | |||
806 | ?> | ||
diff --git a/backend/php/src/objects/class.database.php b/backend/php/src/objects/class.database.php new file mode 100644 index 0000000..e8a13f7 --- a/dev/null +++ b/backend/php/src/objects/class.database.php | |||
@@ -0,0 +1,79 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * <b>Database Connection</b> class. | ||
4 | * @author Php Object Generator | ||
5 | * @version 3.0d / PHP5.1 | ||
6 | * @see http://www.phpobjectgenerator.com/ | ||
7 | * @copyright Free for personal & commercial use. (Offered under the BSD license) | ||
8 | */ | ||
9 | Class Database | ||
10 | { | ||
11 | public $connection; | ||
12 | |||
13 | private function Database() | ||
14 | { | ||
15 | $databaseName = $GLOBALS['configuration']['db']; | ||
16 | $serverName = $GLOBALS['configuration']['host']; | ||
17 | $databaseUser = $GLOBALS['configuration']['user']; | ||
18 | $databasePassword = $GLOBALS['configuration']['pass']; | ||
19 | $databasePort = $GLOBALS['configuration']['port']; | ||
20 | $this->connection = mysql_connect ($serverName.":".$databasePort, $databaseUser, $databasePassword); | ||
21 | if ($this->connection) | ||
22 | { | ||
23 | if (!mysql_select_db ($databaseName)) | ||
24 | { | ||
25 | throw new Exception('I cannot find the specified database "'.$databaseName.'". Please edit configuration.php.'); | ||
26 | } | ||
27 | } | ||
28 | else | ||
29 | { | ||
30 | throw new Exception('I cannot connect to the database. Please edit configuration.php with your database configuration.'); | ||
31 | } | ||
32 | } | ||
33 | |||
34 | public static function Connect() | ||
35 | { | ||
36 | static $database = null; | ||
37 | if (!isset($database)) | ||
38 | { | ||
39 | $database = new Database(); | ||
40 | } | ||
41 | return $database->connection; | ||
42 | } | ||
43 | |||
44 | public static function Reader($query, $connection) | ||
45 | { | ||
46 | $cursor = mysql_query($query, $connection); | ||
47 | return $cursor; | ||
48 | } | ||
49 | |||
50 | public static function Read($cursor) | ||
51 | { | ||
52 | return mysql_fetch_assoc($cursor); | ||
53 | } | ||
54 | |||
55 | public static function NonQuery($query, $connection) | ||
56 | { | ||
57 | mysql_query($query, $connection); | ||
58 | $result = mysql_affected_rows($connection); | ||
59 | if ($result == -1) | ||
60 | { | ||
61 | return false; | ||
62 | } | ||
63 | return $result; | ||
64 | |||
65 | } | ||
66 | |||
67 | public static function Query($query, $connection) | ||
68 | { | ||
69 | $result = mysql_query($query, $connection); | ||
70 | return mysql_num_rows($result); | ||
71 | } | ||
72 | |||
73 | public static function InsertOrUpdate($query, $connection) | ||
74 | { | ||
75 | $result = mysql_query($query, $connection); | ||
76 | return intval(mysql_insert_id($connection)); | ||
77 | } | ||
78 | } | ||
79 | ?> | ||
diff --git a/backend/php/src/objects/class.onetimepassword.php b/backend/php/src/objects/class.onetimepassword.php new file mode 100644 index 0000000..90d5f1d --- a/dev/null +++ b/backend/php/src/objects/class.onetimepassword.php | |||
@@ -0,0 +1,400 @@ | |||
1 | <?php | ||
2 | /* | ||
3 | This SQL query will create the table to store your object. | ||
4 | |||
5 | CREATE TABLE `onetimepassword` ( | ||
6 | `onetimepasswordid` int(11) NOT NULL auto_increment, | ||
7 | `userid` int(11) NOT NULL, | ||
8 | `onetimepasswordstatusid` int(11) NOT NULL, | ||
9 | `reference` VARCHAR(255) NOT NULL, | ||
10 | `key` VARCHAR(255) NOT NULL, | ||
11 | `key_checksum` VARCHAR(255) NOT NULL, | ||
12 | `data` TEXT NOT NULL, | ||
13 | `version` VARCHAR(255) NOT NULL, | ||
14 | `creation_date` TIMESTAMP NOT NULL, | ||
15 | `request_date` TIMESTAMP NOT NULL, | ||
16 | `usage_date` TIMESTAMP NOT NULL, INDEX(`userid`,`onetimepasswordstatusid`), PRIMARY KEY (`onetimepasswordid`)) ENGINE=MyISAM; | ||
17 | */ | ||
18 | |||
19 | /** | ||
20 | * <b>onetimepassword</b> class with integrated CRUD methods. | ||
21 | * @author Php Object Generator | ||
22 | * @version POG 3.0d / PHP5.1 | ||
23 | * @copyright Free for personal & commercial use. (Offered under the BSD license) | ||
24 | * @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pog&objectName=onetimepassword&attributeList=array+%28%0A++0+%3D%3E+%27user%27%2C%0A++1+%3D%3E+%27onetimepasswordstatus%27%2C%0A++2+%3D%3E+%27reference%27%2C%0A++3+%3D%3E+%27key%27%2C%0A++4+%3D%3E+%27key_checksum%27%2C%0A++5+%3D%3E+%27data%27%2C%0A++6+%3D%3E+%27version%27%2C%0A++7+%3D%3E+%27creation_date%27%2C%0A++8+%3D%3E+%27request_date%27%2C%0A++9+%3D%3E+%27usage_date%27%2C%0A%29&typeList=array+%28%0A++0+%3D%3E+%27BELONGSTO%27%2C%0A++1+%3D%3E+%27BELONGSTO%27%2C%0A++2+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++3+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++4+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++5+%3D%3E+%27TEXT%27%2C%0A++6+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++7+%3D%3E+%27TIMESTAMP%27%2C%0A++8+%3D%3E+%27TIMESTAMP%27%2C%0A++9+%3D%3E+%27TIMESTAMP%27%2C%0A%29 | ||
25 | */ | ||
26 | include_once('class.pog_base.php'); | ||
27 | class onetimepassword extends POG_Base | ||
28 | { | ||
29 | public $onetimepasswordId = ''; | ||
30 | |||
31 | /** | ||
32 | * @var INT(11) | ||
33 | */ | ||
34 | public $userId; | ||
35 | |||
36 | /** | ||
37 | * @var INT(11) | ||
38 | */ | ||
39 | public $onetimepasswordstatusId; | ||
40 | |||
41 | /** | ||
42 | * @var VARCHAR(255) | ||
43 | */ | ||
44 | public $reference; | ||
45 | |||
46 | /** | ||
47 | * @var VARCHAR(255) | ||
48 | */ | ||
49 | public $key; | ||
50 | |||
51 | /** | ||
52 | * @var VARCHAR(255) | ||
53 | */ | ||
54 | public $key_checksum; | ||
55 | |||
56 | /** | ||
57 | * @var TEXT | ||
58 | */ | ||
59 | public $data; | ||
60 | |||
61 | /** | ||
62 | * @var VARCHAR(255) | ||
63 | */ | ||
64 | public $version; | ||
65 | |||
66 | /** | ||
67 | * @var TIMESTAMP | ||
68 | */ | ||
69 | public $creation_date; | ||
70 | |||
71 | /** | ||
72 | * @var TIMESTAMP | ||
73 | */ | ||
74 | public $request_date; | ||
75 | |||
76 | /** | ||
77 | * @var TIMESTAMP | ||
78 | */ | ||
79 | public $usage_date; | ||
80 | |||
81 | public $pog_attribute_type = array( | ||
82 | "onetimepasswordId" => array('db_attributes' => array("NUMERIC", "INT")), | ||
83 | "user" => array('db_attributes' => array("OBJECT", "BELONGSTO")), | ||
84 | "onetimepasswordstatus" => array('db_attributes' => array("OBJECT", "BELONGSTO")), | ||
85 | "reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
86 | "key" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
87 | "key_checksum" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
88 | "data" => array('db_attributes' => array("TEXT", "TEXT")), | ||
89 | "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
90 | "creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), | ||
91 | "request_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), | ||
92 | "usage_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), | ||
93 | ); | ||
94 | public $pog_query; | ||
95 | |||
96 | |||
97 | /** | ||
98 | * Getter for some private attributes | ||
99 | * @return mixed $attribute | ||
100 | */ | ||
101 | public function __get($attribute) | ||
102 | { | ||
103 | if (isset($this->{"_".$attribute})) | ||
104 | { | ||
105 | return $this->{"_".$attribute}; | ||
106 | } | ||
107 | else | ||
108 | { | ||
109 | return false; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | function onetimepassword($reference='', $key='', $key_checksum='', $data='', $version='', $creation_date='', $request_date='', $usage_date='') | ||
114 | { | ||
115 | $this->reference = $reference; | ||
116 | $this->key = $key; | ||
117 | $this->key_checksum = $key_checksum; | ||
118 | $this->data = $data; | ||
119 | $this->version = $version; | ||
120 | $this->creation_date = $creation_date; | ||
121 | $this->request_date = $request_date; | ||
122 | $this->usage_date = $usage_date; | ||
123 | } | ||
124 | |||
125 | |||
126 | /** | ||
127 | * Gets object from database | ||
128 | * @param integer $onetimepasswordId | ||
129 | * @return object $onetimepassword | ||
130 | */ | ||
131 | function Get($onetimepasswordId) | ||
132 | { | ||
133 | $connection = Database::Connect(); | ||
134 | $this->pog_query = "select * from `onetimepassword` where `onetimepasswordid`='".intval($onetimepasswordId)."' LIMIT 1"; | ||
135 | $cursor = Database::Reader($this->pog_query, $connection); | ||
136 | while ($row = Database::Read($cursor)) | ||
137 | { | ||
138 | $this->onetimepasswordId = $row['onetimepasswordid']; | ||
139 | $this->userId = $row['userid']; | ||
140 | $this->onetimepasswordstatusId = $row['onetimepasswordstatusid']; | ||
141 | $this->reference = $this->Unescape($row['reference']); | ||
142 | $this->key = $this->Unescape($row['key']); | ||
143 | $this->key_checksum = $this->Unescape($row['key_checksum']); | ||
144 | $this->data = $this->Unescape($row['data']); | ||
145 | $this->version = $this->Unescape($row['version']); | ||
146 | $this->creation_date = $row['creation_date']; | ||
147 | $this->request_date = $row['request_date']; | ||
148 | $this->usage_date = $row['usage_date']; | ||
149 | } | ||
150 | return $this; | ||
151 | } | ||
152 | |||
153 | |||
154 | /** | ||
155 | * Returns a sorted array of objects that match given conditions | ||
156 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
157 | * @param string $sortBy | ||
158 | * @param boolean $ascending | ||
159 | * @param int limit | ||
160 | * @return array $onetimepasswordList | ||
161 | */ | ||
162 | function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') | ||
163 | { | ||
164 | $connection = Database::Connect(); | ||
165 | $sqlLimit = ($limit != '' ? "LIMIT $limit" : ''); | ||
166 | $this->pog_query = "select * from `onetimepassword` "; | ||
167 | $onetimepasswordList = Array(); | ||
168 | if (sizeof($fcv_array) > 0) | ||
169 | { | ||
170 | $this->pog_query .= " where "; | ||
171 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) | ||
172 | { | ||
173 | if (sizeof($fcv_array[$i]) == 1) | ||
174 | { | ||
175 | $this->pog_query .= " ".$fcv_array[$i][0]." "; | ||
176 | continue; | ||
177 | } | ||
178 | else | ||
179 | { | ||
180 | if ($i > 0 && sizeof($fcv_array[$i-1]) != 1) | ||
181 | { | ||
182 | $this->pog_query .= " AND "; | ||
183 | } | ||
184 | if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET') | ||
185 | { | ||
186 | if ($GLOBALS['configuration']['db_encoding'] == 1) | ||
187 | { | ||
188 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'"; | ||
189 | $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value; | ||
190 | } | ||
191 | else | ||
192 | { | ||
193 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'"; | ||
194 | $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value; | ||
195 | } | ||
196 | } | ||
197 | else | ||
198 | { | ||
199 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'"; | ||
200 | $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value; | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | } | ||
205 | if ($sortBy != '') | ||
206 | { | ||
207 | if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET') | ||
208 | { | ||
209 | if ($GLOBALS['configuration']['db_encoding'] == 1) | ||
210 | { | ||
211 | $sortBy = "BASE64_DECODE($sortBy) "; | ||
212 | } | ||
213 | else | ||
214 | { | ||
215 | $sortBy = "$sortBy "; | ||
216 | } | ||
217 | } | ||
218 | else | ||
219 | { | ||
220 | $sortBy = "$sortBy "; | ||
221 | } | ||
222 | } | ||
223 | else | ||
224 | { | ||
225 | $sortBy = "onetimepasswordid"; | ||
226 | } | ||
227 | $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit"; | ||
228 | $thisObjectName = get_class($this); | ||
229 | $cursor = Database::Reader($this->pog_query, $connection); | ||
230 | while ($row = Database::Read($cursor)) | ||
231 | { | ||
232 | $onetimepassword = new $thisObjectName(); | ||
233 | $onetimepassword->onetimepasswordId = $row['onetimepasswordid']; | ||
234 | $onetimepassword->userId = $row['userid']; | ||
235 | $onetimepassword->onetimepasswordstatusId = $row['onetimepasswordstatusid']; | ||
236 | $onetimepassword->reference = $this->Unescape($row['reference']); | ||
237 | $onetimepassword->key = $this->Unescape($row['key']); | ||
238 | $onetimepassword->key_checksum = $this->Unescape($row['key_checksum']); | ||
239 | $onetimepassword->data = $this->Unescape($row['data']); | ||
240 | $onetimepassword->version = $this->Unescape($row['version']); | ||
241 | $onetimepassword->creation_date = $row['creation_date']; | ||
242 | $onetimepassword->request_date = $row['request_date']; | ||
243 | $onetimepassword->usage_date = $row['usage_date']; | ||
244 | $onetimepasswordList[] = $onetimepassword; | ||
245 | } | ||
246 | return $onetimepasswordList; | ||
247 | } | ||
248 | |||
249 | |||
250 | /** | ||
251 | * Saves the object to the database | ||
252 | * @return integer $onetimepasswordId | ||
253 | */ | ||
254 | function Save() | ||
255 | { | ||
256 | $connection = Database::Connect(); | ||
257 | $this->pog_query = "select `onetimepasswordid` from `onetimepassword` where `onetimepasswordid`='".$this->onetimepasswordId."' LIMIT 1"; | ||
258 | $rows = Database::Query($this->pog_query, $connection); | ||
259 | if ($rows > 0) | ||
260 | { | ||
261 | $this->pog_query = "update `onetimepassword` set | ||
262 | `userid`='".$this->userId."', | ||
263 | `onetimepasswordstatusid`='".$this->onetimepasswordstatusId."', | ||
264 | `reference`='".$this->Escape($this->reference)."', | ||
265 | `key`='".$this->Escape($this->key)."', | ||
266 | `key_checksum`='".$this->Escape($this->key_checksum)."', | ||
267 | `data`='".$this->Escape($this->data)."', | ||
268 | `version`='".$this->Escape($this->version)."', | ||
269 | `creation_date`='".$this->creation_date."', | ||
270 | `request_date`='".$this->request_date."', | ||
271 | `usage_date`='".$this->usage_date."' where `onetimepasswordid`='".$this->onetimepasswordId."'"; | ||
272 | } | ||
273 | else | ||
274 | { | ||
275 | $this->pog_query = "insert into `onetimepassword` (`userid`, `onetimepasswordstatusid`, `reference`, `key`, `key_checksum`, `data`, `version`, `creation_date`, `request_date`, `usage_date` ) values ( | ||
276 | '".$this->userId."', | ||
277 | '".$this->onetimepasswordstatusId."', | ||
278 | '".$this->Escape($this->reference)."', | ||
279 | '".$this->Escape($this->key)."', | ||
280 | '".$this->Escape($this->key_checksum)."', | ||
281 | '".$this->Escape($this->data)."', | ||
282 | '".$this->Escape($this->version)."', | ||
283 | '".$this->creation_date."', | ||
284 | '".$this->request_date."', | ||
285 | '".$this->usage_date."' )"; | ||
286 | } | ||
287 | $insertId = Database::InsertOrUpdate($this->pog_query, $connection); | ||
288 | if ($this->onetimepasswordId == "") | ||
289 | { | ||
290 | $this->onetimepasswordId = $insertId; | ||
291 | } | ||
292 | return $this->onetimepasswordId; | ||
293 | } | ||
294 | |||
295 | |||
296 | /** | ||
297 | * Clones the object and saves it to the database | ||
298 | * @return integer $onetimepasswordId | ||
299 | */ | ||
300 | function SaveNew() | ||
301 | { | ||
302 | $this->onetimepasswordId = ''; | ||
303 | return $this->Save(); | ||
304 | } | ||
305 | |||
306 | |||
307 | /** | ||
308 | * Deletes the object from the database | ||
309 | * @return boolean | ||
310 | */ | ||
311 | function Delete() | ||
312 | { | ||
313 | $connection = Database::Connect(); | ||
314 | $this->pog_query = "delete from `onetimepassword` where `onetimepasswordid`='".$this->onetimepasswordId."'"; | ||
315 | return Database::NonQuery($this->pog_query, $connection); | ||
316 | } | ||
317 | |||
318 | |||
319 | /** | ||
320 | * Deletes a list of objects that match given conditions | ||
321 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
322 | * @param bool $deep | ||
323 | * @return | ||
324 | */ | ||
325 | function DeleteList($fcv_array) | ||
326 | { | ||
327 | if (sizeof($fcv_array) > 0) | ||
328 | { | ||
329 | $connection = Database::Connect(); | ||
330 | $pog_query = "delete from `onetimepassword` where "; | ||
331 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) | ||
332 | { | ||
333 | if (sizeof($fcv_array[$i]) == 1) | ||
334 | { | ||
335 | $pog_query .= " ".$fcv_array[$i][0]." "; | ||
336 | continue; | ||
337 | } | ||
338 | else | ||
339 | { | ||
340 | if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1) | ||
341 | { | ||
342 | $pog_query .= " AND "; | ||
343 | } | ||
344 | if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET') | ||
345 | { | ||
346 | $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'"; | ||
347 | } | ||
348 | else | ||
349 | { | ||
350 | $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'"; | ||
351 | } | ||
352 | } | ||
353 | } | ||
354 | return Database::NonQuery($pog_query, $connection); | ||
355 | } | ||
356 | } | ||
357 | |||
358 | |||
359 | /** | ||
360 | * Associates the user object to this one | ||
361 | * @return boolean | ||
362 | */ | ||
363 | function GetUser() | ||
364 | { | ||
365 | $user = new user(); | ||
366 | return $user->Get($this->userId); | ||
367 | } | ||
368 | |||
369 | |||
370 | /** | ||
371 | * Associates the user object to this one | ||
372 | * @return | ||
373 | */ | ||
374 | function SetUser(&$user) | ||
375 | { | ||
376 | $this->userId = $user->userId; | ||
377 | } | ||
378 | |||
379 | |||
380 | /** | ||
381 | * Associates the onetimepasswordstatus object to this one | ||
382 | * @return boolean | ||
383 | */ | ||
384 | function GetOnetimepasswordstatus() | ||
385 | { | ||
386 | $onetimepasswordstatus = new onetimepasswordstatus(); | ||
387 | return $onetimepasswordstatus->Get($this->onetimepasswordstatusId); | ||
388 | } | ||
389 | |||
390 | |||
391 | /** | ||
392 | * Associates the onetimepasswordstatus object to this one | ||
393 | * @return | ||
394 | */ | ||
395 | function SetOnetimepasswordstatus(&$onetimepasswordstatus) | ||
396 | { | ||
397 | $this->onetimepasswordstatusId = $onetimepasswordstatus->onetimepasswordstatusId; | ||
398 | } | ||
399 | } | ||
400 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/objects/class.onetimepasswordstatus.php b/backend/php/src/objects/class.onetimepasswordstatus.php new file mode 100644 index 0000000..f0ef08a --- a/dev/null +++ b/backend/php/src/objects/class.onetimepasswordstatus.php | |||
@@ -0,0 +1,368 @@ | |||
1 | <?php | ||
2 | /* | ||
3 | This SQL query will create the table to store your object. | ||
4 | |||
5 | CREATE TABLE `onetimepasswordstatus` ( | ||
6 | `onetimepasswordstatusid` int(11) NOT NULL auto_increment, | ||
7 | `code` VARCHAR(255) NOT NULL, | ||
8 | `name` VARCHAR(255) NOT NULL, | ||
9 | `description` TEXT NOT NULL, PRIMARY KEY (`onetimepasswordstatusid`)) ENGINE=MyISAM; | ||
10 | */ | ||
11 | |||
12 | /** | ||
13 | * <b>onetimepasswordstatus</b> class with integrated CRUD methods. | ||
14 | * @author Php Object Generator | ||
15 | * @version POG 3.0d / PHP5.1 MYSQL | ||
16 | * @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql | ||
17 | * @copyright Free for personal & commercial use. (Offered under the BSD license) | ||
18 | * @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pdo&pdoDriver=mysql&objectName=onetimepasswordstatus&attributeList=array+%28%0A++0+%3D%3E+%27onetimepassword%27%2C%0A++1+%3D%3E+%27code%27%2C%0A++2+%3D%3E+%27name%27%2C%0A++3+%3D%3E+%27description%27%2C%0A%29&typeList=array%2B%2528%250A%2B%2B0%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2B%2B1%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B2%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B3%2B%253D%253E%2B%2527TEXT%2527%252C%250A%2529 | ||
19 | */ | ||
20 | include_once('class.pog_base.php'); | ||
21 | class onetimepasswordstatus extends POG_Base | ||
22 | { | ||
23 | public $onetimepasswordstatusId = ''; | ||
24 | |||
25 | /** | ||
26 | * @var private array of onetimepassword objects | ||
27 | */ | ||
28 | private $_onetimepasswordList = array(); | ||
29 | |||
30 | /** | ||
31 | * @var VARCHAR(255) | ||
32 | */ | ||
33 | public $code; | ||
34 | |||
35 | /** | ||
36 | * @var VARCHAR(255) | ||
37 | */ | ||
38 | public $name; | ||
39 | |||
40 | /** | ||
41 | * @var TEXT | ||
42 | */ | ||
43 | public $description; | ||
44 | |||
45 | public $pog_attribute_type = array( | ||
46 | "onetimepasswordstatusId" => array('db_attributes' => array("NUMERIC", "INT")), | ||
47 | "onetimepassword" => array('db_attributes' => array("OBJECT", "HASMANY")), | ||
48 | "code" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
49 | "name" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
50 | "description" => array('db_attributes' => array("TEXT", "TEXT")), | ||
51 | ); | ||
52 | public $pog_query; | ||
53 | |||
54 | |||
55 | /** | ||
56 | * Getter for some private attributes | ||
57 | * @return mixed $attribute | ||
58 | */ | ||
59 | public function __get($attribute) | ||
60 | { | ||
61 | if (isset($this->{"_".$attribute})) | ||
62 | { | ||
63 | return $this->{"_".$attribute}; | ||
64 | } | ||
65 | else | ||
66 | { | ||
67 | return false; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | function onetimepasswordstatus($code='', $name='', $description='') | ||
72 | { | ||
73 | $this->_onetimepasswordList = array(); | ||
74 | $this->code = $code; | ||
75 | $this->name = $name; | ||
76 | $this->description = $description; | ||
77 | } | ||
78 | |||
79 | |||
80 | /** | ||
81 | * Gets object from database | ||
82 | * @param integer $onetimepasswordstatusId | ||
83 | * @return object $onetimepasswordstatus | ||
84 | */ | ||
85 | function Get($onetimepasswordstatusId) | ||
86 | { | ||
87 | $connection = Database::Connect(); | ||
88 | $this->pog_query = "select * from `onetimepasswordstatus` where `onetimepasswordstatusid`='".intval($onetimepasswordstatusId)."' LIMIT 1"; | ||
89 | $cursor = Database::Reader($this->pog_query, $connection); | ||
90 | while ($row = Database::Read($cursor)) | ||
91 | { | ||
92 | $this->onetimepasswordstatusId = $row['onetimepasswordstatusid']; | ||
93 | $this->code = $this->Unescape($row['code']); | ||
94 | $this->name = $this->Unescape($row['name']); | ||
95 | $this->description = $this->Unescape($row['description']); | ||
96 | } | ||
97 | return $this; | ||
98 | } | ||
99 | |||
100 | |||
101 | /** | ||
102 | * Returns a sorted array of objects that match given conditions | ||
103 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
104 | * @param string $sortBy | ||
105 | * @param boolean $ascending | ||
106 | * @param int limit | ||
107 | * @return array $onetimepasswordstatusList | ||
108 | */ | ||
109 | function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') | ||
110 | { | ||
111 | $connection = Database::Connect(); | ||
112 | $sqlLimit = ($limit != '' ? "LIMIT $limit" : ''); | ||
113 | $this->pog_query = "select * from `onetimepasswordstatus` "; | ||
114 | $onetimepasswordstatusList = Array(); | ||
115 | if (sizeof($fcv_array) > 0) | ||
116 | { | ||
117 | $this->pog_query .= " where "; | ||
118 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) | ||
119 | { | ||
120 | if (sizeof($fcv_array[$i]) == 1) | ||
121 | { | ||
122 | $this->pog_query .= " ".$fcv_array[$i][0]." "; | ||
123 | continue; | ||
124 | } | ||
125 | else | ||
126 | { | ||
127 | if ($i > 0 && sizeof($fcv_array[$i-1]) != 1) | ||
128 | { | ||
129 | $this->pog_query .= " AND "; | ||
130 | } | ||
131 | if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET') | ||
132 | { | ||
133 | if ($GLOBALS['configuration']['db_encoding'] == 1) | ||
134 | { | ||
135 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'"; | ||
136 | $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value; | ||
137 | } | ||
138 | else | ||
139 | { | ||
140 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'"; | ||
141 | $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value; | ||
142 | } | ||
143 | } | ||
144 | else | ||
145 | { | ||
146 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'"; | ||
147 | $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value; | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | } | ||
152 | if ($sortBy != '') | ||
153 | { | ||
154 | if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET') | ||
155 | { | ||
156 | if ($GLOBALS['configuration']['db_encoding'] == 1) | ||
157 | { | ||
158 | $sortBy = "BASE64_DECODE($sortBy) "; | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | $sortBy = "$sortBy "; | ||
163 | } | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | $sortBy = "$sortBy "; | ||
168 | } | ||
169 | } | ||
170 | else | ||
171 | { | ||
172 | $sortBy = "onetimepasswordstatusid"; | ||
173 | } | ||
174 | $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit"; | ||
175 | $thisObjectName = get_class($this); | ||
176 | $cursor = Database::Reader($this->pog_query, $connection); | ||
177 | while ($row = Database::Read($cursor)) | ||
178 | { | ||
179 | $onetimepasswordstatus = new $thisObjectName(); | ||
180 | $onetimepasswordstatus->onetimepasswordstatusId = $row['onetimepasswordstatusid']; | ||
181 | $onetimepasswordstatus->code = $this->Unescape($row['code']); | ||
182 | $onetimepasswordstatus->name = $this->Unescape($row['name']); | ||
183 | $onetimepasswordstatus->description = $this->Unescape($row['description']); | ||
184 | $onetimepasswordstatusList[] = $onetimepasswordstatus; | ||
185 | } | ||
186 | return $onetimepasswordstatusList; | ||
187 | } | ||
188 | |||
189 | |||
190 | /** | ||
191 | * Saves the object to the database | ||
192 | * @return integer $onetimepasswordstatusId | ||
193 | */ | ||
194 | function Save($deep = true) | ||
195 | { | ||
196 | $connection = Database::Connect(); | ||
197 | $this->pog_query = "select `onetimepasswordstatusid` from `onetimepasswordstatus` where `onetimepasswordstatusid`='".$this->onetimepasswordstatusId."' LIMIT 1"; | ||
198 | $rows = Database::Query($this->pog_query, $connection); | ||
199 | if ($rows > 0) | ||
200 | { | ||
201 | $this->pog_query = "update `onetimepasswordstatus` set | ||
202 | `code`='".$this->Escape($this->code)."', | ||
203 | `name`='".$this->Escape($this->name)."', | ||
204 | `description`='".$this->Escape($this->description)."' where `onetimepasswordstatusid`='".$this->onetimepasswordstatusId."'"; | ||
205 | } | ||
206 | else | ||
207 | { | ||
208 | $this->pog_query = "insert into `onetimepasswordstatus` (`code`, `name`, `description` ) values ( | ||
209 | '".$this->Escape($this->code)."', | ||
210 | '".$this->Escape($this->name)."', | ||
211 | '".$this->Escape($this->description)."' )"; | ||
212 | } | ||
213 | $insertId = Database::InsertOrUpdate($this->pog_query, $connection); | ||
214 | if ($this->onetimepasswordstatusId == "") | ||
215 | { | ||
216 | $this->onetimepasswordstatusId = $insertId; | ||
217 | } | ||
218 | if ($deep) | ||
219 | { | ||
220 | foreach ($this->_onetimepasswordList as $onetimepassword) | ||
221 | { | ||
222 | $onetimepassword->onetimepasswordstatusId = $this->onetimepasswordstatusId; | ||
223 | $onetimepassword->Save($deep); | ||
224 | } | ||
225 | } | ||
226 | return $this->onetimepasswordstatusId; | ||
227 | } | ||
228 | |||
229 | |||
230 | /** | ||
231 | * Clones the object and saves it to the database | ||
232 | * @return integer $onetimepasswordstatusId | ||
233 | */ | ||
234 | function SaveNew($deep = false) | ||
235 | { | ||
236 | $this->onetimepasswordstatusId = ''; | ||
237 | return $this->Save($deep); | ||
238 | } | ||
239 | |||
240 | |||
241 | /** | ||
242 | * Deletes the object from the database | ||
243 | * @return boolean | ||
244 | */ | ||
245 | function Delete($deep = false, $across = false) | ||
246 | { | ||
247 | if ($deep) | ||
248 | { | ||
249 | $onetimepasswordList = $this->GetOnetimepasswordList(); | ||
250 | foreach ($onetimepasswordList as $onetimepassword) | ||
251 | { | ||
252 | $onetimepassword->Delete($deep, $across); | ||
253 | } | ||
254 | } | ||
255 | $connection = Database::Connect(); | ||
256 | $this->pog_query = "delete from `onetimepasswordstatus` where `onetimepasswordstatusid`='".$this->onetimepasswordstatusId."'"; | ||
257 | return Database::NonQuery($this->pog_query, $connection); | ||
258 | } | ||
259 | |||
260 | |||
261 | /** | ||
262 | * Deletes a list of objects that match given conditions | ||
263 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
264 | * @param bool $deep | ||
265 | * @return | ||
266 | */ | ||
267 | function DeleteList($fcv_array, $deep = false, $across = false) | ||
268 | { | ||
269 | if (sizeof($fcv_array) > 0) | ||
270 | { | ||
271 | if ($deep || $across) | ||
272 | { | ||
273 | $objectList = $this->GetList($fcv_array); | ||
274 | foreach ($objectList as $object) | ||
275 | { | ||
276 | $object->Delete($deep, $across); | ||
277 | } | ||
278 | } | ||
279 | else | ||
280 | { | ||
281 | $connection = Database::Connect(); | ||
282 | $pog_query = "delete from `onetimepasswordstatus` where "; | ||
283 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) | ||
284 | { | ||
285 | if (sizeof($fcv_array[$i]) == 1) | ||
286 | { | ||
287 | $pog_query .= " ".$fcv_array[$i][0]." "; | ||
288 | continue; | ||
289 | } | ||
290 | else | ||
291 | { | ||
292 | if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1) | ||
293 | { | ||
294 | $pog_query .= " AND "; | ||
295 | } | ||
296 | if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET') | ||
297 | { | ||
298 | $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'"; | ||
299 | } | ||
300 | else | ||
301 | { | ||
302 | $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'"; | ||
303 | } | ||
304 | } | ||
305 | } | ||
306 | return Database::NonQuery($pog_query, $connection); | ||
307 | } | ||
308 | } | ||
309 | } | ||
310 | |||
311 | |||
312 | /** | ||
313 | * Gets a list of onetimepassword objects associated to this one | ||
314 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
315 | * @param string $sortBy | ||
316 | * @param boolean $ascending | ||
317 | * @param int limit | ||
318 | * @return array of onetimepassword objects | ||
319 | */ | ||
320 | function GetOnetimepasswordList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') | ||
321 | { | ||
322 | $onetimepassword = new onetimepassword(); | ||
323 | $fcv_array[] = array("onetimepasswordstatusId", "=", $this->onetimepasswordstatusId); | ||
324 | $dbObjects = $onetimepassword->GetList($fcv_array, $sortBy, $ascending, $limit); | ||
325 | return $dbObjects; | ||
326 | } | ||
327 | |||
328 | |||
329 | /** | ||
330 | * Makes this the parent of all onetimepassword objects in the onetimepassword List array. Any existing onetimepassword will become orphan(s) | ||
331 | * @return null | ||
332 | */ | ||
333 | function SetOnetimepasswordList(&$list) | ||
334 | { | ||
335 | $this->_onetimepasswordList = array(); | ||
336 | $existingOnetimepasswordList = $this->GetOnetimepasswordList(); | ||
337 | foreach ($existingOnetimepasswordList as $onetimepassword) | ||
338 | { | ||
339 | $onetimepassword->onetimepasswordstatusId = ''; | ||
340 | $onetimepassword->Save(false); | ||
341 | } | ||
342 | $this->_onetimepasswordList = $list; | ||
343 | } | ||
344 | |||
345 | |||
346 | /** | ||
347 | * Associates the onetimepassword object to this one | ||
348 | * @return | ||
349 | */ | ||
350 | function AddOnetimepassword(&$onetimepassword) | ||
351 | { | ||
352 | $onetimepassword->onetimepasswordstatusId = $this->onetimepasswordstatusId; | ||
353 | $found = false; | ||
354 | foreach($this->_onetimepasswordList as $onetimepassword2) | ||
355 | { | ||
356 | if ($onetimepassword->onetimepasswordId > 0 && $onetimepassword->onetimepasswordId == $onetimepassword2->onetimepasswordId) | ||
357 | { | ||
358 | $found = true; | ||
359 | break; | ||
360 | } | ||
361 | } | ||
362 | if (!$found) | ||
363 | { | ||
364 | $this->_onetimepasswordList[] = $onetimepassword; | ||
365 | } | ||
366 | } | ||
367 | } | ||
368 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/objects/class.pog_base.php b/backend/php/src/objects/class.pog_base.php new file mode 100644 index 0000000..6a8f570 --- a/dev/null +++ b/backend/php/src/objects/class.pog_base.php | |||
@@ -0,0 +1,143 @@ | |||
1 | <?php | ||
2 | class POG_Base | ||
3 | { | ||
4 | /** | ||
5 | * Overloading | ||
6 | */ | ||
7 | function __call($method, $argv) | ||
8 | { | ||
9 | include_once($GLOBALS['configuration']['plugins_path']."/IPlugin.php"); | ||
10 | include_once($GLOBALS['configuration']['plugins_path']."/plugin.".strtolower($method).".php"); | ||
11 | eval('$plugin = new $method($this,$argv);'); | ||
12 | return $plugin->Execute(); | ||
13 | } | ||
14 | |||
15 | /** | ||
16 | * constructor | ||
17 | * | ||
18 | * @return POG_Base | ||
19 | */ | ||
20 | private function POG_Base() | ||
21 | { | ||
22 | } | ||
23 | |||
24 | |||
25 | function SetFieldAttribute($fieldName, $attributeName, $attributeValue) | ||
26 | { | ||
27 | if (isset($this->pog_attribute_type[$fieldName]) && isset($this->pog_attribute_type[$fieldName][$attributeName])) | ||
28 | { | ||
29 | $this->pog_attribute_type[$fieldName][$attributeName] = $attributeValue; | ||
30 | } | ||
31 | } | ||
32 | |||
33 | function GetFieldAttribute($fieldName, $attributeName) | ||
34 | { | ||
35 | if (isset($this->pog_attribute_type[$fieldName]) && isset($this->pog_attribute_type[$fieldName][$attributeName])) | ||
36 | { | ||
37 | return $this->pog_attribute_type[$fieldName][$attributeName]; | ||
38 | } | ||
39 | return null; | ||
40 | } | ||
41 | |||
42 | /////////////////////////// | ||
43 | // Data manipulation | ||
44 | /////////////////////////// | ||
45 | |||
46 | /** | ||
47 | * This function will try to encode $text to base64, except when $text is a number. This allows us to Escape all data before they're inserted in the database, regardless of attribute type. | ||
48 | * @param string $text | ||
49 | * @return string encoded to base64 | ||
50 | */ | ||
51 | public function Escape($text) | ||
52 | { | ||
53 | if ($GLOBALS['configuration']['db_encoding'] && !is_numeric($text)) | ||
54 | { | ||
55 | return base64_encode($text); | ||
56 | } | ||
57 | return addslashes($text); | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * Enter description here... | ||
62 | * | ||
63 | * @param unknown_type $text | ||
64 | * @return unknown | ||
65 | */ | ||
66 | public function Unescape($text) | ||
67 | { | ||
68 | if ($GLOBALS['configuration']['db_encoding'] && !is_numeric($text)) | ||
69 | { | ||
70 | return base64_decode($text); | ||
71 | } | ||
72 | return stripcslashes($text); | ||
73 | } | ||
74 | |||
75 | |||
76 | //////////////////////////////// | ||
77 | // Table -> Object Mapping | ||
78 | //////////////////////////////// | ||
79 | |||
80 | /** | ||
81 | * Executes $query against database and returns the result set as an array of POG objects | ||
82 | * | ||
83 | * @param string $query. SQL query to execute against database | ||
84 | * @param string $objectClass. POG Object type to return | ||
85 | * @param bool $lazy. If true, will also load all children/sibling | ||
86 | */ | ||
87 | public function FetchObjects($query, $objectClass, $lazy = true) | ||
88 | { | ||
89 | $databaseConnection = Database::Connect(); | ||
90 | $result = Database::Query($query, $databaseConnection); | ||
91 | $objectList = $this->CreateObjects($result, $objectClass, $lazy); | ||
92 | return $objectList; | ||
93 | } | ||
94 | |||
95 | private function CreateObjects($mysql_result, $objectClass, $lazyLoad = true) | ||
96 | { | ||
97 | $objectList = array(); | ||
98 | while ($row = mysql_fetch_assoc($mysql_result)) | ||
99 | { | ||
100 | $pog_object = new $objectClass(); | ||
101 | $this->PopulateObjectAttributes($row, $pog_object); | ||
102 | $objectList[] = $pog_object; | ||
103 | } | ||
104 | return $objectList; | ||
105 | } | ||
106 | |||
107 | private function PopulateObjectAttributes($fetched_row, $pog_object) | ||
108 | { | ||
109 | foreach ($this->GetAttributes($pog_object) as $column) | ||
110 | { | ||
111 | $pog_object->{$column} = $this->Unescape($fetched_row[strtolower($column)]); | ||
112 | } | ||
113 | return $pog_object; | ||
114 | } | ||
115 | |||
116 | private function GetAttributes($object) | ||
117 | { | ||
118 | $columns = array(); | ||
119 | foreach ($object->pog_attribute_type as $att => $properties) | ||
120 | { | ||
121 | if ($properties['db_attributes'][0] != 'OBJECT') | ||
122 | { | ||
123 | $columns[] = $att; | ||
124 | } | ||
125 | } | ||
126 | return $columns; | ||
127 | } | ||
128 | |||
129 | //misc | ||
130 | public static function IsColumn($value) | ||
131 | { | ||
132 | if (strlen($value) > 2) | ||
133 | { | ||
134 | if (substr($value, 0, 1) == '`' && substr($value, strlen($value) - 1, 1) == '`') | ||
135 | { | ||
136 | return true; | ||
137 | } | ||
138 | return false; | ||
139 | } | ||
140 | return false; | ||
141 | } | ||
142 | } | ||
143 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/objects/class.record.php b/backend/php/src/objects/class.record.php new file mode 100644 index 0000000..a269e75 --- a/dev/null +++ b/backend/php/src/objects/class.record.php | |||
@@ -0,0 +1,436 @@ | |||
1 | <?php | ||
2 | /* | ||
3 | This SQL query will create the table to store your object. | ||
4 | |||
5 | CREATE TABLE `record` ( | ||
6 | `recordid` int(11) NOT NULL auto_increment, | ||
7 | `userid` int(11) NOT NULL, | ||
8 | `reference` VARCHAR(255) NOT NULL, | ||
9 | `data` LONGTEXT NOT NULL, | ||
10 | `version` VARCHAR(255) NOT NULL, | ||
11 | `creation_date` TIMESTAMP NOT NULL, | ||
12 | `update_date` TIMESTAMP NOT NULL, | ||
13 | `access_date` TIMESTAMP NOT NULL, INDEX(`userid`), PRIMARY KEY (`recordid`)) ENGINE=MyISAM; | ||
14 | */ | ||
15 | |||
16 | /** | ||
17 | * <b>record</b> class with integrated CRUD methods. | ||
18 | * @author Php Object Generator | ||
19 | * @version POG 3.0e / PHP5.1 MYSQL | ||
20 | * @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql | ||
21 | * @copyright Free for personal & commercial use. (Offered under the BSD license) | ||
22 | * @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pdo&pdoDriver=mysql&objectName=record&attributeList=array+%28%0A++0+%3D%3E+%27user%27%2C%0A++1+%3D%3E+%27recordversion%27%2C%0A++2+%3D%3E+%27reference%27%2C%0A++3+%3D%3E+%27data%27%2C%0A++4+%3D%3E+%27version%27%2C%0A++5+%3D%3E+%27creation_date%27%2C%0A++6+%3D%3E+%27update_date%27%2C%0A++7+%3D%3E+%27access_date%27%2C%0A%29&typeList=array%2B%2528%250A%2B%2B0%2B%253D%253E%2B%2527BELONGSTO%2527%252C%250A%2B%2B1%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2B%2B2%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B3%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B4%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B5%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B6%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B7%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2529 | ||
23 | */ | ||
24 | include_once('class.pog_base.php'); | ||
25 | class record extends POG_Base | ||
26 | { | ||
27 | public $recordId = ''; | ||
28 | |||
29 | /** | ||
30 | * @var INT(11) | ||
31 | */ | ||
32 | public $userId; | ||
33 | |||
34 | /** | ||
35 | * @var private array of recordversion objects | ||
36 | */ | ||
37 | private $_recordversionList = array(); | ||
38 | |||
39 | /** | ||
40 | * @var VARCHAR(255) | ||
41 | */ | ||
42 | public $reference; | ||
43 | |||
44 | /** | ||
45 | * @var LONGTEXT | ||
46 | */ | ||
47 | public $data; | ||
48 | |||
49 | /** | ||
50 | * @var VARCHAR(255) | ||
51 | */ | ||
52 | public $version; | ||
53 | |||
54 | /** | ||
55 | * @var TIMESTAMP | ||
56 | */ | ||
57 | public $creation_date; | ||
58 | |||
59 | /** | ||
60 | * @var TIMESTAMP | ||
61 | */ | ||
62 | public $update_date; | ||
63 | |||
64 | /** | ||
65 | * @var TIMESTAMP | ||
66 | */ | ||
67 | public $access_date; | ||
68 | |||
69 | public $pog_attribute_type = array( | ||
70 | "recordId" => array('db_attributes' => array("NUMERIC", "INT")), | ||
71 | "user" => array('db_attributes' => array("OBJECT", "BELONGSTO")), | ||
72 | "recordversion" => array('db_attributes' => array("OBJECT", "HASMANY")), | ||
73 | "reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
74 | "data" => array('db_attributes' => array("TEXT", "LONGTEXT")), | ||
75 | "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
76 | "creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), | ||
77 | "update_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), | ||
78 | "access_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), | ||
79 | ); | ||
80 | public $pog_query; | ||
81 | |||
82 | |||
83 | /** | ||
84 | * Getter for some private attributes | ||
85 | * @return mixed $attribute | ||
86 | */ | ||
87 | public function __get($attribute) | ||
88 | { | ||
89 | if (isset($this->{"_".$attribute})) | ||
90 | { | ||
91 | return $this->{"_".$attribute}; | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | return false; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | function record($reference='', $data='', $version='', $creation_date='', $update_date='', $access_date='') | ||
100 | { | ||
101 | $this->_recordversionList = array(); | ||
102 | $this->reference = $reference; | ||
103 | $this->data = $data; | ||
104 | $this->version = $version; | ||
105 | $this->creation_date = $creation_date; | ||
106 | $this->update_date = $update_date; | ||
107 | $this->access_date = $access_date; | ||
108 | } | ||
109 | |||
110 | |||
111 | /** | ||
112 | * Gets object from database | ||
113 | * @param integer $recordId | ||
114 | * @return object $record | ||
115 | */ | ||
116 | function Get($recordId) | ||
117 | { | ||
118 | $connection = Database::Connect(); | ||
119 | $this->pog_query = "select * from `record` where `recordid`='".intval($recordId)."' LIMIT 1"; | ||
120 | $cursor = Database::Reader($this->pog_query, $connection); | ||
121 | while ($row = Database::Read($cursor)) | ||
122 | { | ||
123 | $this->recordId = $row['recordid']; | ||
124 | $this->userId = $row['userid']; | ||
125 | $this->reference = $this->Unescape($row['reference']); | ||
126 | $this->data = $this->Unescape($row['data']); | ||
127 | $this->version = $this->Unescape($row['version']); | ||
128 | $this->creation_date = $row['creation_date']; | ||
129 | $this->update_date = $row['update_date']; | ||
130 | $this->access_date = $row['access_date']; | ||
131 | } | ||
132 | return $this; | ||
133 | } | ||
134 | |||
135 | |||
136 | /** | ||
137 | * Returns a sorted array of objects that match given conditions | ||
138 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
139 | * @param string $sortBy | ||
140 | * @param boolean $ascending | ||
141 | * @param int limit | ||
142 | * @return array $recordList | ||
143 | */ | ||
144 | function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') | ||
145 | { | ||
146 | $connection = Database::Connect(); | ||
147 | $sqlLimit = ($limit != '' ? "LIMIT $limit" : ''); | ||
148 | $this->pog_query = "select * from `record` "; | ||
149 | $recordList = Array(); | ||
150 | if (sizeof($fcv_array) > 0) | ||
151 | { | ||
152 | $this->pog_query .= " where "; | ||
153 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) | ||
154 | { | ||
155 | if (sizeof($fcv_array[$i]) == 1) | ||
156 | { | ||
157 | $this->pog_query .= " ".$fcv_array[$i][0]." "; | ||
158 | continue; | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | if ($i > 0 && sizeof($fcv_array[$i-1]) != 1) | ||
163 | { | ||
164 | $this->pog_query .= " AND "; | ||
165 | } | ||
166 | if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET') | ||
167 | { | ||
168 | if ($GLOBALS['configuration']['db_encoding'] == 1) | ||
169 | { | ||
170 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'"; | ||
171 | $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value; | ||
172 | } | ||
173 | else | ||
174 | { | ||
175 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'"; | ||
176 | $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value; | ||
177 | } | ||
178 | } | ||
179 | else | ||
180 | { | ||
181 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'"; | ||
182 | $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value; | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | } | ||
187 | if ($sortBy != '') | ||
188 | { | ||
189 | if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET') | ||
190 | { | ||
191 | if ($GLOBALS['configuration']['db_encoding'] == 1) | ||
192 | { | ||
193 | $sortBy = "BASE64_DECODE($sortBy) "; | ||
194 | } | ||
195 | else | ||
196 | { | ||
197 | $sortBy = "$sortBy "; | ||
198 | } | ||
199 | } | ||
200 | else | ||
201 | { | ||
202 | $sortBy = "$sortBy "; | ||
203 | } | ||
204 | } | ||
205 | else | ||
206 | { | ||
207 | $sortBy = "recordid"; | ||
208 | } | ||
209 | $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit"; | ||
210 | $thisObjectName = get_class($this); | ||
211 | $cursor = Database::Reader($this->pog_query, $connection); | ||
212 | while ($row = Database::Read($cursor)) | ||
213 | { | ||
214 | $record = new $thisObjectName(); | ||
215 | $record->recordId = $row['recordid']; | ||
216 | $record->userId = $row['userid']; | ||
217 | $record->reference = $this->Unescape($row['reference']); | ||
218 | $record->data = $this->Unescape($row['data']); | ||
219 | $record->version = $this->Unescape($row['version']); | ||
220 | $record->creation_date = $row['creation_date']; | ||
221 | $record->update_date = $row['update_date']; | ||
222 | $record->access_date = $row['access_date']; | ||
223 | $recordList[] = $record; | ||
224 | } | ||
225 | return $recordList; | ||
226 | } | ||
227 | |||
228 | |||
229 | /** | ||
230 | * Saves the object to the database | ||
231 | * @return integer $recordId | ||
232 | */ | ||
233 | function Save($deep = true) | ||
234 | { | ||
235 | $connection = Database::Connect(); | ||
236 | $this->pog_query = "select `recordid` from `record` where `recordid`='".$this->recordId."' LIMIT 1"; | ||
237 | $rows = Database::Query($this->pog_query, $connection); | ||
238 | if ($rows > 0) | ||
239 | { | ||
240 | $this->pog_query = "update `record` set | ||
241 | `userid`='".$this->userId."', | ||
242 | `reference`='".$this->Escape($this->reference)."', | ||
243 | `data`='".$this->Escape($this->data)."', | ||
244 | `version`='".$this->Escape($this->version)."', | ||
245 | `creation_date`='".$this->creation_date."', | ||
246 | `update_date`='".$this->update_date."', | ||
247 | `access_date`='".$this->access_date."' where `recordid`='".$this->recordId."'"; | ||
248 | } | ||
249 | else | ||
250 | { | ||
251 | $this->pog_query = "insert into `record` (`userid`, `reference`, `data`, `version`, `creation_date`, `update_date`, `access_date` ) values ( | ||
252 | '".$this->userId."', | ||
253 | '".$this->Escape($this->reference)."', | ||
254 | '".$this->Escape($this->data)."', | ||
255 | '".$this->Escape($this->version)."', | ||
256 | '".$this->creation_date."', | ||
257 | '".$this->update_date."', | ||
258 | '".$this->access_date."' )"; | ||
259 | } | ||
260 | $insertId = Database::InsertOrUpdate($this->pog_query, $connection); | ||
261 | if ($this->recordId == "") | ||
262 | { | ||
263 | $this->recordId = $insertId; | ||
264 | } | ||
265 | if ($deep) | ||
266 | { | ||
267 | foreach ($this->_recordversionList as $recordversion) | ||
268 | { | ||
269 | $recordversion->recordId = $this->recordId; | ||
270 | $recordversion->Save($deep); | ||
271 | } | ||
272 | } | ||
273 | return $this->recordId; | ||
274 | } | ||
275 | |||
276 | |||
277 | /** | ||
278 | * Clones the object and saves it to the database | ||
279 | * @return integer $recordId | ||
280 | */ | ||
281 | function SaveNew($deep = false) | ||
282 | { | ||
283 | $this->recordId = ''; | ||
284 | return $this->Save($deep); | ||
285 | } | ||
286 | |||
287 | |||
288 | /** | ||
289 | * Deletes the object from the database | ||
290 | * @return boolean | ||
291 | */ | ||
292 | function Delete($deep = false, $across = false) | ||
293 | { | ||
294 | if ($deep) | ||
295 | { | ||
296 | $recordversionList = $this->GetRecordversionList(); | ||
297 | foreach ($recordversionList as $recordversion) | ||
298 | { | ||
299 | $recordversion->Delete($deep, $across); | ||
300 | } | ||
301 | } | ||
302 | $connection = Database::Connect(); | ||
303 | $this->pog_query = "delete from `record` where `recordid`='".$this->recordId."'"; | ||
304 | return Database::NonQuery($this->pog_query, $connection); | ||
305 | } | ||
306 | |||
307 | |||
308 | /** | ||
309 | * Deletes a list of objects that match given conditions | ||
310 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
311 | * @param bool $deep | ||
312 | * @return | ||
313 | */ | ||
314 | function DeleteList($fcv_array, $deep = false, $across = false) | ||
315 | { | ||
316 | if (sizeof($fcv_array) > 0) | ||
317 | { | ||
318 | if ($deep || $across) | ||
319 | { | ||
320 | $objectList = $this->GetList($fcv_array); | ||
321 | foreach ($objectList as $object) | ||
322 | { | ||
323 | $object->Delete($deep, $across); | ||
324 | } | ||
325 | } | ||
326 | else | ||
327 | { | ||
328 | $connection = Database::Connect(); | ||
329 | $pog_query = "delete from `record` where "; | ||
330 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) | ||
331 | { | ||
332 | if (sizeof($fcv_array[$i]) == 1) | ||
333 | { | ||
334 | $pog_query .= " ".$fcv_array[$i][0]." "; | ||
335 | continue; | ||
336 | } | ||
337 | else | ||
338 | { | ||
339 | if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1) | ||
340 | { | ||
341 | $pog_query .= " AND "; | ||
342 | } | ||
343 | if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET') | ||
344 | { | ||
345 | $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'"; | ||
346 | } | ||
347 | else | ||
348 | { | ||
349 | $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'"; | ||
350 | } | ||
351 | } | ||
352 | } | ||
353 | return Database::NonQuery($pog_query, $connection); | ||
354 | } | ||
355 | } | ||
356 | } | ||
357 | |||
358 | |||
359 | /** | ||
360 | * Associates the user object to this one | ||
361 | * @return boolean | ||
362 | */ | ||
363 | function GetUser() | ||
364 | { | ||
365 | $user = new user(); | ||
366 | return $user->Get($this->userId); | ||
367 | } | ||
368 | |||
369 | |||
370 | /** | ||
371 | * Associates the user object to this one | ||
372 | * @return | ||
373 | */ | ||
374 | function SetUser(&$user) | ||
375 | { | ||
376 | $this->userId = $user->userId; | ||
377 | } | ||
378 | |||
379 | |||
380 | /** | ||
381 | * Gets a list of recordversion objects associated to this one | ||
382 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
383 | * @param string $sortBy | ||
384 | * @param boolean $ascending | ||
385 | * @param int limit | ||
386 | * @return array of recordversion objects | ||
387 | */ | ||
388 | function GetRecordversionList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') | ||
389 | { | ||
390 | $recordversion = new recordversion(); | ||
391 | $fcv_array[] = array("recordId", "=", $this->recordId); | ||
392 | $dbObjects = $recordversion->GetList($fcv_array, $sortBy, $ascending, $limit); | ||
393 | return $dbObjects; | ||
394 | } | ||
395 | |||
396 | |||
397 | /** | ||
398 | * Makes this the parent of all recordversion objects in the recordversion List array. Any existing recordversion will become orphan(s) | ||
399 | * @return null | ||
400 | */ | ||
401 | function SetRecordversionList(&$list) | ||
402 | { | ||
403 | $this->_recordversionList = array(); | ||
404 | $existingRecordversionList = $this->GetRecordversionList(); | ||
405 | foreach ($existingRecordversionList as $recordversion) | ||
406 | { | ||
407 | $recordversion->recordId = ''; | ||
408 | $recordversion->Save(false); | ||
409 | } | ||
410 | $this->_recordversionList = $list; | ||
411 | } | ||
412 | |||
413 | |||
414 | /** | ||
415 | * Associates the recordversion object to this one | ||
416 | * @return | ||
417 | */ | ||
418 | function AddRecordversion(&$recordversion) | ||
419 | { | ||
420 | $recordversion->recordId = $this->recordId; | ||
421 | $found = false; | ||
422 | foreach($this->_recordversionList as $recordversion2) | ||
423 | { | ||
424 | if ($recordversion->recordversionId > 0 && $recordversion->recordversionId == $recordversion2->recordversionId) | ||
425 | { | ||
426 | $found = true; | ||
427 | break; | ||
428 | } | ||
429 | } | ||
430 | if (!$found) | ||
431 | { | ||
432 | $this->_recordversionList[] = $recordversion; | ||
433 | } | ||
434 | } | ||
435 | } | ||
436 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/objects/class.recordversion.php b/backend/php/src/objects/class.recordversion.php new file mode 100644 index 0000000..3fbc436 --- a/dev/null +++ b/backend/php/src/objects/class.recordversion.php | |||
@@ -0,0 +1,381 @@ | |||
1 | <?php | ||
2 | /* | ||
3 | This SQL query will create the table to store your object. | ||
4 | |||
5 | CREATE TABLE `recordversion` ( | ||
6 | `recordversionid` int(11) NOT NULL auto_increment, | ||
7 | `recordid` int(11) NOT NULL, | ||
8 | `reference` VARCHAR(255) NOT NULL, | ||
9 | `header` LONGTEXT NOT NULL, | ||
10 | `data` LONGTEXT NOT NULL, | ||
11 | `version` VARCHAR(255) NOT NULL, | ||
12 | `previous_version_key` VARCHAR(255) NOT NULL, | ||
13 | `previous_version_id` INT NOT NULL, | ||
14 | `creation_date` TIMESTAMP NOT NULL, | ||
15 | `update_date` TIMESTAMP NOT NULL, | ||
16 | `access_date` TIMESTAMP NOT NULL, INDEX(`recordid`), PRIMARY KEY (`recordversionid`)) ENGINE=MyISAM; | ||
17 | */ | ||
18 | |||
19 | /** | ||
20 | * <b>recordversion</b> class with integrated CRUD methods. | ||
21 | * @author Php Object Generator | ||
22 | * @version POG 3.0e / PHP5.1 MYSQL | ||
23 | * @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql | ||
24 | * @copyright Free for personal & commercial use. (Offered under the BSD license) | ||
25 | * @link http://www.phpobjectgenerator.com/?language=php5.1=pdo&pdoDriver=mysql&objectName=recordversion&attributeList=array+%28%0A++0+%3D%3E+%27record%27%2C%0A++1+%3D%3E+%27reference%27%2C%0A++2+%3D%3E+%27header%27%2C%0A++3+%3D%3E+%27data%27%2C%0A++4+%3D%3E+%27version%27%2C%0A++5+%3D%3E+%27previous_version_key%27%2C%0A++6+%3D%3E+%27previous_version_id%27%2C%0A++7+%3D%3E+%27creation_date%27%2C%0A++8+%3D%3E+%27update_date%27%2C%0A++9+%3D%3E+%27access_date%27%2C%0A%29&typeList=array%2B%2528%250A%2B%2B0%2B%253D%253E%2B%2527BELONGSTO%2527%252C%250A%2B%2B1%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B2%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B3%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B4%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B5%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B6%2B%253D%253E%2B%2527INT%2527%252C%250A%2B%2B7%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B8%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B9%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2529 | ||
26 | */ | ||
27 | include_once('class.pog_base.php'); | ||
28 | class recordversion extends POG_Base | ||
29 | { | ||
30 | public $recordversionId = ''; | ||
31 | |||
32 | /** | ||
33 | * @var INT(11) | ||
34 | */ | ||
35 | public $recordId; | ||
36 | |||
37 | /** | ||
38 | * @var VARCHAR(255) | ||
39 | */ | ||
40 | public $reference; | ||
41 | |||
42 | /** | ||
43 | * @var LONGTEXT | ||
44 | */ | ||
45 | public $header; | ||
46 | |||
47 | /** | ||
48 | * @var LONGTEXT | ||
49 | */ | ||
50 | public $data; | ||
51 | |||
52 | /** | ||
53 | * @var VARCHAR(255) | ||
54 | */ | ||
55 | public $version; | ||
56 | |||
57 | /** | ||
58 | * @var VARCHAR(255) | ||
59 | */ | ||
60 | public $previous_version_key; | ||
61 | |||
62 | /** | ||
63 | * @var INT | ||
64 | */ | ||
65 | public $previous_version_id; | ||
66 | |||
67 | /** | ||
68 | * @var TIMESTAMP | ||
69 | */ | ||
70 | public $creation_date; | ||
71 | |||
72 | /** | ||
73 | * @var TIMESTAMP | ||
74 | */ | ||
75 | public $update_date; | ||
76 | |||
77 | /** | ||
78 | * @var TIMESTAMP | ||
79 | */ | ||
80 | public $access_date; | ||
81 | |||
82 | public $pog_attribute_type = array( | ||
83 | "recordversionId" => array('db_attributes' => array("NUMERIC", "INT")), | ||
84 | "record" => array('db_attributes' => array("OBJECT", "BELONGSTO")), | ||
85 | "reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
86 | "header" => array('db_attributes' => array("TEXT", "LONGTEXT")), | ||
87 | "data" => array('db_attributes' => array("TEXT", "LONGTEXT")), | ||
88 | "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
89 | "previous_version_key" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
90 | "previous_version_id" => array('db_attributes' => array("NUMERIC", "INT")), | ||
91 | "creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), | ||
92 | "update_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), | ||
93 | "access_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), | ||
94 | ); | ||
95 | public $pog_query; | ||
96 | |||
97 | |||
98 | /** | ||
99 | * Getter for some private attributes | ||
100 | * @return mixed $attribute | ||
101 | */ | ||
102 | public function __get($attribute) | ||
103 | { | ||
104 | if (isset($this->{"_".$attribute})) | ||
105 | { | ||
106 | return $this->{"_".$attribute}; | ||
107 | } | ||
108 | else | ||
109 | { | ||
110 | return false; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | function recordversion($reference='', $header='', $data='', $version='', $previous_version_key='', $previous_version_id='', $creation_date='', $update_date='', $access_date='') | ||
115 | { | ||
116 | $this->reference = $reference; | ||
117 | $this->header = $header; | ||
118 | $this->data = $data; | ||
119 | $this->version = $version; | ||
120 | $this->previous_version_key = $previous_version_key; | ||
121 | $this->previous_version_id = $previous_version_id; | ||
122 | $this->creation_date = $creation_date; | ||
123 | $this->update_date = $update_date; | ||
124 | $this->access_date = $access_date; | ||
125 | } | ||
126 | |||
127 | |||
128 | /** | ||
129 | * Gets object from database | ||
130 | * @param integer $recordversionId | ||
131 | * @return object $recordversion | ||
132 | */ | ||
133 | function Get($recordversionId) | ||
134 | { | ||
135 | $connection = Database::Connect(); | ||
136 | $this->pog_query = "select * from `recordversion` where `recordversionid`='".intval($recordversionId)."' LIMIT 1"; | ||
137 | $cursor = Database::Reader($this->pog_query, $connection); | ||
138 | while ($row = Database::Read($cursor)) | ||
139 | { | ||
140 | $this->recordversionId = $row['recordversionid']; | ||
141 | $this->recordId = $row['recordid']; | ||
142 | $this->reference = $this->Unescape($row['reference']); | ||
143 | $this->header = $this->Unescape($row['header']); | ||
144 | $this->data = $this->Unescape($row['data']); | ||
145 | $this->version = $this->Unescape($row['version']); | ||
146 | $this->previous_version_key = $this->Unescape($row['previous_version_key']); | ||
147 | $this->previous_version_id = $this->Unescape($row['previous_version_id']); | ||
148 | $this->creation_date = $row['creation_date']; | ||
149 | $this->update_date = $row['update_date']; | ||
150 | $this->access_date = $row['access_date']; | ||
151 | } | ||
152 | return $this; | ||
153 | } | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Returns a sorted array of objects that match given conditions | ||
158 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
159 | * @param string $sortBy | ||
160 | * @param boolean $ascending | ||
161 | * @param int limit | ||
162 | * @return array $recordversionList | ||
163 | */ | ||
164 | function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') | ||
165 | { | ||
166 | $connection = Database::Connect(); | ||
167 | $sqlLimit = ($limit != '' ? "LIMIT $limit" : ''); | ||
168 | $this->pog_query = "select * from `recordversion` "; | ||
169 | $recordversionList = Array(); | ||
170 | if (sizeof($fcv_array) > 0) | ||
171 | { | ||
172 | $this->pog_query .= " where "; | ||
173 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) | ||
174 | { | ||
175 | if (sizeof($fcv_array[$i]) == 1) | ||
176 | { | ||
177 | $this->pog_query .= " ".$fcv_array[$i][0]." "; | ||
178 | continue; | ||
179 | } | ||
180 | else | ||
181 | { | ||
182 | if ($i > 0 && sizeof($fcv_array[$i-1]) != 1) | ||
183 | { | ||
184 | $this->pog_query .= " AND "; | ||
185 | } | ||
186 | if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET') | ||
187 | { | ||
188 | if ($GLOBALS['configuration']['db_encoding'] == 1) | ||
189 | { | ||
190 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'"; | ||
191 | $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value; | ||
192 | } | ||
193 | else | ||
194 | { | ||
195 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'"; | ||
196 | $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value; | ||
197 | } | ||
198 | } | ||
199 | else | ||
200 | { | ||
201 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'"; | ||
202 | $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value; | ||
203 | } | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | if ($sortBy != '') | ||
208 | { | ||
209 | if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET') | ||
210 | { | ||
211 | if ($GLOBALS['configuration']['db_encoding'] == 1) | ||
212 | { | ||
213 | $sortBy = "BASE64_DECODE($sortBy) "; | ||
214 | } | ||
215 | else | ||
216 | { | ||
217 | $sortBy = "$sortBy "; | ||
218 | } | ||
219 | } | ||
220 | else | ||
221 | { | ||
222 | $sortBy = "$sortBy "; | ||
223 | } | ||
224 | } | ||
225 | else | ||
226 | { | ||
227 | $sortBy = "recordversionid"; | ||
228 | } | ||
229 | $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit"; | ||
230 | $thisObjectName = get_class($this); | ||
231 | $cursor = Database::Reader($this->pog_query, $connection); | ||
232 | while ($row = Database::Read($cursor)) | ||
233 | { | ||
234 | $recordversion = new $thisObjectName(); | ||
235 | $recordversion->recordversionId = $row['recordversionid']; | ||
236 | $recordversion->recordId = $row['recordid']; | ||
237 | $recordversion->reference = $this->Unescape($row['reference']); | ||
238 | $recordversion->header = $this->Unescape($row['header']); | ||
239 | $recordversion->data = $this->Unescape($row['data']); | ||
240 | $recordversion->version = $this->Unescape($row['version']); | ||
241 | $recordversion->previous_version_key = $this->Unescape($row['previous_version_key']); | ||
242 | $recordversion->previous_version_id = $this->Unescape($row['previous_version_id']); | ||
243 | $recordversion->creation_date = $row['creation_date']; | ||
244 | $recordversion->update_date = $row['update_date']; | ||
245 | $recordversion->access_date = $row['access_date']; | ||
246 | $recordversionList[] = $recordversion; | ||
247 | } | ||
248 | return $recordversionList; | ||
249 | } | ||
250 | |||
251 | |||
252 | /** | ||
253 | * Saves the object to the database | ||
254 | * @return integer $recordversionId | ||
255 | */ | ||
256 | function Save() | ||
257 | { | ||
258 | $connection = Database::Connect(); | ||
259 | $this->pog_query = "select `recordversionid` from `recordversion` where `recordversionid`='".$this->recordversionId."' LIMIT 1"; | ||
260 | $rows = Database::Query($this->pog_query, $connection); | ||
261 | if ($rows > 0) | ||
262 | { | ||
263 | $this->pog_query = "update `recordversion` set | ||
264 | `recordid`='".$this->recordId."', | ||
265 | `reference`='".$this->Escape($this->reference)."', | ||
266 | `header`='".$this->Escape($this->header)."', | ||
267 | `data`='".$this->Escape($this->data)."', | ||
268 | `version`='".$this->Escape($this->version)."', | ||
269 | `previous_version_key`='".$this->Escape($this->previous_version_key)."', | ||
270 | `previous_version_id`='".$this->Escape($this->previous_version_id)."', | ||
271 | `creation_date`='".$this->creation_date."', | ||
272 | `update_date`='".$this->update_date."', | ||
273 | `access_date`='".$this->access_date."' where `recordversionid`='".$this->recordversionId."'"; | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | $this->pog_query = "insert into `recordversion` (`recordid`, `reference`, `header`, `data`, `version`, `previous_version_key`, `previous_version_id`, `creation_date`, `update_date`, `access_date` ) values ( | ||
278 | '".$this->recordId."', | ||
279 | '".$this->Escape($this->reference)."', | ||
280 | '".$this->Escape($this->header)."', | ||
281 | '".$this->Escape($this->data)."', | ||
282 | '".$this->Escape($this->version)."', | ||
283 | '".$this->Escape($this->previous_version_key)."', | ||
284 | '".$this->Escape($this->previous_version_id)."', | ||
285 | '".$this->creation_date."', | ||
286 | '".$this->update_date."', | ||
287 | '".$this->access_date."' )"; | ||
288 | } | ||
289 | $insertId = Database::InsertOrUpdate($this->pog_query, $connection); | ||
290 | if ($this->recordversionId == "") | ||
291 | { | ||
292 | $this->recordversionId = $insertId; | ||
293 | } | ||
294 | return $this->recordversionId; | ||
295 | } | ||
296 | |||
297 | |||
298 | /** | ||
299 | * Clones the object and saves it to the database | ||
300 | * @return integer $recordversionId | ||
301 | */ | ||
302 | function SaveNew() | ||
303 | { | ||
304 | $this->recordversionId = ''; | ||
305 | return $this->Save(); | ||
306 | } | ||
307 | |||
308 | |||
309 | /** | ||
310 | * Deletes the object from the database | ||
311 | * @return boolean | ||
312 | */ | ||
313 | function Delete() | ||
314 | { | ||
315 | $connection = Database::Connect(); | ||
316 | $this->pog_query = "delete from `recordversion` where `recordversionid`='".$this->recordversionId."'"; | ||
317 | return Database::NonQuery($this->pog_query, $connection); | ||
318 | } | ||
319 | |||
320 | |||
321 | /** | ||
322 | * Deletes a list of objects that match given conditions | ||
323 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
324 | * @param bool $deep | ||
325 | * @return | ||
326 | */ | ||
327 | function DeleteList($fcv_array) | ||
328 | { | ||
329 | if (sizeof($fcv_array) > 0) | ||
330 | { | ||
331 | $connection = Database::Connect(); | ||
332 | $pog_query = "delete from `recordversion` where "; | ||
333 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) | ||
334 | { | ||
335 | if (sizeof($fcv_array[$i]) == 1) | ||
336 | { | ||
337 | $pog_query .= " ".$fcv_array[$i][0]." "; | ||
338 | continue; | ||
339 | } | ||
340 | else | ||
341 | { | ||
342 | if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1) | ||
343 | { | ||
344 | $pog_query .= " AND "; | ||
345 | } | ||
346 | if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET') | ||
347 | { | ||
348 | $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'"; | ||
349 | } | ||
350 | else | ||
351 | { | ||
352 | $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'"; | ||
353 | } | ||
354 | } | ||
355 | } | ||
356 | return Database::NonQuery($pog_query, $connection); | ||
357 | } | ||
358 | } | ||
359 | |||
360 | |||
361 | /** | ||
362 | * Associates the record object to this one | ||
363 | * @return boolean | ||
364 | */ | ||
365 | function GetRecord() | ||
366 | { | ||
367 | $record = new record(); | ||
368 | return $record->Get($this->recordId); | ||
369 | } | ||
370 | |||
371 | |||
372 | /** | ||
373 | * Associates the record object to this one | ||
374 | * @return | ||
375 | */ | ||
376 | function SetRecord(&$record) | ||
377 | { | ||
378 | $this->recordId = $record->recordId; | ||
379 | } | ||
380 | } | ||
381 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/objects/class.user.php b/backend/php/src/objects/class.user.php new file mode 100644 index 0000000..f92c7ac --- a/dev/null +++ b/backend/php/src/objects/class.user.php | |||
@@ -0,0 +1,502 @@ | |||
1 | <?php | ||
2 | /* | ||
3 | This SQL query will create the table to store your object. | ||
4 | |||
5 | CREATE TABLE `user` ( | ||
6 | `userid` int(11) NOT NULL auto_increment, | ||
7 | `username` VARCHAR(255) NOT NULL, | ||
8 | `srp_s` VARCHAR(255) NOT NULL, | ||
9 | `srp_v` VARCHAR(255) NOT NULL, | ||
10 | `header` LONGTEXT NOT NULL, | ||
11 | `statistics` LONGTEXT NOT NULL, | ||
12 | `auth_version` VARCHAR(255) NOT NULL, | ||
13 | `version` VARCHAR(255) NOT NULL, | ||
14 | `lock` VARCHAR(255) NOT NULL, PRIMARY KEY (`userid`)) ENGINE=MyISAM; | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * <b>user</b> class with integrated CRUD methods. | ||
19 | * @author Php Object Generator | ||
20 | * @version POG 3.0e / PHP5.1 MYSQL | ||
21 | * @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql | ||
22 | * @copyright Free for personal & commercial use. (Offered under the BSD license) | ||
23 | * @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pdo&pdoDriver=mysql&objectName=user&attributeList=array+%28%0A++0+%3D%3E+%27username%27%2C%0A++1+%3D%3E+%27srp_s%27%2C%0A++2+%3D%3E+%27srp_v%27%2C%0A++3+%3D%3E+%27header%27%2C%0A++4+%3D%3E+%27statistics%27%2C%0A++5+%3D%3E+%27auth_version%27%2C%0A++6+%3D%3E+%27version%27%2C%0A++7+%3D%3E+%27lock%27%2C%0A++8+%3D%3E+%27record%27%2C%0A++9+%3D%3E+%27onetimepassword%27%2C%0A%29&typeList=array%2B%2528%250A%2B%2B0%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B1%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B2%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B3%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B4%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B5%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B6%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B7%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B8%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2B%2B9%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2529 | ||
24 | */ | ||
25 | include_once('class.pog_base.php'); | ||
26 | class user extends POG_Base | ||
27 | { | ||
28 | public $userId = ''; | ||
29 | |||
30 | /** | ||
31 | * @var VARCHAR(255) | ||
32 | */ | ||
33 | public $username; | ||
34 | |||
35 | /** | ||
36 | * @var VARCHAR(255) | ||
37 | */ | ||
38 | public $srp_s; | ||
39 | |||
40 | /** | ||
41 | * @var VARCHAR(255) | ||
42 | */ | ||
43 | public $srp_v; | ||
44 | |||
45 | /** | ||
46 | * @var LONGTEXT | ||
47 | */ | ||
48 | public $header; | ||
49 | |||
50 | /** | ||
51 | * @var LONGTEXT | ||
52 | */ | ||
53 | public $statistics; | ||
54 | |||
55 | /** | ||
56 | * @var VARCHAR(255) | ||
57 | */ | ||
58 | public $auth_version; | ||
59 | |||
60 | /** | ||
61 | * @var VARCHAR(255) | ||
62 | */ | ||
63 | public $version; | ||
64 | |||
65 | /** | ||
66 | * @var VARCHAR(255) | ||
67 | */ | ||
68 | public $lock; | ||
69 | |||
70 | /** | ||
71 | * @var private array of record objects | ||
72 | */ | ||
73 | private $_recordList = array(); | ||
74 | |||
75 | /** | ||
76 | * @var private array of onetimepassword objects | ||
77 | */ | ||
78 | private $_onetimepasswordList = array(); | ||
79 | |||
80 | public $pog_attribute_type = array( | ||
81 | "userId" => array('db_attributes' => array("NUMERIC", "INT")), | ||
82 | "username" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
83 | "srp_s" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
84 | "srp_v" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
85 | "header" => array('db_attributes' => array("TEXT", "LONGTEXT")), | ||
86 | "statistics" => array('db_attributes' => array("TEXT", "LONGTEXT")), | ||
87 | "auth_version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
88 | "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
89 | "lock" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
90 | "record" => array('db_attributes' => array("OBJECT", "HASMANY")), | ||
91 | "onetimepassword" => array('db_attributes' => array("OBJECT", "HASMANY")), | ||
92 | ); | ||
93 | public $pog_query; | ||
94 | |||
95 | |||
96 | /** | ||
97 | * Getter for some private attributes | ||
98 | * @return mixed $attribute | ||
99 | */ | ||
100 | public function __get($attribute) | ||
101 | { | ||
102 | if (isset($this->{"_".$attribute})) | ||
103 | { | ||
104 | return $this->{"_".$attribute}; | ||
105 | } | ||
106 | else | ||
107 | { | ||
108 | return false; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | function user($username='', $srp_s='', $srp_v='', $header='', $statistics='', $auth_version='', $version='', $lock='') | ||
113 | { | ||
114 | $this->username = $username; | ||
115 | $this->srp_s = $srp_s; | ||
116 | $this->srp_v = $srp_v; | ||
117 | $this->header = $header; | ||
118 | $this->statistics = $statistics; | ||
119 | $this->auth_version = $auth_version; | ||
120 | $this->version = $version; | ||
121 | $this->lock = $lock; | ||
122 | $this->_recordList = array(); | ||
123 | $this->_onetimepasswordList = array(); | ||
124 | } | ||
125 | |||
126 | |||
127 | /** | ||
128 | * Gets object from database | ||
129 | * @param integer $userId | ||
130 | * @return object $user | ||
131 | */ | ||
132 | function Get($userId) | ||
133 | { | ||
134 | $connection = Database::Connect(); | ||
135 | $this->pog_query = "select * from `user` where `userid`='".intval($userId)."' LIMIT 1"; | ||
136 | $cursor = Database::Reader($this->pog_query, $connection); | ||
137 | while ($row = Database::Read($cursor)) | ||
138 | { | ||
139 | $this->userId = $row['userid']; | ||
140 | $this->username = $this->Unescape($row['username']); | ||
141 | $this->srp_s = $this->Unescape($row['srp_s']); | ||
142 | $this->srp_v = $this->Unescape($row['srp_v']); | ||
143 | $this->header = $this->Unescape($row['header']); | ||
144 | $this->statistics = $this->Unescape($row['statistics']); | ||
145 | $this->auth_version = $this->Unescape($row['auth_version']); | ||
146 | $this->version = $this->Unescape($row['version']); | ||
147 | $this->lock = $this->Unescape($row['lock']); | ||
148 | } | ||
149 | return $this; | ||
150 | } | ||
151 | |||
152 | |||
153 | /** | ||
154 | * Returns a sorted array of objects that match given conditions | ||
155 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
156 | * @param string $sortBy | ||
157 | * @param boolean $ascending | ||
158 | * @param int limit | ||
159 | * @return array $userList | ||
160 | */ | ||
161 | function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') | ||
162 | { | ||
163 | $connection = Database::Connect(); | ||
164 | $sqlLimit = ($limit != '' ? "LIMIT $limit" : ''); | ||
165 | $this->pog_query = "select * from `user` "; | ||
166 | $userList = Array(); | ||
167 | if (sizeof($fcv_array) > 0) | ||
168 | { | ||
169 | $this->pog_query .= " where "; | ||
170 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) | ||
171 | { | ||
172 | if (sizeof($fcv_array[$i]) == 1) | ||
173 | { | ||
174 | $this->pog_query .= " ".$fcv_array[$i][0]." "; | ||
175 | continue; | ||
176 | } | ||
177 | else | ||
178 | { | ||
179 | if ($i > 0 && sizeof($fcv_array[$i-1]) != 1) | ||
180 | { | ||
181 | $this->pog_query .= " AND "; | ||
182 | } | ||
183 | if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET') | ||
184 | { | ||
185 | if ($GLOBALS['configuration']['db_encoding'] == 1) | ||
186 | { | ||
187 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'"; | ||
188 | $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value; | ||
189 | } | ||
190 | else | ||
191 | { | ||
192 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'"; | ||
193 | $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value; | ||
194 | } | ||
195 | } | ||
196 | else | ||
197 | { | ||
198 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'"; | ||
199 | $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value; | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | if ($sortBy != '') | ||
205 | { | ||
206 | if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET') | ||
207 | { | ||
208 | if ($GLOBALS['configuration']['db_encoding'] == 1) | ||
209 | { | ||
210 | $sortBy = "BASE64_DECODE($sortBy) "; | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | $sortBy = "$sortBy "; | ||
215 | } | ||
216 | } | ||
217 | else | ||
218 | { | ||
219 | $sortBy = "$sortBy "; | ||
220 | } | ||
221 | } | ||
222 | else | ||
223 | { | ||
224 | $sortBy = "userid"; | ||
225 | } | ||
226 | $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit"; | ||
227 | $thisObjectName = get_class($this); | ||
228 | $cursor = Database::Reader($this->pog_query, $connection); | ||
229 | while ($row = Database::Read($cursor)) | ||
230 | { | ||
231 | $user = new $thisObjectName(); | ||
232 | $user->userId = $row['userid']; | ||
233 | $user->username = $this->Unescape($row['username']); | ||
234 | $user->srp_s = $this->Unescape($row['srp_s']); | ||
235 | $user->srp_v = $this->Unescape($row['srp_v']); | ||
236 | $user->header = $this->Unescape($row['header']); | ||
237 | $user->statistics = $this->Unescape($row['statistics']); | ||
238 | $user->auth_version = $this->Unescape($row['auth_version']); | ||
239 | $user->version = $this->Unescape($row['version']); | ||
240 | $user->lock = $this->Unescape($row['lock']); | ||
241 | $userList[] = $user; | ||
242 | } | ||
243 | return $userList; | ||
244 | } | ||
245 | |||
246 | |||
247 | /** | ||
248 | * Saves the object to the database | ||
249 | * @return integer $userId | ||
250 | */ | ||
251 | function Save($deep = true) | ||
252 | { | ||
253 | $connection = Database::Connect(); | ||
254 | $this->pog_query = "select `userid` from `user` where `userid`='".$this->userId."' LIMIT 1"; | ||
255 | $rows = Database::Query($this->pog_query, $connection); | ||
256 | if ($rows > 0) | ||
257 | { | ||
258 | $this->pog_query = "update `user` set | ||
259 | `username`='".$this->Escape($this->username)."', | ||
260 | `srp_s`='".$this->Escape($this->srp_s)."', | ||
261 | `srp_v`='".$this->Escape($this->srp_v)."', | ||
262 | `header`='".$this->Escape($this->header)."', | ||
263 | `statistics`='".$this->Escape($this->statistics)."', | ||
264 | `auth_version`='".$this->Escape($this->auth_version)."', | ||
265 | `version`='".$this->Escape($this->version)."', | ||
266 | `lock`='".$this->Escape($this->lock)."'where `userid`='".$this->userId."'"; | ||
267 | } | ||
268 | else | ||
269 | { | ||
270 | $this->pog_query = "insert into `user` (`username`, `srp_s`, `srp_v`, `header`, `statistics`, `auth_version`, `version`, `lock`) values ( | ||
271 | '".$this->Escape($this->username)."', | ||
272 | '".$this->Escape($this->srp_s)."', | ||
273 | '".$this->Escape($this->srp_v)."', | ||
274 | '".$this->Escape($this->header)."', | ||
275 | '".$this->Escape($this->statistics)."', | ||
276 | '".$this->Escape($this->auth_version)."', | ||
277 | '".$this->Escape($this->version)."', | ||
278 | '".$this->Escape($this->lock)."')"; | ||
279 | } | ||
280 | $insertId = Database::InsertOrUpdate($this->pog_query, $connection); | ||
281 | if ($this->userId == "") | ||
282 | { | ||
283 | $this->userId = $insertId; | ||
284 | } | ||
285 | if ($deep) | ||
286 | { | ||
287 | foreach ($this->_recordList as $record) | ||
288 | { | ||
289 | $record->userId = $this->userId; | ||
290 | $record->Save($deep); | ||
291 | } | ||
292 | foreach ($this->_onetimepasswordList as $onetimepassword) | ||
293 | { | ||
294 | $onetimepassword->userId = $this->userId; | ||
295 | $onetimepassword->Save($deep); | ||
296 | } | ||
297 | } | ||
298 | return $this->userId; | ||
299 | } | ||
300 | |||
301 | |||
302 | /** | ||
303 | * Clones the object and saves it to the database | ||
304 | * @return integer $userId | ||
305 | */ | ||
306 | function SaveNew($deep = false) | ||
307 | { | ||
308 | $this->userId = ''; | ||
309 | return $this->Save($deep); | ||
310 | } | ||
311 | |||
312 | |||
313 | /** | ||
314 | * Deletes the object from the database | ||
315 | * @return boolean | ||
316 | */ | ||
317 | function Delete($deep = false, $across = false) | ||
318 | { | ||
319 | if ($deep) | ||
320 | { | ||
321 | $recordList = $this->GetRecordList(); | ||
322 | foreach ($recordList as $record) | ||
323 | { | ||
324 | $record->Delete($deep, $across); | ||
325 | } | ||
326 | $onetimepasswordList = $this->GetOnetimepasswordList(); | ||
327 | foreach ($onetimepasswordList as $onetimepassword) | ||
328 | { | ||
329 | $onetimepassword->Delete($deep, $across); | ||
330 | } | ||
331 | } | ||
332 | $connection = Database::Connect(); | ||
333 | $this->pog_query = "delete from `user` where `userid`='".$this->userId."'"; | ||
334 | return Database::NonQuery($this->pog_query, $connection); | ||
335 | } | ||
336 | |||
337 | |||
338 | /** | ||
339 | * Deletes a list of objects that match given conditions | ||
340 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
341 | * @param bool $deep | ||
342 | * @return | ||
343 | */ | ||
344 | function DeleteList($fcv_array, $deep = false, $across = false) | ||
345 | { | ||
346 | if (sizeof($fcv_array) > 0) | ||
347 | { | ||
348 | if ($deep || $across) | ||
349 | { | ||
350 | $objectList = $this->GetList($fcv_array); | ||
351 | foreach ($objectList as $object) | ||
352 | { | ||
353 | $object->Delete($deep, $across); | ||
354 | } | ||
355 | } | ||
356 | else | ||
357 | { | ||
358 | $connection = Database::Connect(); | ||
359 | $pog_query = "delete from `user` where "; | ||
360 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) | ||
361 | { | ||
362 | if (sizeof($fcv_array[$i]) == 1) | ||
363 | { | ||
364 | $pog_query .= " ".$fcv_array[$i][0]." "; | ||
365 | continue; | ||
366 | } | ||
367 | else | ||
368 | { | ||
369 | if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1) | ||
370 | { | ||
371 | $pog_query .= " AND "; | ||
372 | } | ||
373 | if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET') | ||
374 | { | ||
375 | $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'"; | ||
376 | } | ||
377 | else | ||
378 | { | ||
379 | $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'"; | ||
380 | } | ||
381 | } | ||
382 | } | ||
383 | return Database::NonQuery($pog_query, $connection); | ||
384 | } | ||
385 | } | ||
386 | } | ||
387 | |||
388 | |||
389 | /** | ||
390 | * Gets a list of record objects associated to this one | ||
391 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
392 | * @param string $sortBy | ||
393 | * @param boolean $ascending | ||
394 | * @param int limit | ||
395 | * @return array of record objects | ||
396 | */ | ||
397 | function GetRecordList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') | ||
398 | { | ||
399 | $record = new record(); | ||
400 | $fcv_array[] = array("userId", "=", $this->userId); | ||
401 | $dbObjects = $record->GetList($fcv_array, $sortBy, $ascending, $limit); | ||
402 | return $dbObjects; | ||
403 | } | ||
404 | |||
405 | |||
406 | /** | ||
407 | * Makes this the parent of all record objects in the record List array. Any existing record will become orphan(s) | ||
408 | * @return null | ||
409 | */ | ||
410 | function SetRecordList(&$list) | ||
411 | { | ||
412 | $this->_recordList = array(); | ||
413 | $existingRecordList = $this->GetRecordList(); | ||
414 | foreach ($existingRecordList as $record) | ||
415 | { | ||
416 | $record->userId = ''; | ||
417 | $record->Save(false); | ||
418 | } | ||
419 | $this->_recordList = $list; | ||
420 | } | ||
421 | |||
422 | |||
423 | /** | ||
424 | * Associates the record object to this one | ||
425 | * @return | ||
426 | */ | ||
427 | function AddRecord(&$record) | ||
428 | { | ||
429 | $record->userId = $this->userId; | ||
430 | $found = false; | ||
431 | foreach($this->_recordList as $record2) | ||
432 | { | ||
433 | if ($record->recordId > 0 && $record->recordId == $record2->recordId) | ||
434 | { | ||
435 | $found = true; | ||
436 | break; | ||
437 | } | ||
438 | } | ||
439 | if (!$found) | ||
440 | { | ||
441 | $this->_recordList[] = $record; | ||
442 | } | ||
443 | } | ||
444 | |||
445 | |||
446 | /** | ||
447 | * Gets a list of onetimepassword objects associated to this one | ||
448 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
449 | * @param string $sortBy | ||
450 | * @param boolean $ascending | ||
451 | * @param int limit | ||
452 | * @return array of onetimepassword objects | ||
453 | */ | ||
454 | function GetOnetimepasswordList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') | ||
455 | { | ||
456 | $onetimepassword = new onetimepassword(); | ||
457 | $fcv_array[] = array("userId", "=", $this->userId); | ||
458 | $dbObjects = $onetimepassword->GetList($fcv_array, $sortBy, $ascending, $limit); | ||
459 | return $dbObjects; | ||
460 | } | ||
461 | |||
462 | |||
463 | /** | ||
464 | * Makes this the parent of all onetimepassword objects in the onetimepassword List array. Any existing onetimepassword will become orphan(s) | ||
465 | * @return null | ||
466 | */ | ||
467 | function SetOnetimepasswordList(&$list) | ||
468 | { | ||
469 | $this->_onetimepasswordList = array(); | ||
470 | $existingOnetimepasswordList = $this->GetOnetimepasswordList(); | ||
471 | foreach ($existingOnetimepasswordList as $onetimepassword) | ||
472 | { | ||
473 | $onetimepassword->userId = ''; | ||
474 | $onetimepassword->Save(false); | ||
475 | } | ||
476 | $this->_onetimepasswordList = $list; | ||
477 | } | ||
478 | |||
479 | |||
480 | /** | ||
481 | * Associates the onetimepassword object to this one | ||
482 | * @return | ||
483 | */ | ||
484 | function AddOnetimepassword(&$onetimepassword) | ||
485 | { | ||
486 | $onetimepassword->userId = $this->userId; | ||
487 | $found = false; | ||
488 | foreach($this->_onetimepasswordList as $onetimepassword2) | ||
489 | { | ||
490 | if ($onetimepassword->onetimepasswordId > 0 && $onetimepassword->onetimepasswordId == $onetimepassword2->onetimepasswordId) | ||
491 | { | ||
492 | $found = true; | ||
493 | break; | ||
494 | } | ||
495 | } | ||
496 | if (!$found) | ||
497 | { | ||
498 | $this->_onetimepasswordList[] = $onetimepassword; | ||
499 | } | ||
500 | } | ||
501 | } | ||
502 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/objects/ignore_objects.txt b/backend/php/src/objects/ignore_objects.txt new file mode 100644 index 0000000..e69de29 --- a/dev/null +++ b/backend/php/src/objects/ignore_objects.txt | |||
diff --git a/backend/php/src/plugins/IPlugin.php b/backend/php/src/plugins/IPlugin.php new file mode 100644 index 0000000..3e39e70 --- a/dev/null +++ b/backend/php/src/plugins/IPlugin.php | |||
@@ -0,0 +1,48 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * All functions must be implemented to create a correct POG plugin | ||
4 | * The 'optional' functions SetupRender() and AuthorPage() must be implemented and return null | ||
5 | * if your plugin does not need them. | ||
6 | * | ||
7 | */ | ||
8 | interface POG_Plugin | ||
9 | { | ||
10 | /** | ||
11 | * | ||
12 | * REQUIRED | ||
13 | * This function must return the version of the plugin. | ||
14 | * It will be used to automatically notify developer when your plugin is updated. | ||
15 | * | ||
16 | */ | ||
17 | function Version(); | ||
18 | |||
19 | /** | ||
20 | * | ||
21 | * REQUIRED | ||
22 | * This function performs the actions that your plugin provides. | ||
23 | * | ||
24 | */ | ||
25 | function Execute(); | ||
26 | |||
27 | /** | ||
28 | * 'OPTIONAL' | ||
29 | * If your plugin needs an administrative interface, implement this function. | ||
30 | * Else return null | ||
31 | * | ||
32 | */ | ||
33 | function SetupRender(); | ||
34 | |||
35 | |||
36 | /** | ||
37 | * | ||
38 | * 'OPTIONAL' | ||
39 | * Implement this function to provide a link to your homepage. | ||
40 | * e.g. return 'http://myhomepage.com'; | ||
41 | * | ||
42 | * return null if you do not want to link to your homepage | ||
43 | * e.g. return null | ||
44 | * | ||
45 | */ | ||
46 | function AuthorPage(); | ||
47 | } | ||
48 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/plugins/base64_install.sql b/backend/php/src/plugins/base64_install.sql new file mode 100644 index 0000000..40401d6 --- a/dev/null +++ b/backend/php/src/plugins/base64_install.sql | |||
@@ -0,0 +1,172 @@ | |||
1 | -- base64.sql - MySQL base64 encoding/decoding functions | ||
2 | -- Copyright (C) 2006 Ian Gulliver | ||
3 | -- | ||
4 | -- This program is free software; you can redistribute it and/or modify | ||
5 | -- it under the terms of version 2 of the GNU General Public License as | ||
6 | -- published by the Free Software Foundation. | ||
7 | -- | ||
8 | -- This program is distributed in the hope that it will be useful, | ||
9 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | -- GNU General Public License for more details. | ||
12 | -- | ||
13 | -- You should have received a copy of the GNU General Public License | ||
14 | -- along with this program; if not, write to the Free Software | ||
15 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
16 | |||
17 | |||
18 | DROP TABLE IF EXISTS base64_data | | ||
19 | CREATE TABLE base64_data (c CHAR(1) BINARY, val TINYINT) | | ||
20 | INSERT INTO base64_data VALUES | ||
21 | ('A',0), ('B',1), ('C',2), ('D',3), ('E',4), ('F',5), ('G',6), ('H',7), ('I',8), ('J',9), | ||
22 | ('K',10), ('L',11), ('M',12), ('N',13), ('O',14), ('P',15), ('Q',16), ('R',17), ('S',18), ('T',19), | ||
23 | ('U',20), ('V',21), ('W',22), ('X',23), ('Y',24), ('Z',25), ('a',26), ('b',27), ('c',28), ('d',29), | ||
24 | ('e',30), ('f',31), ('g',32), ('h',33), ('i',34), ('j',35), ('k',36), ('l',37), ('m',38), ('n',39), | ||
25 | ('o',40), ('p',41), ('q',42), ('r',43), ('s',44), ('t',45), ('u',46), ('v',47), ('w',48), ('x',49), | ||
26 | ('y',50), ('z',51), ('0',52), ('1',53), ('2',54), ('3',55), ('4',56), ('5',57), ('6',58), ('7',59), | ||
27 | ('8',60), ('9',61), ('+',62), ('/',63), ('=',0) | | ||
28 | |||
29 | |||
30 | DROP FUNCTION IF EXISTS BASE64_DECODE | | ||
31 | CREATE FUNCTION BASE64_DECODE (input BLOB) | ||
32 | RETURNS BLOB | ||
33 | CONTAINS SQL | ||
34 | DETERMINISTIC | ||
35 | SQL SECURITY INVOKER | ||
36 | BEGIN | ||
37 | DECLARE ret BLOB DEFAULT ''; | ||
38 | DECLARE done TINYINT DEFAULT 0; | ||
39 | |||
40 | IF input IS NULL THEN | ||
41 | RETURN NULL; | ||
42 | END IF; | ||
43 | |||
44 | each_block: | ||
45 | WHILE NOT done DO BEGIN | ||
46 | DECLARE accum_value BIGINT UNSIGNED DEFAULT 0; | ||
47 | DECLARE in_count TINYINT DEFAULT 0; | ||
48 | DECLARE out_count TINYINT DEFAULT 3; | ||
49 | |||
50 | each_input_char: | ||
51 | WHILE in_count < 4 DO BEGIN | ||
52 | DECLARE first_char CHAR(1); | ||
53 | |||
54 | IF LENGTH(input) = 0 THEN | ||
55 | RETURN ret; | ||
56 | END IF; | ||
57 | |||
58 | SET first_char = SUBSTRING(input,1,1); | ||
59 | SET input = SUBSTRING(input,2); | ||
60 | |||
61 | BEGIN | ||
62 | DECLARE tempval TINYINT UNSIGNED; | ||
63 | DECLARE error TINYINT DEFAULT 0; | ||
64 | DECLARE base64_getval CURSOR FOR SELECT val FROM base64_data WHERE c = first_char; | ||
65 | DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET error = 1; | ||
66 | |||
67 | OPEN base64_getval; | ||
68 | FETCH base64_getval INTO tempval; | ||
69 | CLOSE base64_getval; | ||
70 | |||
71 | IF error THEN | ||
72 | ITERATE each_input_char; | ||
73 | END IF; | ||
74 | |||
75 | SET accum_value = (accum_value << 6) + tempval; | ||
76 | END; | ||
77 | |||
78 | SET in_count = in_count + 1; | ||
79 | |||
80 | IF first_char = '=' THEN | ||
81 | SET done = 1; | ||
82 | SET out_count = out_count - 1; | ||
83 | END IF; | ||
84 | END; END WHILE; | ||
85 | |||
86 | -- We've now accumulated 24 bits; deaccumulate into bytes | ||
87 | |||
88 | -- We have to work from the left, so use the third byte position and shift left | ||
89 | WHILE out_count > 0 DO BEGIN | ||
90 | SET ret = CONCAT(ret,CHAR((accum_value & 0xff0000) >> 16)); | ||
91 | SET out_count = out_count - 1; | ||
92 | SET accum_value = (accum_value << 8) & 0xffffff; | ||
93 | END; END WHILE; | ||
94 | |||
95 | END; END WHILE; | ||
96 | |||
97 | RETURN ret; | ||
98 | END | | ||
99 | |||
100 | DROP FUNCTION IF EXISTS BASE64_ENCODE | | ||
101 | CREATE FUNCTION BASE64_ENCODE (input BLOB) | ||
102 | RETURNS BLOB | ||
103 | CONTAINS SQL | ||
104 | DETERMINISTIC | ||
105 | SQL SECURITY INVOKER | ||
106 | BEGIN | ||
107 | DECLARE ret BLOB DEFAULT ''; | ||
108 | DECLARE done TINYINT DEFAULT 0; | ||
109 | |||
110 | IF input IS NULL THEN | ||
111 | RETURN NULL; | ||
112 | END IF; | ||
113 | |||
114 | each_block: | ||
115 | WHILE NOT done DO BEGIN | ||
116 | DECLARE accum_value BIGINT UNSIGNED DEFAULT 0; | ||
117 | DECLARE in_count TINYINT DEFAULT 0; | ||
118 | DECLARE out_count TINYINT; | ||
119 | |||
120 | each_input_char: | ||
121 | WHILE in_count < 3 DO BEGIN | ||
122 | DECLARE first_char CHAR(1); | ||
123 | |||
124 | IF LENGTH(input) = 0 THEN | ||
125 | SET done = 1; | ||
126 | SET accum_value = accum_value << (8 * (3 - in_count)); | ||
127 | LEAVE each_input_char; | ||
128 | END IF; | ||
129 | |||
130 | SET first_char = SUBSTRING(input,1,1); | ||
131 | SET input = SUBSTRING(input,2); | ||
132 | |||
133 | SET accum_value = (accum_value << 8) + ASCII(first_char); | ||
134 | |||
135 | SET in_count = in_count + 1; | ||
136 | END; END WHILE; | ||
137 | |||
138 | -- We've now accumulated 24 bits; deaccumulate into base64 characters | ||
139 | |||
140 | -- We have to work from the left, so use the third byte position and shift left | ||
141 | CASE | ||
142 | WHEN in_count = 3 THEN SET out_count = 4; | ||
143 | WHEN in_count = 2 THEN SET out_count = 3; | ||
144 | WHEN in_count = 1 THEN SET out_count = 2; | ||
145 | ELSE RETURN ret; | ||
146 | END CASE; | ||
147 | |||
148 | WHILE out_count > 0 DO BEGIN | ||
149 | BEGIN | ||
150 | DECLARE out_char CHAR(1); | ||
151 | DECLARE base64_getval CURSOR FOR SELECT c FROM base64_data WHERE val = (accum_value >> 18); | ||
152 | |||
153 | OPEN base64_getval; | ||
154 | FETCH base64_getval INTO out_char; | ||
155 | CLOSE base64_getval; | ||
156 | |||
157 | SET ret = CONCAT(ret,out_char); | ||
158 | SET out_count = out_count - 1; | ||
159 | SET accum_value = accum_value << 6 & 0xffffff; | ||
160 | END; | ||
161 | END; END WHILE; | ||
162 | |||
163 | CASE | ||
164 | WHEN in_count = 2 THEN SET ret = CONCAT(ret,'='); | ||
165 | WHEN in_count = 1 THEN SET ret = CONCAT(ret,'=='); | ||
166 | ELSE BEGIN END; | ||
167 | END CASE; | ||
168 | |||
169 | END; END WHILE; | ||
170 | |||
171 | RETURN ret; | ||
172 | END | | ||
diff --git a/backend/php/src/plugins/base64_uninstall.sql b/backend/php/src/plugins/base64_uninstall.sql new file mode 100644 index 0000000..02b9b6b --- a/dev/null +++ b/backend/php/src/plugins/base64_uninstall.sql | |||
@@ -0,0 +1,20 @@ | |||
1 | -- base64.sql - MySQL base64 encoding/decoding functions | ||
2 | -- Copyright (C) 2006 Ian Gulliver | ||
3 | -- | ||
4 | -- This program is free software; you can redistribute it and/or modify | ||
5 | -- it under the terms of version 2 of the GNU General Public License as | ||
6 | -- published by the Free Software Foundation. | ||
7 | -- | ||
8 | -- This program is distributed in the hope that it will be useful, | ||
9 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | -- GNU General Public License for more details. | ||
12 | -- | ||
13 | -- You should have received a copy of the GNU General Public License | ||
14 | -- along with this program; if not, write to the Free Software | ||
15 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
16 | |||
17 | |||
18 | DROP TABLE IF EXISTS base64_data | | ||
19 | DROP FUNCTION IF EXISTS BASE64_DECODE | | ||
20 | DROP FUNCTION IF EXISTS BASE64_ENCODE | \ No newline at end of file | ||
diff --git a/backend/php/src/plugins/plugin.base64.php b/backend/php/src/plugins/plugin.base64.php new file mode 100644 index 0000000..323f861 --- a/dev/null +++ b/backend/php/src/plugins/plugin.base64.php | |||
@@ -0,0 +1,128 @@ | |||
1 | <?php | ||
2 | class Base64 | ||
3 | { | ||
4 | var $sourceObject; | ||
5 | var $argv; | ||
6 | var $version = '1.0'; | ||
7 | |||
8 | function Version() | ||
9 | { | ||
10 | return $this->version; | ||
11 | } | ||
12 | |||
13 | function Base64($sourceObject, $argv) | ||
14 | { | ||
15 | $this->sourceObject = $sourceObject; | ||
16 | $this->argv = $argv; | ||
17 | } | ||
18 | |||
19 | function Execute() | ||
20 | { | ||
21 | return null; | ||
22 | } | ||
23 | |||
24 | function SetupRender() | ||
25 | { | ||
26 | if (isset($_POST['install_base64']) || isset($_POST['uninstall_base64'])) | ||
27 | { | ||
28 | $this->SetupExecute(); | ||
29 | } | ||
30 | else | ||
31 | { | ||
32 | $out = "This plugin allows you to install and uninstall a base64 custom function to and from your database. | ||
33 | You can then set \$configuration['db_encoding'] = 1 so that all data is transparently encoded and decoded | ||
34 | with the minimal overhead possible. Enabling data encoding has quite a few advantages: <br/><br/> | ||
35 | |||
36 | "; | ||
37 | $out .= "<br/><br/><textarea>BASE64 Status"; | ||
38 | if (Base64::IsBase64FunctionInstalled()) | ||
39 | { | ||
40 | $out .= "\n\tChecking MySQL function....OK!"; | ||
41 | if (!isset($GLOBALS['configuration']['db_encoding']) || $GLOBALS['configuration']['db_encoding'] != 1) | ||
42 | { | ||
43 | $out .="\n\tChecking db_encoding status....Failed"; | ||
44 | $out .= "\n\n---------------------------------------------------"; | ||
45 | $out .= "\n\$configuration['db_encoding'] is set to 0. Make sure you set the value to 1 to enable data encoding."; | ||
46 | } | ||
47 | else | ||
48 | { | ||
49 | $out .="\n\tChecking db_encoding status....OK!"; | ||
50 | $out .= "\n\nBASE64 Status...OK!"; | ||
51 | $out .= "\n---------------------------------------------------"; | ||
52 | } | ||
53 | $out .= "</textarea><div style='padding-left:250px;padding-top:10px;'><input type='submit' value='UNINSTALL' name='uninstall_base64'/></div>"; | ||
54 | } | ||
55 | else | ||
56 | { | ||
57 | $out .= "\n\tChecking MySQL function....NOT INSTALLED"; | ||
58 | $out .="\n\tChecking db_encoding status ignored"; | ||
59 | $out .= "\n\n---------------------------------------------------"; | ||
60 | $out .= "\nClick the INSTALL button below to install the base64 function to your database."; | ||
61 | $out .= "</textarea><div style='padding-left:250px;padding-top:10px;'><input type='submit' value='INSTALL' name='install_base64'/></div>"; | ||
62 | } | ||
63 | $out .= "<input type='hidden' name='plugins' value='true'/>"; | ||
64 | echo $out; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | function AuthorPage() | ||
69 | { | ||
70 | return null; | ||
71 | } | ||
72 | |||
73 | |||
74 | function SetupExecute() | ||
75 | { | ||
76 | $out = ''; | ||
77 | $connection = Database::Connect(); | ||
78 | if (isset($_POST['install_base64']) && isset($_POST['install_base64']) == true) | ||
79 | { | ||
80 | $initialData = file_get_contents('../plugins/base64_install.sql'); | ||
81 | $statements = explode('|', $initialData); | ||
82 | if (sizeof($statements) > 0) | ||
83 | { | ||
84 | foreach ($statements as $statement) | ||
85 | { | ||
86 | if (trim($statement) != '') | ||
87 | { | ||
88 | Database::NonQuery($statement, $connection); | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | $out .= "<textarea>INSTALL SUCCESSFUL\n\n"; | ||
93 | $out .= "Make sure you set \$configuration[db_encoding] = 1 in the configuration file.</textarea>"; | ||
94 | } | ||
95 | else if (isset($_POST['uninstall_base64']) && $_POST['uninstall_base64'] == true) | ||
96 | { | ||
97 | $initialData = file_get_contents('../plugins/base64_uninstall.sql'); | ||
98 | $statements = explode('|', $initialData); | ||
99 | if (sizeof($statements) > 0) | ||
100 | { | ||
101 | foreach ($statements as $statement) | ||
102 | { | ||
103 | if (trim($statement) != '') | ||
104 | { | ||
105 | Database::NonQuery($statement, $connection); | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | $out .= "<textarea>UNINSTALL SUCCESSFUL\n\n"; | ||
110 | $out .= "Make sure you set \$configuration[db_encoding] = 0 in the configuration file.</textarea>"; | ||
111 | } | ||
112 | echo $out; | ||
113 | } | ||
114 | |||
115 | function IsBase64FunctionInstalled() | ||
116 | { | ||
117 | $sql1 = "show function status where Db='".$GLOBALS['configuration']['db']."' and (Name='BASE64_DECODE' or Name='BASE64_ENCODE')"; | ||
118 | $sql2 = "show tables like 'base64_data'"; | ||
119 | $connection = Database::Connect(); | ||
120 | $result = Database::Query($sql1, $connection); | ||
121 | $result2 = Database::Query($sql2, $connection); | ||
122 | if ($result == 2 && $result2 == 1) | ||
123 | { | ||
124 | return true; | ||
125 | } | ||
126 | return false; | ||
127 | } | ||
128 | } | ||
diff --git a/backend/php/src/setup/data_initialization/additional_table_structures.sql b/backend/php/src/setup/data_initialization/additional_table_structures.sql new file mode 100644 index 0000000..e69de29 --- a/dev/null +++ b/backend/php/src/setup/data_initialization/additional_table_structures.sql | |||
diff --git a/backend/php/src/setup/data_initialization/data_initialization.sql b/backend/php/src/setup/data_initialization/data_initialization.sql new file mode 100644 index 0000000..e69de29 --- a/dev/null +++ b/backend/php/src/setup/data_initialization/data_initialization.sql | |||
diff --git a/backend/php/src/setup/data_initialization/howto.txt b/backend/php/src/setup/data_initialization/howto.txt new file mode 100644 index 0000000..a6f0e24 --- a/dev/null +++ b/backend/php/src/setup/data_initialization/howto.txt | |||
@@ -0,0 +1,13 @@ | |||
1 | Hello there, | ||
2 | |||
3 | To make use of the Data Initialization feature in POG Setup, put your insert statements in the data_initialization.sql file. (One per line). | ||
4 | Then, on step 1 of Setup, choose "Drop, recreate tables and reset data": | ||
5 | |||
6 | This will | ||
7 | |||
8 | 1. Drop any tables that have the same name as the object(s) you have in the objects folder. | ||
9 | 2. Recreate the tables and indexes(if needed) | ||
10 | 3. Execute the insert statements in data_initialization.sql one by one. | ||
11 | |||
12 | Regards, | ||
13 | The POG Team \ No newline at end of file | ||
diff --git a/backend/php/src/setup/data_initialization/read_dump_lib.php b/backend/php/src/setup/data_initialization/read_dump_lib.php new file mode 100644 index 0000000..ed579ab --- a/dev/null +++ b/backend/php/src/setup/data_initialization/read_dump_lib.php | |||
@@ -0,0 +1,205 @@ | |||
1 | <?php | ||
2 | /* $Id: read_dump.lib.php,v 2.11 2006/01/17 17:02:30 cybot_tm Exp $ */ | ||
3 | // vim: expandtab sw=4 ts=4 sts=4: | ||
4 | |||
5 | /** | ||
6 | * Removes comment lines and splits up large sql files into individual queries | ||
7 | * | ||
8 | * Last revision: September 23, 2001 - gandon | ||
9 | * | ||
10 | * @param array the splitted sql commands | ||
11 | * @param string the sql commands | ||
12 | * @param integer the MySQL release number (because certains php3 versions | ||
13 | * can't get the value of a constant from within a function) | ||
14 | * | ||
15 | * @return boolean always true | ||
16 | * | ||
17 | * @access public | ||
18 | */ | ||
19 | function PMA_splitSqlFile(&$ret, $sql, $release) | ||
20 | { | ||
21 | // do not trim, see bug #1030644 | ||
22 | //$sql = trim($sql); | ||
23 | $sql = rtrim($sql, "\n\r"); | ||
24 | $sql_len = strlen($sql); | ||
25 | $char = ''; | ||
26 | $string_start = ''; | ||
27 | $in_string = FALSE; | ||
28 | $nothing = TRUE; | ||
29 | $time0 = time(); | ||
30 | |||
31 | for ($i = 0; $i < $sql_len; ++$i) { | ||
32 | $char = $sql[$i]; | ||
33 | |||
34 | // We are in a string, check for not escaped end of strings except for | ||
35 | // backquotes that can't be escaped | ||
36 | if ($in_string) { | ||
37 | for (;;) { | ||
38 | $i = strpos($sql, $string_start, $i); | ||
39 | // No end of string found -> add the current substring to the | ||
40 | // returned array | ||
41 | if (!$i) { | ||
42 | $ret[] = array('query' => $sql, 'empty' => $nothing); | ||
43 | return TRUE; | ||
44 | } | ||
45 | // Backquotes or no backslashes before quotes: it's indeed the | ||
46 | // end of the string -> exit the loop | ||
47 | elseif ($string_start == '`' || $sql[$i-1] != '\\') { | ||
48 | $string_start = ''; | ||
49 | $in_string = FALSE; | ||
50 | break; | ||
51 | } | ||
52 | // one or more Backslashes before the presumed end of string... | ||
53 | else { | ||
54 | // ... first checks for escaped backslashes | ||
55 | $j = 2; | ||
56 | $escaped_backslash = FALSE; | ||
57 | while ($i-$j > 0 && $sql[$i-$j] == '\\') { | ||
58 | $escaped_backslash = !$escaped_backslash; | ||
59 | $j++; | ||
60 | } | ||
61 | // ... if escaped backslashes: it's really the end of the | ||
62 | // string -> exit the loop | ||
63 | if ($escaped_backslash) { | ||
64 | $string_start = ''; | ||
65 | $in_string = FALSE; | ||
66 | break; | ||
67 | } | ||
68 | // ... else loop | ||
69 | else { | ||
70 | $i++; | ||
71 | } | ||
72 | } // end if...elseif...else | ||
73 | } // end for | ||
74 | } // end if (in string) | ||
75 | |||
76 | // lets skip comments (/*, -- and #) | ||
77 | elseif (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) { | ||
78 | $i = strpos($sql, $char == '/' ? '*/' : "\n", $i); | ||
79 | // didn't we hit end of string? | ||
80 | if ($i === FALSE) { | ||
81 | break; | ||
82 | } | ||
83 | if ($char == '/') { | ||
84 | $i++; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | // We are not in a string, first check for delimiter... | ||
89 | elseif ($char == ';') { | ||
90 | // if delimiter found, add the parsed part to the returned array | ||
91 | $ret[] = array('query' => substr($sql, 0, $i), 'empty' => $nothing); | ||
92 | $nothing = TRUE; | ||
93 | $sql = ltrim(substr($sql, min($i + 1, $sql_len))); | ||
94 | $sql_len = strlen($sql); | ||
95 | if ($sql_len) { | ||
96 | $i = -1; | ||
97 | } else { | ||
98 | // The submited statement(s) end(s) here | ||
99 | return TRUE; | ||
100 | } | ||
101 | } // end elseif (is delimiter) | ||
102 | |||
103 | // ... then check for start of a string,... | ||
104 | elseif (($char == '"') || ($char == '\'') || ($char == '`')) { | ||
105 | $in_string = TRUE; | ||
106 | $nothing = FALSE; | ||
107 | $string_start = $char; | ||
108 | } // end elseif (is start of string) | ||
109 | |||
110 | elseif ($nothing) { | ||
111 | $nothing = FALSE; | ||
112 | } | ||
113 | |||
114 | // loic1: send a fake header each 30 sec. to bypass browser timeout | ||
115 | $time1 = time(); | ||
116 | if ($time1 >= $time0 + 30) { | ||
117 | $time0 = $time1; | ||
118 | header('X-pmaPing: Pong'); | ||
119 | } // end if | ||
120 | } // end for | ||
121 | |||
122 | // add any rest to the returned array | ||
123 | if (!empty($sql) && preg_match('@[^[:space:]]+@', $sql)) { | ||
124 | $ret[] = array('query' => $sql, 'empty' => $nothing); | ||
125 | } | ||
126 | |||
127 | return TRUE; | ||
128 | } // end of the 'PMA_splitSqlFile()' function | ||
129 | |||
130 | |||
131 | /** | ||
132 | * Reads (and decompresses) a (compressed) file into a string | ||
133 | * | ||
134 | * @param string the path to the file | ||
135 | * @param string the MIME type of the file, if empty MIME type is autodetected | ||
136 | * | ||
137 | * @global array the phpMyAdmin configuration | ||
138 | * | ||
139 | * @return string the content of the file or | ||
140 | * boolean FALSE in case of an error. | ||
141 | */ | ||
142 | function PMA_readFile($path, $mime = '') { | ||
143 | global $cfg; | ||
144 | |||
145 | if (!file_exists($path)) { | ||
146 | return FALSE; | ||
147 | } | ||
148 | switch ($mime) { | ||
149 | case '': | ||
150 | $file = @fopen($path, 'rb'); | ||
151 | if (!$file) { | ||
152 | return FALSE; | ||
153 | } | ||
154 | $test = fread($file, 3); | ||
155 | fclose($file); | ||
156 | if ($test[0] == chr(31) && $test[1] == chr(139)) { | ||
157 | return PMA_readFile($path, 'application/x-gzip'); | ||
158 | } | ||
159 | if ($test == 'BZh') { | ||
160 | return PMA_readFile($path, 'application/x-bzip'); | ||
161 | } | ||
162 | return PMA_readFile($path, 'text/plain'); | ||
163 | case 'text/plain': | ||
164 | $file = @fopen($path, 'rb'); | ||
165 | if (!$file) { | ||
166 | return FALSE; | ||
167 | } | ||
168 | $content = fread($file, filesize($path)); | ||
169 | fclose($file); | ||
170 | break; | ||
171 | case 'application/x-gzip': | ||
172 | if ($cfg['GZipDump'] && @function_exists('gzopen')) { | ||
173 | $file = @gzopen($path, 'rb'); | ||
174 | if (!$file) { | ||
175 | return FALSE; | ||
176 | } | ||
177 | $content = ''; | ||
178 | while (!gzeof($file)) { | ||
179 | $content .= gzgetc($file); | ||
180 | } | ||
181 | gzclose($file); | ||
182 | } else { | ||
183 | return FALSE; | ||
184 | } | ||
185 | break; | ||
186 | case 'application/x-bzip': | ||
187 | if ($cfg['BZipDump'] && @function_exists('bzdecompress')) { | ||
188 | $file = @fopen($path, 'rb'); | ||
189 | if (!$file) { | ||
190 | return FALSE; | ||
191 | } | ||
192 | $content = fread($file, filesize($path)); | ||
193 | fclose($file); | ||
194 | $content = bzdecompress($content); | ||
195 | } else { | ||
196 | return FALSE; | ||
197 | } | ||
198 | break; | ||
199 | default: | ||
200 | return FALSE; | ||
201 | } | ||
202 | return $content; | ||
203 | } | ||
204 | |||
205 | ?> | ||
diff --git a/backend/php/src/setup/index.php b/backend/php/src/setup/index.php new file mode 100644 index 0000000..4087961 --- a/dev/null +++ b/backend/php/src/setup/index.php | |||
@@ -0,0 +1,717 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * @author Joel Wan & Mark Slemko. Designs by Jonathan Easton | ||
4 | * @link http://www.phpobjectgenerator.com | ||
5 | * @copyright Offered under the BSD license | ||
6 | * | ||
7 | * This setup file does the following: | ||
8 | * 1. Checks if configuration file is present | ||
9 | * 2. Checks if the data in the configuration file is correct | ||
10 | * 3. Checks if the database and table exist | ||
11 | * 4. Create table if not present | ||
12 | * 5. Tests 5 CRUD functions and determine if everything is OK for all objects within the current directory | ||
13 | * 6. When all tests pass, provides an interface to the database and a way to manage objects. | ||
14 | */ | ||
15 | if (!isset($_SESSION)) | ||
16 | { | ||
17 | session_start(); | ||
18 | } | ||
19 | if(file_exists("../configuration.php")) | ||
20 | { | ||
21 | include_once("../configuration.php"); | ||
22 | } | ||
23 | include_once("setup_library/authentication.php"); | ||
24 | include_once("setup_library/setup_misc.php"); | ||
25 | include_once("data_initialization/read_dump_lib.php"); | ||
26 | if(!isset($_SESSION['diagnosticsSuccessful']) || (isset($_GET['step']) && $_GET['step']=="diagnostics")) | ||
27 | { | ||
28 | $_SESSION['diagnosticsSuccessful'] = false; | ||
29 | } | ||
30 | ?> | ||
31 | <?php include "setup_library/inc.header.php";?> | ||
32 | <?php | ||
33 | ini_set("max_execution_time", 0); | ||
34 | if(count($_POST) > 0 && $_SESSION['diagnosticsSuccessful']==false) | ||
35 | { | ||
36 | ?> | ||
37 | <form action="./index.php" method="POST"> | ||
38 | <div class="container"> | ||
39 | <div class="left"> | ||
40 | <div class="logo2"></div> | ||
41 | <div class="text"><div class="gold">POG setup diagnostics</div> | ||
42 | <br/>Setup performs unit tests on all your objects in the object directory and makes sure they're OK. <br/>This makes sure that your objects can talk to your database correctly. This can also be useful if you modify / customize the objects manually and want to make sure they still work once you're done. | ||
43 | <br/><br/>The diagnostics screen on the right shows the results of those tests. If all tests pass successfully, you can be assured that all objects are working correctly. | ||
44 | </div> | ||
45 | </div> | ||
46 | <div class="middle"> | ||
47 | <div id="tabs"> | ||
48 | <a href="./index.php?step=diagnostics"><img src="./setup_images/tab_setup.gif"/></a> | ||
49 | <img src="./setup_images/tab_separator.gif"/> | ||
50 | <img src="./setup_images/tab_diagnosticresults_on.gif"/> | ||
51 | <img src="./setup_images/tab_separator.gif"/> | ||
52 | <img src="./setup_images/tab_manageobjects.gif"/> | ||
53 | <img src="./setup_images/tab_separator.gif"/> | ||
54 | <img src="./setup_images/tab_manageplugins_off.gif"/> | ||
55 | |||
56 | </div><div class="subtabs"> </div><a href="./index.php?step=diagnostics"><img src="./setup_images/setup_recheck.jpg" border="0"/></a><div class="middle2"> | ||
57 | <?php | ||
58 | $errors = 0; | ||
59 | AddTrace('Initializing POG Setup....OK!'); | ||
60 | if (isset($GLOBALS['configuration']['pdoDriver'])) | ||
61 | { | ||
62 | $errors++; | ||
63 | AddError('POG setup for PHP4/5 objects cannot be run with a PDO configuration file. Regenerate configuration.php'); | ||
64 | } | ||
65 | else | ||
66 | { | ||
67 | /** | ||
68 | * verify file structure status | ||
69 | */ | ||
70 | if(!file_exists("../objects/class.database.php")) | ||
71 | { | ||
72 | $errors++; | ||
73 | AddError('Database wrapper (class.database.php) is missing.'); | ||
74 | } | ||
75 | else | ||
76 | { | ||
77 | include "../objects/class.database.php"; | ||
78 | } | ||
79 | if(!file_exists("../objects/class.pog_base.php")) | ||
80 | { | ||
81 | $errors++; | ||
82 | AddError('POG Base class (class.pog_base.php) is missing.'); | ||
83 | } | ||
84 | else | ||
85 | { | ||
86 | include "../objects/class.pog_base.php"; | ||
87 | } | ||
88 | if (!file_exists("../configuration.php")) | ||
89 | { | ||
90 | $errors++; | ||
91 | AddError('Configuration file (configuration.php) is missing'); | ||
92 | } | ||
93 | if ($GLOBALS['configuration']['plugins_path'] == '') | ||
94 | { | ||
95 | $errors++; | ||
96 | AddError('Path to plugin folder has not been specified in configuration.php'); | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | if (!file_exists($GLOBALS['configuration']['plugins_path']."/plugin.base64.php")) | ||
101 | { | ||
102 | $errors++; | ||
103 | AddError('Base64 plugin file (plugins/plugin.base64.php) is missing'); | ||
104 | } | ||
105 | else | ||
106 | { | ||
107 | include_once($GLOBALS['configuration']['plugins_path']."/plugin.base64.php"); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | |||
112 | |||
113 | //load object names to be ignored | ||
114 | $ignoreObjects = file("../objects/ignore_objects.txt"); | ||
115 | foreach ($ignoreObjects as $key=>$ignoreObject){ | ||
116 | $ignoreObjects[$key] = trim($ignoreObject); | ||
117 | } | ||
118 | |||
119 | $dir = opendir('../objects/'); | ||
120 | $objects = array(); | ||
121 | while(($file = readdir($dir)) !== false) | ||
122 | { | ||
123 | if(strlen($file) > 4 && substr(strtolower($file), strlen($file) - 4) === '.php' && !is_dir($file) && $file != "class.database.php" && $file != "class.pog_base.php") | ||
124 | { | ||
125 | $objects[] = $file; | ||
126 | include_once("../objects/{$file}"); | ||
127 | } | ||
128 | } | ||
129 | closedir($dir); | ||
130 | if (sizeof($objects) == 0) | ||
131 | { | ||
132 | $errors++; | ||
133 | AddError("[objects] folder does not contain any POG object."); | ||
134 | } | ||
135 | |||
136 | if ($errors == 0) | ||
137 | { | ||
138 | $dir = opendir($GLOBALS['configuration']['plugins_path']); | ||
139 | $plugins = array(); | ||
140 | |||
141 | while(($file = readdir($dir)) !== false) | ||
142 | { | ||
143 | if(file_exists($GLOBALS['configuration']['plugins_path']."/IPlugin.php")) | ||
144 | { | ||
145 | include_once($GLOBALS['configuration']['plugins_path']."/IPlugin.php"); | ||
146 | } | ||
147 | if(strlen($file) > 4 && substr(strtolower($file), strlen($file) - 4) === '.php' && !is_dir($file) && strtolower(substr($file, 0, 6)) == 'plugin') | ||
148 | { | ||
149 | include_once($GLOBALS['configuration']['plugins_path']."/{$file}"); | ||
150 | $pluginName = GetPluginName($file); | ||
151 | if ($pluginName != '') | ||
152 | { | ||
153 | $plugins[] = $file; | ||
154 | } | ||
155 | |||
156 | } | ||
157 | } | ||
158 | closedir($dir); | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * verify configuration info | ||
163 | */ | ||
164 | if ($errors == 0) | ||
165 | { | ||
166 | AddTrace('File Structure....OK!'); | ||
167 | if (!@mysql_connect ($GLOBALS['configuration']['host'].":".$GLOBALS['configuration']['port'], $GLOBALS['configuration']['user'], $GLOBALS['configuration']['pass'])) | ||
168 | { | ||
169 | $errors++; | ||
170 | AddError('Cannot connect to the specified database server. Edit configuration.php'); | ||
171 | } | ||
172 | if (isset($GLOBALS['configuration']['db_encoding']) && $GLOBALS['configuration']['db_encoding'] == 1 && !Base64::IsBase64FunctionInstalled()) | ||
173 | { | ||
174 | $errors++; | ||
175 | AddError('$configuration[db_encoding] needs to be set to 0 until you install the base64 plugin. Set db_encoding to 0 by editing configuration.php, run setup again and go to the "Manage Plugins" tab. Install the base64 plugin. Then you can set db_encoding = 1'); | ||
176 | } | ||
177 | if ($errors == 0) | ||
178 | { | ||
179 | if (!@mysql_select_db ($GLOBALS['configuration']['db'])) | ||
180 | { | ||
181 | $errors++; | ||
182 | AddError('Cannot find the specified database "'.$GLOBALS['configuration']['db'].'". Edit configuration.php'); | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | |||
187 | /** | ||
188 | * verify storage status | ||
189 | */ | ||
190 | |||
191 | if ($errors == 0) | ||
192 | { | ||
193 | AddTrace("Configuration Info....OK!\n"); | ||
194 | AddTrace("Storage Status"); | ||
195 | foreach($objects as $object) | ||
196 | { | ||
197 | $objectName = GetObjectName("../objects/".$object); | ||
198 | eval ('$instance = new '.$objectName.'();'); | ||
199 | if (TestStorageExists($objectName, "mysql")) | ||
200 | { | ||
201 | if (isset($_POST['pog_table']) && ($_POST['pog_table'] == "recreate" || $_POST['pog_table'] == "recreate_import")) | ||
202 | { | ||
203 | if (!TestDeleteStorage($instance)) | ||
204 | { | ||
205 | $errors++; | ||
206 | AddError("Dropping table '".strtolower($objectName)."' failed. Drop and recreate the table manually."); | ||
207 | } | ||
208 | else | ||
209 | { | ||
210 | if (!TestCreateStorage("../objects/".$object)) | ||
211 | { | ||
212 | $errors++; | ||
213 | AddError("Creating table [".strtolower($objectName)."] failed. Create the table manually using the generated SQL query in the object header."); | ||
214 | } | ||
215 | else | ||
216 | { | ||
217 | AddTrace("\tDropping & Recreating table [".strtolower($objectName)."]....OK!"); | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | else | ||
222 | { | ||
223 | if (!TestAlterStorage($instance)) | ||
224 | { | ||
225 | $errors++; | ||
226 | AddError("Aligning [$objectName] with table '".strtolower($objectName)."' failed. Alter the table manually so that object attributes and table columns match."); | ||
227 | } | ||
228 | else | ||
229 | { | ||
230 | AddTrace("\tAligning [$objectName] with table '".strtolower($objectName)."'....OK!"); | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | else | ||
235 | { | ||
236 | if (!TestCreateStorage("../objects/".$object)) | ||
237 | { | ||
238 | $errors++; | ||
239 | AddError("Creating table [".strtolower($objectName)."] failed. Create the table manually using the generated SQL query in the object header."); | ||
240 | } | ||
241 | else | ||
242 | { | ||
243 | AddTrace("\tCreating table [".strtolower($objectName)."]....OK!"); | ||
244 | } | ||
245 | } | ||
246 | } | ||
247 | } | ||
248 | |||
249 | $objectNameList = array(); | ||
250 | |||
251 | /** | ||
252 | * Initialize test data? | ||
253 | */ | ||
254 | if (isset($_POST['pog_table']) && $_POST['pog_table'] == 'recreate_import') | ||
255 | { | ||
256 | $initialData = file_get_contents('data_initialization/data_initialization.sql'); | ||
257 | PMA_splitSqlFile($statements, $initialData, 4); | ||
258 | if (sizeof($statements) > 0) | ||
259 | { | ||
260 | foreach ($statements as $statement) | ||
261 | { | ||
262 | if (!TestExecuteQuery($statement['query'])) | ||
263 | |||
264 | { | ||
265 | $errors++; | ||
266 | AddError('Statement "'.$statement['query'].'" failed'); | ||
267 | } | ||
268 | } | ||
269 | } | ||
270 | $structure_changes = file_get_contents('data_initialization/additional_table_structures.sql'); | ||
271 | unset($statements); | ||
272 | PMA_splitSqlFile($statements, $structure_changes, 4); | ||
273 | if (sizeof($statements) > 0) | ||
274 | { | ||
275 | foreach ($statements as $statement) | ||
276 | { | ||
277 | if (!TestExecuteQuery($statement['query'])) | ||
278 | |||
279 | { | ||
280 | $errors++; | ||
281 | AddError('Statement "'.$statement['query'].'" failed'); | ||
282 | } | ||
283 | } | ||
284 | } | ||
285 | } | ||
286 | |||
287 | |||
288 | /** | ||
289 | * verify object status | ||
290 | */ | ||
291 | $objectNameList = array(); | ||
292 | foreach($objects as $object) | ||
293 | { | ||
294 | $objectName = GetObjectName("../objects/".$object); | ||
295 | if (isset($objectName) && array_search($objectName, $ignoreObjects) ===false) | ||
296 | { | ||
297 | $objectNameList[] = $objectName; | ||
298 | } | ||
299 | } | ||
300 | |||
301 | if ($errors == 0) | ||
302 | { | ||
303 | $pluginNameList = array(); | ||
304 | foreach($plugins as $plugin) | ||
305 | { | ||
306 | $pluginName = GetPluginName($plugin); | ||
307 | if ($pluginName != '') | ||
308 | { | ||
309 | $pluginNameList[] = $pluginName; | ||
310 | } | ||
311 | } | ||
312 | } | ||
313 | |||
314 | |||
315 | if ($errors == 0 && isset($_POST['pog_test']) && $_POST['pog_test'] == 'yes') | ||
316 | { | ||
317 | AddTrace("\nPOG Essentials"); | ||
318 | |||
319 | $_SESSION['links'] = array(); | ||
320 | |||
321 | $objectCount = 1; | ||
322 | foreach($objects as $object) | ||
323 | { | ||
324 | $objectName = GetObjectName("../objects/".$object); | ||
325 | if (isset($objectName) && array_search($objectName, $ignoreObjects) ===false) | ||
326 | { | ||
327 | eval('$instance = new '.$objectName.'();'); | ||
328 | AddTrace("\t[".$objectName."]"); | ||
329 | |||
330 | $link = GetAtLink("../objects/".$object); | ||
331 | $_SESSION['links'][$objectName] = $link; | ||
332 | |||
333 | if (!TestEssentials($instance)) | ||
334 | { | ||
335 | $errors++; | ||
336 | AddError("Object $objectName failed essential tests"); | ||
337 | } | ||
338 | if ($objectCount != sizeof($objects)) | ||
339 | { | ||
340 | AddTrace("\t***"); | ||
341 | } | ||
342 | } | ||
343 | $objectCount++; | ||
344 | } | ||
345 | } | ||
346 | |||
347 | |||
348 | if ($errors == 0 && isset($_POST['pog_test']) && $_POST['pog_test'] == 'yes') | ||
349 | { | ||
350 | AddTrace("\nPOG Relations PreRequisites"); | ||
351 | $objectCount = 1; | ||
352 | foreach ($objects as $object) | ||
353 | { | ||
354 | $objectName = GetObjectName("../objects/".$object); | ||
355 | if (isset($objectName) && array_search($objectName, $ignoreObjects) ===false) | ||
356 | { | ||
357 | eval('$instance = new '.$objectName.'();'); | ||
358 | AddTrace("\t[".$objectName."]"); | ||
359 | if (!TestRelationsPreRequisites($instance, $objectNameList, $objectName, $ignoreObjects)) | ||
360 | { | ||
361 | $errors++; | ||
362 | } | ||
363 | if ($objectCount != sizeof($objects)) | ||
364 | { | ||
365 | AddTrace("\t***"); | ||
366 | } | ||
367 | } | ||
368 | $objectCount++; | ||
369 | } | ||
370 | } | ||
371 | |||
372 | |||
373 | if ($errors == 0 && isset($_POST['pog_test']) && $_POST['pog_test'] == 'yes') | ||
374 | { | ||
375 | AddTrace("\nPOG Relations"); | ||
376 | $objectCount = 1; | ||
377 | foreach ($objects as $object) | ||
378 | { | ||
379 | $objectName = GetObjectName("../objects/".$object); | ||
380 | if (isset($objectName) && array_search($objectName, $ignoreObjects) ===false) | ||
381 | { | ||
382 | eval('$instance = new '.$objectName.'();'); | ||
383 | AddTrace("\t[".$objectName."]"); | ||
384 | if (!TestRelations($instance, $objectNameList, $ignoreObjects)) | ||
385 | { | ||
386 | $errors++; | ||
387 | AddError("Object $objectName failed relations tests"); | ||
388 | } | ||
389 | if ($objectCount != sizeof($objects)) | ||
390 | { | ||
391 | AddTrace("\t***"); | ||
392 | } | ||
393 | } | ||
394 | $objectCount++; | ||
395 | } | ||
396 | } | ||
397 | if ($errors == 0) | ||
398 | { | ||
399 | $_SESSION['diagnosticsSuccessful'] = true; | ||
400 | } | ||
401 | if(isset($_POST['pog_test']) && $_POST['pog_test'] == 'no') | ||
402 | { | ||
403 | AddTrace("\nUNIT TESTS NOT PERFORMED. FOUND $errors ERROR(S)"); | ||
404 | } | ||
405 | else | ||
406 | { | ||
407 | AddTrace("\nCHECKED ".count($objectNameList)." OBJECT(S). FOUND $errors ERROR(S)".($errors == 0 ? ". HURRAY!" : ":")); | ||
408 | } | ||
409 | AddTrace("---------------------------------------------------"); | ||
410 | if (isset($_SESSION['errorMessages'])) | ||
411 | { | ||
412 | $errorMessages = unserialize($_SESSION['errorMessages']); | ||
413 | } | ||
414 | $traceMessages = unserialize($_SESSION['traceMessages']); | ||
415 | $diagnostics = ''; | ||
416 | foreach ($traceMessages as $traceMessage) | ||
417 | { | ||
418 | $diagnostics .= "\n$traceMessage"; | ||
419 | } | ||
420 | if (isset($errorMessages)) | ||
421 | { | ||
422 | foreach ($errorMessages as $errorMessage) | ||
423 | { | ||
424 | $diagnostics .= "\n$errorMessage\n"; | ||
425 | } | ||
426 | } | ||
427 | $_SESSION['fileNames'] = serialize($objects); | ||
428 | $_SESSION['objectNameList'] = serialize($objectNameList); | ||
429 | if (isset($pluginNameList)) | ||
430 | { | ||
431 | $_SESSION['pluginNameList'] = serialize($pluginNameList); | ||
432 | } | ||
433 | } | ||
434 | echo "<textarea>".$diagnostics."</textarea><br/><br/><br/></div>"; | ||
435 | if ($_SESSION['diagnosticsSuccessful']) | ||
436 | { | ||
437 | echo '<input type="image" src="./setup_images/setup_proceed.gif" name="submit"/>'; | ||
438 | } | ||
439 | unset($_POST, $instanceId, $_SESSION['traceMessages'], $_SESSION['errorMessages']); | ||
440 | ?> | ||
441 | </div></div> | ||
442 | </form> | ||
443 | <?php | ||
444 | } | ||
445 | else if($_SESSION['diagnosticsSuccessful'] == true && (!isset($_GET['plugins']) || $_GET['plugins'] != true) ) | ||
446 | { | ||
447 | $pluginNameList = unserialize($_SESSION['pluginNameList']); | ||
448 | ?> | ||
449 | <form action="./index.php" method="POST"> | ||
450 | <div class="container"> | ||
451 | <div class="left"> | ||
452 | <div class="logo3"></div> | ||
453 | <div class="text"><div class="gold">POG documentation summary</div> | ||
454 | <br/><br/>The following 3 documents summarize what POG is all about:<br/><br/> | ||
455 | 1. <a href="http://www.phpobjectgenerator.com/plog/file_download/15">POG Essentials</a><br/><br/> | ||
456 | 2. <a href="http://www.phpobjectgenerator.com/plog/file_download/21">POG Object Relations</a><br/><br/> | ||
457 | 3. <a href="http://www.phpobjectgenerator.com/plog/file_download/18">POG SOAP API</a> | ||
458 | </div><!--text--> | ||
459 | </div><!--left--> | ||
460 | <div class="middle33"> | ||
461 | <div id="tabs3"> | ||
462 | <a href="./index.php?step=diagnostics"><img src="./setup_images/tab_setup.gif"/></a> | ||
463 | <img src="./setup_images/tab_separator.gif"/> | ||
464 | <img src="./setup_images/tab_diagnosticresults.gif"/> | ||
465 | <img src="./setup_images/tab_separator.gif"/> | ||
466 | <a href="./index.php"><img src="./setup_images/tab_manageobjects_on.gif"/></a> | ||
467 | <img src="./setup_images/tab_separator.gif"/> | ||
468 | <?php | ||
469 | if (sizeof($pluginNameList) > 0) | ||
470 | { | ||
471 | ?> | ||
472 | <a href="./index.php?plugins=true"><img src="./setup_images/tab_manageplugins_off.gif" border="0"/></a> | ||
473 | <?php | ||
474 | } | ||
475 | ?> | ||
476 | </div><!--tabs3--><div class="subtabs"> | ||
477 | <?php | ||
478 | //provide interface to the database | ||
479 | include "./setup_library/xPandMenu.php"; | ||
480 | $root = new XMenu(); | ||
481 | if(file_exists("configuration.php")) | ||
482 | { | ||
483 | include "../configuration.php"; | ||
484 | } | ||
485 | if(file_exists("../objects/class.database.php")) | ||
486 | { | ||
487 | include "../objects/class.database.php"; | ||
488 | } | ||
489 | |||
490 | $fileNames = unserialize($_SESSION['fileNames']); | ||
491 | foreach($fileNames as $filename) | ||
492 | { | ||
493 | include_once("../objects/{$filename}"); | ||
494 | } | ||
495 | $objectNameList = unserialize($_SESSION['objectNameList']); | ||
496 | if (isset($_GET['objectName'])) | ||
497 | { | ||
498 | $_SESSION['objectName'] = $_GET['objectName']; | ||
499 | } | ||
500 | $objectName = (isset($_SESSION['objectName'])?$_SESSION['objectName']:$objectNameList[0]); | ||
501 | |||
502 | ?> | ||
503 | <div id="header"> | ||
504 | <ul> | ||
505 | <li id='inactive'>My Objects:</li> | ||
506 | <?php | ||
507 | if (!isset($_SESSION['objectName'])) | ||
508 | { | ||
509 | $_SESSION['objectName'] = $objectNameList[0]; | ||
510 | } | ||
511 | for($i=0; $i<count($objectNameList); $i++) | ||
512 | { | ||
513 | $name = $objectNameList[$i]; | ||
514 | eval('$instance = new '.$name.'();'); | ||
515 | if (!TestIsMapping($instance)) | ||
516 | { | ||
517 | echo "<li ".($_SESSION['objectName']==$objectNameList[$i]?"id='current'":'')."><a href='./index.php?objectName=".$objectNameList[$i]."'>".$objectNameList[$i]."</a></li>"; | ||
518 | //echo "<a href='./index.php?objectName=".$objectNameList[$i]."'".(isset($_SESSION['objectName']) && $_SESSION['objectName']==$objectNameList[$i]?"class='activetab'":(!isset($_SESSION['objectName'])&&$i==0?"class='activetab'":"inactivetab")).">".$objectNameList[$i]."</a> "; | ||
519 | } | ||
520 | } | ||
521 | ?> | ||
522 | </ul> | ||
523 | </div><!--header--> | ||
524 | </div><!--subtabs--> | ||
525 | <div class="toolbar"><a href="<?php echo $_SESSION['links'][$_SESSION['objectName']]?>" target="_blank" title="modify and regenerate object"><img src="./setup_images/setup_regenerate.jpg" border="0"/></a><a href="#" title="Delete all objects" onclick="if (confirm('Are you sure you want to delete all objects in this table? TPress OK to Delete.')){window.location='./?thrashall=true';}else{alert('Phew, nothing was deleted ;)');}"><img src='./setup_images/setup_deleteall.jpg' alt='delete all' border="0"/></a><a href="#" onclick="javascript:expandAll();return false;" title="expand all nodes"><img src='./setup_images/setup_expandall.jpg' alt='expand all' border="0"/></a><a href="#" onclick="javascript:collapseAll();return false;" title="collapse all nodes"><img src='./setup_images/setup_collapseall.jpg' alt='collapse all' border="0"/></a><a href="#" title="update all objects to newest POG version" onclick="if (confirm('Setup will now attempt to upgrade your objects by contacting the POG SOAP server. Would you like to continue?')){window.location='./setup_library/upgrade.php';}else{alert('Upgrade aborted');}"><img src='./setup_images/setup_updateall.jpg' alt='update all objects' border='0'/></a></div><div class="middle3"> | ||
526 | <?php | ||
527 | //is there an action to perform? | ||
528 | if (isset($_GET['thrashall'])) | ||
529 | { | ||
530 | eval('$instance = new '.$objectName.'();'); | ||
531 | $instanceId = strtolower(get_class($instance))."Id"; | ||
532 | $instanceList = $instance->GetList(array(array($instanceId, ">", "0"))); | ||
533 | foreach ($instanceList as $instance) | ||
534 | { | ||
535 | $instance->Delete(); | ||
536 | } | ||
537 | unset($_GET); | ||
538 | } | ||
539 | echo '<div id="container"></div>'; | ||
540 | $_SESSION['fileNames'] = serialize($fileNames); | ||
541 | $_SESSION['objectNameList'] = serialize($objectNameList); | ||
542 | ?> | ||
543 | <b class="rbottom"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b> | ||
544 | </div><!--middle3--> | ||
545 | </div><!--middle33--> | ||
546 | </div><!--container--> | ||
547 | </form> | ||
548 | <?php | ||
549 | echo "<script>sndReq('GetList', '', '$objectName', '', '', '', '$objectName');</script>"; | ||
550 | } | ||
551 | else if ($_SESSION['diagnosticsSuccessful'] && $_GET['plugins']) | ||
552 | { | ||
553 | ?> | ||
554 | <form action="./index.php?plugins=true" method="POST"> | ||
555 | <div class="container"> | ||
556 | <div class="left"> | ||
557 | <div class="logo3"></div> | ||
558 | <div class="text"><div class="gold">POG documentation summary</div> | ||
559 | <br/><br/>The following 3 documents summarize what POG is all about:<br/><br/> | ||
560 | 1. <a href="http://www.phpobjectgenerator.com/plog/file_download/15">POG Essentials</a><br/><br/> | ||
561 | 2. <a href="http://www.phpobjectgenerator.com/plog/file_download/21" target="_blank">POG Object Relations</a><br/><br/> | ||
562 | 3. <a href="http://www.phpobjectgenerator.com/plog/file_download/18">POG SOAP API</a> | ||
563 | </div><!--text--> | ||
564 | </div><!--left--> | ||
565 | <div class="middle33"> | ||
566 | <div id="tabs3"> | ||
567 | <a href="./index.php?step=diagnostics"><img src="./setup_images/tab_setup.gif"/></a> | ||
568 | <img src="./setup_images/tab_separator.gif"/> | ||
569 | <img src="./setup_images/tab_diagnosticresults.gif"/> | ||
570 | <img src="./setup_images/tab_separator.gif"/> | ||
571 | <a href="./index.php"><img src="./setup_images/tab_manageobjects.gif"/></a> | ||
572 | <img src="./setup_images/tab_separator.gif"/> | ||
573 | <img src="./setup_images/tab_manageplugins_on.gif"/> | ||
574 | </div><!--tabs3--><div class="subtabs"> | ||
575 | <?php | ||
576 | //provide interface to the database | ||
577 | include "./setup_library/xPandMenu.php"; | ||
578 | $root = new XMenu(); | ||
579 | if(file_exists("configuration.php")) | ||
580 | { | ||
581 | include "../configuration.php"; | ||
582 | } | ||
583 | if(file_exists("../objects/class.database.php")) | ||
584 | { | ||
585 | include "../objects/class.database.php"; | ||
586 | } | ||
587 | include_once('../objects/class.pog_base.php'); | ||
588 | if(file_exists($GLOBALS['configuration']['plugins_path']."/IPlugin.php")) | ||
589 | { | ||
590 | include_once($GLOBALS['configuration']['plugins_path'].'/IPlugin.php'); | ||
591 | } | ||
592 | $pluginNameList = unserialize($_SESSION['pluginNameList']); | ||
593 | foreach($pluginNameList as $pluginName) | ||
594 | { | ||
595 | include_once($GLOBALS['configuration']['plugins_path']."/plugin.".$pluginName.".php"); | ||
596 | } | ||
597 | |||
598 | ?> | ||
599 | <div id="header"> | ||
600 | <ul> | ||
601 | <li id='inactive'>My Plugins:</li> | ||
602 | <?php | ||
603 | if (isset($_GET['pluginName'])) | ||
604 | { | ||
605 | $_SESSION['pluginName'] = $_GET['pluginName']; | ||
606 | } | ||
607 | $pluginName = (isset($_SESSION['pluginName'])?$_SESSION['pluginName']:$pluginNameList[0]); | ||
608 | $_SESSION['pluginName'] = $pluginName; | ||
609 | for($i=0; $i<count($pluginNameList); $i++) | ||
610 | { | ||
611 | $name = $pluginNameList[$i]; | ||
612 | echo "<li ".($_SESSION['pluginName']==$pluginNameList[$i]?"id='current'":'')."><a href='./index.php?plugins=true&pluginName=".$pluginNameList[$i]."'>".$pluginNameList[$i]."</a></li>"; | ||
613 | } | ||
614 | $pluginInstance = new $_SESSION['pluginName']('', ''); | ||
615 | ?> | ||
616 | </ul> | ||
617 | </div><!--header--> | ||
618 | </div><!--subtabs--> | ||
619 | <div class="toolbar"><img src="setup_images/button_toolbar_left.gif"/> | ||
620 | <a href='http://plugins.phpobjectgenerator.com/?id=<?=get_class($pluginInstance)?>' target="_blank"><img src="setup_images/button_toolbar_homepage.gif" border='0'/></a> | ||
621 | <img src="setup_images/toolbar_separator.gif"/> | ||
622 | <?php | ||
623 | if ($pluginInstance->AuthorPage() != null) | ||
624 | { | ||
625 | ?> | ||
626 | <a href='<?php echo $pluginInstance->AuthorPage();?>' target="_blank"><img src="setup_images/button_toolbar_author.gif" border='0'/></a> | ||
627 | <img src="setup_images/toolbar_separator.gif"/> | ||
628 | <?php | ||
629 | } | ||
630 | ?> | ||
631 | <a href='http://plugins.phpobjectgenerator.com/?id=<?=get_class($pluginInstance)?>&help' target="_blank"><img src="setup_images/button_toolbar_help.gif" border='0'/></a> | ||
632 | </div><div class="middle3"> | ||
633 | <?php | ||
634 | echo '<div id="container"><div style="padding:30px;">'; | ||
635 | $pluginInstance->SetupRender(); | ||
636 | echo '</div></div>'; | ||
637 | $_SESSION['pluginNameList'] = serialize($pluginNameList); | ||
638 | ?> | ||
639 | <b class="rbottom"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b> | ||
640 | </div><!--middle3--> | ||
641 | </div><!--middle33--> | ||
642 | </div><!--container--> | ||
643 | </form> | ||
644 | <?php | ||
645 | } | ||
646 | else | ||
647 | { | ||
648 | unset($_SESSION['objectNameList'], $_SESSION['fileNames'], $_SESSION['links'], $_SESSION['pluginNameList']); | ||
649 | //welcome screen | ||
650 | ?> | ||
651 | <form action="./index.php" method="POST"> | ||
652 | <div class="container"> | ||
653 | <div class="left"> | ||
654 | <div class="logo"></div> | ||
655 | <div class="text"><div class="gold">What is POG Setup?</div>POG Setup is an extension of the online Php Object Generator. It is meant to help the veteran POG user and the novice alike. | ||
656 | <br/><br/>POG Setup is a 3 step process which:<br/><br/> | ||
657 | 1. Creates tables for your generated objects.<br/><br/> | ||
658 | 2. Performs diagnostics tests on all objects within your 'objects' directory.<br/><br/> | ||
659 | 3. Provides a light interface to your object tables.</div> | ||
660 | </div> | ||
661 | <div class="middle"> | ||
662 | <div id="tabs"> | ||
663 | <img src="./setup_images/tab_setup_on.gif"/> | ||
664 | <img src="./setup_images/tab_separator.gif" height="20px" width="17px"/> | ||
665 | <img src="./setup_images/tab_diagnosticresults.gif" height="20px" width="137px"/> | ||
666 | <img src="./setup_images/tab_separator.gif" height="20px" width="17px"/> | ||
667 | <img src="./setup_images/tab_manageobjects.gif" height="20px" width="129px"/> | ||
668 | <img src="./setup_images/tab_separator.gif"/> | ||
669 | <img src="./setup_images/tab_manageplugins_off.gif"/> | ||
670 | </div> | ||
671 | <div id="nifty"> | ||
672 | <div style="height:500px"> | ||
673 | <img src="./setup_images/setup_welcome.jpg" height="47px" width="617px"/> | ||
674 | <div class="col1"><img src="./setup_images/pog_setup_closed.jpg"/><div class="gold">What is POG?</div>POG generates PHP objects with integrated CRUD methods to dramatically accelerate web application development in PHP. <br/> | ||
675 | <br/>POG allows developers to easily map object attributes onto columns of a database table without having to write SQL queries.</div> | ||
676 | <div class="col2"><img src="./setup_images/pog_setup_open.jpg"/><div class="gold">What is POG Setup?</div>You've generated one or more objects using Php Object Generator ... Now what?<br/> | ||
677 | <br/>POG SETUP is an answer to this question and takes the POG experience one step further. The Setup process automates <b>table creation</b>, <b>unit testing</b> and provides a light <b>scaffolding</b> environment.</div> | ||
678 | <div class="col3"> | ||
679 | <div class="gold">If you are ready to get POG'd up, click on thebutton below to proceed. Doing this will:</div><br/> | ||
680 | <table> | ||
681 | <tr> | ||
682 | <td>TABLES:</td> | ||
683 | <td> | ||
684 | <select class="ss" name="pog_table"> | ||
685 | <option value="align">Align tables with objects (default)</option> | ||
686 | <option value="recreate">Recreate tables</option> | ||
687 | <option value="recreate_import">Recreate tables and initialize data</option> | ||
688 | </select> | ||
689 | </td> | ||
690 | </tr> | ||
691 | <tr> | ||
692 | <td>TESTS:</td> | ||
693 | <td> | ||
694 | <select class="ss" name="pog_test"> | ||
695 | <option value="yes">Perform unit tests (default)</option> | ||
696 | <option value="no">Bypass unit tests</option> | ||
697 | </select> | ||
698 | </td> | ||
699 | </tr> | ||
700 | </table><br/> | ||
701 | <br/><input type="image" onclick="PleaseWait('');" src="./setup_images/setup_pogmeup.gif" name="submit"/> | ||
702 | <div align="center" id="pleasewait" style="display:none;"><img src="./setup_images/loading.gif"/></div> | ||
703 | </div> | ||
704 | </div> | ||
705 | <b class="rbottom"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b> | ||
706 | </div> | ||
707 | </div> | ||
708 | </div> | ||
709 | </form> | ||
710 | <?php | ||
711 | } | ||
712 | ?> | ||
713 | <div class="footer"> | ||
714 | <?php include "setup_library/inc.footer.php";?> | ||
715 | </div> | ||
716 | </body> | ||
717 | </html> | ||
diff --git a/backend/php/src/setup/rpc.php b/backend/php/src/setup/rpc.php new file mode 100644 index 0000000..2e2d0c1 --- a/dev/null +++ b/backend/php/src/setup/rpc.php | |||
@@ -0,0 +1,227 @@ | |||
1 | <?php | ||
2 | include "./setup_library/xPandMenu.php"; | ||
3 | include "./setup_library/setup_misc.php"; | ||
4 | if(file_exists("../configuration.php")) | ||
5 | { | ||
6 | include_once("../configuration.php"); | ||
7 | } | ||
8 | |||
9 | if(file_exists("../objects/class.database.php")) | ||
10 | { | ||
11 | include_once("../objects/class.database.php"); | ||
12 | } | ||
13 | include_once('../objects/class.pog_base.php'); | ||
14 | |||
15 | $objectName = isset($_REQUEST['objectname']) ? $_REQUEST['objectname'] : ''; | ||
16 | $anchor = isset($_REQUEST['anchor']) ? $_REQUEST['anchor'] : ''; | ||
17 | $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : ''; | ||
18 | $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : ''; | ||
19 | |||
20 | |||
21 | //include all classes (possible relations) | ||
22 | $dir = opendir('../objects/'); | ||
23 | $objects = array(); | ||
24 | while(($file = readdir($dir)) !== false) | ||
25 | { | ||
26 | if(strlen($file) > 4 && substr(strtolower($file), strlen($file) - 4) === '.php' && !is_dir($file) && $file != "class.database.php" && $file != "configuration.php" && $file != "setup.php" && $file != "class.pog_base.php") | ||
27 | { | ||
28 | $objects[] = $file; | ||
29 | } | ||
30 | } | ||
31 | closedir($dir); | ||
32 | foreach ($objects as $object) | ||
33 | { | ||
34 | include_once("../objects/{$object}"); | ||
35 | } | ||
36 | |||
37 | eval ('$instance = new '.$objectName.'();'); | ||
38 | $attributeList = array_keys(get_object_vars($instance)); | ||
39 | $noOfExternalAttributes = sizeof($attributeList) - 3; | ||
40 | |||
41 | // get object id to perform action. required for Delete() and Update() | ||
42 | $objectId = isset($_REQUEST['objectid']) ? $_REQUEST['objectid'] : ''; | ||
43 | |||
44 | // get the ids of all open nodes before action is performed | ||
45 | $openNodes = isset($_REQUEST['opennodes']) ? explode('-', $_REQUEST['opennodes']) : ''; | ||
46 | |||
47 | // get action to perform | ||
48 | $action = $_GET['action']; | ||
49 | |||
50 | $currentNode = -1; | ||
51 | if (isset($_GET['currentnode'])) | ||
52 | { | ||
53 | // get the node id on which the action is performed. required for Delete() and Update() | ||
54 | $currentNode = $_GET['currentnode']; | ||
55 | $currentNodeParts = explode('Xnode', $currentNode); | ||
56 | if (isset($currentNodeParts[1])) | ||
57 | { | ||
58 | $currentNode = $currentNodeParts[1]; | ||
59 | } | ||
60 | } | ||
61 | $root = new XMenu(); | ||
62 | |||
63 | if ($openNodes != '') | ||
64 | { | ||
65 | foreach ($openNodes as $openNode) | ||
66 | { | ||
67 | $openNodeParts = explode('Xtree', $openNode); | ||
68 | $noParts = sizeof($openNodeParts); | ||
69 | |||
70 | // all open nodes when action is initiated | ||
71 | if ($noParts > 0 && is_numeric($openNodeParts[$noParts - 1])) | ||
72 | { | ||
73 | // initialize all open nodes | ||
74 | $root->visibleNodes[] = $openNodeParts[$noParts - 1]; | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | // perform requested action | ||
79 | switch($action) | ||
80 | { | ||
81 | case 'Add': | ||
82 | eval ('$instance = new '.$objectName.'();'); | ||
83 | $attributeList = array_keys(get_object_vars($instance)); | ||
84 | foreach($attributeList as $attribute) | ||
85 | { | ||
86 | if ($attribute != "pog_attribute_type" && $attribute!= "pog_query") | ||
87 | { | ||
88 | if (isset($instance->pog_attribute_type[$attribute])) | ||
89 | { | ||
90 | if (isset($_GET[$attribute])) | ||
91 | { | ||
92 | $instance->{$attribute} = $_GET[$attribute]; | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | if ($instance->Save()) | ||
98 | { | ||
99 | for ($i = 0; $i < sizeof($root->visibleNodes); $i++) | ||
100 | { | ||
101 | if ($root->visibleNodes[$i] > ($noOfExternalAttributes + 2)) | ||
102 | { | ||
103 | $root->visibleNodes[$i] += ($noOfExternalAttributes + 1); | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | RefreshTree($anchor, $root); | ||
108 | break; | ||
109 | case 'Refresh': | ||
110 | RefreshTree($objectName, $root, $offset, $limit); | ||
111 | break; | ||
112 | case 'GetList': | ||
113 | RefreshTree($anchor, $root, $offset, $limit); | ||
114 | break; | ||
115 | case 'DeleteDeep': | ||
116 | case 'Delete': | ||
117 | eval ('$instance = new '.$objectName.'();'); | ||
118 | $instance->Get($objectId); | ||
119 | $instance->Delete(($action == 'DeleteDeep')); | ||
120 | for ($i = 0; $i < sizeof($root->visibleNodes); $i++) | ||
121 | { | ||
122 | if ($root->visibleNodes[$i] > ($noOfExternalAttributes + 2)) | ||
123 | { | ||
124 | if (intval($root->visibleNodes[$i]) == intval($openNodeParts[$noParts - 1])) | ||
125 | { | ||
126 | $root->visibleNodes[$i] = null; | ||
127 | } | ||
128 | else if ($root->visibleNodes[$i] > $currentNode) | ||
129 | { | ||
130 | $root->visibleNodes[$i] -= ($noOfExternalAttributes + 1); | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | RefreshTree($anchor, $root); | ||
135 | break; | ||
136 | case 'Update': | ||
137 | eval ('$instance = new '.$objectName.'();'); | ||
138 | $instance->Get($objectId); | ||
139 | $attributeList = array_keys(get_object_vars($instance)); | ||
140 | foreach($attributeList as $attribute) | ||
141 | { | ||
142 | if ($attribute != "pog_attribute_type" && $attribute!= "pog_query") | ||
143 | { | ||
144 | if (isset($instance->pog_attribute_type[$attribute])) | ||
145 | { | ||
146 | if (isset($_GET[$attribute])) | ||
147 | { | ||
148 | $instance->{$attribute} = $_GET[$attribute]; | ||
149 | } | ||
150 | } | ||
151 | } | ||
152 | } | ||
153 | $instance->Save(); | ||
154 | RefreshTree($anchor, $root); | ||
155 | break; | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * Refreshes the tree after an operation while preserving node statuses | ||
160 | * | ||
161 | * @param unknown_type $objectName | ||
162 | * @param unknown_type $root | ||
163 | */ | ||
164 | function RefreshTree($objectName, $root, $offset = '', $limit = '') | ||
165 | { | ||
166 | if ($limit == '') | ||
167 | { | ||
168 | $offset = 0; | ||
169 | $limit = 50; | ||
170 | } | ||
171 | $sqlLimit = "$offset, $limit"; | ||
172 | |||
173 | $js = "new Array("; | ||
174 | eval ('$instance = new '.$objectName.'();'); | ||
175 | $recCount = GetNumberOfRecords(strtolower($objectName)); | ||
176 | $attributeList = array_keys(get_object_vars($instance)); | ||
177 | $instanceList = $instance->GetList(array(array(strtolower($objectName)."Id",">",0)), strtolower($objectName)."Id", false, $sqlLimit); | ||
178 | $x = 0; | ||
179 | $masterNode = &$root->addItem(new XNode("<span style='color:#998D05'>".$objectName."</span> <span style='font-weight:normal'>{Dimensions:[".sizeof($instanceList)."]}</span>", false, "setup_images/folderclose.gif","setup_images/folderopen.gif")); | ||
180 | $node = &$masterNode->addItem(new XNode("<span style='color:#998D05'>ADD RECORD</span>", false,"setup_images/folderclose.gif","setup_images/folderopen.gif")); | ||
181 | foreach($attributeList as $attribute) | ||
182 | { | ||
183 | if ($attribute != "pog_attribute_type" && $attribute!= "pog_query") | ||
184 | { | ||
185 | if ($x != 0 && isset($instance->pog_attribute_type[$attribute])) | ||
186 | { | ||
187 | $js .= '"'.$attribute.'",'; | ||
188 | $thisValue = ConvertAttributeToHtml($attribute, $instance->pog_attribute_type[$attribute]['db_attributes'], $instance->{$attribute}, $instance->{$attributeList[0]}); | ||
189 | $subnode = &$node->addItem(new XNode("<br/><span style='color:#998D05'>".$attribute."</span> <span style='font-weight:normal;color:#ADA8B2;'>{".$instance->pog_attribute_type[$attribute]['db_attributes'][1]."}</span><br/>".$thisValue."<br/>", false,'',"setup_images/folderopen.gif")); | ||
190 | } | ||
191 | } | ||
192 | $x++; | ||
193 | } | ||
194 | $js = trim($js, ","); | ||
195 | $js .= ")"; | ||
196 | $subnode = &$node->addItem(new XNode("<br/><a href='#' onclick='javascript:sndReq(\"Add\", getOpenNodes(), \"$objectName\", \"".$instance->{strtolower($objectName).'Id'}."\", this.parentNode.parentNode.parentNode.parentNode.id, $js, \"$objectName\");return false;'><img src='./setup_images/button_add.gif' border='0'/></a>", false,'',"folderopen.gif")); | ||
197 | |||
198 | if ($instanceList != null) | ||
199 | { | ||
200 | foreach($instanceList as $instance) | ||
201 | { | ||
202 | ConvertObjectToNode($instance, $masterNode, $js, $objectName); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | $menu_html_code = $root->generateTree(); | ||
207 | $menu_html_code .= "<div class='nav'>"; | ||
208 | $pre = "<div class='nav'>"; | ||
209 | if ($offset != '' && $offset != 0) | ||
210 | { | ||
211 | $pre .= "‹‹<a href='#' onclick='javascript:refTree(".($offset-$limit).", $limit, \"$objectName\");return false;'>Newer</a> | "; | ||
212 | $menu_html_code.= "‹‹<a href='#' onclick='javascript:refTree(".($offset-$limit).", $limit, \"$objectName\");return false;'>Newer</a> | "; | ||
213 | } | ||
214 | $pre .= "<b>".($recCount-$offset-$limit < 0 ? 0 : $recCount-$offset-$limit)." - ".($recCount-$offset)." of $recCount </b>"; | ||
215 | $menu_html_code .= "<b>".($recCount-$offset-$limit < 0 ? 0 : $recCount-$offset-$limit)." - ".($recCount-$offset)." of $recCount </b>"; | ||
216 | |||
217 | if ($offset <= $recCount - $limit) | ||
218 | { | ||
219 | $pre .= "| <a href='#' onclick='javascript:refTree(".($offset+$limit).", $limit, \"$objectName\");return false;'>Older</a>››"; | ||
220 | $menu_html_code.= "| <a href='#' onclick='javascript:refTree(".($offset+$limit).", $limit, \"$objectName\");return false;'>Older</a>››"; | ||
221 | } | ||
222 | $menu_html_code .= "</div>"; | ||
223 | $pre .= "</div>"; | ||
224 | $table = "<div id='container'><br/><br/>".$pre.$menu_html_code."</div>"; | ||
225 | echo $table; | ||
226 | } | ||
227 | ?> | ||
diff --git a/backend/php/src/setup/setup.css b/backend/php/src/setup/setup.css new file mode 100644 index 0000000..3c59e53 --- a/dev/null +++ b/backend/php/src/setup/setup.css | |||
@@ -0,0 +1,77 @@ | |||
1 | .container {background:url('./setup_images/gradient_container.gif') top left repeat-x} | ||
2 | .logo {width:234px;height:191px;position:relative;float:left;background:url('./setup_images/setup_logo1.jpg') top left no-repeat} | ||
3 | .logo2 {width:234px;height:191px;position:relative;float:left;background:url('./setup_images/setup_logo2.jpg') top left no-repeat} | ||
4 | .logo3 {width:234px;height:191px;position:relative;float:left;background:url('./setup_images/setup_logo3.jpg') top left no-repeat} | ||
5 | .bottom3 {float:left;display:inline;position:relative;width:100%;background:url('./setup_images/setup_bottom3tile.jpg') top left repeat-x} | ||
6 | .toolbar {float:left;display:inline;width:100%;height:42px;background-color:#444;background:url('./setup_images/setup_toolbargradient.jpg') top left repeat-x} | ||
7 | body {margin:0 auto;padding:0;color:#828282;background:#fff;font:normal 10px Verdana} | ||
8 | .activetab {font-weight:bold;color:#7B7F0E;background:#ccc} | ||
9 | .error {background:#f00} | ||
10 | .warning {background:#0cf} | ||
11 | .succeed {background:#0f0} | ||
12 | .header {width:90%;height:90px;padding:15px 0 0 15px} | ||
13 | .footer {width:90%;padding-left:15px;vertical-align:middle;height:35px} | ||
14 | .footer img {vertical-align:middle;height:35px} | ||
15 | .toolbar img {display:inline} | ||
16 | .bottom3 img {display:inline} | ||
17 | .left {width:234px;height:550px;z-Index:9;position:absolute;} | ||
18 | .text {width:194px;height:319px;line-height:15px;position:relative;float:left;padding:22px} | ||
19 | .gold {color:#998D05;font-weight:bold;display:block;} | ||
20 | .middle {width:617px;padding-left:234px;height:596px;color:#404855} | ||
21 | .middle2 {float:left;position:relative;padding:20px 0 0 22px;width:594px;background:#E7E9EE} | ||
22 | .middle33 {height:596px;position:relative;padding-left:234px;color:#404855} | ||
23 | .middle3 {float:left;position:relative;width:100%;background:#E7E9EE} | ||
24 | .subtabs {padding-top:35px;float:left;position:relative} | ||
25 | #tabs {width:617px;height:20px;float:left} | ||
26 | #tabs3 {width:100%;height:20px;float:left} | ||
27 | #tabs img,#tabs3 img {float:left;border:none} | ||
28 | .middle img,.middle input,.middle2 img,.middle2 input {display:inline;margin:0;padding:0} | ||
29 | a {text-decoration:none;color:#7F7714} | ||
30 | input.i {position:relative;padding:2px 3px;width:200px;color:#5A4F64;font-size:9px;vertical-align:middle;border-top:1px solid #404040;border-left:1px solid #404040;border-right:1px solid #D1D0CC;border-bottom:1px solid #D1D0CC; background-color:#F7F7F7;} | ||
31 | textarea {width:575px;height:325px;font-size:12px;border-top:1px solid #404040;border-left:1px solid #404040;border-right:1px solid #D1D0CC;border-bottom:1px solid #D1D0CC} | ||
32 | textarea.t {width:450px;height:50px;font-size:12px;border-top:1px solid #404040; color:#5A4F64; border-left:1px solid #404040;border-right:1px solid #D1D0CC;border-bottom:1px solid #D1D0CC; background-color:#F7F7F7;} | ||
33 | select.s, input.c {border-top:1px solid #404040; color:#5A4F64; border-left:1px solid #404040;border-right:1px solid #D1D0CC;border-bottom:1px solid #D1D0CC; background-color:#F7F7F7;} | ||
34 | .ss{font-size:95%;} | ||
35 | table {position:relative;display:inline;background:#E8E9EE} | ||
36 | td {height:25px} | ||
37 | .id {font-weight:bold;padding-left:5px} | ||
38 | div#nifty {background:#E7E9EE;margin-top:40px;position:relative;float:left;width:617px} | ||
39 | div.nifty{margin-top:0;background:#E7E9EE} | ||
40 | b.rtop,b.rbottom {display:block;background:#FFF} | ||
41 | b.rtop b {display:block;height:1px;overflow:hidden;background:#FFF} | ||
42 | b.rbottom b {display:block;height:1px;overflow:hidden;background:#E7E9EE} | ||
43 | b.r1 {margin:0 5px} | ||
44 | b.r2 {margin:0 3px} | ||
45 | b.r3 {margin:0 2px} | ||
46 | b.rtop b.r4,b.rbottom b.r4 {margin:0 1px;height:2px} | ||
47 | .col1,.col2 {padding-left:15px;padding-right:15px;margin-left:10px;line-height:14px;color:#848484;position:relative;width:250px;height:270px;display:inline;float:left} | ||
48 | .col3 {width:300px;padding-left:150px;padding-right:150px;height:190px;display:block;float:leftcolor:#848484} | ||
49 | #header {float:left;width:100%;line-height:normal;} | ||
50 | #header ul {margin:0;padding:8px 10px 0;list-style:none;color:#818183} | ||
51 | #header li {float:left;background:url("norm_right.gif") no-repeat right top;margin-right:5px;padding:0} | ||
52 | #header a {display:block;background:url("norm_left.gif") no-repeat left top;padding:3px 8px 2px;color:#B1B97D} | ||
53 | #header #current {background-image:url("./setup_images/tab_activeobjectright.gif")} | ||
54 | #header #current a {background-image:url("./setup_images/tab_activeobjectleft.gif");padding:3px 8px 2px;font-weight:bold;color:#867C1D} | ||
55 | #header #inactive {padding:3px 3px 2px 5px;font-weight:bold} | ||
56 | a.deleteDeep:hover | ||
57 | { | ||
58 | text-decoration:none; | ||
59 | background-color:#9a1818; | ||
60 | color:#fff; | ||
61 | } | ||
62 | a.deleteShallow:hover | ||
63 | { | ||
64 | text-decoration:none; | ||
65 | background-color:#f3e508; | ||
66 | color:#000; | ||
67 | } | ||
68 | a.deleteCancel:hover | ||
69 | { | ||
70 | text-decoration:none; | ||
71 | background-color:#bee8b6; | ||
72 | color:#000; | ||
73 | } | ||
74 | .nav | ||
75 | { | ||
76 | padding-left:80px; | ||
77 | } \ No newline at end of file | ||
diff --git a/backend/php/src/setup/setup_images/background_id.gif b/backend/php/src/setup/setup_images/background_id.gif new file mode 100644 index 0000000..363cc1c --- a/dev/null +++ b/backend/php/src/setup/setup_images/background_id.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/button_add.gif b/backend/php/src/setup/setup_images/button_add.gif new file mode 100644 index 0000000..2b9fc72 --- a/dev/null +++ b/backend/php/src/setup/setup_images/button_add.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/button_delete.gif b/backend/php/src/setup/setup_images/button_delete.gif new file mode 100644 index 0000000..31cc30f --- a/dev/null +++ b/backend/php/src/setup/setup_images/button_delete.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/button_toolbar_author.gif b/backend/php/src/setup/setup_images/button_toolbar_author.gif new file mode 100644 index 0000000..b7f9f2b --- a/dev/null +++ b/backend/php/src/setup/setup_images/button_toolbar_author.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/button_toolbar_help.gif b/backend/php/src/setup/setup_images/button_toolbar_help.gif new file mode 100644 index 0000000..324f1d4 --- a/dev/null +++ b/backend/php/src/setup/setup_images/button_toolbar_help.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/button_toolbar_homepage.gif b/backend/php/src/setup/setup_images/button_toolbar_homepage.gif new file mode 100644 index 0000000..274f235 --- a/dev/null +++ b/backend/php/src/setup/setup_images/button_toolbar_homepage.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/button_toolbar_left.gif b/backend/php/src/setup/setup_images/button_toolbar_left.gif new file mode 100644 index 0000000..a0bbc5f --- a/dev/null +++ b/backend/php/src/setup/setup_images/button_toolbar_left.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/button_update.gif b/backend/php/src/setup/setup_images/button_update.gif new file mode 100644 index 0000000..1ee086f --- a/dev/null +++ b/backend/php/src/setup/setup_images/button_update.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/folderclose.gif b/backend/php/src/setup/setup_images/folderclose.gif new file mode 100644 index 0000000..112a784 --- a/dev/null +++ b/backend/php/src/setup/setup_images/folderclose.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/folderopen.gif b/backend/php/src/setup/setup_images/folderopen.gif new file mode 100644 index 0000000..443dd4e --- a/dev/null +++ b/backend/php/src/setup/setup_images/folderopen.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/generate.jpg b/backend/php/src/setup/setup_images/generate.jpg new file mode 100644 index 0000000..8eb8e71 --- a/dev/null +++ b/backend/php/src/setup/setup_images/generate.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/gradient_container.gif b/backend/php/src/setup/setup_images/gradient_container.gif new file mode 100644 index 0000000..a6430f8 --- a/dev/null +++ b/backend/php/src/setup/setup_images/gradient_container.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/loading.gif b/backend/php/src/setup/setup_images/loading.gif new file mode 100644 index 0000000..bf510da --- a/dev/null +++ b/backend/php/src/setup/setup_images/loading.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/mini_pog.jpg b/backend/php/src/setup/setup_images/mini_pog.jpg new file mode 100644 index 0000000..3cbf683 --- a/dev/null +++ b/backend/php/src/setup/setup_images/mini_pog.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/pog_setup_closed.jpg b/backend/php/src/setup/setup_images/pog_setup_closed.jpg new file mode 100644 index 0000000..e493506 --- a/dev/null +++ b/backend/php/src/setup/setup_images/pog_setup_closed.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/pog_setup_open.jpg b/backend/php/src/setup/setup_images/pog_setup_open.jpg new file mode 100644 index 0000000..4417e8c --- a/dev/null +++ b/backend/php/src/setup/setup_images/pog_setup_open.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_attachtables.jpg b/backend/php/src/setup/setup_images/setup_attachtables.jpg new file mode 100644 index 0000000..0ffeafa --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_attachtables.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_bottom3.jpg b/backend/php/src/setup/setup_images/setup_bottom3.jpg new file mode 100644 index 0000000..798d96d --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_bottom3.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_bottom3tile.jpg b/backend/php/src/setup/setup_images/setup_bottom3tile.jpg new file mode 100644 index 0000000..abbe75d --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_bottom3tile.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_collapseall.jpg b/backend/php/src/setup/setup_images/setup_collapseall.jpg new file mode 100644 index 0000000..5a316c4 --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_collapseall.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_deleteall.jpg b/backend/php/src/setup/setup_images/setup_deleteall.jpg new file mode 100644 index 0000000..f884e74 --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_deleteall.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_expandall.jpg b/backend/php/src/setup/setup_images/setup_expandall.jpg new file mode 100644 index 0000000..52751dd --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_expandall.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_footer.jpg b/backend/php/src/setup/setup_images/setup_footer.jpg new file mode 100644 index 0000000..4b57b24 --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_footer.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_generateform.jpg b/backend/php/src/setup/setup_images/setup_generateform.jpg new file mode 100644 index 0000000..1da8733 --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_generateform.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_logo1.jpg b/backend/php/src/setup/setup_images/setup_logo1.jpg new file mode 100644 index 0000000..6530570 --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_logo1.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_logo2.jpg b/backend/php/src/setup/setup_images/setup_logo2.jpg new file mode 100644 index 0000000..7d05645 --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_logo2.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_logo3.jpg b/backend/php/src/setup/setup_images/setup_logo3.jpg new file mode 100644 index 0000000..8d97149 --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_logo3.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_pogmeup.gif b/backend/php/src/setup/setup_images/setup_pogmeup.gif new file mode 100644 index 0000000..ab95cb7 --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_pogmeup.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_proceed.gif b/backend/php/src/setup/setup_images/setup_proceed.gif new file mode 100644 index 0000000..878b1c2 --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_proceed.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_recheck.jpg b/backend/php/src/setup/setup_images/setup_recheck.jpg new file mode 100644 index 0000000..0b0bcb7 --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_recheck.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_regenerate.jpg b/backend/php/src/setup/setup_images/setup_regenerate.jpg new file mode 100644 index 0000000..878d6bc --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_regenerate.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_toolbargradient.jpg b/backend/php/src/setup/setup_images/setup_toolbargradient.jpg new file mode 100644 index 0000000..1a9fede --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_toolbargradient.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_updateall.jpg b/backend/php/src/setup/setup_images/setup_updateall.jpg new file mode 100644 index 0000000..2b8be24 --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_updateall.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/setup_welcome.jpg b/backend/php/src/setup/setup_images/setup_welcome.jpg new file mode 100644 index 0000000..59a03e4 --- a/dev/null +++ b/backend/php/src/setup/setup_images/setup_welcome.jpg | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/tab_activeobjectleft.gif b/backend/php/src/setup/setup_images/tab_activeobjectleft.gif new file mode 100644 index 0000000..c80504a --- a/dev/null +++ b/backend/php/src/setup/setup_images/tab_activeobjectleft.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/tab_activeobjectright.gif b/backend/php/src/setup/setup_images/tab_activeobjectright.gif new file mode 100644 index 0000000..646f0b0 --- a/dev/null +++ b/backend/php/src/setup/setup_images/tab_activeobjectright.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/tab_diagnosticresults.gif b/backend/php/src/setup/setup_images/tab_diagnosticresults.gif new file mode 100644 index 0000000..f0e9a5b --- a/dev/null +++ b/backend/php/src/setup/setup_images/tab_diagnosticresults.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/tab_diagnosticresults_on.gif b/backend/php/src/setup/setup_images/tab_diagnosticresults_on.gif new file mode 100644 index 0000000..e2b8002 --- a/dev/null +++ b/backend/php/src/setup/setup_images/tab_diagnosticresults_on.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/tab_manageobjects.gif b/backend/php/src/setup/setup_images/tab_manageobjects.gif new file mode 100644 index 0000000..06b72b2 --- a/dev/null +++ b/backend/php/src/setup/setup_images/tab_manageobjects.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/tab_manageobjects_on.gif b/backend/php/src/setup/setup_images/tab_manageobjects_on.gif new file mode 100644 index 0000000..55006a3 --- a/dev/null +++ b/backend/php/src/setup/setup_images/tab_manageobjects_on.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/tab_manageplugins_off.gif b/backend/php/src/setup/setup_images/tab_manageplugins_off.gif new file mode 100644 index 0000000..d55f605 --- a/dev/null +++ b/backend/php/src/setup/setup_images/tab_manageplugins_off.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/tab_manageplugins_on.gif b/backend/php/src/setup/setup_images/tab_manageplugins_on.gif new file mode 100644 index 0000000..1b26ee0 --- a/dev/null +++ b/backend/php/src/setup/setup_images/tab_manageplugins_on.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/tab_separator.gif b/backend/php/src/setup/setup_images/tab_separator.gif new file mode 100644 index 0000000..76bb9cf --- a/dev/null +++ b/backend/php/src/setup/setup_images/tab_separator.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/tab_setup.gif b/backend/php/src/setup/setup_images/tab_setup.gif new file mode 100644 index 0000000..a4a5a75 --- a/dev/null +++ b/backend/php/src/setup/setup_images/tab_setup.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/tab_setup_on.gif b/backend/php/src/setup/setup_images/tab_setup_on.gif new file mode 100644 index 0000000..c3d4a41 --- a/dev/null +++ b/backend/php/src/setup/setup_images/tab_setup_on.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_images/toolbar_separator.gif b/backend/php/src/setup/setup_images/toolbar_separator.gif new file mode 100644 index 0000000..e061b56 --- a/dev/null +++ b/backend/php/src/setup/setup_images/toolbar_separator.gif | |||
Binary files differ | |||
diff --git a/backend/php/src/setup/setup_library/authentication.php b/backend/php/src/setup/setup_library/authentication.php new file mode 100644 index 0000000..6a6954a --- a/dev/null +++ b/backend/php/src/setup/setup_library/authentication.php | |||
@@ -0,0 +1,30 @@ | |||
1 | <?php | ||
2 | if (sizeof($_POST) > 0 && $GLOBALS['configuration']['setup_password'] != "" && (!isset($_SESSION['authenticated']) || !$_SESSION['authenticated'])) | ||
3 | { | ||
4 | if ($_POST['setup_password'] == $GLOBALS['configuration']['setup_password']) | ||
5 | { | ||
6 | $_SESSION['authenticated'] = true; | ||
7 | } | ||
8 | $_POST = null; | ||
9 | } | ||
10 | if ((!isset($_SESSION['authenticated']) || !$_SESSION['authenticated']) && $GLOBALS['configuration']['setup_password'] != "") | ||
11 | { | ||
12 | ?> | ||
13 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
14 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
15 | <head> | ||
16 | <title>Php Object Generator Setup <?=$GLOBALS['configuration']['versionNumber'].$GLOBALS['configuration']['revisionNumber']?></title> | ||
17 | <link rel="stylesheet" href="./setup.css" type="text/css" /> | ||
18 | <link rel="stylesheet" type="text/css" href="./setup_library/xPandMenu.css"/> | ||
19 | <div align="center"> | ||
20 | <form action="./index.php" method="POST"><br/> | ||
21 | <img src="setup_images/mini_pog.jpg"/><br/><br/> | ||
22 | <input name="setup_password" type="password" class="i"/> | ||
23 | <br/><br/><input type="image" src="setup_images/generate.jpg" name="submit"/> | ||
24 | </form> | ||
25 | </div> | ||
26 | </html> | ||
27 | <?php | ||
28 | exit; | ||
29 | } | ||
30 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/setup/setup_library/class.zipfile.php b/backend/php/src/setup/setup_library/class.zipfile.php new file mode 100644 index 0000000..4bbe779 --- a/dev/null +++ b/backend/php/src/setup/setup_library/class.zipfile.php | |||
@@ -0,0 +1,212 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Class to dynamically create a zip file (archive) | ||
5 | * | ||
6 | * @author Rochak Chauhan. Extended by Joel Wan & Mark Slemko | ||
7 | */ | ||
8 | |||
9 | class createZip { | ||
10 | var $compressedData = array(); | ||
11 | var $centralDirectory = array(); // central directory | ||
12 | var $endOfCentralDirectory = "\x50\x4b\x05\x06\x00\x00\x00\x00"; //end of Central directory record | ||
13 | var $oldOffset = 0; | ||
14 | |||
15 | /** | ||
16 | * Function to create the directory where the file(s) will be unzipped | ||
17 | * | ||
18 | * @param $directoryName string | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | function addDirectory($directoryName) { | ||
23 | $directoryName = str_replace("\\", "/", $directoryName); | ||
24 | |||
25 | $feedArrayRow = "\x50\x4b\x03\x04"; | ||
26 | $feedArrayRow .= "\x0a\x00"; | ||
27 | $feedArrayRow .= "\x00\x00"; | ||
28 | $feedArrayRow .= "\x00\x00"; | ||
29 | $feedArrayRow .= "\x00\x00\x00\x00"; | ||
30 | |||
31 | $feedArrayRow .= pack("V",0); | ||
32 | $feedArrayRow .= pack("V",0); | ||
33 | $feedArrayRow .= pack("V",0); | ||
34 | $feedArrayRow .= pack("v", strlen($directoryName) ); | ||
35 | $feedArrayRow .= pack("v", 0 ); | ||
36 | $feedArrayRow .= $directoryName; | ||
37 | |||
38 | $feedArrayRow .= pack("V",0); | ||
39 | $feedArrayRow .= pack("V",0); | ||
40 | $feedArrayRow .= pack("V",0); | ||
41 | |||
42 | $this -> compressedData[] = $feedArrayRow; | ||
43 | |||
44 | $newOffset = strlen(implode("", $this->compressedData)); | ||
45 | |||
46 | $addCentralRecord = "\x50\x4b\x01\x02"; | ||
47 | $addCentralRecord .="\x00\x00"; | ||
48 | $addCentralRecord .="\x0a\x00"; | ||
49 | $addCentralRecord .="\x00\x00"; | ||
50 | $addCentralRecord .="\x00\x00"; | ||
51 | $addCentralRecord .="\x00\x00\x00\x00"; | ||
52 | $addCentralRecord .= pack("V",0); | ||
53 | $addCentralRecord .= pack("V",0); | ||
54 | $addCentralRecord .= pack("V",0); | ||
55 | $addCentralRecord .= pack("v", strlen($directoryName) ); | ||
56 | $addCentralRecord .= pack("v", 0 ); | ||
57 | $addCentralRecord .= pack("v", 0 ); | ||
58 | $addCentralRecord .= pack("v", 0 ); | ||
59 | $addCentralRecord .= pack("v", 0 ); | ||
60 | $ext = "\x00\x00\x10\x00"; | ||
61 | $ext = "\xff\xff\xff\xff"; | ||
62 | $addCentralRecord .= pack("V", 16 ); | ||
63 | |||
64 | $addCentralRecord .= pack("V", $this -> oldOffset ); | ||
65 | $this -> oldOffset = $newOffset; | ||
66 | |||
67 | $addCentralRecord .= $directoryName; | ||
68 | |||
69 | $this -> centralDirectory[] = $addCentralRecord; | ||
70 | } | ||
71 | |||
72 | /** | ||
73 | * Function to add file(s) to the specified directory in the archive | ||
74 | * | ||
75 | * @param $directoryName string | ||
76 | * | ||
77 | */ | ||
78 | |||
79 | function addFile($data, $directoryName) { | ||
80 | |||
81 | $directoryName = str_replace("\\", "/", $directoryName); | ||
82 | |||
83 | $feedArrayRow = "\x50\x4b\x03\x04"; | ||
84 | $feedArrayRow .= "\x14\x00"; | ||
85 | $feedArrayRow .= "\x00\x00"; | ||
86 | $feedArrayRow .= "\x08\x00"; | ||
87 | $feedArrayRow .= "\x00\x00\x00\x00"; | ||
88 | |||
89 | $uncompressedLength = strlen($data); | ||
90 | $compression = crc32($data); | ||
91 | $gzCompressedData = gzcompress($data); | ||
92 | $gzCompressedData = substr( substr($gzCompressedData, 0, strlen($gzCompressedData) - 4), 2); | ||
93 | $compressedLength = strlen($gzCompressedData); | ||
94 | $feedArrayRow .= pack("V",$compression); | ||
95 | $feedArrayRow .= pack("V",$compressedLength); | ||
96 | $feedArrayRow .= pack("V",$uncompressedLength); | ||
97 | $feedArrayRow .= pack("v", strlen($directoryName) ); | ||
98 | $feedArrayRow .= pack("v", 0 ); | ||
99 | $feedArrayRow .= $directoryName; | ||
100 | |||
101 | $feedArrayRow .= $gzCompressedData; | ||
102 | |||
103 | $feedArrayRow .= pack("V",$compression); | ||
104 | $feedArrayRow .= pack("V",$compressedLength); | ||
105 | $feedArrayRow .= pack("V",$uncompressedLength); | ||
106 | |||
107 | $this -> compressedData[] = $feedArrayRow; | ||
108 | |||
109 | $newOffset = strlen(implode("", $this->compressedData)); | ||
110 | |||
111 | $addCentralRecord = "\x50\x4b\x01\x02"; | ||
112 | $addCentralRecord .="\x00\x00"; | ||
113 | $addCentralRecord .="\x14\x00"; | ||
114 | $addCentralRecord .="\x00\x00"; | ||
115 | $addCentralRecord .="\x08\x00"; | ||
116 | $addCentralRecord .="\x00\x00\x00\x00"; | ||
117 | $addCentralRecord .= pack("V",$compression); | ||
118 | $addCentralRecord .= pack("V",$compressedLength); | ||
119 | $addCentralRecord .= pack("V",$uncompressedLength); | ||
120 | $addCentralRecord .= pack("v", strlen($directoryName) ); | ||
121 | $addCentralRecord .= pack("v", 0 ); | ||
122 | $addCentralRecord .= pack("v", 0 ); | ||
123 | $addCentralRecord .= pack("v", 0 ); | ||
124 | $addCentralRecord .= pack("v", 0 ); | ||
125 | $addCentralRecord .= pack("V", 32 ); | ||
126 | |||
127 | $addCentralRecord .= pack("V", $this -> oldOffset ); | ||
128 | $this -> oldOffset = $newOffset; | ||
129 | |||
130 | $addCentralRecord .= $directoryName; | ||
131 | |||
132 | $this -> centralDirectory[] = $addCentralRecord; | ||
133 | } | ||
134 | |||
135 | /** | ||
136 | * Fucntion to return the zip file | ||
137 | * | ||
138 | * @return zipfile (archive) | ||
139 | */ | ||
140 | |||
141 | function getZippedfile() { | ||
142 | |||
143 | $data = implode("", $this -> compressedData); | ||
144 | $controlDirectory = implode("", $this -> centralDirectory); | ||
145 | |||
146 | return | ||
147 | $data. | ||
148 | $controlDirectory. | ||
149 | $this -> endOfCentralDirectory. | ||
150 | pack("v", sizeof($this -> centralDirectory)). | ||
151 | pack("v", sizeof($this -> centralDirectory)). | ||
152 | pack("V", strlen($controlDirectory)). | ||
153 | pack("V", strlen($data)). | ||
154 | "\x00\x00"; | ||
155 | } | ||
156 | |||
157 | /** | ||
158 | * | ||
159 | * Function to force the download of the archive as soon as it is created | ||
160 | * | ||
161 | * @param archiveName string - name of the created archive file | ||
162 | */ | ||
163 | |||
164 | function forceDownload($archiveName) { | ||
165 | $headerInfo = ''; | ||
166 | header("Pragma: public"); | ||
167 | header("Expires: 0"); | ||
168 | header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | ||
169 | header("Cache-Control: private",false); | ||
170 | header("Content-Type: application/zip"); | ||
171 | header("Content-Disposition: attachment; filename=".basename($archiveName).";" ); | ||
172 | header("Content-Transfer-Encoding: binary"); | ||
173 | echo $this->getZippedfile(); | ||
174 | |||
175 | } | ||
176 | |||
177 | /** | ||
178 | * Generates zip file from POG package. | ||
179 | * | ||
180 | * @param multi-d array $package | ||
181 | * @param array $paths | ||
182 | */ | ||
183 | function addPOGPackage($package, $paths=array()) | ||
184 | { | ||
185 | |||
186 | $i = 0; | ||
187 | foreach ($package as $key=>$value) | ||
188 | { | ||
189 | $path = ''; | ||
190 | foreach ($paths as $p) | ||
191 | { | ||
192 | $path .= (($path == '') ? $p : "/$p"); | ||
193 | } | ||
194 | if (strpos($key, ".") == false) | ||
195 | { | ||
196 | $paths[] = $key; | ||
197 | $this->addDirectory((($path == '') ? "$key/" : "$path/$key/")); | ||
198 | $this->addPOGPackage($package[$key], &$paths); | ||
199 | } | ||
200 | else | ||
201 | { | ||
202 | $this->addFile(base64_decode($value), (($path == '') ? $key : "$path/$key")); | ||
203 | } | ||
204 | if ($i == (sizeof($package)-1)) | ||
205 | { | ||
206 | array_pop($paths); | ||
207 | } | ||
208 | $i++; | ||
209 | } | ||
210 | } | ||
211 | } | ||
212 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/setup/setup_library/inc.footer.php b/backend/php/src/setup/setup_library/inc.footer.php new file mode 100644 index 0000000..d00549d --- a/dev/null +++ b/backend/php/src/setup/setup_library/inc.footer.php | |||
@@ -0,0 +1,6 @@ | |||
1 | <img src="./setup_images/setup_footer.jpg"/> | ||
2 | <a href="http://www.phpobjectgenerator.com" title="Php Object Generator Homepage">PHP Object Generator</a> | | ||
3 | <a href="http://www.phpobjectgenerator.com/plog" title="Php Weblog">POG Weblog</a> | | ||
4 | <a href="http://groups.google.com/group/Php-Object-Generator" title="POG Google Group">Google group</a> | | ||
5 | <a href="http://www.phpobjectgenerator.com/plog/tutorials" title="POG Tutorials">Tutorials</a> | | ||
6 | <a href="mailto:pogguys@phpobjectgenerator.com" title="Contact the POG authors">Contact us</a> \ No newline at end of file | ||
diff --git a/backend/php/src/setup/setup_library/inc.header.php b/backend/php/src/setup/setup_library/inc.header.php new file mode 100644 index 0000000..e53b36d --- a/dev/null +++ b/backend/php/src/setup/setup_library/inc.header.php | |||
@@ -0,0 +1,36 @@ | |||
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
2 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
3 | <head> | ||
4 | <title>Php Object Generator Setup <?=$GLOBALS['configuration']['versionNumber'].$GLOBALS['configuration']['revisionNumber']?></title> | ||
5 | <link rel="stylesheet" type="text/css" href="./setup_library/xPandMenu.css"/> | ||
6 | <link rel="stylesheet" href="./setup.css" type="text/css" /> | ||
7 | <script src="./setup_library/xPandMenu.js"></script> | ||
8 | </head> | ||
9 | <body> | ||
10 | <div class="header"> | ||
11 | <script type="text/javascript"><!-- | ||
12 | google_ad_client = "pub-7832108692498114"; | ||
13 | google_alternate_color = "FFFFFF"; | ||
14 | google_ad_width = 728; | ||
15 | google_ad_height = 90; | ||
16 | google_ad_format = "728x90_as"; | ||
17 | google_ad_type = "text"; | ||
18 | google_ad_channel ="1767526614"; | ||
19 | google_color_border = "FFFFFF"; | ||
20 | google_color_bg = "FFFFFF"; | ||
21 | google_color_link = "716500"; | ||
22 | google_color_url = "B8B8B8"; | ||
23 | google_color_text = "CCC078"; | ||
24 | //--></script> | ||
25 | <script type="text/javascript" | ||
26 | src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> | ||
27 | </script> | ||
28 | <script type="text/javascript"><!-- | ||
29 | function PleaseWait(id) | ||
30 | { | ||
31 | var div = document.getElementById("pleasewait"+id); | ||
32 | div.style.display = "block"; | ||
33 | return false; | ||
34 | } | ||
35 | //--></script> | ||
36 | </div> \ No newline at end of file | ||
diff --git a/backend/php/src/setup/setup_library/setup_misc.php b/backend/php/src/setup/setup_library/setup_misc.php new file mode 100644 index 0000000..f0e4f0e --- a/dev/null +++ b/backend/php/src/setup/setup_library/setup_misc.php | |||
@@ -0,0 +1,2357 @@ | |||
1 | <?php | ||
2 | |||
3 | |||
4 | /** | ||
5 | * Specifies what test data is used during unit testing (step 2 of the setup process) | ||
6 | * Todo: Can be improved but satisfatory for now | ||
7 | * @return array | ||
8 | */ | ||
9 | function InitializeTestValues($pog_attribute_type) | ||
10 | { | ||
11 | $DATETIME = '1997-12-15 23:50:26'; | ||
12 | $DATE = '1997-12-15'; | ||
13 | $TIMESTAMP = '1997-12-15 23:50:26'; | ||
14 | $TIME = '23:50:26'; | ||
15 | $YEAR = '1997'; | ||
16 | $DECIMAL = | ||
17 | $DOUBLE = | ||
18 | $FLOAT = | ||
19 | $BIGINT = | ||
20 | $INT = '12345678'; | ||
21 | $SMALLINT = '1234'; | ||
22 | $MEDIUMINT = '12345'; | ||
23 | $TINYINT = '1'; | ||
24 | $CHAR = 'L'; | ||
25 | $VARCHAR = | ||
26 | $TEXT = | ||
27 | $TINYBLOB = | ||
28 | $TINYTEXT = | ||
29 | $BLOB = | ||
30 | $MEDIUMBLOB = | ||
31 | $MEDIUMTEXT = | ||
32 | $LONGBLOB = | ||
33 | $BINARY= | ||
34 | $LONGTEXT = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry'; | ||
35 | $attribute_testValues = array(); | ||
36 | array_shift($pog_attribute_type); //get rid of objectid | ||
37 | foreach ($pog_attribute_type as $attribute => $property) | ||
38 | { | ||
39 | if (isset($property['db_attributes'][2])) | ||
40 | //length is specified, for e.g. if attribute = VARCHAR(255), $property[2]=255 | ||
41 | { | ||
42 | $limit = explode(',', $property['db_attributes'][2]); | ||
43 | //field is limited | ||
44 | if (intval($limit[0]) > 0) | ||
45 | { | ||
46 | if (isset($limit[1]) && intval($limit[1]) > 0) | ||
47 | { | ||
48 | //decimal, enum, set | ||
49 | $attribute_testValues[$attribute] = substr(${$property['db_attributes'][1]}, 0, ceil($limit[0]*0.6)).".".substr(${$property['db_attributes'][1]}, 0, $limit[1]); | ||
50 | } | ||
51 | else | ||
52 | { | ||
53 | $attribute_testValues[$attribute] = substr(${$property['db_attributes'][1]}, 0, ceil($limit[0] * 0.6)); | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | else | ||
58 | //length not specified, but we still need to account for default mysql behavior | ||
59 | //for eg, FLOAT(X), if X isn't specified, mysql defaults to (10,2). | ||
60 | { | ||
61 | if ($property['db_attributes'][1] == "FLOAT" || $property['db_attributes'][1] == "DOUBLE") | ||
62 | { | ||
63 | $attribute_testValues[$attribute] = "1234.56"; | ||
64 | } | ||
65 | else if ($property['db_attributes'][1] != "HASMANY" && $property['db_attributes'][1] != "BELONGSTO" && $property['db_attributes'][1] != "JOIN") | ||
66 | { | ||
67 | $attribute_testValues[$attribute] = ${$property['db_attributes'][1]}; | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | return $attribute_testValues; | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * Specifies how object attributes are rendered during scaffolding (step 3 of the setup process) | ||
76 | * Todo: Can be improved but satisfactory for now | ||
77 | * @param string $attributeName | ||
78 | * @param string $attributeType | ||
79 | * @param string $attributeValue | ||
80 | * @param int $objectId | ||
81 | * @return string $html | ||
82 | */ | ||
83 | function ConvertAttributeToHtml($attributeName, $attributeProperties, $attributeValue='', $objectId='') | ||
84 | { | ||
85 | switch ($attributeProperties[1]) | ||
86 | { | ||
87 | case "ENUM": | ||
88 | $enumParts = explode(',', $attributeProperties[2]); | ||
89 | $html = "<select id='".($objectId != ''?$attributeName."_".$objectId:$attributeName)."' class='s'>"; | ||
90 | foreach ($enumParts as $enumPart) | ||
91 | { | ||
92 | if ($attributeValue == trim($enumPart, "\' ")) | ||
93 | { | ||
94 | $html .= "<option value='".trim($enumPart, "\' ")."' selected>".trim($enumPart, "\' ")."</option>"; | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | $html .= "<option value='".trim($enumPart, "\' ")."'>".trim($enumPart, "\' ")."</option>"; | ||
99 | } | ||
100 | } | ||
101 | $html .= "</select>"; | ||
102 | break; | ||
103 | case "HASMANY": | ||
104 | case "JOIN": | ||
105 | case "BELONGSTO": | ||
106 | $html = $attributeValue; | ||
107 | break; | ||
108 | case "MEDIUMBLOB": | ||
109 | $html = "sorry. cannot render attribute of type LONGBLOB"; | ||
110 | break; | ||
111 | case "LONGBLOB": | ||
112 | $html = "sorry. cannot render attribute of type LONGBLOB"; | ||
113 | break; | ||
114 | case "TEXT": | ||
115 | case "LONGTEXT": | ||
116 | case "BINARY": | ||
117 | case "MEDIUMTEXT": | ||
118 | case "TINYTEXT": | ||
119 | case "VARCHAR": | ||
120 | case "TINYBLOB": | ||
121 | case "BLOB": | ||
122 | $html = "<textarea class='t' id='".($objectId != ''?$attributeName."_".$objectId:$attributeName)."'>".($attributeValue != ''?$attributeValue:'')."</textarea>"; | ||
123 | break; | ||
124 | case "DATETIME": | ||
125 | case "DATE": | ||
126 | case "TIMESTAMP": | ||
127 | case "TIME": | ||
128 | case "YEAR": | ||
129 | case "DECIMAL": | ||
130 | case "DOUBLE": | ||
131 | case "FLOAT": | ||
132 | case "BIGINT": | ||
133 | case "INT": | ||
134 | case "YEAR": | ||
135 | case "SMALLINT": | ||
136 | case "MEDIUMINT": | ||
137 | case "TINYINT": | ||
138 | case "CHAR": | ||
139 | $html = "<input class='i' id='".($objectId != ''?$attributeName."_".$objectId:$attributeName)."' value='".($attributeValue != ''?$attributeValue:'')."' type='text' />"; | ||
140 | break; | ||
141 | default: | ||
142 | $html = substr($attributeValue, 0, 500); | ||
143 | if (strlen($attributeValue) > 500) | ||
144 | { | ||
145 | $html .= "..."; | ||
146 | } | ||
147 | break; | ||
148 | } | ||
149 | return $html; | ||
150 | } | ||
151 | |||
152 | /** | ||
153 | * Renders an object as an Xtree Node | ||
154 | * | ||
155 | * @param unknown_type $child | ||
156 | */ | ||
157 | function ConvertObjectToNode(&$instance, &$masterNode, $js, $anchor, $once = false) | ||
158 | { | ||
159 | $attributeList = array_keys(get_object_vars($instance)); | ||
160 | $objectName = $className = get_class($instance); | ||
161 | $node = &$masterNode->addItem(new XNode("<span style='color:#0BAA9D'>[".$instance->{strtolower($className)."Id"}."]</span> <a href='#' onclick='ToggleElementVisibility(\"deleteConfirm_".$instance->{strtolower($objectName).'Id'}."\");return false;'><img src=\"./setup_images/button_delete.gif\" border=\"0\"/></a> <span id='deleteConfirm_".$instance->{strtolower($objectName).'Id'}."' style='display:none;width:250px;'><a href='#' class='deleteDeep' onclick='javascript:sndReq(\"DeleteDeep\", getOpenNodes(), \"$objectName\", \"".$instance->{strtolower($objectName).'Id'}."\", this.parentNode.parentNode.parentNode.parentNode.id, $js, \"$anchor\");return false;'>Delete(deep)</a> | <a href='#' class='deleteShallow' onclick='javascript:sndReq(\"Delete\", getOpenNodes(), \"$objectName\", \"".$instance->{strtolower($objectName).'Id'}."\", this.parentNode.parentNode.parentNode.parentNode.id, $js, \"$anchor\");return false;'>Delete(shallow)</a> | <a href='#' class='deleteCancel' onclick='ToggleElementVisibility(\"deleteConfirm_".$instance->{strtolower($objectName).'Id'}."\");return false;'>Cancel</a></span>", false,"setup_images/folderclose.gif","setup_images/folderopen.gif")); | ||
162 | |||
163 | //regular attributes | ||
164 | foreach($attributeList as $attribute) | ||
165 | { | ||
166 | if ($attribute != "pog_attribute_type" && $attribute!= "pog_query" ) | ||
167 | { | ||
168 | if (isset($instance->pog_attribute_type[$attribute])) | ||
169 | { | ||
170 | $thisValue = ConvertAttributeToHtml($attribute, $instance->pog_attribute_type[$attribute]['db_attributes'], $instance->{$attribute}, $instance->{$attributeList[0]}); | ||
171 | $subnode = &$node->addItem(new XNode("<br/>".$attribute."<span style='font-weight:normal;color:#ADA8B2;'>{".$instance->pog_attribute_type[$attribute]['db_attributes'][1]."}</span><br/>".str_replace("\0", "", $thisValue)."<br/><br/>", false,'',"setup_images/folderopen.gif")); | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | |||
176 | //parents, children and mapping | ||
177 | foreach ($instance->pog_attribute_type as $attribute_name => $attrubute_type) | ||
178 | { | ||
179 | if ($attrubute_type['db_attributes'][1] == "HASMANY" || $attrubute_type['db_attributes'][1] == "BELONGSTO" || $attrubute_type['db_attributes'][1] == "JOIN") | ||
180 | { | ||
181 | if ($attrubute_type['db_attributes'][1] == "BELONGSTO") | ||
182 | { | ||
183 | eval ('$value = $instance->'.strtolower($attribute_name).'Id;'); | ||
184 | $thisValue = ConvertAttributeToHtml($attribute_name, $attrubute_type['db_attributes'], $value, ''); | ||
185 | $subnode = &$node->addItem(new XNode("<br/>".$attribute_name."<span style='font-weight:normal;color:#ADA8B2;'>{".($attrubute_type['db_attributes'][1] == "HASMANY" ? "CHILD" : "PARENT")."}</span><br/>".$thisValue."<br/><br/>", false,'',"setup_images/folderopen.gif")); | ||
186 | } | ||
187 | else | ||
188 | { | ||
189 | $value = ''; | ||
190 | eval('$siblingList = $instance->Get'.ucfirst(strtolower($attribute_name)).'List();'); | ||
191 | if (sizeof($siblingList) > 0) | ||
192 | { | ||
193 | $myNode = &$node->addItem(new XNode("<span style='color:#4d4a4a'>[".$attribute_name."List]{Dimensions:[".sizeof($siblingList)."]}</span>", false, "setup_images/folderclose.gif","setup_images/folderopen.gif", true)); | ||
194 | $child = $siblingList[0]; | ||
195 | $js2 = "new Array("; | ||
196 | $attributeList = array_keys(get_object_vars($child)); | ||
197 | $x=0; | ||
198 | foreach($attributeList as $attribute) | ||
199 | { | ||
200 | if ($attribute != "pog_attribute_type" && $attribute!= "pog_query") | ||
201 | { | ||
202 | if ($x != 0 && isset($child->pog_attribute_type[$attribute])) | ||
203 | { | ||
204 | $js2 .= '"'.$attribute.'",'; | ||
205 | } | ||
206 | } | ||
207 | $x++; | ||
208 | } | ||
209 | $js2 = trim($js2, ","); | ||
210 | $js2 .= ")"; | ||
211 | |||
212 | if (!$once) | ||
213 | { | ||
214 | foreach ($siblingList as $child) | ||
215 | { | ||
216 | /*$value .= $child->{strtolower($attribute_name)."Id"} . ",";*/ | ||
217 | if ($attrubute_type['db_attributes'][1] == "JOIN") | ||
218 | { | ||
219 | ConvertObjectToNode($child, $myNode, $js2, $anchor, true); | ||
220 | } | ||
221 | else | ||
222 | { | ||
223 | ConvertObjectToNode($child, $myNode, $js2, $anchor); | ||
224 | } | ||
225 | } | ||
226 | } | ||
227 | } | ||
228 | else | ||
229 | { | ||
230 | $node->addItem(new XNode("<span style='color:#4d4a4a'>[".$attribute_name."List]{Dimensions:[0]}</span><br/><br/>", false, '',"setup_images/folderopen.gif")); | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | $subnode = &$node->addItem(new XNode("<br/><a style='float:left;' href='#' onclick='javascript:PleaseWait(\"".$instance->{strtolower($objectName).'Id'}."\"); sndReq(\"Update\", getOpenNodes(), \"$objectName\", \"".$instance->{strtolower($objectName).'Id'}."\", this.parentNode.parentNode.parentNode.parentNode.id, $js, \"$anchor\");return false;'><img src='./setup_images/button_update.gif' border='0'/></a><span id='pleasewait".$instance->{strtolower($objectName).'Id'}."' style='float:left;display:none;'><img src='./setup_images/loading.gif' style='float:left;'/></span><br/>", false,'',"folderopen.gif")); | ||
236 | } | ||
237 | |||
238 | |||
239 | /** | ||
240 | * Populates object attributes with test values | ||
241 | * | ||
242 | * @param unknown_type $object | ||
243 | * @return unknown | ||
244 | */ | ||
245 | function PopulateTestValues(&$object) | ||
246 | { | ||
247 | $attributeList = array_keys(get_object_vars($object)); | ||
248 | $type_value = InitializeTestValues($object->pog_attribute_type); | ||
249 | |||
250 | $objectName = get_class($object); | ||
251 | foreach($attributeList as $attribute) | ||
252 | { | ||
253 | if (isset($object->pog_attribute_type[$attribute])) | ||
254 | { | ||
255 | if (isset($type_value[$attribute])) | ||
256 | { | ||
257 | $object->{$attribute} = $type_value[$attribute]; | ||
258 | } | ||
259 | else if ($object->pog_attribute_type[$attribute]['db_attributes'][0] != "OBJECT") | ||
260 | { | ||
261 | $object->{$attribute} = "1"; | ||
262 | } | ||
263 | } | ||
264 | } | ||
265 | eval ("\$object -> ".strtolower($objectName)."Id = '';"); | ||
266 | return $object; | ||
267 | } | ||
268 | |||
269 | /** | ||
270 | * Extracts @link from object file | ||
271 | * | ||
272 | * @param unknown_type $objectFilePath | ||
273 | * @return unknown | ||
274 | */ | ||
275 | function GetAtLink($objectFilePath) | ||
276 | { | ||
277 | $link = ''; | ||
278 | $content = file_get_contents($objectFilePath); | ||
279 | $contentParts = split("<b>",$content); | ||
280 | if (isset($contentParts[1])) | ||
281 | { | ||
282 | $contentParts2 = split("</b>",$contentParts[1]); | ||
283 | } | ||
284 | if (isset($contentParts2[0])) | ||
285 | { | ||
286 | $className = trim($contentParts2[0]); | ||
287 | } | ||
288 | if (isset($className)) | ||
289 | { | ||
290 | $linkParts1 = split("\*\/", $contentParts[1]); | ||
291 | $linkParts2 = split("\@link", $linkParts1[0]); | ||
292 | if (isset($linkParts2[1])) | ||
293 | { | ||
294 | $link = $linkParts2[1]; | ||
295 | } | ||
296 | if (isset($GLOBALS['configuration']['homepage']) && isset($link)) | ||
297 | { | ||
298 | $linkParts = explode('?', $link); | ||
299 | if (isset($linkParts[1])) | ||
300 | { | ||
301 | $link = $GLOBALS['configuration']['homepage'].'/?'.$linkParts[1]; | ||
302 | } | ||
303 | } | ||
304 | } | ||
305 | return $link; | ||
306 | } | ||
307 | |||
308 | /** | ||
309 | * Extracts object name from object file. Do not rely on filename. | ||
310 | * | ||
311 | * @param unknown_type $objectFilePath | ||
312 | */ | ||
313 | function GetObjectName($objectFilePath) | ||
314 | { | ||
315 | $content = file_get_contents($objectFilePath); | ||
316 | $contentParts = split("<b>",$content); | ||
317 | if (isset($contentParts[1])) | ||
318 | { | ||
319 | $contentParts2 = split("</b>",$contentParts[1]); | ||
320 | } | ||
321 | if (isset($contentParts2[0])) | ||
322 | { | ||
323 | $className = trim($contentParts2[0]); | ||
324 | } | ||
325 | return $className; | ||
326 | } | ||
327 | |||
328 | /** | ||
329 | * Gets plugin name based on filename | ||
330 | * | ||
331 | * @param unknown_type $fileName | ||
332 | * @return unknown | ||
333 | */ | ||
334 | function GetPluginName($fileName) | ||
335 | { | ||
336 | $fileNameParts = explode('.', $fileName); | ||
337 | if (strtolower($fileName) != "iplugin.php" && strtolower($fileNameParts[0]) == 'plugin' && strtolower($fileNameParts[2]) == 'php') | ||
338 | { | ||
339 | return $fileNameParts[1]; | ||
340 | } | ||
341 | return ''; | ||
342 | } | ||
343 | |||
344 | /** | ||
345 | * Adds message to error queue | ||
346 | * | ||
347 | * @param unknown_type $error | ||
348 | */ | ||
349 | function AddError($error) | ||
350 | { | ||
351 | if (isset($_SESSION['errorMessages'])) | ||
352 | { | ||
353 | $errorMessages = unserialize($_SESSION['errorMessages']); | ||
354 | if (array_search($error, $errorMessages) === false) | ||
355 | { | ||
356 | $errorMessages[] = $error; | ||
357 | } | ||
358 | } | ||
359 | else | ||
360 | { | ||
361 | $errorMessages = array(); | ||
362 | $errorMessages[] = $error; | ||
363 | } | ||
364 | $_SESSION['errorMessages'] = serialize($errorMessages); | ||
365 | } | ||
366 | |||
367 | /** | ||
368 | * Add message to tracing queue | ||
369 | * | ||
370 | * @param unknown_type $trace | ||
371 | */ | ||
372 | function AddTrace($trace) | ||
373 | { | ||
374 | if (isset($_SESSION['traceMessages'])) | ||
375 | { | ||
376 | $traceMessages = unserialize($_SESSION['traceMessages']); | ||
377 | $traceMessages[] = $trace; | ||
378 | } | ||
379 | else | ||
380 | { | ||
381 | $traceMessages = array(); | ||
382 | $traceMessages[] = $trace; | ||
383 | } | ||
384 | $_SESSION['traceMessages'] = serialize($traceMessages); | ||
385 | } | ||
386 | |||
387 | /** | ||
388 | * Unit tests | ||
389 | */ | ||
390 | |||
391 | /** | ||
392 | * Test the base 5 CRUD methods | ||
393 | * | ||
394 | * @param unknown_type $instance | ||
395 | * @return unknown | ||
396 | */ | ||
397 | function TestEssentials($instance, $optimizeAsWell = true) | ||
398 | { | ||
399 | if(TestIsMapping($instance)) | ||
400 | { | ||
401 | return true; | ||
402 | } | ||
403 | $errors = 0; | ||
404 | if (!TestSave($instance)) | ||
405 | { | ||
406 | $errors++; | ||
407 | } | ||
408 | if (!TestSaveNew($instance)) | ||
409 | { | ||
410 | $errors++; | ||
411 | } | ||
412 | if (!TestDelete($instance)) | ||
413 | { | ||
414 | $errors++; | ||
415 | } | ||
416 | if (!TestGetList($instance)) | ||
417 | { | ||
418 | $errors++; | ||
419 | } | ||
420 | if (!TestDeleteList($instance)) | ||
421 | { | ||
422 | $errors++; | ||
423 | } | ||
424 | if ($optimizeAsWell) | ||
425 | { | ||
426 | if (!TestOptimizeStorage(strtolower(get_class($instance)))) | ||
427 | { | ||
428 | $errors++; | ||
429 | } | ||
430 | } | ||
431 | |||
432 | if ($errors == 0) | ||
433 | { | ||
434 | return true; | ||
435 | } | ||
436 | return false; | ||
437 | } | ||
438 | |||
439 | /** | ||
440 | * Enter description here... | ||
441 | * | ||
442 | * @param unknown_type $instance | ||
443 | * @return unknown | ||
444 | */ | ||
445 | function TestRelationsPreRequisites($instance, $allObjectsList, $thisObjectName, $ignoreObjects) | ||
446 | { | ||
447 | if(TestIsMapping($instance)) | ||
448 | { | ||
449 | AddTrace("\tIs Mapping (OK)"); | ||
450 | return true; | ||
451 | } | ||
452 | if (TestIsSingle($instance)) | ||
453 | { | ||
454 | AddTrace("\tIs single (OK)"); | ||
455 | return true; | ||
456 | } | ||
457 | else | ||
458 | { | ||
459 | if (!TestParentChildLink($instance, $allObjectsList, $thisObjectName, $ignoreObjects) || !TestAssociationLink($instance, $allObjectsList, $thisObjectName, $ignoreObjects)) | ||
460 | { | ||
461 | return false; | ||
462 | } | ||
463 | else | ||
464 | { | ||
465 | AddTrace("\tIs properly connected (OK)"); | ||
466 | return true; | ||
467 | } | ||
468 | } | ||
469 | } | ||
470 | |||
471 | /** | ||
472 | * Test the optional object relations methods | ||
473 | * | ||
474 | * @param unknown_type $instance | ||
475 | * @return unknown | ||
476 | */ | ||
477 | function TestRelations($instance, $ignoreObjects) | ||
478 | { | ||
479 | $errors=0; | ||
480 | if (TestIsParent($instance)) | ||
481 | { | ||
482 | if (!TestAddChild($instance, true, $ignoreObjects)) | ||
483 | { | ||
484 | $errors++; | ||
485 | } | ||
486 | if (!TestGetChildrenList($instance, true, $ignoreObjects)) | ||
487 | { | ||
488 | $errors++; | ||
489 | } | ||
490 | if (!TestDeleteDeep_Child($instance, true, $ignoreObjects)) | ||
491 | { | ||
492 | $errors++; | ||
493 | } | ||
494 | if (!TestSaveDeep_Child($instance, true, $ignoreObjects)) | ||
495 | { | ||
496 | $errors++; | ||
497 | } | ||
498 | if (!TestSetChildrenList($instance, true, $ignoreObjects)) | ||
499 | { | ||
500 | $errors++; | ||
501 | } | ||
502 | } | ||
503 | if (TestIsChild($instance)) | ||
504 | { | ||
505 | if (!TestSetParent($instance, true, $ignoreObjects)) | ||
506 | { | ||
507 | $errors++; | ||
508 | } | ||
509 | if (!TestGetParent($instance, true, $ignoreObjects)) | ||
510 | { | ||
511 | $errors++; | ||
512 | } | ||
513 | } | ||
514 | if (TestIsSibling($instance)) | ||
515 | { | ||
516 | if (!TestAddSibling($instance, true, $ignoreObjects)) | ||
517 | { | ||
518 | $errors++; | ||
519 | } | ||
520 | if (!TestGetSiblingList($instance, true, $ignoreObjects)) | ||
521 | { | ||
522 | $errors++; | ||
523 | } | ||
524 | if (!TestSaveDeep_Sibling($instance, true, $ignoreObjects)) | ||
525 | { | ||
526 | $errors++; | ||
527 | } | ||
528 | if (!TestDeleteDeep_Sibling($instance, true, $ignoreObjects)) | ||
529 | { | ||
530 | $errors++; | ||
531 | } | ||
532 | if (!TestSetSiblingList($instance, true, $ignoreObjects)) | ||
533 | { | ||
534 | $errors++; | ||
535 | } | ||
536 | } | ||
537 | if ($errors == 0) | ||
538 | { | ||
539 | return true; | ||
540 | } | ||
541 | return false; | ||
542 | } | ||
543 | |||
544 | /** | ||
545 | * Tests whether object table already exists | ||
546 | * | ||
547 | */ | ||
548 | function TestStorageExists($objectName, $databaseType = "mysql") | ||
549 | { | ||
550 | switch ($databaseType) | ||
551 | { | ||
552 | case "mysql": | ||
553 | $query = "show tables like '".strtolower($objectName)."'"; | ||
554 | break; | ||
555 | case "sqlite": | ||
556 | $query = "select name FROM sqlite_master WHERE type='table' and name='".strtolower($objectName)."'"; | ||
557 | break; | ||
558 | case "pgsql": | ||
559 | $query = "select table_name FROM information_schema.tables WHERE table_schema = 'public' and table_name='".strtolower($objectName)."'"; | ||
560 | break; | ||
561 | case "odbc": | ||
562 | //assume mssql | ||
563 | $query = "select * from information_schema.tables where table_type = 'BASE TABLE' and table_name='".strtolower($objectName)."'"; | ||
564 | break; | ||
565 | case "firebird": | ||
566 | AddError("POG Setup doesn't support automatic table detection for Firebird databases yet. Therefore, your objects/tables may be misaligned. If POG Essential tests failed, this may very well be the case. Create the tables manually and re-run setup."); | ||
567 | return true; | ||
568 | break; | ||
569 | } | ||
570 | |||
571 | $connection = Database::Connect(); | ||
572 | $rows = Database::Query($query, $connection); | ||
573 | if ($rows > 0) | ||
574 | { | ||
575 | return true; | ||
576 | } | ||
577 | return false; | ||
578 | } | ||
579 | |||
580 | /** | ||
581 | * Creates the table to store objects | ||
582 | * | ||
583 | */ | ||
584 | function TestCreateStorage($objectFilePath, $databaseType = "mysql") | ||
585 | { | ||
586 | if ($databaseType == "firebird") | ||
587 | { | ||
588 | AddError("POG Setup doesn't support automatic table creation for Firebird databases yet. Therefore, your objects/tables may be misaligned. If POG Essential tests failed, this may very well be the case. Create the tables manually and re-run setup."); | ||
589 | return true; | ||
590 | } | ||
591 | |||
592 | $objectName = GetObjectName($objectFilePath); | ||
593 | |||
594 | //extract sql | ||
595 | $content = file_get_contents($objectFilePath); | ||
596 | $contentParts = split("<b>",$content); | ||
597 | if (isset($contentParts[1])) | ||
598 | { | ||
599 | $contentParts2 = split("</b>",$contentParts[1]); | ||
600 | } | ||
601 | if (isset($contentParts2[0])) | ||
602 | { | ||
603 | $className = trim($contentParts2[0]); | ||
604 | } | ||
605 | if (isset($className)) | ||
606 | { | ||
607 | $sqlParts = split(";",$contentParts[0]); | ||
608 | $sqlPart = split("CREATE",$sqlParts[0]); | ||
609 | $sql = "CREATE ".$sqlPart[1].";"; | ||
610 | |||
611 | //execute sql | ||
612 | $connection = Database::Connect(); | ||
613 | if (Database::NonQuery($sql, $connection) !== false) | ||
614 | { | ||
615 | return true; | ||
616 | } | ||
617 | } | ||
618 | AddError("Query failed: $sql"); | ||
619 | return false; | ||
620 | } | ||
621 | |||
622 | /** | ||
623 | * Drops the table for the corresponding object | ||
624 | * | ||
625 | */ | ||
626 | function TestDeleteStorage($object, $databaseType = "mysql") | ||
627 | { | ||
628 | $tableName = strtolower(get_class($object)); | ||
629 | $connection = Database::Connect(); | ||
630 | if (Database::NonQuery('drop table `'.strtolower($tableName).'`', $connection) !== false) | ||
631 | { | ||
632 | return true; | ||
633 | } | ||
634 | return false; | ||
635 | } | ||
636 | |||
637 | /** | ||
638 | * Executes an arbitrary query | ||
639 | * | ||
640 | * @param unknown_type $query | ||
641 | */ | ||
642 | function TestExecuteQuery($query) | ||
643 | { | ||
644 | $connection = Database::Connect(); | ||
645 | if ($query == "") | ||
646 | { | ||
647 | return true; | ||
648 | } | ||
649 | if (Database::NonQuery($query, $connection) !== false) | ||
650 | { | ||
651 | return true; | ||
652 | } | ||
653 | return false; | ||
654 | } | ||
655 | |||
656 | /** | ||
657 | * Enter description here... | ||
658 | * | ||
659 | * @param unknown_type $object | ||
660 | * @return unknown | ||
661 | */ | ||
662 | function TestAlterStorage($object, $databaseType = "mysql") | ||
663 | { | ||
664 | if ($databaseType != "mysql") | ||
665 | { | ||
666 | AddTrace("POG Setup doesn't support table automatic alteration for non-MySQL databases yet. Therefore, your objects/tables may be misaligned. If POG Essential tests failed, this may very well be the case. Drop and recreate the tables and re-run setup."); | ||
667 | return true; | ||
668 | } | ||
669 | |||
670 | //find object attributes/table columns mismatch | ||
671 | $tableName = strtolower(get_class($object)); | ||
672 | $columns = array(); | ||
673 | |||
674 | $query = "describe `$tableName` "; | ||
675 | $connection = Database::Connect(); | ||
676 | $cursor = Database::Reader($query, $connection); | ||
677 | if ($cursor !== false) | ||
678 | { | ||
679 | while ($row = Database::Read($cursor)) | ||
680 | { | ||
681 | $columns[$row["Field"]] = $row["Type"]; | ||
682 | } | ||
683 | |||
684 | $attribute_types = $object -> pog_attribute_type; | ||
685 | $lowerAttributes = array(); | ||
686 | foreach (array_keys($attribute_types) as $key) | ||
687 | { | ||
688 | $lowerAttributes[strtolower($key)] = $attribute_types[$key]; | ||
689 | } | ||
690 | |||
691 | //columns to remove | ||
692 | $columnsToRemove = array_diff(array_keys($columns), array_keys($lowerAttributes)); | ||
693 | |||
694 | //columns to add | ||
695 | $columnsToAdd = array_diff(array_keys($lowerAttributes), array_keys($columns)); | ||
696 | |||
697 | //columns whose type has changed | ||
698 | $otherColumns = array_intersect(array_keys($lowerAttributes), array_keys($columns)); | ||
699 | |||
700 | $columnsToModify = array(); | ||
701 | foreach ($otherColumns as $otherColumn) | ||
702 | { | ||
703 | $type = strtolower($lowerAttributes[$otherColumn]['db_attributes'][1]); | ||
704 | if ($type == 'enum' || $type == 'set') | ||
705 | { | ||
706 | $enumPartsObj = explode(',', strtolower($lowerAttributes[$otherColumn]['db_attributes'][2])); | ||
707 | $parts = explode('(',$columns[$otherColumn]); | ||
708 | $parts2 = explode(')',$parts[1]); | ||
709 | $enumpartsDb = explode(',', strtolower(trim($parts2[0]))); | ||
710 | foreach ($enumPartsObj as $ep) | ||
711 | { | ||
712 | if (array_search(trim($ep), $enumpartsDb) === false) | ||
713 | { | ||
714 | $type .= "(".$lowerAttributes[$otherColumn]['db_attributes'][2].")"; | ||
715 | $columnsToModify[$otherColumn] = $type; | ||
716 | break; | ||
717 | } | ||
718 | } | ||
719 | } | ||
720 | else | ||
721 | { | ||
722 | if (isset($lowerAttributes[$otherColumn]['db_attributes'][2])) | ||
723 | { | ||
724 | $type .= "(".$lowerAttributes[$otherColumn]['db_attributes'][2].")"; | ||
725 | } | ||
726 | if (strpos(strtolower($columns[$otherColumn]), $type) === false && $type != "hasmany" && $type != "join") | ||
727 | { | ||
728 | if ($type == "belongsto") | ||
729 | { | ||
730 | $columnsToModify[strtolower($otherColumn)] = "int"; | ||
731 | } | ||
732 | else | ||
733 | { | ||
734 | $columnsToModify[$otherColumn] = $type; | ||
735 | } | ||
736 | } | ||
737 | } | ||
738 | } | ||
739 | |||
740 | $columnsToRemove2 = array(); | ||
741 | foreach ($columnsToRemove as $c) | ||
742 | { | ||
743 | $columnsToRemove2[] = strtolower($c); | ||
744 | } | ||
745 | |||
746 | $columnsToRemove = $columnsToRemove2; | ||
747 | |||
748 | $columnsToAdd2 = array(); | ||
749 | foreach ($columnsToAdd as $c) | ||
750 | { | ||
751 | if ($lowerAttributes[$c]['db_attributes'][1] != "HASMANY" && $lowerAttributes[$c]['db_attributes'][1] != "JOIN") | ||
752 | { | ||
753 | if ($lowerAttributes[$c]['db_attributes'][1] == "BELONGSTO") | ||
754 | { | ||
755 | $colMarkedForDeletion = array_search(strtolower($c)."id", $columnsToRemove); | ||
756 | if ($colMarkedForDeletion === false) //this is clumsy, until we think of something better | ||
757 | { | ||
758 | $columnsToAdd2[] = strtolower($c)."id int"; | ||
759 | } | ||
760 | else | ||
761 | { | ||
762 | //remove entry from columnsToRemove since they are the same. Will lose data if dropped & recreated | ||
763 | array_splice($columnsToRemove, $colMarkedForDeletion, 1); | ||
764 | } | ||
765 | } | ||
766 | else | ||
767 | { | ||
768 | $columnsToAdd2[] = $c; | ||
769 | } | ||
770 | } | ||
771 | } | ||
772 | |||
773 | $common = array(); | ||
774 | $common = array_intersect($columnsToAdd2, $columnsToRemove); | ||
775 | |||
776 | $columnsToAdd = array(); | ||
777 | foreach ($columnsToAdd2 as $col) | ||
778 | { | ||
779 | if (array_search($col, $common) === false) | ||
780 | { | ||
781 | $columnsToAdd[] = $col; | ||
782 | } | ||
783 | } | ||
784 | $columnsToRemove2 = array(); | ||
785 | foreach ($columnsToRemove as $col) | ||
786 | { | ||
787 | if (array_search($col, $common) === false) | ||
788 | { | ||
789 | $columnsToRemove2[] = $col; | ||
790 | } | ||
791 | } | ||
792 | |||
793 | |||
794 | if (sizeof($columnsToAdd) == 0 && sizeof($columnsToRemove2) == 0 && sizeof($columnsToModify) == 0) | ||
795 | { | ||
796 | return true; | ||
797 | } | ||
798 | |||
799 | //construct query | ||
800 | $query = "alter table `$tableName` "; | ||
801 | |||
802 | foreach ($columnsToRemove2 as $remove) | ||
803 | { | ||
804 | $query .= "drop column `$remove`,"; | ||
805 | } | ||
806 | |||
807 | foreach ($columnsToAdd as $add) | ||
808 | { | ||
809 | $columnType = ''; | ||
810 | if (isset($lowerAttributes[$add])) | ||
811 | { | ||
812 | $columnType = strtolower($lowerAttributes[$add]['db_attributes'][1]); | ||
813 | } | ||
814 | if (isset($lowerAttributes[$add]['db_attributes'][2])) | ||
815 | { | ||
816 | $columnType .= "(".$lowerAttributes[$add]['db_attributes'][2].")"; | ||
817 | } | ||
818 | if ($columnType != '') | ||
819 | { | ||
820 | $query .= "add column `$add` $columnType,"; | ||
821 | } | ||
822 | else | ||
823 | { | ||
824 | $query .= "add column $add,"; | ||
825 | } | ||
826 | } | ||
827 | |||
828 | |||
829 | foreach (array_keys($columnsToModify) as $modify) | ||
830 | { | ||
831 | $query .= "modify `$modify` ".$columnsToModify[$modify].","; | ||
832 | } | ||
833 | $query = trim($query, ','); | ||
834 | //execute query | ||
835 | |||
836 | if (Database::NonQuery($query, $connection) !== false) | ||
837 | { | ||
838 | return true; | ||
839 | } | ||
840 | } | ||
841 | AddError("Query failed: $query"); | ||
842 | return false; | ||
843 | } | ||
844 | |||
845 | /** | ||
846 | * Optimizes the table by running mysql optimize | ||
847 | * | ||
848 | * @param unknown_type $objectName | ||
849 | * @return unknown | ||
850 | */ | ||
851 | function TestOptimizeStorage($objectName) | ||
852 | { | ||
853 | $connection = Database::Connect(); | ||
854 | if (Database::NonQuery("optimize table `".strtolower($objectName)."`", $connection) !== false) | ||
855 | { | ||
856 | AddTrace("\tOptimizing....OK!"); | ||
857 | return true; | ||
858 | } | ||
859 | return false; | ||
860 | } | ||
861 | |||
862 | /** | ||
863 | * Unit test for Save() | ||
864 | * | ||
865 | */ | ||
866 | function TestSave($object, $trace=true) | ||
867 | { | ||
868 | $className = get_class($object); | ||
869 | $object = PopulateTestValues($object); | ||
870 | $objectId = false; | ||
871 | $object->{strtolower($className)."Id"} = ""; | ||
872 | $objectId = $object->Save(false); | ||
873 | |||
874 | if(!$objectId) | ||
875 | { | ||
876 | if ($trace) | ||
877 | { | ||
878 | AddTrace("\tSave() failed"); | ||
879 | AddError("Query failed: ".$object->pog_query); | ||
880 | } | ||
881 | return false; | ||
882 | } | ||
883 | //cleanup test data | ||
884 | $query = "delete from `".strtolower($className)."` where ".strtolower($className)."id = '".$objectId."';"; | ||
885 | $connection = Database::Connect(); | ||
886 | Database::NonQuery($query, $connection); | ||
887 | if ($trace) | ||
888 | { | ||
889 | AddTrace("\tSave()....OK!"); | ||
890 | } | ||
891 | return true; | ||
892 | } | ||
893 | |||
894 | /** | ||
895 | * Unit test for SaveNew() | ||
896 | * | ||
897 | */ | ||
898 | function TestSaveNew($object, $trace = true) | ||
899 | { | ||
900 | $className = get_class($object); | ||
901 | if(!TestSave($object, false)) | ||
902 | { | ||
903 | if ($trace) | ||
904 | { | ||
905 | AddTrace("\tSaveNew() ignored"); | ||
906 | } | ||
907 | return false; | ||
908 | } | ||
909 | $objectId = $object->SaveNew(false); | ||
910 | if ($objectId) | ||
911 | { | ||
912 | $query = "delete from `".strtolower($className)."` where ".strtolower($className)."Id = '".$objectId."';"; | ||
913 | $connection = Database::Connect(); | ||
914 | Database::NonQuery($query, $connection); | ||
915 | if ($trace) | ||
916 | { | ||
917 | AddTrace("\tSaveNew()....OK!"); | ||
918 | } | ||
919 | return true; | ||
920 | } | ||
921 | if ($trace) | ||
922 | { | ||
923 | AddTrace("\tSaveNew() failed"); | ||
924 | AddError("Query failed: ".$object->pog_query); | ||
925 | } | ||
926 | return false; | ||
927 | } | ||
928 | |||
929 | /** | ||
930 | * Unit test for GetList(). Implicitly tests Get() | ||
931 | * | ||
932 | */ | ||
933 | function TestGetList($object, $trace = true) | ||
934 | { | ||
935 | if ($trace) | ||
936 | { | ||
937 | AddTrace("\tGetList()"); | ||
938 | } | ||
939 | $errors = 0; | ||
940 | if (TestSave($object,false) && TestSaveNew($object, false) && TestDelete($object, false)) | ||
941 | { | ||
942 | $className = get_class($object); | ||
943 | $objectList = $object->GetList(array(array(strtolower($className)."Id", ">", 0))); | ||
944 | $oldCount = count($objectList); | ||
945 | $object = PopulateTestValues($object); | ||
946 | $objectId = false; | ||
947 | $object->{strtolower($className)."Id"} = 0; | ||
948 | $objectId = $object->Save(false); | ||
949 | $objectId2 = $object->SaveNew(false); | ||
950 | $objectId3 = $object->SaveNew(false); | ||
951 | |||
952 | |||
953 | //Test Multiple Conditions | ||
954 | $objectList = $object->GetList(array(array(strtolower($className)."Id", ">=",$objectId), array(strtolower($className)."Id", "<=", $objectId+2)), strtolower($className)."Id", false, 2); | ||
955 | if (sizeof($objectList) != 2) | ||
956 | { | ||
957 | //Test Limit | ||
958 | if ($trace) | ||
959 | { | ||
960 | AddTrace("\t\tLimit failed"); | ||
961 | AddError('ERROR: GetList() :sizeof(list) != \$limit\n'); | ||
962 | AddError("Query failed: ".$object->pog_query); | ||
963 | } | ||
964 | $errors++; | ||
965 | } | ||
966 | else | ||
967 | { | ||
968 | if ($trace) | ||
969 | { | ||
970 | AddTrace("\t\tLimit....OK!"); | ||
971 | } | ||
972 | } | ||
973 | if ($objectList[1]->{strtolower($className)."Id"} > $objectList[0]->{strtolower($className)."Id"}) | ||
974 | { | ||
975 | //Test Sorting | ||
976 | if ($trace) | ||
977 | { | ||
978 | AddTrace("\t\tSorting failed"); | ||
979 | AddError("ERROR: GetList() :list is not properly sorted"); | ||
980 | AddError("Query failed: ".$object->pog_query); | ||
981 | } | ||
982 | $errors++; | ||
983 | } | ||
984 | else | ||
985 | { | ||
986 | if ($trace) | ||
987 | { | ||
988 | AddTrace("\t\tSorting....OK!"); | ||
989 | } | ||
990 | } | ||
991 | if ($errors == 0) | ||
992 | { | ||
993 | $objectList = $object->GetList(array(array(strtolower($className)."Id", ">=",$objectId), array(strtolower($className)."Id", "<=", $objectId+2)), strtolower($className)."Id", false, 3); | ||
994 | foreach ($objectList as $object) | ||
995 | { | ||
996 | $attributeList = array_keys(get_object_vars($object)); | ||
997 | foreach ($attributeList as $attribute) | ||
998 | { | ||
999 | if (isset($object->pog_attribute_type[$attribute])) | ||
1000 | { | ||
1001 | if (isset($type_value[$attribute])) | ||
1002 | { | ||
1003 | if ($object->{$attribute} != $type_value[$attribute]) | ||
1004 | { | ||
1005 | if($trace) | ||
1006 | { | ||
1007 | AddError("WARNING: Failed to retrieve attribute `$attribute`. Expecting `".$type_value[$attribute]."`; found `".$object->{$attribute}."`. Check that column `$attribute` in the `$className` table is of type `".$object->pog_attribute_type[$attribute]['db_attributes'][1]."`"); | ||
1008 | } | ||
1009 | } | ||
1010 | } | ||
1011 | } | ||
1012 | } | ||
1013 | $object->Delete(); | ||
1014 | } | ||
1015 | return true; | ||
1016 | } | ||
1017 | else | ||
1018 | { | ||
1019 | if ($trace) | ||
1020 | { | ||
1021 | AddTrace("\tGetList() failed"); | ||
1022 | AddError("Query failed: ".$object->pog_query); | ||
1023 | } | ||
1024 | return false; | ||
1025 | } | ||
1026 | } | ||
1027 | if ($trace) | ||
1028 | { | ||
1029 | AddTrace("\tGetList() ignored"); | ||
1030 | } | ||
1031 | return false; | ||
1032 | } | ||
1033 | |||
1034 | /** | ||
1035 | * Unit test for Delete() | ||
1036 | * | ||
1037 | */ | ||
1038 | function TestDelete($object, $trace = true) | ||
1039 | { | ||
1040 | if(!TestSave($object, false)) | ||
1041 | { | ||
1042 | if ($trace) | ||
1043 | { | ||
1044 | AddTrace("\tDelete() ignored"); | ||
1045 | } | ||
1046 | return false; | ||
1047 | } | ||
1048 | $object = PopulateTestValues($object); | ||
1049 | $object->Save(false); | ||
1050 | if ($object->Delete(false)) | ||
1051 | { | ||
1052 | if ($trace) | ||
1053 | { | ||
1054 | AddTrace("\tDelete()....OK!"); | ||
1055 | } | ||
1056 | return true; | ||
1057 | } | ||
1058 | if ($trace) | ||
1059 | { | ||
1060 | AddTrace("\tDelete() failed"); | ||
1061 | AddError("Query failed: ".$object->pog_query); | ||
1062 | } | ||
1063 | return false; | ||
1064 | } | ||
1065 | |||
1066 | /** | ||
1067 | * Unit Test for DeleteList() | ||
1068 | * | ||
1069 | * @param unknown_type $object | ||
1070 | * @param unknown_type $trace | ||
1071 | */ | ||
1072 | function TestDeleteList($object, $trace = true) | ||
1073 | { | ||
1074 | $className = get_class($object); | ||
1075 | if(!TestSave($object, false) || !TestGetList($object, false)) | ||
1076 | { | ||
1077 | if ($trace) | ||
1078 | { | ||
1079 | AddTrace("\tDeleteList() ignored"); | ||
1080 | } | ||
1081 | return false; | ||
1082 | } | ||
1083 | |||
1084 | $object = PopulateTestValues($object); | ||
1085 | |||
1086 | $originalCount = GetNumberOfRecords($className); | ||
1087 | |||
1088 | $objectId = false; | ||
1089 | $object->{strtolower($className)."Id"} = 0; | ||
1090 | $objectId = $object->Save(false); | ||
1091 | $objectId2 = $object->SaveNew(false); | ||
1092 | $objectId3 = $object->SaveNew(false); | ||
1093 | |||
1094 | $className = get_class($object); | ||
1095 | $object->DeleteList(array(array(strtolower($className)."Id", "=", $objectId), array("or"), array(strtolower($className)."Id", "=", $objectId2), array("or"), array(strtolower($className)."Id", "=", $objectId3))); | ||
1096 | |||
1097 | $newCount = GetNumberOfRecords($className); | ||
1098 | |||
1099 | if ($newCount == $originalCount) | ||
1100 | { | ||
1101 | if ($trace) | ||
1102 | { | ||
1103 | AddTrace("\tDeleteList()....OK!"); | ||
1104 | } | ||
1105 | return true; | ||
1106 | } | ||
1107 | |||
1108 | if ($trace) | ||
1109 | { | ||
1110 | AddTrace("\tDeleteList() failed"); | ||
1111 | AddError("Query failed: ".$object->pog_query); | ||
1112 | } | ||
1113 | return false; | ||
1114 | } | ||
1115 | |||
1116 | /** | ||
1117 | * Tests whether the object is connected at all | ||
1118 | * | ||
1119 | * @param unknown_type $object | ||
1120 | * @param unknown_type $allObjectsList | ||
1121 | */ | ||
1122 | function TestIsSingle($object) | ||
1123 | { | ||
1124 | $attribute_types = $object->pog_attribute_type; | ||
1125 | |||
1126 | //get all child classes | ||
1127 | $childrenList = array(); | ||
1128 | foreach ($attribute_types as $key => $attribute_array) | ||
1129 | { | ||
1130 | if ($attribute_array['db_attributes'][1] == "HASMANY") | ||
1131 | { | ||
1132 | $childrenList[] = $key; | ||
1133 | } | ||
1134 | } | ||
1135 | |||
1136 | //get all parent classes | ||
1137 | $parentsList = array(); | ||
1138 | foreach ($attribute_types as $key => $attribute_array) | ||
1139 | { | ||
1140 | if ($attribute_array['db_attributes'][1] == "BELONGSTO") | ||
1141 | { | ||
1142 | $parentsList[] = $key; | ||
1143 | } | ||
1144 | } | ||
1145 | |||
1146 | //get all associations | ||
1147 | $associationsList = array(); | ||
1148 | foreach ($attribute_types as $key => $attribute_array) | ||
1149 | { | ||
1150 | if ($attribute_array['db_attributes'][1] == "JOIN") | ||
1151 | { | ||
1152 | $associationsList[] = $key; | ||
1153 | } | ||
1154 | } | ||
1155 | |||
1156 | if (sizeof($childrenList) == 0 && sizeof($parentsList) == 0 && sizeof($associationsList) == 0) | ||
1157 | { | ||
1158 | return true; | ||
1159 | } | ||
1160 | return false; | ||
1161 | } | ||
1162 | |||
1163 | /** | ||
1164 | * Tests that all parents have children and vice-versa | ||
1165 | * | ||
1166 | * @param unknown_type $object | ||
1167 | * @param unknown_type $allObjectsList | ||
1168 | * @param unknown_type $thisObjectName | ||
1169 | * @return unknown | ||
1170 | */ | ||
1171 | function TestParentChildLink($object, $allObjectsList, $thisObjectName = '', $ignoreObjects) | ||
1172 | { | ||
1173 | $attribute_types = $object->pog_attribute_type; | ||
1174 | |||
1175 | //get all child classes | ||
1176 | $childrenList = array(); | ||
1177 | foreach ($attribute_types as $key => $attribute_array) | ||
1178 | { | ||
1179 | if ($attribute_array['db_attributes'][1] == "HASMANY") | ||
1180 | { | ||
1181 | $childrenList[] = $key; | ||
1182 | } | ||
1183 | } | ||
1184 | |||
1185 | //get all parent classes | ||
1186 | $parentsList = array(); | ||
1187 | foreach ($attribute_types as $key => $attribute_array) | ||
1188 | { | ||
1189 | if ($attribute_array['db_attributes'][1] == "BELONGSTO") | ||
1190 | { | ||
1191 | $parentsList[] = $key; | ||
1192 | } | ||
1193 | } | ||
1194 | |||
1195 | $errors = 0; | ||
1196 | foreach ($childrenList as $child) | ||
1197 | { | ||
1198 | if (array_search($child, $allObjectsList) === false) | ||
1199 | { | ||
1200 | $errors++; | ||
1201 | AddError("$thisObjectName refers to $child as {Child}, which couldn't be found. Generate the $child object with reference to $thisObjectName as {Parent}"); | ||
1202 | } | ||
1203 | else | ||
1204 | { | ||
1205 | //test that child refers to this object as parent | ||
1206 | eval ("\$childInstance = new $child();"); | ||
1207 | $childAttributes = array_keys($childInstance->pog_attribute_type); | ||
1208 | if (array_search($thisObjectName, $childAttributes) === false) | ||
1209 | { | ||
1210 | $errors++; | ||
1211 | AddError("$thisObjectName refers to $child as {Child}, but $child does not refer to $thisObjectName as {Parent}. Relations need to be reciprocal."); | ||
1212 | } | ||
1213 | } | ||
1214 | } | ||
1215 | |||
1216 | foreach ($parentsList as $parent) | ||
1217 | { | ||
1218 | if (array_search($parent, $allObjectsList) === false) | ||
1219 | { | ||
1220 | $errors++; | ||
1221 | AddError("$thisObjectName refers to $parent as parent, which couldn't be found. Generate the $parent object with reference to $thisObjectName as {Child}"); | ||
1222 | } | ||
1223 | else | ||
1224 | { | ||
1225 | //test that parent refers to this object as child | ||
1226 | eval ("\$parentInstance = new $parent();"); | ||
1227 | $parentAttributes = array_keys($parentInstance->pog_attribute_type); | ||
1228 | if (array_search($thisObjectName, $parentAttributes) === false) | ||
1229 | { | ||
1230 | $errors++; | ||
1231 | AddError("$thisObjectName refers to $parent as {Parent}, but $parent does not refer to $thisObjectName as {Child}. Relations need to be reciprocal."); | ||
1232 | } | ||
1233 | } | ||
1234 | } | ||
1235 | |||
1236 | if ($errors == 0) | ||
1237 | { | ||
1238 | return true; | ||
1239 | } | ||
1240 | return false; | ||
1241 | } | ||
1242 | |||
1243 | /** | ||
1244 | * Tests that all Joins have reciprocal links | ||
1245 | * | ||
1246 | * @param unknown_type $object | ||
1247 | * @param unknown_type $allObjectsList | ||
1248 | * @param unknown_type $thisObjectName | ||
1249 | */ | ||
1250 | function TestAssociationLink($object, $allObjectsList, $thisObjectName = '', $ignoreObjects) | ||
1251 | { | ||
1252 | $attribute_types = $object->pog_attribute_type; | ||
1253 | |||
1254 | //get all join classes | ||
1255 | $associationsList = array(); | ||
1256 | foreach ($attribute_types as $key => $attribute_array) | ||
1257 | { | ||
1258 | if ($attribute_array['db_attributes'][1] == "JOIN") | ||
1259 | { | ||
1260 | $associationsList[] = $key; | ||
1261 | } | ||
1262 | } | ||
1263 | |||
1264 | $errors = 0; | ||
1265 | foreach ($associationsList as $association) | ||
1266 | { | ||
1267 | if (array_search($association, $allObjectsList) === false) | ||
1268 | { | ||
1269 | $errors++; | ||
1270 | AddError("$thisObjectName refers to $association as {SIBLING}, which couldn't be found. Generate the $association object with reference to $thisObjectName as {SIBLING}"); | ||
1271 | } | ||
1272 | else | ||
1273 | { | ||
1274 | //test that association refers to this object as map | ||
1275 | eval ("\$associationInstance = new $association();"); | ||
1276 | $associationAttributes = array_keys($associationInstance->pog_attribute_type); | ||
1277 | if (array_search($thisObjectName, $associationAttributes) === false) | ||
1278 | { | ||
1279 | $errors++; | ||
1280 | AddError("$thisObjectName refers to $association as {SIBLING}, but $association does not refer to $thisObjectName as {SIBLING}. Relations need to be reciprocal."); | ||
1281 | } | ||
1282 | } | ||
1283 | } | ||
1284 | |||
1285 | if ($errors == 0) | ||
1286 | { | ||
1287 | return true; | ||
1288 | } | ||
1289 | return false; | ||
1290 | } | ||
1291 | |||
1292 | /** | ||
1293 | * Unit test to see if object is a parent | ||
1294 | * | ||
1295 | * @param unknown_type $object | ||
1296 | */ | ||
1297 | function TestIsParent($object) | ||
1298 | { | ||
1299 | $attribute_types = $object->pog_attribute_type; | ||
1300 | foreach ($attribute_types as $attribute_array) | ||
1301 | { | ||
1302 | if ($attribute_array['db_attributes'][1] == "HASMANY") | ||
1303 | { | ||
1304 | return true; | ||
1305 | } | ||
1306 | } | ||
1307 | return false; | ||
1308 | } | ||
1309 | |||
1310 | /** | ||
1311 | * Unit test to see if object is child | ||
1312 | * | ||
1313 | * @param unknown_type $object | ||
1314 | */ | ||
1315 | function TestIsChild($object) | ||
1316 | { | ||
1317 | $attribute_types = $object->pog_attribute_type; | ||
1318 | foreach ($attribute_types as $attribute_array) | ||
1319 | { | ||
1320 | if ($attribute_array['db_attributes'][1] == "BELONGSTO") | ||
1321 | { | ||
1322 | return true; | ||
1323 | } | ||
1324 | } | ||
1325 | return false; | ||
1326 | } | ||
1327 | |||
1328 | /** | ||
1329 | * Unit test to see if object is Sibling | ||
1330 | * | ||
1331 | * @param unknown_type $object | ||
1332 | * @return unknown | ||
1333 | */ | ||
1334 | function TestIsSibling($object) | ||
1335 | { | ||
1336 | $attribute_types = $object->pog_attribute_type; | ||
1337 | foreach ($attribute_types as $attribute_array) | ||
1338 | { | ||
1339 | if ($attribute_array['db_attributes'][1] == "JOIN") | ||
1340 | { | ||
1341 | return true; | ||
1342 | } | ||
1343 | } | ||
1344 | return false; | ||
1345 | } | ||
1346 | |||
1347 | /** | ||
1348 | * Unit test to see if object is a Mapping object | ||
1349 | * | ||
1350 | * @param unknown_type $object | ||
1351 | */ | ||
1352 | function TestIsMapping($object) | ||
1353 | { | ||
1354 | $funcs = get_class_methods(get_class($object)); | ||
1355 | foreach ($funcs as $func) | ||
1356 | { | ||
1357 | if (strtolower($func) == "addmapping") | ||
1358 | { | ||
1359 | return true; | ||
1360 | } | ||
1361 | } | ||
1362 | return false; | ||
1363 | } | ||
1364 | |||
1365 | /** | ||
1366 | * Unit test for Save($deep) | ||
1367 | * | ||
1368 | * @param unknown_type $object | ||
1369 | */ | ||
1370 | function TestSaveDeep_Child($object, $trace = true, $ignoreObjects) | ||
1371 | { | ||
1372 | $thisObjectName = get_class($object); | ||
1373 | if (!TestAddChild($object, false, $ignoreObjects)) | ||
1374 | { | ||
1375 | if ($trace) | ||
1376 | { | ||
1377 | AddTrace("\tSave(deep) ignored"); | ||
1378 | AddError("Save(deep) ignored since AddChild could not be performed"); | ||
1379 | } | ||
1380 | return false; | ||
1381 | } | ||
1382 | if (!TestGetChildrenList($object, false, $ignoreObjects)) | ||
1383 | { | ||
1384 | if ($trace) | ||
1385 | { | ||
1386 | AddTrace("\tSave(deep) ignored"); | ||
1387 | AddError("Save(deep) ignored since GetChildrenList could not be performed"); | ||
1388 | } | ||
1389 | return false; | ||
1390 | } | ||
1391 | if (!TestDeleteDeep_Child($object, false, $ignoreObjects)) | ||
1392 | { | ||
1393 | if ($trace) | ||
1394 | { | ||
1395 | AddTrace("\tSave(deep) ignored"); | ||
1396 | AddError("Save(deep) ignored since Delete(deep) could not be performed"); | ||
1397 | } | ||
1398 | return false; | ||
1399 | } | ||
1400 | |||
1401 | //get all child classes | ||
1402 | $childrenList = array(); | ||
1403 | eval("\$object = new $thisObjectName();"); | ||
1404 | $object = PopulateTestValues($object); | ||
1405 | $attribute_types = $object->pog_attribute_type; | ||
1406 | |||
1407 | foreach ($attribute_types as $key => $attribute_array) | ||
1408 | { | ||
1409 | if ($attribute_array['db_attributes'][1] == "HASMANY") | ||
1410 | { | ||
1411 | $childrenList[] = $key; | ||
1412 | } | ||
1413 | } | ||
1414 | |||
1415 | $errors = 0; | ||
1416 | foreach ($childrenList as $child) | ||
1417 | { | ||
1418 | //instantiate | ||
1419 | eval("\$childInstance = new $child();"); | ||
1420 | $childInstance = PopulateTestValues($childInstance); | ||
1421 | |||
1422 | //add children | ||
1423 | eval ("\$object -> Add$child(\$childInstance);"); | ||
1424 | } | ||
1425 | |||
1426 | //test | ||
1427 | if (!$object->Save(true)) | ||
1428 | { | ||
1429 | $errors++; | ||
1430 | return false; | ||
1431 | } | ||
1432 | |||
1433 | foreach ($childrenList as $child) | ||
1434 | { | ||
1435 | //instantiate | ||
1436 | eval("\$childArray = \$object->Get".$child."List();"); | ||
1437 | if (sizeof($childArray) == 0) | ||
1438 | { | ||
1439 | if ($trace) | ||
1440 | { | ||
1441 | AddTrace("\tSave($child) failed"); | ||
1442 | |||
1443 | } | ||
1444 | $errors++; | ||
1445 | } | ||
1446 | else | ||
1447 | { | ||
1448 | if ($trace) | ||
1449 | { | ||
1450 | AddTrace("\tSave($child)....OK!"); | ||
1451 | } | ||
1452 | } | ||
1453 | } | ||
1454 | |||
1455 | //cleanup | ||
1456 | $object->Delete(true); | ||
1457 | |||
1458 | if ($errors == 0) | ||
1459 | { | ||
1460 | return true; | ||
1461 | } | ||
1462 | return false; | ||
1463 | } | ||
1464 | |||
1465 | /** | ||
1466 | * Unit test for Save($deep) | ||
1467 | * | ||
1468 | * @param unknown_type $object | ||
1469 | * @return unknown | ||
1470 | */ | ||
1471 | function TestSaveDeep_Sibling($object, $trace = true, $ignoreObjects) | ||
1472 | { | ||
1473 | $thisObjectName = get_class($object); | ||
1474 | if (!TestAddSibling($object, false, $ignoreObjects)) | ||
1475 | { | ||
1476 | if ($trace) | ||
1477 | { | ||
1478 | AddTrace("\tSave(deep) ignored"); | ||
1479 | AddError("Save(deep) ignored since AddSibling could not be performed"); | ||
1480 | } | ||
1481 | return false; | ||
1482 | } | ||
1483 | if (!TestGetSiblingList($object, false, $ignoreObjects)) | ||
1484 | { | ||
1485 | if ($trace) | ||
1486 | { | ||
1487 | AddTrace("\tSave(deep) ignored"); | ||
1488 | AddError("Save(deep) ignored since GetSiblingList could not be performed"); | ||
1489 | } | ||
1490 | return false; | ||
1491 | } | ||
1492 | |||
1493 | //get all sibling classes | ||
1494 | $siblingList = array(); | ||
1495 | eval("\$object = new $thisObjectName();"); | ||
1496 | $object = PopulateTestValues($object); | ||
1497 | $attribute_types = $object->pog_attribute_type; | ||
1498 | |||
1499 | foreach ($attribute_types as $key => $attribute_array) | ||
1500 | { | ||
1501 | if ($attribute_array['db_attributes'][1] == "JOIN") | ||
1502 | { | ||
1503 | $siblingList[] = $key; | ||
1504 | } | ||
1505 | } | ||
1506 | |||
1507 | $errors = 0; | ||
1508 | |||
1509 | $siblingStore = array(); | ||
1510 | |||
1511 | foreach ($siblingList as $sibling) | ||
1512 | { | ||
1513 | //instantiate | ||
1514 | eval("\$siblingInstance = new $sibling();"); | ||
1515 | $siblingStore[] = $siblingInstance; | ||
1516 | $siblingInstance = PopulateTestValues($siblingInstance); | ||
1517 | |||
1518 | //add children | ||
1519 | eval ("\$object -> Add$sibling(\$siblingInstance);"); | ||
1520 | } | ||
1521 | |||
1522 | //test | ||
1523 | if (!$object->Save(true)) | ||
1524 | { | ||
1525 | $errors++; | ||
1526 | return false; | ||
1527 | } | ||
1528 | |||
1529 | foreach ($siblingList as $sibling) | ||
1530 | { | ||
1531 | //instantiate | ||
1532 | eval("\$siblingArray = \$object->Get".$sibling."List();"); | ||
1533 | if (sizeof($siblingArray) == 0) | ||
1534 | { | ||
1535 | if ($trace) | ||
1536 | { | ||
1537 | AddTrace("\tSave($sibling) failed"); | ||
1538 | } | ||
1539 | $errors++; | ||
1540 | } | ||
1541 | else | ||
1542 | { | ||
1543 | if ($trace) | ||
1544 | { | ||
1545 | AddTrace("\tSave($sibling)....OK!"); | ||
1546 | } | ||
1547 | } | ||
1548 | } | ||
1549 | |||
1550 | //cleanup | ||
1551 | $object->Delete(); | ||
1552 | foreach($siblingStore as $stored) | ||
1553 | { | ||
1554 | $stored->Delete(); | ||
1555 | } | ||
1556 | |||
1557 | if ($errors == 0) | ||
1558 | { | ||
1559 | return true; | ||
1560 | } | ||
1561 | return false; | ||
1562 | } | ||
1563 | |||
1564 | /** | ||
1565 | * Unit test for Delete($deep) | ||
1566 | * | ||
1567 | * @param unknown_type $object | ||
1568 | */ | ||
1569 | function TestDeleteDeep_Child($object, $trace = true, $ignoreObjects) | ||
1570 | { | ||
1571 | $thisObjectName = get_class($object); | ||
1572 | $attribute_types = $object->pog_attribute_type; | ||
1573 | |||
1574 | if (!TestSetParent($object, false, $ignoreObjects)) | ||
1575 | { | ||
1576 | AddTrace("\tDelete(deep) ignored"); | ||
1577 | return false; | ||
1578 | } | ||
1579 | //get all child classes | ||
1580 | $childrenList = array(); | ||
1581 | foreach ($attribute_types as $key => $attribute_array) | ||
1582 | { | ||
1583 | if ($attribute_array['db_attributes'][1] == "HASMANY") | ||
1584 | { | ||
1585 | $childrenList[] = $key; | ||
1586 | } | ||
1587 | } | ||
1588 | |||
1589 | $errors = 0; | ||
1590 | |||
1591 | $object = PopulateTestValues($object); | ||
1592 | $objectId = $object->Save(false); | ||
1593 | |||
1594 | |||
1595 | $childrenStore = array(); | ||
1596 | foreach ($childrenList as $child) | ||
1597 | { | ||
1598 | //instantiate | ||
1599 | eval("\$childInstance = new $child();"); | ||
1600 | $childInstance = PopulateTestValues($childInstance); | ||
1601 | eval("\$childInstance -> Set".$thisObjectName."(\$object);"); | ||
1602 | $childInstance -> Save(); | ||
1603 | $childrenStore[] = &$childInstance; | ||
1604 | } | ||
1605 | |||
1606 | //test | ||
1607 | if (!$object->Delete(true)) | ||
1608 | { | ||
1609 | $errors++; | ||
1610 | } | ||
1611 | |||
1612 | foreach ($childrenList as $child) | ||
1613 | { | ||
1614 | eval("\$childInstance = new $child();"); | ||
1615 | $parentList = $childInstance->GetList(array(array(strtolower($thisObjectName)."Id", "=", $objectId))); | ||
1616 | if (sizeof($parentList) > 0) | ||
1617 | { | ||
1618 | if ($trace) | ||
1619 | { | ||
1620 | AddTrace("\tDelete($child) failed"); | ||
1621 | $errors++; | ||
1622 | } | ||
1623 | } | ||
1624 | else | ||
1625 | { | ||
1626 | if ($trace) | ||
1627 | { | ||
1628 | AddTrace("\tDelete($child)....OK!"); | ||
1629 | } | ||
1630 | } | ||
1631 | } | ||
1632 | |||
1633 | //cleanup | ||
1634 | foreach ($childrenStore as $child); | ||
1635 | { | ||
1636 | $child->Delete(); | ||
1637 | } | ||
1638 | |||
1639 | if ($errors == 0) | ||
1640 | { | ||
1641 | return true; | ||
1642 | } | ||
1643 | return false; | ||
1644 | } | ||
1645 | |||
1646 | /** | ||
1647 | * Unit test for Delete($deep) | ||
1648 | * | ||
1649 | * @param unknown_type $object | ||
1650 | * @param unknown_type $trace | ||
1651 | */ | ||
1652 | function TestDeleteDeep_Sibling($object, $trace = true, $ignoreObjects) | ||
1653 | { | ||
1654 | $thisObjectName = get_class($object); | ||
1655 | $attribute_types = $object->pog_attribute_type; | ||
1656 | |||
1657 | if (!TestAddSibling($object, false, $ignoreObjects) || !TestSaveDeep_Sibling($object, false, $ignoreObjects)) | ||
1658 | { | ||
1659 | AddTrace("\tDelete(deep) ignored"); | ||
1660 | return false; | ||
1661 | } | ||
1662 | //get all sibling classes | ||
1663 | $siblingList = array(); | ||
1664 | foreach ($attribute_types as $key => $attribute_array) | ||
1665 | { | ||
1666 | if ($attribute_array['db_attributes'][1] == "JOIN") | ||
1667 | { | ||
1668 | $siblingList[] = $key; | ||
1669 | } | ||
1670 | } | ||
1671 | |||
1672 | $errors = 0; | ||
1673 | |||
1674 | $object = PopulateTestValues($object); | ||
1675 | $object->Save(false); | ||
1676 | |||
1677 | $siblingStore = array(); | ||
1678 | foreach ($siblingList as $sibling) | ||
1679 | { | ||
1680 | //instantiate | ||
1681 | eval("\$siblingInstance = new $sibling();"); | ||
1682 | $siblingInstance = PopulateTestValues($siblingInstance); | ||
1683 | eval("\$siblingInstance->Add".$thisObjectName."(\$object);"); | ||
1684 | $siblingId = $siblingInstance->Save(); | ||
1685 | $siblingStore[] = $siblingId; | ||
1686 | } | ||
1687 | |||
1688 | //test | ||
1689 | if (!$object->Delete(false, true)) | ||
1690 | { | ||
1691 | $errors++; | ||
1692 | } | ||
1693 | |||
1694 | $x = 0; | ||
1695 | foreach ($siblingList as $sibling) | ||
1696 | { | ||
1697 | eval("\$siblingInstance = new $sibling();"); | ||
1698 | $siblingLeft = $siblingInstance->GetList(array(array(strtolower($sibling)."Id", "=", $siblingStore[$x]))); | ||
1699 | if (sizeof($siblingLeft) > 0) | ||
1700 | { | ||
1701 | if ($trace) | ||
1702 | { | ||
1703 | AddTrace("\tDelete($sibling) failed"); | ||
1704 | $errors++; | ||
1705 | } | ||
1706 | } | ||
1707 | else | ||
1708 | { | ||
1709 | if ($trace) | ||
1710 | { | ||
1711 | AddTrace("\tDelete($sibling)....OK!"); | ||
1712 | } | ||
1713 | } | ||
1714 | $x++; | ||
1715 | } | ||
1716 | |||
1717 | |||
1718 | //cleanup | ||
1719 | $object->Delete(); | ||
1720 | $x = 0; | ||
1721 | foreach ($siblingList as $sibling) | ||
1722 | { | ||
1723 | eval("\$siblingInstance = new $sibling();"); | ||
1724 | if (isset($siblingStore[$x]) && $siblingStore[$x] != '') | ||
1725 | { | ||
1726 | eval ("\$siblingInstance->".strtolower($sibling)."Id = ".$siblingStore[$x].";"); | ||
1727 | $siblingInstance->Delete(); | ||
1728 | } | ||
1729 | $x++; | ||
1730 | } | ||
1731 | |||
1732 | if ($errors == 0) | ||
1733 | { | ||
1734 | return true; | ||
1735 | } | ||
1736 | return false; | ||
1737 | } | ||
1738 | |||
1739 | /** | ||
1740 | * Unit test for SetParent() | ||
1741 | * | ||
1742 | * @param unknown_type $object | ||
1743 | */ | ||
1744 | function TestSetParent($object, $trace = true, $ignoreObjects) | ||
1745 | { | ||
1746 | $thisObjectName = get_class($object); | ||
1747 | $attribute_types = $object->pog_attribute_type; | ||
1748 | |||
1749 | //get all parent classes | ||
1750 | $parentList = array(); | ||
1751 | foreach ($attribute_types as $key => $attribute_array) | ||
1752 | { | ||
1753 | if ($attribute_array['db_attributes'][1] == "BELONGSTO") | ||
1754 | { | ||
1755 | $parentList[] = $key; | ||
1756 | } | ||
1757 | } | ||
1758 | |||
1759 | $errors = 0; | ||
1760 | foreach ($parentList as $parent) | ||
1761 | { | ||
1762 | //instantiate | ||
1763 | eval("\$parentInstance = new $parent();"); | ||
1764 | |||
1765 | //save | ||
1766 | $parentInstance = PopulateTestValues($parentInstance); | ||
1767 | $parentInstance -> Save(false); | ||
1768 | |||
1769 | //set parent | ||
1770 | eval ("\$object -> Set$parent(\$parentInstance);"); | ||
1771 | |||
1772 | eval ("\$objectId = \$object->".strtolower($parent)."Id;"); | ||
1773 | |||
1774 | eval ("\$parentId = \$parentInstance->".strtolower($parent)."Id;"); | ||
1775 | |||
1776 | if ($objectId != $parentId) | ||
1777 | { | ||
1778 | if ($trace) | ||
1779 | { | ||
1780 | AddTrace("\tSet$parent() failed"); | ||
1781 | AddError("Could not set $parent as {Parent} of $thisObjectName"); | ||
1782 | } | ||
1783 | $errors++; | ||
1784 | } | ||
1785 | else | ||
1786 | { | ||
1787 | if ($trace) | ||
1788 | { | ||
1789 | AddTrace("\tSet$parent()....OK!"); | ||
1790 | } | ||
1791 | } | ||
1792 | //cleanup (delete parent) | ||
1793 | $parentInstance -> Delete(false); | ||
1794 | eval ("\$object->".strtolower($parent)."Id = '';"); | ||
1795 | } | ||
1796 | |||
1797 | if ($errors == 0) | ||
1798 | { | ||
1799 | return true; | ||
1800 | } | ||
1801 | return false; | ||
1802 | } | ||
1803 | |||
1804 | /** | ||
1805 | * Unit test for GetParent() | ||
1806 | * | ||
1807 | * @param unknown_type $object | ||
1808 | */ | ||
1809 | function TestGetParent($object, $ignoreObjects) | ||
1810 | { | ||
1811 | $thisObjectName = get_class($object); | ||
1812 | eval ("\$object = new $thisObjectName();"); | ||
1813 | |||
1814 | $attribute_types = $object->pog_attribute_type; | ||
1815 | |||
1816 | //get all parent classes | ||
1817 | $parentList = array(); | ||
1818 | foreach ($attribute_types as $key => $attribute_array) | ||
1819 | { | ||
1820 | if ($attribute_array['db_attributes'][1] == "BELONGSTO") | ||
1821 | { | ||
1822 | $parentList[] = $key; | ||
1823 | } | ||
1824 | } | ||
1825 | |||
1826 | $errors = 0; | ||
1827 | |||
1828 | foreach ($parentList as $parent) | ||
1829 | { | ||
1830 | /*if (TestSetParent($object, false)) | ||
1831 | {*/ | ||
1832 | //instantiate | ||
1833 | eval("\$parentInstance = new $parent();"); | ||
1834 | |||
1835 | //save | ||
1836 | $parentInstance = PopulateTestValues($parentInstance); | ||
1837 | $parentInstance -> Save(false); | ||
1838 | |||
1839 | |||
1840 | //set parent | ||
1841 | eval ("\$object -> Set$parent(\$parentInstance);"); | ||
1842 | |||
1843 | eval("\$myParent = \$object->Get$parent();"); | ||
1844 | |||
1845 | eval ("\$objectId = \$object->".strtolower($parent)."Id;"); | ||
1846 | |||
1847 | eval ("\$parentId = \$myParent->".strtolower($parent)."Id;"); | ||
1848 | |||
1849 | if ($objectId != $parentId) | ||
1850 | { | ||
1851 | AddTrace("\tGet$parent() failed"); | ||
1852 | AddError("Could not retrieve parent object $parent"); | ||
1853 | $errors++; | ||
1854 | } | ||
1855 | else | ||
1856 | { | ||
1857 | AddTrace("\tGet$parent()....OK!"); | ||
1858 | } | ||
1859 | |||
1860 | //cleanup (delete parent) | ||
1861 | $parentInstance -> Delete(false); | ||
1862 | /*} | ||
1863 | else | ||
1864 | { | ||
1865 | AddTrace("\tGet$parent() ignored"); | ||
1866 | }*/ | ||
1867 | } | ||
1868 | if ($errors == 0) | ||
1869 | { | ||
1870 | return true; | ||
1871 | } | ||
1872 | return false; | ||
1873 | } | ||
1874 | |||
1875 | /** | ||
1876 | * Unit test for AddChild() | ||
1877 | * | ||
1878 | * @param unknown_type $object | ||
1879 | */ | ||
1880 | function TestAddChild($object, $trace = true, $ignoreObjects) | ||
1881 | { | ||
1882 | $thisObjectName = get_class($object); | ||
1883 | eval ("\$object = new $thisObjectName();"); | ||
1884 | $attribute_types = $object->pog_attribute_type; | ||
1885 | |||
1886 | $object = PopulateTestValues($object); | ||
1887 | |||
1888 | //get all child classes | ||
1889 | $childrenList = array(); | ||
1890 | foreach ($attribute_types as $key => $attribute_array) | ||
1891 | { | ||
1892 | if ($attribute_array['db_attributes'][1] == "HASMANY") | ||
1893 | { | ||
1894 | $childrenList[] = $key; | ||
1895 | } | ||
1896 | } | ||
1897 | |||
1898 | $errors = 0; | ||
1899 | foreach ($childrenList as $child) | ||
1900 | { | ||
1901 | //instantiate | ||
1902 | eval ("\$childInstance = new $child();"); | ||
1903 | $childInstance = PopulateTestValues($childInstance); | ||
1904 | |||
1905 | //instantiate other | ||
1906 | eval("\$childInstance2 = new $child();"); | ||
1907 | $childInstance2 = PopulateTestValues($childInstance2); | ||
1908 | |||
1909 | //add children | ||
1910 | eval ("\$object -> Add$child(\$childInstance);"); | ||
1911 | eval ("\$object -> Add$child(\$childInstance2);"); | ||
1912 | |||
1913 | //verify that children were added | ||
1914 | |||
1915 | eval ("\$children = \$object->".strtolower($child)."List;"); | ||
1916 | |||
1917 | if (sizeof($children) != 2) | ||
1918 | { | ||
1919 | if ($trace) | ||
1920 | { | ||
1921 | AddTrace("\tAdd$child() failed"); | ||
1922 | AddError("Could not add child object $child"); | ||
1923 | } | ||
1924 | $errors++; | ||
1925 | } | ||
1926 | else | ||
1927 | { | ||
1928 | if ($trace) | ||
1929 | { | ||
1930 | AddTrace("\tAdd$child()....OK!"); | ||
1931 | } | ||
1932 | } | ||
1933 | } | ||
1934 | |||
1935 | if ($errors == 0) | ||
1936 | { | ||
1937 | return true; | ||
1938 | } | ||
1939 | return false; | ||
1940 | } | ||
1941 | |||
1942 | /** | ||
1943 | * Unit test for GetChildrenList() | ||
1944 | * | ||
1945 | * @param unknown_type $object | ||
1946 | */ | ||
1947 | function TestGetChildrenList($object, $trace = true, $ignoreObjects) | ||
1948 | { | ||
1949 | $thisObjectName = get_class($object); | ||
1950 | eval ("\$object = new $thisObjectName();"); | ||
1951 | $attribute_types = $object->pog_attribute_type; | ||
1952 | $errors = 0; | ||
1953 | |||
1954 | //get all child classes | ||
1955 | $childrenList = array(); | ||
1956 | foreach ($attribute_types as $key => $attribute_array) | ||
1957 | { | ||
1958 | if ($attribute_array['db_attributes'][1] == "HASMANY") | ||
1959 | { | ||
1960 | $childrenList[] = $key; | ||
1961 | } | ||
1962 | } | ||
1963 | |||
1964 | //save shallow | ||
1965 | $object = PopulateTestValues($object); | ||
1966 | $object->Save(false); | ||
1967 | |||
1968 | |||
1969 | foreach ($childrenList as $child) | ||
1970 | { | ||
1971 | //instantiate | ||
1972 | eval("\$childInstance = new $child();"); | ||
1973 | $childInstance = PopulateTestValues($childInstance); | ||
1974 | |||
1975 | if (!TestSetParent($childInstance, false, $ignoreObjects)) | ||
1976 | { | ||
1977 | AddTrace("\tGetChildrenList() ignored"); | ||
1978 | return false; | ||
1979 | } | ||
1980 | eval("\$childInstance->Set".$thisObjectName."(\$object);"); | ||
1981 | |||
1982 | $childInstance->Save(); | ||
1983 | |||
1984 | |||
1985 | |||
1986 | //try getting all children | ||
1987 | eval ("\$children = \$object -> Get".$child."List();"); | ||
1988 | if (sizeof($children) != 1) | ||
1989 | { | ||
1990 | AddTrace("\tGet".$child."List() failed"); | ||
1991 | AddError("Could not get children list"); | ||
1992 | $errors++; | ||
1993 | } | ||
1994 | |||
1995 | //cleanup | ||
1996 | $childInstance->Delete(); | ||
1997 | |||
1998 | if ($errors == 0 && $trace) | ||
1999 | { | ||
2000 | AddTrace("\tGet".$child."List()....OK!"); | ||
2001 | } | ||
2002 | } | ||
2003 | |||
2004 | $object->Delete(false); | ||
2005 | |||
2006 | if ($errors == 0) | ||
2007 | { | ||
2008 | return true; | ||
2009 | } | ||
2010 | return false; | ||
2011 | } | ||
2012 | |||
2013 | /** | ||
2014 | * Unit Test for SetChildrenList | ||
2015 | * | ||
2016 | * @param unknown_type $object | ||
2017 | * @param unknown_type $trace | ||
2018 | * @return unknown | ||
2019 | */ | ||
2020 | function TestSetChildrenList($object, $trace = true, $ignoreObjects) | ||
2021 | { | ||
2022 | $thisObjectName = get_class($object); | ||
2023 | if (!TestSaveDeep_Child($object, false, $ignoreObjects)) | ||
2024 | { | ||
2025 | AddTrace("\tSetChildrenList(deep) ignored"); | ||
2026 | AddError("SetChildrenList ignored since SaveDeep could not be performed"); | ||
2027 | return false; | ||
2028 | } | ||
2029 | |||
2030 | //get all child classes | ||
2031 | $childrenList = array(); | ||
2032 | eval("\$object = new $thisObjectName();"); | ||
2033 | $object = PopulateTestValues($object); | ||
2034 | $attribute_types = $object->pog_attribute_type; | ||
2035 | |||
2036 | foreach ($attribute_types as $key => $attribute_array) | ||
2037 | { | ||
2038 | if ($attribute_array['db_attributes'][1] == "HASMANY") | ||
2039 | { | ||
2040 | $childrenList[] = $key; | ||
2041 | } | ||
2042 | } | ||
2043 | |||
2044 | $errors = 0; | ||
2045 | foreach ($childrenList as $child) | ||
2046 | { | ||
2047 | //instantiate | ||
2048 | $childInstanceList = array(); | ||
2049 | eval("\$childInstance = new $child();"); | ||
2050 | eval("\$childInstance2 = new $child();"); | ||
2051 | $childInstance = PopulateTestValues($childInstance); | ||
2052 | $childInstance2 = PopulateTestValues($childInstance2); | ||
2053 | |||
2054 | //add children to array | ||
2055 | $childInstanceList[] = $childInstance; | ||
2056 | $childInstanceList[] = $childInstance2; | ||
2057 | |||
2058 | eval ("\$object -> Set".$child."List(\$childInstanceList);"); | ||
2059 | } | ||
2060 | |||
2061 | //test | ||
2062 | if (!$object->Save(true)) | ||
2063 | { | ||
2064 | $errors++; | ||
2065 | return false; | ||
2066 | } | ||
2067 | |||
2068 | foreach ($childrenList as $child) | ||
2069 | { | ||
2070 | //instantiate | ||
2071 | eval("\$childArray = \$object->Get".$child."List();"); | ||
2072 | if (sizeof($childArray) == 0) | ||
2073 | { | ||
2074 | AddTrace("\tSet($child)List failed"); | ||
2075 | $errors++; | ||
2076 | } | ||
2077 | else | ||
2078 | { | ||
2079 | AddTrace("\tSet($child)List....OK!"); | ||
2080 | } | ||
2081 | } | ||
2082 | |||
2083 | //cleanup | ||
2084 | $object->Delete(true); | ||
2085 | |||
2086 | if ($errors == 0) | ||
2087 | { | ||
2088 | return true; | ||
2089 | } | ||
2090 | return false; | ||
2091 | } | ||
2092 | |||
2093 | /** | ||
2094 | * Unit Test for AddSibling() | ||
2095 | * | ||
2096 | * @param unknown_type $object | ||
2097 | * @param unknown_type $trace | ||
2098 | * @return unknown | ||
2099 | */ | ||
2100 | function TestAddSibling($object, $trace = true, $ignoreObjects) | ||
2101 | { | ||
2102 | $thisObjectName = get_class($object); | ||
2103 | eval ("\$object = new $thisObjectName();"); | ||
2104 | $attribute_types = $object->pog_attribute_type; | ||
2105 | |||
2106 | $object = PopulateTestValues($object); | ||
2107 | |||
2108 | //get all sibling classes | ||
2109 | $siblingList = array(); | ||
2110 | foreach ($attribute_types as $key => $attribute_array) | ||
2111 | { | ||
2112 | if ($attribute_array['db_attributes'][1] == "JOIN") | ||
2113 | { | ||
2114 | $siblingList[] = $key; | ||
2115 | } | ||
2116 | } | ||
2117 | |||
2118 | $errors = 0; | ||
2119 | foreach ($siblingList as $sibling) | ||
2120 | { | ||
2121 | //instantiate | ||
2122 | eval ("\$siblingInstance = new $sibling();"); | ||
2123 | $siblingInstance = PopulateTestValues($siblingInstance); | ||
2124 | |||
2125 | //instantiate other | ||
2126 | eval("\$siblingInstance2 = new $sibling();"); | ||
2127 | $siblingInstance2 = PopulateTestValues($siblingInstance2); | ||
2128 | |||
2129 | //add sibling | ||
2130 | eval ("\$object -> Add$sibling(\$siblingInstance);"); | ||
2131 | eval ("\$object -> Add$sibling(\$siblingInstance2);"); | ||
2132 | |||
2133 | //verify that slbings were added | ||
2134 | eval ("\$siblings = \$object->".strtolower($sibling)."List;"); | ||
2135 | |||
2136 | if (sizeof($siblings) != 2) | ||
2137 | { | ||
2138 | if ($trace) | ||
2139 | { | ||
2140 | AddTrace("\tAdd$sibling() failed"); | ||
2141 | AddError("Could not add sibling object $sibling"); | ||
2142 | } | ||
2143 | $errors++; | ||
2144 | } | ||
2145 | else | ||
2146 | { | ||
2147 | if ($trace) | ||
2148 | { | ||
2149 | AddTrace("\tAdd$sibling()....OK!"); | ||
2150 | } | ||
2151 | } | ||
2152 | } | ||
2153 | |||
2154 | if ($errors == 0) | ||
2155 | { | ||
2156 | return true; | ||
2157 | } | ||
2158 | return false; | ||
2159 | } | ||
2160 | |||
2161 | /** | ||
2162 | * Unit test for GetSiblingList() | ||
2163 | * | ||
2164 | * @param unknown_type $object | ||
2165 | * @param unknown_type $trace | ||
2166 | * @return unknown | ||
2167 | */ | ||
2168 | function TestGetSiblingList($object, $trace = true, $ignoreObjects) | ||
2169 | { | ||
2170 | $thisObjectName = get_class($object); | ||
2171 | eval ("\$object = new $thisObjectName();"); | ||
2172 | $attribute_types = $object->pog_attribute_type; | ||
2173 | $errors = 0; | ||
2174 | |||
2175 | //get all sibling classes | ||
2176 | $siblingList = array(); | ||
2177 | foreach ($attribute_types as $key => $attribute_array) | ||
2178 | { | ||
2179 | if ($attribute_array['db_attributes'][1] == "JOIN") | ||
2180 | { | ||
2181 | $siblingList[] = $key; | ||
2182 | } | ||
2183 | } | ||
2184 | |||
2185 | $object = PopulateTestValues($object); | ||
2186 | |||
2187 | $siblingsStore = array(); | ||
2188 | |||
2189 | foreach ($siblingList as $sibling) | ||
2190 | { | ||
2191 | //instantiate | ||
2192 | eval("\$siblingInstance = new $sibling();"); | ||
2193 | $siblingsStore[] = $siblingInstance; | ||
2194 | $siblingInstance = PopulateTestValues($siblingInstance); | ||
2195 | |||
2196 | if (!TestAddSibling($siblingInstance, false, $ignoreObjects)) | ||
2197 | { | ||
2198 | if ($trace) | ||
2199 | { | ||
2200 | AddTrace("\tGetSiblingList() ignored"); | ||
2201 | } | ||
2202 | return false; | ||
2203 | } | ||
2204 | eval("\$object->Add".$sibling."(\$siblingInstance);"); | ||
2205 | |||
2206 | } | ||
2207 | |||
2208 | $object->Save(); | ||
2209 | |||
2210 | foreach ($siblingList as $sibling) | ||
2211 | { | ||
2212 | |||
2213 | //try getting all siblings | ||
2214 | eval ("\$siblings = \$object -> Get".$sibling."List();"); | ||
2215 | if (sizeof($siblings) != 1) | ||
2216 | { | ||
2217 | if ($trace) | ||
2218 | { | ||
2219 | AddTrace("\tGet".$sibling."List() failed"); | ||
2220 | AddError("Could not get sibling list"); | ||
2221 | } | ||
2222 | $errors++; | ||
2223 | } | ||
2224 | else if ($trace) | ||
2225 | { | ||
2226 | AddTrace("\tGet".$sibling."List()....OK!"); | ||
2227 | } | ||
2228 | } | ||
2229 | |||
2230 | foreach ($siblingsStore as $stored) | ||
2231 | { | ||
2232 | $stored->Delete(); | ||
2233 | } | ||
2234 | |||
2235 | $object->Delete(false); | ||
2236 | |||
2237 | if ($errors == 0) | ||
2238 | { | ||
2239 | return true; | ||
2240 | } | ||
2241 | return false; | ||
2242 | } | ||
2243 | |||
2244 | /** | ||
2245 | * Unit test for SetSiblingList() | ||
2246 | * | ||
2247 | * @param unknown_type $object | ||
2248 | * @param unknown_type $trace | ||
2249 | */ | ||
2250 | function TestSetSiblingList($object, $trace = true, $ignoreObjects) | ||
2251 | { | ||
2252 | $thisObjectName = get_class($object); | ||
2253 | if (!TestSaveDeep_Sibling($object, false, $ignoreObjects)) | ||
2254 | { | ||
2255 | AddTrace("\tSetSiblingList(deep) ignored"); | ||
2256 | AddError("SetSiblingList ignored since SaveDeep could not be performed"); | ||
2257 | return false; | ||
2258 | } | ||
2259 | |||
2260 | //get all sibling classes | ||
2261 | $siblingList = array(); | ||
2262 | eval("\$object = new $thisObjectName();"); | ||
2263 | $object = PopulateTestValues($object); | ||
2264 | $attribute_types = $object->pog_attribute_type; | ||
2265 | |||
2266 | foreach ($attribute_types as $key => $attribute_array) | ||
2267 | { | ||
2268 | if ($attribute_array['db_attributes'][1] == "JOIN") | ||
2269 | { | ||
2270 | $siblingList[] = $key; | ||
2271 | } | ||
2272 | } | ||
2273 | |||
2274 | $errors = 0; | ||
2275 | foreach ($siblingList as $sibling) | ||
2276 | { | ||
2277 | //instantiate | ||
2278 | $siblingInstanceList = array(); | ||
2279 | eval("\$siblingInstance = new $sibling();"); | ||
2280 | eval("\$siblingInstance2 = new $sibling();"); | ||
2281 | $siblingInstance = PopulateTestValues($siblingInstance); | ||
2282 | $siblingInstance2 = PopulateTestValues($siblingInstance2); | ||
2283 | |||
2284 | //add sibling to array | ||
2285 | $siblingInstanceList[] = $siblingInstance; | ||
2286 | $siblingInstanceList[] = $siblingInstance2; | ||
2287 | |||
2288 | eval ("\$object -> Set".$sibling."List(\$siblingInstanceList);"); | ||
2289 | } | ||
2290 | |||
2291 | //test | ||
2292 | if (!$object->Save(true)) | ||
2293 | { | ||
2294 | $errors++; | ||
2295 | return false; | ||
2296 | } | ||
2297 | |||
2298 | foreach ($siblingList as $sibling) | ||
2299 | { | ||
2300 | //instantiate | ||
2301 | eval("\$siblingArray = \$object->Get".$sibling."List();"); | ||
2302 | if (sizeof($siblingArray) == 0) | ||
2303 | { | ||
2304 | if ($trace) | ||
2305 | { | ||
2306 | AddTrace("\tSet($sibling)List failed"); | ||
2307 | } | ||
2308 | $errors++; | ||
2309 | } | ||
2310 | else if ($trace) | ||
2311 | { | ||
2312 | AddTrace("\tSet($sibling)List....OK!"); | ||
2313 | } | ||
2314 | } | ||
2315 | |||
2316 | //cleanup | ||
2317 | $object->Delete(false, true); | ||
2318 | |||
2319 | if ($errors == 0) | ||
2320 | { | ||
2321 | return true; | ||
2322 | } | ||
2323 | return false; | ||
2324 | } | ||
2325 | |||
2326 | /** | ||
2327 | * Creates the mapping name | ||
2328 | * | ||
2329 | * @param unknown_type $objectName1 | ||
2330 | * @param unknown_type $objectName2 | ||
2331 | * @return unknown | ||
2332 | */ | ||
2333 | function MappingName($objectName1, $objectName2) | ||
2334 | { | ||
2335 | $array = array($objectName1, $objectName2); | ||
2336 | sort($array); | ||
2337 | return implode($array)."Map"; | ||
2338 | } | ||
2339 | |||
2340 | /** | ||
2341 | * Gets total no. of records; | ||
2342 | */ | ||
2343 | function GetNumberOfRecords($objectName) | ||
2344 | { | ||
2345 | $sql = 'select count(*) from `'.strtolower($objectName)."`"; | ||
2346 | $connection = Database::Connect(); | ||
2347 | $cursor = Database::Reader($sql, $connection); | ||
2348 | if ($cursor !== false) | ||
2349 | { | ||
2350 | while($row = Database::Read($cursor)) | ||
2351 | { | ||
2352 | return $row['count(*)']; | ||
2353 | } | ||
2354 | } | ||
2355 | return 0; | ||
2356 | } | ||
2357 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/setup/setup_library/upgrade.php b/backend/php/src/setup/setup_library/upgrade.php new file mode 100644 index 0000000..122da58 --- a/dev/null +++ b/backend/php/src/setup/setup_library/upgrade.php | |||
@@ -0,0 +1,140 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * @author Joel Wan & Mark Slemko. Designs by Jonathan Easton | ||
4 | * @link http://www.phpobjectgenerator.com | ||
5 | * @copyright Offered under the BSD license | ||
6 | * | ||
7 | * This upgrade file does the following: | ||
8 | * 1. Checks if there is a new version of POG | ||
9 | * 2. If there is, it reads generates newer versions of all objects in the object directory, | ||
10 | * zip then and present them to the user to 'download' | ||
11 | */ | ||
12 | ini_set("max_execution_time", 0); | ||
13 | include_once "../../configuration.php"; | ||
14 | include_once "class.zipfile.php"; | ||
15 | include_once "setup_misc.php"; | ||
16 | |||
17 | /** | ||
18 | * Connects to POG SOAP server defined in configuration.php and | ||
19 | * generates new versions of all objects detected in /objects/ dir. | ||
20 | * All upgraded objects are then zipped and presented to user. | ||
21 | * | ||
22 | * @param string $path | ||
23 | */ | ||
24 | function UpdateAllObjects($path) | ||
25 | { | ||
26 | $dir = opendir($path); | ||
27 | $objects = array(); | ||
28 | while(($file = readdir($dir)) !== false) | ||
29 | { | ||
30 | if(strlen($file) > 4 && substr(strtolower($file), strlen($file) - 4) === '.php' && !is_dir($file) && $file != "class.database.php" && $file != "configuration.php" && $file != "setup.php" && $file != "class.pog_base.php") | ||
31 | { | ||
32 | $objects[] = $file; | ||
33 | } | ||
34 | } | ||
35 | closedir($dir); | ||
36 | $i = 0; | ||
37 | foreach($objects as $object) | ||
38 | { | ||
39 | $content = file_get_contents($path."/".$object); | ||
40 | $contentParts = split("<b>",$content); | ||
41 | if (isset($contentParts[1])) | ||
42 | { | ||
43 | $contentParts2 = split("</b>",$contentParts[1]); | ||
44 | } | ||
45 | if (isset($contentParts2[0])) | ||
46 | { | ||
47 | $className = trim($contentParts2[0]); | ||
48 | } | ||
49 | if (isset($className)) | ||
50 | { | ||
51 | eval ('include_once("../../objects/class.'.strtolower($className).'.php");'); | ||
52 | $instance = new $className(); | ||
53 | if (!TestIsMapping($instance)) | ||
54 | { | ||
55 | $objectNameList[] = $className; | ||
56 | |||
57 | $linkParts1 = split("\*\/", $contentParts[1]); | ||
58 | $linkParts2 = split("\@link", $linkParts1[0]); | ||
59 | $link = $linkParts2[1]; | ||
60 | $options = false; | ||
61 | if ($GLOBALS['configuration']['proxy_host'] != false && | ||
62 | $GLOBALS['configuration']['proxy_port'] != false && | ||
63 | $GLOBALS['configuration']['proxy_username'] != false && | ||
64 | $GLOBALS['configuration']['proxy_password'] != false) | ||
65 | { | ||
66 | $options = array( | ||
67 | 'proxy_host' => $GLOBALS['configuration']['proxy_host'], | ||
68 | 'proxy_port' => $GLOBALS['configuration']['proxy_port'], | ||
69 | 'proxy_login' => $GLOBALS['configuration']['proxy_username'], | ||
70 | 'proxy_password' => $GLOBALS['configuration']['proxy_password'] | ||
71 | ); | ||
72 | } | ||
73 | $client = new SoapClient( | ||
74 | $GLOBALS['configuration']['soap'], | ||
75 | $options) ; | ||
76 | if ($i == 0) | ||
77 | { | ||
78 | $package = unserialize($client->GeneratePackageFromLink($link)); | ||
79 | } | ||
80 | else | ||
81 | { | ||
82 | $objectString = $client->GenerateObjectFromLink($link); | ||
83 | $package["objects"]["class.".strtolower($className).".php"] = $objectString; | ||
84 | } | ||
85 | } | ||
86 | } | ||
87 | $i++; | ||
88 | } | ||
89 | |||
90 | |||
91 | //upgrade mapping classes if any | ||
92 | foreach ($objectNameList as $objectName) | ||
93 | { | ||
94 | $instance = new $objectName(); | ||
95 | foreach ($instance->pog_attribute_type as $key => $attribute_type) | ||
96 | { | ||
97 | if ($attribute_type['db_attributes'][1] == "JOIN") | ||
98 | { | ||
99 | $mappingString = $client->GenerateMapping($objectName, $key, (isset($GLOBALS['configuration']['pdoDriver']) ? 'php5.1' :'php5'), (isset($GLOBALS['configuration']['pdoDriver']) ? 'pdo' :'pog'), (isset($GLOBALS['configuration']['pdoDriver']) ? 'mysql' :'')); | ||
100 | $package["objects"]['class.'.strtolower(MappingName($objectName, $key)).'.php'] = $mappingString; | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | |||
105 | $zipfile = new createZip(); | ||
106 | $zipfile -> addPOGPackage($package); | ||
107 | $zipfile -> forceDownload("pog.".time().".zip"); | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * Checks if POG generator has been updated | ||
112 | * | ||
113 | * @return unknown | ||
114 | */ | ||
115 | function UpdateAvailable() | ||
116 | { | ||
117 | $client = new SoapClient($GLOBALS['configuration']['soap']); | ||
118 | $generatorVersion = base64_decode($client -> GetGeneratorVersion()); | ||
119 | if ($generatorVersion != $GLOBALS['configuration']['versionNumber'].$GLOBALS['configuration']['revisionNumber']) | ||
120 | { | ||
121 | return true; | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | return false; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | if (UpdateAvailable()) | ||
130 | { | ||
131 | UpdateAllObjects("../../objects/"); | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | echo "<script> | ||
136 | alert('All POG objects are already up to date'); | ||
137 | window.close(); | ||
138 | </script>"; | ||
139 | } | ||
140 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/setup/setup_library/xPandMenu.css b/backend/php/src/setup/setup_library/xPandMenu.css new file mode 100644 index 0000000..744debe --- a/dev/null +++ b/backend/php/src/setup/setup_library/xPandMenu.css | |||
@@ -0,0 +1,55 @@ | |||
1 | #container { | ||
2 | width:500px; | ||
3 | background-color:#E7E9EE; | ||
4 | } | ||
5 | .Xtree, .XtreeRoot { | ||
6 | list-style-type:none; | ||
7 | margin:15px 20px; | ||
8 | } | ||
9 | .Xtree { | ||
10 | /* Indentation of a sub-item compared to its parent */ | ||
11 | padding-left:25px; | ||
12 | margin-left:3px; | ||
13 | border-left:1px dotted #998D05; | ||
14 | width:100%; | ||
15 | } | ||
16 | .Xnode { | ||
17 | /* Top and bottom space for a node item */ | ||
18 | margin-top:-3px;margin-bottom:3px; | ||
19 | /* Height of the node item */ | ||
20 | height:20px; | ||
21 | /* Node background color */ | ||
22 | background:#E7E9EE; | ||
23 | /* Font specifications for a node */ | ||
24 | font-weight:bold; | ||
25 | font-size:10px; | ||
26 | cursor:pointer; | ||
27 | vertical-align:middle; | ||
28 | width:100%; | ||
29 | } | ||
30 | .Xnode img{ vertical-align:middle; } | ||
31 | .Xleaf { | ||
32 | /* Top and bottom space for a leaf item */ | ||
33 | margin-top:-10px;margin-bottom:1px; | ||
34 | /* Height of the leag item */ | ||
35 | /* Leaf background color */ | ||
36 | /* Font specifications for a leaf */ | ||
37 | font-weight:normal; | ||
38 | font-size:10px; | ||
39 | padding:2px; | ||
40 | } | ||
41 | .Xnode a { | ||
42 | text-decoration:none; | ||
43 | } | ||
44 | .Xnode a:hover { | ||
45 | color:red; | ||
46 | text-decoration:underline; | ||
47 | } | ||
48 | .Xleaf a { | ||
49 | text-decoration:none; | ||
50 | } | ||
51 | .Xleaf a:hover { | ||
52 | color:red; | ||
53 | text-decoration:none; | ||
54 | background:#eee; | ||
55 | } \ No newline at end of file | ||
diff --git a/backend/php/src/setup/setup_library/xPandMenu.js b/backend/php/src/setup/setup_library/xPandMenu.js new file mode 100644 index 0000000..7f9a632 --- a/dev/null +++ b/backend/php/src/setup/setup_library/xPandMenu.js | |||
@@ -0,0 +1,273 @@ | |||
1 | /******************************** | ||
2 | * xPandMenu MULTI-LEVEL class | ||
3 | ********************************* | ||
4 | * Javascript file | ||
5 | ********************************* | ||
6 | * Patrick Brosset | ||
7 | * patrickbrosset@gmail.com | ||
8 | ********************************* | ||
9 | * 02/2005 | ||
10 | *********************************/ | ||
11 | |||
12 | |||
13 | // Show / hide a sub-menu | ||
14 | function xMenuShowHide(obj) | ||
15 | { | ||
16 | |||
17 | if(obj.style.display == 'none'){ | ||
18 | obj.style.display = 'block'; | ||
19 | }else{ | ||
20 | obj.style.display = 'none'; | ||
21 | } | ||
22 | |||
23 | } | ||
24 | |||
25 | |||
26 | // Toggle expanded / collapsed versions of items' images | ||
27 | function xSwapImg(imgDiv,srcImg,srcAltImg){ | ||
28 | |||
29 | /* Update by Christian Vallee <cv@valtechnologie.com> | ||
30 | ==> No need to specify absolute URL for images anymore, this feature will find it on its own */ | ||
31 | |||
32 | // looking for the images' root URL based on the current image | ||
33 | var str = imgDiv.src; | ||
34 | var pos = str.search(srcImg); | ||
35 | // if the URL root wasn't found using the first image, try with the alternative one | ||
36 | if ( pos == -1 ) { pos = str.search(srcAltImg); } | ||
37 | // extracting the URL root | ||
38 | var root = str.substring(0,pos); | ||
39 | // adding the root the image path supplied | ||
40 | srcImg = root.concat(srcImg); | ||
41 | srcAltImg = root.concat(srcAltImg); | ||
42 | |||
43 | /* End Update */ | ||
44 | |||
45 | if(imgDiv.src == srcImg){ | ||
46 | imgDiv.src = srcAltImg; | ||
47 | }else{ | ||
48 | imgDiv.src = srcImg; | ||
49 | } | ||
50 | |||
51 | } | ||
52 | |||
53 | |||
54 | // Restore the menu state when the page loads | ||
55 | function xRestoreState() | ||
56 | { | ||
57 | //restore list state | ||
58 | var name = "xMenuState"; | ||
59 | var start = document.cookie.indexOf(name+"="); | ||
60 | if(start != -1) | ||
61 | { | ||
62 | var len = start+name.length+1; | ||
63 | if ((!start) && (name != document.cookie.substring(0,name.length))) return null; | ||
64 | if (start == -1) return null; | ||
65 | var end = document.cookie.indexOf(";",len); | ||
66 | if (end == -1) end = document.cookie.length; | ||
67 | var value = unescape(document.cookie.substring(len,end)); | ||
68 | var values = value.split("|"); | ||
69 | for(i=0;i<values.length-1;i++) | ||
70 | { | ||
71 | var couple = values[i].split(":"); | ||
72 | document.getElementById(couple[0]).style.display = couple[1]; | ||
73 | } | ||
74 | } | ||
75 | //restore img state | ||
76 | name = "xMenuStateImg"; | ||
77 | start = document.cookie.indexOf(name+"="); | ||
78 | if(start != -1) | ||
79 | { | ||
80 | var len = start+name.length+1; | ||
81 | if ((!start) && (name != document.cookie.substring(0,name.length))) return null; | ||
82 | if (start == -1) return null; | ||
83 | var end = document.cookie.indexOf(";",len); | ||
84 | if (end == -1) end = document.cookie.length; | ||
85 | var value = unescape(document.cookie.substring(len,end)); | ||
86 | var values = value.split("[]"); | ||
87 | for(i=0;i<values.length-1;i++) | ||
88 | { | ||
89 | var couple = values[i].split(">>"); | ||
90 | var imgs = couple[1].split(","); | ||
91 | for(var il in imgs) | ||
92 | { | ||
93 | document.getElementById(imgs[il]).src = couple[0]; | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | |||
99 | //Get the ids of all open nodes | ||
100 | function getOpenNodes() | ||
101 | { | ||
102 | value = new Array(); | ||
103 | var myLists = document.getElementsByTagName("UL"); | ||
104 | for(i=0;i<myLists.length;i++) | ||
105 | { | ||
106 | if(myLists[i].className == "Xtree" && myLists[i].style.display == "block")value += myLists[i].id + "-"; | ||
107 | } | ||
108 | return value; | ||
109 | } | ||
110 | |||
111 | // Save the menu state when the page unloads | ||
112 | function xSaveState() | ||
113 | { | ||
114 | //Save list state | ||
115 | var value = ""; | ||
116 | var myLists = document.getElementsByTagName("UL"); | ||
117 | for(i=0;i<myLists.length;i++) | ||
118 | { | ||
119 | if(myLists[i].className == "Xtree")value += myLists[i].id + ":" + myLists[i].style.display + "|"; | ||
120 | } | ||
121 | document.cookie = "xMenuState=" + escape(value) + ";"; | ||
122 | //save img state | ||
123 | value = new Array(); | ||
124 | myLists = document.getElementsByTagName("IMG"); | ||
125 | for(i=0;i<myLists.length;i++) | ||
126 | { | ||
127 | if(myLists[i].id.substring(0,4) == "Ximg") | ||
128 | { | ||
129 | if(value[myLists[i].src]){value[myLists[i].src] += "," + myLists[i].id;} | ||
130 | else{value[myLists[i].src] = myLists[i].id;} | ||
131 | } | ||
132 | } | ||
133 | var str = ""; | ||
134 | for(var imgPath in value) | ||
135 | { | ||
136 | str += imgPath + ">>" + value[imgPath] + "[]"; | ||
137 | } | ||
138 | var cook = str.substring(0,str.length-2); | ||
139 | document.cookie = "xMenuStateImg=" + escape(cook) + ";"; | ||
140 | } | ||
141 | |||
142 | function createRequestObject() | ||
143 | { | ||
144 | var ro; | ||
145 | if (window.XMLHttpRequest) | ||
146 | { | ||
147 | ro = new XMLHttpRequest(); | ||
148 | } | ||
149 | else | ||
150 | { | ||
151 | ro = new ActiveXObject('MSXML2.XMLHTTP.3.0'); | ||
152 | } | ||
153 | return ro; | ||
154 | } | ||
155 | |||
156 | var http = createRequestObject(); | ||
157 | |||
158 | function refTree(offset, limit, objectName) | ||
159 | { | ||
160 | http = createRequestObject(); | ||
161 | var req = './rpc.php?action=Refresh&offset='+offset+'&limit='+limit+'&objectname='+objectName; | ||
162 | http.open('get', req); | ||
163 | http.onreadystatechange = handleResponse; | ||
164 | http.send(null); | ||
165 | } | ||
166 | |||
167 | function sndReq(action, openNodes, objectName, objectId, currentNode, attributes, anchor) | ||
168 | { | ||
169 | |||
170 | |||
171 | http = createRequestObject(); | ||
172 | var req = './rpc.php?action='+action+'&opennodes='+openNodes+'&objectname='+objectName+'&objectid='+objectId+'¤tnode='+currentNode+'&anchor='+anchor; | ||
173 | if (action == "Add") | ||
174 | { | ||
175 | for (i=0; i<attributes.length; i++) | ||
176 | { | ||
177 | thisId = attributes[i]; | ||
178 | var thisInput = document.getElementById(thisId); | ||
179 | if (thisInput != null) | ||
180 | { | ||
181 | if (thisInput.type == "checkbox") | ||
182 | { | ||
183 | if (thisInput.checked) | ||
184 | { | ||
185 | req += "&" + thisId + "=" + thisInput.value; | ||
186 | } | ||
187 | } | ||
188 | else | ||
189 | { | ||
190 | req += "&" + thisId + "=" + thisInput.value; | ||
191 | } | ||
192 | } | ||
193 | } | ||
194 | } | ||
195 | else if (action == "Update") | ||
196 | { | ||
197 | for (i=0; i<attributes.length; i++) | ||
198 | { | ||
199 | thisId = attributes[i]; | ||
200 | var thisInput = document.getElementById(thisId+"_"+objectId); | ||
201 | if (thisInput.type == "checkbox") | ||
202 | { | ||
203 | if (thisInput.checked) | ||
204 | { | ||
205 | req += "&" + thisId + "=" + thisInput.value; | ||
206 | } | ||
207 | } | ||
208 | else | ||
209 | { | ||
210 | req += "&" + thisId + "=" + thisInput.value; | ||
211 | } | ||
212 | } | ||
213 | } | ||
214 | http.open('get', req); | ||
215 | http.onreadystatechange = handleResponse; | ||
216 | http.send(null); | ||
217 | } | ||
218 | |||
219 | function handleResponse() | ||
220 | { | ||
221 | if(http.readyState == 4) | ||
222 | { | ||
223 | var response = http.responseText; | ||
224 | document.getElementById('container').innerHTML = response; | ||
225 | } | ||
226 | } | ||
227 | |||
228 | function expandAll() | ||
229 | { | ||
230 | var myLists = document.getElementsByTagName("UL"); | ||
231 | for(i=0;i<myLists.length;i++) | ||
232 | { | ||
233 | if(myLists[i].className == "Xtree" && myLists[i].style.display == "none")myLists[i].style.display = "block"; | ||
234 | } | ||
235 | myLists = document.getElementsByTagName("IMG"); | ||
236 | for(i=0;i<myLists.length;i++) | ||
237 | { | ||
238 | if(myLists[i].id.substring(0,4) == "Ximg") | ||
239 | { | ||
240 | myLists[i].src = "setup_images/folderopen.gif"; | ||
241 | } | ||
242 | } | ||
243 | } | ||
244 | |||
245 | function collapseAll() | ||
246 | { | ||
247 | var myLists = document.getElementsByTagName("UL"); | ||
248 | for(i=0;i<myLists.length;i++) | ||
249 | { | ||
250 | if(myLists[i].className == "Xtree" && myLists[i].style.display == "block")myLists[i].style.display = "none"; | ||
251 | } | ||
252 | myLists = document.getElementsByTagName("IMG"); | ||
253 | for(i=0;i<myLists.length;i++) | ||
254 | { | ||
255 | if(myLists[i].id.substring(0,4) == "Ximg") | ||
256 | { | ||
257 | myLists[i].src = "setup_images/folderclose.gif"; | ||
258 | } | ||
259 | } | ||
260 | } | ||
261 | |||
262 | function ToggleElementVisibility(elementId) | ||
263 | { | ||
264 | var element = document.getElementById(elementId); | ||
265 | if (element.style.display != 'none') | ||
266 | { | ||
267 | element.style.display = 'none'; | ||
268 | } | ||
269 | else | ||
270 | { | ||
271 | element.style.display = 'inline'; | ||
272 | } | ||
273 | } \ No newline at end of file | ||
diff --git a/backend/php/src/setup/setup_library/xPandMenu.php b/backend/php/src/setup/setup_library/xPandMenu.php new file mode 100644 index 0000000..d9c7d07 --- a/dev/null +++ b/backend/php/src/setup/setup_library/xPandMenu.php | |||
@@ -0,0 +1,233 @@ | |||
1 | <?php | ||
2 | |||
3 | /******************************** | ||
4 | * xPandMenu MULTI-LEVEL class | ||
5 | ********************************* | ||
6 | * Creates a tree-view menu. | ||
7 | * The menu can be as deep as needed | ||
8 | * The menu items are organised in HTML unordered lists | ||
9 | * Container nodes can be expanded/collapsed thanks to Javascript actions | ||
10 | ********************************* | ||
11 | * Patrick Brosset | ||
12 | * patrickbrosset@gmail.com | ||
13 | ********************************* | ||
14 | * 02/2005 | ||
15 | *********************************/ | ||
16 | |||
17 | |||
18 | |||
19 | // Path to default image files (directories and documents icons) -- (use absolute URL) | ||
20 | define('NODE_DEFAULT_IMG','http://project.zoe.co.nz/patrick/xpand/multi/images/folder_win.gif'); | ||
21 | define('LEAF_DEFAULT_IMG','http://project.zoe.co.nz/patrick/xpand/multi/images/document_win.gif'); | ||
22 | define('NODE_DEFAULT_ALT_IMG','http://project.zoe.co.nz/patrick/xpand/multi/images/folder_win_o.gif'); | ||
23 | define('LEAF_DEFAULT_ALT_IMG','http://project.zoe.co.nz/patrick/xpand/multi/images/document_win_o.gif'); | ||
24 | |||
25 | // Reference to the File class for saving and loading the generated menu | ||
26 | //include_once 'File.php'; | ||
27 | |||
28 | |||
29 | |||
30 | // Xmenu class | ||
31 | class XMenu | ||
32 | { | ||
33 | |||
34 | |||
35 | // Sub-nodes contained in this menu (references to Xnode objects) | ||
36 | var $items = array(); | ||
37 | |||
38 | // Keeps track of the HTML code indent to use (formatting of UL and LI) | ||
39 | var $indent; | ||
40 | |||
41 | // Is it the first node ? | ||
42 | var $first; | ||
43 | |||
44 | // Used for assigning unique IDs to HTML elements (for the javascript function) | ||
45 | var $treeCount; | ||
46 | |||
47 | // Same for images | ||
48 | var $imgCount; | ||
49 | |||
50 | // Contains the generated HTML code | ||
51 | var $output; | ||
52 | |||
53 | // Contains the nodes to expand when generating tree | ||
54 | var $visibleNodes = array("1"); | ||
55 | |||
56 | |||
57 | |||
58 | // Constructor | ||
59 | function XMenu() | ||
60 | { | ||
61 | $this->indent = 0; | ||
62 | $this->first = true; | ||
63 | $this->treeCount = 0; | ||
64 | $this->imgCount = 0; | ||
65 | $this->output = ""; | ||
66 | } | ||
67 | |||
68 | |||
69 | |||
70 | // addItem, adds a child to this menu | ||
71 | // Takes a XNode object reference as argument | ||
72 | function &addItem(&$node) | ||
73 | { | ||
74 | $this->items[] = &$node; | ||
75 | return $this->items[count($this->items) - 1]; | ||
76 | } | ||
77 | |||
78 | |||
79 | |||
80 | // generateTree, generates the HTML code (UL list) for the dynamic tree-view | ||
81 | function generateTree($root = false) | ||
82 | { | ||
83 | if(!$root)$root = $this; | ||
84 | |||
85 | if($this->first){ | ||
86 | $this->output .= $this->codeIndent()."<ul id=\"XRoot\" class=\"XtreeRoot\">\n"; | ||
87 | $this->first = false; | ||
88 | }else{ | ||
89 | if (array_search($this->treeCount, $this->visibleNodes) !== false) | ||
90 | { | ||
91 | $this->output .= $this->codeIndent()."<ul id=\"Xtree".$this->treeCount."\" class=\"Xtree\" style=\"display:block;\">\n"; | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | $this->output .= $this->codeIndent()."<ul id=\"Xtree".$this->treeCount."\" class=\"Xtree\" style=\"display:none;\">\n"; | ||
96 | } | ||
97 | } | ||
98 | $this->treeCount ++; | ||
99 | foreach($root->items as $myChild){ | ||
100 | $this->imgCount ++; | ||
101 | if($myChild->img){ | ||
102 | if($myChild->alt_img){ | ||
103 | $img_js = "xSwapImg(document.getElementById('Ximg".$this->imgCount."'),'".$myChild->img."','".$myChild->alt_img."');"; | ||
104 | }else{ | ||
105 | $img_js = ""; | ||
106 | } | ||
107 | if (array_search($this->treeCount, $this->visibleNodes) !== false) | ||
108 | { | ||
109 | $img = "<img onClick=\"".$img_js."xMenuShowHide(document.getElementById('Xtree".$this->treeCount."'));\" id=\"Ximg".$this->imgCount."\" src=\"".$myChild->alt_img."\" border=\"0\"> "; | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | $img = "<img onClick=\"".$img_js."xMenuShowHide(document.getElementById('Xtree".$this->treeCount."'));\" id=\"Ximg".$this->imgCount."\" src=\"".$myChild->img."\" border=\"0\"> "; | ||
114 | } | ||
115 | }else{ | ||
116 | $img = "";$img_js = ""; | ||
117 | } | ||
118 | if($myChild->link){ | ||
119 | $href_open = "<a href=\"".$myChild->link."\">"; | ||
120 | $href_close = "</a>"; | ||
121 | }else{ | ||
122 | $href_open = ""; | ||
123 | $href_close = ""; | ||
124 | } | ||
125 | if(count($myChild->items) != 0){ | ||
126 | $this->output .= $this->codeIndent()."<li class=\"Xnode\" id=\"Xnode".$this->treeCount."\"><div>".$href_open.$img.$myChild->name.$href_close."</div></li>\n"; | ||
127 | $this->indent ++; | ||
128 | $this->generateTree($myChild); | ||
129 | }else{ | ||
130 | $this->output .= $this->codeIndent()."<li class=\"Xleaf\"><div onClick=\"".$img_js."\">".$href_open.$img.$myChild->name.$href_close."</div></li>\n"; | ||
131 | } | ||
132 | } | ||
133 | $this->output .= $this->codeIndent()."</ul>\n"; | ||
134 | $this->indent --; | ||
135 | |||
136 | return $this->output; | ||
137 | } | ||
138 | |||
139 | |||
140 | |||
141 | // saveTree and restoreTree - thanks to Niels Fanoe (niels.f@noee.dk) for giving me the idea | ||
142 | |||
143 | // saveTree, save the generated HTML code to a file for future use without generating again | ||
144 | function saveTree($filename = "xMenuCache.html") | ||
145 | { | ||
146 | $file = new File(); | ||
147 | $file->write($this->output,$filename); | ||
148 | $file->printError(); | ||
149 | return $filename; | ||
150 | } | ||
151 | |||
152 | |||
153 | |||
154 | // restoreTree, returns the previously generated HTML code stored in a file | ||
155 | // Call this method STATICALLY for easier use: XMenu::restoreTree("xPandMenuCode.html"); | ||
156 | function restoreTree($filename = "xMenuCache.html") | ||
157 | { | ||
158 | $file = new File(); | ||
159 | $menu = $file->read($filename); | ||
160 | $error = $file->getError(); | ||
161 | if(!empty($error))return false; | ||
162 | elsereturn $menu; | ||
163 | } | ||
164 | |||
165 | |||
166 | |||
167 | // codeIndent, only used to create a nice and readable HTML code (indents the UL and LI tags) | ||
168 | function codeIndent() | ||
169 | { | ||
170 | $str = ""; | ||
171 | for($i=0;$i<$this->indent;$i++){ | ||
172 | $str .= ""; | ||
173 | } | ||
174 | return $str; | ||
175 | } | ||
176 | |||
177 | |||
178 | } | ||
179 | |||
180 | |||
181 | |||
182 | |||
183 | // XNode class: A node item in the menu | ||
184 | class XNode | ||
185 | { | ||
186 | |||
187 | |||
188 | // Name assigned to this node (Text shown on the item) | ||
189 | var $name; | ||
190 | |||
191 | // Link for the item (if any) | ||
192 | var $link; | ||
193 | |||
194 | // Sub-items of this node | ||
195 | var $items = array(); | ||
196 | |||
197 | // Absolute URL of this node's icon | ||
198 | var $img; | ||
199 | |||
200 | // Absolute URL of this node's icon (alternate, used for expanded and collapsed states) | ||
201 | var $alt_img; | ||
202 | |||
203 | |||
204 | |||
205 | // constructor | ||
206 | // $name: text shown for this item | ||
207 | // $link: where does this item links to when clicked (optional) | ||
208 | // $img and $alt_img: images displayed next to this item (absolute paths to images must be used) | ||
209 | function XNode($name,$link = false,$img = LEAF_DEFAULT_IMG,$alt_img = LEAF_DEFAULT_ALT_IMG) | ||
210 | { | ||
211 | $this->name = $name; | ||
212 | $this->link = $link; | ||
213 | $this->img = $img; | ||
214 | $this->alt_img = $alt_img; | ||
215 | } | ||
216 | |||
217 | |||
218 | |||
219 | // addItem, adds a subnode under this node | ||
220 | // Takes a XNode object reference as argument | ||
221 | function &addItem(&$node) | ||
222 | { | ||
223 | if($this->img == LEAF_DEFAULT_IMG){$this->img = NODE_DEFAULT_IMG;} | ||
224 | if($this->alt_img == LEAF_DEFAULT_ALT_IMG){$this->alt_img = NODE_DEFAULT_ALT_IMG;} | ||
225 | $this->items[] = &$node; | ||
226 | return $this->items[count($this->items) - 1]; | ||
227 | } | ||
228 | |||
229 | |||
230 | |||
231 | } | ||
232 | |||
233 | ?> \ No newline at end of file | ||
diff --git a/backend/php/src/test.php b/backend/php/src/test.php new file mode 100644 index 0000000..827ee66 --- a/dev/null +++ b/backend/php/src/test.php | |||
@@ -0,0 +1,15 @@ | |||
1 | <?php | ||
2 | // $Id: index.php,v 1.0 2004/05/11 11:11:11 phppp(D.J.) Exp $ | ||
3 | // Copyright (c) 2004 INFOphp.com // | ||
4 | // ---------------------------------------------------------------- // | ||
5 | // This program is distributed in the hope that it will be useful, // | ||
6 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | ||
7 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | ||
8 | // GNU General Public License for more details. // | ||
9 | // ---------------------------------------------------------------- // | ||
10 | |||
11 | //include "infophp.inc"; | ||
12 | //echo infophp::phpinfo(); | ||
13 | |||
14 | echo phpinfo(); | ||
15 | ?> \ No newline at end of file | ||
diff --git a/backend/python/properties/python.properties.json b/backend/python/properties/python.properties.json new file mode 100644 index 0000000..e69de29 --- a/dev/null +++ b/backend/python/properties/python.properties.json | |||
diff --git a/backend/python/src/app.yaml b/backend/python/src/app.yaml new file mode 100644 index 0000000..5e085a9 --- a/dev/null +++ b/backend/python/src/app.yaml | |||
@@ -0,0 +1,20 @@ | |||
1 | application: clipperz | ||
2 | version: 1 | ||
3 | runtime: python | ||
4 | api_version: 1 | ||
5 | |||
6 | handlers: | ||
7 | - url: /json | ||
8 | script: clipperz.py | ||
9 | |||
10 | - url: /css | ||
11 | static_dir: css | ||
12 | |||
13 | - url: /js | ||
14 | static_dir: js | ||
15 | |||
16 | - url: /images | ||
17 | static_dir: images | ||
18 | |||
19 | - url: /.* | ||
20 | script: clipperz.py | ||
diff --git a/backend/python/src/clipperz.py b/backend/python/src/clipperz.py new file mode 100644 index 0000000..c8d91de --- a/dev/null +++ b/backend/python/src/clipperz.py | |||
@@ -0,0 +1,708 @@ | |||
1 | # | ||
2 | #Copyright 2008-2011 Clipperz Srl | ||
3 | # | ||
4 | #This file is part of Clipperz's Javascript Crypto Library. | ||
5 | #Javascript Crypto Library provides web developers with an extensive | ||
6 | #and efficient set of cryptographic functions. The library aims to | ||
7 | #obtain maximum execution speed while preserving modularity and | ||
8 | #reusability. | ||
9 | #For further information about its features and functionalities please | ||
10 | #refer to http://www.clipperz.com | ||
11 | # | ||
12 | #* Javascript Crypto Library is free software: you can redistribute | ||
13 | # it and/or modify it under the terms of the GNU Affero General Public | ||
14 | # License as published by the Free Software Foundation, either version | ||
15 | # 3 of the License, or (at your option) any later version. | ||
16 | # | ||
17 | #* Javascript Crypto Library is distributed in the hope that it will | ||
18 | # be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
19 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
20 | # See the GNU Affero General Public License for more details. | ||
21 | # | ||
22 | #* You should have received a copy of the GNU Affero General Public | ||
23 | # License along with Javascript Crypto Library. If not, see | ||
24 | # <http://www.gnu.org/licenses/>. | ||
25 | # | ||
26 | |||
27 | import os | ||
28 | import cgi | ||
29 | import wsgiref.handlers | ||
30 | |||
31 | import datetime | ||
32 | import uuid | ||
33 | import random | ||
34 | import hashlib | ||
35 | |||
36 | import logging | ||
37 | |||
38 | from google.appengine.api import users | ||
39 | from google.appengine.ext import webapp | ||
40 | from google.appengine.ext import db | ||
41 | from google.appengine.ext.webapp import template | ||
42 | |||
43 | from django.utils import simplejson | ||
44 | |||
45 | #============================================================================== | ||
46 | |||
47 | sessionTimeout = datetime.timedelta(minutes=-2) | ||
48 | |||
49 | def randomSeed(): | ||
50 | return hex(random.getrandbits(32*8))[2:-1] | ||
51 | |||
52 | def clipperzHash(aString): | ||
53 | #logging.info(">>> string: " + aString) | ||
54 | firstRound = hashlib.sha256() | ||
55 | firstRound.update(aString) | ||
56 | #logging.info("firstRound: " + firstRound.hexdigest() + " - " + firstRound.digest()) | ||
57 | result = hashlib.sha256() | ||
58 | result.update(firstRound.digest()) | ||
59 | #logging.info("<<< finalResul: " + result.hexdigest()) | ||
60 | |||
61 | return result.hexdigest() | ||
62 | |||
63 | #============================================================================== | ||
64 | |||
65 | class User(db.Model): | ||
66 | username= db.StringProperty() | ||
67 | srp_s = db.StringProperty() | ||
68 | srp_v = db.StringProperty() | ||
69 | header = db.TextProperty() | ||
70 | statistics= db.TextProperty() | ||
71 | auth_version= db.StringProperty() | ||
72 | version = db.StringProperty() | ||
73 | lock = db.StringProperty() | ||
74 | |||
75 | def updateCredentials(self, someCredentials): | ||
76 | self.username = someCredentials['C'] | ||
77 | self.srp_s = someCredentials['s'] | ||
78 | self.srp_v = someCredentials['v'] | ||
79 | self.auth_version= someCredentials['version'] | ||
80 | |||
81 | def update(self, someData): | ||
82 | self.header = someData['header'] | ||
83 | self.statistics= someData['statistics'] | ||
84 | self.version= someData['version'] | ||
85 | self.lock = someData['lock'] | ||
86 | |||
87 | #------------------------------------------------------------------------------ | ||
88 | |||
89 | class Record(db.Model): | ||
90 | user = db.ReferenceProperty(User) | ||
91 | reference = db.StringProperty() | ||
92 | data = db.TextProperty() | ||
93 | version = db.StringProperty() | ||
94 | creation_date= db.DateTimeProperty(auto_now_add=True) | ||
95 | update_date = db.DateTimeProperty(auto_now_add=True) | ||
96 | access_date = db.DateTimeProperty(auto_now_add=True) | ||
97 | |||
98 | #------------------------------------------------------------------------------ | ||
99 | |||
100 | class RecordVersion(db.Model): | ||
101 | record = db.ReferenceProperty(Record) | ||
102 | reference = db.StringProperty() | ||
103 | header = db.TextProperty() | ||
104 | data = db.TextProperty() | ||
105 | version = db.StringProperty() | ||
106 | previousVersionKey= db.StringProperty() | ||
107 | previousVersion = db.SelfReferenceProperty() | ||
108 | creation_date = db.DateTimeProperty(auto_now_add=True) | ||
109 | update_date = db.DateTimeProperty(auto_now_add=True) | ||
110 | access_date = db.DateTimeProperty(auto_now_add=True) | ||
111 | |||
112 | def update(self, someData): | ||
113 | recordData = someData['record']; | ||
114 | self.parent().reference =recordData['reference'] | ||
115 | self.parent().data = recordData['data'] | ||
116 | self.parent().version = recordData['version'] | ||
117 | self.parent().update_date =datetime.datetime.now() | ||
118 | |||
119 | recordVersionData = someData['currentRecordVersion']; | ||
120 | self.reference = recordVersionData ['reference'] | ||
121 | self.data = recordVersionData ['data'] | ||
122 | self.version = recordVersionData ['version'] | ||
123 | #self.previous_version =#recordVersionData ['previousVersion'] | ||
124 | self.previous_version_key =recordVersionData ['previousVersionKey'] | ||
125 | self.update_date = datetime.datetime.now() | ||
126 | |||
127 | #------------------------------------------------------------------------------ | ||
128 | |||
129 | class OneTimePassword(db.Model): | ||
130 | user = db.ReferenceProperty(User) | ||
131 | status = db.StringProperty() | ||
132 | reference = db.StringProperty() | ||
133 | keyValue = db.StringProperty() | ||
134 | keyChecksum = db.StringProperty() | ||
135 | data = db.TextProperty() | ||
136 | version = db.StringProperty() | ||
137 | creation_date= db.DateTimeProperty(auto_now_add=True) | ||
138 | request_date= db.DateTimeProperty() | ||
139 | usage_date = db.DateTimeProperty() | ||
140 | |||
141 | def update(self, someParameters, aStatus): | ||
142 | self.reference = someParameters['reference'] | ||
143 | self.keyValue = someParameters['key'] | ||
144 | self.keyChecksum = someParameters['keyChecksum'] | ||
145 | self.data = someParameters['data'] | ||
146 | self.version = someParameters['version'] | ||
147 | self.status = aStatus | ||
148 | |||
149 | def reset(self, aStatus): | ||
150 | self.data = "" | ||
151 | self.status =aStatus | ||
152 | |||
153 | return self | ||
154 | |||
155 | #------------------------------------------------------------------------------ | ||
156 | |||
157 | class Session(db.Expando): | ||
158 | sessionId= db.StringProperty() | ||
159 | access_date= db.DateTimeProperty() | ||
160 | |||
161 | #============================================================================== | ||
162 | |||
163 | class MainPage(webapp.RequestHandler): | ||
164 | def get(self): | ||
165 | path = os.path.join(os.path.dirname(__file__), 'static%s' % self.request.path) | ||
166 | self.response.out.write(template.render(path, {})) | ||
167 | |||
168 | #============================================================================== | ||
169 | |||
170 | class XHR(webapp.RequestHandler): | ||
171 | |||
172 | #========================================================================== | ||
173 | |||
174 | def get(self): | ||
175 | logging.info("self.request.path: " + self.request.path) | ||
176 | if self.request.path == "/dump": | ||
177 | session = self.getSession() | ||
178 | userData = {} | ||
179 | offline_data_placeholder = "" | ||
180 | |||
181 | user = db.Query(User).filter('username =', session.C).get() | ||
182 | |||
183 | userData['users'] = { | ||
184 | 'catchAllUser': { | ||
185 | '__masterkey_test_value__': 'masterkey', | ||
186 | 's': '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00', | ||
187 | 'v': '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00' | ||
188 | } | ||
189 | } | ||
190 | |||
191 | records = {} | ||
192 | for currentRecord in db.Query(Record).ancestor(user): | ||
193 | versions = {} | ||
194 | for currentVersion in db.Query(RecordVersion).ancestor(currentRecord): | ||
195 | versions[currentVersion.reference] ={ | ||
196 | 'header': currentVersion.header, | ||
197 | 'data': currentVersion.data, | ||
198 | 'version': currentVersion.version, | ||
199 | 'creationDate':str(currentVersion.creation_date), | ||
200 | 'updateDate':str(currentVersion.update_date), | ||
201 | 'accessDate':str(currentVersion.access_date) | ||
202 | } | ||
203 | |||
204 | records[currentRecord.reference] = { | ||
205 | 'data': currentRecord.data, | ||
206 | 'version': currentRecord.version, | ||
207 | 'creationDate': str(currentRecord.creation_date), | ||
208 | 'updateDate': str(currentRecord.update_date), | ||
209 | 'accessDate': str(currentRecord.access_date), | ||
210 | 'currentVersion':currentVersion.reference, | ||
211 | 'versions': versions | ||
212 | } | ||
213 | |||
214 | userData['users'][user.username] = { | ||
215 | 's': user.srp_s, | ||
216 | 'v': user.srp_v, | ||
217 | 'version': user.auth_version, | ||
218 | 'maxNumberOfRecords':'100', | ||
219 | 'userDetails': user.header, | ||
220 | 'statistics': user.statistics, | ||
221 | 'userDetailsVersion':user.version, | ||
222 | 'records': records | ||
223 | } | ||
224 | |||
225 | offline_data_placeholder = offline_data_placeholder + "_clipperz_dump_data_ = " + simplejson.dumps(userData, indent=4) + "\n" | ||
226 | offline_data_placeholder = offline_data_placeholder + "Clipperz.PM.Proxy.defaultProxy = new Clipperz.PM.Proxy.Offline();" + "\n" | ||
227 | offline_data_placeholder = offline_data_placeholder + "Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();" + "\n" | ||
228 | |||
229 | path = os.path.join(os.path.dirname(__file__), 'static/dump.html') | ||
230 | |||
231 | self.response.headers.add_header('Content-Type', 'text/html') | ||
232 | self.response.headers.add_header('Content-Disposition', 'attachment', filename='Clipperz.html') | ||
233 | self.response.out.write(template.render(path, {'offline_data_placeholder': offline_data_placeholder})) | ||
234 | |||
235 | #========================================================================== | ||
236 | |||
237 | def post(self): | ||
238 | method = self.request.get('method') | ||
239 | parameters = simplejson.loads(self.request.get('parameters')) | ||
240 | session = self.getSession() | ||
241 | result = {}; | ||
242 | |||
243 | #---------------------------------------------------------------------- | ||
244 | |||
245 | if method == 'registration': | ||
246 | message = parameters['message']; | ||
247 | |||
248 | if message == 'completeRegistration': | ||
249 | user = User() | ||
250 | |||
251 | user.updateCredentials(parameters['credentials']) | ||
252 | user.update(parameters['user']) | ||
253 | user.put() | ||
254 | |||
255 | result['lock'] = user.lock | ||
256 | result['result'] = "done" | ||
257 | |||
258 | #---------------------------------------------------------------------- | ||
259 | |||
260 | elif method == 'handshake': | ||
261 | srp_g = 2L | ||
262 | srp_n = long("0x%s" % "115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3", 16) | ||
263 | |||
264 | message = parameters['message']; | ||
265 | |||
266 | #------------------------------------------------------------------ | ||
267 | |||
268 | if message == 'connect': | ||
269 | session.C = parameters['parameters']['C'] | ||
270 | session.A = parameters['parameters']['A'] | ||
271 | |||
272 | user = db.Query(User).filter('username =', session.C).get() | ||
273 | |||
274 | if user != None: | ||
275 | try: | ||
276 | optId = session.otpId | ||
277 | |||
278 | oneTimePassword = db.Query(OneTimePassword).filter('keyValue =', optId).get() | ||
279 | |||
280 | if oneTimePassword.parent().username != user.username: | ||
281 | oneTimePassword.reset('DISABLED').put() | ||
282 | raise Exception, "User missmatch between the current session and 'One Time Password' user" | ||
283 | elif oneTimePassword.status != 'REQUESTED': | ||
284 | oneTimePassword.reset('DISABLED').put() | ||
285 | raise Exception, "Tring to use an 'One Time Password' in the wrong state" | ||
286 | |||
287 | oneTimePassword.reset("USED").put() | ||
288 | |||
289 | result['oneTimePassword'] = oneTimePassword.reference | ||
290 | |||
291 | except Exception, detail: | ||
292 | logging.error("connect.optId: " + str(detail)) | ||
293 | |||
294 | session.s = user.srp_s | ||
295 | session.v = user.srp_v | ||
296 | else: | ||
297 | session.s = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00" | ||
298 | session.v = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00" | ||
299 | |||
300 | session.b = randomSeed() | ||
301 | session.B = hex(long("0x%s" % session.v, 16) + pow(srp_g, long("0x%s" %session.b, 16), srp_n))[2:-1] | ||
302 | |||
303 | result['s'] = session.s | ||
304 | result['B'] = session.B | ||
305 | |||
306 | #------------------------------------------------------------------ | ||
307 | |||
308 | elif message == 'credentialCheck': | ||
309 | B = long("0x%s" % session.B, 16) | ||
310 | b = long("0x%s" % session.b, 16) | ||
311 | A = long("0x%s" % session.A, 16) | ||
312 | v = long("0x%s" % session.v, 16) | ||
313 | u = long("0x%s" % clipperzHash(str(B)), 16) | ||
314 | n = srp_n | ||
315 | |||
316 | S = pow((A * pow(v, u, n)), b, n) | ||
317 | K = clipperzHash(str(S)) | ||
318 | M1 = clipperzHash(str(A) + str(B) + K) | ||
319 | |||
320 | if M1 == parameters['parameters']['M1']: | ||
321 | session.K = K | ||
322 | M2 = clipperzHash(str(A) + M1 + K) | ||
323 | |||
324 | result['M2'] = M2 | ||
325 | result["connectionId"] = "" | ||
326 | result["loginInfo"] = {} | ||
327 | result["loginInfo"]["latest"] = {} | ||
328 | result["loginInfo"]["current"] = {} | ||
329 | result["offlineCopyNeeded"] = "false"; | ||
330 | result["lock"] = "----"; | ||
331 | else: | ||
332 | result['error'] = "?" | ||
333 | |||
334 | #------------------------------------------------------------------ | ||
335 | |||
336 | elif message == 'oneTimePassword': | ||
337 | oneTimePassword = db.Query(OneTimePassword).filter("keyValue =", parameters["parameters"]["oneTimePasswordKey"]).get() | ||
338 | |||
339 | if oneTimePassword != None: | ||
340 | if oneTimePassword.status == 'ACTIVE': | ||
341 | if oneTimePassword.keyChecksum == parameters['parameters']['oneTimePasswordKeyChecksum']: | ||
342 | #session.userId =str(oneTimePassword.parent().username) | ||
343 | session.otpId = str(oneTimePassword.keyValue) | ||
344 | |||
345 | result['data'] = oneTimePassword.data | ||
346 | result['version'] = oneTimePassword.version | ||
347 | |||
348 | oneTimePassword.reset('REQUESTED').put() | ||
349 | |||
350 | else: | ||
351 | oneTimePassword.reset('DISABLED').put() | ||
352 | raise Exception, "The requested One Time Password has been disabled, due to a wrong keyChecksum" | ||
353 | else: | ||
354 | raise Exception, "The requested One Time Password was not active" | ||
355 | else: | ||
356 | raise Exception, "The requested One Time Password has not been found" | ||
357 | |||
358 | #---------------------------------------------------------------------- | ||
359 | |||
360 | elif method == 'message': | ||
361 | if parameters['srpSharedSecret'] == session.K: | ||
362 | message = parameters['message'] | ||
363 | |||
364 | if message == 'getUserDetails': | ||
365 | #{"message":"getUserDetails", "srpSharedSecret":"f18e5cf7c3a83b67d4db9444af813ee48c13daf4f8f6635397d593e52ba89a08", "parameters":{}} | ||
366 | user = db.Query(User).filter('username =', session.C).get() | ||
367 | |||
368 | result['header'] = user.header; | ||
369 | result['statistics'] =user.statistics; | ||
370 | result['version'] = user.version; | ||
371 | |||
372 | elif message == "addNewRecords": | ||
373 | user = db.Query(User).filter('username =', session.C).get() | ||
374 | result = db.run_in_transaction(self.addNewRecords, session, user, parameters) | ||
375 | |||
376 | """ | ||
377 | user = db.Query(User).filter('username =', session.C).get() | ||
378 | user.update(parameters['parameters']['user']) | ||
379 | |||
380 | for recordParameter in parameters['parameters']['records']: | ||
381 | record = Record(parent=user) | ||
382 | record.put() | ||
383 | recordVersion = RecordVersion(parent=record) | ||
384 | recordVersion.put() | ||
385 | |||
386 | recordVersion.update(recordParameter) | ||
387 | |||
388 | record.put() | ||
389 | recordVersion.put() | ||
390 | |||
391 | user.put(); | ||
392 | |||
393 | result['lock'] = user.lock | ||
394 | result['result'] = 'done' | ||
395 | """ | ||
396 | |||
397 | elif message == 'getRecordDetail': | ||
398 | record = db.Query(Record).ancestor(db.Query(User).filter('username =', session.C).get()).filter('reference =', parameters["parameters"]["reference"]).get() | ||
399 | recordVersion = db.Query(RecordVersion).ancestor(record).get() | ||
400 | |||
401 | result['currentVersion'] = {} | ||
402 | result['currentVersion']['reference'] = recordVersion.reference | ||
403 | result['currentVersion']['data'] = recordVersion.data | ||
404 | result['currentVersion']['header'] = recordVersion.header | ||
405 | result['currentVersion']['version'] = recordVersion.version | ||
406 | result['currentVersion']['creationDate'] =str(recordVersion.creation_date) | ||
407 | result['currentVersion']['updateDate'] =str(recordVersion.update_date) | ||
408 | result['currentVersion']['accessDate'] =str(recordVersion.access_date) | ||
409 | |||
410 | result['reference'] = record.reference | ||
411 | result['data'] = record.data | ||
412 | result['version'] = record.version | ||
413 | result['creationDate'] = str(record.creation_date) | ||
414 | result['updateDate'] = str(record.update_date) | ||
415 | result['accessDate'] = str(record.access_date) | ||
416 | result['oldestUsedEncryptedVersion'] = "---" | ||
417 | |||
418 | elif message == 'updateData': | ||
419 | user = db.Query(User).filter('username =', session.C).get() | ||
420 | user.update(parameters['parameters']['user']) | ||
421 | |||
422 | for recordParameter in parameters['parameters']['records']: | ||
423 | logging.info('reference =' + recordParameter['record']['reference']) | ||
424 | record = db.Query(Record).ancestor(user).filter('reference =', recordParameter['record']['reference']).get() | ||
425 | recordVersion = db.Query(RecordVersion).ancestor(record).get() | ||
426 | |||
427 | recordVersion.update(recordParameter) | ||
428 | |||
429 | recordVersion.put() | ||
430 | recordVersion.parent().put() | ||
431 | |||
432 | user.put(); | ||
433 | |||
434 | result['lock'] = user.lock | ||
435 | result['result'] = 'done' | ||
436 | |||
437 | elif message == 'deleteRecords': | ||
438 | user = db.Query(User).filter('username =', session.C).get() | ||
439 | user.update(parameters['parameters']['user']) | ||
440 | |||
441 | for recordReference in parameters['parameters']['recordReferences']: | ||
442 | record = db.Query(Record).ancestor(user).filter('reference =', recordReference).get() | ||
443 | #recordVersion = db.Query(RecordVersion).ancestor(record).get() | ||
444 | |||
445 | db.delete(db.Query(RecordVersion).ancestor(record)) | ||
446 | record.delete() | ||
447 | |||
448 | user.put() | ||
449 | |||
450 | result['lock'] = user.lock | ||
451 | result['result'] = 'done' | ||
452 | |||
453 | elif message == 'deleteUser': | ||
454 | user = db.Query(User).filter('username =', session.C).get() | ||
455 | db.delete(db.Query(RecordVersion).ancestor(user)) | ||
456 | db.delete(db.Query(Record).ancestor(user)) | ||
457 | user.delete() | ||
458 | |||
459 | elif message == 'addNewOneTimePassword': | ||
460 | user = db.Query(User).filter('username =', session.C).get() | ||
461 | user.update(parameters['parameters']['user']) | ||
462 | |||
463 | oneTimePassword = OneTimePassword(parent=user) | ||
464 | oneTimePassword.update(parameters['parameters']['oneTimePassword'], "ACTIVE") | ||
465 | oneTimePassword.put() | ||
466 | |||
467 | user.put() | ||
468 | |||
469 | result['lock'] = user.lock | ||
470 | result['result'] = 'done' | ||
471 | |||
472 | elif message == 'updateOneTimePasswords': | ||
473 | user = db.Query(User).filter('username =', session.C).get() | ||
474 | user.update(parameters['parameters']['user']) | ||
475 | |||
476 | validOtpReferences = parameters['parameters']['oneTimePasswords'] | ||
477 | for currentOtp in db.Query(OneTimePassword).ancestor(user): | ||
478 | if currentOtp.reference in validOtpReferences: | ||
479 | pass | ||
480 | else: | ||
481 | currentOtp.delete() | ||
482 | |||
483 | user.put() | ||
484 | |||
485 | result['result'] = user.lock | ||
486 | |||
487 | elif message == 'getOneTimePasswordsDetails': | ||
488 | pass | ||
489 | |||
490 | elif message == 'getLoginHistory': | ||
491 | result["result"] = [] | ||
492 | |||
493 | elif message == 'upgradeUserCredentials': | ||
494 | user = db.Query(User).filter('username =', session.C).get() | ||
495 | |||
496 | user.updateCredentials(parameters['parameters']['credentials']) | ||
497 | user.update(parameters['parameters']['user']) | ||
498 | |||
499 | for oneTimePasswordReference in parameters['parameters']['oneTimePasswords']: | ||
500 | oneTimePassword = db.Query(OneTimePassword).ancestor(user).filter("reference =", oneTimePasswordReference).get() | ||
501 | |||
502 | if oneTimePassword != None: | ||
503 | oneTimePassword.data = parameters['parameters']['oneTimePasswords'][oneTimePasswordReference] | ||
504 | oneTimePassword.put() | ||
505 | |||
506 | user.put() | ||
507 | |||
508 | result['lock'] = user.lock | ||
509 | result['result'] = 'done' | ||
510 | |||
511 | """ | ||
512 | $user = new user(); | ||
513 | $user->Get($_SESSION["userId"]); | ||
514 | |||
515 | $otp = new onetimepassword(); | ||
516 | |||
517 | updateUserCredentials($parameters["parameters"]["credentials"], $user); | ||
518 | updateUserData($parameters["parameters"]["user"], $user); | ||
519 | |||
520 | $otpList = $parameters["parameters"]["oneTimePasswords"]; | ||
521 | foreach($otpList as $otpReference=>$otpData) { | ||
522 | $otpList = $otp->GetList(array(array("reference", "=", $otpReference))); | ||
523 | $currentOtp = $otpList[0]; | ||
524 | $currentOtp->data = $otpData; | ||
525 | $currentOtp->Save(); | ||
526 | } | ||
527 | |||
528 | $user->Save(); | ||
529 | |||
530 | $result["lock"] = $user->lock; | ||
531 | $result["result"] = "done"; | ||
532 | """ | ||
533 | |||
534 | #============================================================= | ||
535 | |||
536 | """ | ||
537 | java.util.Mapresult; | ||
538 | |||
539 | try { | ||
540 | java.util.Mapcredentials; | ||
541 | |||
542 | if (someParameters.get("credentials") != null) { | ||
543 | credentials = (java.util.Map)someParameters.get("credentials"); | ||
544 | } else { | ||
545 | credentials = someParameters; | ||
546 | } | ||
547 | |||
548 | aUser.setUsername((java.lang.String)credentials.get("C")); | ||
549 | aUser.setSrpS((java.lang.String)credentials.get("s")); | ||
550 | aUser.setSrpV((java.lang.String)credentials.get("v")); | ||
551 | aUser.setVersion((java.lang.String)credentials.get("version")); | ||
552 | |||
553 | if (someParameters.get("user") != null) { | ||
554 | com.clipperz.dataModel.EncoderHelper.updateWithMap(aUser, (java.util.Map)someParameters.get("user")); | ||
555 | } | ||
556 | |||
557 | if (someParameters.get("oneTimePasswords") != null) { | ||
558 | java.util.MapupdatedOneTimePasswords; | ||
559 | java.util.ListusersOneTimePasswords; | ||
560 | int i,c; | ||
561 | |||
562 | updatedOneTimePasswords = (java.util.Map)someParameters.get("oneTimePasswords"); | ||
563 | usersOneTimePasswords = com.clipperz.dataModel.OneTimePassword.oneTimePasswordsForUser(this.user()); | ||
564 | c = usersOneTimePasswords.size(); | ||
565 | for (i=0; i<c; i++) { | ||
566 | com.clipperz.dataModel.OneTimePasswordcurrentOneTimePassword; | ||
567 | |||
568 | currentOneTimePassword = (com.clipperz.dataModel.OneTimePassword)usersOneTimePasswords.get(i); | ||
569 | |||
570 | if (updatedOneTimePasswords.get(currentOneTimePassword.getReference()) != null) { | ||
571 | currentOneTimePassword.setData((java.lang.String)updatedOneTimePasswords.get(currentOneTimePassword.getReference())); | ||
572 | } | ||
573 | } | ||
574 | } | ||
575 | |||
576 | result = new java.util.Hashtable(); | ||
577 | this.dataContext().commitChanges(); | ||
578 | result.put("lock", this.user().getNewLock()); | ||
579 | result.put("result", "done"); | ||
580 | } catch(java.lang.Exception exception) { | ||
581 | this.dataContext().rollbackChanges(); | ||
582 | logger.error(exception); | ||
583 | throw exception; | ||
584 | } | ||
585 | |||
586 | return result; | ||
587 | """ | ||
588 | |||
589 | elif message == 'echo': | ||
590 | result['result'] = parameters; | ||
591 | |||
592 | else: | ||
593 | result['error'] = "Wrong shared secret!" | ||
594 | |||
595 | #---------------------------------------------------------------------- | ||
596 | |||
597 | elif method == 'logout': | ||
598 | result['method'] = 'logout' | ||
599 | |||
600 | #---------------------------------------------------------------------- | ||
601 | |||
602 | else: | ||
603 | result['method'] = 'PRRRRRR' | ||
604 | |||
605 | #---------------------------------------------------------------------- | ||
606 | |||
607 | self.saveSession(session) | ||
608 | self.response.out.write(simplejson.dumps(result)) | ||
609 | |||
610 | #========================================================================== | ||
611 | |||
612 | def addNewRecords (self, aSession, aUser, someParameters): | ||
613 | result = {} | ||
614 | |||
615 | #user = db.Query(User).filter('username =', aSession.C).get() | ||
616 | aUser.update(someParameters['parameters']['user']) | ||
617 | |||
618 | for recordParameter in someParameters['parameters']['records']: | ||
619 | record = Record(parent=aUser) | ||
620 | record.put() | ||
621 | recordVersion = RecordVersion(parent=record) | ||
622 | recordVersion.put() | ||
623 | |||
624 | recordVersion.update(recordParameter) | ||
625 | |||
626 | record.put() | ||
627 | recordVersion.put() | ||
628 | |||
629 | aUser.put(); | ||
630 | |||
631 | result['lock'] = aUser.lock | ||
632 | result['result'] = 'done' | ||
633 | |||
634 | return result | ||
635 | |||
636 | #========================================================================== | ||
637 | |||
638 | def getSession(self): | ||
639 | #logging.info(">>> getSession (%d) => %s" % (db.Query(Session).count(), str(map(lambda v: v.sessionId, db.Query(Session).fetch(100)))) ) | ||
640 | result = None | ||
641 | try: | ||
642 | sessionId = self.request.cookies['sessionId'] | ||
643 | except: | ||
644 | sessionId = None | ||
645 | |||
646 | #logging.info("wannabe sessionId: " + str(sessionId)) | ||
647 | |||
648 | if sessionId != None: | ||
649 | #query = db.Query(Session) | ||
650 | #query.filter('sessionId =', sessionId) | ||
651 | |||
652 | #result = query.get() | ||
653 | |||
654 | #result = db.Query(Session).filter('sessionId =', str(sessionId)).filter('access_date >', (datetime.datetime.utcnow() - sessionTimeout)).get() | ||
655 | result = db.Query(Session).filter('sessionId =', str(sessionId)).get() | ||
656 | #logging.info("searching session on datastore. Found: " + str(result)) | ||
657 | |||
658 | if result == None: | ||
659 | sessionId = str(uuid.uuid4()) | ||
660 | #logging.info("creating a new session with sessionId=" + str(sessionId)) | ||
661 | result = Session(sessionId=sessionId) | ||
662 | |||
663 | result.access_date = datetime.datetime.utcnow() | ||
664 | result.put() | ||
665 | |||
666 | #logging.info("<<< getSession (%d)" % db.Query(Session).count()) | ||
667 | |||
668 | return result | ||
669 | |||
670 | #========================================================================== | ||
671 | |||
672 | def saveSession(self, aSession): | ||
673 | #logging.info(">>> saveSession (%d)" % db.Query(Session).count()) | ||
674 | #self.response.set_cookie('sessionId', aSession.sessionId, max_age=360, path='/', domain='example.org', secure=True) | ||
675 | aSession.put() | ||
676 | self.response.headers.add_header('Set-Cookie', 'sessionId=' + str(aSession.sessionId), path='/') | ||
677 | self.cleanOldSessions() | ||
678 | #logging.info("<<< saveSession (%d)" % db.Query(Session).count()) | ||
679 | |||
680 | #========================================================================== | ||
681 | |||
682 | def cleanOldSessions(self): | ||
683 | query = db.Query(Session).filter('accessDate <', (datetime.datetime.utcnow() - sessionTimeout)) | ||
684 | |||
685 | expiredSessions = query.count(); | ||
686 | if expiredSessions != 0: | ||
687 | #logging.info("deleting %d sessions" % expiredSessions) | ||
688 | pass | ||
689 | |||
690 | """ | ||
691 | try: | ||
692 | db.delete(query) | ||
693 | except Exception, exception: | ||
694 | logging.error("some issues raised while deleting the expired sessions") | ||
695 | logging.error("exception type: " + str(type(exception))) | ||
696 | logging.error("exception: " + str(exception)) | ||
697 | """ | ||
698 | pass | ||
699 | |||
700 | #============================================================================== | ||
701 | |||
702 | def main(): | ||
703 | application = webapp.WSGIApplication([('/xhr', XHR), ('/dump', XHR), ('/.*', MainPage)], debug=True) | ||
704 | wsgiref.handlers.CGIHandler().run(application) | ||
705 | |||
706 | if __name__ == "__main__": | ||
707 | main() | ||
708 | |||