62 files changed, 4581 insertions, 0 deletions
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 | ||