--- branches/paul/admin/include/subject_builder.php 2003/12/05 18:40:01 3 +++ branches/paul/admin/include/subject_builder.php 2004/03/18 19:24:54 67 @@ -1,8 +1,8 @@ -Last Modified: 11.04.2003 +Original Author: Paul Bramscher +Last Modified: 03.04.2004 *********************************************************** Comments: This small library brings together basic functionality to @@ -27,13 +27,13 @@ /********************************************************** Function: assignSubOtherSub Author: Paul Bramscher -Last Modified: 11.04.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Assigns other RQS pages (possibly multiple) to a given -subject and calls formSubject back again. +subject and calls the subject page editor back again. **********************************************************/ -function assignSubOtherSub($con, $subject_id_array, $subject_id) { +function assignSubOtherSub($subject_id_array, $subject_id) { // For every subject, assign it to the selected subject for ($subscript = 0; $subscript < sizeof($subject_id_array); $subscript++ ) { @@ -44,7 +44,7 @@ . " AND othersub_id = " . $subject_id_array[$subscript]; - $rs = mysql_query($sql); + $rs = mysql_tryquery($sql); if (mysql_num_rows($rs) == 0) { $sql = "INSERT INTO sub_othersub (subject_id, othersub_id) VALUES (" @@ -52,16 +52,7 @@ . ", " . $subject_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 sub_othersub + mysql_tryquery($sql); } // other subject not already assigned @@ -75,13 +66,13 @@ /********************************************************** Function: assignSubPage Author: Paul Bramscher -Last Modified: 06.17.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Assigns PageScribe pages (possibly multiple) to a given -subject and calls formSubject back again. +subject and calls the subject page editor back again. **********************************************************/ -function assignSubPage($con, $page_id_array, $subject_id) { +function assignSubPage($page_id_array, $subject_id) { // For every page, assign it to the selected subject for ($subscript = 0; $subscript < sizeof($page_id_array); $subscript++ ) { @@ -92,7 +83,7 @@ . " AND page_id = " . $page_id_array[$subscript]; - $rs = mysql_query($sql); + $rs = mysql_tryquery($sql); if (mysql_num_rows($rs) == 0) { $sql = "INSERT INTO sub_page (subject_id, page_id) VALUES (" @@ -100,16 +91,7 @@ . ", " . $page_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 sub_page + mysql_tryquery($sql); } // page not already assigned @@ -124,29 +106,21 @@ /********************************************************** Function: deleteSubjectBuilder Author: Paul Bramscher -Last Modified: 04.21.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Deletes an entry on an RQS page, based on a triple composite primary key of resource, subject and information type. **********************************************************/ -function deleteSubjectBuilder($con, $infotype_id, $resource_id, $subject_id) { +function deleteSubjectBuilder($infotype_id, $resource_id, $subject_id) { // Find the default information type for this resource $sql = "DELETE FROM res_sub_infotype WHERE resource_id = " . $resource_id . " AND subject_id = " . $subject_id . " AND infotype_id = " . $infotype_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: subject_builder.phtml?subject_id=" . $subject_id); @@ -156,14 +130,14 @@ /********************************************************** Function: deleteSubOtherSub Author: Paul Bramscher -Last Modified: 11.04.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Deletes subject-othersubject associations based on the supplied subject id (possibly multiple) and calls -formSubject back again. +the subject page editor back again. **********************************************************/ -function deleteSubOtherSub($con, $key_list_array, $subject_id){ +function deleteSubOtherSub($key_list_array, $subject_id){ // For every page in the array, delete it from the bridging table for ($element = 0; $element < sizeof($key_list_array); $element++) { @@ -172,18 +146,7 @@ . $subject_id . " AND othersub_id = " . $key_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); } header("Location: subject_builder.phtml?subject_id=" . $subject_id); @@ -193,14 +156,14 @@ /********************************************************** Function: deleteSubPage Author: Paul Bramscher -Last Modified: 06.17.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Deletes subject-page associations based on the supplied subject id (possibly multiple) and calls -formSubject back again. +the subject page editor back again. **********************************************************/ -function deleteSubPage($con, $key_list_array, $subject_id){ +function deleteSubPage($key_list_array, $subject_id){ // For every page in the array, delete it from the bridging table for ($element = 0; $element < sizeof($key_list_array); $element++) { @@ -209,18 +172,7 @@ . $subject_id . " AND page_id = " . $key_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); } header("Location: subject_builder.phtml?subject_id=" . $subject_id); @@ -230,7 +182,7 @@ /********************************************************** Function: insertSubjectBuilder Author: Paul Bramscher -Last Modified: 04.21.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Inserts a resource onto an RQS page. Note that the incoming @@ -242,7 +194,7 @@ it'll be NULL and appear initially on RQS pages under the (N/A) and (N/A) masterinfotype and infotype headings. **********************************************************/ -function insertSubjectBuilder($con, $highlighted, $resource_id, $subject_id) { +function insertSubjectBuilder($highlighted, $resource_id, $subject_id) { // Continue only if a resource was selected if ($resource_id > 0) { @@ -252,15 +204,15 @@ // Find the default information type for this resource $sql = "SELECT infotype_id FROM resource WHERE resource_id = " . $resource_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $infotype_id = $row["infotype_id"]; // Check to see if it's already there. - $exists = existsResSub($con, $resource_id, $subject_id); + $exists = existsResSub($resource_id, $subject_id); // If already there, check to see whether the (N/A) infotype exists - if ($exists > 0) $existsNA = existsResSubNA($con, $resource_id, $subject_id); + if ($exists > 0) $existsNA = existsResSubNA($resource_id, $subject_id); // If (N/A) exists, disallow adding if ($existsNA > 0) $allow = 0; @@ -275,7 +227,7 @@ else $highlighted = 0; // Fetch the master information type - $masterinfotype_id = lookupField($con, "infotype", "infotype_id", $infotype_id, "masterinfotype_id"); + $masterinfotype_id = lookupField("infotype", "infotype_id", $infotype_id, "masterinfotype_id"); // Build the SQL $sql = "INSERT INTO res_sub_infotype (resource_id, subject_id, infotype_id, masterinfotype_id, highlighted) VALUES (" @@ -289,18 +241,7 @@ . ", " . $highlighted . ")"; - - // Debugging - // printf("sql was: %s
", $sql); - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); } @@ -314,27 +255,16 @@ /********************************************************** Function: rqsPublish Author: Paul Bramscher -Last Modified: 08.27.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Toggles the RQS published flag to 1 (true). **********************************************************/ -function rqsPublish($con, $subject_id){ +function rqsPublish($subject_id){ $sql = "UPDATE subject SET rqs_published = '1' WHERE subject_id = " . $subject_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); header("Location: subject_builder.phtml?subject_id=" . $subject_id); } @@ -343,27 +273,16 @@ /********************************************************** Function: rqsUnpublish Author: Paul Bramscher -Last Modified: 08.27.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Toggles the RQS published flag to 0 (false). **********************************************************/ -function rqsUnpublish($con, $subject_id){ +function rqsUnpublish($subject_id){ $sql = "UPDATE subject SET rqs_published = '0' WHERE subject_id = " . $subject_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); header("Location: subject_builder.phtml?subject_id=" . $subject_id); } @@ -372,43 +291,32 @@ /********************************************************** Function: updateRQSUpdate Author: Paul Bramscher -Last Modified: 08.27.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Modifies the RQS "last updated" fields accordingly. **********************************************************/ -function updateRQSUpdate($con, $sess_staff_account, $subject_id) { +function updateRQSUpdate($sess_staff_account, $subject_id) { $sql = "UPDATE subject SET rqs_date_modified = now(), rqs_account_modified ='" . $sess_staff_account . "' WHERE subject_id = " . $subject_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); } /********************************************************** Function: updateSubjectBuilder Author: Paul Bramscher -Last Modified: 05.27.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Update the RQS resource-subject-infoype assignment. Note that the incoming variables also include a flag for whether the assignment is to be a highlighted or "core" resource. **********************************************************/ -function updateSubjectBuilder($con, $description, $descr_default, $highlighted, +function updateSubjectBuilder($description, $descr_default, $highlighted, $infotype_id, $old_infotype_id, $resource_id, $subject_id) { // Clean up strings @@ -424,21 +332,13 @@ . " OR infotype_id = " . $infotype_id . ")"; - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query ("UNLOCK TABLES", $con); - } + mysql_tryquery($sql); // If the user opted for default resource description, void out the incoming $description; if ($descr_default == 1) $description = ""; // Fetch the master information type - $masterinfotype_id = lookupField($con, "infotype", "infotype_id", $infotype_id, "masterinfotype_id"); + $masterinfotype_id = lookupField("infotype", "infotype_id", $infotype_id, "masterinfotype_id"); // Insert the new row $sql = "INSERT INTO res_sub_infotype ( @@ -460,16 +360,8 @@ . "', '" . $description . "')"; - - 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: subject_builder.phtml?subject_id=" . $subject_id . "#" . $resource_id); } -?> +?> \ No newline at end of file