/[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 59 - (show annotations)
Sat Mar 6 04:38:41 2004 UTC (20 years, 2 months ago) by dpavlin
File size: 30065 byte(s)
fixed xx_insert_id replacemenet

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 libunit_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 print "### $libunit_id ";
364 var_dump($insert_res);
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 resource_id as id from resource where annotation = ? and author = ? and call_no = ? and cat_num = ? and coverage_detail = ? 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 ! from ! where ! = ?", $table."_id", $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 service_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 staff_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 subject_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