1 |
<?php |
2 |
/********************************************************** |
3 |
Function Library: scribe_application.php |
4 |
Original Author: Paul Bramscher <brams006@umn.edu> |
5 |
Last Modified: 03.16.2004 |
6 |
*********************************************************** |
7 |
Comments: |
8 |
This library brings together all of the SQL actions in |
9 |
the CLPS system. Note that it occasionally relies |
10 |
on app_controls.php and other libraries as well, but these |
11 |
are specific to CLPS. |
12 |
*********************************************************** |
13 |
Table of Contents: |
14 |
assignPageStaff |
15 |
assignStaffCoordinator |
16 |
copyPasteElement |
17 |
deleteCopyBuffer |
18 |
deleteCoursePers |
19 |
deleteElement |
20 |
deletePage |
21 |
deletePageConfirm |
22 |
deletePageStaff |
23 |
displayTOC |
24 |
elementDown |
25 |
elementMultiFormat |
26 |
elementSize |
27 |
elementUp |
28 |
getMaxIndent |
29 |
insertCoursePers |
30 |
insertScribeLabel |
31 |
insertScribeLocation |
32 |
insertScribeResource |
33 |
insertScribeRQS |
34 |
insertScribeRQSLink |
35 |
insertScribeService |
36 |
insertScribeStaff |
37 |
pageLoadStats |
38 |
pageTemplate |
39 |
pageTemplateConfirm |
40 |
parentIs |
41 |
parentProbe |
42 |
pasteElement |
43 |
populateGenArray |
44 |
scribePublish |
45 |
scribeUnpublish |
46 |
sibProbeElder |
47 |
sibProbeYounger |
48 |
toggleTOCDisplay |
49 |
toggleTOCWrap |
50 |
toggleURLDisplay |
51 |
toggleUpDisplay |
52 |
toggleUpText |
53 |
updatePageDebug |
54 |
updatePageHeader |
55 |
updatePageTitleStyle |
56 |
updateScribeCourse |
57 |
updateScribeCourseConcat |
58 |
updateScribeElement |
59 |
updateScribeHeader |
60 |
updateScribeStyle |
61 |
updateScribeUpdate |
62 |
youngerProbe |
63 |
**********************************************************/ |
64 |
|
65 |
|
66 |
|
67 |
/********************************************************** |
68 |
Function: assignPageStaff |
69 |
Author: Paul Bramscher |
70 |
Last Modified: 03.03.2004 |
71 |
*********************************************************** |
72 |
Purpose: |
73 |
Assigns staffpersons (possibly multiple) to a given page |
74 |
and calls the page edit mode back again. |
75 |
**********************************************************/ |
76 |
function assignPageStaff($page_id, $staff_id_array) { |
77 |
|
78 |
// For all staff in the array |
79 |
for ($subscript = 0; $subscript < sizeof($staff_id_array); $subscript++ ) { |
80 |
|
81 |
// Check to make sure that the staff isn't already assigned |
82 |
$sql = "SELECT * FROM page_staff where page_id = " . $page_id . |
83 |
" AND staff_id = " . $staff_id_array[$subscript]; |
84 |
$rs = xx_tryquery($sql); |
85 |
if (xx_num_rows($rs) == 0) { |
86 |
|
87 |
$sql = "INSERT INTO page_staff (page_id, staff_id) VALUES (" |
88 |
. $page_id |
89 |
. ", " |
90 |
. $staff_id_array[$subscript] |
91 |
. ")"; |
92 |
xx_tryquery($sql); |
93 |
|
94 |
} // staff not already assigned |
95 |
|
96 |
} // array of staff id's |
97 |
|
98 |
// Call the PageScribe back |
99 |
header("Location: scribe.phtml?page_id=" . $page_id . "&cmd=pagestaff"); |
100 |
|
101 |
} // function |
102 |
|
103 |
|
104 |
/********************************************************** |
105 |
Function: assignStaffCoordinator |
106 |
Author: Paul Bramscher |
107 |
Last Modified: 03.03.2004 |
108 |
*********************************************************** |
109 |
Purpose: |
110 |
Assigns a single staff coordinator to a given page and |
111 |
calls the page edit mode back again. |
112 |
**********************************************************/ |
113 |
function assignStaffCoordinator($page_id, $staff_coordinator) { |
114 |
|
115 |
$sql = "UPDATE page SET staff_coordinator = " |
116 |
. $staff_coordinator |
117 |
. " WHERE page_id = " |
118 |
. $page_id; |
119 |
|
120 |
xx_tryquery ($sql); |
121 |
header("Location: scribe.phtml?page_id=" . $page_id); |
122 |
} |
123 |
|
124 |
|
125 |
/********************************************************** |
126 |
Function: copyPasteElement |
127 |
Author: Paul Bramscher |
128 |
Last Modified: 03.03.2004 |
129 |
*********************************************************** |
130 |
Purpose: |
131 |
Copies the supplied element id and descendants (if picked) |
132 |
and inserts them into the user's copy/paste buffer. Any |
133 |
previously copied data is replaced. |
134 |
**********************************************************/ |
135 |
function copyPasteElement($page_id, $place_array_HTML, $copysingle, $sess_staff_id){ |
136 |
|
137 |
// Split by comma separated values |
138 |
$place_array = split(",", $place_array_HTML); |
139 |
|
140 |
// Break apart place array |
141 |
$element_id = $place_array[0]; |
142 |
$element_order = $place_array[1]; |
143 |
$indent_level = $place_array[2]; |
144 |
$parent_id = $place_array[3]; |
145 |
$position = $place_array[4]; |
146 |
|
147 |
// First, we delete any previously cut elements from the pastebuffer table |
148 |
$sql = "DELETE FROM pastebuffer WHERE paste_staff_id = " |
149 |
. $sess_staff_id; |
150 |
xx_tryquery($sql); |
151 |
|
152 |
// Element is a parent, and user is copying that element only. |
153 |
if ($copysingle == 1) { |
154 |
$end_element_order = $element_order; |
155 |
|
156 |
} |
157 |
|
158 |
// Copy parent and all descendants. Determine the block of affected rows |
159 |
else { |
160 |
|
161 |
// End order flags |
162 |
$end_found = 0; |
163 |
$end_element_order = $element_order; |
164 |
$last_element_order = $element_order; |
165 |
|
166 |
$sql = "SELECT element_id, indent_level, element_order FROM element where page_id = " |
167 |
. $page_id |
168 |
. " AND element_order > " |
169 |
. $element_order |
170 |
. " ORDER BY element_order"; |
171 |
$rs = xx_tryquery($sql); |
172 |
|
173 |
// Check for indent level |
174 |
while (($row = xx_fetch_array ($rs, xx_ASSOC)) && ($end_found == 0)) { |
175 |
|
176 |
$probe_element_id = $row["element_id"]; |
177 |
$probe_indent_level = $row["indent_level"]; |
178 |
$probe_element_order = $row["element_order"]; |
179 |
|
180 |
if ($probe_indent_level <= $indent_level) { |
181 |
$end_element_order = $last_element_order; |
182 |
$end_found = 1; |
183 |
} |
184 |
else $end_element_order = $probe_element_order; |
185 |
$last_element_order = $probe_element_order; |
186 |
//printf("probed element: %d<BR>", $probe_element_id); |
187 |
//printf("probed indent: %d<BR>", $probe_indent_level); |
188 |
|
189 |
} // end of affected elements to copy |
190 |
|
191 |
} // determine last descendant to copy |
192 |
|
193 |
/* |
194 |
Select the block of affected elements and insert them into the pastebuffer table |
195 |
*/ |
196 |
$sql = "INSERT INTO pastebuffer ( |
197 |
paste_staff_id, |
198 |
parent_id, |
199 |
resource_id, |
200 |
location_id, |
201 |
service_id, |
202 |
staff_id, |
203 |
subject_id, |
204 |
indent_level, |
205 |
label, |
206 |
label_url, |
207 |
element_descr, |
208 |
element_size, |
209 |
element_order) |
210 |
SELECT |
211 |
staff.staff_id AS paste_staff_id, |
212 |
parent_id, |
213 |
resource_id, |
214 |
location_id, |
215 |
service_id, |
216 |
element.staff_id, |
217 |
subject_id, |
218 |
indent_level, |
219 |
label, |
220 |
label_url, |
221 |
element_descr, |
222 |
element_size, |
223 |
element_order |
224 |
FROM element, staff |
225 |
WHERE staff.staff_id = " |
226 |
. $sess_staff_id |
227 |
. " AND page_id = " |
228 |
. $page_id |
229 |
. " AND element_order >=" |
230 |
. $element_order |
231 |
. " AND element_order <=" |
232 |
. $end_element_order |
233 |
. " ORDER BY element_order"; |
234 |
|
235 |
xx_tryquery($sql); |
236 |
header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
237 |
|
238 |
} // end function |
239 |
|
240 |
|
241 |
/********************************************************** |
242 |
Function: deleteCopyBuffer |
243 |
Author: Paul Bramscher |
244 |
Last Modified: 03.03.2004 |
245 |
*********************************************************** |
246 |
Purpose: |
247 |
Clears the user's copy/paste buffer. |
248 |
**********************************************************/ |
249 |
function deleteCopyBuffer($page_id, $paste_staff_id){ |
250 |
|
251 |
$sql = "DELETE from pastebuffer WHERE paste_staff_id = " |
252 |
. $paste_staff_id; |
253 |
xx_tryquery($sql); |
254 |
header("Location: scribe.phtml?page_id=". $page_id); |
255 |
} |
256 |
|
257 |
|
258 |
/********************************************************** |
259 |
Function: deleteCoursePers |
260 |
Author: Paul Bramscher |
261 |
Last Modified: 03.03.2004 |
262 |
*********************************************************** |
263 |
Purpose: |
264 |
Deletes the supplied personnel id from the course. |
265 |
**********************************************************/ |
266 |
function deleteCoursePers($course_id, $page_id, $personnel_id){ |
267 |
|
268 |
// Build the sql. |
269 |
$sql = "DELETE from course_personnel WHERE personnel_id = " |
270 |
. $personnel_id |
271 |
. " AND course_id = " |
272 |
. $course_id; |
273 |
xx_tryquery($sql); |
274 |
header("Location: scribe.phtml?page_id=". $page_id); |
275 |
} |
276 |
|
277 |
|
278 |
/********************************************************** |
279 |
Function: deleteElement |
280 |
Author: Paul Bramscher |
281 |
Last Modified: 03.03.2004 |
282 |
*********************************************************** |
283 |
Purpose: |
284 |
Deletes the supplied element id. Depending on user selection, |
285 |
all descendants are also deleted, or else promoted to the |
286 |
generation of the deleted parent. |
287 |
|
288 |
This function also deletes references to the affected element, |
289 |
and any removed descendants, from the libstats statistics |
290 |
table. |
291 |
**********************************************************/ |
292 |
function deleteElement($page_id, $place_array_HTML, $promote){ |
293 |
|
294 |
// Split by comma separated values |
295 |
$place_array = split(",", $place_array_HTML); |
296 |
|
297 |
// Break apart place array |
298 |
$element_id = $place_array[0]; |
299 |
$element_order = $place_array[1]; |
300 |
$indent_level = $place_array[2]; |
301 |
$parent_id = $place_array[3]; |
302 |
$position = $place_array[4]; |
303 |
|
304 |
|
305 |
/* Incoming promote parameters |
306 |
0: no children |
307 |
1: children present, promote them |
308 |
2: children present, delete them |
309 |
*/ |
310 |
|
311 |
|
312 |
/******************************************************** |
313 |
** Item is singular, no children. Simple delete case. ** |
314 |
********************************************************/ |
315 |
|
316 |
if ($promote == 0) { |
317 |
|
318 |
// First delete the element |
319 |
$sql = "DELETE from element WHERE page_id = " |
320 |
. $page_id |
321 |
. " AND element_id = " |
322 |
. $element_id; |
323 |
xx_tryquery($sql); |
324 |
|
325 |
// Next, update the order of the remainders |
326 |
$sql = "UPDATE element SET element_order = element_order - 1 WHERE page_id = " |
327 |
. $page_id |
328 |
. " AND element_order > " |
329 |
. $element_order; |
330 |
xx_tryquery($sql); |
331 |
|
332 |
// Last, delete the element reference from the stats database |
333 |
$sql = "DELETE from libstats.elementstats WHERE page_id = " |
334 |
. $page_id |
335 |
. " AND element_id = " |
336 |
. $element_id; |
337 |
xx_tryquery($sql); |
338 |
|
339 |
// Done, return to page |
340 |
if ($position > 2) $new_pos = $position - 1; |
341 |
else $new_pos = 1; |
342 |
header("Location: scribe.phtml?page_id=". $page_id . "#p" . $new_pos); |
343 |
|
344 |
} // end simple delete |
345 |
|
346 |
|
347 |
/************************************* |
348 |
** Delete element, promote children ** |
349 |
*************************************/ |
350 |
|
351 |
else if ($promote == 1) { |
352 |
|
353 |
// Success flag |
354 |
$success = 1; |
355 |
|
356 |
// Intialize first descendant indent level to proper value |
357 |
$desc_indent_level = $indent_level + 1; |
358 |
|
359 |
/* |
360 |
First, we need to march through the records, starting at the |
361 |
first child. We need to decrease all indent levels by one. When |
362 |
we arrive at an indent level equal to the parent's, it is a sibling |
363 |
(of the parent) and we stop. |
364 |
*/ |
365 |
|
366 |
$sql = "SELECT element_id, parent_id, indent_level, element_order FROM element WHERE page_id = " |
367 |
. $page_id |
368 |
. " AND element_order > " |
369 |
. $element_order |
370 |
. " ORDER BY element_order"; |
371 |
$rs = xx_tryquery($sql); |
372 |
|
373 |
// Check for and promote all descendants |
374 |
while (($row = xx_fetch_array ($rs, xx_ASSOC)) && ($desc_indent_level > $indent_level)) { |
375 |
$desc_element_id = $row["element_id"]; |
376 |
$desc_parent_id = $row["parent_id"]; |
377 |
$desc_indent_level = $row["indent_level"]; |
378 |
|
379 |
// We've found a descendant, alter the indent level |
380 |
if ($desc_indent_level > $indent_level) { |
381 |
$promote_sql = "UPDATE element SET indent_level = indent_level - 1 WHERE page_id = " |
382 |
. $page_id |
383 |
. " AND element_id = " |
384 |
. $desc_element_id; |
385 |
xx_tryquery($promote_sql); |
386 |
|
387 |
} // end of check for one descendant |
388 |
|
389 |
|
390 |
/* |
391 |
Reset the parent ID on the immediate first-generation children. |
392 |
Note that at this point they have the same indent level as their |
393 |
parent in the database, but differ here in PHP. |
394 |
*/ |
395 |
|
396 |
if ($desc_indent_level == $indent_level + 1) { |
397 |
|
398 |
$newparent_sql = "UPDATE element SET parent_id = " |
399 |
. $parent_id |
400 |
. " WHERE page_id = " |
401 |
. $page_id |
402 |
. " AND element_id = " |
403 |
. $desc_element_id; |
404 |
xx_tryquery($newparent_sql); |
405 |
|
406 |
} // end check for first generation children |
407 |
|
408 |
} // end check for all descendants |
409 |
|
410 |
// Next, delete the parent |
411 |
$parent_sql = "DELETE FROM element WHERE element_id = " |
412 |
. $element_id; |
413 |
xx_tryquery($parent_sql); |
414 |
|
415 |
// Increment the deleted counter to include the parent |
416 |
$num_desc++; |
417 |
|
418 |
// Next, update the order of the remainders |
419 |
$order_sql = "UPDATE element SET element_order = element_order - 1 WHERE page_id = " |
420 |
. $page_id |
421 |
. " AND element_order > " |
422 |
. $element_order; |
423 |
xx_tryquery($order_sql); |
424 |
|
425 |
// Last, delete the (parent) element reference from the stats database |
426 |
$sql = "DELETE from libstats.elementstats WHERE page_id = " |
427 |
. $page_id |
428 |
. " AND element_id = " |
429 |
. $element_id; |
430 |
xx_tryquery($sql); |
431 |
|
432 |
// Done, return to page |
433 |
if ($position > 2) $new_pos = $position - 1; |
434 |
else $new_pos = 1; |
435 |
header("Location: scribe.phtml?page_id=". $page_id . "#p" . $new_pos); |
436 |
|
437 |
} // end delete and promote |
438 |
|
439 |
|
440 |
/******************************** |
441 |
** Delete element and children ** |
442 |
********************************/ |
443 |
|
444 |
|
445 |
else if ($promote == 2) { |
446 |
|
447 |
// Intialize first descendant indent level to proper value |
448 |
$desc_indent_level = $indent_level + 1; |
449 |
$num_desc = 0; |
450 |
|
451 |
/* First, we need to march through the records, starting at the |
452 |
first child, and purge any with an indent level equal to or |
453 |
greater than the first child. When we reach an indent level |
454 |
equal to the parent, we are now dealing with a sibling (of |
455 |
the parent) and stop. It may possible to do this recursively, |
456 |
but it might involve more SQL's and probably represent less |
457 |
clear logic. |
458 |
*/ |
459 |
|
460 |
$sql = "SELECT element_id, parent_id, indent_level, element_order FROM element WHERE page_id = " |
461 |
. $page_id |
462 |
. " AND element_order > " |
463 |
. $element_order |
464 |
. " ORDER BY element_order"; |
465 |
$rs = xx_tryquery($sql); |
466 |
|
467 |
// Check for and delete all descendants |
468 |
while (($row = xx_fetch_array ($rs, xx_ASSOC)) && ($desc_indent_level > $indent_level)) { |
469 |
$desc_element_id = $row["element_id"]; |
470 |
$desc_parent_id = $row["parent_id"]; |
471 |
$desc_indent_level = $row["indent_level"]; |
472 |
|
473 |
// We've found a descendant, delete it |
474 |
if ($desc_indent_level > $indent_level) { |
475 |
$delete_sql = "DELETE FROM element WHERE element_id = " |
476 |
. $desc_element_id; |
477 |
xx_tryquery($delete_sql); |
478 |
|
479 |
// Increment the deleted descendant counter |
480 |
$num_desc++; |
481 |
|
482 |
} // end of check for one descendant |
483 |
|
484 |
// Delete this (descendant) element reference from the stats database |
485 |
$sql = "DELETE from libstats.elementstats WHERE page_id = " |
486 |
. $page_id |
487 |
. " AND element_id = " |
488 |
. $desc_element_id; |
489 |
xx_tryquery($sql); |
490 |
|
491 |
} // end check for all descendants |
492 |
|
493 |
// Delete the parent itself |
494 |
$parent_sql = "DELETE FROM element WHERE element_id = " |
495 |
. $element_id; |
496 |
xx_tryquery($parent_sql); |
497 |
|
498 |
// Increment the deleted counter to include the parent |
499 |
$num_desc++; |
500 |
|
501 |
// Next, update the order of the remainders |
502 |
$order_sql = "UPDATE element SET element_order = element_order - " |
503 |
. $num_desc |
504 |
. " WHERE page_id = " |
505 |
. $page_id |
506 |
. " AND element_order > " |
507 |
. $element_order; |
508 |
xx_tryquery($order_sql); |
509 |
|
510 |
// Last, delete the (parent) element reference from the stats database |
511 |
$sql = "DELETE from libstats.elementstats WHERE page_id = " |
512 |
. $page_id |
513 |
. " AND element_id = " |
514 |
. $element_id; |
515 |
xx_tryquery($sql); |
516 |
|
517 |
// Done, return to page |
518 |
if ($position > 2) $new_pos = $position - 1; |
519 |
else $new_pos = 1; |
520 |
header("Location: scribe.phtml?page_id=". $page_id . "#p" . $new_pos); |
521 |
|
522 |
} // end delete parent and children |
523 |
|
524 |
} // end function |
525 |
|
526 |
|
527 |
/********************************************************** |
528 |
Function: deletePage |
529 |
Author: Paul Bramscher |
530 |
Last Modified: 03.16.2004 |
531 |
*********************************************************** |
532 |
Purpose: |
533 |
Deletes the supplied page id. In doing so, elements, |
534 |
assigned page staff, course information, assigned course |
535 |
personnel, and the page itself are deleted. |
536 |
|
537 |
This function also deletes any references to the supplied |
538 |
page id in the libstats database, including element-level |
539 |
and overall page statistics. |
540 |
**********************************************************/ |
541 |
function deletePage($page_id){ |
542 |
|
543 |
// Load globals |
544 |
include("global_vars.php"); |
545 |
|
546 |
// Include the page header |
547 |
include ($GLOBAL_ADMIN_INC."scribe_header.phtml"); |
548 |
|
549 |
// HTML header |
550 |
printf("<html>\n"); |
551 |
printf("<head>\n"); |
552 |
printf("<title>PageScribe: Deleting page...</title>\n"); |
553 |
printf("<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\">\n", $GLOBAL_ADMIN_CSS); |
554 |
printf("</head>\n"); |
555 |
|
556 |
msgTableOpen(1, "Deleting Page (ID# " . $page_id . ")"); |
557 |
printf("<b>Messages:</b><br>\n"); |
558 |
|
559 |
// Purge all |
560 |
if ($page_id > 0) { |
561 |
|
562 |
// Initialize |
563 |
$course_id = 0; |
564 |
|
565 |
// First identify whether this is a CourseLib page. If so, collect the course id. |
566 |
$sql = "SELECT course_id FROM course WHERE page_id = " |
567 |
. $page_id; |
568 |
|
569 |
$rs = xx_tryquery($sql); |
570 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
571 |
|
572 |
// Collect the access information |
573 |
$course_id = $row["course_id"]; |
574 |
|
575 |
// Delete all elements first |
576 |
$sql = "DELETE from element WHERE page_id =" . $page_id; |
577 |
if (xx_tryquery ($sql)) printf("Removed this page's elements.<BR>\n"); |
578 |
|
579 |
// Delete course information, if any |
580 |
$sql = "DELETE from course WHERE page_id =" . $page_id; |
581 |
if (xx_tryquery ($sql)) printf("Removed course information (if any).<BR>\n"); |
582 |
|
583 |
// Delete assigned course personnel, if any |
584 |
if ($course_id > 0) { |
585 |
|
586 |
$sql = "DELETE from course_personnel WHERE course_id =" . $course_id; |
587 |
if (xx_tryquery ($sql)) printf("Removed assigned course personnel (if any).<BR>\n"); |
588 |
} |
589 |
|
590 |
// Delete assigned staff, if any |
591 |
$sql = "DELETE from page_staff WHERE page_id =" . $page_id; |
592 |
if (xx_tryquery ($sql)) printf("Removed assigned staff (if any).<BR>\n"); |
593 |
|
594 |
// Delete assigned subjects, if any |
595 |
$sql = "DELETE from sub_page WHERE page_id =" . $page_id; |
596 |
if (xx_tryquery ($sql)) printf("Removed assigned subjects (if any).<BR>\n"); |
597 |
|
598 |
// Delete element statistics, if any |
599 |
$sql = "DELETE from libstats.elementstats WHERE page_id =" . $page_id; |
600 |
if (xx_tryquery ($sql)) printf("Removed page's element statistics (if any).<BR>\n"); |
601 |
|
602 |
// Delete page overall statistics, if any |
603 |
$sql = "DELETE from libstats.pagestats WHERE page_id =" . $page_id; |
604 |
if (xx_tryquery ($sql)) printf("Removed page's overall statistics (if any).<BR>\n"); |
605 |
|
606 |
// Delete the page information |
607 |
$sql = "DELETE from page WHERE page_id =" . $page_id; |
608 |
if (xx_tryquery ($sql)) printf("Removed page successfully."); |
609 |
|
610 |
} |
611 |
else printf("Scribe page not found."); |
612 |
|
613 |
printf("<br><br>\n"); |
614 |
msgTableClose(); |
615 |
|
616 |
// Link to return to admin console |
617 |
adminReturn(""); |
618 |
|
619 |
// Include the footer |
620 |
include ($GLOBAL_ADMIN_INC."scribe_footer.phtml"); |
621 |
} |
622 |
|
623 |
|
624 |
/********************************************************** |
625 |
Function: deletePageConfirm |
626 |
Author: Paul Bramscher |
627 |
Last Modified: 03.16.2004 |
628 |
*********************************************************** |
629 |
Purpose: |
630 |
Confirm prompt to delete the supplied page id. |
631 |
**********************************************************/ |
632 |
function deletePageConfirm($page_id){ |
633 |
|
634 |
// Load globals |
635 |
include ("global_vars.php"); |
636 |
|
637 |
// Make sure we have a valid integer type |
638 |
$page_id = (int) $page_id; |
639 |
|
640 |
// Include the page header |
641 |
include ($GLOBAL_ADMIN_INC."scribe_header.phtml"); |
642 |
|
643 |
// HTML header |
644 |
printf("<html>\n"); |
645 |
printf("<head>\n"); |
646 |
printf("<title>PageScribe: Delete Page?</title>\n"); |
647 |
printf("<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\">\n", $GLOBAL_ADMIN_CSS); |
648 |
printf("</head>\n"); |
649 |
|
650 |
msgTableOpen(1, "Delete Page (ID# " . $page_id . ")?"); |
651 |
|
652 |
// Check to see if its possible |
653 |
$exists = existsRow("page", "page_id", $page_id); |
654 |
if ($exists > 0){ |
655 |
|
656 |
// Lookup the title & author |
657 |
$page_title = lookupField("page", "page_id", $page_id, "page_title"); |
658 |
printf("<b>Page Title:</b> %s<br><br>\n ", $page_title); |
659 |
printf("This will permanently remove the page and its various assignments from the system.<br><br>\n"); |
660 |
|
661 |
// Form to draw the delete button |
662 |
printf("<form method = \"POST\" action = \"scribe_transaction.phtml\" >\n"); |
663 |
printf("<input type = \"Hidden\" name = \"transaction\" value = \"deletePage\" >\n"); |
664 |
printf("<input type = \"Hidden\" name = \"page_id\" value = \"%d\" >\n", $page_id); |
665 |
printf("<center>\n"); |
666 |
|
667 |
// Interior table |
668 |
printf("<table border=\"0\">\n"); |
669 |
|
670 |
printf("<tr><td>\n"); |
671 |
printf("<input type =\"Submit\" value=\"Delete!\">\n"); |
672 |
printf("</center>\n"); |
673 |
printf("</form>\n"); |
674 |
printf("</td>\n"); |
675 |
|
676 |
// Cancel button |
677 |
printf("<td>\n"); |
678 |
printf("<form method=\"POST\" action=\"scribe.phtml?page_id=%d\">\n", $page_id); |
679 |
printf("<input type=\"hidden\" name=\"cmd\" value=\"\">\n"); |
680 |
printf("<input type=\"submit\" value=\"Cancel\">\n"); |
681 |
printf("</form>\n"); |
682 |
printf("</td></tr>\n"); |
683 |
|
684 |
// Close interior table |
685 |
printf("</table>\n"); |
686 |
} |
687 |
|
688 |
// Failed |
689 |
else if ($exists < 1) printf ("Page not found. Operation cancelled.<br><br>\n"); |
690 |
|
691 |
msgTableClose(); |
692 |
|
693 |
// Link to return to admin console |
694 |
adminReturn(""); |
695 |
|
696 |
// Include the footer |
697 |
include ($GLOBAL_ADMIN_INC."scribe_footer.phtml"); |
698 |
} |
699 |
|
700 |
|
701 |
/********************************************************** |
702 |
Function: deletePageStaff |
703 |
Author: Paul Bramscher |
704 |
Last Modified: 03.03.2004 |
705 |
*********************************************************** |
706 |
Purpose: |
707 |
Delete a staffperson (possibly multiple) associated with |
708 |
the supplied page id. |
709 |
**********************************************************/ |
710 |
function deletePageStaff($page_id, $staff_list_array){ |
711 |
|
712 |
for ($element = 0; $element < sizeof($staff_list_array); $element++) { |
713 |
$sql = "DELETE FROM page_staff where page_id = " . $page_id . |
714 |
" AND staff_id = " . $staff_list_array[$element]; |
715 |
|
716 |
xx_tryquery($sql); |
717 |
} |
718 |
|
719 |
// Call the PageScribe page back |
720 |
header("Location: scribe.phtml?page_id=" . $page_id . "&cmd=pagestaff"); |
721 |
} |
722 |
|
723 |
|
724 |
/********************************************************** |
725 |
Function: displayTOC |
726 |
Author: Paul Bramscher |
727 |
Last Modified: 03.03.2004 |
728 |
*********************************************************** |
729 |
Purpose: |
730 |
Generates and displays a table of contents (TOC) for the |
731 |
supplied page id. This is done dynamically, and uses |
732 |
root-level elements on the given page. |
733 |
|
734 |
This function allows for the optional display of a |
735 |
two-column table of contents, split at the midpoint |
736 |
(rounded up for odd numbers of root elements). |
737 |
**********************************************************/ |
738 |
function displayTOC($page_id, $wrap_toc) { |
739 |
|
740 |
// Calculate number of elements |
741 |
$sql = "SELECT COUNT(*) as num_elements FROM element WHERE indent_level < 1 AND page_id = " |
742 |
. $page_id; |
743 |
$rs = xx_tryquery($sql); |
744 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
745 |
$num_elements = $row["num_elements"]; |
746 |
|
747 |
// Calculate midpoint element |
748 |
if ($num_elements > 0) $midpoint = ceil($num_elements / 2); |
749 |
else $midpoint = 0; |
750 |
|
751 |
if ($num_elements > 0) { |
752 |
|
753 |
// Retrieve all elements on that page |
754 |
$sql = "SELECT |
755 |
e.element_id, |
756 |
e.label, |
757 |
r.resource_id, |
758 |
r.title, |
759 |
l.location_id, |
760 |
l.location, |
761 |
v.service_id, |
762 |
v.service, |
763 |
s.staff_id, |
764 |
s.last_name, |
765 |
s.first_name, |
766 |
b.subject_id, |
767 |
b.subject |
768 |
|
769 |
FROM |
770 |
page p |
771 |
LEFT JOIN element e using (page_id) |
772 |
LEFT JOIN resource r on e.resource_id = r.resource_id |
773 |
LEFT JOIN location l on e.location_id = l.location_id |
774 |
LEFT JOIN service v on e.service_id = v.service_id |
775 |
LEFT JOIN staff s on e.staff_id = s.staff_id |
776 |
LEFT JOIN subject b on e.subject_id = b.subject_id |
777 |
|
778 |
WHERE |
779 |
p.page_id = " |
780 |
. $page_id |
781 |
. " AND e.indent_level < 1 ORDER BY e.element_order"; |
782 |
|
783 |
$rs = xx_tryquery($sql); |
784 |
|
785 |
// Build a general ToC anchor |
786 |
printf("<a name=\"toc\"></a>\n"); |
787 |
printf("<b>Table of Contents:</b><br>\n"); |
788 |
printf("<table>\n"); |
789 |
|
790 |
// Build the (single) row |
791 |
printf("<tr>\n"); |
792 |
|
793 |
// Populate the left cell |
794 |
printf("<td valign=\"top\"><ul>\n"); |
795 |
|
796 |
$row_num = 0; |
797 |
|
798 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
799 |
|
800 |
// Check for the midpoint |
801 |
if ($wrap_toc == 1) |
802 |
if ($row_num == $midpoint) { |
803 |
|
804 |
// Close the ul tag & table cell |
805 |
printf("</ul>\n"); |
806 |
printf("</td>\n"); |
807 |
|
808 |
// Start a new one |
809 |
printf("<td valign=\"top\">\n"); |
810 |
printf("<ul>\n"); |
811 |
|
812 |
} |
813 |
|
814 |
// General |
815 |
$element_id = $row["element_id"]; |
816 |
|
817 |
// Resource |
818 |
$resource_id = $row["resource_id"]; |
819 |
$title = $row["title"]; |
820 |
|
821 |
// Label/unique |
822 |
$label = $row["label"]; |
823 |
|
824 |
// Location |
825 |
$location_id = $row["location_id"]; |
826 |
$location = $row["location"]; |
827 |
|
828 |
// Service |
829 |
$service_id = $row["service_id"]; |
830 |
$service = $row["service"]; |
831 |
|
832 |
// Staff |
833 |
$staff_id = $row["staff_id"]; |
834 |
$last_name = $row["last_name"]; |
835 |
$first_name = $row["first_name"]; |
836 |
|
837 |
// Subject |
838 |
$subject_id = $row["subject_id"]; |
839 |
$subject = $row["subject"]; |
840 |
|
841 |
// Determine what sort of element it is |
842 |
$toc_label = ""; |
843 |
if ($resource_id > 0) $toc_label = $title; |
844 |
else if (strlen($label) > 0) $toc_label = $label; |
845 |
else if ($location_id > 0) $toc_label = $location; |
846 |
else if ($service_id > 0) $toc_label = $service; |
847 |
else if ($staff_id > 0) $toc_label = $first_name . " " . $last_name; |
848 |
else if ($subject_id > 0) $toc_label = $subject; |
849 |
|
850 |
// Last-minute error check |
851 |
if (strlen($toc_label) > 0) printf("<li><a href=\"#toc%d\">%s</a></li>\n", $element_id, $toc_label); |
852 |
|
853 |
$row_num++; |
854 |
|
855 |
} // end elements |
856 |
|
857 |
// Close things |
858 |
printf("</ul>\n"); |
859 |
printf("</td></tr></table><br>\n"); |
860 |
|
861 |
|
862 |
} // at least one item on this page |
863 |
} |
864 |
|
865 |
|
866 |
/********************************************************** |
867 |
Function: elementDown |
868 |
Author: Paul Bramscher |
869 |
Last Modified: 03.04.2004 |
870 |
*********************************************************** |
871 |
Incoming: |
872 |
$element_id Element to move down |
873 |
$page_id Page the element is location on |
874 |
$position Position on the page |
875 |
*********************************************************** |
876 |
Outgoing: |
877 |
None |
878 |
*********************************************************** |
879 |
Purpose: |
880 |
Moves a selected element (and any descendants) down to the |
881 |
position of the next youngest sibling. The sibling (and |
882 |
any of its descendants are moved up). The main challenge in |
883 |
the algorithm is the final shuffling phase since it's not |
884 |
possible move affected elements down, and then move the |
885 |
other affected elements up -- since they are selected by |
886 |
their order and duplicate positions will be created this |
887 |
way. Therefore, they are moved and written individually |
888 |
within the same recordset. One alternative would be to |
889 |
assign the "down set" temporary orders, over the current |
890 |
maximum, move the "up set" up, then re-assign the "down set" |
891 |
to its position. With the next iteration, perhaps... |
892 |
**********************************************************/ |
893 |
|
894 |
function elementDown($element_id, $page_id, $position) { |
895 |
|
896 |
// Get information about the element to move down |
897 |
$sql = "SELECT indent_level, parent_id, element_order FROM element WHERE page_id = " |
898 |
. $page_id |
899 |
. " AND element_id = " |
900 |
. $element_id; |
901 |
$rs = xx_tryquery($sql); |
902 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
903 |
$down_indent_level = $row["indent_level"]; |
904 |
$down_element_order = $row["element_order"]; |
905 |
|
906 |
// Identify information about the element to move up |
907 |
$sql = "SELECT element_id, element_order, indent_level FROM element WHERE page_id = " |
908 |
. $page_id |
909 |
. " AND indent_level = " |
910 |
. $down_indent_level |
911 |
. " AND element_order > " |
912 |
. $down_element_order |
913 |
. " ORDER BY element_order"; |
914 |
|
915 |
$rs = xx_tryquery($sql); |
916 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
917 |
$up_element_id = $row["element_id"]; |
918 |
$up_element_order = $row["element_order"]; |
919 |
|
920 |
/* |
921 |
Determine number of affected children to move down. Note that we count the |
922 |
number of elements from the starting position with an indent level of greater |
923 |
than the starting indent level (they are descendents) up to the position of the |
924 |
first younger sibling. Then we add the element itself. |
925 |
*/ |
926 |
|
927 |
$sql = "SELECT COUNT(*) as down_num FROM element WHERE page_id = " |
928 |
. $page_id |
929 |
. " AND element_order > " |
930 |
. $down_element_order |
931 |
. " AND indent_level > " |
932 |
. $down_indent_level |
933 |
. " AND element_order < " |
934 |
. $up_element_order; |
935 |
|
936 |
$rs = xx_tryquery($sql); |
937 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
938 |
$down_num = $row["down_num"]; |
939 |
|
940 |
// Add the element itself |
941 |
$down_num++; |
942 |
|
943 |
/* |
944 |
Determine number of elements which will be moved up. Note that we need to |
945 |
probe until we hit the next sibling or older generation element. |
946 |
*/ |
947 |
|
948 |
$sql = "SELECT element_id, indent_level, element_order FROM element WHERE page_id = " |
949 |
. $page_id |
950 |
. " AND element_order > " |
951 |
. $up_element_order |
952 |
. " ORDER BY element_order"; |
953 |
|
954 |
$rs = xx_tryquery($sql); |
955 |
|
956 |
// Flag to determine the end of this element's lineage |
957 |
$lineage = 1; |
958 |
|
959 |
/* |
960 |
Initialize the last affected element to be the next sibling. It may be overwritten |
961 |
the sibling's last descendant (if any). |
962 |
*/ |
963 |
|
964 |
$stop_element_order = $up_element_order; |
965 |
$stop_element_id = $up_element_id; |
966 |
|
967 |
// Number of descendants |
968 |
$up_num = 0; |
969 |
|
970 |
/* |
971 |
March through the list looking for all descendants. Take note of the last |
972 |
descendant affected by a move. |
973 |
*/ |
974 |
|
975 |
while (($row = xx_fetch_array ($rs, xx_ASSOC)) && $lineage == 1) { |
976 |
$desc_element_id = $row["element_id"]; |
977 |
$desc_indent_level = $row["indent_level"]; |
978 |
$desc_element_order = $row["element_order"]; |
979 |
|
980 |
if ($desc_indent_level > $down_indent_level) { |
981 |
$up_num++; |
982 |
$stop_element_id = $desc_element_id; |
983 |
$stop_element_order = $desc_element_order; |
984 |
} |
985 |
else { |
986 |
$lineage = 0; |
987 |
} |
988 |
} |
989 |
|
990 |
// Add the younger sibling itself |
991 |
$up_num++; |
992 |
|
993 |
// Flag to determine whether to move down (1) or up (0) |
994 |
$move_down = 1; |
995 |
|
996 |
// Begin the update process. Create a recordset of all affected elements. |
997 |
$sql = "SELECT element_id, indent_level, element_order FROM element WHERE page_id = " |
998 |
. $page_id |
999 |
. " AND element_order >= " |
1000 |
. $down_element_order |
1001 |
. " AND element_order <= " |
1002 |
. $stop_element_order |
1003 |
. " ORDER BY element_order"; |
1004 |
$rs = xx_tryquery($sql); |
1005 |
|
1006 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
1007 |
$mod_element_id = $row["element_id"]; |
1008 |
$mod_indent_level = $row["indent_level"]; |
1009 |
$mod_element_order = $row["element_order"]; |
1010 |
|
1011 |
/* |
1012 |
When we've moved the selected elements down, we switch operations and move |
1013 |
the others up. |
1014 |
*/ |
1015 |
|
1016 |
if ($mod_element_id == $up_element_id) $move_down = 0; |
1017 |
|
1018 |
if ($move_down == 1) { |
1019 |
$new_order = $mod_element_order + $up_num; |
1020 |
//printf("move element %d down %d spaces -- %d<BR>", $mod_element_id, $up_num, $new_order); |
1021 |
} |
1022 |
else { |
1023 |
$new_order = $mod_element_order - $down_num; |
1024 |
//printf("move element %d up %d spaces -- %d<BR>", $mod_element_id, $down_num, $new_order); |
1025 |
} |
1026 |
|
1027 |
$mod_sql = "UPDATE element SET element_order = " |
1028 |
. $new_order |
1029 |
. " WHERE page_id = " |
1030 |
. $page_id |
1031 |
. " AND element_id = " |
1032 |
. $mod_element_id; |
1033 |
xx_tryquery($mod_sql); |
1034 |
|
1035 |
} // all affected elements |
1036 |
|
1037 |
/* |
1038 |
Note: This part is somewhat a kludge. It typically comes out close, |
1039 |
but not exact due to the latest scribe engine. Should do some more |
1040 |
refinement here. |
1041 |
|
1042 |
Position is calculated by N + 2(N - 1) where N = element position. |
1043 |
We also need to add (3X - 1) of the downset, where X is the number of |
1044 |
children moved up. |
1045 |
*/ |
1046 |
|
1047 |
// Position is calculated by N + 2(N - 1) where N = element position. |
1048 |
// We also need to add the number of elements Z * 3. |
1049 |
$position = $position + (3 * $up_num); |
1050 |
|
1051 |
header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
1052 |
|
1053 |
} |
1054 |
|
1055 |
|
1056 |
/********************************************************** |
1057 |
Function: elementMultiFormat |
1058 |
Author: Paul Bramscher |
1059 |
Last Modified: 03.03.2004 |
1060 |
*********************************************************** |
1061 |
Incoming: |
1062 |
$auto_font_style Corresponds to 0-5 CSS style styles |
1063 |
$auto_indent_level Indent level upon which to apply |
1064 |
the changes. |
1065 |
$page_id Affected CourseLib/PageScribe page |
1066 |
*********************************************************** |
1067 |
Outgoing: |
1068 |
None |
1069 |
*********************************************************** |
1070 |
Purpose: |
1071 |
Performs a sweep-style format, changing all elements at a |
1072 |
particular indent level to the selected size on the |
1073 |
supplied page id. |
1074 |
**********************************************************/ |
1075 |
function elementMultiFormat($auto_element_size, $auto_indent_level, $page_id){ |
1076 |
|
1077 |
// Build the SQL |
1078 |
$sql = "UPDATE element SET element_size = " |
1079 |
. $auto_element_size |
1080 |
. " WHERE page_id = " |
1081 |
. $page_id |
1082 |
. " AND indent_level = " |
1083 |
. $auto_indent_level; |
1084 |
xx_tryquery($sql); |
1085 |
header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
1086 |
|
1087 |
} |
1088 |
|
1089 |
|
1090 |
/********************************************************** |
1091 |
Function: elementSize |
1092 |
Author: Paul Bramscher |
1093 |
Last Modified: 03.03.2004 |
1094 |
*********************************************************** |
1095 |
Incoming: |
1096 |
$element_id Element to perform decrease on |
1097 |
$page_id Page the element is location on |
1098 |
$position Position on the page |
1099 |
$size Value 1-5 of the element size to |
1100 |
utilize. |
1101 |
*********************************************************** |
1102 |
Outgoing: |
1103 |
None |
1104 |
*********************************************************** |
1105 |
Purpose: |
1106 |
Changes the size code for the specified element. Values |
1107 |
less than 1 are treated as 0, greater than 5 is treated as |
1108 |
5. This function is meant to deprecate the elementIncrease() |
1109 |
and elementDecrease() pair of functions. |
1110 |
**********************************************************/ |
1111 |
function elementSize($element_id, $page_id, $position, $size){ |
1112 |
|
1113 |
// Error trap |
1114 |
if ($size < 1) $size = 0; |
1115 |
if ($size > 5) $size = 5; |
1116 |
|
1117 |
$sql = "UPDATE element SET element_size = " |
1118 |
. $size |
1119 |
. " WHERE page_id = " |
1120 |
. $page_id |
1121 |
. " AND element_id = " |
1122 |
. $element_id; |
1123 |
xx_tryquery($sql); |
1124 |
header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
1125 |
} |
1126 |
|
1127 |
|
1128 |
/********************************************************** |
1129 |
Function: elementUp |
1130 |
Author: Paul Bramscher |
1131 |
Last Modified: 03.03.2004 |
1132 |
*********************************************************** |
1133 |
Incoming: |
1134 |
$element_id Element to move up |
1135 |
$page_id Page the element is location on |
1136 |
$position Position on the page |
1137 |
*********************************************************** |
1138 |
Outgoing: |
1139 |
None |
1140 |
*********************************************************** |
1141 |
Purpose: |
1142 |
Similar to elementDown, but differs since the user-selected |
1143 |
element is the "up set" rather than the "down set". See |
1144 |
comments under elementDown for further information. |
1145 |
**********************************************************/ |
1146 |
function elementUp($element_id, $page_id, $position) { |
1147 |
|
1148 |
// Get information about the element to move up |
1149 |
$sql = "SELECT indent_level, parent_id, element_order FROM element WHERE page_id = " |
1150 |
. $page_id |
1151 |
. " AND element_id = " |
1152 |
. $element_id; |
1153 |
$rs = xx_tryquery($sql); |
1154 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
1155 |
$up_indent_level = $row["indent_level"]; |
1156 |
$up_element_order = $row["element_order"]; |
1157 |
|
1158 |
// Identify information about the element which will move down |
1159 |
$sql = "SELECT element_id, element_order, indent_level FROM element WHERE page_id = " |
1160 |
. $page_id |
1161 |
. " AND indent_level = " |
1162 |
. $up_indent_level |
1163 |
. " AND element_order < " |
1164 |
. $up_element_order |
1165 |
. " ORDER BY element_order DESC"; |
1166 |
|
1167 |
$rs = xx_tryquery($sql); |
1168 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
1169 |
$down_element_id = $row["element_id"]; |
1170 |
$down_element_order = $row["element_order"]; |
1171 |
|
1172 |
/* |
1173 |
Determine number of affected children to move down. Note that we count the |
1174 |
number of elements from the starting position with an indent level of greater |
1175 |
than the starting indent level (they are descendents) up to the position of the |
1176 |
first younger sibling. Then we add the element itself. |
1177 |
*/ |
1178 |
|
1179 |
$sql = "SELECT COUNT(*) as down_num FROM element WHERE page_id = " |
1180 |
. $page_id |
1181 |
. " AND element_order > " |
1182 |
. $down_element_order |
1183 |
. " AND indent_level > " |
1184 |
. $up_indent_level |
1185 |
. " AND element_order < " |
1186 |
. $up_element_order; |
1187 |
|
1188 |
$rs = xx_tryquery($sql); |
1189 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
1190 |
$down_num = $row["down_num"]; |
1191 |
|
1192 |
// Add the element itself |
1193 |
$down_num++; |
1194 |
|
1195 |
/* |
1196 |
Determine number of elements which will be moved up. Note that we need to |
1197 |
probe until we hit the next sibling or older generation element. |
1198 |
*/ |
1199 |
|
1200 |
$sql = "SELECT element_id, indent_level, element_order FROM element WHERE page_id = " |
1201 |
. $page_id |
1202 |
. " AND element_order > " |
1203 |
. $up_element_order |
1204 |
. " ORDER BY element_order"; |
1205 |
$rs = xx_tryquery($sql); |
1206 |
|
1207 |
// Flag to determine the end of this element's lineage |
1208 |
$lineage = 1; |
1209 |
|
1210 |
/* |
1211 |
Initialize the last affected element to be the next sibling. It may be overwritten |
1212 |
the sibling's last descendant (if any). |
1213 |
*/ |
1214 |
|
1215 |
$stop_element_order = $up_element_order; |
1216 |
$stop_element_id = $up_element_id; |
1217 |
|
1218 |
// Number of descendants |
1219 |
$up_num = 0; |
1220 |
|
1221 |
/* |
1222 |
March through the list looking for all descendants. Take note of the last |
1223 |
descendant affected by a move. |
1224 |
*/ |
1225 |
|
1226 |
while (($row = xx_fetch_array ($rs, xx_ASSOC)) && $lineage == 1) { |
1227 |
$desc_element_id = $row["element_id"]; |
1228 |
$desc_indent_level = $row["indent_level"]; |
1229 |
$desc_element_order = $row["element_order"]; |
1230 |
|
1231 |
if ($desc_indent_level > $up_indent_level) { |
1232 |
$up_num++; |
1233 |
$stop_element_id = $desc_element_id; |
1234 |
$stop_element_order = $desc_element_order; |
1235 |
} |
1236 |
else { |
1237 |
$lineage = 0; |
1238 |
} |
1239 |
} |
1240 |
|
1241 |
// Add the younger sibling itself |
1242 |
$up_num++; |
1243 |
|
1244 |
// Flag to determine whether to move down (1) or up (0) |
1245 |
$move_down = 1; |
1246 |
|
1247 |
// Begin the update process. Create a recordset of all affected elements. |
1248 |
$sql = "SELECT element_id, indent_level, element_order FROM element WHERE page_id = " |
1249 |
. $page_id |
1250 |
. " AND element_order >= " |
1251 |
. $down_element_order |
1252 |
. " AND element_order <= " |
1253 |
. $stop_element_order |
1254 |
. " ORDER BY element_order"; |
1255 |
$rs = xx_tryquery($sql); |
1256 |
|
1257 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
1258 |
$mod_element_id = $row["element_id"]; |
1259 |
$mod_indent_level = $row["indent_level"]; |
1260 |
$mod_element_order = $row["element_order"]; |
1261 |
|
1262 |
/* |
1263 |
When we've moved the selected elements down, we switch operations and move |
1264 |
the others up. |
1265 |
*/ |
1266 |
|
1267 |
if ($mod_element_id == $element_id) $move_down = 0; |
1268 |
|
1269 |
if ($move_down == 1) { |
1270 |
$new_order = $mod_element_order + $up_num; |
1271 |
//printf("move element %d down %d spaces -- %d<BR>", $mod_element_id, $up_num, $new_order); |
1272 |
} |
1273 |
else { |
1274 |
$new_order = $mod_element_order - $down_num; |
1275 |
//printf("move element %d up %d spaces -- %d<BR>", $mod_element_id, $down_num, $new_order); |
1276 |
} |
1277 |
|
1278 |
$mod_sql = "UPDATE element SET element_order = " |
1279 |
. $new_order |
1280 |
. " WHERE page_id = " |
1281 |
. $page_id |
1282 |
. " AND element_id = " |
1283 |
. $mod_element_id; |
1284 |
xx_tryquery($mod_sql); |
1285 |
|
1286 |
} // all affected elements |
1287 |
|
1288 |
// Position is calculated by N + 2(N - 1) where N = element position. |
1289 |
$position = $down_element_order + (2 * $down_element_order - 1); |
1290 |
|
1291 |
header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
1292 |
|
1293 |
} |
1294 |
|
1295 |
|
1296 |
/********************************************************** |
1297 |
Function: getMaxIndent |
1298 |
Author: Paul Bramscher |
1299 |
Last Modified: 03.03.2004 |
1300 |
*********************************************************** |
1301 |
Purpose: |
1302 |
Return the maximum indent level for the supplied page id. |
1303 |
**********************************************************/ |
1304 |
function getMaxIndent($page_id){ |
1305 |
|
1306 |
// Initialize |
1307 |
$max_indent = 0; |
1308 |
|
1309 |
// Build the query |
1310 |
$sql = "SELECT MAX(indent_level) AS max_indent FROM element WHERE page_id = " |
1311 |
. $page_id; |
1312 |
|
1313 |
$rs = xx_tryquery($sql); |
1314 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
1315 |
$max_indent = $row["max_indent"]; |
1316 |
|
1317 |
return $max_indent; |
1318 |
} |
1319 |
|
1320 |
|
1321 |
/********************************************************** |
1322 |
Function: insertCoursePers |
1323 |
Author: Paul Bramscher |
1324 |
Last Modified: 03.03.2004 |
1325 |
*********************************************************** |
1326 |
Purpose: |
1327 |
Associates the incoming personnel information with the |
1328 |
supplied course id. Note that the incoming may be one of |
1329 |
three types of personnel: a library staff person, a faculty |
1330 |
member (existing or newly created on the fly), or a |
1331 |
non-indexed TA. |
1332 |
**********************************************************/ |
1333 |
function insertCoursePers($course_id, $faculty_id, |
1334 |
$page_id, $pers_email, $pers_firstname, $pers_lastname, |
1335 |
$pers_type, $pers_account, $staff_id, $stafftitle_id){ |
1336 |
|
1337 |
// Error flag |
1338 |
$err_code = 0; |
1339 |
|
1340 |
// Incoming was library staff |
1341 |
if ($staff_id > 1) { |
1342 |
$sql = "INSERT INTO course_personnel (course_id, stafftitle_id, staff_id) VALUES (" |
1343 |
. $course_id |
1344 |
. ", " |
1345 |
. $stafftitle_id |
1346 |
. ", " |
1347 |
. $staff_id |
1348 |
. ")"; |
1349 |
|
1350 |
} |
1351 |
|
1352 |
// Incoming was faculty |
1353 |
else if ($faculty_id > 1) { |
1354 |
$sql = "INSERT INTO course_personnel (course_id, stafftitle_id, faculty_id) VALUES (" |
1355 |
. $course_id |
1356 |
. ", " |
1357 |
. $stafftitle_id |
1358 |
. ", " |
1359 |
. $faculty_id |
1360 |
. ")"; |
1361 |
|
1362 |
} |
1363 |
|
1364 |
// Incoming was a new faculty member |
1365 |
else if (strlen($pers_lastname) > 0 && $pers_type == "faculty") { |
1366 |
|
1367 |
// Check for uniqueness |
1368 |
$faculty_name_display = $pers_firstname . " " . $pers_lastname; |
1369 |
$exists_id = existsFaculty($pers_firstname, $pers_lastname); |
1370 |
|
1371 |
if ($exists_id > 0) { |
1372 |
$err_code = 1; |
1373 |
$err_msg = "Failed. '" . $faculty_name_display . "' already exists in the Faculty table. Faculty firstname + lastname must be unique."; |
1374 |
} |
1375 |
|
1376 |
// So long as there are no errors |
1377 |
if ($err_code < 1) { |
1378 |
|
1379 |
// Clean up strings |
1380 |
if (strlen($pers_lastname) > 0) $pers_lastname = textInmySQL($pers_lastname); |
1381 |
if (strlen($pers_firstname) > 0) $pers_firstname = textInmySQL($pers_firstname); |
1382 |
if (strlen($pers_email) > 0) $pers_email = textInmySQL($pers_email); |
1383 |
if (strlen($pers_account) > 0) $pers_account = textInmySQL($pers_account); |
1384 |
|
1385 |
// Insert into the faculty table |
1386 |
$sql = "INSERT INTO faculty (faculty_lastname, faculty_firstname, faculty_account, faculty_email) VALUES ('" |
1387 |
. $pers_lastname |
1388 |
. "', '" |
1389 |
. $pers_firstname |
1390 |
. "', '" |
1391 |
. $pers_account |
1392 |
. "', '" |
1393 |
. $pers_email |
1394 |
. "')"; |
1395 |
xx_tryquery($sql); |
1396 |
$new_faculty_id = xx_insert_id(); |
1397 |
|
1398 |
// Now, build the SQL for the insert into course_personnel |
1399 |
$sql = "INSERT INTO course_personnel (course_id, stafftitle_id, faculty_id) VALUES (" |
1400 |
. $course_id |
1401 |
. ", " |
1402 |
. $stafftitle_id |
1403 |
. ", " |
1404 |
. $new_faculty_id |
1405 |
. ")"; |
1406 |
|
1407 |
} |
1408 |
} |
1409 |
|
1410 |
// Incoming was a lowly TA or "other". Don't index these, plop them into the course_personnel table |
1411 |
else if (strlen($pers_lastname) > 0 && $pers_type == "other") { |
1412 |
|
1413 |
// Clean up strings |
1414 |
if (strlen($pers_lastname) > 0) $pers_lastname = textInmySQL($pers_lastname); |
1415 |
if (strlen($pers_firstname) > 0) $pers_firstname = textInmySQL($pers_firstname); |
1416 |
if (strlen($pers_email) > 0) $pers_email = textInmySQL($pers_email); |
1417 |
if (strlen($pers_account) > 0) $pers_account = textInmySQL($pers_account); |
1418 |
|
1419 |
$sql = "INSERT INTO course_personnel (course_id, stafftitle_id, pers_lastname, pers_firstname, pers_account, pers_email) VALUES (" |
1420 |
. $course_id |
1421 |
. ", " |
1422 |
. $stafftitle_id |
1423 |
. ", '" |
1424 |
. $pers_lastname |
1425 |
. "', '" |
1426 |
. $pers_firstname |
1427 |
. "', '" |
1428 |
. $pers_account |
1429 |
. "', '" |
1430 |
. $pers_email |
1431 |
. "')"; |
1432 |
} |
1433 |
|
1434 |
// Must have at least a last name. Send them back to the page. |
1435 |
else header("Location: scribe.phtml?page_id=" . $page_id); |
1436 |
|
1437 |
|
1438 |
// Proceed if there are no error messages |
1439 |
if ($err_code == 0) { |
1440 |
xx_tryquery($sql); |
1441 |
|
1442 |
// Done. Call the PageScribe page back |
1443 |
header("Location: scribe.phtml?page_id=" . $page_id . "#coursePers"); |
1444 |
|
1445 |
} |
1446 |
|
1447 |
else { |
1448 |
|
1449 |
// Page header |
1450 |
require_once ($GLOBAL_ADMIN_INC."scribe_header.phtml"); |
1451 |
|
1452 |
printf("<center><h3>Adding Course Personnel...</h3>\n"); |
1453 |
|
1454 |
// Table |
1455 |
printf("<table width = \"60%%\" border = \"3\" cellpadding =\"4\" class=\"backLight\">\n"); |
1456 |
printf("<tr><td>\n"); |
1457 |
printf("<b>Messages:</b><br>\n"); |
1458 |
printf("%s", $err_msg); |
1459 |
printf("<br><br></td></tr></table>\n"); |
1460 |
printf("</center>\n"); |
1461 |
|
1462 |
// Page footer |
1463 |
require_once ($GLOBAL_ADMIN_INC."scribe_footer.phtml"); |
1464 |
|
1465 |
} |
1466 |
|
1467 |
} |
1468 |
|
1469 |
|
1470 |
/********************************************************** |
1471 |
Function: insertScribeLabel |
1472 |
Author: Paul Bramscher |
1473 |
Last Modified: 03.03.2004 |
1474 |
*********************************************************** |
1475 |
Purpose: |
1476 |
Inserts a "label" or free-text type PageScribe element onto |
1477 |
a PageScribe page. |
1478 |
**********************************************************/ |
1479 |
function insertScribeLabel($element_descr, $label, $label_url, $place_array_HTML, $page_id){ |
1480 |
|
1481 |
// Clean up strings |
1482 |
$element_descr = textInmySQL($element_descr); |
1483 |
$label = textInmySQL($label); |
1484 |
|
1485 |
// Problem flag |
1486 |
$problem = 0; |
1487 |
|
1488 |
// Protect against blank label |
1489 |
if (strlen($label) < 1) { |
1490 |
$problem = 1; |
1491 |
} |
1492 |
|
1493 |
// No problems |
1494 |
if ($problem == 0) { |
1495 |
|
1496 |
// Error check |
1497 |
if ($label_url == "http://") $label_url = ""; |
1498 |
|
1499 |
// Split by comma separated values |
1500 |
$place_array = split(",", $place_array_HTML); |
1501 |
|
1502 |
// Break apart place array |
1503 |
$prev_element_id = $place_array[0]; |
1504 |
$prev_element_order = $place_array[1]; |
1505 |
$prev_indent_level = $place_array[2]; |
1506 |
// $parent_id = $place_array[3]; |
1507 |
$position = $place_array[4]; |
1508 |
|
1509 |
// First probe for the new parent_id |
1510 |
$parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); |
1511 |
|
1512 |
// Next, bump all of the following items down by one |
1513 |
$sql = "UPDATE element SET element_order = element_order + 1 WHERE page_id = " |
1514 |
. $page_id . " AND element_order >= " . $prev_element_order; |
1515 |
xx_tryquery($sql); |
1516 |
|
1517 |
// Next insert the new label |
1518 |
$sql = "INSERT INTO element (page_id, label, label_url, element_descr, element_order, indent_level,parent_id) VALUES (" |
1519 |
. $page_id . ", '" |
1520 |
. $label . "', '" |
1521 |
. $label_url . "', '" |
1522 |
. $element_descr . "', " |
1523 |
. $prev_element_order . ", " |
1524 |
. $prev_indent_level . ", " |
1525 |
. $parent_id . ")"; |
1526 |
xx_tryquery($sql); |
1527 |
} |
1528 |
|
1529 |
header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
1530 |
} |
1531 |
|
1532 |
|
1533 |
/********************************************************** |
1534 |
Function: insertScribeLocation |
1535 |
Author: Paul Bramscher |
1536 |
Last Modified: 03.03.2004 |
1537 |
*********************************************************** |
1538 |
Purpose: |
1539 |
Inserts location type element onto a PageScribe page. |
1540 |
**********************************************************/ |
1541 |
function insertScribeLocation($location_id, $place_array_HTML, $page_id){ |
1542 |
|
1543 |
// Error checking |
1544 |
if ($location_id > 0) { |
1545 |
|
1546 |
// Split by comma separated values |
1547 |
$place_array = split(",", $place_array_HTML); |
1548 |
|
1549 |
// Break apart place array |
1550 |
$prev_element_id = $place_array[0]; |
1551 |
$prev_element_order = $place_array[1]; |
1552 |
$prev_indent_level = $place_array[2]; |
1553 |
// $parent_id = $place_array[3]; |
1554 |
$position = $place_array[4]; |
1555 |
|
1556 |
// First probe for the new parent_id |
1557 |
$parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); |
1558 |
|
1559 |
// Next, bump all of the following items down by one |
1560 |
$sql = "UPDATE element SET element_order = element_order + 1 WHERE page_id = " |
1561 |
. $page_id . " AND element_order >= " . $prev_element_order; |
1562 |
xx_tryquery($sql); |
1563 |
|
1564 |
// Next insert the new location |
1565 |
$sql = "INSERT INTO element (page_id, location_id, element_order, indent_level,parent_id) VALUES (" |
1566 |
. $page_id . ", " |
1567 |
. $location_id . ", " |
1568 |
. $prev_element_order . ", " |
1569 |
. $prev_indent_level . ", " |
1570 |
. $parent_id . ")"; |
1571 |
xx_tryquery($sql); |
1572 |
|
1573 |
} |
1574 |
|
1575 |
header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
1576 |
} |
1577 |
|
1578 |
|
1579 |
/********************************************************** |
1580 |
Function: insertScribeResource |
1581 |
Author: Paul Bramscher |
1582 |
Last Modified: 03.03.2004 |
1583 |
*********************************************************** |
1584 |
Purpose: |
1585 |
Inserts a resource type element onto a PageScribe page. |
1586 |
**********************************************************/ |
1587 |
function insertScribeResource($place_array_HTML, $resource_id, $page_id){ |
1588 |
|
1589 |
// Error checking |
1590 |
if ($resource_id > 0) { |
1591 |
|
1592 |
// Split by comma separated values |
1593 |
$place_array = split(",", $place_array_HTML); |
1594 |
|
1595 |
// Break apart place array |
1596 |
$prev_element_id = $place_array[0]; |
1597 |
$prev_element_order = $place_array[1]; |
1598 |
$prev_indent_level = $place_array[2]; |
1599 |
// $parent_id = $place_array[3]; |
1600 |
$position = $place_array[4]; |
1601 |
|
1602 |
// First probe for the new parent_id |
1603 |
$parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); |
1604 |
|
1605 |
// Next, bump all of the following items down by one |
1606 |
$sql = "UPDATE element SET element_order = element_order + 1 WHERE page_id = " |
1607 |
. $page_id . " AND element_order >= " . $prev_element_order; |
1608 |
xx_tryquery($sql); |
1609 |
|
1610 |
// Next insert the new resource |
1611 |
$sql = "INSERT INTO element (page_id, resource_id, element_order, indent_level,parent_id) VALUES (" |
1612 |
. $page_id . ", " |
1613 |
. $resource_id . ", " |
1614 |
. $prev_element_order . ", " |
1615 |
. $prev_indent_level . ", " |
1616 |
. $parent_id . ")"; |
1617 |
xx_tryquery($sql); |
1618 |
|
1619 |
} |
1620 |
|
1621 |
header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
1622 |
} |
1623 |
|
1624 |
|
1625 |
/********************************************************** |
1626 |
Function: insertScribeRQS |
1627 |
Author: Paul Bramscher |
1628 |
Last Modified: 03.03.2004 |
1629 |
*********************************************************** |
1630 |
Purpose: |
1631 |
This function performs the "RQS harvest". For the supplied |
1632 |
subject id, collect all of the resources and insert them |
1633 |
as elements onto a PageScribe page. |
1634 |
**********************************************************/ |
1635 |
function insertScribeRQS($place_array_HTML, $subject_id, $page_id){ |
1636 |
|
1637 |
// Error checking |
1638 |
if ($subject_id > 0) { |
1639 |
|
1640 |
// Split by comma separated values |
1641 |
$place_array = split(",", $place_array_HTML); |
1642 |
|
1643 |
// Break apart place array |
1644 |
$prev_element_id = $place_array[0]; |
1645 |
$prev_element_order = $place_array[1]; |
1646 |
$prev_indent_level = $place_array[2]; |
1647 |
// $parent_id = $place_array[3]; |
1648 |
$position = $place_array[4]; |
1649 |
|
1650 |
// First probe for the new parent_id |
1651 |
$parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); |
1652 |
|
1653 |
// Identify the number of new elements to add |
1654 |
$sql = "SELECT COUNT(*) as num_rqs from res_sub_infotype WHERE subject_id = " . $subject_id; |
1655 |
$rs = xx_tryquery($sql); |
1656 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
1657 |
|
1658 |
// Pull out the possible display values |
1659 |
$num_rqs = $row["num_rqs"]; |
1660 |
|
1661 |
// Continue if num_rqs > 0. If the RQS+ page was empty, skip all of this. |
1662 |
if ($num_rqs > 0) { |
1663 |
|
1664 |
// Next, bump all of the following items down by the number of incoming |
1665 |
$sql = "UPDATE element SET element_order = element_order + " |
1666 |
. $num_rqs |
1667 |
. " WHERE page_id = " |
1668 |
. $page_id . " AND element_order >= " . $prev_element_order; |
1669 |
xx_tryquery($sql); |
1670 |
|
1671 |
// Cycle through the resources |
1672 |
$sql = "SELECT rsi.resource_id, r.title |
1673 |
FROM res_sub_infotype rsi |
1674 |
LEFT JOIN resource r using (resource_id) |
1675 |
WHERE subject_id = " . $subject_id . |
1676 |
" ORDER BY r.title"; |
1677 |
|
1678 |
$rs = xx_tryquery($sql); |
1679 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
1680 |
|
1681 |
// Fetch resource |
1682 |
$resource_id = $row["resource_id"]; |
1683 |
|
1684 |
// Next insert the culled resource |
1685 |
$i_sql = "INSERT INTO element (page_id, resource_id, element_order, indent_level,parent_id) VALUES (" |
1686 |
. $page_id . ", " |
1687 |
. $resource_id . ", " |
1688 |
. $prev_element_order . ", " |
1689 |
. $prev_indent_level . ", " |
1690 |
. $parent_id . ")"; |
1691 |
xx_tryquery($i_sql); |
1692 |
|
1693 |
// Increment element order |
1694 |
$prev_element_order++; |
1695 |
|
1696 |
} // for all resources on RQS page |
1697 |
|
1698 |
} // rqs+ page was not empty |
1699 |
|
1700 |
} |
1701 |
|
1702 |
header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
1703 |
|
1704 |
} |
1705 |
|
1706 |
|
1707 |
/********************************************************** |
1708 |
Function: insertScribeRQSLink |
1709 |
Author: Paul Bramscher |
1710 |
Last Modified: 03.03.2004 |
1711 |
*********************************************************** |
1712 |
Purpose: |
1713 |
Inserts an RQS subject page element onto a PageScribe page. |
1714 |
**********************************************************/ |
1715 |
function insertScribeRQSLink($place_array_HTML, $subject_id, $page_id){ |
1716 |
|
1717 |
// Error checking |
1718 |
if ($subject_id > 0) { |
1719 |
|
1720 |
// Split by comma separated values |
1721 |
$place_array = split(",", $place_array_HTML); |
1722 |
|
1723 |
// Break apart place array |
1724 |
$prev_element_id = $place_array[0]; |
1725 |
$prev_element_order = $place_array[1]; |
1726 |
$prev_indent_level = $place_array[2]; |
1727 |
// $parent_id = $place_array[3]; |
1728 |
$position = $place_array[4]; |
1729 |
|
1730 |
// First probe for the new parent_id |
1731 |
$parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); |
1732 |
|
1733 |
// Next, bump all of the following items down by one |
1734 |
$sql = "UPDATE element SET element_order = element_order + 1 WHERE page_id = " |
1735 |
. $page_id . " AND element_order >= " . $prev_element_order; |
1736 |
xx_tryquery($sql); |
1737 |
|
1738 |
// Next insert the new resource |
1739 |
$sql = "INSERT INTO element (page_id, subject_id, element_order, indent_level,parent_id) VALUES (" |
1740 |
. $page_id . ", " |
1741 |
. $subject_id . ", " |
1742 |
. $prev_element_order . ", " |
1743 |
. $prev_indent_level . ", " |
1744 |
. $parent_id . ")"; |
1745 |
xx_tryquery($sql); |
1746 |
|
1747 |
} |
1748 |
|
1749 |
header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
1750 |
} |
1751 |
|
1752 |
|
1753 |
/********************************************************** |
1754 |
Function: insertScribeService |
1755 |
Author: Paul Bramscher |
1756 |
Last Modified: 03.03.2004 |
1757 |
*********************************************************** |
1758 |
Purpose: |
1759 |
Inserts a service type element onto a PageScribe page. |
1760 |
**********************************************************/ |
1761 |
function insertScribeService($place_array_HTML, $page_id, $service_id){ |
1762 |
|
1763 |
// Error checking |
1764 |
if ($service_id > 0) { |
1765 |
|
1766 |
// Split by comma separated values |
1767 |
$place_array = split(",", $place_array_HTML); |
1768 |
|
1769 |
// Break apart place array |
1770 |
$prev_element_id = $place_array[0]; |
1771 |
$prev_element_order = $place_array[1]; |
1772 |
$prev_indent_level = $place_array[2]; |
1773 |
// $parent_id = $place_array[3]; |
1774 |
$position = $place_array[4]; |
1775 |
|
1776 |
// First probe for the new parent_id |
1777 |
$parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); |
1778 |
|
1779 |
// Next, bump all of the following items down by one |
1780 |
$sql = "UPDATE element SET element_order = element_order + 1 WHERE page_id = " |
1781 |
. $page_id . " AND element_order >= " . $prev_element_order; |
1782 |
xx_tryquery($sql); |
1783 |
|
1784 |
// Next insert the new service |
1785 |
$sql = "INSERT INTO element (page_id, service_id, element_order, indent_level,parent_id) VALUES (" |
1786 |
. $page_id . ", " |
1787 |
. $service_id . ", " |
1788 |
. $prev_element_order . ", " |
1789 |
. $prev_indent_level . ", " |
1790 |
. $parent_id . ")"; |
1791 |
xx_tryquery($sql); |
1792 |
|
1793 |
} |
1794 |
|
1795 |
header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
1796 |
} |
1797 |
|
1798 |
|
1799 |
/********************************************************** |
1800 |
Function: insertScribeStaff |
1801 |
Author: Paul Bramscher |
1802 |
Last Modified: 03.03.2004 |
1803 |
*********************************************************** |
1804 |
Purpose: |
1805 |
Inserts a staffperson as an element on a PageScribe page. |
1806 |
**********************************************************/ |
1807 |
function insertScribeStaff($place_array_HTML, $staff_id, $page_id){ |
1808 |
|
1809 |
// Split by comma separated values |
1810 |
$place_array = split(",", $place_array_HTML); |
1811 |
|
1812 |
// Break apart place array |
1813 |
$prev_element_id = $place_array[0]; |
1814 |
$prev_element_order = $place_array[1]; |
1815 |
$prev_indent_level = $place_array[2]; |
1816 |
// $parent_id = $place_array[3]; |
1817 |
$position = $place_array[4]; |
1818 |
|
1819 |
// First probe for the new parent_id |
1820 |
$parent_id = parentProbe($page_id, $prev_element_order, $prev_indent_level); |
1821 |
|
1822 |
// Next, bump all of the following items down by one |
1823 |
$sql = "UPDATE element SET element_order = element_order + 1 WHERE page_id = " |
1824 |
. $page_id . " AND element_order >= " . $prev_element_order; |
1825 |
xx_tryquery($sql); |
1826 |
|
1827 |
// Next insert the new staff |
1828 |
$sql = "INSERT INTO element (page_id, staff_id, element_order, indent_level,parent_id) VALUES (" |
1829 |
. $page_id . ", " |
1830 |
. $staff_id . ", " |
1831 |
. $prev_element_order . ", " |
1832 |
. $prev_indent_level . ", " |
1833 |
. $parent_id . ")"; |
1834 |
xx_tryquery($sql); |
1835 |
|
1836 |
header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
1837 |
} |
1838 |
|
1839 |
|
1840 |
/********************************************************** |
1841 |
Function: pageLoadStats |
1842 |
Author: Paul Bramscher |
1843 |
Last Modified: 03.03.2004 |
1844 |
*********************************************************** |
1845 |
Purpose: |
1846 |
Logs a statistical entry for a PageScribe/CourseLib page |
1847 |
load. Page id, date, and IP address are currently logged. |
1848 |
It would be relatively trivial to add other fields, |
1849 |
such as browser type, refer URL, etc. both to the database |
1850 |
and this function here. However, care must be taken so |
1851 |
that the database doesn't grow too large. Currently there |
1852 |
exists no automatic mechanism to purge or archive stats. |
1853 |
**********************************************************/ |
1854 |
function pageLoadStats($page_id){ |
1855 |
|
1856 |
// Add a row for page usage |
1857 |
|
1858 |
// Fetch user ip |
1859 |
$user_ip = $GLOBALS["REMOTE_ADDR"]; |
1860 |
|
1861 |
// Do the stat stuff here |
1862 |
$sql = "INSERT INTO libstats.pagestats ( |
1863 |
page_id, |
1864 |
visit_date, |
1865 |
user_ip) VALUES (" |
1866 |
. $page_id |
1867 |
. ", now(), '" |
1868 |
. $user_ip |
1869 |
. "')"; |
1870 |
xx_tryquery($sql); |
1871 |
|
1872 |
} |
1873 |
|
1874 |
|
1875 |
/********************************************************** |
1876 |
Function: pageTemplate |
1877 |
Author: Paul Bramscher |
1878 |
Last Modified: 03.03.2004 |
1879 |
*********************************************************** |
1880 |
Purpose: |
1881 |
Performs the clone or copy page functionality. Note that |
1882 |
the new title is "Copy of:" prefixed to the previous page |
1883 |
title. Also, not all parameters are copied. Specifically, |
1884 |
those relating to permissions must be set independently. |
1885 |
|
1886 |
This function could probably be cleaned up for efficiency. |
1887 |
The biggest challenge is in handling the parent-child |
1888 |
relationships on the new page. While the abstract structure |
1889 |
remains the same, the pointers to specific element id's |
1890 |
on the new page are all new and must be calculated on the |
1891 |
fly. |
1892 |
**********************************************************/ |
1893 |
function pageTemplate($page_id, $sess_staff_id, $sess_staff_account){ |
1894 |
|
1895 |
// First copy the page elements |
1896 |
$sql = "SELECT * FROM page WHERE page_id = " |
1897 |
. $page_id; |
1898 |
$rs = xx_tryquery($sql); |
1899 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
1900 |
|
1901 |
// Fetch results |
1902 |
$style_id = $row["style_id"]; |
1903 |
$pagetype_id = $row["pagetype_id"]; |
1904 |
$page_title = $row["page_title"]; |
1905 |
$pagetitle_style = $row["pagetitle_style"]; |
1906 |
$display_toc = $row["display_toc"]; |
1907 |
$wrap_toc = $row["wrap_toc"]; |
1908 |
$display_up = $row["display_up"]; |
1909 |
$up_text = $row["up_text"]; |
1910 |
|
1911 |
// Handle possible nulls |
1912 |
if ($display_toc < 1) $display_toc = "NULL"; |
1913 |
if ($wrap_toc < 1) $wrap_toc = "NULL"; |
1914 |
if ($display_up < 1) $display_up = "NULL"; |
1915 |
if ($pagetitle_style < 1) $pagetitle_style = "NULL"; |
1916 |
|
1917 |
// Clean up strings |
1918 |
$page_title = textInmySQL($page_title); |
1919 |
if (strlen($up_text) > 0) $up_text = textInmySQL($up_text); |
1920 |
|
1921 |
// Create new page insert statement |
1922 |
|
1923 |
|
1924 |
$sql = "INSERT INTO page |
1925 |
(date_created, |
1926 |
account_created, |
1927 |
staff_coordinator, |
1928 |
style_id, |
1929 |
pagetype_id, |
1930 |
page_title, |
1931 |
pagetitle_style, |
1932 |
display_toc, |
1933 |
wrap_toc, |
1934 |
display_up, |
1935 |
up_text) |
1936 |
VALUES ( |
1937 |
now(), '" |
1938 |
. $sess_staff_account |
1939 |
. "', " |
1940 |
. $sess_staff_id |
1941 |
. ", " |
1942 |
. $style_id |
1943 |
. ", " |
1944 |
. $pagetype_id |
1945 |
. ", 'Copy of: " |
1946 |
. $page_title |
1947 |
. "', " |
1948 |
. $pagetitle_style |
1949 |
. ", " |
1950 |
. $display_toc |
1951 |
. ", " |
1952 |
. $wrap_toc |
1953 |
. ", " |
1954 |
. $display_up |
1955 |
. ", '" |
1956 |
. $up_text |
1957 |
. "')"; |
1958 |
|
1959 |
xx_tryquery($sql); |
1960 |
$new_page_id = xx_insert_id(); |
1961 |
|
1962 |
// If a new stub was created, and this happens to be a course page, get the course id. |
1963 |
if ($new_page_id > 0 && $pagetype_id == 3) { |
1964 |
$course_id = lookupfield("course", "page_id", $page_id, "course_id"); |
1965 |
} |
1966 |
|
1967 |
|
1968 |
if ($course_id > 0 && $new_page_id > 0) { |
1969 |
|
1970 |
// Copy the course elements |
1971 |
$sql = "SELECT * FROM course WHERE page_id = " |
1972 |
. $page_id; |
1973 |
$rs = xx_tryquery($sql); |
1974 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
1975 |
|
1976 |
// Fetch results |
1977 |
$coursesub_id = $row["coursesub_id"]; |
1978 |
$course_num = $row["course_num"]; |
1979 |
$course_section = $row["course_section"]; |
1980 |
$course_concat = $row["course_concat"]; |
1981 |
$term_id = $row["term_id"]; |
1982 |
$course_year = $row["course_year"]; |
1983 |
$campus_id = $row["campus_id"]; |
1984 |
$courseheader = $row["courseheader"]; |
1985 |
$introheader1 = $row["introheader1"]; |
1986 |
$intromessage1 = $row["intromessage1"]; |
1987 |
$introheader2 = $row["introheader2"]; |
1988 |
$intromessage2 = $row["intromessage2"]; |
1989 |
|
1990 |
// Cleanup |
1991 |
$course_num = textInmySQL($course_num); |
1992 |
$course_section = textInmySQL($course_section); |
1993 |
$course_concat = textInmySQL($course_concat); |
1994 |
$course_year = textInmySQL($course_year); |
1995 |
$courseheader = textInmySQL($courseheader); |
1996 |
$introheader1 = textInmySQL($introheader1); |
1997 |
$intromessage1 = textInmySQL($intromessage1); |
1998 |
$introheader2 = textInmySQL($introheader2); |
1999 |
$intromessage2 = textInmySQL($intromessage2); |
2000 |
|
2001 |
// Cleanup for null or numeric values |
2002 |
if ($coursesub_id < 1) $coursesub_id = 0; |
2003 |
if ($term_id < 1) $term_id = 0; |
2004 |
if ($campus_id < 1) $campus_id = 0; |
2005 |
|
2006 |
|
2007 |
// Create new course insert statement |
2008 |
|
2009 |
|
2010 |
$sql = "INSERT INTO course |
2011 |
(page_id, |
2012 |
coursesub_id, |
2013 |
course_num, |
2014 |
course_section, |
2015 |
course_concat, |
2016 |
term_id, |
2017 |
course_year, |
2018 |
campus_id, |
2019 |
courseheader, |
2020 |
introheader1, |
2021 |
intromessage1, |
2022 |
introheader2, |
2023 |
intromessage2) |
2024 |
VALUES ( " . |
2025 |
$new_page_id . ", " . |
2026 |
$coursesub_id . ", '" . |
2027 |
$course_num . "', '" . |
2028 |
$course_section . "', 'Copy: " . |
2029 |
$course_concat . "'," . |
2030 |
$term_id . ", '" . |
2031 |
$course_year . "', " . |
2032 |
$campus_id . ", '" . |
2033 |
$courseheader . "', '" . |
2034 |
$introheader1 . "', '" . |
2035 |
$intromessage1 . "', '" . |
2036 |
$introheader2 . "', '" . |
2037 |
$intromessage2 . "')"; |
2038 |
|
2039 |
xx_tryquery($sql); |
2040 |
|
2041 |
} // was a CourseScribe type page |
2042 |
|
2043 |
// Next, copy all elements |
2044 |
// This is not the most efficient method, but it works for now. |
2045 |
|
2046 |
|
2047 |
$sql = "SELECT * FROM element WHERE page_id = " |
2048 |
. $page_id |
2049 |
. " ORDER BY element_id"; |
2050 |
|
2051 |
$rs = xx_tryquery($sql); |
2052 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
2053 |
|
2054 |
// Fetch previous values |
2055 |
$element_id = $row["element_id"]; |
2056 |
$parent_id = $row["parent_id"]; |
2057 |
$resource_id = $row["resource_id"]; |
2058 |
$location_id = $row["location_id"]; |
2059 |
$service_id = $row["service_id"]; |
2060 |
$staff_id = $row["staff_id"]; |
2061 |
$subject_id = $row["subject_id"]; |
2062 |
$label = $row["label"]; |
2063 |
$label_url = $row["label_url"]; |
2064 |
$element_descr = $row["element_descr"]; |
2065 |
$element_size = $row["element_size"]; |
2066 |
$element_order = $row["element_order"]; |
2067 |
$indent_level = $row["indent_level"]; |
2068 |
|
2069 |
// Cleanup for null or numeric values |
2070 |
if ($parent_id < 1) $parent_id = 0; |
2071 |
if ($resource_id < 1) $resource_id = "NULL"; |
2072 |
if ($location_id < 1) $location_id = "NULL"; |
2073 |
if ($service_id < 1) $service_id = "NULL"; |
2074 |
if ($staff_id < 1 ) $staff_id = "NULL"; |
2075 |
if ($subject_id < 1 ) $subject_id = "NULL"; |
2076 |
if ($element_size < 1) $element_size = "NULL"; |
2077 |
if ($indent_level < 1) $indent_level = 0; |
2078 |
|
2079 |
// Cleanup for text values |
2080 |
if (strlen($label) > 0) $label = textInmySQL($label); |
2081 |
if (strlen($label_url) > 0) $label_url = textInmySQL($label_url); |
2082 |
if (strlen($element_descr) > 0) $element_descr = textInmySQL($element_descr); |
2083 |
|
2084 |
// Calculate the new parent if needed |
2085 |
if ($parent_id > 0) $parent_id = parentProbe($new_page_id, $element_order, $indent_level); |
2086 |
|
2087 |
// Insert the element onto the new page |
2088 |
$clone_sql = "INSERT INTO element ( |
2089 |
page_id, |
2090 |
parent_id, |
2091 |
resource_id, |
2092 |
location_id, |
2093 |
service_id, |
2094 |
staff_id, |
2095 |
subject_id, |
2096 |
label, |
2097 |
label_url, |
2098 |
element_descr, |
2099 |
element_size, |
2100 |
element_order, |
2101 |
indent_level) |
2102 |
VALUES (" . |
2103 |
$new_page_id . ", " . |
2104 |
$parent_id . ", " . |
2105 |
$resource_id . ", " . |
2106 |
$location_id . ", " . |
2107 |
$service_id . ", " . |
2108 |
$staff_id . ", " . |
2109 |
$subject_id . ", '" . |
2110 |
$label . "', '" . |
2111 |
$label_url . "', '" . |
2112 |
$element_descr . "', " . |
2113 |
$element_size . ", " . |
2114 |
$element_order . ", " . |
2115 |
$indent_level . ")"; |
2116 |
|
2117 |
// Execute the query |
2118 |
xx_tryquery($clone_sql); |
2119 |
|
2120 |
} |
2121 |
|
2122 |
header("Location: scribe.phtml?page_id=" . $new_page_id); |
2123 |
|
2124 |
} |
2125 |
|
2126 |
|
2127 |
/********************************************************** |
2128 |
Function: pageTemplateConfirm |
2129 |
Author: Paul Bramscher |
2130 |
Last Modified: 03.03.2004 |
2131 |
*********************************************************** |
2132 |
Purpose: |
2133 |
Prompts the author that he/she is about to template a |
2134 |
page. |
2135 |
**********************************************************/ |
2136 |
function pageTemplateConfirm($page_id, $sess_staff_id, $sess_staff_account){ |
2137 |
|
2138 |
// Load globals |
2139 |
include("global_vars.php"); |
2140 |
|
2141 |
// Include the page header |
2142 |
include ($GLOBAL_ADMIN_INC."scribe_header.phtml"); |
2143 |
|
2144 |
// HTML headers |
2145 |
printf("<html>\n"); |
2146 |
printf("<head>\n"); |
2147 |
printf("<title>%s: Confirm Clone & Load</title>\n", $GLOBAL_SYS_NAME); |
2148 |
printf("<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\">\n", $GLOBAL_ADMIN_CSS); |
2149 |
printf("</head>\n"); |
2150 |
|
2151 |
// Table |
2152 |
printf("<center>\n"); |
2153 |
printf("<table width = \"60%%\" border = \"1\" cellpadding =\"4\" class=\"backLight\">\n"); |
2154 |
printf("<tr><td class=\"cellPlain\">\n"); |
2155 |
printf("Confirm Clone & Load"); |
2156 |
printf("</td></tr>\n"); |
2157 |
printf("<tr><td>\n"); |
2158 |
|
2159 |
// Collect information |
2160 |
$sql = "SELECT |
2161 |
p.page_title, |
2162 |
s.first_name, |
2163 |
s.last_name, |
2164 |
s.staff_email |
2165 |
FROM |
2166 |
page p, |
2167 |
staff s |
2168 |
WHERE |
2169 |
p.page_id = " |
2170 |
. $page_id |
2171 |
. " AND p.staff_coordinator = s.staff_id"; |
2172 |
|
2173 |
$rs = xx_tryquery($sql); |
2174 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
2175 |
|
2176 |
$page_title = strip_tags($row["page_title"]); |
2177 |
$first_name = $row["first_name"]; |
2178 |
$last_name = $row["last_name"]; |
2179 |
$staff_email = $row["staff_email"]; |
2180 |
$staff_name = $first_name . " " . $last_name; |
2181 |
|
2182 |
printf("<b>Page Title: </b>%s<br>\n", $page_title); |
2183 |
printf("<b>Coordinator: </b>%s <a href=\"mailto:%s\">%s</a><br><br>\n", $staff_name, $staff_email, $staff_email); |
2184 |
printf("Before cloning this page, please consider seeking permission from and/or giving "); |
2185 |
printf("attribution to the page author(s) of the original work.<br><br>\n"); |
2186 |
|
2187 |
// Button to continue |
2188 |
printf("<form method=\"POST\" action=\"scribe_transaction.phtml\">\n"); |
2189 |
printf("<input type=\"hidden\" name =\"transaction\" value = \"pageTemplate\">\n"); |
2190 |
printf("<input type=\"hidden\" name =\"page_id\" value = \"%d\">\n", $page_id); |
2191 |
printf("<input type=\"hidden\" name =\"sess_staff_account\" value = \"%d\">\n", $sess_staff_account); |
2192 |
printf("<input type=\"hidden\" name =\"sess_staff_id\" value = \"%d\">\n", $sess_staff_id); |
2193 |
printf("<center><input type=\"submit\" value=\"Continue\"></center>\n"); |
2194 |
printf("<br><br></td></tr></table>\n"); |
2195 |
|
2196 |
// Link to return to admin console |
2197 |
adminReturn(""); |
2198 |
|
2199 |
printf("</center>\n"); |
2200 |
|
2201 |
// Include the footer |
2202 |
include ($GLOBAL_ADMIN_INC."scribe_footer.phtml"); |
2203 |
} |
2204 |
|
2205 |
|
2206 |
/********************************************************** |
2207 |
Function: parentIs |
2208 |
Author: Paul Bramscher |
2209 |
Last Modified: 03.03.2004 |
2210 |
*********************************************************** |
2211 |
Purpose: |
2212 |
Tests the supplied element to determine whether it has any |
2213 |
children. |
2214 |
**********************************************************/ |
2215 |
function parentIs($element_id, $page_id){ |
2216 |
|
2217 |
// First initialize the number of children |
2218 |
$num_children = 0; |
2219 |
|
2220 |
$sql = "SELECT COUNT(*) AS num_children FROM element where page_id = " |
2221 |
. $page_id |
2222 |
. " AND parent_id = " |
2223 |
. $element_id; |
2224 |
$rs = xx_tryquery($sql); |
2225 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
2226 |
$num_children = $row["num_children"]; |
2227 |
|
2228 |
return $num_children; |
2229 |
} |
2230 |
|
2231 |
|
2232 |
/********************************************************** |
2233 |
Function: parentProbe |
2234 |
Author: Paul Bramscher |
2235 |
Last Modified: 03.03.2004 |
2236 |
*********************************************************** |
2237 |
Purpose: |
2238 |
Probes for a parent (if not a root-level element) of the |
2239 |
supplied element order. For example, what is the parent |
2240 |
of the Nth element on page M? The parent is calculated by |
2241 |
looking for the first previous element with an indent |
2242 |
(generation) level of precisely one less. |
2243 |
**********************************************************/ |
2244 |
function parentProbe($page_id, $prev_element_order, $prev_indent_level){ |
2245 |
|
2246 |
// If the item's indent level is 0, it is its own parent. Return 0. |
2247 |
if ($prev_indent_level < 1) $parent_id = 0; |
2248 |
|
2249 |
// Otherwise, probe for the parent |
2250 |
else { |
2251 |
|
2252 |
/* Build the SQL. We know that the parent must appear earlier in the |
2253 |
list, so we limit the SQL to same or previous elements for efficiency. */ |
2254 |
|
2255 |
$sql = "SELECT * FROM element WHERE page_id = " |
2256 |
. $page_id |
2257 |
. " AND element_order < " |
2258 |
. $prev_element_order |
2259 |
. " ORDER BY element_order DESC"; |
2260 |
|
2261 |
// Found parent tag |
2262 |
$found = 0; |
2263 |
|
2264 |
$rs = xx_tryquery($sql); |
2265 |
while (($row = xx_fetch_array ($rs, xx_ASSOC)) && $found == 0) { |
2266 |
|
2267 |
/* Cycle through the list, looking for the first item with an indent |
2268 |
of less. */ |
2269 |
$element_id = $row["element_id"]; |
2270 |
$indent_level = $row["indent_level"]; |
2271 |
|
2272 |
// Probe for parent. |
2273 |
if ($indent_level == ($prev_indent_level - 1)) { |
2274 |
$parent_id = $element_id; |
2275 |
$found = 1; |
2276 |
} |
2277 |
|
2278 |
} |
2279 |
} |
2280 |
|
2281 |
// Just in case there was a problem probing |
2282 |
if ($parent_id < 1) $parent_id = 0; |
2283 |
|
2284 |
return $parent_id; |
2285 |
} |
2286 |
|
2287 |
|
2288 |
/********************************************************** |
2289 |
Function: pasteElement |
2290 |
Author: Paul Bramscher |
2291 |
Last Modified: 03.11.2004 |
2292 |
*********************************************************** |
2293 |
Purpose: |
2294 |
Copies the user's copy/paste buffer onto the supplied |
2295 |
PageScribe/CourseScribe page at the specified position. |
2296 |
This sort of logic required a fair amount of coffee to |
2297 |
work out. |
2298 |
**********************************************************/ |
2299 |
function pasteElement($element_order, $indent_level, $page_id, $position, $sess_staff_id) { |
2300 |
|
2301 |
// Debug mode: 0=off, 1=on. |
2302 |
$debug = 0; |
2303 |
|
2304 |
if ($debug == 1) { |
2305 |
printf("<h3>Element Paste - Debug Mode</h3><br>\n"); |
2306 |
printf("On page id: %d<br>\n", $page_id); |
2307 |
printf("It will go in order #%d<br>\n", $element_order); |
2308 |
printf("Afterwards you'll return to pos: %d<br>\n", $position); |
2309 |
} |
2310 |
|
2311 |
|
2312 |
// First determine number of elements in buffer |
2313 |
$sql = "SELECT COUNT(*) as buffer_size FROM pastebuffer WHERE paste_staff_id = " |
2314 |
. $sess_staff_id |
2315 |
. " ORDER BY element_order"; |
2316 |
$rs = xx_tryquery($sql); |
2317 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
2318 |
$buffer_size = $row["buffer_size"]; |
2319 |
|
2320 |
if ($debug == 1) printf("Number of elements in buffer: %s<br>\n", $buffer_size); |
2321 |
|
2322 |
|
2323 |
// Determine parent ID of first pasted element |
2324 |
$sql = "SELECT element_id from element WHERE page_id = " |
2325 |
. $page_id |
2326 |
. " AND element_order = " |
2327 |
. $element_order; |
2328 |
$rs = xx_tryquery($sql); |
2329 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
2330 |
$adjust_parent_id = $row["element_id"]; |
2331 |
|
2332 |
if ($debug == 1) printf("Parent of first element will be: %d<BR>", $adjust_parent_id); |
2333 |
|
2334 |
|
2335 |
// Next bump down all elements after the affected element |
2336 |
$sql = "UPDATE element set element_order = element_order + " |
2337 |
. $buffer_size |
2338 |
. " WHERE page_id = " |
2339 |
. $page_id |
2340 |
. " AND element_order >= " |
2341 |
. $element_order; |
2342 |
|
2343 |
if ($debug == 1) printf("bump down sql was: %s<br>\n", $sql); |
2344 |
|
2345 |
xx_tryquery($sql); |
2346 |
|
2347 |
// Select from the paste buffer |
2348 |
$sql = "SELECT * FROM pastebuffer WHERE paste_staff_id = " |
2349 |
. $sess_staff_id |
2350 |
. " ORDER BY element_order"; |
2351 |
$rs = xx_tryquery($sql); |
2352 |
|
2353 |
// row count |
2354 |
$row_num = 0; |
2355 |
|
2356 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
2357 |
|
2358 |
// Load copy-paste buffer elements |
2359 |
$copy_indent_level = $row["indent_level"]; |
2360 |
$copy_parent_id = $row["parent_id"]; |
2361 |
$copy_resource_id = $row["resource_id"]; |
2362 |
$copy_location_id = $row["location_id"]; |
2363 |
$copy_service_id = $row["service_id"]; |
2364 |
$copy_staff_id = $row["staff_id"]; |
2365 |
$copy_subject_id = $row["subject_id"]; |
2366 |
$copy_label = $row["label"]; |
2367 |
$copy_label_url = $row["label_url"]; |
2368 |
$copy_element_descr = $row["element_descr"]; |
2369 |
$copy_element_size = $row["element_size"]; |
2370 |
$copy_element_order = $row["element_order"]; |
2371 |
|
2372 |
// Initialize as necessary -- all values must be set |
2373 |
if ($copy_indent_level <1) $copy_indent_level = 0; |
2374 |
if ($copy_parent_id < 1) $copy_parent_id = 0; |
2375 |
if ($copy_resource_id < 1) $copy_resource_id = "NULL"; |
2376 |
if ($copy_location_id < 1) $copy_location_id = "NULL"; |
2377 |
if ($copy_service_id < 1) $copy_service_id = "NULL"; |
2378 |
if ($copy_subject_id < 1) $copy_subject_id = "NULL"; |
2379 |
if ($copy_staff_id < 1) $copy_staff_id = "NULL"; |
2380 |
if ($copy_element_size < 1) $copy_element_size = "NULL"; |
2381 |
if ($copy_element_order < 1) $copy_element_order = 1; |
2382 |
|
2383 |
// Clean up text type entries for insertion |
2384 |
$copy_label = textInmySQL($copy_label); |
2385 |
$copy_label_url = textInmySQL($copy_label_url); |
2386 |
$copy_element_descr = textInmySQL($copy_element_descr); |
2387 |
|
2388 |
// Determine the New W0rld 0rder |
2389 |
$adjust_element_order = $element_order + $row_num; |
2390 |
|
2391 |
/* |
2392 |
Determine relative indent level. If this is the first item, |
2393 |
it will adopt the same indent level as the incoming indent level. |
2394 |
Everything else will be relative to it. |
2395 |
*/ |
2396 |
|
2397 |
if ($row_num == 0) { |
2398 |
$adjust_indent_level = $indent_level; |
2399 |
} |
2400 |
|
2401 |
// The copied item is a child |
2402 |
else if ($copy_indent_level > $last_copy_indent_level) $adjust_indent_level = $last_adjust_indent_level + 1; |
2403 |
|
2404 |
// The copied item was older |
2405 |
else if ($copy_indent_level < $last_copy_indent_level) $adjust_indent_level = $last_adjust_indent_level - 1; |
2406 |
|
2407 |
// Else the copied item was a sibling of the last inserted item |
2408 |
else $adjust_indent_level = $last_adjust_indent_level; |
2409 |
|
2410 |
// Determine parent for all but the first item |
2411 |
$adjust_parent_id = parentProbe($page_id, $adjust_element_order, $adjust_indent_level); |
2412 |
|
2413 |
// Debugging |
2414 |
if ($debug == 1) { |
2415 |
printf("new position start indent:<br>\n"); |
2416 |
printf("last copy indent: %d, ", $last_copy_indent_level); |
2417 |
printf("this copy indent: %d<br>\n", $copy_indent_level); |
2418 |
printf("last adjust indent: %d, ", $last_adjust_indent_level); |
2419 |
printf("this adjust indent: %d<br>\n", $adjust_indent_level); |
2420 |
|
2421 |
} |
2422 |
|
2423 |
// Build the paste SQL |
2424 |
$p_sql = "INSERT INTO element ( |
2425 |
page_id, |
2426 |
indent_level, |
2427 |
parent_id, |
2428 |
resource_id, |
2429 |
location_id, |
2430 |
service_id, |
2431 |
staff_id, |
2432 |
subject_id, |
2433 |
label, |
2434 |
label_url, |
2435 |
element_descr, |
2436 |
element_size, |
2437 |
element_order) VALUES (" |
2438 |
. $page_id |
2439 |
. ", " |
2440 |
. $adjust_indent_level |
2441 |
. ", " |
2442 |
. $adjust_parent_id |
2443 |
. ", " |
2444 |
. $copy_resource_id |
2445 |
. ", " |
2446 |
. $copy_location_id |
2447 |
. ", " |
2448 |
. $copy_service_id |
2449 |
. ", " |
2450 |
. $copy_staff_id |
2451 |
. ", " |
2452 |
. $copy_subject_id |
2453 |
. ", '" |
2454 |
. $copy_label |
2455 |
. "', '" |
2456 |
. $copy_label_url |
2457 |
. "', '" |
2458 |
. $copy_element_descr |
2459 |
. "', " |
2460 |
. $copy_element_size |
2461 |
. ", " |
2462 |
. $adjust_element_order |
2463 |
. ")"; |
2464 |
|
2465 |
// Debugging |
2466 |
if ($debug == 1) printf("insert sql was: %s<br>\n", $p_sql); |
2467 |
|
2468 |
// Perform the write |
2469 |
xx_tryquery($p_sql); |
2470 |
$paste_element_id = xx_insert_id(); |
2471 |
|
2472 |
// Debugging |
2473 |
if ($debug == 1) { |
2474 |
printf("insert sql was: %s<br>\n", $p_sql); |
2475 |
printf("<b>inserted id was: %d</b><br>\n", $paste_element_id); |
2476 |
printf("<b>adjust parent was: %d</b><br>\n", $adjust_parent_id); |
2477 |
printf("<b>adjust order was: %d</b><br><br>\n", $adjust_element_order); |
2478 |
} |
2479 |
|
2480 |
// Track some variables |
2481 |
$last_copy_indent_level = $copy_indent_level; |
2482 |
$last_adjust_indent_level = $adjust_indent_level; |
2483 |
$row_num++; |
2484 |
|
2485 |
} // Done pasting all elements |
2486 |
|
2487 |
if ($debug == 0) header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
2488 |
} |
2489 |
|
2490 |
|
2491 |
/********************************************************** |
2492 |
Function: populateGenArray |
2493 |
Author: Paul Bramscher |
2494 |
Last Modified: 03.03.2004 |
2495 |
*********************************************************** |
2496 |
Purpose: |
2497 |
Builds an array from 0 (unused empty placeholder) to N, |
2498 |
where N is the number of elements on the page, ordered by |
2499 |
the element order. Each element in the array holds the |
2500 |
indent level (generation) of the page element. The array |
2501 |
is created outside the function. This function modifies |
2502 |
and returns it. |
2503 |
**********************************************************/ |
2504 |
function populateGenArray(&$genArray, $page_id) { |
2505 |
|
2506 |
// Initialize the 0th (unused) array element |
2507 |
$genArray[0] = 0; |
2508 |
|
2509 |
// Load the page element structure into the array |
2510 |
$sql = "SELECT element_order, indent_level |
2511 |
FROM element |
2512 |
WHERE page_id = " |
2513 |
. $page_id |
2514 |
. " ORDER BY element_order"; |
2515 |
$rs = xx_tryquery($sql); |
2516 |
|
2517 |
// Start populating generation array subscript [1] |
2518 |
$rowcount = 1; |
2519 |
|
2520 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
2521 |
|
2522 |
// Fetch values |
2523 |
$element_order = $row["element_order"]; |
2524 |
$indent_level = $row["indent_level"]; |
2525 |
|
2526 |
// Just in case |
2527 |
if ($indent_level < 0) $indent_level = 0; |
2528 |
if ($element_order < 0) $element_order = 0; |
2529 |
|
2530 |
array_push($genArray, $indent_level); |
2531 |
|
2532 |
$rowcount++; |
2533 |
} |
2534 |
|
2535 |
return $genArray; |
2536 |
} |
2537 |
|
2538 |
|
2539 |
/********************************************************** |
2540 |
Function: scribePublish |
2541 |
Author: Paul Bramscher |
2542 |
Last Modified: 03.11.2004 |
2543 |
*********************************************************** |
2544 |
Purpose: |
2545 |
Performs the PageScribe/CourseLib page publish functionality. |
2546 |
Note that in addition to flipping the published field in the |
2547 |
page table to 1 (TRUE), it also opens a socket to the dynamic |
2548 |
URL for the page, sucks down all page source in 4k blocks, |
2549 |
then concatenates them into the pageHTML field in the page |
2550 |
table. This creates a static snapshot of the page, which |
2551 |
requires only a single SQL to dump the entire output of the |
2552 |
page. Use that URL (displayed on the scribe.phtml authoring |
2553 |
page for published pages) if there are concerns about page load |
2554 |
performance issues with the fully dynamic version. |
2555 |
**********************************************************/ |
2556 |
function scribePublish($page_id) { |
2557 |
|
2558 |
|
2559 |
/* |
2560 |
First determine whether the current page is (a) a courselib page and |
2561 |
(b) is missing a course subject/department. If so, this page cannot |
2562 |
be published. |
2563 |
*/ |
2564 |
|
2565 |
// Initialize |
2566 |
$coursesub_id = 0; |
2567 |
$pagetype_id = 0; |
2568 |
|
2569 |
// Build the SQL |
2570 |
$sql = "SELECT |
2571 |
c.coursesub_id, |
2572 |
p.pagetype_id |
2573 |
FROM course c, page p |
2574 |
WHERE p.page_id = " |
2575 |
. $page_id |
2576 |
. " AND p.page_id = c.page_id"; |
2577 |
|
2578 |
// printf("sql was: %s", $sql); |
2579 |
|
2580 |
$rs = xx_tryquery($sql); |
2581 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
2582 |
$coursesub_id = $row["coursesub_id"]; |
2583 |
$pagetype_id = $row["pagetype_id"]; |
2584 |
|
2585 |
// This was a courselib page missing a course/department subject |
2586 |
// Note that coursesub_id of 1 = N/A, so we don't want this value either. |
2587 |
if ($coursesub_id < 2 && $pagetype_id == 3) { |
2588 |
|
2589 |
// Load globals |
2590 |
include("global_vars.php"); |
2591 |
|
2592 |
// Include the page header |
2593 |
include ($GLOBAL_ADMIN_INC."scribe_header.phtml"); |
2594 |
|
2595 |
// HTML headers |
2596 |
printf("<html>\n"); |
2597 |
printf("<head>\n"); |
2598 |
printf("<title>%s: Missing Information</title>\n", $GLOBAL_SYS_NAME); |
2599 |
printf("<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\">\n", $GLOBAL_ADMIN_CSS); |
2600 |
printf("</head>\n"); |
2601 |
|
2602 |
// Draw form heading |
2603 |
printf("<center><h3>%s: Missing Information</h3>\n", $GLOBAL_SYS_NAME); |
2604 |
|
2605 |
// Table |
2606 |
printf("<table width = \"60%%\" border = \"1\" cellpadding =\"4\" class=\"backLight\">\n"); |
2607 |
printf("<tr><td>\n"); |
2608 |
printf("<b>Messages:</b><br>\n"); |
2609 |
printf("CourseLib pages may not be published without a course designator. "); |
2610 |
printf("This is a required field -- please go back and select a course designator. "); |
2611 |
printf("If one does not apply, this should probably be a PageScribe page instead.<br><br>\n"); |
2612 |
|
2613 |
printf("</td></tr></table>\n"); |
2614 |
|
2615 |
|
2616 |
// Link to return to admin console |
2617 |
adminReturn(""); |
2618 |
|
2619 |
printf("</center>\n"); |
2620 |
|
2621 |
// Include the footer |
2622 |
include ($GLOBAL_ADMIN_INC."scribe_footer.phtml"); |
2623 |
} |
2624 |
|
2625 |
// Page may be published |
2626 |
else { |
2627 |
|
2628 |
/* |
2629 |
Uncomment this portion if the static page functionality is desired. |
2630 |
PFB: 06-23-2003 |
2631 |
|
2632 |
// Load globals |
2633 |
include ("global_vars.php"); |
2634 |
|
2635 |
// Test URL to snapshot |
2636 |
$page_loc = $GLOBAL_SCRIBE_URL . "page.phtml?page_id=" . $page_id; |
2637 |
|
2638 |
// Clear out existing published information |
2639 |
// This is important, also, to get rid of a NULL value before performing a CONCAT below. |
2640 |
$sql = "UPDATE page set pageHTML = '' WHERE page_id = " . $page_id; |
2641 |
xx_tryquery($sql); |
2642 |
|
2643 |
// Open the filepointer for a screen dump |
2644 |
$fp = fopen ($page_loc, "r"); |
2645 |
|
2646 |
// Open failed |
2647 |
if (!$fp) { |
2648 |
echo "$errstr ($errno)<br>\n"; |
2649 |
} |
2650 |
// Continue as long as there's data |
2651 |
else { |
2652 |
fputs ($fp, "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", $page_loc); |
2653 |
while (!feof($fp)) { |
2654 |
|
2655 |
// Fetch the stream |
2656 |
$iostream = fgets ($fp,4096); |
2657 |
|
2658 |
// Replace single quotes with two single quotes |
2659 |
$iostream_fix = ereg_replace("'","''",$iostream); |
2660 |
|
2661 |
// Concatenate the stream into the pageHTML field |
2662 |
$sql = "UPDATE page set pageHTML = CONCAT(pageHTML,'" . $iostream_fix . "') WHERE page_id = " . $page_id; |
2663 |
xx_tryquery($sql); |
2664 |
} |
2665 |
|
2666 |
// Close up the open file pointer |
2667 |
fclose ($fp); |
2668 |
|
2669 |
// Set published flag to 1 |
2670 |
$sql = "UPDATE page set published = '1' WHERE page_id = " . $page_id; |
2671 |
xx_tryquery($sql); |
2672 |
|
2673 |
} // end open file pointer |
2674 |
|
2675 |
end of comment-out */ |
2676 |
|
2677 |
/********************************************************************* |
2678 |
** Comment out this portion if static page functionality is desired ** |
2679 |
*********************************************************************/ |
2680 |
|
2681 |
// Set published flag to 1 |
2682 |
$sql = "UPDATE page set published = '1' WHERE page_id = " . $page_id; |
2683 |
xx_tryquery($sql); |
2684 |
|
2685 |
/*********************** |
2686 |
** End of comment-out ** |
2687 |
***********************/ |
2688 |
|
2689 |
header("Location: scribe.phtml?page_id=" . $page_id); |
2690 |
|
2691 |
} |
2692 |
|
2693 |
} // end function |
2694 |
|
2695 |
|
2696 |
/********************************************************** |
2697 |
Function: scribeUnpublish |
2698 |
Author: Paul Bramscher |
2699 |
Last Modified: 03.03.2004 |
2700 |
*********************************************************** |
2701 |
Purpose: |
2702 |
Unpublishes the supplied page id. Note that we set both |
2703 |
the pageHTML to NULL and flip the published flag back to |
2704 |
0 (FALSE). |
2705 |
**********************************************************/ |
2706 |
function scribeUnpublish($page_id) { |
2707 |
|
2708 |
// Build the SQL |
2709 |
$sql = "UPDATE page SET pageHTML = NULL, published = '0' WHERE page_id =" . $page_id; |
2710 |
xx_tryquery($sql); |
2711 |
|
2712 |
header("Location: scribe.phtml?page_id=" . $page_id); |
2713 |
} |
2714 |
|
2715 |
|
2716 |
/********************************************************** |
2717 |
Function: sibProbeElder |
2718 |
Author: Paul Bramscher |
2719 |
Last Modified: 06.30.2003 |
2720 |
*********************************************************** |
2721 |
Purpose: |
2722 |
Probes the generational array for an elder sibling. If |
2723 |
found, the function returns TRUE (1). Note that there is |
2724 |
an optimizing exit condition, namely that if the probed |
2725 |
element's indent level is less than the current indent |
2726 |
level, we've already reached a parent and thus quit |
2727 |
probing early. |
2728 |
**********************************************************/ |
2729 |
function sibProbeElder($genArray, $page_id, $place_array){ |
2730 |
|
2731 |
// Break apart place array |
2732 |
$element_id = $place_array[0]; |
2733 |
$element_order = $place_array[1]; |
2734 |
$indent_level = $place_array[2]; |
2735 |
//$parent_id = $place_array[3]; |
2736 |
//$position = $place_array[4]; |
2737 |
|
2738 |
// Initialize finding an elder sibling to FALSE |
2739 |
$elder = 0; |
2740 |
|
2741 |
if ($element_order > 1) { |
2742 |
|
2743 |
// Initialize more things |
2744 |
$probe = $element_order - 1; |
2745 |
$continue = 1; |
2746 |
|
2747 |
while ($elder == 0 && $continue == 1 && $probe >= 1) { |
2748 |
|
2749 |
if ($genArray[$probe] == $indent_level) $elder = 1; |
2750 |
else if ($genArray[$probe] < $indent_level) $continue = 0; |
2751 |
|
2752 |
$probe--; |
2753 |
} |
2754 |
} |
2755 |
|
2756 |
return $elder; |
2757 |
} |
2758 |
|
2759 |
|
2760 |
/********************************************************** |
2761 |
Function: sibProbeYounger |
2762 |
Author: Paul Bramscher |
2763 |
Last Modified: 06.30.2003 |
2764 |
*********************************************************** |
2765 |
Purpose: |
2766 |
Probes the generational array for a younger sibling. If |
2767 |
found, the function returns TRUE (1). Note that there is |
2768 |
an optimizing exit condition, namely that if the probed |
2769 |
element's indent level is less than the current indent |
2770 |
level, we've already reached a parent (of a separate nuclear |
2771 |
family) and thus quit probing early. |
2772 |
**********************************************************/ |
2773 |
function sibProbeYounger($genArray, $page_id, $place_array){ |
2774 |
|
2775 |
// Break apart place array |
2776 |
$element_id = $place_array[0]; |
2777 |
$element_order = $place_array[1]; |
2778 |
$indent_level = $place_array[2]; |
2779 |
//$parent_id = $place_array[3]; |
2780 |
//$position = $place_array[4]; |
2781 |
|
2782 |
// Initialize finding a younger sibling to FALSE |
2783 |
$younger = 0; |
2784 |
|
2785 |
if ($element_order < sizeof($genArray)) { |
2786 |
|
2787 |
// Initialize more things |
2788 |
$probe = $element_order + 1; |
2789 |
$continue = 1; |
2790 |
|
2791 |
while ($younger == 0 && $continue == 1 && $probe <= sizeof($genArray)) { |
2792 |
|
2793 |
if ($genArray[$probe] == $indent_level) $younger = 1; |
2794 |
else if ($genArray[$probe] < $indent_level) $continue = 0; |
2795 |
|
2796 |
$probe++; |
2797 |
} |
2798 |
} |
2799 |
|
2800 |
return $younger; |
2801 |
} |
2802 |
|
2803 |
|
2804 |
/********************************************************** |
2805 |
Function: toggleTOCDisplay |
2806 |
Author: Paul Bramscher |
2807 |
Last Modified: 03.03.2004 |
2808 |
*********************************************************** |
2809 |
Purpose: |
2810 |
Flips the flag to 1 (TRUE) or 0 (FALSE) for the display |
2811 |
of the PageScribe/CourseLib table of contents. This |
2812 |
ToC is autogenerated and includes the root elements on the |
2813 |
page. |
2814 |
**********************************************************/ |
2815 |
function toggleTOCDisplay($display_toc, $page_id) { |
2816 |
|
2817 |
$sql = "UPDATE page SET display_toc = " |
2818 |
. $display_toc |
2819 |
. " WHERE page_id = " |
2820 |
. $page_id; |
2821 |
xx_tryquery($sql); |
2822 |
|
2823 |
// Call the PageScribe page back |
2824 |
header("Location: scribe.phtml?page_id=" . $page_id); |
2825 |
} |
2826 |
|
2827 |
|
2828 |
/********************************************************** |
2829 |
Function: toggleTOCWrap |
2830 |
Author: Paul Bramscher |
2831 |
Last Modified: 03.03.2004 |
2832 |
*********************************************************** |
2833 |
Purpose: |
2834 |
Flips the flag to 1 (TRUE) or 0 (FALSE) for the wrapping |
2835 |
of the PageScribe/CourseLib table of contents. This |
2836 |
ToC is autogenerated and includes the root elements on the |
2837 |
page. The wrap results in a two-column view of the ToC. |
2838 |
**********************************************************/ |
2839 |
function toggleTOCWrap($page_id, $wrap_toc) { |
2840 |
|
2841 |
$sql = "UPDATE page SET wrap_toc = " |
2842 |
. $wrap_toc |
2843 |
. " WHERE page_id = " |
2844 |
. $page_id; |
2845 |
xx_tryquery($sql); |
2846 |
|
2847 |
// Call the PageScribe page back |
2848 |
header("Location: scribe.phtml?page_id=" . $page_id); |
2849 |
} |
2850 |
|
2851 |
|
2852 |
/********************************************************** |
2853 |
Function: toggleUpDisplay |
2854 |
Author: Paul Bramscher |
2855 |
Last Modified: 03.03.2004 |
2856 |
*********************************************************** |
2857 |
Purpose: |
2858 |
Toggles the display of the [return to top] text on the |
2859 |
supplied page id before each new root element. If there |
2860 |
is currently no value in the up_text field (i.e. the user |
2861 |
has never saved anything previously), then this function |
2862 |
will also insert a preliminary value as passed from the |
2863 |
default string setting on the scribe authoring page. |
2864 |
**********************************************************/ |
2865 |
function toggleUpDisplay($display_up, $page_id, $up_text) { |
2866 |
|
2867 |
// Collect some data on the current up text |
2868 |
$current_up_text = lookupField("page", "page_id", $page_id, "up_text"); |
2869 |
|
2870 |
// Toggle the flag to TRUE or FALSE |
2871 |
$sql = "UPDATE page SET display_up = " |
2872 |
. $display_up |
2873 |
. " WHERE page_id = " |
2874 |
. $page_id; |
2875 |
xx_tryquery($sql); |
2876 |
|
2877 |
/* If the current up_text is blank, and the user has |
2878 |
toggled ON, then insert the default wording. */ |
2879 |
if ($display_up == 1 && strlen($current_up_text) < 1) { |
2880 |
$sql = "UPDATE page SET up_text = '" |
2881 |
. $up_text |
2882 |
. "' WHERE page_id = " |
2883 |
. $page_id; |
2884 |
xx_tryquery($sql); |
2885 |
} |
2886 |
|
2887 |
// Call the PageScribe page back |
2888 |
header("Location: scribe.phtml?page_id=" . $page_id); |
2889 |
} |
2890 |
|
2891 |
|
2892 |
/********************************************************** |
2893 |
Function: toggleUpText |
2894 |
Author: Paul Bramscher |
2895 |
Last Modified: 03.03.2004 |
2896 |
*********************************************************** |
2897 |
Purpose: |
2898 |
Changes the [return to top] text for the supplied page id, |
2899 |
on a given page id before each new root element. |
2900 |
**********************************************************/ |
2901 |
function toggleUpText($page_id, $up_text) { |
2902 |
|
2903 |
// Clean the string |
2904 |
$up_text = textInmySQL($up_text); |
2905 |
|
2906 |
// Make the change |
2907 |
$sql = "UPDATE page SET up_text = '" |
2908 |
. $up_text |
2909 |
. "' WHERE page_id = " |
2910 |
. $page_id; |
2911 |
xx_tryquery($sql); |
2912 |
|
2913 |
// Call the PageScribe page back |
2914 |
header("Location: scribe.phtml?page_id=" . $page_id); |
2915 |
} |
2916 |
|
2917 |
|
2918 |
/********************************************************** |
2919 |
Function: toggleURLDisplay |
2920 |
Author: Paul Bramscher |
2921 |
Last Modified: 03.03.2004 |
2922 |
*********************************************************** |
2923 |
Purpose: |
2924 |
This function updates the display_urls field in the |
2925 |
page table. When set to 1 (TRUE), URL's are diplayed |
2926 |
during the PageScribe edit mode. |
2927 |
|
2928 |
Previously, we used this flag to create pages for which the |
2929 |
URL's ought to be displayed or surpressed to the user |
2930 |
(not merely the page author). However, with the creation |
2931 |
of the "printer friendly version" of a page, which |
2932 |
automatically displays URL's, the utility here is lessened. |
2933 |
Still, it might be useful for an author to see his/her |
2934 |
URL's in edit mode for a quick visual inspection without |
2935 |
having to resort to the user interface. |
2936 |
**********************************************************/ |
2937 |
function toggleURLDisplay($display_urls, $page_id) { |
2938 |
|
2939 |
// Build the SQL |
2940 |
$sql = "UPDATE page SET display_urls = " |
2941 |
. $display_urls |
2942 |
. " WHERE page_id = " |
2943 |
. $page_id; |
2944 |
xx_tryquery($sql); |
2945 |
|
2946 |
// Call the PageScribe page back |
2947 |
header("Location: scribe.phtml?page_id=" . $page_id); |
2948 |
} |
2949 |
|
2950 |
/********************************************************** |
2951 |
Function: updatePageDebug |
2952 |
Author: Paul Bramscher |
2953 |
Last Modified: 03.03.2004 |
2954 |
*********************************************************** |
2955 |
Purpose: |
2956 |
Updates the flag for page debug to 1 (TRUE) or 0 (FALSE). |
2957 |
|
2958 |
Notes: This is not currently used. Potentially we could |
2959 |
utilize this flag when TRUE, to run the debugger every |
2960 |
time a page is loaded. |
2961 |
**********************************************************/ |
2962 |
function updatePageDebug($page_debug, $page_id) { |
2963 |
|
2964 |
$sql = "UPDATE page SET page_debug = " |
2965 |
. $page_debug |
2966 |
. " WHERE page_id = " |
2967 |
. $page_id; |
2968 |
xx_tryquery($sql); |
2969 |
|
2970 |
// Call the PageScribe page back |
2971 |
header("Location: scribe.phtml?page_id=" . $page_id); |
2972 |
} |
2973 |
|
2974 |
|
2975 |
/********************************************************** |
2976 |
Function: updatePageHeader |
2977 |
Author: Paul Bramscher |
2978 |
Last Modified: 03.03.2004 |
2979 |
*********************************************************** |
2980 |
Purpose: |
2981 |
Updates the supplied page id's pageheader |
2982 |
**********************************************************/ |
2983 |
function updatePageHeader($page_id, $pageheader) { |
2984 |
|
2985 |
// Clean up |
2986 |
if (strlen($pageheader) > 0) $pageheader = textInmySQL($pageheader); |
2987 |
|
2988 |
$sql = "UPDATE page SET pageheader = '" |
2989 |
. $pageheader |
2990 |
. "' WHERE page_id = " |
2991 |
. $page_id; |
2992 |
xx_tryquery($sql); |
2993 |
|
2994 |
// Call the PageScribe page back |
2995 |
header("Location: scribe.phtml?page_id=" . $page_id); |
2996 |
} |
2997 |
|
2998 |
|
2999 |
/********************************************************** |
3000 |
Function: updatePageTitleStyle |
3001 |
Author: Paul Bramscher |
3002 |
Last Modified: 03.03.2004 |
3003 |
*********************************************************** |
3004 |
Purpose: |
3005 |
Updates the style class for the supplied page_id |
3006 |
**********************************************************/ |
3007 |
function updatePageTitleStyle($page_id, $pagetitle_style) { |
3008 |
|
3009 |
$sql = "UPDATE page SET pagetitle_style = " |
3010 |
. $pagetitle_style |
3011 |
. " WHERE page_id = " |
3012 |
. $page_id; |
3013 |
xx_tryquery($sql); |
3014 |
|
3015 |
// Call the PageScribe page back |
3016 |
header("Location: scribe.phtml?page_id=" . $page_id); |
3017 |
} |
3018 |
|
3019 |
|
3020 |
/********************************************************** |
3021 |
Function: updateScribeCourse |
3022 |
Author: Paul Bramscher |
3023 |
Last Modified: 03.03.2004 |
3024 |
*********************************************************** |
3025 |
Purpose: |
3026 |
Updates the supplied field and value for the course id. |
3027 |
The concatenated course title is also updated, in case |
3028 |
there were modifications which affect the title |
3029 |
(subject, designator, or section). |
3030 |
**********************************************************/ |
3031 |
function updateScribeCourse($course_id, $field_name, $field_value, $page_id) { |
3032 |
|
3033 |
// Clean up for entry |
3034 |
if (strlen($field_value) > 0) $field_value = textInmySQL($field_value); |
3035 |
|
3036 |
// Determine whether this is an existing course or a new one |
3037 |
if ($course_id > 0) { |
3038 |
|
3039 |
// Build the SQL. Key on both course_id and page_id for safety sake. |
3040 |
$sql = "UPDATE course SET " |
3041 |
. $field_name |
3042 |
. " = '" |
3043 |
. $field_value |
3044 |
. "' WHERE course_id = " |
3045 |
. $course_id |
3046 |
. " AND page_id = " |
3047 |
. $page_id; |
3048 |
xx_tryquery($sql); |
3049 |
|
3050 |
|
3051 |
} |
3052 |
|
3053 |
// New course |
3054 |
else { |
3055 |
$sql = "INSERT INTO course ('" |
3056 |
. $field_name |
3057 |
. "', page_id) VALUES ('" |
3058 |
. $field_value |
3059 |
. "', " |
3060 |
. $page_id |
3061 |
. ")"; |
3062 |
|
3063 |
xx_tryquery($sql); |
3064 |
$course_id = xx_insert_id(); |
3065 |
|
3066 |
} |
3067 |
updateScribeCourseConcat($course_id, $page_id); |
3068 |
} |
3069 |
|
3070 |
/********************************************************** |
3071 |
Function: updateScribeCourseConcat |
3072 |
Author: Paul Bramscher |
3073 |
Last Modified: 03.03.2004 |
3074 |
*********************************************************** |
3075 |
Purpose: |
3076 |
This function updates a CourseLib course title of the |
3077 |
supplied page id and course id. This course title is a |
3078 |
concatenation of the course subject + designator + |
3079 |
section (if provided). This was done because there was a |
3080 |
problem in sorting multiple fields with our version of |
3081 |
mySQL. We needed to present a completely ordered list of |
3082 |
courses -- not merely by course subject. |
3083 |
**********************************************************/ |
3084 |
function updateScribeCourseConcat($course_id, $page_id) { |
3085 |
|
3086 |
// Fetch course related information |
3087 |
$sql = "SELECT |
3088 |
p.page_title, |
3089 |
c.course_num, |
3090 |
c.course_section, |
3091 |
s.coursesub_id, |
3092 |
s.coursesub |
3093 |
FROM |
3094 |
course c |
3095 |
LEFT JOIN page p using (page_id) |
3096 |
LEFT JOIN coursesub s on c.coursesub_id = s.coursesub_id |
3097 |
|
3098 |
WHERE |
3099 |
course_id = " . $course_id; |
3100 |
|
3101 |
$rs = xx_tryquery($sql); |
3102 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
3103 |
|
3104 |
$page_title = $row["page_title"]; |
3105 |
$coursesub_id = $row["coursesub_id"]; |
3106 |
$coursesub = $row["coursesub"]; |
3107 |
$course_num = $row["course_num"]; |
3108 |
$course_section = $row["course_section"]; |
3109 |
|
3110 |
// Initialize |
3111 |
$course_concat = ""; |
3112 |
|
3113 |
// So long as the course subject is not N/A |
3114 |
// if ($coursesub_id > 1) $course_concat = $coursesub . " "; |
3115 |
if ($coursesub_id > 1) $course_concat = $coursesub; |
3116 |
|
3117 |
//if (strlen($course_num) > 1) $course_concat = $course_concat . $course_num . " "; |
3118 |
//$course_concat = $course_concat . $page_title . " "; |
3119 |
|
3120 |
if (strlen($course_num) > 1) $course_concat = $course_concat . " " . $course_num . ": "; |
3121 |
else $course_concat = $course_concat . " "; |
3122 |
$course_concat = $course_concat . $page_title . " "; |
3123 |
|
3124 |
if (strlen($course_section) > 1) $course_concat = $course_concat . $course_section . " "; |
3125 |
|
3126 |
// Clean up |
3127 |
$course_concat = textInmySQL($course_concat); |
3128 |
|
3129 |
// Update the concatenated title into the course table |
3130 |
$sql = "UPDATE course SET course_concat = '" |
3131 |
. $course_concat |
3132 |
. "' WHERE course_id = " |
3133 |
. $course_id; |
3134 |
xx_tryquery($sql); |
3135 |
|
3136 |
header("Location: scribe.phtml?page_id=" . $page_id); |
3137 |
|
3138 |
} |
3139 |
|
3140 |
/********************************************************** |
3141 |
Function: updateScribeElement |
3142 |
Author: Paul Bramscher |
3143 |
Last Modified: 03.03.2004 |
3144 |
*********************************************************** |
3145 |
Purpose: |
3146 |
Updates a PageScribe element. This function handles the |
3147 |
updating of text or label type elements, their url's and |
3148 |
descriptions -- as well as customized descriptions for |
3149 |
any other element type. |
3150 |
**********************************************************/ |
3151 |
function updateScribeElement($element_descr, |
3152 |
$element_id, $label, $label_flag, $label_url, $page_id, $position) { |
3153 |
|
3154 |
// Problem flagging |
3155 |
$problem = 0; |
3156 |
|
3157 |
// Clean up strings |
3158 |
if (strlen($element_descr) > 0) $element_descr = textInmySQL($element_descr); |
3159 |
if (strlen($label) > 0) $label = textInmySQL($label); |
3160 |
if (strlen($label_url) > 0) $label_url = textInmySQL($label_url); |
3161 |
|
3162 |
// Protection against no url supplied |
3163 |
if ($label_url == "http://") $label_url = ""; |
3164 |
|
3165 |
/* |
3166 |
Protection against a blank label. If this element type is a label, some text |
3167 |
must be supplied. |
3168 |
*/ |
3169 |
|
3170 |
if ($label_flag == 1 && strlen($label) < 1) { |
3171 |
$problem = 1; |
3172 |
printf("Error. You must provide a text label if you wish it to be on the page.<br>\n"); |
3173 |
} |
3174 |
|
3175 |
|
3176 |
// If no problems |
3177 |
if ($problem == 0) { |
3178 |
|
3179 |
/* |
3180 |
First handle text-label type elements. It is assumed they |
3181 |
are all non-default descriptions. |
3182 |
*/ |
3183 |
|
3184 |
if ($label_flag == 1) { |
3185 |
// Build the SQL |
3186 |
$sql = "UPDATE element SET element_descr = '" |
3187 |
. $element_descr |
3188 |
. "', label = '" |
3189 |
. $label |
3190 |
. "', label_url = '" |
3191 |
. $label_url |
3192 |
. "' WHERE page_id =" |
3193 |
. $page_id |
3194 |
. " AND element_id = " |
3195 |
. $element_id; |
3196 |
xx_tryquery($sql); |
3197 |
|
3198 |
|
3199 |
} |
3200 |
|
3201 |
/* |
3202 |
This is a non- text-label element, and the user changed the default description. |
3203 |
*/ |
3204 |
|
3205 |
else if ($label_flag == 0 && strlen($element_descr) > 0) { |
3206 |
|
3207 |
// Build the SQL |
3208 |
$sql = "UPDATE element SET element_descr = '" |
3209 |
. $element_descr |
3210 |
. "' WHERE page_id =" |
3211 |
. $page_id |
3212 |
. " AND element_id = " |
3213 |
. $element_id; |
3214 |
xx_tryquery($sql); |
3215 |
|
3216 |
} |
3217 |
|
3218 |
/* |
3219 |
This is a non- text-label element. The user cleared everything out. |
3220 |
Dump the unique description. By doing this, the page-rendering interfaces |
3221 |
will revert to the default description for the element. |
3222 |
*/ |
3223 |
|
3224 |
else if ($label_flag == 0 && strlen($element_descr) == 0) { |
3225 |
|
3226 |
// Build the SQL |
3227 |
$sql = "UPDATE element SET element_descr = NULL WHERE page_id = " |
3228 |
. $page_id |
3229 |
. " AND element_id = " |
3230 |
. $element_id; |
3231 |
xx_tryquery($sql); |
3232 |
|
3233 |
} |
3234 |
|
3235 |
header("Location: scribe.phtml?page_id=" . $page_id . "#p" . $position); |
3236 |
|
3237 |
} // no problems |
3238 |
|
3239 |
} |
3240 |
|
3241 |
|
3242 |
/********************************************************** |
3243 |
Function: updateScribeHeader |
3244 |
Author: Paul Bramscher |
3245 |
Last Modified: 03.03.2004 |
3246 |
*********************************************************** |
3247 |
Purpose: |
3248 |
Updates the page title for the supplied page id. |
3249 |
**********************************************************/ |
3250 |
function updateScribeHeader($course_id, $page_id, $page_title, $pagetype_id) { |
3251 |
|
3252 |
// Clean up strings |
3253 |
$page_title = textInmySQL($page_title); |
3254 |
|
3255 |
// Build the SQL |
3256 |
$sql = "UPDATE page SET page_title = '" |
3257 |
. $page_title |
3258 |
. "' WHERE page_id =" |
3259 |
. $page_id; |
3260 |
xx_tryquery($sql); |
3261 |
|
3262 |
// Update the concatenated course title if this is a course page |
3263 |
if ($pagetype_id == 3) updateScribeCourseConcat($course_id, $page_id); |
3264 |
|
3265 |
header("Location: scribe.phtml?page_id=" . $page_id); |
3266 |
|
3267 |
} |
3268 |
|
3269 |
|
3270 |
/********************************************************** |
3271 |
Function: updateScribeStyle |
3272 |
Author: Paul Bramscher |
3273 |
Last Modified: 03.03.2004 |
3274 |
*********************************************************** |
3275 |
Purpose: |
3276 |
Changes the style definition for the supplied page id. |
3277 |
**********************************************************/ |
3278 |
function updateScribeStyle($page_id, $style_id) { |
3279 |
|
3280 |
// Build the SQL |
3281 |
$sql = "UPDATE page SET style_id = " |
3282 |
. $style_id |
3283 |
. " WHERE page_id =" |
3284 |
. $page_id; |
3285 |
xx_tryquery($sql); |
3286 |
|
3287 |
header("Location: scribe.phtml?page_id=" . $page_id); |
3288 |
} |
3289 |
|
3290 |
|
3291 |
/********************************************************** |
3292 |
Function: updateScribeUpdate |
3293 |
Author: Paul Bramscher |
3294 |
Last Modified: 03.03.2004 |
3295 |
*********************************************************** |
3296 |
Purpose: |
3297 |
Modifies the PageScribe/CourseLib page "last updated" |
3298 |
field. |
3299 |
**********************************************************/ |
3300 |
function updateScribeUpdate($page_id, $sess_staff_account) { |
3301 |
|
3302 |
$sql = "UPDATE page SET date_modified = now(), account_modified ='" |
3303 |
. $sess_staff_account |
3304 |
. "' WHERE page_id = " |
3305 |
. $page_id; |
3306 |
xx_tryquery($sql); |
3307 |
} |
3308 |
|
3309 |
|
3310 |
/********************************************************** |
3311 |
Function: youngerProbe |
3312 |
Author: Paul Bramscher |
3313 |
Last Modified: 10.29.2002 |
3314 |
*********************************************************** |
3315 |
Incoming: |
3316 |
$page_id ID of the page involved |
3317 |
$place_array Variables related to the last element |
3318 |
displayed. |
3319 |
$rs Record set with cursor position. |
3320 |
*********************************************************** |
3321 |
Outgoing: |
3322 |
$younger Returns 0 if next element is not |
3323 |
younger, 1 if it is. |
3324 |
*********************************************************** |
3325 |
Purpose: |
3326 |
Starts out with the cursor pointing at the next element in |
3327 |
the recordset. Examines the value of its indent level and |
3328 |
determines whether it is older or younger than the previous |
3329 |
element. If younger, it returns a 1. If not, returns a 0. |
3330 |
|
3331 |
Note that we need some range checking. $element_order |
3332 |
represents the order 1 to N of the elements on a page, |
3333 |
whereas the cursor sits at positions 0 to (N - 1). Thus, |
3334 |
we need to make sure we never check beyond the limit of |
3335 |
the number of rows. After the check, we need to move the |
3336 |
cursor back to $element_order - 1. This would correspond to |
3337 |
the cursor row it was originally sitting at coming into the |
3338 |
function. |
3339 |
**********************************************************/ |
3340 |
function youngerProbe($page_id, $place_array, $rs){ |
3341 |
|
3342 |
// Break apart place array |
3343 |
$element_id = $place_array[0]; |
3344 |
$element_order = $place_array[1]; |
3345 |
$indent_level = $place_array[2]; |
3346 |
//$parent_id = $place_array[3]; |
3347 |
//$position = $place_array[4]; |
3348 |
|
3349 |
// Younger found |
3350 |
$younger = 0; |
3351 |
|
3352 |
if ($element_order <= xx_num_rows($rs)) { |
3353 |
|
3354 |
$row = xx_fetch_array ($rs); |
3355 |
$probe_indent_level = $row["indent_level"]; |
3356 |
$probe_element_id = $row["element_id"]; |
3357 |
|
3358 |
/* |
3359 |
printf("<BR>this element: %d, this indent: %d<BR>", $element_id, $indent_level); |
3360 |
printf("probed element: %d, probed indent: %d<BR>", $probe_element_id, $probe_indent_level); |
3361 |
printf("order was: %d<br>", $element_order); |
3362 |
*/ |
3363 |
|
3364 |
if ($probe_indent_level > $indent_level) $younger = 1; |
3365 |
if ($element_order <= xx_num_rows($rs)) xx_data_seek($rs, $element_order - 1); |
3366 |
|
3367 |
} |
3368 |
|
3369 |
return $younger; |
3370 |
|
3371 |
} |
3372 |
?> |