1 |
dpavlin |
1 |
<?php |
2 |
|
|
/********************************************************** |
3 |
|
|
Function Library: subject_builder.php |
4 |
|
|
Original Author: Paul Bramscher <brams006@tc.umn.edu> |
5 |
|
|
Last Modified: 11.04.2003 |
6 |
|
|
*********************************************************** |
7 |
|
|
Comments: |
8 |
|
|
This small library brings together basic functionality to |
9 |
|
|
delete, insert, and update RQS subject pages. Note that all |
10 |
|
|
of the function involve a header redirect back to the |
11 |
|
|
authoring environment of RQS. |
12 |
|
|
*********************************************************** |
13 |
|
|
Table of Contents: |
14 |
|
|
assignSubOtherSub |
15 |
|
|
assignSubPage |
16 |
|
|
deleteSubjectBuilder |
17 |
|
|
deleteSubOtherSub |
18 |
|
|
deleteSubPage |
19 |
|
|
insertSubjectBuilder |
20 |
|
|
rqsPublish |
21 |
|
|
rqsUnpublish |
22 |
|
|
updateRQSUpdate |
23 |
|
|
updateSubjectBuilder |
24 |
|
|
**********************************************************/ |
25 |
|
|
|
26 |
|
|
|
27 |
|
|
/********************************************************** |
28 |
|
|
Function: assignSubOtherSub |
29 |
|
|
Author: Paul Bramscher |
30 |
|
|
Last Modified: 11.04.2003 |
31 |
|
|
*********************************************************** |
32 |
|
|
Purpose: |
33 |
|
|
Assigns other RQS pages (possibly multiple) to a given |
34 |
|
|
subject and calls formSubject back again. |
35 |
|
|
**********************************************************/ |
36 |
|
|
function assignSubOtherSub($con, $subject_id_array, $subject_id) { |
37 |
|
|
|
38 |
|
|
// For every subject, assign it to the selected subject |
39 |
|
|
for ($subscript = 0; $subscript < sizeof($subject_id_array); $subscript++ ) { |
40 |
|
|
|
41 |
|
|
// Check to make sure that the page isn't already assigned |
42 |
|
|
$sql = "SELECT * FROM sub_othersub WHERE subject_id = " |
43 |
|
|
. $subject_id |
44 |
|
|
. " AND othersub_id = " |
45 |
|
|
. $subject_id_array[$subscript]; |
46 |
|
|
|
47 |
dpavlin |
42 |
$rs = xx_query($sql); |
48 |
|
|
if (xx_num_rows($rs) == 0) { |
49 |
dpavlin |
1 |
|
50 |
|
|
$sql = "INSERT INTO sub_othersub (subject_id, othersub_id) VALUES (" |
51 |
|
|
. $subject_id |
52 |
|
|
. ", " |
53 |
|
|
. $subject_id_array[$subscript] |
54 |
|
|
. ")"; |
55 |
|
|
|
56 |
dpavlin |
42 |
if (!xx_query($sql, $con)){ |
57 |
dpavlin |
1 |
sql_err($con); |
58 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
59 |
dpavlin |
1 |
bailout(); |
60 |
|
|
} // bad write |
61 |
|
|
else { |
62 |
dpavlin |
42 |
xx_query("UNLOCK TABLES", $con); |
63 |
dpavlin |
1 |
|
64 |
|
|
} // good write of sub_othersub |
65 |
|
|
|
66 |
|
|
} // other subject not already assigned |
67 |
|
|
|
68 |
|
|
} // array of subject id's |
69 |
|
|
|
70 |
|
|
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
71 |
|
|
|
72 |
|
|
} // function |
73 |
|
|
|
74 |
|
|
|
75 |
|
|
/********************************************************** |
76 |
|
|
Function: assignSubPage |
77 |
|
|
Author: Paul Bramscher |
78 |
|
|
Last Modified: 06.17.2003 |
79 |
|
|
*********************************************************** |
80 |
|
|
Purpose: |
81 |
|
|
Assigns PageScribe pages (possibly multiple) to a given |
82 |
|
|
subject and calls formSubject back again. |
83 |
|
|
**********************************************************/ |
84 |
|
|
function assignSubPage($con, $page_id_array, $subject_id) { |
85 |
|
|
|
86 |
|
|
// For every page, assign it to the selected subject |
87 |
|
|
for ($subscript = 0; $subscript < sizeof($page_id_array); $subscript++ ) { |
88 |
|
|
|
89 |
|
|
// Check to make sure that the page isn't already assigned |
90 |
|
|
$sql = "SELECT * FROM sub_page WHERE subject_id = " |
91 |
|
|
. $subject_id |
92 |
|
|
. " AND page_id = " |
93 |
|
|
. $page_id_array[$subscript]; |
94 |
|
|
|
95 |
dpavlin |
42 |
$rs = xx_query($sql); |
96 |
|
|
if (xx_num_rows($rs) == 0) { |
97 |
dpavlin |
1 |
|
98 |
|
|
$sql = "INSERT INTO sub_page (subject_id, page_id) VALUES (" |
99 |
|
|
. $subject_id |
100 |
|
|
. ", " |
101 |
|
|
. $page_id_array[$subscript] |
102 |
|
|
. ")"; |
103 |
|
|
|
104 |
dpavlin |
42 |
if (!xx_query($sql, $con)){ |
105 |
dpavlin |
1 |
sql_err($con); |
106 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
107 |
dpavlin |
1 |
bailout(); |
108 |
|
|
} // bad write |
109 |
|
|
else { |
110 |
dpavlin |
42 |
xx_query("UNLOCK TABLES", $con); |
111 |
dpavlin |
1 |
|
112 |
|
|
} // good write of sub_page |
113 |
|
|
|
114 |
|
|
} // page not already assigned |
115 |
|
|
|
116 |
|
|
} // array of page id's |
117 |
|
|
|
118 |
|
|
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
119 |
|
|
|
120 |
|
|
} // function |
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
/********************************************************** |
125 |
|
|
Function: deleteSubjectBuilder |
126 |
|
|
Author: Paul Bramscher |
127 |
|
|
Last Modified: 04.21.2003 |
128 |
|
|
*********************************************************** |
129 |
|
|
Purpose: |
130 |
|
|
Deletes an entry on an RQS page, based on a triple |
131 |
|
|
composite primary key of resource, subject and information |
132 |
|
|
type. |
133 |
|
|
**********************************************************/ |
134 |
|
|
function deleteSubjectBuilder($con, $infotype_id, $resource_id, $subject_id) { |
135 |
|
|
|
136 |
|
|
// Find the default information type for this resource |
137 |
|
|
$sql = "DELETE FROM res_sub_infotype WHERE resource_id = " |
138 |
|
|
. $resource_id . " AND subject_id = " |
139 |
|
|
. $subject_id . " AND infotype_id = " |
140 |
|
|
. $infotype_id; |
141 |
|
|
|
142 |
dpavlin |
42 |
if (!xx_query ($sql, $con)){ |
143 |
dpavlin |
1 |
sql_err($sql); |
144 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
145 |
dpavlin |
1 |
bailout(); |
146 |
|
|
} |
147 |
|
|
else { |
148 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
149 |
dpavlin |
1 |
} |
150 |
|
|
|
151 |
|
|
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
152 |
|
|
|
153 |
|
|
} |
154 |
|
|
|
155 |
|
|
|
156 |
|
|
/********************************************************** |
157 |
|
|
Function: deleteSubOtherSub |
158 |
|
|
Author: Paul Bramscher |
159 |
|
|
Last Modified: 11.04.2003 |
160 |
|
|
*********************************************************** |
161 |
|
|
Purpose: |
162 |
|
|
Deletes subject-othersubject associations based on the |
163 |
|
|
supplied subject id (possibly multiple) and calls |
164 |
|
|
formSubject back again. |
165 |
|
|
**********************************************************/ |
166 |
|
|
function deleteSubOtherSub($con, $key_list_array, $subject_id){ |
167 |
|
|
|
168 |
|
|
// For every page in the array, delete it from the bridging table |
169 |
|
|
for ($element = 0; $element < sizeof($key_list_array); $element++) { |
170 |
|
|
|
171 |
|
|
$sql = "DELETE FROM sub_othersub WHERE subject_id = " |
172 |
|
|
. $subject_id |
173 |
|
|
. " AND othersub_id = " |
174 |
|
|
. $key_list_array[$element]; |
175 |
|
|
|
176 |
|
|
// Failed |
177 |
dpavlin |
42 |
if (!xx_query ($sql, $con)){ |
178 |
dpavlin |
1 |
sql_err($sql); |
179 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
180 |
dpavlin |
1 |
bailout(); |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
// Succeeded |
184 |
|
|
else { |
185 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
186 |
dpavlin |
1 |
} |
187 |
|
|
} |
188 |
|
|
|
189 |
|
|
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
190 |
|
|
} |
191 |
|
|
|
192 |
|
|
|
193 |
|
|
/********************************************************** |
194 |
|
|
Function: deleteSubPage |
195 |
|
|
Author: Paul Bramscher |
196 |
|
|
Last Modified: 06.17.2003 |
197 |
|
|
*********************************************************** |
198 |
|
|
Purpose: |
199 |
|
|
Deletes subject-page associations based on the |
200 |
|
|
supplied subject id (possibly multiple) and calls |
201 |
|
|
formSubject back again. |
202 |
|
|
**********************************************************/ |
203 |
|
|
function deleteSubPage($con, $key_list_array, $subject_id){ |
204 |
|
|
|
205 |
|
|
// For every page in the array, delete it from the bridging table |
206 |
|
|
for ($element = 0; $element < sizeof($key_list_array); $element++) { |
207 |
|
|
|
208 |
|
|
$sql = "DELETE FROM sub_page WHERE subject_id = " |
209 |
|
|
. $subject_id |
210 |
|
|
. " AND page_id = " |
211 |
|
|
. $key_list_array[$element]; |
212 |
|
|
|
213 |
|
|
// Failed |
214 |
dpavlin |
42 |
if (!xx_query ($sql, $con)){ |
215 |
dpavlin |
1 |
sql_err($sql); |
216 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
217 |
dpavlin |
1 |
bailout(); |
218 |
|
|
} |
219 |
|
|
|
220 |
|
|
// Succeeded |
221 |
|
|
else { |
222 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
223 |
dpavlin |
1 |
} |
224 |
|
|
} |
225 |
|
|
|
226 |
|
|
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
227 |
|
|
} |
228 |
|
|
|
229 |
|
|
|
230 |
|
|
/********************************************************** |
231 |
|
|
Function: insertSubjectBuilder |
232 |
|
|
Author: Paul Bramscher |
233 |
|
|
Last Modified: 04.21.2003 |
234 |
|
|
*********************************************************** |
235 |
|
|
Purpose: |
236 |
|
|
Inserts a resource onto an RQS page. Note that the incoming |
237 |
|
|
parameters include a flag for whether this is a highlighted |
238 |
|
|
or "core" resource, the resource id itself, and the subject |
239 |
|
|
id. The third key in the primary composite key for the |
240 |
|
|
resource-subject-infotype is supplied by looking up the |
241 |
|
|
resource's default information type. Unless specified, |
242 |
|
|
it'll be NULL and appear initially on RQS pages under |
243 |
|
|
the (N/A) and (N/A) masterinfotype and infotype headings. |
244 |
|
|
**********************************************************/ |
245 |
|
|
function insertSubjectBuilder($con, $highlighted, $resource_id, $subject_id) { |
246 |
|
|
|
247 |
|
|
// Continue only if a resource was selected |
248 |
|
|
if ($resource_id > 0) { |
249 |
|
|
|
250 |
|
|
// Flag to allow adding to this RQS+ page |
251 |
|
|
$allow = 1; |
252 |
|
|
|
253 |
|
|
// Find the default information type for this resource |
254 |
|
|
$sql = "SELECT infotype_id FROM resource WHERE resource_id = " . $resource_id; |
255 |
dpavlin |
42 |
$rs = xx_query($sql, $con); |
256 |
|
|
$row = xx_fetch_array ($rs); |
257 |
dpavlin |
1 |
$infotype_id = $row["infotype_id"]; |
258 |
|
|
|
259 |
|
|
// Check to see if it's already there. |
260 |
|
|
$exists = existsResSub($con, $resource_id, $subject_id); |
261 |
|
|
|
262 |
|
|
// If already there, check to see whether the (N/A) infotype exists |
263 |
|
|
if ($exists > 0) $existsNA = existsResSubNA($con, $resource_id, $subject_id); |
264 |
|
|
|
265 |
|
|
// If (N/A) exists, disallow adding |
266 |
|
|
if ($existsNA > 0) $allow = 0; |
267 |
|
|
|
268 |
|
|
// Else allow the adding, but force into (N/A) infotype. |
269 |
|
|
if ($exists > 0 && $existsNA < 1) $infotype_id = 1; |
270 |
|
|
|
271 |
|
|
if ($allow == 1) { |
272 |
|
|
|
273 |
|
|
// Determine if highlighted/core |
274 |
|
|
if ($highlighted == "Add Core") $highlighted = 1; |
275 |
|
|
else $highlighted = 0; |
276 |
|
|
|
277 |
|
|
// Fetch the master information type |
278 |
|
|
$masterinfotype_id = lookupField($con, "infotype", "infotype_id", $infotype_id, "masterinfotype_id"); |
279 |
|
|
|
280 |
|
|
// Build the SQL |
281 |
|
|
$sql = "INSERT INTO res_sub_infotype (resource_id, subject_id, infotype_id, masterinfotype_id, highlighted) VALUES (" |
282 |
|
|
. $resource_id |
283 |
|
|
. ", " |
284 |
|
|
. $subject_id |
285 |
|
|
. ", " |
286 |
|
|
. $infotype_id |
287 |
|
|
. ", " |
288 |
|
|
. $masterinfotype_id |
289 |
|
|
. ", " |
290 |
|
|
. $highlighted |
291 |
|
|
. ")"; |
292 |
|
|
|
293 |
|
|
// Debugging |
294 |
|
|
// printf("sql was: %s<BR>", $sql); |
295 |
|
|
|
296 |
dpavlin |
42 |
if (!xx_query ($sql, $con)){ |
297 |
dpavlin |
1 |
sql_err($sql); |
298 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
299 |
dpavlin |
1 |
bailout(); |
300 |
|
|
} |
301 |
|
|
else { |
302 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
303 |
dpavlin |
1 |
} |
304 |
|
|
|
305 |
|
|
} |
306 |
|
|
|
307 |
|
|
} |
308 |
|
|
|
309 |
|
|
header("Location: subject_builder.phtml?subject_id=" . $subject_id . "&recent=" . $resource_id . "#select"); |
310 |
|
|
|
311 |
|
|
} |
312 |
|
|
|
313 |
|
|
|
314 |
|
|
/********************************************************** |
315 |
|
|
Function: rqsPublish |
316 |
|
|
Author: Paul Bramscher |
317 |
|
|
Last Modified: 08.27.2003 |
318 |
|
|
*********************************************************** |
319 |
|
|
Purpose: |
320 |
|
|
Toggles the RQS published flag to 1 (true). |
321 |
|
|
**********************************************************/ |
322 |
|
|
function rqsPublish($con, $subject_id){ |
323 |
|
|
|
324 |
|
|
$sql = "UPDATE subject SET rqs_published = '1' WHERE subject_id = " |
325 |
|
|
. $subject_id; |
326 |
|
|
|
327 |
|
|
// Failed |
328 |
dpavlin |
42 |
if (!xx_query ($sql, $con)){ |
329 |
dpavlin |
1 |
sql_err($sql); |
330 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
331 |
dpavlin |
1 |
bailout(); |
332 |
|
|
} |
333 |
|
|
|
334 |
|
|
// Succeeded |
335 |
|
|
else { |
336 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
337 |
dpavlin |
1 |
} |
338 |
|
|
|
339 |
|
|
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
340 |
|
|
} |
341 |
|
|
|
342 |
|
|
|
343 |
|
|
/********************************************************** |
344 |
|
|
Function: rqsUnpublish |
345 |
|
|
Author: Paul Bramscher |
346 |
|
|
Last Modified: 08.27.2003 |
347 |
|
|
*********************************************************** |
348 |
|
|
Purpose: |
349 |
|
|
Toggles the RQS published flag to 0 (false). |
350 |
|
|
**********************************************************/ |
351 |
|
|
function rqsUnpublish($con, $subject_id){ |
352 |
|
|
|
353 |
|
|
$sql = "UPDATE subject SET rqs_published = '0' WHERE subject_id = " |
354 |
|
|
. $subject_id; |
355 |
|
|
|
356 |
|
|
// Failed |
357 |
dpavlin |
42 |
if (!xx_query ($sql, $con)){ |
358 |
dpavlin |
1 |
sql_err($sql); |
359 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
360 |
dpavlin |
1 |
bailout(); |
361 |
|
|
} |
362 |
|
|
|
363 |
|
|
// Succeeded |
364 |
|
|
else { |
365 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
366 |
dpavlin |
1 |
} |
367 |
|
|
|
368 |
|
|
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
369 |
|
|
} |
370 |
|
|
|
371 |
|
|
|
372 |
|
|
/********************************************************** |
373 |
|
|
Function: updateRQSUpdate |
374 |
|
|
Author: Paul Bramscher |
375 |
|
|
Last Modified: 08.27.2003 |
376 |
|
|
*********************************************************** |
377 |
|
|
Purpose: |
378 |
|
|
Modifies the RQS "last updated" fields accordingly. |
379 |
|
|
**********************************************************/ |
380 |
|
|
function updateRQSUpdate($con, $sess_staff_account, $subject_id) { |
381 |
|
|
|
382 |
|
|
$sql = "UPDATE subject SET rqs_date_modified = now(), rqs_account_modified ='" |
383 |
|
|
. $sess_staff_account |
384 |
|
|
. "' WHERE subject_id = " |
385 |
|
|
. $subject_id; |
386 |
|
|
|
387 |
|
|
// Failed |
388 |
dpavlin |
42 |
if (!xx_query ($sql, $con)){ |
389 |
dpavlin |
1 |
sql_err($sql); |
390 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
391 |
dpavlin |
1 |
bailout(); |
392 |
|
|
} |
393 |
|
|
|
394 |
|
|
// Succeeded |
395 |
|
|
else { |
396 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
397 |
dpavlin |
1 |
} |
398 |
|
|
} |
399 |
|
|
|
400 |
|
|
|
401 |
|
|
/********************************************************** |
402 |
|
|
Function: updateSubjectBuilder |
403 |
|
|
Author: Paul Bramscher |
404 |
|
|
Last Modified: 05.27.2003 |
405 |
|
|
*********************************************************** |
406 |
|
|
Purpose: |
407 |
|
|
Update the RQS resource-subject-infoype assignment. Note |
408 |
|
|
that the incoming variables also include a flag for whether |
409 |
|
|
the assignment is to be a highlighted or "core" resource. |
410 |
|
|
**********************************************************/ |
411 |
|
|
function updateSubjectBuilder($con, $description, $descr_default, $highlighted, |
412 |
|
|
$infotype_id, $old_infotype_id, $resource_id, $subject_id) { |
413 |
|
|
|
414 |
|
|
// Clean up strings |
415 |
|
|
if (strlen($description) > 0) $description = textInmySQL($description); |
416 |
|
|
|
417 |
|
|
// First delete the one, as well as the newly-selected information type entry (if exists) |
418 |
|
|
$sql = "DELETE FROM res_sub_infotype WHERE resource_id = " |
419 |
|
|
. $resource_id |
420 |
|
|
. " AND subject_id = " |
421 |
|
|
. $subject_id |
422 |
|
|
. " AND (infotype_id = " |
423 |
|
|
. $old_infotype_id |
424 |
|
|
. " OR infotype_id = " |
425 |
|
|
. $infotype_id |
426 |
|
|
. ")"; |
427 |
|
|
|
428 |
dpavlin |
42 |
if (!xx_query ($sql, $con)){ |
429 |
dpavlin |
1 |
sql_err($sql); |
430 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
431 |
dpavlin |
1 |
bailout(); |
432 |
|
|
} |
433 |
|
|
else { |
434 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
435 |
dpavlin |
1 |
} |
436 |
|
|
|
437 |
|
|
// If the user opted for default resource description, void out the incoming $description; |
438 |
|
|
if ($descr_default == 1) $description = ""; |
439 |
|
|
|
440 |
|
|
// Fetch the master information type |
441 |
|
|
$masterinfotype_id = lookupField($con, "infotype", "infotype_id", $infotype_id, "masterinfotype_id"); |
442 |
|
|
|
443 |
|
|
// Insert the new row |
444 |
|
|
$sql = "INSERT INTO res_sub_infotype ( |
445 |
|
|
resource_id, |
446 |
|
|
subject_id, |
447 |
|
|
infotype_id, |
448 |
|
|
masterinfotype_id, |
449 |
|
|
highlighted, |
450 |
|
|
description) VALUES (" |
451 |
|
|
. $resource_id |
452 |
|
|
. ", " |
453 |
|
|
. $subject_id |
454 |
|
|
. ", " |
455 |
|
|
. $infotype_id |
456 |
|
|
. ", " |
457 |
|
|
. $masterinfotype_id |
458 |
|
|
. ", '" |
459 |
|
|
. $highlighted |
460 |
|
|
. "', '" |
461 |
|
|
. $description |
462 |
|
|
. "')"; |
463 |
|
|
|
464 |
dpavlin |
42 |
if (!xx_query ($sql, $con)){ |
465 |
dpavlin |
1 |
sql_err($sql); |
466 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
467 |
dpavlin |
1 |
bailout(); |
468 |
|
|
} |
469 |
|
|
else { |
470 |
dpavlin |
42 |
xx_query ("UNLOCK TABLES", $con); |
471 |
dpavlin |
1 |
} |
472 |
|
|
|
473 |
|
|
header("Location: subject_builder.phtml?subject_id=" . $subject_id . "#" . $resource_id); |
474 |
|
|
} |
475 |
|
|
?> |