--- branches/paul/public_controls.php 2004/03/07 19:15:27 66 +++ branches/paul/public_controls.php 2004/03/18 19:24:54 67 @@ -1,8 +1,8 @@ -Last Modified: 12.15.2003 +Original Author: Paul Bramscher +Last Modified: 03.04.2004 *********************************************************** Comments: Publicly accessible and executable functions. @@ -18,7 +18,6 @@ dropDownFieldOmit dropDownFieldSelected existsRow -locationList lookupField lookupStaff pageLoadStats @@ -37,7 +36,7 @@ Purpose: Output the course related information for a course page. **********************************************************/ -function displayCourseHeader($con, $page_id, $pagetitle_style) { +function displayCourseHeader($page_id, $pagetitle_style) { // Retrieve current information $sql = "SELECT * @@ -50,8 +49,8 @@ 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); $course_id = $row["course_id"]; $staff_id_created = $row["staff_id_created"]; @@ -128,16 +127,16 @@ /********************************************************** Function: displayCoursePers Author: Paul Bramscher -Last Modified: 09.10.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Displays the personnel associated with the course, by looking up the course id based on the page id. **********************************************************/ -function displayCoursePers($con, $page_id) { +function displayCoursePers($page_id) { // Determine the course id - $course_id = lookupfield($con, "course", "page_id", $page_id, "course_id"); + $course_id = lookupfield("course", "page_id", $page_id, "course_id"); // Retrieve current information $sql = "SELECT * @@ -150,7 +149,7 @@ WHERE course_id = " . $course_id . " ORDER BY personnel_id"; - $rs = mysql_query($sql, $con); + $rs = mysql_tryquery($sql); // See how many in this record set $num_personnel = mysql_num_rows($rs); @@ -162,7 +161,7 @@ printf("Personnel:
\n"); - while ($row = mysql_fetch_array ($rs)) { + while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { // Initialize $last_name = ""; @@ -220,12 +219,11 @@ /********************************************************** -Function: displayRelatedPages($con, $subject_id) +Function: displayRelatedPages($subject_id) Author: Paul Bramscher -Last Modified: 06.17.2003 +Last Modified: 03.04.2004 *********************************************************** Incoming: -$con Database connection string $subject_id Subject of the RQS page *********************************************************** Outgoing: @@ -235,15 +233,15 @@ Displays any PageScribe pages associated with the supplied subject id. **********************************************************/ -function displayRelatedPages($con, $subject_id){ +function displayRelatedPages($subject_id){ $sql = "SELECT p.page_id, p.page_title FROM page p, sub_page sp WHERE sp.subject_id = " . $subject_id . " AND sp.page_id = p.page_id ORDER BY p.page_title"; - $rs = mysql_query($sql, $con); - while ($row = mysql_fetch_array ($rs)) { + $rs = mysql_tryquery($sql); + while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { $page_id = $row["page_id"]; $page_title = $row["page_title"]; @@ -256,12 +254,11 @@ /********************************************************** -Function: displayRelatedSubjects($con, $subject_id) +Function: displayRelatedSubjects($subject_id) Author: Paul Bramscher -Last Modified: 11.05.2003 +Last Modified: 03.04.2004 *********************************************************** Incoming: -$con Database connection string $subject_id Subject of the RQS page *********************************************************** Outgoing: @@ -271,7 +268,7 @@ Displays any RQS pages associated with the supplied subject id. **********************************************************/ -function displayRelatedSubjects($con, $subject_id){ +function displayRelatedSubjects($subject_id){ $sql = "SELECT s.subject, so.othersub_id FROM subject s, sub_othersub so @@ -279,8 +276,8 @@ . $subject_id . " AND so.othersub_id = s.subject_id ORDER BY s.subject"; - $rs = mysql_query($sql, $con); - while ($row = mysql_fetch_array ($rs)) { + $rs = mysql_tryquery($sql); + while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { $othersub_id = $row["othersub_id"]; $subject = $row["subject"]; @@ -295,7 +292,7 @@ /********************************************************** Function: displayTOC Author: Paul Bramscher -Last Modified: 12.15.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Generates and displays a table of contents (TOC) for the @@ -306,12 +303,12 @@ 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); + $rs = mysql_tryquery($sql); $row = mysql_fetch_array ($rs); $num_elements = $row["num_elements"]; @@ -351,7 +348,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"); @@ -366,7 +363,7 @@ $row_num = 0; - while ($row = mysql_fetch_array ($rs)) { + while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { // Check for the midpoint if ($row_num == $midpoint && $wrap_toc == 1) { @@ -434,12 +431,11 @@ /********************************************************** -Function: dropDownCoursesubSelected($con, $limit, $preselected) +Function: dropDownCoursesubSelected($limit, $preselected) Author: Paul Bramscher -Last Modified: 08.18.2003 +Last Modified: 03.04.2004 *********************************************************** Incoming: -$con Database connection string $limit Initial limit to the result set $preselected Incoming course subject to preselect *********************************************************** @@ -452,7 +448,7 @@ which have associated and published CourseLib pages will appear in the drop down box. **********************************************************/ -function dropDownCoursesubSelected($con, $limit, $preselected){ +function dropDownCoursesubSelected($limit, $preselected){ $sql = "SELECT DISTINCT s.coursesub @@ -465,20 +461,8 @@ AND s.coursesub_id = c.coursesub_id " . " ORDER BY s.coursesub"; -/* - Use this SQL instead, if all distinct course designators, used or not, - would rather be displayed. - - - $sql = "SELECT DISTINCT s.coursesub FROM coursesub s, course c" - . $limit - . " AND s.coursesub_id = c.coursesub_id " - . " ORDER BY s.coursesub"; -*/ - - - $rs = mysql_query($sql, $con); - while ($row = mysql_fetch_array ($rs)) { + $rs = mysql_tryquery($sql); + while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { $coursesub = $row["coursesub"]; printf("\n"); + . "\" >" + . $field_display_item + . "\n"); }; } /********************************************************** -Function: dropDownFieldSelected($con, $table, $field_display, +Function: dropDownFieldSelected($table, $field_display, $field_value, $limit, $preselected) Author: Paul Bramscher -Last Modified: 12.04.2002 +Last Modified: 03.04.2004 *********************************************************** Incoming: -$con Database connection string $table Table in database to search $field_display Select displayed to user $field_value Actual value of the HTML tag @@ -624,7 +595,7 @@ parameter $preselected determines which (single) selection is selected. **********************************************************/ -function dropDownFieldSelected($con, $table, $field_display, +function dropDownFieldSelected($table, $field_display, $field_value, $limit, $preselected){ $sql = "SELECT " @@ -638,11 +609,8 @@ . " ORDER BY " . $field_display; - // Debugging - //printf("sql was: %s
", $sql); - - $rs = mysql_query($sql, $con); - while ($row = mysql_fetch_array ($rs)) { + $rs = mysql_tryquery($sql); + while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) { $field_display_item = $row[$field_display]; $field_value_item = $row[$field_value]; if (strlen($field_display_item) > 50) $field_display_item = substr($field_display_item, 0, 49) . "..."; @@ -657,10 +625,9 @@ /********************************************************** Function: existsRow Author: Paul Bramscher -Last Modified: 12.09.2002 +Last Modified: 03.04.2004 *********************************************************** Incoming: -$con Database connection string $table Table to search $key_field Field against which to search $key_id Limit for the where clause @@ -673,7 +640,7 @@ sure that a row entity exists matching the supplied key before going any further. **********************************************************/ -function existsRow($con, $table, $key_field, $limit_id){ +function existsRow($table, $key_field, $limit_id){ // Cast as integer to avoid future problems $limit_id = (int) $limit_id; @@ -687,7 +654,7 @@ . "=" . $limit_id; - $rs = mysql_query($sql, $con); + $rs = mysql_tryquery($sql); $rowcount = mysql_num_rows($rs); if ($rowcount >= 1){ $rowcount = 1; @@ -699,52 +666,12 @@ /********************************************************** -Function: locationList($con, $resource_id) -Author: Paul Bramscher -Last Modified: 07.02.2002 -*********************************************************** -Incoming: -$con Database connection string -$resource_id Resource ID to check locations on -*********************************************************** -Outgoing: -None -*********************************************************** -Purpose: -Looks up location(s) for this resource -**********************************************************/ -function locationList($con, $resource_id){ - - // Initialize - $locations = ""; - $first = 1; - - $sql = "SELECT location FROM location l, res_loc rl WHERE rl.resource_id = " - . $resource_id - . " AND rl.location_id = l.location_id ORDER BY location"; - - $rs = mysql_query($sql, $con); - while ($row = mysql_fetch_array ($rs)) { - $location = $row["location"]; - if ($first == 1) { - $first = 0; - $locations = $location; - } - else $locations .= "; " . $location; - } - - return $locations; -} - - -/********************************************************** -Function: lookupField($con, $table, $key_field, $key_value, +Function: lookupField($table, $key_field, $key_value, $desc_field) Author: Paul Bramscher -Last Modified: 9.14.2000 +Last Modified: 03.04.2004 *********************************************************** Incoming: -$con Database connection string $table Table in database to search $key_field Name of field on which to lookup $key_value Value to attempt lookup with @@ -757,7 +684,7 @@ Performs a lookup, typically on an ID field, to retrieve a user-friendly descriptive name to the page. **********************************************************/ -function lookupField($con, $table, $key_field, $key_value, +function lookupField($table, $key_field, $key_value, $desc_field){ $sql = "SELECT " @@ -769,8 +696,8 @@ . "='" . $key_value . "'"; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); if (mysql_num_rows($rs) == 1) $result = $row[$desc_field]; else $result = ""; @@ -779,12 +706,11 @@ /********************************************************** -Function: lookupStaff($con, $staff_id) +Function: lookupStaff($staff_id) Author: Paul Bramscher -Last Modified: 7.22.2002 +Last Modified: 03.04.2004 *********************************************************** Incoming: -$con Database connection string $staff_id Staff ID number to retrieve *********************************************************** Outgoing: @@ -793,12 +719,12 @@ Purpose: Performs a lookup on staff ID to retrieve name. **********************************************************/ -function lookupStaff($con, $staff_id){ +function lookupStaff($staff_id){ $sql = "SELECT first_name, last_name FROM staff WHERE staff_id = " . $staff_id; - $rs = mysql_query($sql, $con); - $row = mysql_fetch_array ($rs); + $rs = mysql_tryquery($sql); + $row = mysql_fetch_array ($rs, MYSQL_ASSOC); $last_name = $row["last_name"]; $first_name = $row["first_name"]; @@ -814,7 +740,7 @@ /********************************************************** Function: pageLoadStats Author: Paul Bramscher -Last Modified: 04.23.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Logs a statistical entry for a PageScribe/CourseLib page @@ -825,7 +751,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 @@ -841,16 +767,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); } @@ -884,7 +801,7 @@ /********************************************************** Function: subLoadStats Author: Paul Bramscher -Last Modified: 08.25.2003 +Last Modified: 03.04.2004 *********************************************************** Purpose: Logs a statistical entry for a RQS page load. Subject id, @@ -894,7 +811,7 @@ No differentiation between them is made, only between subjects **********************************************************/ -function subLoadStats($con, $subject_id){ +function subLoadStats($subject_id){ // Add a row for page usage @@ -910,16 +827,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 substats table + mysql_tryquery($sql); } @@ -963,4 +871,4 @@ return $outgoing; } -?> +?> \ No newline at end of file