/[libdata]/branches/pear-db/admin/include/update.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /branches/pear-db/admin/include/update.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations)
Fri Dec 5 18:34:18 2003 UTC (20 years, 5 months ago) by dpavlin
Original Path: trunk/admin/include/update.php
File size: 34917 byte(s)
Initial revision

1 dpavlin 1 <?php
2     /**********************************************************
3     Function Library: update.php
4     Original Author: Paul Bramscher <brams006@tc.umn.edu>
5     Last Modified: 09.30.2003 by Paul Bramscher
6     ***********************************************************
7     Comments:
8     This library brings together all SQL update functions for
9     LibData general setup tables. Those pertaining to
10     PageScribe and SubjectBuilder are located in
11     scribe_application.php and subject_builder.php
12     respectively.
13     ***********************************************************
14     Table of Contents:
15    
16     purgePassword
17     updateCoursesub
18     updateFaculty
19     updateFeature
20     updateInfotype
21     updateLibunit
22     updateLocation
23     updatePassword
24     updateResource
25     updateService
26     updateSingleField
27     updateStaff
28     updateStyle
29     updateSubject
30    
31    
32     **********************************************************/
33    
34    
35     /**********************************************************
36     Function: purgePassword
37     Author: Paul Bramscher
38     Last Modified: 06.23.2003
39     ***********************************************************
40     Purpose:
41     This function purges the locally encrypted mySQL stored
42     password for the supplied staff id (sets to NULL). Note
43     that at no point does this system actually retrieve the
44     value of the password and bring it to an HTML form, neither
45     in plaintext nor in a "password" type HTML form field.
46     **********************************************************/
47     function purgePassword($con, $staff_id){
48    
49     // Draw form heading
50     printf("<center><h3>Purging Password...</h3>");
51    
52     // Table
53     printf("<table width = \"60%%\" border = \"1\" cellpadding =\"4\" class=\"backLight\">");
54     printf("<tr><td><br>");
55     printf("<strong>Messages:</strong><br>");
56    
57     // Problem flag for each step
58     $problem = 0;
59    
60     if ($staff_id > 0) {
61     $sql = "UPDATE staff SET password = NULL WHERE staff_id = " . $staff_id;
62    
63     if (!mysql_query ($sql, $con)){
64     $problem = 1;
65     sql_err($sql);
66     mysql_query ("UNLOCK TABLES", $con);
67     bailout();
68     }
69     else {
70     mysql_query ("UNLOCK TABLES", $con);
71     printf("Purged password successfully for this staff account.<br><BR>\n");
72     }
73    
74     }
75     else printf("Staff ID not found.</b>.<br><br>\n");
76    
77     printf("</td></tr></table>\n");
78     printf("</center>\n");
79     }
80    
81    
82     /**********************************************************
83     Function: updateCoursesub
84     Author: Paul Bramscher
85     Last Modified: 06.03.2003
86     ***********************************************************
87     Purpose:
88     Update supplied course subject id.
89     **********************************************************/
90     function updateCoursesub($con, $campus_id, $cip_code, $coursesub, $coursesub_descr, $coursesub_id) {
91    
92     // Error flag
93     $err_code = 0;
94    
95     // Need for display/uniqueness
96     $coursesub_display = $coursesub;
97     $coursesub_search = textSearchmySQL($coursesub);
98    
99     // Check to see if already exists
100     $exists = recordCount($con, "coursesub", "coursesub", $coursesub_search, "A");
101     $exists_id = lookupField($con, "coursesub", "coursesub", $coursesub_search, "coursesub_id");
102    
103     // If exists in the courseub table under a different coursesub_id
104     if ($exists > 0 && $exists_id != $coursesub_id) {
105     $err_code = 1;
106     $err_msg = "Failed. '" . $coursesub_display . "' already exists in the course subject table.";
107     }
108    
109     // Check for blank entry
110     if ($coursesub == "") {
111     $err_code = 2;
112     $err_msg = "Failed. Must supply some value for the course subject.";
113     }
114    
115     printf("<center><h3>Updating Course Subject...</h3>\n");
116    
117     // Table
118     printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">\n");
119     printf("<tr><td><br>\n");
120     printf("<strong>Messages:</strong><br>");
121    
122     // Perform the update only if no errors encountered
123     if ($err_code == 0) {
124    
125     // Clean up strings
126     $coursesub = textInmySQL($coursesub);
127     $coursesub_descr = textInmySQL($coursesub_descr);
128     $cip_code = textInmySQL($cip_code);
129    
130     // Build the SQL
131     $sql = "UPDATE coursesub SET coursesub = '"
132     . $coursesub
133     . "', coursesub_descr ='"
134     . $coursesub_descr
135     . "', cip_code = '"
136     . $cip_code
137     . "', campus_id = "
138     . $campus_id
139     . " WHERE coursesub_id ="
140     . $coursesub_id;
141    
142     if (!mysql_query ($sql, $con)){
143     sql_err($sql);
144     mysql_query ("UNLOCK TABLES", $con);
145     bailout();
146     }
147     else {
148     mysql_query ("UNLOCK TABLES", $con);
149     printf("Updated <b>%s</b> course subject.<BR><BR>\n", $coursesub_display);
150     }
151     }
152    
153     else printf("%s", $err_msg);
154    
155     printf("<br><br>\n");
156     printf("</td></tr></table>\n");
157     printf("</center>\n");
158    
159     }
160    
161    
162     /**********************************************************
163     Function: updateFaculty
164     Author: Paul Bramscher
165     Last Modified: 06.24.2003
166     ***********************************************************
167     Purpose:
168     Update supplied faculty id.
169     **********************************************************/
170     function updateFaculty($con, $faculty_email, $faculty_firstname,
171     $faculty_id, $faculty_lastname, $faculty_account) {
172    
173     /*
174     Faculty must have both a unique non-blank staff_account, and non-blank last name.
175     */
176    
177     // Error flag
178     $err_code = 0;
179    
180     // Need for display/uniqueness
181     $faculty_name_display = $faculty_firstname . " " . $faculty_lastname;
182    
183     // Check to see if already exists
184     $exists_id = existsFaculty($con, $faculty_firstname, $faculty_lastname);
185    
186     if ($exists_id > 0 && $exists_id != $faculty_id) {
187     $err_code = 1;
188     $err_msg = "Failed. '" . $faculty_name_display . "' already exists in the Faculty table.";
189     }
190    
191     // Check for blank last name
192     if ($faculty_lastname == "") {
193     $err_code = 2;
194     $err_msg = "Failed. Cannot have a blank Last Name.";
195     }
196    
197    
198     printf("<center><h3>Updating Faculty...</h3>");
199    
200     // Table
201     printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">");
202     printf("<tr><td><br>");
203     printf("<strong>Messages:</strong><br>");
204    
205     if ($err_code == 0 ) {
206    
207     // Clean up strings
208     if (strlen($faculty_lastname) > 0) $faculty_lastname = textInmySQL($faculty_lastname);
209     if (strlen($faculty_firstname) > 0) $faculty_firstname = textInmySQL($faculty_firstname);
210     if (strlen($faculty_email) > 0) $faculty_email = textInmySQL($faculty_email);
211     if (strlen($faculty_account) > 0) $faculty_account = textInmySQL($faculty_account);
212    
213     // Build the SQL
214     $sql = "UPDATE faculty SET faculty_lastname = '"
215     . $faculty_lastname
216     . "', faculty_firstname ='"
217     . $faculty_firstname
218     . "', faculty_email ='"
219     . $faculty_email
220     . "', faculty_account ='"
221     . $faculty_account
222     . "' WHERE faculty_id ="
223     . $faculty_id;
224    
225     if (!mysql_query ($sql, $con)){
226     sql_err($sql);
227     mysql_query ("UNLOCK TABLES", $con);
228     bailout();
229     }
230     else {
231     mysql_query ("UNLOCK TABLES", $con);
232     printf("Successfully updated Faculty <b>%s</b><BR><BR>\n", $faculty_name_display);
233     }
234     }
235    
236     else printf("%s", $err_msg);
237     printf("<br><br>\n");
238     printf("</td></tr></table>\n");
239     printf("</center>\n");
240    
241     }
242    
243    
244     /**********************************************************
245     Function: updateFeature
246     Author: Paul Bramscher
247     Last Modified: 05.21.2003
248     ***********************************************************
249     Purpose:
250     Update supplied feature id.
251     **********************************************************/
252     function updateFeature($con, $feature, $feature_id, $image_alt, $image_path) {
253    
254     // Error flag
255     $err_code = 0;
256    
257     // Need for display/uniqueness
258     $feature_display = $feature;
259     $feature_search = textSearchmySQL($feature);
260    
261     // Check to see if already exists
262     $exists = recordCount($con, "feature", "feature", $feature_search, "A");
263     $exists_id = lookupField($con, "feature", "feature", $feature_search, "feature_id");
264    
265     // If exists in the feature table under a different feature_id
266     if ($exists > 0 && $exists_id != $feature_id) {
267     $err_code = 1;
268     $err_msg = "Failed. '" . $feature_display . "' already exists in the feature table.";
269     }
270    
271     // Check for blank entry
272     if ($feature == "") {
273     $err_code = 2;
274     $err_msg = "Failed. Must supply some value for the feature.";
275     }
276    
277     printf("<center><h3>Updating Feature...</h3>\n");
278    
279     // Table
280     printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">\n");
281     printf("<tr><td><br>\n");
282     printf("<strong>Messages:</strong><br>");
283    
284    
285     // Perform the update only if no errors encountered
286     if ($err_code == 0) {
287    
288     // Clean up strings
289     $feature = textInmySQL($feature);
290     $image_alt = textInmySQL($image_alt);
291     $image_path = textInmySQL($image_path);
292    
293     // Build the SQL
294     $sql = "UPDATE feature SET feature = '"
295     . $feature
296     . "', image_alt ='"
297     . $image_alt
298     . "', image_path ='"
299     . $image_path
300     . "' WHERE feature_id ="
301     . $feature_id;
302    
303     if (!mysql_query ($sql, $con)){
304     sql_err($sql);
305     mysql_query ("UNLOCK TABLES", $con);
306     bailout();
307     }
308     else {
309     mysql_query ("UNLOCK TABLES", $con);
310     printf("Updated <b>%s</b> feature.<BR><BR>\n", $feature_display);
311     }
312     }
313    
314     else printf("%s", $err_msg);
315    
316     printf("<br><br>\n");
317     printf("</td></tr></table>\n");
318     printf("</center>\n");
319    
320     }
321    
322    
323     /**********************************************************
324     Function: updateInfotype
325     Author: Paul Bramscher
326     Last Modified: 06.05.2003
327     ***********************************************************
328     Purpose:
329     Update supplied infotype id.
330     **********************************************************/
331     function updateInfotype($con, $infotype, $infotype_id, $masterinfotype_id, $mastersubject_id) {
332    
333     // Error flag
334     $err_code = 0;
335    
336     // Need for display/uniqueness purposes
337     $infotype_display = $infotype;
338     $infotype_search = textSearchmySQL($infotype);
339    
340     // Check to see if already exists
341     $exists = recordCount($con, "infotype", "infotype", $infotype_search, "A");
342     $exists_id = lookupField($con, "infotype", "infotype", $infotype_search, "infotype_id");
343    
344     // If exists in the infotype table under a different infotype_id (not editing the name of this infotype)
345     if ($exists > 0 && $exists_id != $infotype_id) {
346     $err_code = 1;
347     $err_msg = "Failed. <b>" . $infotype_display . "</b> already exists in the Information Type table.";
348     }
349    
350     // Check for blank entry
351     if ($infotype == "") {
352     $err_code = 2;
353     $err_msg = "Failed. Must supply some value for the Information Type name.";
354     }
355    
356     printf("<center><h3>Updating Infotype...</h3>");
357    
358     // Table
359     printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">");
360     printf("<tr><td><br>");
361     printf("<strong>Messages:</strong><br>");
362    
363     // Proceed if no errors encountered
364     if ($err_code == 0) {
365    
366     // Clean up strings
367     $infotype = textInmySQL($infotype);
368    
369    
370     // First, update affected RQS relationships
371     $sql = "UPDATE res_sub_infotype SET masterinfotype_id = "
372     . $masterinfotype_id
373     . " WHERE infotype_id = "
374     . $infotype_id;
375    
376     if (!mysql_query ($sql, $con)){
377     $err_code = 1;
378     sql_err($sql);
379     mysql_query ("UNLOCK TABLES", $con);
380     bailout();
381     }
382     else {
383     mysql_query ("UNLOCK TABLES", $con);
384     printf("Updated affected RQS relationships (if any)<BR>\n");
385     }
386     }
387    
388    
389     if ($err_code == 0) {
390    
391     // Build the SQL
392     $sql = "UPDATE infotype SET infotype = '"
393     . $infotype
394     . "', masterinfotype_id ="
395     . $masterinfotype_id
396     . ", mastersubject_id ="
397     . $mastersubject_id
398     . " WHERE infotype_id ="
399     . $infotype_id;
400    
401     if (!mysql_query ($sql, $con)){
402     $err_code = 1;
403     sql_err($sql);
404     mysql_query ("UNLOCK TABLES", $con);
405     bailout();
406     }
407     else {
408     mysql_query ("UNLOCK TABLES", $con);
409     printf("Updated Information Type to <b>%s</b>.<BR><BR>\n", $infotype_display);
410     }
411    
412     }
413    
414     else printf("%s<BR><BR>", $err_msg);
415    
416     printf("<BR>");
417     printf("</td></tr></table><BR>");
418     printf("</center>");
419    
420     }
421    
422    
423     /**********************************************************
424     Function: updateLibunit
425     Author: Paul Bramscher
426     Last Modified: 05.22.2003
427     ***********************************************************
428     Purpose:
429     Updates the supplied library unit id with new information.
430     **********************************************************/
431     function updateLibunit($con, $head_staff_id, $libunit, $libunit_abbrev, $libunit_id) {
432    
433     /*
434     Library Units must have both a unique name and unique abbreviation
435     e.g. "Digital Library Developement Laboratory" and "DLDL"
436     Additionally, empty values are not allowed.
437     */
438    
439     // Error flag
440     $err_code = 0;
441    
442     // Need for display/uniqueness purposes
443     $libunit_display = $libunit;
444     $libunit_abbrev_display = $libunit_abbrev;
445     $libunit_search = textSearchmySQL($libunit);
446     $libunit_abbrev_search = textSearchmySQL($libunit_abbrev);
447    
448     // Check to see if libunit already exists
449     $exists = recordCount($con, "libunit", "libunit", $libunit_search, "A");
450     $exists_id = lookupField($con, "libunit", "libunit", $libunit_search, "libunit_id");
451     if ($exists > 0 && $exists_id != $libunit_id) {
452     $err_code = 1;
453     $err_msg = "Failed. '" . $libunit_display . "' already exists in the Library Unit table.";
454     }
455    
456     // Check to see if libunit abbreviation already exists
457     $exists = recordCount($con, "libunit", "libunit_abbrev", $libunit_abbrev_search, "A");
458     $exists_id = lookupField($con, "libunit", "libunit_abbrev", $libunit_abbrev_search, "libunit_id");
459    
460     if ($exists > 0 && $exists_id != $libunit_id) {
461     $err_code = 2;
462     $err_msg = "Failed. '" . $libunit_abbrev_display . "' abbreviation already exists in the Library Unit table.";
463     }
464    
465     // Check for blank linunit entry
466     if ($libunit == "") {
467     $err_code = 3;
468     $err_msg = "Failed. Cannot enter a blank Library Unit.";
469     }
470    
471     // Check for blank linunit abbrev entry
472     if ($libunit_abbrev == "") {
473     $err_code = 4;
474     $err_msg = "Failed. Cannot enter a blank Library Unit abbreviation.";
475     }
476    
477     // Add only if no errors encountered
478     if ($err_code == 0) {
479    
480     if (strlen($libunit) > 0) $libunit = textInmySQL($libunit);
481     if (strlen($libunit_abbrev) > 0) $libunit_abbrev = textInmySQL($libunit_abbrev);
482    
483     // Build the SQL
484     $sql = "UPDATE libunit SET libunit = '"
485     . $libunit
486     . "', libunit_abbrev ='"
487     . $libunit_abbrev
488     . "', head_staff_id ="
489     . $head_staff_id
490     . " WHERE libunit_id ="
491     . $libunit_id;
492    
493     if (!mysql_query ($sql, $con)){
494     sql_err($sql);
495     mysql_query ("UNLOCK TABLES", $con);
496     bailout();
497     }
498     else {
499     mysql_query ("UNLOCK TABLES", $con);
500    
501     // Call the libunit form back
502     formLibunit($con, $libunit_id);
503     }
504     }
505    
506     else {
507     printf("<center><h3>Updating Library Unit...</h3>");
508    
509     // Table
510     printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">\n");
511     printf("<tr><td><br>\n");
512     printf("<strong>Messages:</strong><br>\n");
513     printf("%s", $err_msg);
514     printf("<BR><BR>\n");
515     printf("</td></tr></table>\n");
516     printf("</center>\n");
517     }
518     }
519    
520    
521     /**********************************************************
522     Function: updateLocation
523     Author: Paul Bramscher
524     Last Modified: 04.21.2003
525     ***********************************************************
526     Purpose:
527     Update supplied location id.
528     **********************************************************/
529     function updateLocation($con, $address1, $address2,
530     $address3, $address4, $campus, $hoursURL, $location, $location_descr,
531     $location_id, $mainURL, $mapURL, $referenceURL, $telephone) {
532    
533     // Error flag
534     $err_code = 0;
535    
536     // Need for display/uniqueness purposes
537     $location_display = $location;
538     $location_search = textSearchmySQL($location);
539    
540     // Check to see if already exists
541     $exists = recordCount($con, "location", "location", $location_search, "A");
542     $exists_id = lookupField($con, "location", "location", $location_search, "location_id");
543    
544     // If exists in the location table under a different location_id
545     if ($exists > 0 && $exists_id != $location_id) {
546     $err_code = 1;
547     $err_msg = "Failed. '" . $location_display . "' already exists in the location table.";
548     }
549    
550     // Check for blank entry
551     if ($location == "") {
552     $err_code = 2;
553     $err_msg = "Failed. Must supply some value for the location name.";
554     }
555    
556     printf("<center><h3>Updating Location...</h3>\n");
557    
558     // Table
559     printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">\n");
560     printf("<tr><td><br>\n");
561     printf("<strong>Messages:</strong><br>\n");
562    
563     // Perform the update only if no errors encountered
564     if ($err_code == 0) {
565    
566     // Clean up strings
567     if (strlen($location) > 0) $location = textInmySQL($location);
568     if (strlen($location_descr) > 0) $location_descr = textInmySQL($location_descr);
569     if (strlen($campus) > 0) $campus = textInmySQL($campus);
570     if (strlen($address1) > 0) $address1 = textInmySQL($address1);
571     if (strlen($address2) > 0) $address2 = textInmySQL($address2);
572     if (strlen($address3) > 0) $address3 = textInmySQL($address3);
573     if (strlen($address4) > 0) $address4 = textInmySQL($address4);
574     if (strlen($telephone) > 0) $telephone = textInmySQL($telephone);
575     if (strlen($mainURL) > 0) $mainURL = textInmySQL($mainURL);
576     if (strlen($referenceURL) > 0) $referenceURL = textInmySQL($referenceURL);
577     if (strlen($mapURL) > 0) $mapURL = textInmySQL($mapURL);
578     if (strlen($hoursURL) > 0) $hoursURL = textInmySQL($hoursURL);
579    
580     // Build the SQL
581     $sql = "UPDATE location SET location = '"
582     . $location
583     . "', location_descr ='"
584     . $location_descr
585     . "', campus ='"
586     . $campus
587     . "', address1 ='"
588     . $address1
589     . "', address2 ='"
590     . $address2
591     . "', address3 ='"
592     . $address3
593     . "', address4 ='"
594     . $address4
595     . "', mainURL ='"
596     . $mainURL
597     . "', hoursURL ='"
598     . $hoursURL
599     . "', referenceURL ='"
600     . $referenceURL
601     . "', mapURL ='"
602     . $mapURL
603     . "', telephone ='"
604     . $telephone
605     . "' WHERE location_id ="
606     . $location_id;
607    
608     if (!mysql_query ($sql, $con)){
609     sql_err($sql);
610     mysql_query ("UNLOCK TABLES", $con);
611     bailout();
612     }
613     else {
614     mysql_query ("UNLOCK TABLES", $con);
615     printf("Updated Location to <b>%s</b>.<BR><BR>\n", $location_display);
616     }
617     }
618     else printf("%s", $err_msg);
619    
620     printf("<br><br>\n");
621     printf("</td></tr></table>\n");
622     printf("</center>\n");
623    
624     }
625    
626    
627     /**********************************************************
628     Function: updatePassword
629     Author: Paul Bramscher
630     Last Modified: 06.23.2003
631     ***********************************************************
632     Purpose:
633     Changes the locally encrypted and mySQL stored password to
634     the newly supplied value. Note that the new password and
635     the "confirm" must match, and it must be 6 characters
636     minimum. As with purgePassword, at no time does this
637     system bring the password out of the database and present
638     it on an HTML form, neither in plaintext nor in a
639     "password" type HTML form field. The password in plaintext
640     is never viewable to the system, nor to mySQL itself. If
641     a user forgets his/her password, it must be reset by an
642     administrator.
643     **********************************************************/
644     function updatePassword($con, $password, $password_confirm, $staff_id) {
645    
646     // Error flag
647     $err_code = 0;
648    
649     // Check for less than 6 char.
650     if (strlen($password) < 6) {
651     $err_code = 1;
652     $err_msg = "Failed. Password must be 6 characters minimum.";
653     }
654    
655     // Check for mis-matched password and confirm
656     if ($password != $password_confirm) {
657     $err_code = 2;
658     $err_msg = "Failed. Password and confirm password didn't match.";
659     }
660    
661     // Update only if no errors encountered
662     if ($err_code == 0) {
663    
664     // Build the SQL
665     $sql = "UPDATE staff SET password = password('"
666     . $password
667     . "') WHERE staff_id ="
668     . $staff_id;
669    
670     if (!mysql_query ($sql, $con)){
671     sql_err($sql);
672     mysql_query ("UNLOCK TABLES", $con);
673     bailout();
674     }
675     else {
676     mysql_query ("UNLOCK TABLES", $con);
677    
678     // Call the staff form back
679     formStaff($con, $staff_id);
680     }
681     }
682    
683     else {
684     printf("<center><h3>Updating Local Password...</h3>");
685    
686     // Table
687     printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">\n");
688     printf("<tr><td><br>\n");
689     printf("<strong>Messages:</strong><br>\n");
690     printf("%s", $err_msg);
691     printf("<BR><BR>\n");
692     printf("</td></tr></table>\n");
693     printf("</center>\n");
694     }
695     }
696    
697    
698     /**********************************************************
699     Function: updateResource
700     Author: Paul Bramscher
701     Last Modified: 05.07.2003
702     ***********************************************************
703     Purpose:
704     Update supplied resource id, and call formResource back
705     again.
706     **********************************************************/
707     function updateResource($con, $annotation, $author, $call_no, $cat_num, $coverage_detail,
708     $edition, $infotype_id, $key_id, $other_title, $pub_date, $publisher, $sess_staff_account,
709     $sources_indexed, $title, $url) {
710    
711     // Clean up strings
712     if (strlen($annotation) > 0) $annotation = textInmySQL($annotation);
713     if (strlen($author) > 0) $author = textInmySQL($author);
714     if (strlen($call_no) > 0) $call_no = textInmySQL($call_no);
715     if (strlen($cat_num) > 0) $cat_num = textInmySQL($cat_num);
716     if (strlen($coverage_detail) > 0) $coverage_detail = textInmySQL($coverage_detail);
717     if (strlen($edition) > 0) $edition = textInmySQL($edition);
718     if (strlen($other_title) > 0) $other_title = textInmySQL($other_title);
719     if (strlen($pub_date) > 0) $pub_date = textInmySQL($pub_date);
720     if (strlen($publisher) > 0) $publisher = textInmySQL($publisher);
721     if (strlen($sources_indexed) > 0) $sources_indexed = textInmySQL($sources_indexed);
722     if (strlen($title)> 0) $title = textInmySQL($title);
723     if (strlen($url) > 0) $url = textInmySQL($url);
724    
725     // Set up SQL
726     $sql = "UPDATE resource SET annotation = '"
727     . $annotation
728     . "', author = '"
729     . $author
730     . "', call_no = '"
731     . $call_no
732     . "', cat_num = '"
733     . $cat_num
734     . "', coverage_detail = '"
735     . $coverage_detail
736     . "', date_modified = now() "
737     . ", edition = '"
738     . $edition
739     . "', infotype_id = "
740     . $infotype_id
741     . ", other_title = '"
742     . $other_title
743     . "', pub_date = '"
744     . $pub_date
745     . "', publisher = '"
746     . $publisher
747     . "', sources_indexed = '"
748     . $sources_indexed
749     . "', title = '"
750     . $title
751     . "', url = '"
752     . $url
753     . "', vendor_id = '"
754     . $vendor_id
755     . "', account_modified = '"
756     . $sess_staff_account
757     . "' WHERE resource_id = "
758     . $key_id;
759    
760     // printf("sql was: %s<br><br>\n", $sql);
761    
762     // Edit the record
763     mysql_query ("LOCK TABLE resource WRITE", $con);
764     if (!mysql_query($sql, $con)){
765     sql_err($con);
766     mysql_query ("UNLOCK TABLES", $con);
767     bailout();
768     }
769     else {
770     mysql_query("UNLOCK TABLES", $con);
771     formResource($con, $key_id, 0, 0, '');
772     }
773    
774     }
775    
776    
777     /**********************************************************
778     Function: updateService
779     Author: Paul Bramscher
780     Last Modified: 05.21.2003
781     ***********************************************************
782     Purpose:
783     Update supplied service id and call formService back again.
784     **********************************************************/
785     function updateService($con, $address1, $address2, $address3, $address4, $email,
786     $fax, $nonaff, $service, $serviceDescr, $service_id, $serviceURL, $telephone) {
787    
788     // Error flag
789     $err_code = 0;
790    
791     // Need for display/uniqueness
792     $service_display = $service;
793     $service_search = textSearchmySQL($service);
794    
795     // Check to see if already exists
796     $exists = recordCount($con, "service", "service", $service_search, "A");
797     $exists_id = lookupField($con, "service", "service", $service_search, "service_id");
798    
799     if ($exists > 0 && $exists_id != $service_id) {
800     $err_code = 1;
801     $err_msg = "Failed. '" . $service_display . "' already exists in the service table.";
802     }
803    
804     // Check for blank entry
805     if ($service == "") {
806     $err_code = 2;
807     $err_msg = "Failed. Cannot enter a blank service.";
808     }
809    
810     if ($err_code == 0) {
811    
812     // Clean up strings
813     if (strlen($address1) > 0) $address1 = textInmySQL($address1);
814     if (strlen($address2) > 0) $address2 = textInmySQL($address2);
815     if (strlen($address3) > 0) $address3 = textInmySQL($address3);
816     if (strlen($address4) > 0) $address4 = textInmySQL($address4);
817     if (strlen($email) > 0) $email = textInmySQL($email);
818     if (strlen($fax) > 0) $fax = textInmySQL($fax);
819     if (strlen($service) > 0) $service = textInmySQL($service);
820     if (strlen($serviceDescr) > 0) $serviceDescr = textInmySQL($serviceDescr);
821     if (strlen($serviceURL) > 0) $serviceURL = textInmySQL($serviceURL);
822     if (strlen($telephone) > 0) $telephone = textInmySQL($telephone);
823    
824     // Build the SQL
825     $sql = "UPDATE service SET service = '"
826     . $service
827     . "', serviceDescr ='"
828     . $serviceDescr
829     . "', address1 ='"
830     . $address1
831     . "', address2 ='"
832     . $address2
833     . "', address3 ='"
834     . $address3
835     . "', address4 ='"
836     . $address4
837     . "', serviceURL ='"
838     . $serviceURL
839     . "', email ='"
840     . $email
841     . "', fax ='"
842     . $fax
843     . "', telephone ='"
844     . $telephone
845     . "', nonaff = '"
846     . $nonaff
847     . "' WHERE service_id ="
848     . $service_id;
849    
850     if (!mysql_query ($sql, $con)){
851     sql_err($sql);
852     mysql_query ("UNLOCK TABLES", $con);
853     bailout();
854     }
855     else {
856     mysql_query ("UNLOCK TABLES", $con);
857    
858     // Call the service form back
859     formService($con, $service_id);
860     }
861    
862     }
863    
864     else {
865     printf("<center><h3>Updating Service...</h3>");
866    
867     // Table
868     printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">\n");
869     printf("<tr><td><br>\n");
870     printf("<strong>Messages:</strong><br>\n");
871     printf("%s", $err_msg);
872     printf("<BR><BR>\n");
873     printf("</td></tr></table>\n");
874     printf("</center>\n");
875     }
876    
877     }
878    
879    
880     /**********************************************************
881     Function: updateSingleField
882     Author: Paul Bramscher
883     Last Modified: 05.21.2003
884     ***********************************************************
885     Purpose:
886     Updates any single field in any supplied table. Checks
887     for uniqueness and blank value.
888     **********************************************************/
889     function updateSingleField($con, $display, $display_field, $key_field,
890     $key_id, $newValue, $table){
891    
892     // Error flag
893     $err_code = 0;
894    
895     $newValue_search = textSearchmySQL($newValue);
896    
897     // Check to see if already exists
898     $exists = recordCount($con, $table, $display_field, $newValue_search, "A");
899     $exists_id = lookupField($con, $table, $display_field, $newValue_search, $key_field);
900    
901     // If exists in the infotype table under a different infotype_id (not editing the name of this infotype)
902     if ($exists > 0 && $exists_id != $key_field) {
903     $err_code = 1;
904     $err_msg = "Failed. <b>" . $newValue . "</b> already exists in the <b>"
905     . $table
906     . "</b> table.\n";
907     }
908    
909     // Check for blank entry
910     if ($newValue == "") {
911     $err_code = 2;
912     $err_msg = "Failed. Must supply some value for the <b>"
913     . $display
914     . "</b>.";
915     }
916    
917     // Draw page heading
918     printf("<center><h3>Updating %s...</h3>", $display);
919    
920     printf("<table width =\"50%%\" border = \"3\" class=\"backLight\">");
921     printf("<tr><td><font face = \"Arial\">");
922     printf("<b>Messages:</b><br>\n");
923    
924     // Continue if no errors
925     if ($err_code == 0) {
926    
927     $newValue_display = $newValue;
928     $newValue = textInmySQL($newValue);
929    
930     // Build the SQL
931     $sql = "UPDATE "
932     . $table
933     . " SET "
934     . $display_field
935     . " = '"
936     . $newValue
937     . "' WHERE "
938     . $key_field
939     . " = "
940     . $key_id;
941    
942     if (!mysql_query ($sql, $con)){
943     sql_err($sql);
944     mysql_query ("UNLOCK TABLES", $con);
945     bailout();
946     }
947     else {
948     mysql_query ("UNLOCK TABLES", $con);
949     printf("%s successfully changed to <b>%s</b>.\n", $display, $newValue_display);
950     }
951    
952     }
953    
954     else printf("%s", $err_msg);
955    
956     printf("<br><br></td></tr></table><br>");
957     printf("</center>");
958     }
959    
960    
961     /**********************************************************
962     Function: updateStaff
963     Author: Paul Bramscher
964     Last Modified: 06.23.2003
965     ***********************************************************
966     Purpose:
967     Updates the supplied staff id with new information.
968     **********************************************************/
969     function updateStaff($con, $access_id, $first_name,
970     $last_name, $sess_access_level, $staff_account, $staff_email, $staff_id, $stafftitle_id) {
971    
972     /*
973     Staff must have, at a minimum, a last name, first name, and unique staff account
974     name. Uniqueness is enforced only on staff_account.
975     */
976    
977     // Error flag
978     $err_code = 0;
979    
980     // Need for display/uniqueness purposes
981     $staff_account_display = $staff_account;
982     $staff_account_search = textSearchmySQL($staff_account);
983    
984     // Check to see if the staff_account already exists
985     $exists = recordCount($con, "staff", "staff_account", $staff_account_search, "A");
986     $exists_id = lookupField($con, "staff", "staff_account", $staff_account_search, "staff_id");
987    
988     if ($exists > 0 && $exists_id != $staff_id) {
989     $err_code = 1;
990     $err_msg = "Failed. '" . $staff_account_display . "' already exists in the Staff table.";
991     }
992    
993     // Check for blank first name or last name
994     if ($first_name == "" || $last_name == "") {
995     $err_code = 2;
996     $err_msg = "Failed. A first and last name must be supplied for all staff.";
997     }
998    
999     // Check for blank staff_account
1000     if ($staff_account == "") {
1001     $err_code = 3;
1002     $err_msg = "Failed. A staff account must be supplied for all staff.";
1003     }
1004    
1005     // Check for access level higher than current access
1006     $this_access_level = lookupfield($con, "access", "access_id", $access_id, "access_level");
1007     if ($this_access_level > $sess_access_level) {
1008     $err_code = 4;
1009     $err_msg = "Failed. You may not promote staff to higher privileges than your own.";
1010     }
1011    
1012     // Continue only if no errors.
1013     if ($err_code == 0) {
1014    
1015     // Clean up strings
1016     if (strlen($first_name) > 0) $first_name = textInmySQL($first_name);
1017     if (strlen($last_name) > 0) $last_name = textInmySQL($last_name);
1018     if (strlen($staff_account) > 0) $staff_account = textInmySQL($staff_account);
1019     if (strlen($staff_email) > 0) $staff_email = textInmySQL($staff_email);
1020    
1021     // Build the SQL
1022     $sql = "UPDATE staff SET access_id = "
1023     . $access_id
1024     . ", first_name ='"
1025     . $first_name
1026     . "', last_name ='"
1027     . $last_name
1028     . "', stafftitle_id = "
1029     . $stafftitle_id
1030     . ", staff_account = '"
1031     . $staff_account
1032     . "', staff_email = '"
1033     . $staff_email
1034     . "' WHERE staff_id ="
1035     . $staff_id;
1036    
1037     if (!mysql_query ($sql, $con)){
1038     sql_err($sql);
1039     mysql_query ("UNLOCK TABLES", $con);
1040     bailout();
1041     }
1042     else {
1043     // Success. Call formStaff back.
1044     mysql_query ("UNLOCK TABLES", $con);
1045     formStaff($con, $staff_id);
1046     }
1047     }
1048     else {
1049    
1050     printf("<center><h3>Updating Staff...</h3>\n");
1051    
1052     // Table
1053     printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">\n");
1054     printf("<tr><td><br>\n");
1055     printf("<strong>Messages:</strong><br>\n");
1056    
1057     printf("%s<BR><BR>\n", $err_msg);
1058     printf("</td></tr></table>\n");
1059     printf("</center>\n");
1060     }
1061     }
1062    
1063    
1064     /**********************************************************
1065     Function: updateStyle
1066     Author: Paul Bramscher
1067     Last Modified: 05.22.2003
1068     ***********************************************************
1069     Purpose:
1070     Update the supplied style id. As with the insert transaction,
1071     no error checking is done to ensure that the supplied files
1072     actually exist and have proper permissions.
1073     **********************************************************/
1074     function updateStyle($con, $css_file, $footer_file, $header_file, $style_id, $style_title) {
1075    
1076     // Error flag
1077     $err_code = 0;
1078    
1079     // Need for display/uniqueness
1080     $style_title_display = $style_title;
1081     $style_title_search = textSearchmySQL($style_title);
1082    
1083     // Check to see if already exists under a different style_id
1084     $exists = recordCount($con, "style", "style_title", $style_title_search, "A");
1085     $exists_id = lookupField($con, "style", "style_title", $style_title_search, "style_id");
1086    
1087     if ($exists > 0 && $exists_id != $style_id) {
1088     $err_code = 1;
1089     $err_msg = "Failed. '" . $style_title_display . "' already exists in the style table.";
1090     }
1091    
1092     // Check for blank entry
1093     if ($style_title == "") {
1094     $err_code = 2;
1095     $err_msg = "Failed. Cannot enter a blank style.";
1096     }
1097    
1098     printf("<center><h3>Updating Style...</h3>");
1099    
1100     // Table
1101     printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">");
1102     printf("<tr><td><br>");
1103     printf("<strong>Messages:</strong><br>");
1104    
1105     if ($err_code == 0) {
1106    
1107     // Clean up strings
1108     if (strlen($css_file) > 0) $css_file = textInmySQL($css_file);
1109     if (strlen($footer_file) > 0) $footer_file = textInmySQL($footer_file);
1110     if (strlen($header_file) > 0) $header_file = textInmySQL($header_file);
1111     if (strlen($style_title) > 0) $style_title = textInmySQL($style_title);
1112    
1113     // Build the SQL
1114     $sql = "UPDATE style SET style_title = '"
1115     . $style_title
1116     . "', css_file ='"
1117     . $css_file
1118     . "', footer_file ='"
1119     . $footer_file
1120     . "', header_file ='"
1121     . $header_file
1122     . "' WHERE style_id ="
1123     . $style_id;
1124    
1125     if (!mysql_query ($sql, $con)){
1126     sql_err($sql);
1127     mysql_query ("UNLOCK TABLES", $con);
1128     bailout();
1129     }
1130     else {
1131     mysql_query ("UNLOCK TABLES", $con);
1132     printf("Successfully updated <b>%s</b> style.", $style_title_display);
1133     }
1134     }
1135     else printf("%s", $err_msg);
1136    
1137     printf("<br><br>\n");
1138     printf("</td></tr></table>\n");
1139     printf("</center>\n");
1140    
1141     }
1142    
1143    
1144     /**********************************************************
1145     Function: updateSubject
1146     Author: Paul Bramscher
1147     Last Modified: 06.11.2003
1148     ***********************************************************
1149     Purpose:
1150     Update the supplied subject id, and call formSubject back
1151     again.
1152     **********************************************************/
1153     function updateSubject($con, $subject, $subject_descr, $subject_id, $sublocation_id) {
1154    
1155     // Error flag
1156     $err_code = 0;
1157    
1158     // Need for display/uniqueness purposes
1159     $subject_display = $subject;
1160     $subject_search = textSearchmySQL($subject);
1161    
1162     // Check to see if already exists
1163     $exists = recordCount($con, "subject", "subject", $subject_search, "A");
1164     $exists_id = lookupField($con, "subject", "subject", $subject_search, "subject_id");
1165    
1166     // If exists in the subject table under a different subject_id (not editing the name of this subject)
1167     if ($exists > 0 && $exists_id != $subject_id) {
1168     $err_code = 1;
1169     $err_msg = "Failed. '" . $subject . "' already exists in the subject table.";
1170     }
1171    
1172     // Check for blank entry
1173     if ($subject == "") {
1174     $err_code = 2;
1175     $err_msg = "Failed. Must supply some value for the subject name.";
1176     }
1177    
1178     // Perform the update only if no errors encountered
1179     if ($err_code == 0) {
1180    
1181     // Clean up strings
1182     $subject = textInmySQL($subject);
1183     if (strlen($subject_descr) > 0) $subject_descr = textInmySQL($subject_descr);
1184    
1185     // Build the SQL
1186     $sql = "UPDATE subject SET subject = '"
1187     . $subject
1188     . "', subject_descr = '"
1189     . $subject_descr
1190     . "', sublocation_id ="
1191     . $sublocation_id
1192     . " WHERE subject_id = " . $subject_id;
1193    
1194     if (!mysql_query ($sql, $con)){
1195     sql_err($sql);
1196     mysql_query ("UNLOCK TABLES", $con);
1197     bailout();
1198     }
1199     else {
1200     mysql_query ("UNLOCK TABLES", $con);
1201     formSubject($con, $subject_id);
1202     } // updated subject
1203    
1204     }
1205    
1206     else {
1207    
1208     printf("<center><h3>Updating subject...</h3>");
1209    
1210     // Table
1211     printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">");
1212     printf("<tr><td><br>");
1213     printf("<strong>Messages:</strong><br>");
1214    
1215     printf("%s<BR><BR>", $err_msg);
1216     printf("</td></tr></table>");
1217     printf("</center>");
1218     }
1219     }
1220     ?>

  ViewVC Help
Powered by ViewVC 1.1.26