1 |
dpavlin |
1 |
<?php |
2 |
|
|
// Load globals |
3 |
|
|
require_once ("global_vars.php"); |
4 |
|
|
|
5 |
|
|
// Includes |
6 |
|
|
require_once ($GLOBAL_ADMIN_INC."sessionClass.php"); |
7 |
|
|
require_once ($GLOBAL_ADMIN_INC."accessClass.php"); |
8 |
|
|
require_once ($GLOBAL_ADMIN_INC."db_connect.php"); |
9 |
|
|
require_once ($GLOBAL_ADMIN_INC."app_controls.php"); |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
// HTML header |
13 |
|
|
printf("<HTML>\n"); |
14 |
|
|
printf("<HEAD>\n"); |
15 |
|
|
printf("<title>PageScribe-CourseLib Search Results</title>\n"); |
16 |
|
|
printf("<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\">\n", $GLOBAL_ADMIN_CSS); |
17 |
|
|
printf("</HEAD>\n"); |
18 |
|
|
|
19 |
|
|
|
20 |
|
|
// Page header |
21 |
|
|
require_once ($GLOBAL_ADMIN_HEADER); |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
// Collect access information |
25 |
|
|
if(isset($libsession)) { |
26 |
|
|
|
27 |
|
|
// Fetch session information |
28 |
|
|
$sessionClass = new sessionClass("", $libsession, "", ""); |
29 |
|
|
$accessClass = new accessClass($sessionClass); |
30 |
|
|
|
31 |
|
|
// Load user session variables |
32 |
|
|
$sess_time_human = $sessionClass->time_human; |
33 |
|
|
$sess_staff_account = $sessionClass->staff_account; |
34 |
|
|
$sess_access_level = $accessClass->access_level; |
35 |
|
|
$sess_access = $accessClass->access; |
36 |
|
|
$sess_last_name = $accessClass->last_name; |
37 |
|
|
$sess_first_name = $accessClass->first_name; |
38 |
|
|
|
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
// If the cookie is set and access level is appropriate |
42 |
|
|
if(isset($libsession) && $sess_access_level >= 20) { |
43 |
|
|
|
44 |
|
|
// Orderby field function |
45 |
|
|
function orderByField($noOrderSQL, $field_name, $validated){ |
46 |
|
|
$finalSQL = $noOrderSQL . " ORDER BY " . $field_name; |
47 |
|
|
printf("<form method = \"POST\" action = \"page_results_brief.phtml\" >\n"); |
48 |
|
|
printf("<input type = \"Submit\" value = \"Sort\" >", $field_name); |
49 |
|
|
printf("</form><br>\n"); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
// Display page heading |
53 |
|
|
printf("<center><h3>Search Results</h3>\n"); |
54 |
|
|
|
55 |
|
|
// Set up a flagging variable to track possible problems with the search parameters |
56 |
|
|
$problem = 0; |
57 |
|
|
|
58 |
|
|
// Algorithm is cleared to search |
59 |
|
|
if ($problem < 1) { |
60 |
|
|
|
61 |
|
|
/* Select a distinct row of reference information, but build the extra |
62 |
|
|
joins in case the user wants to limit by additional criteria. */ |
63 |
|
|
|
64 |
|
|
$sql = "SELECT DISTINCT |
65 |
|
|
p.page_id, |
66 |
|
|
p.page_title, |
67 |
|
|
p.account_created, |
68 |
|
|
p.account_modified, |
69 |
|
|
p.date_created, |
70 |
|
|
p.date_modified, |
71 |
|
|
p.staff_coordinator, |
72 |
|
|
c.course_concat, |
73 |
|
|
c.course_id, |
74 |
|
|
s.first_name, |
75 |
|
|
s.last_name, |
76 |
|
|
s.staff_account |
77 |
|
|
|
78 |
|
|
FROM |
79 |
|
|
page p |
80 |
|
|
LEFT JOIN course c using (page_id) |
81 |
|
|
LEFT JOIN staff s on p.staff_coordinator = s.staff_id "; |
82 |
|
|
|
83 |
|
|
// Dont' join with course_personnel unless we must. This, of course, is not very profound. |
84 |
|
|
if (strlen($pers_lastname) > 1 || $faculty_id > 0 || $pers_staff_id > 0) $sql .= "LEFT JOIN course_personnel cp on c.course_id = cp.course_id "; |
85 |
|
|
|
86 |
|
|
$sql .= "LEFT JOIN page_staff ps on p.page_id = ps.page_id |
87 |
|
|
|
88 |
|
|
WHERE ( |
89 |
|
|
( p.page_id > 0 ) "; |
90 |
|
|
|
91 |
|
|
|
92 |
|
|
// If user limited by course introductory text |
93 |
|
|
if (strlen($intro_text) > 1){ |
94 |
|
|
|
95 |
|
|
$intro_text = textSearchmySQL($intro_text); |
96 |
|
|
$sql .= " AND (c.introheader1 LIKE '%" |
97 |
|
|
. $intro_text |
98 |
|
|
. "%' OR c.introheader2 LIKE '%" |
99 |
|
|
. $intro_text |
100 |
|
|
. "%' OR c.intromessage1 LIKE '%" |
101 |
|
|
. $intro_text |
102 |
|
|
. "%' OR c.intromessage2 LIKE '%" |
103 |
|
|
. $intro_text |
104 |
|
|
. "%')"; |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
// If user limited by page title |
108 |
|
|
if ($page_title !=""){ |
109 |
|
|
|
110 |
|
|
$page_title = textSearchmySQL($page_title); |
111 |
|
|
$sql .= " AND (p.page_title LIKE '%" |
112 |
|
|
. $page_title |
113 |
|
|
. "%')"; |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
// If user limited by date created |
117 |
|
|
if ($date_created !=""){ |
118 |
|
|
|
119 |
|
|
$date_created = textSearchmySQL($date_created); |
120 |
|
|
$sql .= " AND (p.date_created LIKE '%" |
121 |
|
|
. $date_created |
122 |
|
|
. "%')"; |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
// If user limited by date modified |
126 |
|
|
if ($date_modified !=""){ |
127 |
|
|
|
128 |
|
|
$date_modified = textSearchmySQL($date_modified); |
129 |
|
|
$sql .= " AND (p.date_modified LIKE '%" |
130 |
|
|
. $date_modified |
131 |
|
|
. "%')"; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
// If user limited by staff coordinator |
135 |
|
|
if ($staff_coordinator > 1){ |
136 |
|
|
$sql .= " AND (p.staff_coordinator =" |
137 |
|
|
. $staff_coordinator |
138 |
|
|
. ")"; |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
// If user limited by staff co-maintainer |
142 |
|
|
if ($comaintainer_id > 1){ |
143 |
|
|
$sql .= " AND (ps.staff_id =" |
144 |
|
|
. $comaintainer_id |
145 |
|
|
. ")"; |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
// If user limited by page type |
149 |
|
|
if ($pagetype_id > 1){ |
150 |
|
|
$sql .= " AND (p.pagetype_id =" |
151 |
|
|
. $pagetype_id |
152 |
|
|
. ")"; |
153 |
|
|
} |
154 |
|
|
|
155 |
|
|
// If user limited by faculty_id or TA/Other instructor. These are all LEFT JOIN special cases. |
156 |
|
|
if ($faculty_id > 0 || $pers_staff_id > 0 || strlen($pers_lastname) > 1){ |
157 |
|
|
|
158 |
|
|
/* |
159 |
|
|
We need this section regrettably. The problem is in joining to |
160 |
|
|
course_personnel. We can't simply AND conditions to it since |
161 |
|
|
a particular row can't be both a staff, faculty, and TA/Other. |
162 |
|
|
It is only one of the above. Adding AND's affect the same row, and will |
163 |
|
|
automatically revert to false. If you can visualize this problem, you're |
164 |
|
|
good -- very good. Otherwise, look ye upon this code and despair! |
165 |
|
|
*/ |
166 |
|
|
|
167 |
|
|
// Flag it to TRUE when the first clause is found. |
168 |
|
|
$cp_flag = 0; |
169 |
|
|
|
170 |
|
|
// Check for faculty_id first |
171 |
|
|
if ($faculty_id > 0) { |
172 |
|
|
$sql .= " AND (cp.faculty_id = " . $faculty_id; |
173 |
|
|
$cp_flag = 1; |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
// Check for staff_id (as course personnel) next. Determine whether to AND or OR |
177 |
|
|
if ($pers_staff_id > 0) { |
178 |
|
|
if ($cp_flag == 0) { |
179 |
|
|
$sql .= " AND (cp.staff_id = " . $pers_staff_id; |
180 |
|
|
$cp_flag = 1; |
181 |
|
|
} |
182 |
|
|
else $sql .= " OR cp.staff_id = " . $pers_staff_id; |
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
// Check for instructor personnel last name |
186 |
|
|
if (strlen($pers_lastname) > 0) { |
187 |
|
|
if ($cp_flag == 0) { |
188 |
|
|
|
189 |
|
|
$pers_lastname = textSearchmySQL($pers_lastname); |
190 |
|
|
$sql .= " AND (cp.pers_lastname LIKE '%" . $pers_lastname . "%'"; |
191 |
|
|
$cp_flag = 1; |
192 |
|
|
} |
193 |
|
|
else $sql .= " OR cp.pers_lastname LIKE '%" . $pers_lastname . "%'"; |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
// At some point above we've added a paren, so close it. |
197 |
|
|
$sql .= ")"; |
198 |
|
|
|
199 |
|
|
} // limited by course personnel |
200 |
|
|
|
201 |
|
|
// If user limited by account (x500 if applicable) created |
202 |
|
|
if (strlen($account_created) > 1){ |
203 |
|
|
|
204 |
|
|
$account_created = textSearchmySQL($account_created); |
205 |
|
|
$sql .= " AND (p.account_created ='" |
206 |
|
|
. $account_created |
207 |
|
|
. "')"; |
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
// If user limited by account (x500 if applicable) modified |
211 |
|
|
if (strlen($account_modified) > 1){ |
212 |
|
|
|
213 |
|
|
$account_modified = textSearchmySQL($account_modified); |
214 |
|
|
$sql .= " AND (p.account_modified ='" |
215 |
|
|
. $account_modified |
216 |
|
|
. "')"; |
217 |
|
|
} |
218 |
|
|
|
219 |
|
|
// If user limited by course subject id |
220 |
|
|
if ($coursesub_id > 0){ |
221 |
|
|
$sql .= " AND (c.coursesub_id =" |
222 |
|
|
. $coursesub_id |
223 |
|
|
. ")"; |
224 |
|
|
} |
225 |
|
|
|
226 |
|
|
// If user limited by campus_id |
227 |
|
|
if ($campus_id > 0){ |
228 |
|
|
$sql .= " AND (c.campus_id =" |
229 |
|
|
. $campus_id |
230 |
|
|
. ")"; |
231 |
|
|
} |
232 |
|
|
|
233 |
|
|
// If user limited by term_id |
234 |
|
|
if ($term_id > 0){ |
235 |
|
|
$sql .= " AND (c.term_id =" |
236 |
|
|
. $term_id |
237 |
|
|
. ")"; |
238 |
|
|
} |
239 |
|
|
|
240 |
|
|
// If user limited by course year |
241 |
|
|
if (strlen($course_year) > 1){ |
242 |
|
|
|
243 |
|
|
$course_year = textSearchmySQL($course_year); |
244 |
|
|
$sql .= " AND (c.course_year ='" |
245 |
|
|
. $course_year |
246 |
|
|
. "')"; |
247 |
|
|
} |
248 |
|
|
|
249 |
|
|
// cap it off |
250 |
|
|
$sql .= ")"; |
251 |
|
|
|
252 |
|
|
// Order by |
253 |
|
|
if ($orderby !="" && $orderdir != ""){ |
254 |
|
|
$sql .= " ORDER BY " . $orderby . " " . $orderdir; |
255 |
|
|
} |
256 |
|
|
|
257 |
|
|
// Debugging |
258 |
|
|
// printf("sql was: %s<BR>", $sql); |
259 |
|
|
|
260 |
dpavlin |
42 |
if ( !$rs = xx_query ( $sql, $con ) ) { |
261 |
dpavlin |
1 |
sql_err ( $sql ) And bailout(); |
262 |
|
|
} |
263 |
|
|
|
264 |
|
|
// Table |
265 |
|
|
printf("<center><table width=\"90%%\" border =\"1\" bgcolor =\"#ffffff\" cellpadding=\"4\">"); |
266 |
|
|
|
267 |
|
|
// Page ID |
268 |
|
|
printf("<tr><td width = \"5%%\" class=\"cellPlain\">\n"); |
269 |
|
|
printf("Page ID#"); |
270 |
|
|
printf("</td>\n"); |
271 |
|
|
|
272 |
|
|
// Edit |
273 |
|
|
printf("<td width=\"10%%\" align=\"center\" class=\"cellPlain\">Command</td>\n"); |
274 |
|
|
|
275 |
|
|
// Page coordinator |
276 |
|
|
printf("<td width=\"20%%\" class=\"cellPlain\">Coordinator</td>\n"); |
277 |
|
|
|
278 |
|
|
// Page/Course Title |
279 |
|
|
printf("<td width = \"45%%\" class=\"cellPlain\">\n"); |
280 |
|
|
printf("Page/Course Title"); |
281 |
|
|
printf("</td>\n"); |
282 |
|
|
|
283 |
|
|
// Date created |
284 |
|
|
printf("<td width = \"10%%\" class=\"cellPlain\">\n"); |
285 |
|
|
printf("Created"); |
286 |
|
|
printf("</td>\n"); |
287 |
|
|
|
288 |
|
|
// Date modified |
289 |
|
|
printf("<td width = \"10%%\" class=\"cellPlain\">\n"); |
290 |
|
|
printf("Modified"); |
291 |
|
|
printf("</td>\n"); |
292 |
|
|
|
293 |
|
|
// Close row |
294 |
|
|
printf("</tr>\n"); |
295 |
|
|
|
296 |
|
|
// Initialize counter |
297 |
|
|
$rowcount = 0; |
298 |
|
|
|
299 |
|
|
// Cycle through the result set |
300 |
dpavlin |
42 |
while ( $row = xx_fetch_array ( $rs ) ) { |
301 |
dpavlin |
1 |
$page_id = $row["page_id"]; |
302 |
|
|
$page_title = Trim($row["page_title"]); |
303 |
|
|
$date_created = substr($row["date_created"], 0, 10); |
304 |
|
|
$date_modified = substr($row["date_modified"], 0, 10); |
305 |
|
|
$course_concat = Trim($row["course_concat"]); |
306 |
|
|
|
307 |
|
|
$first_name = Trim($row["first_name"]); |
308 |
|
|
$last_name = Trim($row["last_name"]); |
309 |
|
|
$staff_account = Trim($row["staff_account"]); |
310 |
|
|
|
311 |
|
|
$staff_display = $first_name . " " . $last_name . " (" . $staff_account . ")"; |
312 |
|
|
|
313 |
|
|
|
314 |
|
|
// New row |
315 |
|
|
if ($rowcount % 2 == 0) $color = " class=\"backLight\" "; |
316 |
|
|
else $color =""; |
317 |
|
|
|
318 |
|
|
// Use full course name if this is a coursescribe page |
319 |
|
|
if (strlen($course_concat) > 0) $page_title = $course_concat; |
320 |
|
|
|
321 |
|
|
// Pull out any HTML |
322 |
|
|
$page_title = strip_tags($page_title); |
323 |
|
|
|
324 |
|
|
// Page id |
325 |
|
|
printf("<tr>"); |
326 |
|
|
printf("<td width=\"5%%\" %s>\n", $color); |
327 |
|
|
printf("<a href=\"%spage.phtml?page_id=%d\">%d</a>\n",$GLOBAL_SCRIBE_URL, $page_id, $page_id); |
328 |
|
|
printf("</td>\n"); |
329 |
|
|
|
330 |
|
|
// Edit/View command |
331 |
|
|
printf("<td width=\"10%%\"align=\"center\" %s>\n", $color); |
332 |
|
|
printf("<a href=\"%spage.phtml?page_id=%d\">View</a> | ",$GLOBAL_SCRIBE_URL, $page_id); |
333 |
|
|
printf("<a href=\"scribe.phtml?page_id=" |
334 |
|
|
. $page_id |
335 |
|
|
. "\">Edit</a>\n"); |
336 |
|
|
printf("</td>\n"); |
337 |
|
|
|
338 |
|
|
// Staff Coordinator |
339 |
|
|
printf("<td width=\"20%%\" %s>%s</td>\n", $color, $staff_display); |
340 |
|
|
|
341 |
|
|
// Title |
342 |
|
|
printf("<td width=\"45%%\" %s>%s</td>\n", $color, $page_title); |
343 |
|
|
|
344 |
|
|
// Date created |
345 |
|
|
printf("<td width=\"10%%\" %s>%s</td>\n", $color, $date_created); |
346 |
|
|
|
347 |
|
|
// Date last modified |
348 |
|
|
printf("<td width=\"10%%\" %s>%s</td>\n", $color, $date_modified); |
349 |
|
|
|
350 |
|
|
// Close row |
351 |
|
|
printf("</tr>\n"); |
352 |
|
|
|
353 |
|
|
// Increment counter |
354 |
|
|
$rowcount++; |
355 |
|
|
|
356 |
|
|
} |
357 |
|
|
|
358 |
|
|
// Search statistics |
359 |
|
|
printf("<tr><td align = \"right\" colspan =\"6\" class=\"backLight\">"); |
360 |
|
|
$records = "record"; |
361 |
dpavlin |
42 |
printf("<BR>Returned %d ", xx_num_rows($rs)); |
362 |
|
|
if (xx_num_rows($rs) != 1) $records .= "s"; |
363 |
dpavlin |
1 |
printf($records); |
364 |
|
|
printf("."); |
365 |
|
|
|
366 |
|
|
// Close off the table |
367 |
|
|
printf ("</td></tr></table></center><BR>"); |
368 |
|
|
|
369 |
|
|
} |
370 |
|
|
|
371 |
|
|
printf("<center>"); |
372 |
|
|
|
373 |
|
|
// Error trapping |
374 |
|
|
// No search criteria supplied |
375 |
|
|
if ($problem == 2) printf ("No search criteria supplied. Please go back and select some criteria.<br><br"); |
376 |
|
|
|
377 |
|
|
printf("</center>"); |
378 |
|
|
|
379 |
|
|
// Link to return to admin console |
380 |
|
|
adminReturn($sess_access_level); |
381 |
|
|
|
382 |
|
|
} // logged in |
383 |
|
|
|
384 |
|
|
// No access page |
385 |
|
|
else require_once ($GLOBAL_NO_ACCESS); |
386 |
|
|
|
387 |
|
|
|
388 |
|
|
// Page footer |
389 |
|
|
require_once ($GLOBAL_ADMIN_FOOTER); |
390 |
|
|
?> |
391 |
|
|
|
392 |
|
|
</body> |
393 |
|
|
</html> |