/[libdata]/trunk/public_controls.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

Annotation of /trunk/public_controls.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 42 - (hide annotations)
Thu Mar 4 22:43:50 2004 UTC (17 years, 6 months ago) by dpavlin
File size: 27796 byte(s)
rename all mysql_ functions to xx_ so that wrapper can be used

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

  ViewVC Help
Powered by ViewVC 1.1.26