--- branches/paul/admin/include/insert.php 2004/03/07 19:15:27 66 +++ branches/paul/admin/include/insert.php 2004/03/18 19:24:54 67 @@ -1,17 +1,17 @@ -Last Modified: 09.30.2003 by Paul Bramscher +Original Author: Paul Bramscher +Last Modified: 03.15.2004 by Paul Bramscher *********************************************************** Comments: This library brings together all SQL insert functions for LibData general setup tables. Those pertaining to -CLPS and RQS are located in scribe_application.php and -subject_builder.php respectively. +PageScribe and SubjectBuilder are located in +scribe_application.php and subject_builder.php +respectively. *********************************************************** Table of Contents: - insertCoursesub insertFaculty insertFeature @@ -24,20 +24,22 @@ insertStaff insertStyle insertSubject - - +insertVendor **********************************************************/ /********************************************************** Function: insertCoursesub Author: Paul Bramscher -Last Modified: 06.03.2003 +Last Modified: 03.15.2004 *********************************************************** Purpose: Inserts a course subject. **********************************************************/ -function insertCoursesub($con, $campus_id, $cip_code, $coursesub, $coursesub_descr) { +function insertCoursesub($campus_id, $cip_code, $coursesub, $coursesub_descr) { + + msgTableOpen(1, "Adding Course Subject..."); + printf("Messages:
\n"); // Error flag $err_code = 0; @@ -47,10 +49,10 @@ $coursesub_search = textSearchmySQL($coursesub); // Check to see if already exists - $exists = recordCount($con, "coursesub", "coursesub", $coursesub_search, "A"); + $exists = recordCount("coursesub", "coursesub", $coursesub_search, "A"); if ($exists > 0) { $err_code = 1; - $err_msg = "Failed. '" . $coursesub_display . "' already exists in the course subject table."; + $err_msg = "Failed. " . $coursesub_display . " already exists in the course subject table."; } // Check for blank entry @@ -59,13 +61,6 @@ $err_msg = "Failed. Cannot enter a blank course subject."; } - printf("

Adding Course Subject...

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

"); - printf("Messages:
"); - // Add only if this coursesub doesn't already exist, and something was supplied if ($err_code == 0) { @@ -86,48 +81,40 @@ . ")"; // Write the new row to the database - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - printf("Added Course Subject %s.
", $coursesub_display); - mysql_query("UNLOCK TABLES", $con); - } + if (mysql_tryquery($sql)) printf("Added Course Subject %s.", $coursesub_display); } else printf("%s", $err_msg); + printf("

\n"); - printf("
\n"); - printf("
\n"); + msgTableClose(); } /********************************************************** Function: insertFaculty Author: Paul Bramscher -Last Modified: 06.24.2003 +Last Modified: 03.15.2004 *********************************************************** Purpose: -Inserts a faculty member. +Inserts a faculty member. Faculty must have a last name, +and unique first/last name pair. **********************************************************/ -function insertFaculty($con, $faculty_email, $faculty_firstname, +function insertFaculty($faculty_email, $faculty_firstname, $faculty_lastname, $faculty_account) { - /* - Faculty must have both a unique non-blank staff_account, and non-blank last name. - */ + msgTableOpen(1, "Adding Faculty..."); + printf("Messages:
\n"); // Error flag $err_code = 0; // Need for display/uniqueness $faculty_name_display = $faculty_firstname . " " . $faculty_lastname; - $exists_id = existsFaculty($con, $faculty_firstname, $faculty_lastname); + $exists_id = existsFaculty($faculty_firstname, $faculty_lastname); if ($exists_id > 0) { $err_code = 1; - $err_msg = "Failed. '" . $faculty_name_display . "' already exists in the Faculty table."; + $err_msg = "Failed. " . $faculty_name_display . " already exists in the Faculty table."; } // Check for blank last name @@ -136,13 +123,6 @@ $err_msg = "Failed. Cannot enter a blank Last Name."; } - printf("

Adding Faculty...

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

"); - printf("Messages:
"); - // Add only if no errors encountered if ($err_code == 0) { @@ -163,35 +143,30 @@ . "', '" . $faculty_account . "')"; - + // Write the new row to the database - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - printf("Added %s to the faculty table.
\n", $faculty_name_display); - mysql_query("UNLOCK TABLES", $con); - } + if (mysql_tryquery($sql)) printf("Added %s to the faculty table.", $faculty_name_display); } else printf("%s", $err_msg); + printf("

\n"); - printf("
\n"); - printf("
\n"); + msgTableClose(); } /********************************************************** Function: insertFeature Author: Paul Bramscher -Last Modified: 05.21.2003 +Last Modified: 03.15.2004 *********************************************************** Purpose: Inserts a feature. **********************************************************/ -function insertFeature($con, $feature, $image_alt, $image_path) { +function insertFeature($feature, $image_alt, $image_path) { + + msgTableOpen(1, "Adding Feature..."); + printf("Messages:
\n"); // Error flag $err_code = 0; @@ -201,10 +176,10 @@ $feature_search = textSearchmySQL($feature); // Check to see if already exists - $exists = recordCount($con, "feature", "feature", $feature_search, "A"); + $exists = recordCount("feature", "feature", $feature_search, "A"); if ($exists > 0) { $err_code = 1; - $err_msg = "Failed. '" . $feature_display . "' already exists in the feature table."; + $err_msg = "Failed. " . $feature_display . " already exists in the feature table."; } // Check for blank entry @@ -213,13 +188,6 @@ $err_msg = "Failed. Cannot enter a blank feature."; } - printf("

Adding Feature...

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

"); - printf("Messages:
"); - // Add only if this feature doesn't already exist, and something was supplied if ($err_code == 0) { @@ -238,32 +206,28 @@ . "')"; // Write the new row to the database - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - printf("Added Feature %s.
", $feature_display); - mysql_query("UNLOCK TABLES", $con); - } + if (mysql_tryquery($sql)) printf("Added Feature %s.", $feature_display); + } else printf("%s", $err_msg); + printf("

\n"); - printf("
\n"); - printf("
\n"); + msgTableClose(); } /********************************************************** Function: insertInfotype Author: Paul Bramscher -Last Modified: 05.21.2003 +Last Modified: 03.15.2004 *********************************************************** Purpose: Inserts an information type. **********************************************************/ -function insertInfotype($con, $infotype, $masterinfotype_id, $mastersubject_id) { +function insertInfotype($infotype, $masterinfotype_id, $mastersubject_id) { + + msgTableOpen(1, "Adding Information Type..."); + printf("Messages:
\n"); // Error flag $err_code = 0; @@ -273,12 +237,12 @@ $infotype_search = textSearchmySQL($infotype); // Check to see if already exists - $exists = recordCount($con, "infotype", "infotype", $infotype_search, "A"); + $exists = recordCount("infotype", "infotype", $infotype_search, "A"); // If exists in the table if ($exists > 0) { $err_code = 1; - $err_msg = "Failed. '" . $infotype_display . "' already exists in the Information Type table."; + $err_msg = "Failed. " . $infotype_display . " already exists in the Information Type table."; } // Check for blank entry @@ -287,14 +251,6 @@ $err_msg = "Failed. Must supply some value for the Information Type name."; } - - printf("

Adding Information Type...

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

"); - printf("Messages:
"); - // Add only if this infotype doesn't already exist if ($err_code == 0) { @@ -311,43 +267,30 @@ . ")"; // Write the new row to the database - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - printf("Added Information Type %s.
", $infotype_display); - mysql_query("UNLOCK TABLES", $con); - } - } - - else printf("%s

", $err_msg); - - // Close the table - printf("
"); - printf("
"); - printf("
"); + if (mysql_tryquery($sql)) printf("Added Information Type %s.", $infotype_display); + } + else printf("%s", $err_msg); + + printf("

\n"); + msgTableClose(); } /********************************************************** Function: insertLibunit Author: Paul Bramscher -Last Modified: 05.22.2003 +Last Modified: 03.15.2004 *********************************************************** Purpose: Inserts the supplied library unit information into the database, and calls formLibunit back again, if the insert passed a few checks (unique, no blank values, etc.) -**********************************************************/ -function insertLibunit($con, $head_staff_id, $libunit, $libunit_abbrev) { - /* - Library Units must have both a unique name and unique abbreviation - e.g. "Digital Library Developement Laboratory" and "DLDL" - Additionally, empty values are not allowed. - */ +Library Units must have both a unique name and unique +abbreviation e.g. "Digital Library Developement Laboratory" +and "DLDL". +**********************************************************/ +function insertLibunit($head_staff_id, $libunit, $libunit_abbrev) { // Error flag $err_code = 0; @@ -359,17 +302,17 @@ $libunit_abbrev_search = textSearchmySQL($libunit_abbrev); // Check to see if libunit already exists - $exists = recordCount($con, "libunit", "libunit", $libunit_search, "A"); + $exists = recordCount("libunit", "libunit", $libunit_search, "A"); if ($exists > 0) { $err_code = 1; - $err_msg = "Failed. '" . $libunit_display . "' already exists in the Library Unit table."; + $err_msg = "Failed. " . $libunit_display . " already exists in the Library Unit table."; } // Check to see if libunit abbreviation already exists - $exists = recordCount($con, "libunit", "libunit_abbrev", $libunit_abbrev_search, "A"); + $exists = recordCount("libunit", "libunit_abbrev", $libunit_abbrev_search, "A"); if ($exists > 0) { $err_code = 2; - $err_msg = "Failed. '" . $libunit_abbrev_display . "' abbreviation already exists in the Library Unit table."; + $err_msg = "Failed. " . $libunit_abbrev_display . " abbreviation already exists in the Library Unit table."; } // Check for blank linunit entry @@ -399,30 +342,16 @@ . ")"; // Write the new row to the database - mysql_query ("LOCK TABLE libunit WRITE", $con); - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - $libunit_id = mysql_insert_id($con); - mysql_query("UNLOCK TABLES", $con); - formLibunit($con, $libunit_id); - } + mysql_tryquery ($sql); + $libunit_id = mysql_insert_id(); + formLibunit($libunit_id); } - else { - printf("

Adding Library Unit...

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

\n"); - printf("Messages:
\n"); + msgTableOpen(1, "Adding Library Unit..."); + printf("Messages:
\n"); printf("%s", $err_msg); - printf("

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

\n"); + msgTableClose(); } } @@ -430,15 +359,18 @@ /********************************************************** Function: insertLocation Author: Paul Bramscher -Last Modified: 06.16.2003 +Last Modified: 03.15.2004 *********************************************************** Purpose: Inserts a library/location. **********************************************************/ -function insertLocation($con, $address1, $address2, $address3, +function insertLocation($address1, $address2, $address3, $address4, $campus, $hoursURL, $location, $location_descr, $mainURL, $mapURL, $referenceURL, $telephone) { + msgTableOpen(1, "Adding Location..."); + printf("Messages:
\n"); + // Need for display purposes $location_display = $location; $location_search = textSearchmySQL($location); @@ -447,10 +379,10 @@ $err_code = 0; // Check to see if already exists - $exists = recordCount($con, "location", "location", $location_search, "A"); + $exists = recordCount("location", "location", $location_search, "A"); if ($exists > 0) { $err_code = 1; - $err_msg = "Failed. '" . $location_display . "' already exists in the location table."; + $err_msg = "Failed. " . $location_display . " already exists in the location table."; } // Check for blank entry @@ -459,13 +391,6 @@ $err_msg = "Failed. Cannot enter a blank location."; } - printf("

Adding Location...

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

\n"); - printf("Messages:
\n"); - // Add only if this location doesn't already exist, and something was supplied if ($err_code == 0) { @@ -513,22 +438,13 @@ . "')"; // Write the new row to the database - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - - printf("Added %s location.", $location_display); - mysql_query("UNLOCK TABLES", $con); - } + if (mysql_tryquery($sql)) printf("Added %s location.", $location_display); + } - else printf("%s", $err_msg); + printf("

\n"); - printf("
\n"); - printf("
\n"); + msgTableClose(); } @@ -536,25 +452,26 @@ /********************************************************** Function: insertResource Author: Paul Bramscher -Last Modified: 04.21.2003 +Last Modified: 03.15.2004 *********************************************************** Purpose: Inserts a resource. **********************************************************/ -function insertResource($con, $annotation, $author, $call_no, $cat_num, - $coverage_detail, $edition, $infotype_id, $mastersubject_id, $other_title, - $pub_date, $publisher, $sess_staff_account, $sources_indexed, $title, $url) { +function insertResource($annotation, $author, $call_no, $cat_num, + $coverage_detail, $edition, $guide_url, $infotype_id, $mastersubject_id, + $other_title, $pub_date, $publisher, $resource_message, $resource_status, + $sess_staff_account, $sources_indexed, $title, $url, $vendor_id) { // Error flag $err_code = 0; // Check to see if already exists - $exists = recordCount($con, "resource", "title", $title, "A"); + $exists = recordCount("resource", "title", $title, "A"); // If exists in the table if ($exists > 0) { $err_code = 1; - $err_msg = "Failed. '" . $title . "' already exists in the Resource table."; + $err_msg = "Failed. " . $title . " already exists in the Resource table."; } // Check for blank entry @@ -579,12 +496,19 @@ if (strlen($sources_indexed) > 0) $sources_indexed = textInmySQL($sources_indexed); if (strlen($title) > 0) $title = textInmySQL($title); if (strlen($url) > 0) $url = textInmySQL($url); + if (strlen($guide_url) > 0) $guide_url = textInmySQL($guide_url); + if (strlen($resource_message) > 0) $resource_message = textInmySQL($resource_message); + if ($resource_status < 1) { + $resource_status = ""; + $resource_message = ""; + } // Build the SQL $sql = "INSERT INTO resource (annotation, author, call_no, cat_num, - coverage_detail, date_created, date_modified, edition, - infotype_id, other_title, pub_date, publisher, sources_indexed, - title, url, account_created) VALUES ('" + coverage_detail, date_created, date_modified, edition, guide_url, + infotype_id, other_title, pub_date, publisher, resource_message, + resource_status, sources_indexed, title, url, vendor_id, + account_created) VALUES ('" . $annotation . "', '" . $author @@ -596,6 +520,8 @@ . $coverage_detail . "', now(), now(), '" . $edition + . "', '" + . $guide_url . "', " . $infotype_id . ", '" @@ -605,159 +531,62 @@ . "', '" . $publisher . "', '" + . $resource_message + . "', '" + . $resource_status + . "', '" . $sources_indexed . "', '" . $title . "', '" . $url . "', '" + . $vendor_id + . "', '" . $sess_staff_account . "')"; - // Debugging - // printf("sql was: %s
", $sql); - // Write the new record to the database - mysql_query ("LOCK TABLE resource WRITE", $con); - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - $resource_id = mysql_insert_id($con); - mysql_query("UNLOCK TABLES", $con); - - // Now set up this resource with its first mastersubject - // Note that id#1 = N/A and id#2 = (All), and are not used here. - if ($mastersubject_id > 2) { - $sql = "INSERT INTO res_mastersubject (resource_id, mastersubject_id) VALUES (" - . $resource_id - . ", " - . $mastersubject_id - . ")"; - - // Write the new res_mastersubject to the database - mysql_query ("LOCK TABLE res_mastersubject WRITE", $con); - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - } - } + mysql_tryquery ($sql); + $resource_id = mysql_insert_id(); + + // Now set up this resource with its first mastersubject + // Note that id#1 = N/A and id#2 = (All) are not used here. + if ($mastersubject_id > 2) { + $sql = "INSERT INTO res_mastersubject (resource_id, mastersubject_id) VALUES (" + . $resource_id + . ", " + . $mastersubject_id + . ")"; + // Write the new res_mastersubject to the database + mysql_tryquery ($sql); } // Call the formResource page back, in case user wants to edit further - formResource($con, $resource_id, 0, 0, ''); + formResource($resource_id, 0, 0, ''); } // end insert new resource else { - printf("

Adding Resource...

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

\n"); - printf("Messages:
\n"); + msgTableOpen(1, "Adding Resource..."); + printf("Messages:
\n"); printf("%s", $err_msg); - printf("

\n"); - printf("
\n"); - printf("
\n"); - } // end error messages - -} // end function - - -/********************************************************** -Function: insertSingleField -Author: Paul Bramscher -Last Modified: 05.21.2003 -*********************************************************** -Purpose: -Inserts any single field value into any table. -**********************************************************/ -function insertSingleField($con, $display, $field, $newValue, $table){ - - // Error flag - $err_code = 0; - - // Need for display/uniqueness purposes - $newValue_search = textSearchmySQL($newValue); - $newValue_display = $newValue; - - // Check to see if already exists - $exists = recordCount($con, $table, $field, $newValue_search, "A"); - if ($exists > 0) { - $err_code = 1; - $err_msg = "Failed. " - . $newValue_display - . " already exists in the " - . $display - . " table."; - } - - // Check for blank entry - if ($newValue == "") { - $err_code = 2; - $err_msg = "Failed. Cannot enter a blank " - . $display - . " value."; - } - - // Draw page heading - printf("

Adding New %s

", $display); - - printf(""); - printf("
Messages:
"); - - // Add only if this item doesn't already exist, and a value was supplied - if ($err_code == 0){ - - // Clean up strings - $newValue = textInmySQL($newValue); - - // Build the SQL - $sql = "INSERT INTO " - . $table - ." (" - . $field - . ") VALUES ('" - . $newValue - . "')"; - - // Debugging - // printf("sql was: %s
", $sql); - - if (!mysql_query ($sql, $con)){ - sql_err($sql); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - $new_id = mysql_insert_id($con); - mysql_query ("UNLOCK TABLES", $con); - printf("%s %s successfully added.\n", $display, $newValue_display); - } + printf("

\n"); + msgTableClose(); } - else printf ("%s\n", $err_msg); - printf("

"); - printf("
"); -} +} // end function /********************************************************** Function: insertService Author: Paul Bramscher -Last Modified: 05.21.2003 +Last Modified: 03.15.2004 *********************************************************** Purpose: Inserts a service. **********************************************************/ -function insertService($con, $address1, $address2, $address3, $address4, +function insertService($address1, $address2, $address3, $address4, $email, $fax, $nonaff, $service, $serviceDescr, $serviceURL, $telephone) { // Error flag @@ -768,10 +597,10 @@ $service_search = textSearchmySQL($service); // Check to see if already exists - $exists = recordCount($con, "service", "service", $service_search, "A"); + $exists = recordCount("service", "service", $service_search, "A"); if ($exists > 0) { $err_code = 1; - $err_msg = "Failed. '" . $service_display . "' already exists in the service table."; + $err_msg = "Failed. " . $service_display . " already exists in the service table."; } // Check for blank entry @@ -823,49 +652,103 @@ . "')"; // Write the new row to the database - mysql_query ("LOCK TABLE service WRITE", $con); - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - $service_id = mysql_insert_id($con); - mysql_query("UNLOCK TABLES", $con); - formService($con, $service_id); - } + mysql_tryquery ($sql); + $service_id = mysql_insert_id(); + formService($service_id); } + else { - // Draw page heading - printf("

Adding New Service...

"); + msgTableOpen(1, "Adding Service..."); + printf("Messages:
\n"); + printf("%s", $err_msg); + printf("

\n"); + msgTableClose(); + } + +} + + +/********************************************************** +Function: insertSingleField +Author: Paul Bramscher +Last Modified: 03.15.2004 +*********************************************************** +Purpose: +Inserts any single field value into any table. +**********************************************************/ +function insertSingleField($display, $field, $newValue, + $table) { - printf(""); - printf("
Messages:
"); + msgTableOpen(1, "Adding " . $display . "..."); + printf("Messages:
\n"); + + // Error flag + $err_code = 0; + + // Need for display/uniqueness purposes + $newValue_search = textSearchmySQL($newValue); + $newValue_display = $newValue; + + // Check to see if already exists + $exists = recordCount($table, $field, $newValue_search, "A"); + if ($exists > 0) { + $err_code = 1; + $err_msg = "Failed. " + . $newValue_display + . " already exists in the " + . $display + . " table."; + } - printf ("%s\n", $err_msg); - printf("

"); - printf("
"); + // Check for blank entry + if ($newValue == "") { + $err_code = 2; + $err_msg = "Failed. Cannot enter a blank " + . $display + . " value."; } + // Add only if this item doesn't already exist, and a value was supplied + if ($err_code == 0){ + + // Clean up strings + $newValue = textInmySQL($newValue); + + // Build the SQL + $sql = "INSERT INTO " + . $table + ." (" + . $field + . ") VALUES ('" + . $newValue + . "')"; + + mysql_tryquery ($sql); + $new_id = mysql_insert_id(); + printf("%s %s successfully added.", $display, $newValue_display); + } + else printf ("%s", $err_msg); + + printf("

\n"); + msgTableClose(); } /********************************************************** Function: insertStaff Author: Paul Bramscher -Last Modified: 06.23.2003 +Last Modified: 03.15.2004 *********************************************************** Purpose: Inserts the supplied staffperson information, and calls -formStaff back again if the insert was valid. +formStaff back again if the insert was valid. Staff must +have, at a minimum, a last name, first name, and unique +staff account name. Uniqueness is enforced only on +staff_account. **********************************************************/ -function insertStaff($con, $access_id, $first_name, - $last_name, $sess_access_level, $staff_account, $staff_email, $stafftitle_id) { - - /* - Staff must have, at a minimum, a last name, first name, and unique staff account name. - Uniqueness is enforced only on staff_account. - */ +function insertStaff($access_id, $first_name, + $last_name, $sess_access_level, $staff_account, + $staff_email, $stafftitle_id) { // Error flag $err_code = 0; @@ -875,10 +758,10 @@ $staff_account_search = textSearchmySQL($staff_account); // Check to see if the account name already exists - $exists = recordCount($con, "staff", "staff_account", $staff_account_search, "A"); + $exists = recordCount("staff", "staff_account", $staff_account_search, "A"); if ($exists > 0) { $err_code = 1; - $err_msg = "Failed. '" . $staff_account_display . "' already exists in the Staff table."; + $err_msg = "Failed. " . $staff_account_display . " already exists in the Staff table."; } // Check for blank first name or last name @@ -894,7 +777,7 @@ } // Check for access level higher than current access - $this_access_level = lookupfield($con, "access", "access_id", $access_id, "access_level"); + $this_access_level = lookupfield("access", "access_id", $access_id, "access_level"); if ($this_access_level > $sess_access_level) { $err_code = 4; $err_msg = "Failed. You may not create staff with higher privileges than your own."; @@ -924,35 +807,20 @@ . "', '" . $staff_email . "')"; - - // Debugging - // printf("sql was: %s

\n", $sql); // Write the new row to the database - mysql_query ("LOCK TABLE staff WRITE", $con); - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - - // Success, call formStaff back. - $staff_id = mysql_insert_id($con); - mysql_query("UNLOCK TABLES", $con); - formStaff($con, $staff_id); - } + mysql_tryquery ($sql); + $staff_id = mysql_insert_id(); + + // Call staff form back + formStaff($staff_id); } else { - // Failure message box - printf("

Adding Staff...

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

\n"); - printf("Messages:
\n"); + msgTableOpen(1, "Adding Staff..."); + printf("Messages:
\n"); printf("%s", $err_msg); printf("

\n"); - printf("
\n"); - printf("
\n"); + msgTableClose(); } } @@ -960,7 +828,7 @@ /********************************************************** Function: insertStyle Author: Paul Bramscher -Last Modified: 05.22.2003 +Last Modified: 03.15.2004 *********************************************************** Purpose: Inserts a style type. Note that css_file, footer_file, and @@ -969,7 +837,11 @@ and permissions settings. This must be accomplished by someone with proper OS access. **********************************************************/ -function insertStyle($con, $css_file, $footer_file, $header_file, $style_title) { +function insertStyle($css_file, $footer_file, $header_file, + $style_title) { + + msgTableOpen(1, "Adding Style..."); + printf("Messages:
\n"); // Error flag $err_code = 0; @@ -979,10 +851,10 @@ $style_title_search = textSearchmySQL($style_title); // Check to see if already exists - $exists = recordCount($con, "style", "style_title", $style_title_search, "A"); + $exists = recordCount("style", "style_title", $style_title_search, "A"); if ($exists > 0) { $err_code = 1; - $err_msg = "Failed. '" . $style_title_display . "' already exists in the style table."; + $err_msg = "Failed. " . $style_title_display . " already exists in the style table."; } // Check for blank entry @@ -991,13 +863,6 @@ $err_msg = "Failed. Cannot enter a blank style."; } - printf("

Adding Style...

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

"); - printf("Messages:
"); - // Add only if this style doesn't already exist, and something was supplied if ($err_code == 0) { @@ -1019,33 +884,26 @@ . "')"; // Write the new row to the database - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - printf("Added %s style.

\n", $style_title_display); - } + if (mysql_tryquery($sql)) printf("Added %s style.", $style_title_display); } else printf("%s", $err_msg); + printf("

\n"); - printf("
\n"); - printf("
\n"); + msgTableClose(); } /********************************************************** Function: insertSubject Author: Paul Bramscher -Last Modified: 09.23.2003 +Last Modified: 03.15.2004 *********************************************************** Purpose: Inserts a subject. If successful, calls formSubject back again. **********************************************************/ -function insertSubject($con, $sess_staff_account, $sess_staff_id, $subject, $subject_descr, $sublocation_id) { +function insertSubject($sess_staff_account, $sess_staff_id, + $subject, $subject_descr, $sublocation_id) { // Error flag $err_code = 0; @@ -1055,10 +913,10 @@ $subject_search = textSearchmySQL($subject); // Check to see if already exists - $exists = recordCount($con, "subject", "subject", $subject_search, "A"); + $exists = recordCount("subject", "subject", $subject_search, "A"); if ($exists > 0) { $err_code = 1; - $err_msg = "Failed. '" . $subject_display . "' already exists in the subject table."; + $err_msg = "Failed. " . $subject_display . " already exists in the subject table."; } // Check for blank entry @@ -1084,51 +942,91 @@ . ", now(), '" . $sess_staff_account . "')"; - - // Write the new row to the database - mysql_query ("LOCK TABLE subject WRITE", $con); - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - $subject_id = mysql_insert_id($con); - mysql_query("UNLOCK TABLES", $con); - - // Insert this staff person as an assigned staff member to this subject - $sql = "INSERT INTO sub_staff (subject_id, staff_id) VALUES (" - . $subject_id - . ", " - . $sess_staff_id - . ")"; - - if (!mysql_query($sql, $con)){ - sql_err($con); - mysql_query ("UNLOCK TABLES", $con); - bailout(); - } - else { - mysql_query("UNLOCK TABLES", $con); - } - - formSubject($con, $subject_id); - } // good write of subject + mysql_tryquery ($sql); + $subject_id = mysql_insert_id(); + + // Insert this staff person as an assigned staff member to this subject + $sql = "INSERT INTO sub_staff (subject_id, staff_id) VALUES (" + . $subject_id + . ", " + . $sess_staff_id + . ")"; + mysql_tryquery($sql); + formSubject($subject_id); } else { - - printf("

Adding subject...

"); + msgTableOpen(1, "Adding Subject..."); + printf("Messages:
\n"); + printf("%s", $err_msg); + printf("

\n"); + msgTableClose(); + } + +} - // Table - printf(""); - printf("

"); - printf("Messages:
"); - printf("%s

", $err_msg); - printf("
"); - printf("
"); +/********************************************************** +Function: insertVendor +Author: Paul Bramscher +Last Modified: 03.15.2004 +*********************************************************** +Purpose: +Inserts a vendor. +**********************************************************/ +function insertVendor($vendor, $vendor_descr, + $vendor_message, $vendor_status) { + + msgTableOpen(1, "Adding Vendor..."); + printf("Messages:
\n"); + + // Error flag + $err_code = 0; + + // Need for display/uniqueness + $vendor_display = $vendor; + $vendor_search = textSearchmySQL($vendor); + + // Check to see if already exists + $exists = recordCount("vendor", "vendor", $vendor_search, "A"); + if ($exists > 0) { + $err_code = 1; + $err_msg = "Failed. " . $vendor_display . " already exists in the vendor table."; + } + + // Check for blank entry + if ($vendor == "") { + $err_code = 2; + $err_msg = "Failed. Cannot enter a blank vendor."; } + + // Add only if this vendor doesn't already exist, and something was supplied + if ($err_code == 0) { + + // Clean up strings + if (strlen($vendor) > 0) $vendor = textInmySQL($vendor); + if (strlen($vendor_descr) > 0) $vendor_descr = textInmySQL($vendor_descr); + if (strlen($vendor_message) >0) $vendor_message = textInmySQL($vendor_message); + if ($vendor_status < 1) { + $vendor_status = ""; + $vendor_message = ""; + } + + // Set up SQL + $sql = "INSERT INTO vendor (vendor, vendor_descr, vendor_message, vendor_status) VALUES ('" + . $vendor + . "', '" + . $vendor_descr + . "', '" + . $vendor_message + . "', '" + . $vendor_status + . "')"; + if (mysql_tryquery($sql)) printf("Added Vendor %s.", $vendor_display); -} // function -?> + } + else printf("%s", $err_msg); + printf("

\n"); + msgTableClose(); +} +?> \ No newline at end of file