1 |
<?php |
<?php |
2 |
/********************************************************** |
/********************************************************** |
3 |
Function Library: scribe_fix.php |
Function Library: scribe_fix.php |
4 |
Original Author: Paul Bramscher <brams006@tc.umn.edu> |
Original Author: Paul Bramscher <brams006@umn.edu> |
5 |
Last Modified: 10.29.2003 |
Last Modified: 03.16.2004 |
6 |
*********************************************************** |
*********************************************************** |
7 |
Comments: |
Comments: |
8 |
This library brings together CourseLib/PageScribe page |
This library brings together CourseLib/PageScribe page |
9 |
debugging and fixing algorithms. |
debugging and fixing algorithms. |
10 |
*********************************************************** |
*********************************************************** |
11 |
|
Table of Contents: |
12 |
errorTrap |
errorTrap |
13 |
genCalc |
genCalc |
14 |
isOrphan |
isOrphan |
23 |
/********************************************************** |
/********************************************************** |
24 |
Function: errorTrap |
Function: errorTrap |
25 |
Author: Paul Bramscher |
Author: Paul Bramscher |
26 |
Last Modified: 10.28.2003 |
Last Modified: 03.04.2004 |
27 |
*********************************************************** |
*********************************************************** |
28 |
Purpose: |
Purpose: |
29 |
Debugger available for CLPS system, to check for various |
Debugger available for CLPS system, to check for various |
32 |
scribe.phtml automatically. Otherwise, it's called |
scribe.phtml automatically. Otherwise, it's called |
33 |
manually from the DBA console. |
manually from the DBA console. |
34 |
**********************************************************/ |
**********************************************************/ |
35 |
function errorTrap($con, $page_id){ |
function errorTrap($page_id){ |
36 |
|
|
37 |
// Fetch title |
// Fetch title |
38 |
$page_title = lookupField($con, "page", "page_id", $page_id, "page_title"); |
$page_title = lookupField("page", "page_id", $page_id, "page_title"); |
39 |
|
|
40 |
// Overall status |
// Overall status |
41 |
$passed = 1; |
$passed = 1; |
42 |
|
|
43 |
printf("<center>\n"); |
printf("<center>\n"); |
44 |
printf("<table width=\"90%%\" class=\"backLight\" border=\"1\">\n"); |
printf("<table width=\"90%%\" class=\"backLight\" border=\"1\">\n"); |
45 |
printf("<tr><td class=\"cellPlain\">Debug Data: %s (#%d)</td></tr>\n", $page_title, $page_id); |
printf("<tr><td class=\"cellPlain\">Debug Data: %s (ID# %d)</td></tr>\n", $page_title, $page_id); |
46 |
printf("<tr><td><br>\n"); |
printf("<tr><td><br>\n"); |
47 |
|
|
48 |
/*********************** |
/*********************** |
49 |
** Basic Element Data ** |
** Basic Element Data ** |
50 |
***********************/ |
***********************/ |
51 |
|
|
52 |
printf("<b>Element Data:</b><br>"); |
printf("<b>Element Data:</b><br>\n"); |
53 |
|
|
54 |
// Distinct orders |
// Distinct orders |
55 |
$sql = "SELECT DISTINCT element_order FROM element WHERE page_id =" |
$sql = "SELECT DISTINCT element_order FROM element WHERE page_id =" |
56 |
. $page_id; |
. $page_id; |
57 |
$rs = mysql_query($sql, $con); |
$rs = mysql_tryquery($sql); |
58 |
$num_orders = mysql_num_rows($rs); |
$num_orders = mysql_num_rows($rs); |
59 |
printf("Unique orders: %d<br>\n", $num_orders); |
printf("Unique orders: %d<br>\n", $num_orders); |
60 |
|
|
61 |
// Number of rows (should be the same) |
// Number of rows (should be the same) |
62 |
$sql = "SELECT element_id FROM element WHERE page_id = " |
$sql = "SELECT element_id FROM element WHERE page_id = " |
63 |
. $page_id; |
. $page_id; |
64 |
$rs = mysql_query($sql, $con); |
$rs = mysql_tryquery($sql); |
65 |
$num_rows = mysql_num_rows($rs); |
$num_rows = mysql_num_rows($rs); |
66 |
printf("Number of rows: %d<BR>\n", $num_rows); |
printf("Number of rows: %d<BR>\n", $num_rows); |
67 |
|
|
68 |
// Smallest order (if rows present, should be 1) |
// Smallest order (if rows present, should be 1) |
69 |
$sql = "SELECT MIN(element_order) as min_order FROM element WHERE page_id = " |
$sql = "SELECT MIN(element_order) as min_order FROM element WHERE page_id = " |
70 |
. $page_id; |
. $page_id; |
71 |
$rs = mysql_query($sql, $con); |
$rs = mysql_tryquery($sql); |
72 |
$row = mysql_fetch_array ($rs); |
$row = mysql_fetch_array ($rs, MYSQL_ASSOC); |
73 |
$min_order = $row["min_order"]; |
$min_order = $row["min_order"]; |
74 |
printf("First order: %d<br>\n", $min_order); |
printf("First order: %d<br>\n", $min_order); |
75 |
|
|
76 |
// Largest order (should equal distinct rows and number of rows |
// Largest order (should equal distinct rows and number of rows |
77 |
$sql = "SELECT MAX(element_order) as max_order FROM element WHERE page_id = " |
$sql = "SELECT MAX(element_order) as max_order FROM element WHERE page_id = " |
78 |
. $page_id; |
. $page_id; |
79 |
$rs = mysql_query($sql, $con); |
$rs = mysql_tryquery($sql); |
80 |
$row = mysql_fetch_array ($rs); |
$row = mysql_fetch_array ($rs, MYSQL_ASSOC); |
81 |
$max_order = $row["max_order"]; |
$max_order = $row["max_order"]; |
82 |
printf("Last order: %d<br><br>\n", $max_order); |
printf("Last order: %d<br><br>\n", $max_order); |
83 |
|
|
89 |
$c1_sql = "SELECT element_id, parent_id, element_order, indent_level FROM element WHERE page_id = " |
$c1_sql = "SELECT element_id, parent_id, element_order, indent_level FROM element WHERE page_id = " |
90 |
. $page_id |
. $page_id |
91 |
. " AND parent_id > 0 ORDER BY element_order"; |
. " AND parent_id > 0 ORDER BY element_order"; |
92 |
$c1_rs = mysql_query($c1_sql, $con); |
$c1_rs = mysql_tryquery($c1_sql); |
93 |
|
|
94 |
while ($c1_row = mysql_fetch_array ($c1_rs)) { |
while ($c1_row = mysql_fetch_array ($c1_rs, MYSQL_ASSOC)) { |
95 |
$parent_id = $c1_row["parent_id"]; |
$parent_id = $c1_row["parent_id"]; |
96 |
$indent_level = $c1_row["indent_level"]; |
$indent_level = $c1_row["indent_level"]; |
97 |
$element_id = $c1_row["element_id"]; |
$element_id = $c1_row["element_id"]; |
100 |
// For each row returned, hunt for the parent |
// For each row returned, hunt for the parent |
101 |
$c2_sql ="SELECT element_id, element_order, indent_level FROM element WHERE element_id = " |
$c2_sql ="SELECT element_id, element_order, indent_level FROM element WHERE element_id = " |
102 |
. $parent_id; |
. $parent_id; |
103 |
$c2_rs = mysql_query($c2_sql, $con); |
$c2_rs = mysql_tryquery($c2_sql); |
104 |
$c2_row = mysql_fetch_array ($c2_rs); |
$c2_row = mysql_fetch_array ($c2_rs, MYSQL_ASSOC); |
105 |
$c2_indent_level = $c2_row["indent_level"]; |
$c2_indent_level = $c2_row["indent_level"]; |
106 |
$c2_element_id = $c2_row["element_id"]; |
$c2_element_id = $c2_row["element_id"]; |
107 |
$c2_element_order = $c2_row["element_order"]; |
$c2_element_order = $c2_row["element_order"]; |
173 |
. $page_id |
. $page_id |
174 |
. " ORDER BY element_order"; |
. " ORDER BY element_order"; |
175 |
|
|
176 |
$rs = mysql_query($sql, $con); |
$rs = mysql_tryquery($sql); |
177 |
|
|
178 |
while ($row = mysql_fetch_array ($rs)) { |
while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { |
179 |
$element_id = $row["element_id"]; |
$element_id = $row["element_id"]; |
180 |
$indent_level = $row["indent_level"]; |
$indent_level = $row["indent_level"]; |
181 |
$parent_id = $row["parent_id"]; |
$parent_id = $row["parent_id"]; |
182 |
$gen_level = 0; |
$gen_level = 0; |
183 |
|
|
184 |
// Call the generational calculator for each element |
// Call the generational calculator for each element |
185 |
$gen_level = genCalc($con, $element_id, $gen_level, $page_id, $parent_id); |
$gen_level = genCalc($element_id, $gen_level, $page_id, $parent_id); |
186 |
|
|
187 |
if ($gen_level != $indent_level) { |
if ($gen_level != $indent_level) { |
188 |
printf("Failed. Element ID#%d reported generation of %d, but calculated at %d.<BR>\n", $element_id, $indent_level, $gen_level); |
printf("Failed. Element ID#%d reported generation of %d, but calculated at %d.<BR>\n", $element_id, $indent_level, $gen_level); |
215 |
/********************************************************** |
/********************************************************** |
216 |
Function: genCalc |
Function: genCalc |
217 |
Author: Paul Bramscher |
Author: Paul Bramscher |
218 |
Last Modified: 10.27.2003 |
Last Modified: 03.04.2004 |
219 |
*********************************************************** |
*********************************************************** |
220 |
Purpose: |
Purpose: |
221 |
Recursively calculate the traversable generational level of |
Recursively calculate the traversable generational level of |
224 |
will update the indent_level value in the elements table |
will update the indent_level value in the elements table |
225 |
with the calculated value determined here. |
with the calculated value determined here. |
226 |
**********************************************************/ |
**********************************************************/ |
227 |
function genCalc($con, $element_id, $gen_level, $page_id, $parent_id) { |
function genCalc($element_id, $gen_level, $page_id, $parent_id) { |
228 |
|
|
229 |
// If there is a parent to probe |
// If there is a parent to probe |
230 |
if ($parent_id > 0) { |
if ($parent_id > 0) { |
237 |
. " AND page_id = " |
. " AND page_id = " |
238 |
. $page_id; |
. $page_id; |
239 |
|
|
240 |
$rs = mysql_query($sql, $con); |
$rs = mysql_tryquery($sql); |
241 |
$row = mysql_fetch_array ($rs); |
$row = mysql_fetch_array ($rs, MYSQL_ASSOC); |
242 |
$probe_parent_id = $row["parent_id"]; |
$probe_parent_id = $row["parent_id"]; |
243 |
$probe_element_id = $row["parent_id"]; |
$probe_element_id = $row["parent_id"]; |
244 |
|
|
245 |
// See if the probed element has any parents to probe further |
// See if the probed element has any parents to probe further |
246 |
if ($probe_element_id > 0) { |
if ($probe_element_id > 0) { |
247 |
return 1 + genCalc($con, $probe_element_id, $gen_level, $page_id, $probe_parent_id); |
return 1 + genCalc($probe_element_id, $gen_level, $page_id, $probe_parent_id); |
248 |
|
|
249 |
} |
} |
250 |
|
|
261 |
/********************************************************** |
/********************************************************** |
262 |
Function: isOrphan |
Function: isOrphan |
263 |
Author: Paul Bramscher |
Author: Paul Bramscher |
264 |
Last Modified: 08.27.2003 |
Last Modified: 03.04.2004 |
265 |
*********************************************************** |
*********************************************************** |
266 |
Purpose: |
Purpose: |
267 |
Determines if the supplied PageScribe/CourseLib element is |
Determines if the supplied PageScribe/CourseLib element is |
271 |
fails, the element is said to be orphaned, a bastard or |
fails, the element is said to be orphaned, a bastard or |
272 |
otherwise of problematic ancestry. |
otherwise of problematic ancestry. |
273 |
**********************************************************/ |
**********************************************************/ |
274 |
function isOrphan($con, $element_id, $element_order, $page_id, $parent_id) { |
function isOrphan($element_id, $element_order, $page_id, $parent_id) { |
275 |
|
|
276 |
//Initialize |
//Initialize |
277 |
$orphan = 0; |
$orphan = 0; |
291 |
// testing |
// testing |
292 |
// printf("orphan probe sql was: %s ", $sql); |
// printf("orphan probe sql was: %s ", $sql); |
293 |
|
|
294 |
$rs = mysql_query($sql, $con); |
$rs = mysql_tryquery($sql); |
295 |
$row = mysql_fetch_array ($rs); |
$row = mysql_fetch_array ($rs, MYSQL_ASSOC); |
296 |
$par_found = $row["par_found"]; |
$par_found = $row["par_found"]; |
297 |
|
|
298 |
// Should have only one match. If none (or multiple) set to 0. |
// Should have only one match. If none (or multiple) set to 0. |
300 |
else $orphan = 1; |
else $orphan = 1; |
301 |
|
|
302 |
// Output |
// Output |
303 |
if ($orphan == 1) printf("Found orphan: ID#%d.<br>", $element_id); |
if ($orphan == 1) printf("Found orphan: ID#%d.<br>\n", $element_id); |
304 |
|
|
305 |
} |
} |
306 |
|
|
311 |
/********************************************************** |
/********************************************************** |
312 |
Function: purgeOrphans |
Function: purgeOrphans |
313 |
Author: Paul Bramscher |
Author: Paul Bramscher |
314 |
Last Modified: 10.28.2003 |
Last Modified: 03.04.2004 |
315 |
*********************************************************** |
*********************************************************** |
316 |
Purpose: |
Purpose: |
317 |
Purges and orphans found on the page. |
Purges and orphans found on the page. |
318 |
**********************************************************/ |
**********************************************************/ |
319 |
|
function purgeOrphans($page_id) { |
|
function purgeOrphans($con, $page_id) { |
|
320 |
|
|
321 |
printf("<b>Method #2 Delete fostered children and their descendants</b><br><br>\n"); |
printf("<b>Method #2 Delete fostered children and their descendants</b><br><br>\n"); |
322 |
printf("<b>Messages:</b><br>\n"); |
printf("<b>Messages:</b><br>\n"); |
331 |
. $page_id |
. $page_id |
332 |
. " ORDER BY element_order"; |
. " ORDER BY element_order"; |
333 |
|
|
334 |
$rs = mysql_query($sql, $con); |
$rs = mysql_tryquery($sql); |
335 |
|
|
336 |
while ($row = mysql_fetch_array ($rs)) { |
while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { |
337 |
$element_id = $row["element_id"]; |
$element_id = $row["element_id"]; |
338 |
$element_order = $row["element_order"]; |
$element_order = $row["element_order"]; |
339 |
$parent_id = $row["parent_id"]; |
$parent_id = $row["parent_id"]; |
341 |
/* If an orphan, delete it and its first generation. |
/* If an orphan, delete it and its first generation. |
342 |
Recall some Egyptian/Biblical curse here.*/ |
Recall some Egyptian/Biblical curse here.*/ |
343 |
|
|
344 |
if ($parent_id > 0 && isOrphan($con, $element_id, $element_order, $page_id, $parent_id)) { |
if ($parent_id > 0 && isOrphan($element_id, $element_order, $page_id, $parent_id)) { |
345 |
|
|
346 |
$sub_sql = "DELETE FROM element |
$sub_sql = "DELETE FROM element |
347 |
WHERE page_id = " |
WHERE page_id = " |
350 |
. $element_id |
. $element_id |
351 |
. " AND parent_id = " |
. " AND parent_id = " |
352 |
. $parent_id; |
. $parent_id; |
353 |
|
if (mysql_tryquery ($sub_sql)) printf("Element %d was an orphan. Deleted it.<br>\n", $element_id); |
|
// printf("delete sql wasd: %s<BR>", $sql); |
|
|
|
|
|
if (!mysql_query ($sub_sql, $con)){ |
|
|
sql_err($sub_sql); |
|
|
mysql_query ("UNLOCK TABLES", $con); |
|
|
bailout(); |
|
|
} |
|
|
else { |
|
|
|
|
|
// Output |
|
|
printf("Element %d was an orphan. Deleted it.<br>\n", $element_id); |
|
|
|
|
|
mysql_query ("UNLOCK TABLES", $con); |
|
|
} // deleted this element |
|
354 |
|
|
355 |
} // delete all elements which are orphaned |
} // delete all elements which are orphaned |
356 |
|
|
362 |
/********************************************************** |
/********************************************************** |
363 |
Function: purgeRelationships |
Function: purgeRelationships |
364 |
Author: Paul Bramscher |
Author: Paul Bramscher |
365 |
Last Modified: 10.28.2003 |
Last Modified: 03.04.2004 |
366 |
*********************************************************** |
*********************************************************** |
367 |
Purpose: |
Purpose: |
368 |
Purges all parent-child relationships on the page, and |
Purges all parent-child relationships on the page, and |
370 |
destructive, but virtually guaranteed to fix a page. |
destructive, but virtually guaranteed to fix a page. |
371 |
**********************************************************/ |
**********************************************************/ |
372 |
|
|
373 |
function purgeRelationships($con, $page_id) { |
function purgeRelationships($page_id) { |
374 |
|
|
375 |
printf("<b>Method #3 Purge all parent-child relationships!</b><br><br>\n"); |
printf("<b>Method #3 Purge all parent-child relationships!</b><br><br>\n"); |
376 |
printf("<b>Messages:</b><br>\n"); |
printf("<b>Messages:</b><br>\n"); |
379 |
SET parent_id = 0, indent_level = 0 |
SET parent_id = 0, indent_level = 0 |
380 |
WHERE page_id = " |
WHERE page_id = " |
381 |
. $page_id; |
. $page_id; |
382 |
|
if (mysql_tryquery ($sql)) printf("Purged all!<br>\n"); |
|
if (!mysql_query ($sql, $con)){ |
|
|
sql_err($sql); |
|
|
mysql_query ("UNLOCK TABLES", $con); |
|
|
bailout(); |
|
|
} |
|
|
else { |
|
|
|
|
|
printf("Purged all!<br>\n"); |
|
|
mysql_query ("UNLOCK TABLES", $con); |
|
|
} // purged all! |
|
|
|
|
383 |
|
|
384 |
} // end purgeRelationships |
} // end purgeRelationships |
385 |
|
|
403 |
(b) Fill in any "holes" in the element order. |
(b) Fill in any "holes" in the element order. |
404 |
(c) Clean up all indent levels. |
(c) Clean up all indent levels. |
405 |
**********************************************************/ |
**********************************************************/ |
406 |
function scribeFix($con, $method, $page_id){ |
function scribeFix($method, $page_id){ |
407 |
|
|
408 |
printf("<center>\n"); |
printf("<center>\n"); |
409 |
printf("<table width=\"90%%\" class=\"backLight\" border=\"1\">\n"); |
printf("<table width=\"90%%\" class=\"backLight\" border=\"1\">\n"); |
410 |
printf("<tr><td class=\"cellPlain\">Page Fix Dialog (#%d)</td></tr>\n", $page_id); |
printf("<tr><td class=\"cellPlain\">Page Fix Dialog (ID# %d)</td></tr>\n", $page_id); |
411 |
printf("<tr><td><br>\n"); |
printf("<tr><td><br>\n"); |
412 |
|
|
413 |
switch ($method) { |
switch ($method) { |
414 |
|
|
415 |
// Update orphans |
// Update orphans |
416 |
case 1: updateOrphans($con, $page_id); |
case 1: updateOrphans($page_id); |
417 |
break; |
break; |
418 |
|
|
419 |
// Purge orphans |
// Purge orphans |
420 |
case 2: purgeOrphans($con, $page_id); |
case 2: purgeOrphans($page_id); |
421 |
break; |
break; |
422 |
|
|
423 |
// Purge all parent-child relationships |
// Purge all parent-child relationships |
424 |
case 3: purgeRelationships($con, $page_id); |
case 3: purgeRelationships($page_id); |
425 |
break; |
break; |
426 |
|
|
427 |
default: |
default: |
430 |
} |
} |
431 |
|
|
432 |
// Required cleanup, regardless of fix methodology |
// Required cleanup, regardless of fix methodology |
433 |
updateOrders($con, $page_id); |
updateOrders($page_id); |
434 |
updateGenerations($con, $page_id); |
updateGenerations($page_id); |
435 |
|
|
436 |
printf("<br>Done. Re-run the debugger against this page to determine success: <a href=\"scribe_debug.phtml?page_id=%d\">Debug Page ID#%d</a><br><br>", $page_id, $page_id); |
printf("<br>Done. Re-run the debugger against this page to determine success: <a href=\"scribe_debug.phtml?page_id=%d\">Debug Page ID#%d</a><br><br>", $page_id, $page_id); |
437 |
printf("</td></tr></table></center>\n"); |
printf("</td></tr></table></center>\n"); |
443 |
/********************************************************** |
/********************************************************** |
444 |
Function: updateGenerations |
Function: updateGenerations |
445 |
Author: Paul Bramscher |
Author: Paul Bramscher |
446 |
Last Modified: 10.28.2003 |
Last Modified: 03.04.2004 |
447 |
*********************************************************** |
*********************************************************** |
448 |
Purpose: |
Purpose: |
449 |
Walks through a page and compares calculated generation with |
Walks through a page and compares calculated generation with |
450 |
reported indent level. When a discrepancy is found, fix it |
reported indent level. When a discrepancy is found, fix it |
451 |
according to the calculated generation. |
according to the calculated generation. |
452 |
**********************************************************/ |
**********************************************************/ |
453 |
function updateGenerations($con, $page_id) { |
function updateGenerations($page_id) { |
454 |
|
|
455 |
printf("<br><b>Analyzing generational structure:</b><br>\n"); |
printf("<br><b>Analyzing generational structure:</b><br>\n"); |
456 |
|
|
469 |
. $page_id |
. $page_id |
470 |
. " ORDER BY element_order"; |
. " ORDER BY element_order"; |
471 |
|
|
472 |
$rs = mysql_query($sql, $con); |
$rs = mysql_tryquery($sql); |
473 |
|
|
474 |
while ($row = mysql_fetch_array ($rs)) { |
while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { |
475 |
$element_id = $row["element_id"]; |
$element_id = $row["element_id"]; |
476 |
$indent_level = $row["indent_level"]; |
$indent_level = $row["indent_level"]; |
477 |
$parent_id = $row["parent_id"]; |
$parent_id = $row["parent_id"]; |
480 |
$gen_level = 0; |
$gen_level = 0; |
481 |
|
|
482 |
// Call the generational calculator for each element |
// Call the generational calculator for each element |
483 |
$gen_level = genCalc($con, $element_id, $gen_level, $page_id, $parent_id); |
$gen_level = genCalc($element_id, $gen_level, $page_id, $parent_id); |
484 |
|
|
485 |
// A discrepancy was founnd |
// A discrepancy was founnd |
486 |
if ($gen_level != $indent_level) { |
if ($gen_level != $indent_level) { |
496 |
. $page_id |
. $page_id |
497 |
. " AND element_id = " |
. " AND element_id = " |
498 |
. $element_id; |
. $element_id; |
499 |
|
if (mysql_tryquery ($sub_sql)) printf("Element #%d reported generation of %d, but calculated at %d. Fixed.<br>\n", $element_id, $indent_level, $gen_level); |
|
if (!mysql_query ($sub_sql, $con)){ |
|
|
sql_err($sub_sql); |
|
|
mysql_query ("UNLOCK TABLES", $con); |
|
|
bailout(); |
|
|
} |
|
|
else { |
|
|
// Output |
|
|
printf("Element #%d reported generation of %d, but calculated at %d. Fixed.<br>\n", $element_id, $indent_level, $gen_level); |
|
|
mysql_query ("UNLOCK TABLES", $con); |
|
|
|
|
|
} // fixed this element's indent |
|
500 |
|
|
501 |
} // if there is a discrepancy with calculated generation level |
} // if there is a discrepancy with calculated generation level |
502 |
|
|
510 |
/********************************************************** |
/********************************************************** |
511 |
Function: updateOrders |
Function: updateOrders |
512 |
Author: Paul Bramscher |
Author: Paul Bramscher |
513 |
Last Modified: 10.28.2003 |
Last Modified: 03.04.2004 |
514 |
*********************************************************** |
*********************************************************** |
515 |
Purpose: |
Purpose: |
516 |
Walks through a page and compares calculated order with |
Walks through a page and compares calculated order with |
517 |
reported order. When a discrepancy is found, fix it |
reported order. When a discrepancy is found, fix it |
518 |
according to the calculated order. |
according to the calculated order. |
519 |
**********************************************************/ |
**********************************************************/ |
520 |
function updateOrders($con, $page_id) { |
function updateOrders($page_id) { |
521 |
|
|
522 |
printf("<br><b>Analyzing cardinal orders:</b><br>\n"); |
printf("<br><b>Analyzing cardinal orders:</b><br>\n"); |
523 |
|
|
535 |
. $page_id |
. $page_id |
536 |
. " ORDER BY element_order"; |
. " ORDER BY element_order"; |
537 |
|
|
538 |
$rs = mysql_query($sql, $con); |
$rs = mysql_tryquery($sql); |
539 |
|
|
540 |
while ($row = mysql_fetch_array ($rs)) { |
while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { |
541 |
$element_id = $row["element_id"]; |
$element_id = $row["element_id"]; |
542 |
$element_order = $row["element_order"]; |
$element_order = $row["element_order"]; |
543 |
|
|
558 |
. $page_id |
. $page_id |
559 |
. " AND element_id = " |
. " AND element_id = " |
560 |
. $element_id; |
. $element_id; |
561 |
|
if (mysql_tryquery ($sub_sql)) printf("Row #%d reported cardinal order of %d, but calculated at %d. Fixed.<br>\n", $element_count, $element_order, $element_count); |
|
if (!mysql_query ($sub_sql, $con)){ |
|
|
sql_err($sub_sql); |
|
|
mysql_query ("UNLOCK TABLES", $con); |
|
|
bailout(); |
|
|
} |
|
|
else { |
|
|
|
|
|
// Output |
|
|
printf("Row #%d reported cardinal order of %d, but calculated at %d. Fixed.<br>\n", $element_count, $element_order, $element_count); |
|
|
mysql_query ("UNLOCK TABLES", $con); |
|
|
} // fixed this element's order |
|
562 |
|
|
563 |
} // if an order discrepancy was found |
} // if an order discrepancy was found |
564 |
|
|
573 |
/********************************************************** |
/********************************************************** |
574 |
Function: updateOrphans |
Function: updateOrphans |
575 |
Author: Paul Bramscher |
Author: Paul Bramscher |
576 |
Last Modified: 10.28.2003 |
Last Modified: 03.04.2004 |
577 |
*********************************************************** |
*********************************************************** |
578 |
Purpose: |
Purpose: |
579 |
Walks through a page and hunts for orphaned/bastard |
Walks through a page and hunts for orphaned/bastard |
580 |
children. Hunts for most likely parent and attaches the |
children. Hunts for most likely parent and attaches the |
581 |
child to it. |
child to it. |
582 |
**********************************************************/ |
**********************************************************/ |
583 |
function updateOrphans($con, $page_id) { |
function updateOrphans($page_id) { |
584 |
|
|
585 |
// Initialize |
// Initialize |
586 |
$passed_orphan = 1; |
$passed_orphan = 1; |
598 |
. $page_id |
. $page_id |
599 |
. " ORDER BY element_order"; |
. " ORDER BY element_order"; |
600 |
|
|
601 |
$rs = mysql_query($sql, $con); |
$rs = mysql_tryquery($sql); |
602 |
|
|
603 |
while ($row = mysql_fetch_array ($rs)) { |
while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { |
604 |
$element_id = $row["element_id"]; |
$element_id = $row["element_id"]; |
605 |
$element_order = $row["element_order"]; |
$element_order = $row["element_order"]; |
606 |
$parent_id = $row["parent_id"]; |
$parent_id = $row["parent_id"]; |
607 |
$indent_level = $row["indent_level"]; |
$indent_level = $row["indent_level"]; |
608 |
|
|
609 |
$new_parent_id = parentProbe($con, $page_id, $element_order, $indent_level); |
$new_parent_id = parentProbe($page_id, $element_order, $indent_level); |
610 |
$orphaned = 0; |
$orphaned = 0; |
611 |
$orphaned = isOrphan($con, $element_id, $element_order, $page_id, $parent_id); |
$orphaned = isOrphan($element_id, $element_order, $page_id, $parent_id); |
612 |
|
|
613 |
// Hunt for most likely parent, and assign to it instead. |
// Hunt for most likely parent, and assign to it instead. |
614 |
if ($parent_id > 0 && $orphaned == 1) { |
if ($parent_id > 0 && $orphaned == 1) { |
623 |
. $page_id |
. $page_id |
624 |
. " AND element_id = " |
. " AND element_id = " |
625 |
. $element_id; |
. $element_id; |
626 |
|
if (mysql_tryquery ($sub_sql)) printf("Element #%d orphaned. Reassigned to parent #%d<br>\n", $element_id, $new_parent_id); |
|
if (!mysql_query ($sub_sql, $con)){ |
|
|
sql_err($sub_sql); |
|
|
mysql_query ("UNLOCK TABLES", $con); |
|
|
bailout(); |
|
|
} |
|
|
else { |
|
|
|
|
|
// Output |
|
|
printf("Element #%d orphaned. Reassigned to parent #%d<br>\n", $element_id, $new_parent_id); |
|
|
|
|
|
mysql_query ("UNLOCK TABLES", $con); |
|
|
} // reassigned this element |
|
627 |
|
|
628 |
} // reassign problematic elements |
} // reassign problematic elements |
629 |
|
|
632 |
if ($passed_orphan == 1) printf("No orphans found.<br>\n"); |
if ($passed_orphan == 1) printf("No orphans found.<br>\n"); |
633 |
|
|
634 |
} // end updateOrphans |
} // end updateOrphans |
635 |
?> |
?> |