/[libdata]/branches/pear-db/admin/include/insert.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

Contents of /branches/pear-db/admin/include/insert.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 57 - (show annotations)
Sat Mar 6 03:09:46 2004 UTC (20 years, 1 month ago) by dpavlin
File size: 30031 byte(s)
cosmetic changes

1 <?php
2 /**********************************************************
3 Function Library: insert.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 insert functions for
9 LibData general setup tables. Those pertaining to
10 CLPS and RQS are located in scribe_application.php and
11 subject_builder.php respectively.
12 ***********************************************************
13 Table of Contents:
14
15 insertCoursesub
16 insertFaculty
17 insertFeature
18 insertInfotype
19 insertLibunit
20 insertLocation
21 insertResource
22 insertService
23 insertSingleField
24 insertStaff
25 insertStyle
26 insertSubject
27
28
29 **********************************************************/
30
31
32 /**********************************************************
33 Function: insertCoursesub
34 Author: Paul Bramscher
35 Last Modified: 06.03.2003
36 ***********************************************************
37 Purpose:
38 Inserts a course subject.
39 **********************************************************/
40 function insertCoursesub($con, $campus_id, $cip_code, $coursesub, $coursesub_descr) {
41
42 // Error flag
43 $err_code = 0;
44
45 // Need for display/uniqueness
46 $coursesub_display = $coursesub;
47 $coursesub_search = textSearchmySQL($coursesub);
48
49 // Check to see if already exists
50 $exists = recordCount($con, "coursesub", "coursesub", $coursesub_search, "A");
51 if ($exists > 0) {
52 $err_code = 1;
53 $err_msg = "Failed. '" . $coursesub_display . "' already exists in the course subject table.";
54 }
55
56 // Check for blank entry
57 if ($coursesub == "") {
58 $err_code = 2;
59 $err_msg = "Failed. Cannot enter a blank course subject.";
60 }
61
62 printf("<center><h3>Adding Course Subject...</h3>");
63
64 // Table
65 printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">");
66 printf("<tr><td><br>");
67 printf("<strong>Messages:</strong><br>");
68
69 // Add only if this coursesub doesn't already exist, and something was supplied
70 if ($err_code == 0) {
71
72 // Set up SQL
73 $sql = "INSERT INTO coursesub (coursesub, coursesub_descr, cip_code, campus_id) VALUES ( ? , ? , ? , ? )";
74
75 // Write the new row to the database
76 if (!xx_prepare_execute($sql, $coursesub, $coursesub_descr, $cip_code, $campus_id)){
77 sql_err($con);
78 xx_query ("UNLOCK TABLES", $con);
79 bailout();
80 }
81 else {
82 printf("Added Course Subject <b>%s</b>.<BR>", $coursesub_display);
83 xx_query("UNLOCK TABLES", $con);
84 }
85 }
86 else printf("%s", $err_msg);
87 printf("<br><br>\n");
88 printf("</td></tr></table>\n");
89 printf("</center>\n");
90 }
91
92
93 /**********************************************************
94 Function: insertFaculty
95 Author: Paul Bramscher
96 Last Modified: 06.24.2003
97 ***********************************************************
98 Purpose:
99 Inserts a faculty member.
100 **********************************************************/
101 function insertFaculty($con, $faculty_email, $faculty_firstname,
102 $faculty_lastname, $faculty_account) {
103
104 /*
105 Faculty must have both a unique non-blank staff_account, and non-blank last name.
106 */
107
108 // Error flag
109 $err_code = 0;
110
111 // Need for display/uniqueness
112 $faculty_name_display = $faculty_firstname . " " . $faculty_lastname;
113 $exists_id = existsFaculty($con, $faculty_firstname, $faculty_lastname);
114
115 if ($exists_id > 0) {
116 $err_code = 1;
117 $err_msg = "Failed. '" . $faculty_name_display . "' already exists in the Faculty table.";
118 }
119
120 // Check for blank last name
121 if ($faculty_lastname == "") {
122 $err_code = 2;
123 $err_msg = "Failed. Cannot enter a blank Last Name.";
124 }
125
126 printf("<center><h3>Adding Faculty...</h3>");
127
128 // Table
129 printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">");
130 printf("<tr><td><br>");
131 printf("<strong>Messages:</strong><br>");
132
133 // Add only if no errors encountered
134 if ($err_code == 0) {
135
136 // Clean up strings
137
138 // Set up SQL
139 $sql = "INSERT INTO faculty (faculty_lastname, faculty_firstname,
140 faculty_email, faculty_account) VALUES ( ? , ? , ? , ? )";
141
142 // Write the new row to the database
143 if (!xx_prepare_execute($sql, $faculty_lastname, $faculty_firstname, $faculty_email, $faculty_account)){
144 sql_err($con);
145 xx_query ("UNLOCK TABLES", $con);
146 bailout();
147 }
148 else {
149 printf("Added <b>%s</b> to the faculty table.<BR>\n", $faculty_name_display);
150 xx_query("UNLOCK TABLES", $con);
151 }
152 }
153
154 else printf("%s", $err_msg);
155 printf("<br><br>\n");
156 printf("</td></tr></table>\n");
157 printf("</center>\n");
158 }
159
160
161 /**********************************************************
162 Function: insertFeature
163 Author: Paul Bramscher
164 Last Modified: 05.21.2003
165 ***********************************************************
166 Purpose:
167 Inserts a feature.
168 **********************************************************/
169 function insertFeature($con, $feature, $image_alt, $image_path) {
170
171 // Error flag
172 $err_code = 0;
173
174 // Need for display/uniqueness
175 $feature_display = $feature;
176 $feature_search = textSearchmySQL($feature);
177
178 // Check to see if already exists
179 $exists = recordCount($con, "feature", "feature", $feature_search, "A");
180 if ($exists > 0) {
181 $err_code = 1;
182 $err_msg = "Failed. '" . $feature_display . "' already exists in the feature table.";
183 }
184
185 // Check for blank entry
186 if ($feature == "") {
187 $err_code = 2;
188 $err_msg = "Failed. Cannot enter a blank feature.";
189 }
190
191 printf("<center><h3>Adding Feature...</h3>");
192
193 // Table
194 printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">");
195 printf("<tr><td><br>");
196 printf("<strong>Messages:</strong><br>");
197
198 // Add only if this feature doesn't already exist, and something was supplied
199 if ($err_code == 0) {
200
201 // Clean up strings
202
203 // Set up SQL
204 $sql = "INSERT INTO feature (feature, image_alt, image_path) VALUES ( ? , ? , ? )";
205
206 // Write the new row to the database
207 if (!xx_prepare_execute($sql, $feature, $image_alt, $image_path)){
208 sql_err($con);
209 xx_query ("UNLOCK TABLES", $con);
210 bailout();
211 }
212 else {
213 printf("Added Feature <b>%s</b>.<BR>", $feature_display);
214 xx_query("UNLOCK TABLES", $con);
215 }
216 }
217 else printf("%s", $err_msg);
218 printf("<br><br>\n");
219 printf("</td></tr></table>\n");
220 printf("</center>\n");
221 }
222
223
224 /**********************************************************
225 Function: insertInfotype
226 Author: Paul Bramscher
227 Last Modified: 05.21.2003
228 ***********************************************************
229 Purpose:
230 Inserts an information type.
231 **********************************************************/
232 function insertInfotype($con, $infotype, $masterinfotype_id, $mastersubject_id) {
233
234 // Error flag
235 $err_code = 0;
236
237 // Need for display/uniqueness purposes
238 $infotype_display = $infotype;
239 $infotype_search = textSearchmySQL($infotype);
240
241 // Check to see if already exists
242 $exists = recordCount($con, "infotype", "infotype", $infotype_search, "A");
243
244 // If exists in the table
245 if ($exists > 0) {
246 $err_code = 1;
247 $err_msg = "Failed. '" . $infotype_display . "' already exists in the Information Type table.";
248 }
249
250 // Check for blank entry
251 if ($infotype == "") {
252 $err_code = 2;
253 $err_msg = "Failed. Must supply some value for the Information Type name.";
254 }
255
256
257 printf("<center><h3>Adding Information Type...</h3>");
258
259 // Table
260 printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">");
261 printf("<tr><td><br>");
262 printf("<strong>Messages:</strong><br>");
263
264 // Add only if this infotype doesn't already exist
265 if ($err_code == 0) {
266
267 // Clean up strings
268
269 // Set up SQL
270 $sql = "INSERT INTO infotype (infotype, masterinfotype_id, mastersubject_id) VALUES ( ? , ? , ? )";
271
272 // Write the new row to the database
273 if (!xx_prepare_execute($sql, $infotype, $masterinfotype_id, $mastersubject_id)){
274 sql_err($con);
275 xx_query ("UNLOCK TABLES", $con);
276 bailout();
277 }
278 else {
279 printf("Added Information Type <b>%s</b>.<BR>", $infotype_display);
280 xx_query("UNLOCK TABLES", $con);
281 }
282 }
283
284 else printf("%s<BR><BR>", $err_msg);
285
286 // Close the table
287 printf("<BR>");
288 printf("</td></tr></table>");
289 printf("</center>");
290 }
291
292
293 /**********************************************************
294 Function: insertLibunit
295 Author: Paul Bramscher
296 Last Modified: 05.22.2003
297 ***********************************************************
298 Purpose:
299 Inserts the supplied library unit information into the
300 database, and calls formLibunit back again, if the
301 insert passed a few checks (unique, no blank values, etc.)
302 **********************************************************/
303 function insertLibunit($con, $head_staff_id, $libunit, $libunit_abbrev) {
304
305 /*
306 Library Units must have both a unique name and unique abbreviation
307 e.g. "Digital Library Developement Laboratory" and "DLDL"
308 Additionally, empty values are not allowed.
309 */
310
311 // Error flag
312 $err_code = 0;
313
314 // Need for display/uniqueness purposes
315 $libunit_display = $libunit;
316 $libunit_abbrev_display = $libunit_abbrev;
317 $libunit_search = textSearchmySQL($libunit);
318 $libunit_abbrev_search = textSearchmySQL($libunit_abbrev);
319
320 // Check to see if libunit already exists
321 $exists = recordCount($con, "libunit", "libunit", $libunit_search, "A");
322 if ($exists > 0) {
323 $err_code = 1;
324 $err_msg = "Failed. '" . $libunit_display . "' already exists in the Library Unit table.";
325 }
326
327 // Check to see if libunit abbreviation already exists
328 $exists = recordCount($con, "libunit", "libunit_abbrev", $libunit_abbrev_search, "A");
329 if ($exists > 0) {
330 $err_code = 2;
331 $err_msg = "Failed. '" . $libunit_abbrev_display . "' abbreviation already exists in the Library Unit table.";
332 }
333
334 // Check for blank linunit entry
335 if ($libunit == "") {
336 $err_code = 3;
337 $err_msg = "Failed. Cannot enter a blank Library Unit.";
338 }
339
340 // Check for blank linunit abbrev entry
341 if ($libunit_abbrev == "") {
342 $err_code = 4;
343 $err_msg = "Failed. Cannot enter a blank Library Unit abbreviation.";
344 }
345
346 // Add only if no errors encountered
347 if ($err_code == 0) {
348
349
350 $sql = "INSERT INTO libunit (libunit, libunit_abbrev, head_staff_id) VALUES ( ? , ? , ? )";
351
352 // Write the new row to the database
353 xx_query ("LOCK TABLE libunit WRITE", $con);
354 if (!xx_prepare_execute($sql, $libunit, $libunit_abbrev, $head_staff_id)){
355 sql_err($con);
356 xx_query ("UNLOCK TABLES", $con);
357 bailout();
358 }
359 else {
360 // $libunit_id = xx_insert_id($con)
361 $insert_res = xx_prepare_execute("select 1 as id from libunit where libunit = ? and libunit_abbrev = ? and head_staff_id = ?", $libunit, $libunit_abbrev, $head_staff_id);
362 list($libunit_id) = $insert_res->fetchRow(DB_FETCHMODE_ORDERED);
363 xx_query("UNLOCK TABLES", $con);
364 formLibunit($con, $libunit_id);
365 }
366 }
367
368 else {
369 printf("<center><h3>Adding Library Unit...</h3>");
370
371 // Table
372 printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">\n");
373 printf("<tr><td><br>\n");
374 printf("<strong>Messages:</strong><br>\n");
375 printf("%s", $err_msg);
376 printf("<BR><BR>\n");
377 printf("</td></tr></table>\n");
378 printf("</center>\n");
379 }
380 }
381
382
383 /**********************************************************
384 Function: insertLocation
385 Author: Paul Bramscher
386 Last Modified: 06.16.2003
387 ***********************************************************
388 Purpose:
389 Inserts a library/location.
390 **********************************************************/
391 function insertLocation($con, $address1, $address2, $address3,
392 $address4, $campus, $hoursURL, $location, $location_descr, $mainURL,
393 $mapURL, $referenceURL, $telephone) {
394
395 // Need for display purposes
396 $location_display = $location;
397 $location_search = textSearchmySQL($location);
398
399 // Error flag
400 $err_code = 0;
401
402 // Check to see if already exists
403 $exists = recordCount($con, "location", "location", $location_search, "A");
404 if ($exists > 0) {
405 $err_code = 1;
406 $err_msg = "Failed. '" . $location_display . "' already exists in the location table.";
407 }
408
409 // Check for blank entry
410 if ($location == "") {
411 $err_code = 2;
412 $err_msg = "Failed. Cannot enter a blank location.";
413 }
414
415 printf("<center><h3>Adding Location...</h3>\n");
416
417 // Table
418 printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">\n");
419 printf("<tr><td><br>\n");
420 printf("<strong>Messages:</strong><br>\n");
421
422 // Add only if this location doesn't already exist, and something was supplied
423 if ($err_code == 0) {
424
425 // Clean up strings
426
427 // Set up SQL
428 $sql = "INSERT INTO location (location, location_descr, campus, address1,
429 address2, address3, address4, telephone, mainURL, referenceURL,
430 mapURL, hoursURL) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
431
432 // Write the new row to the database
433 if (!xx_prepare_execute($sql, $location, $location_descr, $campus, $address1, $address2, $address3, $address4, $telephone, $mainURL, $referenceURL, $mapURL, $hoursURL)){
434 sql_err($con);
435 xx_query ("UNLOCK TABLES", $con);
436 bailout();
437 }
438 else {
439
440 printf("Added <b>%s</b> location.", $location_display);
441 xx_query("UNLOCK TABLES", $con);
442 }
443 }
444
445 else printf("%s", $err_msg);
446 printf("<br><br>\n");
447 printf("</td></tr></table>\n");
448 printf("</center>\n");
449
450 }
451
452
453 /**********************************************************
454 Function: insertResource
455 Author: Paul Bramscher
456 Last Modified: 04.21.2003
457 ***********************************************************
458 Purpose:
459 Inserts a resource.
460 **********************************************************/
461 function insertResource($con, $annotation, $author, $call_no, $cat_num,
462 $coverage_detail, $edition, $infotype_id, $mastersubject_id, $other_title,
463 $pub_date, $publisher, $sess_staff_account, $sources_indexed, $title, $url) {
464
465 // Error flag
466 $err_code = 0;
467
468 // Check to see if already exists
469 $exists = recordCount($con, "resource", "title", $title, "A");
470
471 // If exists in the table
472 if ($exists > 0) {
473 $err_code = 1;
474 $err_msg = "Failed. '" . $title . "' already exists in the Resource table.";
475 }
476
477 // Check for blank entry
478 if ($title == "") {
479 $err_code = 2;
480 $err_msg = "Failed. Must supply some value for the Title field.";
481 }
482
483 // Proceed only if no errors
484 if ($err_code == 0) {
485
486 // Clean up strings
487
488 // Build the SQL
489 $sql = "INSERT INTO resource (annotation, author, call_no, cat_num,
490 coverage_detail, date_created, date_modified, edition,
491 infotype_id, other_title, pub_date, publisher, sources_indexed,
492 title, url, account_created) VALUES ( ? , ? , ? , ? , ? , now(), now(), ? , ? , ? , ? , ? , ? , ? , ? , ? )";
493
494 // Debugging
495 // printf("sql was: %s<BR>", $sql);
496
497 // Write the new record to the database
498 xx_query ("LOCK TABLE resource WRITE", $con);
499 if (!xx_prepare_execute($sql, $annotation, $author, $call_no, $cat_num, $coverage_detail, $edition, $infotype_id, $other_title, $pub_date, $publisher, $sources_indexed, $title, $url, $sess_staff_account)){
500 sql_err($con);
501 xx_query ("UNLOCK TABLES", $con);
502 bailout();
503 }
504 else {
505 // $resource_id = xx_insert_id($con)
506 $insert_res = xx_prepare_execute("select 1 as id from resource where annotation = ? and author = ? and call_no = ? and cat_num = ? and coverage_detail = ? and date_created = ? and date_modified = ? and edition = ? and infotype_id = ? and other_title = ? and pub_date = ? and publisher = ? and sources_indexed = ? and title = ? and url = ? and account_created = ?", $annotation, $author, $call_no, $cat_num, $coverage_detail, $edition, $infotype_id, $other_title, $pub_date, $publisher, $sources_indexed, $title, $url, $sess_staff_account);
507 list($resource_id) = $insert_res->fetchRow(DB_FETCHMODE_ORDERED);
508 xx_query("UNLOCK TABLES", $con);
509
510 // Now set up this resource with its first mastersubject
511 // Note that id#1 = N/A and id#2 = (All), and are not used here.
512 if ($mastersubject_id > 2) {
513 $sql = "INSERT INTO res_mastersubject (resource_id, mastersubject_id) VALUES ( ? , ? )";
514
515 // Write the new res_mastersubject to the database
516 xx_query ("LOCK TABLE res_mastersubject WRITE", $con);
517 if (!xx_prepare_execute($sql, $resource_id, $mastersubject_id)){
518 sql_err($con);
519 xx_query ("UNLOCK TABLES", $con);
520 bailout();
521 }
522 else {
523 xx_query("UNLOCK TABLES", $con);
524 }
525 }
526 }
527
528 // Call the formResource page back, in case user wants to edit further
529 formResource($con, $resource_id, 0, 0, '');
530
531 } // end insert new resource
532
533 else {
534 printf("<center><h3>Adding Resource...</h3>");
535
536 // Table
537 printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">\n");
538 printf("<tr><td><br>\n");
539 printf("<strong>Messages:</strong><br>\n");
540 printf("%s", $err_msg);
541 printf("<BR><BR>\n");
542 printf("</td></tr></table>\n");
543 printf("</center>\n");
544 } // end error messages
545
546 } // end function
547
548
549 /**********************************************************
550 Function: insertSingleField
551 Author: Paul Bramscher
552 Last Modified: 05.21.2003
553 ***********************************************************
554 Purpose:
555 Inserts any single field value into any table.
556 **********************************************************/
557 function insertSingleField($con, $display, $field, $newValue, $table){
558
559 // Error flag
560 $err_code = 0;
561
562 // Need for display/uniqueness purposes
563 $newValue_search = textSearchmySQL($newValue);
564 $newValue_display = $newValue;
565
566 // Check to see if already exists
567 $exists = recordCount($con, $table, $field, $newValue_search, "A");
568 if ($exists > 0) {
569 $err_code = 1;
570 $err_msg = "Failed. <b>"
571 . $newValue_display
572 . "</b> already exists in the "
573 . $display
574 . " table.";
575 }
576
577 // Check for blank entry
578 if ($newValue == "") {
579 $err_code = 2;
580 $err_msg = "Failed. Cannot enter a blank <b>"
581 . $display
582 . "</b> value.";
583 }
584
585 // Draw page heading
586 printf("<center><h3>Adding New %s</h3>", $display);
587
588 printf("<table width =\"50%%\" border = \"3\" class=\"backLight\">");
589 printf("<tr><td><b>Messages:</b><br>");
590
591 // Add only if this item doesn't already exist, and a value was supplied
592 if ($err_code == 0){
593
594 // Clean up strings
595
596 // Build the SQL
597 $sql = "INSERT INTO ! ( ! ) VALUES ( ? )";
598
599 // Debugging
600 // printf("sql was: %s<br>", $sql);
601
602 if (!xx_prepare_execute($sql, $table, $field, $newValue)){
603 sql_err($sql);
604 xx_query ("UNLOCK TABLES", $con);
605 bailout();
606 }
607 else {
608 // $new_id = xx_insert_id($con)
609 $insert_res = xx_prepare_execute("select 1 as id from ? where ? = ?", $table, $field, $newValue);
610 list($new_id) = $insert_res->fetchRow(DB_FETCHMODE_ORDERED);
611 xx_query ("UNLOCK TABLES", $con);
612 printf("%s <b>%s</b> successfully added.\n", $display, $newValue_display);
613 }
614 }
615
616 else printf ("%s\n", $err_msg);
617 printf("<br><br></td></tr></table>");
618 printf("</center>");
619 }
620
621
622 /**********************************************************
623 Function: insertService
624 Author: Paul Bramscher
625 Last Modified: 05.21.2003
626 ***********************************************************
627 Purpose:
628 Inserts a service.
629 **********************************************************/
630 function insertService($con, $address1, $address2, $address3, $address4,
631 $email, $fax, $nonaff, $service, $serviceDescr, $serviceURL, $telephone) {
632
633 // Error flag
634 $err_code = 0;
635
636 // Need for display/uniqueness
637 $service_display = $service;
638 $service_search = textSearchmySQL($service);
639
640 // Check to see if already exists
641 $exists = recordCount($con, "service", "service", $service_search, "A");
642 if ($exists > 0) {
643 $err_code = 1;
644 $err_msg = "Failed. '" . $service_display . "' already exists in the service table.";
645 }
646
647 // Check for blank entry
648 if ($service == "") {
649 $err_code = 2;
650 $err_msg = "Failed. Cannot enter a blank service.";
651 }
652
653 // Add only if this service doesn't already exist, and something was supplied
654 if ($err_code == 0) {
655
656 // Clean up strings
657
658 // Set up SQL
659 $sql = "INSERT INTO service (address1, address2, address3, address4,
660 email, fax, nonaff, service, serviceDescr, serviceURL,
661 telephone) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
662
663 // Write the new row to the database
664 xx_query ("LOCK TABLE service WRITE", $con);
665 if (!xx_prepare_execute($sql, $address1, $address2, $address3, $address4, $email, $fax, $nonaff, $service, $serviceDescr, $serviceURL, $telephone)){
666 sql_err($con);
667 xx_query ("UNLOCK TABLES", $con);
668 bailout();
669 }
670 else {
671 // $service_id = xx_insert_id($con)
672 $insert_res = xx_prepare_execute("select 1 as id from service where address1 = ? and address2 = ? and address3 = ? and address4 = ? and email = ? and fax = ? and nonaff = ? and service = ? and serviceDescr = ? and serviceURL = ? and telephone = ?", $address1, $address2, $address3, $address4, $email, $fax, $nonaff, $service, $serviceDescr, $serviceURL, $telephone);
673 list($service_id) = $insert_res->fetchRow(DB_FETCHMODE_ORDERED);
674 xx_query("UNLOCK TABLES", $con);
675 formService($con, $service_id);
676 }
677 }
678 else {
679 // Draw page heading
680 printf("<center><h3>Adding New Service...</h3>");
681
682 printf("<table width =\"50%%\" border = \"3\" class=\"backLight\">");
683 printf("<tr><td><b>Messages:</b><br>");
684
685 printf ("%s\n", $err_msg);
686 printf("<br><br></td></tr></table>");
687 printf("</center>");
688 }
689
690 }
691
692
693 /**********************************************************
694 Function: insertStaff
695 Author: Paul Bramscher
696 Last Modified: 06.23.2003
697 ***********************************************************
698 Purpose:
699 Inserts the supplied staffperson information, and calls
700 formStaff back again if the insert was valid.
701 **********************************************************/
702 function insertStaff($con, $access_id, $first_name,
703 $last_name, $sess_access_level, $staff_account, $staff_email, $stafftitle_id) {
704
705 /*
706 Staff must have, at a minimum, a last name, first name, and unique staff account name.
707 Uniqueness is enforced only on staff_account.
708 */
709
710 // Error flag
711 $err_code = 0;
712
713 // Need for display/uniqueness purposes
714 $staff_account_display = $staff_account;
715 $staff_account_search = textSearchmySQL($staff_account);
716
717 // Check to see if the account name already exists
718 $exists = recordCount($con, "staff", "staff_account", $staff_account_search, "A");
719 if ($exists > 0) {
720 $err_code = 1;
721 $err_msg = "Failed. '" . $staff_account_display . "' already exists in the Staff table.";
722 }
723
724 // Check for blank first name or last name
725 if ($first_name == "" || $last_name == "") {
726 $err_code = 2;
727 $err_msg = "Failed. A first and last name must be supplied for all staff.";
728 }
729
730 // Check for blank staff account
731 if ($staff_account == "") {
732 $err_code = 3;
733 $err_msg = "Failed. A staff account (x500 if applicable) must be supplied for all staff.";
734 }
735
736 // Check for access level higher than current access
737 $this_access_level = lookupfield($con, "access", "access_id", $access_id, "access_level");
738 if ($this_access_level > $sess_access_level) {
739 $err_code = 4;
740 $err_msg = "Failed. You may not create staff with higher privileges than your own.";
741 }
742
743 // Add only if no errors encountered
744 if ($err_code == 0) {
745
746 // Clean up strings
747
748 // Set up SQL
749 $sql = "INSERT INTO staff (access_id, first_name, last_name, stafftitle_id,
750 staff_account, staff_email) VALUES ( ? , ? , ? , ? , ? , ? )";
751
752 // Debugging
753 // printf("sql was: %s<br><br>\n", $sql);
754
755 // Write the new row to the database
756 xx_query ("LOCK TABLE staff WRITE", $con);
757 if (!xx_prepare_execute($sql, $access_id, $first_name, $last_name, $stafftitle_id, $staff_account, $staff_email)){
758 sql_err($con);
759 xx_query ("UNLOCK TABLES", $con);
760 bailout();
761 }
762 else {
763
764 // Success, call formStaff back.
765 // $staff_id = xx_insert_id($con)
766 $insert_res = xx_prepare_execute("select 1 as id from staff where access_id = ? and first_name = ? and last_name = ? and stafftitle_id = ? and staff_account = ? and staff_email = ?", $access_id, $first_name, $last_name, $stafftitle_id, $staff_account, $staff_email);
767 list($staff_id) = $insert_res->fetchRow(DB_FETCHMODE_ORDERED);
768 xx_query("UNLOCK TABLES", $con);
769 formStaff($con, $staff_id);
770 }
771 }
772 else {
773 // Failure message box
774 printf("<center><h3>Adding Staff...</h3>\n");
775 printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">\n");
776 printf("<tr><td><br>\n");
777 printf("<strong>Messages:</strong><br>\n");
778 printf("%s", $err_msg);
779 printf("<br><br>\n");
780 printf("</td></tr></table>\n");
781 printf("</center>\n");
782 }
783 }
784
785
786 /**********************************************************
787 Function: insertStyle
788 Author: Paul Bramscher
789 Last Modified: 05.22.2003
790 ***********************************************************
791 Purpose:
792 Inserts a style type. Note that css_file, footer_file, and
793 header_file fields are merely pointers to those files.
794 No error checking is done here to ensure their existence
795 and permissions settings. This must be accomplished by
796 someone with proper OS access.
797 **********************************************************/
798 function insertStyle($con, $css_file, $footer_file, $header_file, $style_title) {
799
800 // Error flag
801 $err_code = 0;
802
803 // Need for display/uniqueness
804 $style_title_display = $style_title;
805 $style_title_search = textSearchmySQL($style_title);
806
807 // Check to see if already exists
808 $exists = recordCount($con, "style", "style_title", $style_title_search, "A");
809 if ($exists > 0) {
810 $err_code = 1;
811 $err_msg = "Failed. '" . $style_title_display . "' already exists in the style table.";
812 }
813
814 // Check for blank entry
815 if ($style_title == "") {
816 $err_code = 2;
817 $err_msg = "Failed. Cannot enter a blank style.";
818 }
819
820 printf("<center><h3>Adding Style...</h3>");
821
822 // Table
823 printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">");
824 printf("<tr><td><br>");
825 printf("<strong>Messages:</strong><br>");
826
827 // Add only if this style doesn't already exist, and something was supplied
828 if ($err_code == 0) {
829
830 // Clean up strings
831
832 // Set up SQL
833 $sql = "INSERT INTO style (css_file, footer_file, header_file, style_title) VALUES ( ? , ? , ? , ? )";
834
835 // Write the new row to the database
836 if (!xx_prepare_execute($sql, $css_file, $footer_file, $header_file, $style_title)){
837 sql_err($con);
838 xx_query ("UNLOCK TABLES", $con);
839 bailout();
840 }
841 else {
842 xx_query("UNLOCK TABLES", $con);
843 printf("Added <b>%s</b> style.<br><br>\n", $style_title_display);
844 }
845 }
846 else printf("%s", $err_msg);
847 printf("<br><br>\n");
848 printf("</td></tr></table>\n");
849 printf("</center>\n");
850 }
851
852
853 /**********************************************************
854 Function: insertSubject
855 Author: Paul Bramscher
856 Last Modified: 09.23.2003
857 ***********************************************************
858 Purpose:
859 Inserts a subject. If successful, calls formSubject
860 back again.
861 **********************************************************/
862 function insertSubject($con, $sess_staff_account, $sess_staff_id, $subject, $subject_descr, $sublocation_id) {
863
864 // Error flag
865 $err_code = 0;
866
867 // Need for display/uniqueness purposes
868 $subject_display = $subject;
869 $subject_search = textSearchmySQL($subject);
870
871 // Check to see if already exists
872 $exists = recordCount($con, "subject", "subject", $subject_search, "A");
873 if ($exists > 0) {
874 $err_code = 1;
875 $err_msg = "Failed. '" . $subject_display . "' already exists in the subject table.";
876 }
877
878 // Check for blank entry
879 if ($subject == "") {
880 $err_code = 2;
881 $err_msg = "Failed. Cannot enter a blank subject.";
882 }
883
884 // Add only if this subject doesn't already exist, and something was supplied
885 if ($err_code == 0) {
886
887 // Clean up strings
888
889 // Set up SQL
890 $sql = "INSERT INTO subject (subject, subject_descr, sublocation_id, rqs_date_created, rqs_account_created) VALUES ( ? , ? , ? , now(), ? )";
891
892 // Write the new row to the database
893 xx_query ("LOCK TABLE subject WRITE", $con);
894 if (!xx_prepare_execute($sql, $subject, $subject_descr, $sublocation_id, $sess_staff_account)){
895 sql_err($con);
896 xx_query ("UNLOCK TABLES", $con);
897 bailout();
898 }
899 else {
900 // $subject_id = xx_insert_id($con)
901 $insert_res = xx_prepare_execute("select 1 as id from subject where subject = ? and subject_descr = ? and sublocation_id = ? and rqs_account_created = ?", $subject, $subject_descr, $sublocation_id, $sess_staff_account);
902 list($subject_id) = $insert_res->fetchRow(DB_FETCHMODE_ORDERED);
903 xx_query("UNLOCK TABLES", $con);
904
905 // Insert this staff person as an assigned staff member to this subject
906 $sql = "INSERT INTO sub_staff (subject_id, staff_id) VALUES ( ? , ? )";
907
908 if (!xx_prepare_execute($sql, $subject_id, $sess_staff_id)){
909 sql_err($con);
910 xx_query ("UNLOCK TABLES", $con);
911 bailout();
912 }
913 else {
914 xx_query("UNLOCK TABLES", $con);
915 }
916
917 formSubject($con, $subject_id);
918 } // good write of subject
919 }
920
921 else {
922
923 printf("<center><h3>Adding subject...</h3>");
924
925 // Table
926 printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">");
927 printf("<tr><td><br>");
928 printf("<strong>Messages:</strong><br>");
929
930 printf("%s<BR><BR>", $err_msg);
931 printf("</td></tr></table>");
932 printf("</center>");
933 }
934
935 } // function
936 ?>

  ViewVC Help
Powered by ViewVC 1.1.26