1 |
<?php |
2 |
/********************************************************** |
3 |
Function Library: public_controls.php |
4 |
Original Author: Paul Bramscher <brams006@umn.edu> |
5 |
Last Modified: 03.04.2004 |
6 |
*********************************************************** |
7 |
Comments: |
8 |
Publicly accessible and executable functions. |
9 |
*********************************************************** |
10 |
Table of Contents: |
11 |
displayCourseHeader |
12 |
displayCoursePers |
13 |
displayRelatedPages |
14 |
displayRelatedSubjects |
15 |
displayTOC |
16 |
dropDownCoursesubSelected |
17 |
dropDownFacultySelected |
18 |
dropDownFieldOmit |
19 |
dropDownFieldSelected |
20 |
existsRow |
21 |
lookupField |
22 |
lookupStaff |
23 |
pageLoadStats |
24 |
printAlphabet |
25 |
subLoadStats |
26 |
textOutHTML |
27 |
textSearchmySQL |
28 |
**********************************************************/ |
29 |
|
30 |
|
31 |
/********************************************************** |
32 |
Function: displayCourseHeader |
33 |
Author: Paul Bramscher |
34 |
Last Modified: 11.21.2003 |
35 |
*********************************************************** |
36 |
Purpose: |
37 |
Output the course related information for a course page. |
38 |
**********************************************************/ |
39 |
function displayCourseHeader($page_id, $pagetitle_style) { |
40 |
|
41 |
// Retrieve current information |
42 |
$sql = "SELECT * |
43 |
FROM |
44 |
course c |
45 |
LEFT JOIN term t using (term_id) |
46 |
LEFT JOIN campus p on c.campus_id = p.campus_id |
47 |
LEFT JOIN coursesub s on c.coursesub_id = s.coursesub_id |
48 |
|
49 |
WHERE |
50 |
page_id = " . $page_id; |
51 |
|
52 |
$rs = xx_tryquery($sql); |
53 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
54 |
|
55 |
$course_id = $row["course_id"]; |
56 |
$staff_id_created = $row["staff_id_created"]; |
57 |
$staff_id_edited = $row["staff_id_edited"]; |
58 |
$coursesub_id = $row["coursesub_id"]; |
59 |
$coursesub = $row["coursesub"]; |
60 |
$course_num = $row["course_num"]; |
61 |
$course_section = $row["course_section"]; |
62 |
$course_concat = $row["course_concat"]; |
63 |
$term_id = $row["term_id"]; |
64 |
$term = $row["term"]; |
65 |
$course_year = $row["course_year"]; |
66 |
$campus_id = $row["campus_id"]; |
67 |
$campus = $row["campus"]; |
68 |
$courseheader = $row["courseheader"]; |
69 |
$introheader1 = $row["introheader1"]; |
70 |
$intromessage1 = $row["intromessage1"]; |
71 |
$introheader2 = $row["introheader2"]; |
72 |
$intromessage2 = $row["intromessage2"]; |
73 |
|
74 |
// Course Header |
75 |
if (strlen($courseheader) > 1) printf("%s<BR>\n", $courseheader); |
76 |
|
77 |
// Start the span class |
78 |
if ($pagetitle_style > 0) printf("<span class=\"S%d\">%s</span>", $pagetitle_style, $course_concat); |
79 |
else printf("%s", $course_concat); |
80 |
printf("<BR><BR>\n"); |
81 |
|
82 |
// Display course term |
83 |
if (strlen($term) > 1 && $term_id > 1) printf("%s", $term); |
84 |
|
85 |
// Display Comma |
86 |
if (strlen($term) > 1 && strlen($course_year) > 1) printf(", "); |
87 |
|
88 |
// Display course year |
89 |
if (strlen($course_year) > 1) printf("%s", $course_year); |
90 |
|
91 |
printf("<BR>"); |
92 |
|
93 |
// Campus |
94 |
if (strlen($campus) > 0 && $campus_id > 1) printf("%s<BR>\n", $campus); |
95 |
|
96 |
// Intro header1 |
97 |
if (strlen($introheader1) > 0) { |
98 |
printf("<center><b>\n"); |
99 |
printf("%s", $introheader1); |
100 |
printf("</b></center><br>\n"); |
101 |
|
102 |
} |
103 |
|
104 |
// Intro Message1 |
105 |
if (strlen($intromessage1) > 0) { |
106 |
printf("%s", $intromessage1); |
107 |
printf("<br>\n"); |
108 |
} |
109 |
|
110 |
// Intro header2 |
111 |
if (strlen($introheader2) > 0) { |
112 |
printf("<center><b>\n"); |
113 |
printf("%s", $introheader2); |
114 |
printf("</b></center><br>\n"); |
115 |
|
116 |
} |
117 |
|
118 |
// Intro Message2 |
119 |
if (strlen($intromessage2) > 0) { |
120 |
printf("%s", $intromessage2); |
121 |
printf("<br>\n"); |
122 |
} |
123 |
|
124 |
} |
125 |
|
126 |
|
127 |
/********************************************************** |
128 |
Function: displayCoursePers |
129 |
Author: Paul Bramscher |
130 |
Last Modified: 03.04.2004 |
131 |
*********************************************************** |
132 |
Purpose: |
133 |
Displays the personnel associated with the course, by |
134 |
looking up the course id based on the page id. |
135 |
**********************************************************/ |
136 |
function displayCoursePers($page_id) { |
137 |
|
138 |
// Determine the course id |
139 |
$course_id = lookupfield("course", "page_id", $page_id, "course_id"); |
140 |
|
141 |
// Retrieve current information |
142 |
$sql = "SELECT * |
143 |
FROM |
144 |
course_personnel cp |
145 |
LEFT JOIN staff s using (staff_id) |
146 |
LEFT JOIN stafftitle st on cp.stafftitle_id = st.stafftitle_id |
147 |
LEFT JOIN faculty f on cp.faculty_id = f.faculty_id |
148 |
|
149 |
WHERE |
150 |
course_id = " . $course_id . " ORDER BY personnel_id"; |
151 |
|
152 |
$rs = xx_tryquery($sql); |
153 |
|
154 |
// See how many in this record set |
155 |
$num_personnel = xx_num_rows($rs); |
156 |
|
157 |
if ($num_personnel > 0) { |
158 |
|
159 |
// Display course personnel |
160 |
printf("<BR>\n"); |
161 |
printf("<b>Personnel:</b><br>\n"); |
162 |
|
163 |
|
164 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
165 |
|
166 |
// Initialize |
167 |
$last_name = ""; |
168 |
$first_name = ""; |
169 |
$email = ""; |
170 |
$stafftitle = ""; |
171 |
|
172 |
// Fetch the general stuff |
173 |
$personnel_id = $row["personnel_id"]; |
174 |
$staff_id = $row["staff_id"]; |
175 |
$faculty_id = $row["faculty_id"]; |
176 |
$stafftitle = $row["stafftitle"]; |
177 |
$stafftitle_id = $row["stafftitle_id"]; |
178 |
|
179 |
// Row is staff. (Not 0, NULL, 1=N/A). |
180 |
if ($staff_id > 1) { |
181 |
|
182 |
// Gather the staff table fields |
183 |
$last_name = $row["last_name"]; |
184 |
$first_name = $row["first_name"]; |
185 |
$email = $row["staff_email"]; |
186 |
|
187 |
} |
188 |
|
189 |
// Row is faculty (Not 0, NULL, 1=N/A). |
190 |
else if ($faculty_id > 1) { |
191 |
|
192 |
// Gather the faculty table fields |
193 |
$last_name = $row["faculty_lastname"]; |
194 |
$first_name = $row["faculty_firstname"]; |
195 |
$email = $row["faculty_email"]; |
196 |
|
197 |
} |
198 |
|
199 |
// Row is "other", use the freetext fields |
200 |
else { |
201 |
|
202 |
// Gather the catch-all fields |
203 |
$last_name = $row["pers_lastname"]; |
204 |
$first_name = $row["pers_firstname"]; |
205 |
$email = $row["pers_email"]; |
206 |
} |
207 |
|
208 |
|
209 |
// Display the data |
210 |
if ($stafftitle_id > 1) printf("%s: ", $stafftitle); |
211 |
printf("%s %s <a href=\"mailto:%s\">%s</a><br>\n", |
212 |
$first_name, $last_name, $email, $email); |
213 |
|
214 |
} // all course_personnel rows |
215 |
|
216 |
} // if there were any persons attached to this course |
217 |
|
218 |
} |
219 |
|
220 |
|
221 |
/********************************************************** |
222 |
Function: displayRelatedPages($subject_id) |
223 |
Author: Paul Bramscher |
224 |
Last Modified: 03.04.2004 |
225 |
*********************************************************** |
226 |
Incoming: |
227 |
$subject_id Subject of the RQS page |
228 |
*********************************************************** |
229 |
Outgoing: |
230 |
None |
231 |
*********************************************************** |
232 |
Purpose: |
233 |
Displays any PageScribe pages associated with the supplied |
234 |
subject id. |
235 |
**********************************************************/ |
236 |
function displayRelatedPages($subject_id){ |
237 |
$sql = "SELECT p.page_id, p.page_title |
238 |
FROM page p, sub_page sp |
239 |
WHERE sp.subject_id = " |
240 |
. $subject_id |
241 |
. " AND sp.page_id = p.page_id ORDER BY p.page_title"; |
242 |
|
243 |
$rs = xx_tryquery($sql); |
244 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
245 |
$page_id = $row["page_id"]; |
246 |
$page_title = $row["page_title"]; |
247 |
|
248 |
// Pull out any HTML |
249 |
$page_title = strip_tags($page_title); |
250 |
|
251 |
printf("<a href=\"page.phtml?page_id=%s\">%s</a><BR>\n", $page_id, $page_title); |
252 |
}; |
253 |
} |
254 |
|
255 |
|
256 |
/********************************************************** |
257 |
Function: displayRelatedSubjects($subject_id) |
258 |
Author: Paul Bramscher |
259 |
Last Modified: 03.04.2004 |
260 |
*********************************************************** |
261 |
Incoming: |
262 |
$subject_id Subject of the RQS page |
263 |
*********************************************************** |
264 |
Outgoing: |
265 |
None |
266 |
*********************************************************** |
267 |
Purpose: |
268 |
Displays any RQS pages associated with the supplied |
269 |
subject id. |
270 |
**********************************************************/ |
271 |
function displayRelatedSubjects($subject_id){ |
272 |
|
273 |
$sql = "SELECT s.subject, so.othersub_id |
274 |
FROM subject s, sub_othersub so |
275 |
WHERE so.subject_id = " |
276 |
. $subject_id |
277 |
. " AND so.othersub_id = s.subject_id ORDER BY s.subject"; |
278 |
|
279 |
$rs = xx_tryquery($sql); |
280 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
281 |
$othersub_id = $row["othersub_id"]; |
282 |
$subject = $row["subject"]; |
283 |
|
284 |
printf("<a href=\"rqs.phtml?subject_id=%s\">%s</a><BR>\n", $othersub_id, $subject); |
285 |
}; |
286 |
|
287 |
|
288 |
|
289 |
} |
290 |
|
291 |
|
292 |
/********************************************************** |
293 |
Function: displayTOC |
294 |
Author: Paul Bramscher |
295 |
Last Modified: 03.04.2004 |
296 |
*********************************************************** |
297 |
Purpose: |
298 |
Generates and displays a table of contents (TOC) for the |
299 |
supplied page id. This is done dynamically, and uses |
300 |
root-level elements on the given page. |
301 |
|
302 |
This function allows for the optional display of a |
303 |
two-column table of contents, split at the midpoint |
304 |
(rounded up for odd numbers of root elements). |
305 |
**********************************************************/ |
306 |
function displayTOC($page_id, $wrap_toc) { |
307 |
|
308 |
// Calculate number of elements |
309 |
$sql = "SELECT COUNT(*) as num_elements FROM element WHERE indent_level < 1 AND page_id = " |
310 |
. $page_id; |
311 |
$rs = xx_tryquery($sql); |
312 |
$row = xx_fetch_array ($rs); |
313 |
$num_elements = $row["num_elements"]; |
314 |
|
315 |
// Calculate midpoint element |
316 |
if ($num_elements > 0) $midpoint = ceil($num_elements / 2); |
317 |
else $midpoint = 0; |
318 |
|
319 |
if ($num_elements > 0) { |
320 |
|
321 |
// Retrieve all elements on that page |
322 |
$sql = "SELECT |
323 |
e.element_id, |
324 |
e.label, |
325 |
r.resource_id, |
326 |
r.title, |
327 |
l.location_id, |
328 |
l.location, |
329 |
v.service_id, |
330 |
v.service, |
331 |
s.staff_id, |
332 |
s.last_name, |
333 |
s.first_name, |
334 |
b.subject_id, |
335 |
b.subject |
336 |
|
337 |
FROM |
338 |
page p |
339 |
LEFT JOIN element e using (page_id) |
340 |
LEFT JOIN resource r on e.resource_id = r.resource_id |
341 |
LEFT JOIN location l on e.location_id = l.location_id |
342 |
LEFT JOIN service v on e.service_id = v.service_id |
343 |
LEFT JOIN staff s on e.staff_id = s.staff_id |
344 |
LEFT JOIN subject b on e.subject_id = b.subject_id |
345 |
|
346 |
WHERE |
347 |
p.page_id = " |
348 |
. $page_id |
349 |
. " AND e.indent_level < 1 ORDER BY e.element_order"; |
350 |
|
351 |
$rs = xx_tryquery($sql); |
352 |
|
353 |
// Build a general ToC anchor |
354 |
printf("<a name=\"toc\"></a>\n"); |
355 |
printf("<b>Table of Contents:</b><br>\n"); |
356 |
printf("<table>\n"); |
357 |
|
358 |
// Build the (single) row |
359 |
printf("<tr>\n"); |
360 |
|
361 |
// Populate the left cell |
362 |
printf("<td valign=\"top\"><ul>\n"); |
363 |
|
364 |
$row_num = 0; |
365 |
|
366 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
367 |
|
368 |
// Check for the midpoint |
369 |
if ($row_num == $midpoint && $wrap_toc == 1) { |
370 |
|
371 |
// Close the ul tag & table cell |
372 |
printf("</ul>\n"); |
373 |
printf("</td>\n"); |
374 |
|
375 |
// Start a new one |
376 |
printf("<td valign=\"top\">\n"); |
377 |
printf("<ul>\n"); |
378 |
|
379 |
} |
380 |
|
381 |
// General |
382 |
$element_id = $row["element_id"]; |
383 |
|
384 |
// Resource |
385 |
$resource_id = $row["resource_id"]; |
386 |
$title = $row["title"]; |
387 |
|
388 |
// Label/unique |
389 |
$label = $row["label"]; |
390 |
|
391 |
// Location |
392 |
$location_id = $row["location_id"]; |
393 |
$location = $row["location"]; |
394 |
|
395 |
// Service |
396 |
$service_id = $row["service_id"]; |
397 |
$service = $row["service"]; |
398 |
|
399 |
// Staff |
400 |
$staff_id = $row["staff_id"]; |
401 |
$last_name = $row["last_name"]; |
402 |
$first_name = $row["first_name"]; |
403 |
|
404 |
// Subject |
405 |
$subject_id = $row["subject_id"]; |
406 |
$subject = $row["subject"]; |
407 |
|
408 |
// Determine what sort of element it is |
409 |
$toc_label = ""; |
410 |
if ($resource_id > 0) $toc_label = $title; |
411 |
else if (strlen($label) > 0) $toc_label = $label; |
412 |
else if ($location_id > 0) $toc_label = $location; |
413 |
else if ($service_id > 0) $toc_label = $service; |
414 |
else if ($staff_id > 0) $toc_label = $first_name . " " . $last_name; |
415 |
else if ($subject_id > 0) $toc_label = $subject; |
416 |
|
417 |
// Last-minute error check |
418 |
if (strlen($toc_label) > 0) printf("<li><a href=\"#toc%d\">%s</a></li>\n", $element_id, $toc_label); |
419 |
|
420 |
$row_num++; |
421 |
|
422 |
} // end elements |
423 |
|
424 |
// Close things |
425 |
printf("</ul>\n"); |
426 |
printf("</td></tr></table><br>\n"); |
427 |
|
428 |
|
429 |
} // at least one item on this page |
430 |
} |
431 |
|
432 |
|
433 |
/********************************************************** |
434 |
Function: dropDownCoursesubSelected($limit, $preselected) |
435 |
Author: Paul Bramscher |
436 |
Last Modified: 03.04.2004 |
437 |
*********************************************************** |
438 |
Incoming: |
439 |
$limit Initial limit to the result set |
440 |
$preselected Incoming course subject to preselect |
441 |
*********************************************************** |
442 |
Outgoing: |
443 |
None |
444 |
*********************************************************** |
445 |
Purpose: |
446 |
Populates a drop-down box on an HTML form with select |
447 |
statements. Note that only course subjects (designators) |
448 |
which have associated and published CourseLib pages will |
449 |
appear in the drop down box. |
450 |
**********************************************************/ |
451 |
function dropDownCoursesubSelected($limit, $preselected){ |
452 |
|
453 |
|
454 |
$sql = "SELECT DISTINCT s.coursesub |
455 |
FROM coursesub s, course c, page p " |
456 |
. $limit |
457 |
. " |
458 |
AND s.coursesub_id = c.coursesub_id |
459 |
AND c.page_id = p.page_id |
460 |
AND p.published = '1' |
461 |
AND s.coursesub_id = c.coursesub_id " |
462 |
. " ORDER BY s.coursesub"; |
463 |
|
464 |
$rs = xx_tryquery($sql); |
465 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
466 |
$coursesub = $row["coursesub"]; |
467 |
|
468 |
printf("<option value = \"%s\"", $coursesub); |
469 |
if ($coursesub == $preselected) printf(" selected "); |
470 |
printf(">" . $coursesub . "</option>\n"); |
471 |
}; |
472 |
} |
473 |
|
474 |
|
475 |
/********************************************************** |
476 |
Function: dropDownFacultySelected($limit, $preselected) |
477 |
Author: Paul Bramscher |
478 |
Last Modified: 03.04.2004 |
479 |
*********************************************************** |
480 |
Incoming: |
481 |
$limit Any WHERE clause |
482 |
$preselected Incoming faculty person to preselect |
483 |
*********************************************************** |
484 |
Outgoing: |
485 |
None |
486 |
*********************************************************** |
487 |
Purpose: |
488 |
Populates a drop-down box on an HTML form with select |
489 |
statements. The faculty are displayed only if they |
490 |
(a) are currently teaching 1+ courselib courses and |
491 |
(b) that course(s) is published. |
492 |
**********************************************************/ |
493 |
function dropDownFacultySelected($limit, $preselected){ |
494 |
|
495 |
$sql = "SELECT DISTINCT |
496 |
f.faculty_id, |
497 |
f.faculty_lastname, |
498 |
f.faculty_firstname |
499 |
FROM faculty f, course c, course_personnel cp, page p " |
500 |
. $limit |
501 |
. " |
502 |
AND f.faculty_id = cp.faculty_id |
503 |
AND cp.course_id = c.course_id |
504 |
AND c.page_id = p.page_id |
505 |
AND p.published = '1'" |
506 |
. " ORDER BY f.faculty_lastname, f.faculty_firstname"; |
507 |
|
508 |
$rs = xx_tryquery($sql); |
509 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
510 |
$faculty_id = $row["faculty_id"]; |
511 |
$faculty_lastname = $row["faculty_lastname"]; |
512 |
$faculty_firstname = $row["faculty_firstname"]; |
513 |
$faculty_account = $row["faculty_account"]; |
514 |
|
515 |
// Make it look more friendly |
516 |
if ($faculty_id == 1) $faculty = "(N/A)"; |
517 |
else { |
518 |
$faculty = $faculty_lastname . ", " . $faculty_firstname; |
519 |
} |
520 |
|
521 |
printf("<option value = \"%d\"", $faculty_id); |
522 |
if ($faculty_id == $preselected) printf(" selected "); |
523 |
printf(">" . $faculty . "</option>\n"); |
524 |
}; |
525 |
} |
526 |
|
527 |
|
528 |
/********************************************************** |
529 |
Function: dropDownFieldOmit($table, $field_display, |
530 |
$field_value, $where) |
531 |
Author: Paul Bramscher |
532 |
Last Modified: 03.04.2004 |
533 |
*********************************************************** |
534 |
Incoming: |
535 |
$table Table in database to search |
536 |
$field_display Select displayed to user |
537 |
$field_value Actual value of the HTML tag |
538 |
$where SQL criteria in the list to exlude |
539 |
*********************************************************** |
540 |
Outgoing: |
541 |
None |
542 |
*********************************************************** |
543 |
Purpose: |
544 |
Populates a drop-down box on an HTML form with select |
545 |
options. They are ordered by the $field_display field. |
546 |
Typically, $field_value is the primary key field. $where |
547 |
can be used to filter out results. |
548 |
**********************************************************/ |
549 |
function dropDownFieldOmit($table, $field_display, |
550 |
$field_value, $where){ |
551 |
|
552 |
$sql = "SELECT " |
553 |
. $field_display |
554 |
. ", " |
555 |
. $field_value |
556 |
. " FROM " |
557 |
. $table |
558 |
. " " |
559 |
. $where |
560 |
. " ORDER BY " |
561 |
. $field_display; |
562 |
$rs = xx_tryquery($sql); |
563 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
564 |
$field_display_item = $row[$field_display]; |
565 |
if (strlen($field_display_item) > 40) $field_display_item = substr($field_display_item, 0, 39) . "..."; |
566 |
$field_value_item = $row[$field_value]; |
567 |
printf("<option value = \"" . $field_value_item |
568 |
. "\" >" |
569 |
. $field_display_item |
570 |
. "</option>\n"); |
571 |
}; |
572 |
} |
573 |
|
574 |
|
575 |
/********************************************************** |
576 |
Function: dropDownFieldSelected($table, $field_display, |
577 |
$field_value, $limit, $preselected) |
578 |
Author: Paul Bramscher |
579 |
Last Modified: 03.04.2004 |
580 |
*********************************************************** |
581 |
Incoming: |
582 |
$table Table in database to search |
583 |
$field_display Select displayed to user |
584 |
$field_value Actual value of the HTML tag |
585 |
$preselected A selected $field_value |
586 |
$limit A WHERE clause |
587 |
*********************************************************** |
588 |
Outgoing: |
589 |
None |
590 |
*********************************************************** |
591 |
Purpose: |
592 |
Populates a drop-down box on an HTML form with select |
593 |
options. They are ordered by the $field_display field. |
594 |
Typically, $field_value is the primary key field. The |
595 |
parameter $preselected determines which (single) selection |
596 |
is selected. |
597 |
**********************************************************/ |
598 |
function dropDownFieldSelected($table, $field_display, |
599 |
$field_value, $limit, $preselected){ |
600 |
|
601 |
$sql = "SELECT " |
602 |
. $field_display |
603 |
. ", " |
604 |
. $field_value |
605 |
. " FROM " |
606 |
. $table |
607 |
. " " |
608 |
. $limit |
609 |
. " ORDER BY " |
610 |
. $field_display; |
611 |
|
612 |
$rs = xx_tryquery($sql); |
613 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
614 |
$field_display_item = $row[$field_display]; |
615 |
$field_value_item = $row[$field_value]; |
616 |
if (strlen($field_display_item) > 50) $field_display_item = substr($field_display_item, 0, 49) . "..."; |
617 |
|
618 |
printf("<option value = \"" . $field_value_item . "\" "); |
619 |
if ($field_value_item == $preselected) printf (" selected"); |
620 |
printf(">" . $field_display_item . "</option>\n"); |
621 |
}; |
622 |
} |
623 |
|
624 |
|
625 |
/********************************************************** |
626 |
Function: existsRow |
627 |
Author: Paul Bramscher |
628 |
Last Modified: 03.04.2004 |
629 |
*********************************************************** |
630 |
Incoming: |
631 |
$table Table to search |
632 |
$key_field Field against which to search |
633 |
$key_id Limit for the where clause |
634 |
*********************************************************** |
635 |
Outgoing: |
636 |
"1" if the row exists, "0" if not |
637 |
*********************************************************** |
638 |
Purpose: |
639 |
Useful in performing delete and other operations to make |
640 |
sure that a row entity exists matching the supplied key |
641 |
before going any further. |
642 |
**********************************************************/ |
643 |
function existsRow($table, $key_field, $limit_id){ |
644 |
// Cast as integer to avoid future problems |
645 |
$limit_id = (int) $limit_id; |
646 |
|
647 |
// Build the sql |
648 |
$sql = "SELECT " |
649 |
. $key_field |
650 |
. " FROM " |
651 |
. $table |
652 |
. " WHERE " |
653 |
. $key_field |
654 |
. "=" |
655 |
. $limit_id; |
656 |
|
657 |
$rs = xx_tryquery($sql); |
658 |
$rowcount = xx_num_rows($rs); |
659 |
if ($rowcount >= 1){ |
660 |
$rowcount = 1; |
661 |
} |
662 |
else $rowcount = 0; |
663 |
|
664 |
return $rowcount; |
665 |
} |
666 |
|
667 |
|
668 |
/********************************************************** |
669 |
Function: lookupField($table, $key_field, $key_value, |
670 |
$desc_field) |
671 |
Author: Paul Bramscher |
672 |
Last Modified: 03.04.2004 |
673 |
*********************************************************** |
674 |
Incoming: |
675 |
$table Table in database to search |
676 |
$key_field Name of field on which to lookup |
677 |
$key_value Value to attempt lookup with |
678 |
$desc_field Descriptive value to return |
679 |
*********************************************************** |
680 |
Outgoing: |
681 |
A descriptive name for an ID number. |
682 |
*********************************************************** |
683 |
Purpose: |
684 |
Performs a lookup, typically on an ID field, to retrieve a |
685 |
user-friendly descriptive name to the page. |
686 |
**********************************************************/ |
687 |
function lookupField($table, $key_field, $key_value, |
688 |
$desc_field){ |
689 |
|
690 |
$sql = "SELECT " |
691 |
. $desc_field |
692 |
. " FROM " |
693 |
. $table |
694 |
. " WHERE " |
695 |
. $key_field |
696 |
. "='" |
697 |
. $key_value |
698 |
. "'"; |
699 |
$rs = xx_tryquery($sql); |
700 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
701 |
if (xx_num_rows($rs) == 1) $result = $row[$desc_field]; |
702 |
else $result = ""; |
703 |
|
704 |
return $result; |
705 |
} |
706 |
|
707 |
|
708 |
/********************************************************** |
709 |
Function: lookupStaff($staff_id) |
710 |
Author: Paul Bramscher |
711 |
Last Modified: 03.04.2004 |
712 |
*********************************************************** |
713 |
Incoming: |
714 |
$staff_id Staff ID number to retrieve |
715 |
*********************************************************** |
716 |
Outgoing: |
717 |
Staff name in {First Name} {Last Name} format. |
718 |
*********************************************************** |
719 |
Purpose: |
720 |
Performs a lookup on staff ID to retrieve name. |
721 |
**********************************************************/ |
722 |
function lookupStaff($staff_id){ |
723 |
|
724 |
$sql = "SELECT first_name, last_name FROM staff WHERE staff_id = " |
725 |
. $staff_id; |
726 |
$rs = xx_tryquery($sql); |
727 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
728 |
$last_name = $row["last_name"]; |
729 |
$first_name = $row["first_name"]; |
730 |
|
731 |
$staff_name .= $first_name . " " . $last_name; |
732 |
|
733 |
// Debugging |
734 |
//printf("sql was: %s<BR>", $sql); |
735 |
|
736 |
return $staff_name; |
737 |
} |
738 |
|
739 |
|
740 |
/********************************************************** |
741 |
Function: pageLoadStats |
742 |
Author: Paul Bramscher |
743 |
Last Modified: 03.04.2004 |
744 |
*********************************************************** |
745 |
Purpose: |
746 |
Logs a statistical entry for a PageScribe/CourseLib page |
747 |
load. Page id, date, and IP address are currently logged. |
748 |
It would be relatively trivial to add other fields, |
749 |
such as browser type, refer URL, etc. both to the database |
750 |
and this function here. However, care must be taken so |
751 |
that the database doesn't grow too large. Currently there |
752 |
exists no automatic mechanism to purge or archive stats. |
753 |
**********************************************************/ |
754 |
function pageLoadStats($page_id){ |
755 |
|
756 |
// Add a row for page usage |
757 |
|
758 |
// Fetch user ip |
759 |
$user_ip = $GLOBALS["REMOTE_ADDR"]; |
760 |
|
761 |
// Do the stat stuff here |
762 |
$sql = "INSERT INTO libstats.pagestats ( |
763 |
page_id, |
764 |
visit_date, |
765 |
user_ip) VALUES (" |
766 |
. $page_id |
767 |
. ", now(), '" |
768 |
. $user_ip |
769 |
. "')"; |
770 |
xx_tryquery($sql); |
771 |
|
772 |
} |
773 |
|
774 |
/********************************************************** |
775 |
Function: printAlphabet |
776 |
Author: Paul Bramscher |
777 |
Last Modified: 07.07.2003 |
778 |
*********************************************************** |
779 |
Purpose: |
780 |
Prints upper-case alphabet characters separated by the |
781 |
specified separator character, wrapped with the specified |
782 |
URL. |
783 |
**********************************************************/ |
784 |
function printAlphabet($separator_char, $url) { |
785 |
|
786 |
printf("<table class=\"strong\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n"); |
787 |
printf("<tr><td>\n"); |
788 |
|
789 |
for ($ascii_char = 65; $ascii_char <= 90; $ascii_char++) { |
790 |
printf("<a href= \"%s?letter=%s\">%s</a>", $url, |
791 |
chr($ascii_char), chr($ascii_char)); |
792 |
if ($ascii_char != 90) printf ("%s", $separator_char); |
793 |
} |
794 |
|
795 |
printf("</td></tr>\n"); |
796 |
printf("</table>\n"); |
797 |
|
798 |
|
799 |
} |
800 |
|
801 |
/********************************************************** |
802 |
Function: subLoadStats |
803 |
Author: Paul Bramscher |
804 |
Last Modified: 03.04.2004 |
805 |
*********************************************************** |
806 |
Purpose: |
807 |
Logs a statistical entry for a RQS page load. Subject id, |
808 |
date, and IP address are currently logged. Note that |
809 |
both default (screen) and printer-friendly loads for the |
810 |
same subject are logged with this function. |
811 |
No differentiation between them is made, only between |
812 |
subjects |
813 |
**********************************************************/ |
814 |
function subLoadStats($subject_id){ |
815 |
|
816 |
// Add a row for page usage |
817 |
|
818 |
// Fetch user ip |
819 |
$user_ip = $GLOBALS["REMOTE_ADDR"]; |
820 |
|
821 |
// Do the stat stuff here |
822 |
$sql = "INSERT INTO libstats.substats ( |
823 |
subject_id, |
824 |
visit_date, |
825 |
user_ip) VALUES (" |
826 |
. $subject_id |
827 |
. ", now(), '" |
828 |
. $user_ip |
829 |
. "')"; |
830 |
xx_tryquery($sql); |
831 |
|
832 |
} |
833 |
|
834 |
/********************************************************** |
835 |
Function: textOutHTML |
836 |
Author: Paul Bramscher |
837 |
Last Modified: 04.21.2003 |
838 |
*********************************************************** |
839 |
Purpose: |
840 |
This function will help render some data more presentable |
841 |
on HTML forms, particularly pre-setting form field values |
842 |
which might contain a double-quote. This function may also |
843 |
be extended to cover other cases. |
844 |
**********************************************************/ |
845 |
function textOutHTML($incoming) { |
846 |
|
847 |
// Replace double quotes with the HTML " |
848 |
$outgoing = ereg_replace("\"",""",$incoming); |
849 |
|
850 |
return $outgoing; |
851 |
|
852 |
} |
853 |
|
854 |
|
855 |
/********************************************************** |
856 |
Function: textSearchmySQL |
857 |
Author: Paul Bramscher |
858 |
Last Modified: 05.20.2003 |
859 |
*********************************************************** |
860 |
Purpose: |
861 |
This function is to be used on HTML search forms |
862 |
that might contain a single quote. They are escaped with |
863 |
a backslash. Any other potential SELECT filtering can |
864 |
happen here. |
865 |
**********************************************************/ |
866 |
function textSearchmySQL($incoming) { |
867 |
|
868 |
// Replace single quotes with two single quotes |
869 |
$outgoing = ereg_replace("'","\'",$incoming); |
870 |
|
871 |
return $outgoing; |
872 |
|
873 |
} |
874 |
?> |