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