/[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 55 - (show annotations)
Sat Mar 6 02:44:16 2004 UTC (20 years, 1 month ago) by dpavlin
File size: 30056 byte(s)
half-working subject

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

  ViewVC Help
Powered by ViewVC 1.1.26