--- branches/paul/admin/include/scribe_application.php 2004/03/07 19:15:27 66 +++ branches/paul/admin/include/scribe_application.php 2004/03/18 19:24:54 67 @@ -1,8 +1,8 @@ -Last Modified: 01.27.2004 +Original Author: Paul Bramscher +Last Modified: 03.16.2004 *********************************************************** Comments: This library brings together all of the SQL actions in @@ -10,6 +10,7 @@ on app_controls.php and other libraries as well, but these are specific to CLPS. *********************************************************** +Table of Contents: assignPageStaff assignStaffCoordinator copyPasteElement @@ -19,12 +20,8 @@ deletePage deletePageConfirm deletePageStaff -displayCourseHeader -displayCoursePers displayTOC -elementDecrease elementDown -elementIncrease elementMultiFormat elementSize elementUp @@ -46,14 +43,6 @@ populateGenArray scribePublish scribeUnpublish - ---- -Deprecated: -siblingElderProbe -siblingYoungerProbe ---- - - sibProbeElder sibProbeYounger toggleTOCDisplay @@ -78,13 +67,13 @@ /********************************************************** Function: assignPageStaff Author: Paul Bramscher -Last Modified: 04.23.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Assigns staffpersons (possibly multiple) to a given page and calls the page edit mode back again. **********************************************************/ -function assignPageStaff($con, $page_id, $staff_id_array) { +function assignPageStaff($page_id, $staff_id_array) { // For all staff in the array for ($subscript = 0; $subscript < sizeof($staff_id_array); $subscript++ ) { @@ -92,24 +81,15 @@ // Check to make sure that the staff isn't already assigned $sql = "SELECT * FROM page_staff where page_id = " . $page_id . " AND staff_id = " . $staff_id_array[$subscript]; - $rs = mysql_query($sql); + $rs = mysql_tryquery($sql); if (mysql_num_rows($rs) == 0) { $sql = "INSERT INTO page_staff (page_id, staff_id) VALUES (" . $page_id . ", " . $staff_id_array[$subscript] - . ")"; - - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } // bad write - else { - mysql_query("UNLOCK TABLES", $con); - - } // good write of staff + . ")"; + mysql_tryquery($sql); } // staff not already assigned @@ -124,42 +104,35 @@ /********************************************************** Function: assignStaffCoordinator Author: Paul Bramscher -Last Modified: 04.22.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Assigns a single staff coordinator to a given page and calls the page edit mode back again. **********************************************************/ -function assignStaffCoordinator($con, $page_id, $staff_coordinator) { +function assignStaffCoordinator($page_id, $staff_coordinator) { $sql = "UPDATE page SET staff_coordinator = " . $staff_coordinator . " WHERE page_id = " . $page_id; - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { // Success call the page back - mysql_query ("UNLOCK TABLES", $con); - header("Location: scribe.phtml?page_id=" . $page_id); - } + mysql_tryquery ($sql); + header("Location: scribe.phtml?page_id=" . $page_id); } /********************************************************** Function: copyPasteElement Author: Paul Bramscher -Last Modified: 06.11.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Copies the supplied element id and descendants (if picked) and inserts them into the user's copy/paste buffer. Any previously copied data is replaced. **********************************************************/ -function copyPasteElement($con, $page_id, $place_array_HTML, $copysingle, $sess_staff_id){ +function copyPasteElement($page_id, $place_array_HTML, $copysingle, $sess_staff_id){ // Split by comma separated values $place_array = split(",", $place_array_HTML); @@ -174,20 +147,7 @@ // First, we delete any previously cut elements from the pastebuffer table $sql = "DELETE FROM pastebuffer WHERE paste_staff_id = " . $sess_staff_id; - - //printf("sql was: %s
\n", $sql); - - - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - $success = 0; - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - - } + mysql_tryquery($sql); // Element is a parent, and user is copying that element only. if ($copysingle == 1) { @@ -208,10 +168,10 @@ . " AND element_order > " . $element_order . " ORDER BY element_order"; - $rs = mysql_query($sql, $con); + $rs = mysql_tryquery($sql); // Check for indent level - while (($row = mysql_fetch_array ($rs)) && ($end_found == 0)) { + while (($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) && ($end_found == 0)) { $probe_element_id = $row["element_id"]; $probe_indent_level = $row["indent_level"]; @@ -272,17 +232,7 @@ . $end_element_order . " ORDER BY element_order"; - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - $success = 0; - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - - } - + mysql_tryquery($sql); header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); } // end function @@ -291,25 +241,16 @@ /********************************************************** Function: deleteCopyBuffer Author: Paul Bramscher -Last Modified: 04.22.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Clears the user's copy/paste buffer. **********************************************************/ -function deleteCopyBuffer($con, $page_id, $paste_staff_id){ +function deleteCopyBuffer($page_id, $paste_staff_id){ $sql = "DELETE from pastebuffer WHERE paste_staff_id = " . $paste_staff_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - } - + mysql_tryquery($sql); header("Location: scribe.phtml?page_id=". $page_id); } @@ -317,37 +258,27 @@ /********************************************************** Function: deleteCoursePers Author: Paul Bramscher -Last Modified: 12.02.2002 +Last Modified: 03.03.2004 *********************************************************** Purpose: Deletes the supplied personnel id from the course. **********************************************************/ -function deleteCoursePers($con, $course_id, $page_id, $personnel_id){ +function deleteCoursePers($course_id, $page_id, $personnel_id){ // Build the sql. $sql = "DELETE from course_personnel WHERE personnel_id = " . $personnel_id . " AND course_id = " . $course_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - } - + mysql_tryquery($sql); header("Location: scribe.phtml?page_id=". $page_id); } - /********************************************************** Function: deleteElement Author: Paul Bramscher -Last Modified: 04.24.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Deletes the supplied element id. Depending on user selection, @@ -358,7 +289,7 @@ and any removed descendants, from the libstats statistics table. **********************************************************/ -function deleteElement($con, $page_id, $place_array_HTML, $promote){ +function deleteElement($page_id, $place_array_HTML, $promote){ // Split by comma separated values $place_array = split(",", $place_array_HTML); @@ -384,68 +315,31 @@ if ($promote == 0) { - // Success flag - $success = 1; - // First delete the element $sql = "DELETE from element WHERE page_id = " . $page_id . " AND element_id = " . $element_id; - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - $success = 0; - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - - } + mysql_tryquery($sql); // Next, update the order of the remainders - if ($success == 1) { - - $sql = "UPDATE element SET element_order = element_order - 1 WHERE page_id = " - . $page_id - . " AND element_order > " - . $element_order; - - // Make the change - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - - } // end reordering - - } // end safety check for reordering + $sql = "UPDATE element SET element_order = element_order - 1 WHERE page_id = " + . $page_id + . " AND element_order > " + . $element_order; + mysql_tryquery($sql); // Last, delete the element reference from the stats database - if ($success == 1) { - $sql = "DELETE from libstats.elementstats WHERE page_id = " - . $page_id - . " AND element_id = " - . $element_id; - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - $success = 0; - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - - // Done, return to page - if ($position > 2) $new_pos = $position - 1; - else $new_pos = 1; - header("Location: scribe.phtml?page_id=". $page_id . "#p" . $new_pos); + $sql = "DELETE from libstats.elementstats WHERE page_id = " + . $page_id + . " AND element_id = " + . $element_id; + mysql_tryquery($sql); - } - } // end removal from stats database + // Done, return to page + if ($position > 2) $new_pos = $position - 1; + else $new_pos = 1; + header("Location: scribe.phtml?page_id=". $page_id . "#p" . $new_pos); } // end simple delete @@ -474,10 +368,10 @@ . " AND element_order > " . $element_order . " ORDER BY element_order"; - $rs = mysql_query($sql, $con); + $rs = mysql_tryquery($sql); // Check for and promote all descendants - while (($row = mysql_fetch_array ($rs)) && ($desc_indent_level > $indent_level)) { + while (($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) && ($desc_indent_level > $indent_level)) { $desc_element_id = $row["element_id"]; $desc_parent_id = $row["parent_id"]; $desc_indent_level = $row["indent_level"]; @@ -488,17 +382,7 @@ . $page_id . " AND element_id = " . $desc_element_id; - - if (!mysql_query($promote_sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - $success = 0; - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - - } // end of a descendant promote + mysql_tryquery($promote_sql); } // end of check for one descendant @@ -517,85 +401,38 @@ . $page_id . " AND element_id = " . $desc_element_id; - if (!mysql_query($newparent_sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - $success = 0; - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - - } // end of a first-generation parent reassignment + mysql_tryquery($newparent_sql); } // end check for first generation children } // end check for all descendants // Next, delete the parent - if ($success == 1) { - $parent_sql = "DELETE FROM element WHERE element_id = " - . $element_id; - if (!mysql_query($parent_sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - $success = 0; - } - else { - mysql_query("UNLOCK TABLES", $con); - - // Increment the deleted counter to include the parent - $num_desc++; - - } // end of parent delete - - } // end of safety check for parent delete + $parent_sql = "DELETE FROM element WHERE element_id = " + . $element_id; + mysql_tryquery($parent_sql); + + // Increment the deleted counter to include the parent + $num_desc++; // Next, update the order of the remainders - if ($success == 1) { - $order_sql = "UPDATE element SET element_order = element_order - 1 WHERE page_id = " - . $page_id - . " AND element_order > " - . $element_order; - if (!mysql_query($order_sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - $success = 0; - } - else { - mysql_query("UNLOCK TABLES", $con); - - } // end reordering - - } // end of safety check for reordering - + $order_sql = "UPDATE element SET element_order = element_order - 1 WHERE page_id = " + . $page_id + . " AND element_order > " + . $element_order; + mysql_tryquery($order_sql); // Last, delete the (parent) element reference from the stats database - if ($success == 1) { - $sql = "DELETE from libstats.elementstats WHERE page_id = " - . $page_id - . " AND element_id = " - . $element_id; - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - $success = 0; - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - - // Done, return to page - if ($position > 2) $new_pos = $position - 1; - else $new_pos = 1; - header("Location: scribe.phtml?page_id=". $page_id . "#p" . $new_pos); - - } - - } // end removal from stats database + $sql = "DELETE from libstats.elementstats WHERE page_id = " + . $page_id + . " AND element_id = " + . $element_id; + mysql_tryquery($sql); + // Done, return to page + if ($position > 2) $new_pos = $position - 1; + else $new_pos = 1; + header("Location: scribe.phtml?page_id=". $page_id . "#p" . $new_pos); } // end delete and promote @@ -606,9 +443,6 @@ else if ($promote == 2) { - - // Success flag - $success = 1; // Intialize first descendant indent level to proper value $desc_indent_level = $indent_level + 1; @@ -628,10 +462,10 @@ . " AND element_order > " . $element_order . " ORDER BY element_order"; - $rs = mysql_query($sql, $con); + $rs = mysql_tryquery($sql); // Check for and delete all descendants - while (($row = mysql_fetch_array ($rs)) && ($desc_indent_level > $indent_level)) { + while (($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) && ($desc_indent_level > $indent_level)) { $desc_element_id = $row["element_id"]; $desc_parent_id = $row["parent_id"]; $desc_indent_level = $row["indent_level"]; @@ -639,109 +473,51 @@ // We've found a descendant, delete it if ($desc_indent_level > $indent_level) { $delete_sql = "DELETE FROM element WHERE element_id = " - . $desc_element_id; - if (!mysql_query($delete_sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - $success = 0; - } - else { - mysql_query("UNLOCK TABLES", $con); - - // Increment the deleted descendant counter - $num_desc++; - } // end of a descendant delete + . $desc_element_id; + mysql_tryquery($delete_sql); + + // Increment the deleted descendant counter + $num_desc++; } // end of check for one descendant - // Delete this (descendant) element reference from the stats database - if ($success == 1) { - $sql = "DELETE from libstats.elementstats WHERE page_id = " - . $page_id - . " AND element_id = " - . $desc_element_id; - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - $success = 0; - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - - } - } // end removal from stats database + $sql = "DELETE from libstats.elementstats WHERE page_id = " + . $page_id + . " AND element_id = " + . $desc_element_id; + mysql_tryquery($sql); } // end check for all descendants // Delete the parent itself - if ($success == 1) { - $parent_sql = "DELETE FROM element WHERE element_id = " - . $element_id; - if (!mysql_query($parent_sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - $success = 0; - } - else { - mysql_query("UNLOCK TABLES", $con); + $parent_sql = "DELETE FROM element WHERE element_id = " + . $element_id; + mysql_tryquery($parent_sql); - // Increment the deleted counter to include the parent - $num_desc++; - - } // end of parent delete - - } // end of safety check for parent delete + // Increment the deleted counter to include the parent + $num_desc++; // Next, update the order of the remainders - if ($success == 1) { - $order_sql = "UPDATE element SET element_order = element_order - " - . $num_desc - . " WHERE page_id = " - . $page_id - . " AND element_order > " - . $element_order; - if (!mysql_query($order_sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - $success = 0; - } - else { - mysql_query("UNLOCK TABLES", $con); - - } // end reordering - - } // end of safety check for reordering - + $order_sql = "UPDATE element SET element_order = element_order - " + . $num_desc + . " WHERE page_id = " + . $page_id + . " AND element_order > " + . $element_order; + mysql_tryquery($order_sql); // Last, delete the (parent) element reference from the stats database - if ($success == 1) { - $sql = "DELETE from libstats.elementstats WHERE page_id = " - . $page_id - . " AND element_id = " - . $element_id; - - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - $success = 0; - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - - // Done, return to page - if ($position > 2) $new_pos = $position - 1; - else $new_pos = 1; - header("Location: scribe.phtml?page_id=". $page_id . "#p" . $new_pos); + $sql = "DELETE from libstats.elementstats WHERE page_id = " + . $page_id + . " AND element_id = " + . $element_id; + mysql_tryquery($sql); - } - - } // end removal from stats database + // Done, return to page + if ($position > 2) $new_pos = $position - 1; + else $new_pos = 1; + header("Location: scribe.phtml?page_id=". $page_id . "#p" . $new_pos); } // end delete parent and children @@ -751,7 +527,7 @@ /********************************************************** Function: deletePage Author: Paul Bramscher -Last Modified: 06.17.2003 +Last Modified: 03.16.2004 *********************************************************** Purpose: Deletes the supplied page id. In doing so, elements, @@ -762,7 +538,7 @@ page id in the libstats database, including element-level and overall page statistics. **********************************************************/ -function deletePage($con, $page_id){ +function deletePage($page_id){ // Load globals include("global_vars.php"); @@ -770,29 +546,19 @@ // Include the page header include ($GLOBAL_ADMIN_INC."scribe_header.phtml"); - // HTML headers + // HTML header printf("\n"); printf("\n"); printf("PageScribe: Deleting page...\n"); printf("\n", $GLOBAL_ADMIN_CSS); - printf(""); - - - // Draw form heading - printf("

Deleting Page...

\n"); - - // Table - printf("\n"); - printf("

\n"); - printf("Messages:
\n"); + printf("\n"); + msgTableOpen(1, "Deleting Page (ID# " . $page_id . ")"); + printf("Messages:
\n"); // Purge all if ($page_id > 0) { - // Error flag - $success = 1; - // Initialize $course_id = 0; @@ -800,154 +566,55 @@ $sql = "SELECT course_id FROM course WHERE page_id = " . $page_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); // Collect the access information $course_id = $row["course_id"]; // Delete all elements first $sql = "DELETE from element WHERE page_id =" . $page_id; - - if (!mysql_query ($sql, $con)){ - $success = 0; - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - printf("Removed this page's elements.
\n"); - } + if (mysql_tryquery ($sql)) printf("Removed this page's elements.
\n"); - // Delete course information, if any - if ($success == 1) { - - $sql = "DELETE from course WHERE page_id =" . $page_id; - - if (!mysql_query ($sql, $con)){ - $success = 0; - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - printf("Removed course information (if any).
\n"); - } - } + // Delete course information, if any + $sql = "DELETE from course WHERE page_id =" . $page_id; + if (mysql_tryquery ($sql)) printf("Removed course information (if any).
\n"); // Delete assigned course personnel, if any - if ($success == 1 && $course_id > 0) { + if ($course_id > 0) { $sql = "DELETE from course_personnel WHERE course_id =" . $course_id; - - if (!mysql_query ($sql, $con)){ - $success = 0; - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - printf("Removed assigned course personnel (if any).
\n"); - } + if (mysql_tryquery ($sql)) printf("Removed assigned course personnel (if any).
\n"); } // Delete assigned staff, if any - if ($success == 1) { - - $sql = "DELETE from page_staff WHERE page_id =" . $page_id; - - if (!mysql_query ($sql, $con)){ - $success = 0; - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - printf("Removed assigned staff (if any).
\n"); - } - } + $sql = "DELETE from page_staff WHERE page_id =" . $page_id; + if (mysql_tryquery ($sql)) printf("Removed assigned staff (if any).
\n"); // Delete assigned subjects, if any - if ($success == 1) { - - $sql = "DELETE from sub_page WHERE page_id =" . $page_id; - - if (!mysql_query ($sql, $con)){ - $success = 0; - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - printf("Removed assigned subjects (if any).
\n"); - } - } + $sql = "DELETE from sub_page WHERE page_id =" . $page_id; + if (mysql_tryquery ($sql)) printf("Removed assigned subjects (if any).
\n"); // Delete element statistics, if any - if ($success == 1) { - - $sql = "DELETE from libstats.elementstats WHERE page_id =" . $page_id; - - if (!mysql_query ($sql, $con)){ - $success = 0; - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - printf("Removed page's element statistics (if any).
\n"); - } - } + $sql = "DELETE from libstats.elementstats WHERE page_id =" . $page_id; + if (mysql_tryquery ($sql)) printf("Removed page's element statistics (if any).
\n"); // Delete page overall statistics, if any - if ($success == 1) { - - $sql = "DELETE from libstats.pagestats WHERE page_id =" . $page_id; - - if (!mysql_query ($sql, $con)){ - $success = 0; - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - printf("Removed page's overall statistics (if any).
\n"); - } - } + $sql = "DELETE from libstats.pagestats WHERE page_id =" . $page_id; + if (mysql_tryquery ($sql)) printf("Removed page's overall statistics (if any).
\n"); // Delete the page information - if ($success == 1) { - - $sql = "DELETE from page WHERE page_id =" . $page_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - printf("Removed page successfully.

\n"); - } - } + $sql = "DELETE from page WHERE page_id =" . $page_id; + if (mysql_tryquery ($sql)) printf("Removed page successfully."); } - else printf("Scribe page not found.

\n"); - - printf("
\n"); + else printf("Scribe page not found."); + printf("

\n"); + msgTableClose(); // Link to return to admin console - adminReturn(""); - - printf("
\n"); + adminReturn(""); // Include the footer include ($GLOBAL_ADMIN_INC."scribe_footer.phtml"); @@ -957,12 +624,12 @@ /********************************************************** Function: deletePageConfirm Author: Paul Bramscher -Last Modified: 05.01.2003 +Last Modified: 03.16.2004 *********************************************************** Purpose: Confirm prompt to delete the supplied page id. **********************************************************/ -function deletePageConfirm($con, $page_id){ +function deletePageConfirm($page_id){ // Load globals include ("global_vars.php"); @@ -973,33 +640,28 @@ // Include the page header include ($GLOBAL_ADMIN_INC."scribe_header.phtml"); - // HTML junk + // HTML header printf("\n"); printf("\n"); printf("PageScribe: Delete Page?\n"); printf("\n", $GLOBAL_ADMIN_CSS); - printf(""); + printf("\n"); - // Draw page heading - printf("

Delete Page?

"); + msgTableOpen(1, "Delete Page (ID# " . $page_id . ")?"); // Check to see if its possible - $exists = existsRow($con, "page", "page_id", $page_id); + $exists = existsRow("page", "page_id", $page_id); if ($exists > 0){ - // Table - printf(""); - printf("
"); - // Lookup the title & author - $page_title = lookupField($con, "page", "page_id", $page_id, "page_title"); - printf("
Page Title: %s
\n ", $page_title); + $page_title = lookupField("page", "page_id", $page_id, "page_title"); + printf("Page Title: %s

\n ", $page_title); + printf("This will permanently remove the page and its various assignments from the system.

\n"); // Form to draw the delete button printf("
\n"); printf("\n"); printf("\n", $page_id); - printf("This will permanently remove the page and its various assignments from the system

\n"); printf("
\n"); // Interior table @@ -1021,21 +683,16 @@ // Close interior table printf("
\n"); - - // Close table - printf("\n"); } - // Failed for whatever reason - else if ($exists < 1) printf ("Page not found. Operation cancelled.
\n"); + // Failed + else if ($exists < 1) printf ("Page not found. Operation cancelled.

\n"); + msgTableClose(); // Link to return to admin console adminReturn(""); - - printf("
"); - // Include the footer include ($GLOBAL_ADMIN_INC."scribe_footer.phtml"); } @@ -1044,29 +701,19 @@ /********************************************************** Function: deletePageStaff Author: Paul Bramscher -Last Modified: 04.22.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Delete a staffperson (possibly multiple) associated with the supplied page id. **********************************************************/ -function deletePageStaff($con, $page_id, $staff_list_array){ +function deletePageStaff($page_id, $staff_list_array){ for ($element = 0; $element < sizeof($staff_list_array); $element++) { $sql = "DELETE FROM page_staff where page_id = " . $page_id . - " AND staff_id = " . $staff_list_array[$element]; + " AND staff_id = " . $staff_list_array[$element]; - // Failed - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - - // Succeeded - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); } // Call the PageScribe page back @@ -1075,207 +722,9 @@ /********************************************************** -Function: displayCourseHeader -Author: Paul Bramscher -Last Modified: 04.24.2003 -*********************************************************** -Purpose: -Output the course related information for a course page. -**********************************************************/ -function displayCourseHeader($con, $page_id, $page_title) { - - // Retrieve current information - $sql = "SELECT * - FROM - course c - LEFT JOIN term t using (term_id) - LEFT JOIN campus p on c.campus_id = p.campus_id - LEFT JOIN coursesub s on c.coursesub_id = s.coursesub_id - - WHERE - page_id = " . $page_id; - - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); - - $course_id = $row["course_id"]; - $staff_id_created = $row["staff_id_created"]; - $staff_id_edited = $row["staff_id_edited"]; - $coursesub_id = $row["coursesub_id"]; - $coursesub = $row["coursesub"]; - $course_num = $row["course_num"]; - $course_section = $row["course_section"]; - $course_concat = $row["course_concat"]; - $term_id = $row["term_id"]; - $term = $row["term"]; - $course_year = $row["course_year"]; - $campus_id = $row["campus_id"]; - $campus = $row["campus"]; - $courseheader = $row["courseheader"]; - $introheader1 = $row["introheader1"]; - $intromessage1 = $row["intromessage1"]; - $introheader2 = $row["introheader2"]; - $intromessage2 = $row["intromessage2"]; - - // Course Header - if (strlen($courseheader) > 1) printf("%s
\n", $courseheader); - - // Start the span class - printf(""); - - // Display concatenated course title - printf("%s", $course_concat); - - // Close the span - printf("

\n"); - - // Display course term - if (strlen($term) > 1 && $term_id > 1) printf("%s", $term); - - // Display Comma - if (strlen($term) > 1 && strlen($course_year) > 1) printf(", "); - - // Display course year - if (strlen($course_year) > 1) printf("%s", $course_year); - - printf("
"); - - // Campus - if (strlen($campus) > 0 && $campus_id > 1) printf("%s
\n", $campus); - - // Intro header1 - if (strlen($introheader1) > 0) { - printf("
\n"); - printf("%s", $introheader1); - printf("

\n"); - - } - - // Intro Message1 - if (strlen($intromessage1) > 0) { - printf("%s", $intromessage1); - printf("
\n"); - } - - // Intro header2 - if (strlen($introheader2) > 0) { - printf("
\n"); - printf("%s", $introheader2); - printf("

\n"); - - } - - // Intro Message2 - if (strlen($intromessage2) > 0) { - printf("%s", $intromessage2); - printf("
\n"); - } - -} - - -/********************************************************** -Function: displayCoursePers -Author: Paul Bramscher -Last Modified: 04.22.2003 -*********************************************************** -Purpose: -Displays the personnel associated with the course, by -looking up the course id based on the page id. -**********************************************************/ -function displayCoursePers($con, $page_id) { - - // Determine the course id - $course_id = lookupfield($con, "course", "page_id", $page_id, "course_id"); - - // Retrieve current information - $sql = "SELECT * - FROM - course_personnel cp - LEFT JOIN staff s using (staff_id) - LEFT JOIN stafftitle st on cp.stafftitle_id = st.stafftitle_id - LEFT JOIN faculty f on cp.faculty_id = f.faculty_id - - WHERE - course_id = " . $course_id . " ORDER BY personnel_id"; - - $rs = mysql_query($sql, $con); - - // See how many in this record set - $num_personnel = mysql_num_rows($rs); - - if ($num_personnel > 0) { - - // Display course personnel - printf("
\n"); - printf("Personnel:
\n"); - - - while ($row = mysql_fetch_array ($rs)) { - - // Initialize - $last_name = ""; - $first_name = ""; - $x500 = ""; - $email = ""; - $stafftitle = ""; - - // Fetch the general stuff - $personnel_id = $row["personnel_id"]; - $staff_id = $row["staff_id"]; - $faculty_id = $row["faculty_id"]; - $stafftitle = $row["stafftitle"]; - $stafftitle_id = $row["stafftitle_id"]; - - // Row is staff. (Not 0, NULL, 1=N/A). - if ($staff_id > 1) { - - // Gather the staff table fields - $last_name = $row["last_name"]; - $first_name = $row["first_name"]; - $x500 = $row["staff_account"]; - $email = $x500 . "@umn.edu"; - - } - - // Row is faculty (Not 0, NULL, 1=N/A). - else if ($faculty_id > 1) { - - // Gather the faculty table fields - $last_name = $row["faculty_lastname"]; - $first_name = $row["faculty_firstname"]; - $x500 = $row["faculty_account"]; - $email = $row["faculty_email"]; - - } - - // Row is "other", use the freetext fields - else { - - // Gather the catch-all fields - $last_name = $row["pers_lastname"]; - $first_name = $row["pers_firstname"]; - $x500 = $row["pers_account"]; - $email = $row["pers_email"]; - } - - - // Display the data - if ($stafftitle_id > 1) printf("%s: ", $stafftitle); - printf("%s %s %s
\n", - $first_name, $last_name, $email, $email); - - } // all course_personnel rows - - } // if there were any persons attached to this course - -} - - -/********************************************************** Function: displayTOC Author: Paul Bramscher -Last Modified: 12.15.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Generates and displays a table of contents (TOC) for the @@ -1286,13 +735,13 @@ two-column table of contents, split at the midpoint (rounded up for odd numbers of root elements). **********************************************************/ -function displayTOC($con, $page_id, $wrap_toc) { +function displayTOC($page_id, $wrap_toc) { // Calculate number of elements $sql = "SELECT COUNT(*) as num_elements FROM element WHERE indent_level < 1 AND page_id = " . $page_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $num_elements = $row["num_elements"]; // Calculate midpoint element @@ -1331,7 +780,7 @@ . $page_id . " AND e.indent_level < 1 ORDER BY e.element_order"; - $rs = mysql_query($sql, $con); + $rs = mysql_tryquery($sql); // Build a general ToC anchor printf("\n"); @@ -1346,7 +795,7 @@ $row_num = 0; - while ($row = mysql_fetch_array ($rs)) { + while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { // Check for the midpoint if ($wrap_toc == 1) @@ -1414,80 +863,12 @@ } -/********************************************************** -Function: elementDecrease -Author: Paul Bramscher -Last Modified: 10.29.2002 -*********************************************************** -Incoming: -$con Database connection string -$element_id Element to perform decrease on -$page_id Page the element is location on -$position Position on the page -*********************************************************** -Outgoing: -None -*********************************************************** -Purpose: -Decreases the output size of the element. Note that the -HTML tag operates in reverse, with H1 typically being -larger than H5. So this increase effectively increases the -numerical value of the tag. - -If the user shrinks below 5, set it equal to zero, which -means that the tag will be unused by the system. - -NOTE: This has been deprecated with the elementSize() -function. It is not currently being used. -**********************************************************/ -function elementDecrease($con, $element_id, $page_id, $position){ - - // Get current element size - $sql = "SELECT element_size FROM element WHERE element_id = " - . $element_id - . " AND page_id = " - . $page_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); - $element_size = $row["element_size"]; - - // Default to
if nothing specified - if ($element_size < 1) $element_size = 5; - - // Original was less than 5. Note that we don't shrink smaller than 5. - else if ($element_size < 5) $element_size++; - - // Else get rid of the size value altogether - else if ($element_size == 5) $element_size = 0; - - $sql = "UPDATE element SET element_size = " - . $element_size - . " WHERE page_id = " - . $page_id - . " AND element_id = " - . $element_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { // Success call the page back - mysql_query ("UNLOCK TABLES", $con); - - header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); - } - -} - - /********************************************************** Function: elementDown Author: Paul Bramscher -Last Modified: 09.24.2002 +Last Modified: 03.04.2004 *********************************************************** Incoming: -$con Database connection string $element_id Element to move down $page_id Page the element is location on $position Position on the page @@ -1510,15 +891,15 @@ to its position. With the next iteration, perhaps... **********************************************************/ -function elementDown($con, $element_id, $page_id, $position) { +function elementDown($element_id, $page_id, $position) { // Get information about the element to move down $sql = "SELECT indent_level, parent_id, element_order FROM element WHERE page_id = " . $page_id . " AND element_id = " . $element_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $down_indent_level = $row["indent_level"]; $down_element_order = $row["element_order"]; @@ -1531,8 +912,8 @@ . $down_element_order . " ORDER BY element_order"; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $up_element_id = $row["element_id"]; $up_element_order = $row["element_order"]; @@ -1552,8 +933,8 @@ . " AND element_order < " . $up_element_order; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $down_num = $row["down_num"]; // Add the element itself @@ -1570,7 +951,7 @@ . $up_element_order . " ORDER BY element_order"; - $rs = mysql_query($sql, $con); + $rs = mysql_tryquery($sql); // Flag to determine the end of this element's lineage $lineage = 1; @@ -1591,7 +972,7 @@ descendant affected by a move. */ - while (($row = mysql_fetch_array ($rs)) && $lineage == 1) { + while (($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) && $lineage == 1) { $desc_element_id = $row["element_id"]; $desc_indent_level = $row["indent_level"]; $desc_element_order = $row["element_order"]; @@ -1620,9 +1001,9 @@ . " AND element_order <= " . $stop_element_order . " ORDER BY element_order"; - $rs = mysql_query($sql, $con); + $rs = mysql_tryquery($sql); - while ($row = mysql_fetch_array ($rs)) { + while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { $mod_element_id = $row["element_id"]; $mod_indent_level = $row["indent_level"]; $mod_element_order = $row["element_order"]; @@ -1649,14 +1030,7 @@ . $page_id . " AND element_id = " . $mod_element_id; - if (!mysql_query ($mod_sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { // Success - mysql_query ("UNLOCK TABLES", $con); - } // moved an element up or down + mysql_tryquery($mod_sql); } // all affected elements @@ -1678,74 +1052,13 @@ } - -/********************************************************** -Function: elementIncrease -Author: Paul Bramscher -Last Modified: 09.12.2002 -*********************************************************** -Incoming: -$con Database connection string -$element_id Element to perform decrease on -$page_id Page the element is location on -$position Position on the page -*********************************************************** -Outgoing: -None -*********************************************************** -Purpose: -Increases the output size of the element. Note that the -HTML tag operates in reverse, with H1 typically being -larger than H5. So this increase effectively decreases the -numerical value of the tag. - -NOTE: This has been deprecated with the elementSize() -function. It is not currently being used. -**********************************************************/ -function elementIncrease($con, $element_id, $page_id, $position){ - - // Get current element size - $sql = "SELECT element_size FROM element WHERE element_id = " - . $element_id - . " AND page_id = " - . $page_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); - $element_size = $row["element_size"]; - - // Default to
if nothing specified - if ($element_size < 1) $element_size = 5; - - // Original was larger than 1. Note that we don't shrink smaller than 1. - else if ($element_size > 1) $element_size--; - - $sql = "UPDATE element SET element_size = " - . $element_size - . " WHERE page_id = " - . $page_id - . " AND element_id = " - . $element_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { // Success call the page back - mysql_query ("UNLOCK TABLES", $con); - header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); - } - -} - - + /********************************************************** Function: elementMultiFormat Author: Paul Bramscher -Last Modified: 06.25.2003 +Last Modified: 03.03.2004 *********************************************************** Incoming: -$con Database connection string $auto_font_style Corresponds to 0-5 CSS style styles $auto_indent_level Indent level upon which to apply the changes. @@ -1759,7 +1072,7 @@ particular indent level to the selected size on the supplied page id. **********************************************************/ -function elementMultiFormat($con, $auto_element_size, $auto_indent_level, $page_id){ +function elementMultiFormat($auto_element_size, $auto_indent_level, $page_id){ // Build the SQL $sql = "UPDATE element SET element_size = " @@ -1768,17 +1081,8 @@ . $page_id . " AND indent_level = " . $auto_indent_level; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { // Success call the page back - mysql_query ("UNLOCK TABLES", $con); - - header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); - } + mysql_tryquery($sql); + header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); } @@ -1786,10 +1090,9 @@ /********************************************************** Function: elementSize Author: Paul Bramscher -Last Modified: 02.18.2003 +Last Modified: 03.03.2004 *********************************************************** Incoming: -$con Database connection string $element_id Element to perform decrease on $page_id Page the element is location on $position Position on the page @@ -1805,7 +1108,7 @@ 5. This function is meant to deprecate the elementIncrease() and elementDecrease() pair of functions. **********************************************************/ -function elementSize($con, $element_id, $page_id, $position, $size){ +function elementSize($element_id, $page_id, $position, $size){ // Error trap if ($size < 1) $size = 0; @@ -1817,27 +1120,17 @@ . $page_id . " AND element_id = " . $element_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { // Success call the page back - mysql_query ("UNLOCK TABLES", $con); - header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); - } - + mysql_tryquery($sql); + header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); } /********************************************************** Function: elementUp Author: Paul Bramscher -Last Modified: 09.24.2002 +Last Modified: 03.03.2004 *********************************************************** Incoming: -$con Database connection string $element_id Element to move up $page_id Page the element is location on $position Position on the page @@ -1850,15 +1143,15 @@ element is the "up set" rather than the "down set". See comments under elementDown for further information. **********************************************************/ -function elementUp($con, $element_id, $page_id, $position) { +function elementUp($element_id, $page_id, $position) { // Get information about the element to move up $sql = "SELECT indent_level, parent_id, element_order FROM element WHERE page_id = " . $page_id . " AND element_id = " . $element_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $up_indent_level = $row["indent_level"]; $up_element_order = $row["element_order"]; @@ -1871,8 +1164,8 @@ . $up_element_order . " ORDER BY element_order DESC"; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $down_element_id = $row["element_id"]; $down_element_order = $row["element_order"]; @@ -1892,8 +1185,8 @@ . " AND element_order < " . $up_element_order; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $down_num = $row["down_num"]; // Add the element itself @@ -1909,8 +1202,7 @@ . " AND element_order > " . $up_element_order . " ORDER BY element_order"; - - $rs = mysql_query($sql, $con); + $rs = mysql_tryquery($sql); // Flag to determine the end of this element's lineage $lineage = 1; @@ -1931,7 +1223,7 @@ descendant affected by a move. */ - while (($row = mysql_fetch_array ($rs)) && $lineage == 1) { + while (($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) && $lineage == 1) { $desc_element_id = $row["element_id"]; $desc_indent_level = $row["indent_level"]; $desc_element_order = $row["element_order"]; @@ -1960,9 +1252,9 @@ . " AND element_order <= " . $stop_element_order . " ORDER BY element_order"; - $rs = mysql_query($sql, $con); + $rs = mysql_tryquery($sql); - while ($row = mysql_fetch_array ($rs)) { + while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { $mod_element_id = $row["element_id"]; $mod_indent_level = $row["indent_level"]; $mod_element_order = $row["element_order"]; @@ -1989,16 +1281,7 @@ . $page_id . " AND element_id = " . $mod_element_id; - - if (!mysql_query ($mod_sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { // Success - mysql_query ("UNLOCK TABLES", $con); - } // moved an element up or down - + mysql_tryquery($mod_sql); } // all affected elements @@ -2013,12 +1296,12 @@ /********************************************************** Function: getMaxIndent Author: Paul Bramscher -Last Modified: 06.25.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Return the maximum indent level for the supplied page id. **********************************************************/ -function getMaxIndent($con, $page_id){ +function getMaxIndent($page_id){ // Initialize $max_indent = 0; @@ -2027,8 +1310,8 @@ $sql = "SELECT MAX(indent_level) AS max_indent FROM element WHERE page_id = " . $page_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $max_indent = $row["max_indent"]; return $max_indent; @@ -2038,7 +1321,7 @@ /********************************************************** Function: insertCoursePers Author: Paul Bramscher -Last Modified: 06.24.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Associates the incoming personnel information with the @@ -2047,7 +1330,7 @@ member (existing or newly created on the fly), or a non-indexed TA. **********************************************************/ -function insertCoursePers($con, $course_id, $faculty_id, +function insertCoursePers($course_id, $faculty_id, $page_id, $pers_email, $pers_firstname, $pers_lastname, $pers_type, $pers_account, $staff_id, $stafftitle_id){ @@ -2083,7 +1366,7 @@ // Check for uniqueness $faculty_name_display = $pers_firstname . " " . $pers_lastname; - $exists_id = existsFaculty($con, $pers_firstname, $pers_lastname); + $exists_id = existsFaculty($pers_firstname, $pers_lastname); if ($exists_id > 0) { $err_code = 1; @@ -2109,17 +1392,8 @@ . "', '" . $pers_email . "')"; - - mysql_query ("LOCK TABLE faculty WRITE", $con); - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - $new_faculty_id = mysql_insert_id($con); - mysql_query("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); + $new_faculty_id = mysql_insert_id(); // Now, build the SQL for the insert into course_personnel $sql = "INSERT INTO course_personnel (course_id, stafftitle_id, faculty_id) VALUES (" @@ -2163,18 +1437,7 @@ // Proceed if there are no error messages if ($err_code == 0) { - - // Failed - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - - // Succeeded - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Done. Call the PageScribe page back header("Location: scribe.phtml?page_id=" . $page_id . "#coursePers"); @@ -2186,15 +1449,14 @@ // Page header require_once ($GLOBAL_ADMIN_INC."scribe_header.phtml"); - printf("

Adding Course Personnel...

"); + printf("

Adding Course Personnel...

\n"); // Table printf("\n"); - printf("

\n"); - printf("Messages:
\n"); + printf("
\n"); + printf("Messages:
\n"); printf("%s", $err_msg); - printf("

\n"); - printf("
\n"); + printf("

\n"); printf("
\n"); // Page footer @@ -2208,13 +1470,13 @@ /********************************************************** Function: insertScribeLabel Author: Paul Bramscher -Last Modified: 07.03.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Inserts a "label" or free-text type PageScribe element onto a PageScribe page. **********************************************************/ -function insertScribeLabel($con, $element_descr, $label, $label_url, $place_array_HTML, $page_id){ +function insertScribeLabel($element_descr, $label, $label_url, $place_array_HTML, $page_id){ // Clean up strings $element_descr = textInmySQL($element_descr); @@ -2245,22 +1507,12 @@ $position = $place_array[4]; // First probe for the new parent_id - $parent_id = parentProbe($con, $page_id, $prev_element_order, $prev_indent_level); + $parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); // Next, bump all of the following items down by one $sql = "UPDATE element SET element_order = element_order + 1 WHERE page_id = " . $page_id . " AND element_order >= " . $prev_element_order; - - // Make the change - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - } - + mysql_tryquery($sql); // Next insert the new label $sql = "INSERT INTO element (page_id, label, label_url, element_descr, element_order, indent_level,parent_id) VALUES (" @@ -2270,17 +1522,8 @@ . $element_descr . "', " . $prev_element_order . ", " . $prev_indent_level . ", " - . $parent_id . ")"; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - // Success - mysql_query ("UNLOCK TABLES", $con); - } + . $parent_id . ")"; + mysql_tryquery($sql); } header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); @@ -2290,12 +1533,12 @@ /********************************************************** Function: insertScribeLocation Author: Paul Bramscher -Last Modified: 07.03.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Inserts location type element onto a PageScribe page. **********************************************************/ -function insertScribeLocation($con, $location_id, $place_array_HTML, $page_id){ +function insertScribeLocation($location_id, $place_array_HTML, $page_id){ // Error checking if ($location_id > 0) { @@ -2311,21 +1554,12 @@ $position = $place_array[4]; // First probe for the new parent_id - $parent_id = parentProbe($con, $page_id, $prev_element_order, $prev_indent_level); + $parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); // Next, bump all of the following items down by one $sql = "UPDATE element SET element_order = element_order + 1 WHERE page_id = " . $page_id . " AND element_order >= " . $prev_element_order; - - // Make the change - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Next insert the new location $sql = "INSERT INTO element (page_id, location_id, element_order, indent_level,parent_id) VALUES (" @@ -2334,15 +1568,7 @@ . $prev_element_order . ", " . $prev_indent_level . ", " . $parent_id . ")"; - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - // Success - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); } @@ -2353,12 +1579,12 @@ /********************************************************** Function: insertScribeResource Author: Paul Bramscher -Last Modified: 07.03.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Inserts a resource type element onto a PageScribe page. **********************************************************/ -function insertScribeResource($con, $place_array_HTML, $resource_id, $page_id){ +function insertScribeResource($place_array_HTML, $resource_id, $page_id){ // Error checking if ($resource_id > 0) { @@ -2374,21 +1600,12 @@ $position = $place_array[4]; // First probe for the new parent_id - $parent_id = parentProbe($con, $page_id, $prev_element_order, $prev_indent_level); + $parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); // Next, bump all of the following items down by one $sql = "UPDATE element SET element_order = element_order + 1 WHERE page_id = " . $page_id . " AND element_order >= " . $prev_element_order; - - // Make the change - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Next insert the new resource $sql = "INSERT INTO element (page_id, resource_id, element_order, indent_level,parent_id) VALUES (" @@ -2397,15 +1614,7 @@ . $prev_element_order . ", " . $prev_indent_level . ", " . $parent_id . ")"; - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - // Success - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); } @@ -2416,14 +1625,14 @@ /********************************************************** Function: insertScribeRQS Author: Paul Bramscher -Last Modified: 07.03.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: This function performs the "RQS harvest". For the supplied subject id, collect all of the resources and insert them as elements onto a PageScribe page. **********************************************************/ -function insertScribeRQS($con, $place_array_HTML, $subject_id, $page_id){ +function insertScribeRQS($place_array_HTML, $subject_id, $page_id){ // Error checking if ($subject_id > 0) { @@ -2439,12 +1648,12 @@ $position = $place_array[4]; // First probe for the new parent_id - $parent_id = parentProbe($con, $page_id, $prev_element_order, $prev_indent_level); + $parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); // Identify the number of new elements to add $sql = "SELECT COUNT(*) as num_rqs from res_sub_infotype WHERE subject_id = " . $subject_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); // Pull out the possible display values $num_rqs = $row["num_rqs"]; @@ -2457,16 +1666,7 @@ . $num_rqs . " WHERE page_id = " . $page_id . " AND element_order >= " . $prev_element_order; - - // Make the change - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Cycle through the resources $sql = "SELECT rsi.resource_id, r.title @@ -2475,8 +1675,8 @@ WHERE subject_id = " . $subject_id . " ORDER BY r.title"; - $rs = mysql_query($sql, $con); - while ($row = mysql_fetch_array ($rs)) { + $rs = mysql_tryquery($sql); + while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { // Fetch resource $resource_id = $row["resource_id"]; @@ -2488,15 +1688,7 @@ . $prev_element_order . ", " . $prev_indent_level . ", " . $parent_id . ")"; - if (!mysql_query ($i_sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - // Success - mysql_query ("UNLOCK TABLES", $con); - } // successful import + mysql_tryquery($i_sql); // Increment element order $prev_element_order++; @@ -2515,12 +1707,12 @@ /********************************************************** Function: insertScribeRQSLink Author: Paul Bramscher -Last Modified: 07.03.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Inserts an RQS subject page element onto a PageScribe page. **********************************************************/ -function insertScribeRQSLink($con, $place_array_HTML, $subject_id, $page_id){ +function insertScribeRQSLink($place_array_HTML, $subject_id, $page_id){ // Error checking if ($subject_id > 0) { @@ -2536,21 +1728,12 @@ $position = $place_array[4]; // First probe for the new parent_id - $parent_id = parentProbe($con, $page_id, $prev_element_order, $prev_indent_level); + $parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); // Next, bump all of the following items down by one $sql = "UPDATE element SET element_order = element_order + 1 WHERE page_id = " . $page_id . " AND element_order >= " . $prev_element_order; - - // Make the change - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Next insert the new resource $sql = "INSERT INTO element (page_id, subject_id, element_order, indent_level,parent_id) VALUES (" @@ -2559,15 +1742,7 @@ . $prev_element_order . ", " . $prev_indent_level . ", " . $parent_id . ")"; - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - // Success - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); } @@ -2578,12 +1753,12 @@ /********************************************************** Function: insertScribeService Author: Paul Bramscher -Last Modified: 07.03.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Inserts a service type element onto a PageScribe page. **********************************************************/ -function insertScribeService($con, $place_array_HTML, $page_id, $service_id){ +function insertScribeService($place_array_HTML, $page_id, $service_id){ // Error checking if ($service_id > 0) { @@ -2599,21 +1774,12 @@ $position = $place_array[4]; // First probe for the new parent_id - $parent_id = parentProbe($con, $page_id, $prev_element_order, $prev_indent_level); + $parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); // Next, bump all of the following items down by one $sql = "UPDATE element SET element_order = element_order + 1 WHERE page_id = " . $page_id . " AND element_order >= " . $prev_element_order; - - // Make the change - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Next insert the new service $sql = "INSERT INTO element (page_id, service_id, element_order, indent_level,parent_id) VALUES (" @@ -2622,15 +1788,7 @@ . $prev_element_order . ", " . $prev_indent_level . ", " . $parent_id . ")"; - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - // Success - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); } @@ -2641,12 +1799,12 @@ /********************************************************** Function: insertScribeStaff Author: Paul Bramscher -Last Modified: 04.22.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Inserts a staffperson as an element on a PageScribe page. **********************************************************/ -function insertScribeStaff($con, $place_array_HTML, $staff_id, $page_id){ +function insertScribeStaff($place_array_HTML, $staff_id, $page_id){ // Split by comma separated values $place_array = split(",", $place_array_HTML); @@ -2659,21 +1817,12 @@ $position = $place_array[4]; // First probe for the new parent_id - $parent_id = parentProbe($con, $page_id, $prev_element_order, $prev_indent_level); + $parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); // Next, bump all of the following items down by one $sql = "UPDATE element SET element_order = element_order + 1 WHERE page_id = " . $page_id . " AND element_order >= " . $prev_element_order; - - // Make the change - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Next insert the new staff $sql = "INSERT INTO element (page_id, staff_id, element_order, indent_level,parent_id) VALUES (" @@ -2682,15 +1831,7 @@ . $prev_element_order . ", " . $prev_indent_level . ", " . $parent_id . ")"; - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - // Success - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); } @@ -2699,7 +1840,7 @@ /********************************************************** Function: pageLoadStats Author: Paul Bramscher -Last Modified: 04.23.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Logs a statistical entry for a PageScribe/CourseLib page @@ -2710,7 +1851,7 @@ that the database doesn't grow too large. Currently there exists no automatic mechanism to purge or archive stats. **********************************************************/ -function pageLoadStats($con, $page_id){ +function pageLoadStats($page_id){ // Add a row for page usage @@ -2726,16 +1867,7 @@ . ", now(), '" . $user_ip . "')"; - - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } // bad write - else { - mysql_query("UNLOCK TABLES", $con); - - } // good write to the pagestats table + mysql_tryquery($sql); } @@ -2743,7 +1875,7 @@ /********************************************************** Function: pageTemplate Author: Paul Bramscher -Last Modified: 12.15.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Performs the clone or copy page functionality. Note that @@ -2758,13 +1890,13 @@ on the new page are all new and must be calculated on the fly. **********************************************************/ -function pageTemplate($con, $page_id, $sess_staff_id, $sess_staff_account){ +function pageTemplate($page_id, $sess_staff_id, $sess_staff_account){ // First copy the page elements $sql = "SELECT * FROM page WHERE page_id = " . $page_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); // Fetch results $style_id = $row["style_id"]; @@ -2824,34 +1956,22 @@ . $up_text . "')"; - //printf("sql was: %s", $sql); - - mysql_query ("LOCK TABLE page WRITE", $con); - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - $new_page_id = mysql_insert_id($con); - mysql_query("UNLOCK TABLES", $con); - } - + mysql_tryquery($sql); + $new_page_id = mysql_insert_id(); // If a new stub was created, and this happens to be a course page, get the course id. if ($new_page_id > 0 && $pagetype_id == 3) { - $course_id = lookupfield($con, "course", "page_id", $page_id, "course_id"); + $course_id = lookupfield("course", "page_id", $page_id, "course_id"); } if ($course_id > 0 && $new_page_id > 0) { - // Copy the course elements $sql = "SELECT * FROM course WHERE page_id = " . $page_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); // Fetch results $coursesub_id = $row["coursesub_id"]; @@ -2916,20 +2036,11 @@ $introheader2 . "', '" . $intromessage2 . "')"; - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - } - } // was a CourseScribe type page + mysql_tryquery($sql); + } // was a CourseScribe type page // Next, copy all elements - - // This is not the most efficient method, but it works for now. @@ -2937,8 +2048,8 @@ . $page_id . " ORDER BY element_id"; - $rs = mysql_query($sql, $con); - while ($row = mysql_fetch_array ($rs)) { + $rs = mysql_tryquery($sql); + while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { // Fetch previous values $element_id = $row["element_id"]; @@ -2971,7 +2082,7 @@ if (strlen($element_descr) > 0) $element_descr = textInmySQL($element_descr); // Calculate the new parent if needed - if ($parent_id > 0) $parent_id = parentProbe($con, $new_page_id, $element_order, $indent_level); + if ($parent_id > 0) $parent_id = parentProbe($new_page_id, $element_order, $indent_level); // Insert the element onto the new page $clone_sql = "INSERT INTO element ( @@ -3004,14 +2115,7 @@ $indent_level . ")"; // Execute the query - if (!mysql_query($clone_sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - } + mysql_tryquery($clone_sql); } @@ -3023,13 +2127,13 @@ /********************************************************** Function: pageTemplateConfirm Author: Paul Bramscher -Last Modified: 11.07.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Prompts the author that he/she is about to template a page. **********************************************************/ -function pageTemplateConfirm($con, $page_id, $sess_staff_id, $sess_staff_account){ +function pageTemplateConfirm($page_id, $sess_staff_id, $sess_staff_account){ // Load globals include("global_vars.php"); @@ -3042,7 +2146,7 @@ printf("\n"); printf("%s: Confirm Clone & Load\n", $GLOBAL_SYS_NAME); printf("\n", $GLOBAL_ADMIN_CSS); - printf(""); + printf("\n"); // Table printf("
\n"); @@ -3050,7 +2154,7 @@ printf("\n"); printf("Confirm Clone & Load"); printf("\n"); - printf("
\n"); + printf("\n"); // Collect information $sql = "SELECT @@ -3066,8 +2170,8 @@ . $page_id . " AND p.staff_coordinator = s.staff_id"; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $page_title = strip_tags($row["page_title"]); $first_name = $row["first_name"]; @@ -3075,9 +2179,8 @@ $staff_email = $row["staff_email"]; $staff_name = $first_name . " " . $last_name; - printf("Page Title: %s
", $page_title); - printf("Coordinator: %s %s

", $staff_name, $staff_email, $staff_email); - + printf("Page Title: %s
\n", $page_title); + printf("Coordinator: %s %s

\n", $staff_name, $staff_email, $staff_email); printf("Before cloning this page, please consider seeking permission from and/or giving "); printf("attribution to the page author(s) of the original work.

\n"); @@ -3088,7 +2191,7 @@ printf("\n", $sess_staff_account); printf("\n", $sess_staff_id); printf("
\n"); - printf("\n"); + printf("

\n"); // Link to return to admin console adminReturn(""); @@ -3103,13 +2206,13 @@ /********************************************************** Function: parentIs Author: Paul Bramscher -Last Modified: 04.23.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Tests the supplied element to determine whether it has any children. **********************************************************/ -function parentIs($con, $element_id, $page_id){ +function parentIs($element_id, $page_id){ // First initialize the number of children $num_children = 0; @@ -3118,8 +2221,8 @@ . $page_id . " AND parent_id = " . $element_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $num_children = $row["num_children"]; return $num_children; @@ -3129,7 +2232,7 @@ /********************************************************** Function: parentProbe Author: Paul Bramscher -Last Modified: 11.20.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Probes for a parent (if not a root-level element) of the @@ -3138,7 +2241,7 @@ looking for the first previous element with an indent (generation) level of precisely one less. **********************************************************/ -function parentProbe($con, $page_id, $prev_element_order, $prev_indent_level){ +function parentProbe($page_id, $prev_element_order, $prev_indent_level){ // If the item's indent level is 0, it is its own parent. Return 0. if ($prev_indent_level < 1) $parent_id = 0; @@ -3158,8 +2261,8 @@ // Found parent tag $found = 0; - $rs = mysql_query($sql, $con); - while (($row = mysql_fetch_array ($rs)) && $found == 0) { + $rs = mysql_tryquery($sql); + while (($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) && $found == 0) { /* Cycle through the list, looking for the first item with an indent of less. */ @@ -3185,7 +2288,7 @@ /********************************************************** Function: pasteElement Author: Paul Bramscher -Last Modified: 04.23.2003 +Last Modified: 03.11.2004 *********************************************************** Purpose: Copies the user's copy/paste buffer onto the supplied @@ -3193,16 +2296,16 @@ This sort of logic required a fair amount of coffee to work out. **********************************************************/ -function pasteElement($con, $element_order, $indent_level, $page_id, $position, $sess_staff_id) { +function pasteElement($element_order, $indent_level, $page_id, $position, $sess_staff_id) { // Debug mode: 0=off, 1=on. $debug = 0; if ($debug == 1) { - printf("

This will eventually paste your elements... Close, but not quite bug-free.


\n"); - printf("On page id: %d
\n", $page_id); - printf("It will go in order #%d
\n", $element_order); - printf("Afterwards you'll return to pos: %d
\n", $position); + printf("

Element Paste - Debug Mode


\n"); + printf("On page id: %d
\n", $page_id); + printf("It will go in order #%d
\n", $element_order); + printf("Afterwards you'll return to pos: %d
\n", $position); } @@ -3210,11 +2313,11 @@ $sql = "SELECT COUNT(*) as buffer_size FROM pastebuffer WHERE paste_staff_id = " . $sess_staff_id . " ORDER BY element_order"; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $buffer_size = $row["buffer_size"]; - if ($debug == 1) printf("Number of elements in buffer: %s
\n", $buffer_size); + if ($debug == 1) printf("Number of elements in buffer: %s
\n", $buffer_size); // Determine parent ID of first pasted element @@ -3222,8 +2325,8 @@ . $page_id . " AND element_order = " . $element_order; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $adjust_parent_id = $row["element_id"]; if ($debug == 1) printf("Parent of first element will be: %d
", $adjust_parent_id); @@ -3237,28 +2340,20 @@ . " AND element_order >= " . $element_order; - if ($debug == 1) printf("bump down sql was: %s
", $sql); - + if ($debug == 1) printf("bump down sql was: %s
\n", $sql); - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Select from the paste buffer $sql = "SELECT * FROM pastebuffer WHERE paste_staff_id = " . $sess_staff_id . " ORDER BY element_order"; - $rs = mysql_query($sql, $con); + $rs = mysql_tryquery($sql); // row count $row_num = 0; - while ($row = mysql_fetch_array ($rs)) { + while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { // Load copy-paste buffer elements $copy_indent_level = $row["indent_level"]; @@ -3313,15 +2408,15 @@ else $adjust_indent_level = $last_adjust_indent_level; // Determine parent for all but the first item - $adjust_parent_id = parentProbe($con, $page_id, $adjust_element_order, $adjust_indent_level); + $adjust_parent_id = parentProbe($page_id, $adjust_element_order, $adjust_indent_level); // Debugging if ($debug == 1) { - printf("new position start indent:
"); + printf("new position start indent:
\n"); printf("last copy indent: %d, ", $last_copy_indent_level); - printf("this copy indent: %d
", $copy_indent_level); + printf("this copy indent: %d
\n", $copy_indent_level); printf("last adjust indent: %d, ", $last_adjust_indent_level); - printf("this adjust indent: %d
", $adjust_indent_level); + printf("this adjust indent: %d
\n", $adjust_indent_level); } @@ -3368,26 +2463,18 @@ . ")"; // Debugging - if ($debug == 1) printf("insert sql was: %s
\n", $p_sql); + if ($debug == 1) printf("insert sql was: %s
\n", $p_sql); // Perform the write - mysql_query ("LOCK TABLE element WRITE", $con); - if (!mysql_query($p_sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - $paste_element_id = mysql_insert_id($con); - mysql_query("UNLOCK TABLES", $con); - } + mysql_tryquery($p_sql); + $paste_element_id = mysql_insert_id(); // Debugging if ($debug == 1) { - printf("insert sql was: %s
\n", $p_sql); - printf("inserted id was: %d
\n", $paste_element_id); - printf("adjust parent was: %d
\n", $adjust_parent_id); - printf("adjust order was: %d

\n", $adjust_element_order); + printf("insert sql was: %s
\n", $p_sql); + printf("inserted id was: %d
\n", $paste_element_id); + printf("adjust parent was: %d
\n", $adjust_parent_id); + printf("adjust order was: %d

\n", $adjust_element_order); } // Track some variables @@ -3404,7 +2491,7 @@ /********************************************************** Function: populateGenArray Author: Paul Bramscher -Last Modified: 06.30.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Builds an array from 0 (unused empty placeholder) to N, @@ -3414,7 +2501,7 @@ is created outside the function. This function modifies and returns it. **********************************************************/ -function populateGenArray($con, &$genArray, $page_id) { +function populateGenArray(&$genArray, $page_id) { // Initialize the 0th (unused) array element $genArray[0] = 0; @@ -3425,13 +2512,12 @@ WHERE page_id = " . $page_id . " ORDER BY element_order"; - - $rs = mysql_query($sql, $con); + $rs = mysql_tryquery($sql); // Start populating generation array subscript [1] $rowcount = 1; - while ($row = mysql_fetch_array ($rs)) { + while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { // Fetch values $element_order = $row["element_order"]; @@ -3453,7 +2539,7 @@ /********************************************************** Function: scribePublish Author: Paul Bramscher -Last Modified: 04.23.2003 +Last Modified: 03.11.2004 *********************************************************** Purpose: Performs the PageScribe/CourseLib page publish functionality. @@ -3467,7 +2553,7 @@ page for published pages) if there are concerns about page load performance issues with the fully dynamic version. **********************************************************/ -function scribePublish($con, $page_id) { +function scribePublish($page_id) { /* @@ -3491,8 +2577,8 @@ // printf("sql was: %s", $sql); - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $coursesub_id = $row["coursesub_id"]; $pagetype_id = $row["pagetype_id"]; @@ -3511,18 +2597,18 @@ printf("\n"); printf("%s: Missing Information\n", $GLOBAL_SYS_NAME); printf("\n", $GLOBAL_ADMIN_CSS); - printf(""); + printf("\n"); // Draw form heading printf("

%s: Missing Information

\n", $GLOBAL_SYS_NAME); // Table printf("\n"); - printf("

\n"); - printf("Messages:
\n"); + printf("
\n"); + printf("Messages:
\n"); printf("CourseLib pages may not be published without a course designator. "); printf("This is a required field -- please go back and select a course designator. "); - printf("If one does not apply, this should probably be a PageScribe page instead.

\n"); + printf("If one does not apply, this should probably be a PageScribe page instead.

\n"); printf("
\n"); @@ -3552,15 +2638,7 @@ // Clear out existing published information // This is important, also, to get rid of a NULL value before performing a CONCAT below. $sql = "UPDATE page set pageHTML = '' WHERE page_id = " . $page_id; - - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } // bad write - else { - mysql_query("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Open the filepointer for a screen dump $fp = fopen ($page_loc, "r"); @@ -3582,16 +2660,7 @@ // Concatenate the stream into the pageHTML field $sql = "UPDATE page set pageHTML = CONCAT(pageHTML,'" . $iostream_fix . "') WHERE page_id = " . $page_id; - - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - printf("sql was: %s
", $sql); - bailout(); - } // bad write - else { - mysql_query("UNLOCK TABLES", $con); - } // good write + mysql_tryquery($sql); } // Close up the open file pointer @@ -3599,20 +2668,11 @@ // Set published flag to 1 $sql = "UPDATE page set published = '1' WHERE page_id = " . $page_id; - - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } // bad write - else { - mysql_query("UNLOCK TABLES", $con); - - } // good write + mysql_tryquery($sql); } // end open file pointer - end of comment-out */ + end of comment-out */ /********************************************************************* ** Comment out this portion if static page functionality is desired ** @@ -3620,16 +2680,7 @@ // Set published flag to 1 $sql = "UPDATE page set published = '1' WHERE page_id = " . $page_id; - - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } // bad write - else { - mysql_query("UNLOCK TABLES", $con); - - } // good write + mysql_tryquery($sql); /*********************** ** End of comment-out ** @@ -3645,125 +2696,24 @@ /********************************************************** Function: scribeUnpublish Author: Paul Bramscher -Last Modified: 04.23.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Unpublishes the supplied page id. Note that we set both the pageHTML to NULL and flip the published flag back to 0 (FALSE). **********************************************************/ -function scribeUnpublish($con, $page_id) { +function scribeUnpublish($page_id) { // Build the SQL $sql = "UPDATE page SET pageHTML = NULL, published = '0' WHERE page_id =" . $page_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); header("Location: scribe.phtml?page_id=" . $page_id); } /********************************************************** -Function: siblingElderProbe -Author: Paul Bramscher -Last Modified: 04.23.2003 -*********************************************************** -Purpose: -Tests the supplied element to see whether it has an elder -sibling. If so, then this element (and descendants) may -be moved up a position and the up arrow becomes available -on the PageScribe/CourseLib authoring page. -**********************************************************/ -function siblingElderProbe($con, $page_id, $place_array){ - - // Break apart place array - $prev_element_id = $place_array[0]; - $prev_element_order = $place_array[1]; - $prev_indent_level = $place_array[2]; - $prev_parent_id = $place_array[3]; - $prev_position = $place_array[4]; - - // Error checking - if ($prev_indent_level < 1) $prev_indent_level = 0; - if ($prev_parent_id < 1) $prev_parent_id = 0; - if ($prev_element_order < 1) $prev_element_order = 0; - - // ID of elder sibling - $element_id = 0; - - $sql = "SELECT element_id, element_order FROM element WHERE page_id = " - . $page_id - . " AND indent_level = " - . $prev_indent_level - . " AND parent_id = " - . $prev_parent_id - . " AND element_order < " - . $prev_element_order - . " ORDER BY element_order DESC LIMIT 1"; - - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); - $element_id = $row["element_id"]; - - return $element_id; -} - - -/********************************************************** -Function: siblingYoungerProbe -Author: Paul Bramscher -Last Modified: 04.23.2003 -*********************************************************** -Purpose: -Tests the supplied element to see whether it has a younger -sibling. If so, then this element (and descendants) may -be moved down a position and the down arrow becomes available -on the PageScribe/CourseLib authoring page. -**********************************************************/ -function siblingYoungerProbe($con, $page_id, $place_array){ - - // Break apart place array - $prev_element_id = $place_array[0]; - $prev_element_order = $place_array[1]; - $prev_indent_level = $place_array[2]; - $prev_parent_id = $place_array[3]; - $prev_position = $place_array[4]; - - // Error checking - if ($prev_indent_level < 1) $prev_indent_level = 0; - if ($prev_parent_id < 1) $prev_parent_id = 0; - if ($prev_element_order < 1) $prev_element_order = 0; - - // Younger sibling ID - $element_id = 0; - - $sql = "SELECT element_id, element_order FROM element WHERE page_id = " - . $page_id - . " AND indent_level = " - . $prev_indent_level - . " AND parent_id = " - . $prev_parent_id - . " AND element_order > " - . $prev_element_order - . " ORDER BY element_order LIMIT 1"; - - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); - $element_id = $row["element_id"]; - - return $element_id; - -} - - -/********************************************************** Function: sibProbeElder Author: Paul Bramscher Last Modified: 06.30.2003 @@ -3854,7 +2804,7 @@ /********************************************************** Function: toggleTOCDisplay Author: Paul Bramscher -Last Modified: 04.24.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Flips the flag to 1 (TRUE) or 0 (FALSE) for the display @@ -3862,24 +2812,13 @@ ToC is autogenerated and includes the root elements on the page. **********************************************************/ -function toggleTOCDisplay($con, $display_toc, $page_id) { +function toggleTOCDisplay($display_toc, $page_id) { $sql = "UPDATE page SET display_toc = " . $display_toc . " WHERE page_id = " . $page_id; - - // Failed - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - - // Succeeded - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Call the PageScribe page back header("Location: scribe.phtml?page_id=" . $page_id); @@ -3889,7 +2828,7 @@ /********************************************************** Function: toggleTOCWrap Author: Paul Bramscher -Last Modified: 12.15.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Flips the flag to 1 (TRUE) or 0 (FALSE) for the wrapping @@ -3897,24 +2836,13 @@ ToC is autogenerated and includes the root elements on the page. The wrap results in a two-column view of the ToC. **********************************************************/ -function toggleTOCWrap($con, $page_id, $wrap_toc) { +function toggleTOCWrap($page_id, $wrap_toc) { $sql = "UPDATE page SET wrap_toc = " . $wrap_toc . " WHERE page_id = " . $page_id; - - // Failed - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - - // Succeeded - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Call the PageScribe page back header("Location: scribe.phtml?page_id=" . $page_id); @@ -3924,7 +2852,7 @@ /********************************************************** Function: toggleUpDisplay Author: Paul Bramscher -Last Modified: 04.24.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Toggles the display of the [return to top] text on the @@ -3934,28 +2862,17 @@ will also insert a preliminary value as passed from the default string setting on the scribe authoring page. **********************************************************/ -function toggleUpDisplay($con, $display_up, $page_id, $up_text) { +function toggleUpDisplay($display_up, $page_id, $up_text) { // Collect some data on the current up text - $current_up_text = lookupField($con, "page", "page_id", $page_id, "up_text"); + $current_up_text = lookupField("page", "page_id", $page_id, "up_text"); // Toggle the flag to TRUE or FALSE $sql = "UPDATE page SET display_up = " . $display_up . " WHERE page_id = " . $page_id; - - // Failed - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - - // Succeeded - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); /* If the current up_text is blank, and the user has toggled ON, then insert the default wording. */ @@ -3964,18 +2881,7 @@ . $up_text . "' WHERE page_id = " . $page_id; - - // Failed - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - - // Succeeded - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); } // Call the PageScribe page back @@ -3986,13 +2892,13 @@ /********************************************************** Function: toggleUpText Author: Paul Bramscher -Last Modified: 04.24.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Changes the [return to top] text for the supplied page id, on a given page id before each new root element. **********************************************************/ -function toggleUpText($con, $page_id, $up_text) { +function toggleUpText($page_id, $up_text) { // Clean the string $up_text = textInmySQL($up_text); @@ -4002,18 +2908,7 @@ . $up_text . "' WHERE page_id = " . $page_id; - - // Failed - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - - // Succeeded - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Call the PageScribe page back header("Location: scribe.phtml?page_id=" . $page_id); @@ -4023,7 +2918,7 @@ /********************************************************** Function: toggleURLDisplay Author: Paul Bramscher -Last Modified: 04.24.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: This function updates the display_urls field in the @@ -4039,25 +2934,14 @@ URL's in edit mode for a quick visual inspection without having to resort to the user interface. **********************************************************/ -function toggleURLDisplay($con, $display_urls, $page_id) { +function toggleURLDisplay($display_urls, $page_id) { // Build the SQL $sql = "UPDATE page SET display_urls = " . $display_urls . " WHERE page_id = " . $page_id; - - // Failed - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - - // Succeeded - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Call the PageScribe page back header("Location: scribe.phtml?page_id=" . $page_id); @@ -4066,29 +2950,22 @@ /********************************************************** Function: updatePageDebug Author: Paul Bramscher -Last Modified: 04.24.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Updates the flag for page debug to 1 (TRUE) or 0 (FALSE). + +Notes: This is not currently used. Potentially we could +utilize this flag when TRUE, to run the debugger every +time a page is loaded. **********************************************************/ -function updatePageDebug($con, $page_debug, $page_id) { +function updatePageDebug($page_debug, $page_id) { $sql = "UPDATE page SET page_debug = " . $page_debug . " WHERE page_id = " . $page_id; - - // Failed - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - - // Succeeded - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Call the PageScribe page back header("Location: scribe.phtml?page_id=" . $page_id); @@ -4098,12 +2975,12 @@ /********************************************************** Function: updatePageHeader Author: Paul Bramscher -Last Modified: 01.27.2004 +Last Modified: 03.03.2004 *********************************************************** Purpose: -Updates the supplie page id's pageheader +Updates the supplied page id's pageheader **********************************************************/ -function updatePageHeader($con, $page_id, $pageheader) { +function updatePageHeader($page_id, $pageheader) { // Clean up if (strlen($pageheader) > 0) $pageheader = textInmySQL($pageheader); @@ -4112,18 +2989,7 @@ . $pageheader . "' WHERE page_id = " . $page_id; - - // Failed - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - - // Succeeded - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Call the PageScribe page back header("Location: scribe.phtml?page_id=" . $page_id); @@ -4133,29 +2999,18 @@ /********************************************************** Function: updatePageTitleStyle Author: Paul Bramscher -Last Modified: 11.21.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Updates the style class for the supplied page_id **********************************************************/ -function updatePageTitleStyle($con, $page_id, $pagetitle_style) { +function updatePageTitleStyle($page_id, $pagetitle_style) { $sql = "UPDATE page SET pagetitle_style = " . $pagetitle_style . " WHERE page_id = " . $page_id; - - // Failed - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - - // Succeeded - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Call the PageScribe page back header("Location: scribe.phtml?page_id=" . $page_id); @@ -4165,7 +3020,7 @@ /********************************************************** Function: updateScribeCourse Author: Paul Bramscher -Last Modified: 06.25.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Updates the supplied field and value for the course id. @@ -4173,7 +3028,7 @@ there were modifications which affect the title (subject, designator, or section). **********************************************************/ -function updateScribeCourse($con, $course_id, $field_name, $field_value, $page_id) { +function updateScribeCourse($course_id, $field_name, $field_value, $page_id) { // Clean up for entry if (strlen($field_value) > 0) $field_value = textInmySQL($field_value); @@ -4190,15 +3045,7 @@ . $course_id . " AND page_id = " . $page_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); } @@ -4213,26 +3060,17 @@ . $page_id . ")"; - // Write the new row to the database - mysql_query ("LOCK TABLE course WRITE", $con); - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - $course_id = mysql_insert_id($con); - mysql_query("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); + $course_id = mysql_insert_id(); } - updateScribeCourseConcat($con, $course_id, $page_id); + updateScribeCourseConcat($course_id, $page_id); } /********************************************************** Function: updateScribeCourseConcat Author: Paul Bramscher -Last Modified: 04.24.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: This function updates a CourseLib course title of the @@ -4243,7 +3081,7 @@ mySQL. We needed to present a completely ordered list of courses -- not merely by course subject. **********************************************************/ -function updateScribeCourseConcat($con, $course_id, $page_id) { +function updateScribeCourseConcat($course_id, $page_id) { // Fetch course related information $sql = "SELECT @@ -4260,8 +3098,8 @@ WHERE course_id = " . $course_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $page_title = $row["page_title"]; $coursesub_id = $row["coursesub_id"]; @@ -4293,15 +3131,7 @@ . $course_concat . "' WHERE course_id = " . $course_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); header("Location: scribe.phtml?page_id=" . $page_id); @@ -4310,7 +3140,7 @@ /********************************************************** Function: updateScribeElement Author: Paul Bramscher -Last Modified: 07.01.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Updates a PageScribe element. This function handles the @@ -4318,7 +3148,7 @@ descriptions -- as well as customized descriptions for any other element type. **********************************************************/ -function updateScribeElement($con, $element_descr, +function updateScribeElement($element_descr, $element_id, $label, $label_flag, $label_url, $page_id, $position) { // Problem flagging @@ -4363,15 +3193,7 @@ . $page_id . " AND element_id = " . $element_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); } @@ -4389,15 +3211,7 @@ . $page_id . " AND element_id = " . $element_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); } @@ -4414,15 +3228,7 @@ . $page_id . " AND element_id = " . $element_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); } @@ -4436,12 +3242,12 @@ /********************************************************** Function: updateScribeHeader Author: Paul Bramscher -Last Modified: 04.24.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Updates the page title for the supplied page id. **********************************************************/ -function updateScribeHeader($con, $course_id, $page_id, $page_title, $pagetype_id) { +function updateScribeHeader($course_id, $page_id, $page_title, $pagetype_id) { // Clean up strings $page_title = textInmySQL($page_title); @@ -4451,18 +3257,10 @@ . $page_title . "' WHERE page_id =" . $page_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // Update the concatenated course title if this is a course page - if ($pagetype_id == 3) updateScribeCourseConcat($con, $course_id, $page_id); + if ($pagetype_id == 3) updateScribeCourseConcat($course_id, $page_id); header("Location: scribe.phtml?page_id=" . $page_id); @@ -4472,27 +3270,19 @@ /********************************************************** Function: updateScribeStyle Author: Paul Bramscher -Last Modified: 04.24.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Changes the style definition for the supplied page id. **********************************************************/ -function updateScribeStyle($con, $page_id, $style_id) { +function updateScribeStyle($page_id, $style_id) { // Build the SQL $sql = "UPDATE page SET style_id = " . $style_id . " WHERE page_id =" . $page_id; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); header("Location: scribe.phtml?page_id=" . $page_id); } @@ -4501,30 +3291,19 @@ /********************************************************** Function: updateScribeUpdate Author: Paul Bramscher -Last Modified: 04.24.2003 +Last Modified: 03.03.2004 *********************************************************** Purpose: Modifies the PageScribe/CourseLib page "last updated" field. **********************************************************/ -function updateScribeUpdate($con, $page_id, $sess_staff_account) { +function updateScribeUpdate($page_id, $sess_staff_account) { $sql = "UPDATE page SET date_modified = now(), account_modified ='" . $sess_staff_account . "' WHERE page_id = " . $page_id; - - // Failed - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - - // Succeeded - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); } @@ -4590,4 +3369,4 @@ return $younger; } -?> +?> \ No newline at end of file