1 |
<?php |
2 |
/********************************************************** |
3 |
Function Library: subject_builder.php |
4 |
Original Author: Paul Bramscher <brams006@umn.edu> |
5 |
Last Modified: 03.04.2004 |
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: 03.04.2004 |
31 |
*********************************************************** |
32 |
Purpose: |
33 |
Assigns other RQS pages (possibly multiple) to a given |
34 |
subject and calls the subject page editor back again. |
35 |
**********************************************************/ |
36 |
function assignSubOtherSub($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 |
$rs = xx_tryquery($sql); |
48 |
if (xx_num_rows($rs) == 0) { |
49 |
|
50 |
$sql = "INSERT INTO sub_othersub (subject_id, othersub_id) VALUES (" |
51 |
. $subject_id |
52 |
. ", " |
53 |
. $subject_id_array[$subscript] |
54 |
. ")"; |
55 |
xx_tryquery($sql); |
56 |
|
57 |
} // other subject not already assigned |
58 |
|
59 |
} // array of subject id's |
60 |
|
61 |
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
62 |
|
63 |
} // function |
64 |
|
65 |
|
66 |
/********************************************************** |
67 |
Function: assignSubPage |
68 |
Author: Paul Bramscher |
69 |
Last Modified: 03.04.2004 |
70 |
*********************************************************** |
71 |
Purpose: |
72 |
Assigns PageScribe pages (possibly multiple) to a given |
73 |
subject and calls the subject page editor back again. |
74 |
**********************************************************/ |
75 |
function assignSubPage($page_id_array, $subject_id) { |
76 |
|
77 |
// For every page, assign it to the selected subject |
78 |
for ($subscript = 0; $subscript < sizeof($page_id_array); $subscript++ ) { |
79 |
|
80 |
// Check to make sure that the page isn't already assigned |
81 |
$sql = "SELECT * FROM sub_page WHERE subject_id = " |
82 |
. $subject_id |
83 |
. " AND page_id = " |
84 |
. $page_id_array[$subscript]; |
85 |
|
86 |
$rs = xx_tryquery($sql); |
87 |
if (xx_num_rows($rs) == 0) { |
88 |
|
89 |
$sql = "INSERT INTO sub_page (subject_id, page_id) VALUES (" |
90 |
. $subject_id |
91 |
. ", " |
92 |
. $page_id_array[$subscript] |
93 |
. ")"; |
94 |
xx_tryquery($sql); |
95 |
|
96 |
} // page not already assigned |
97 |
|
98 |
} // array of page id's |
99 |
|
100 |
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
101 |
|
102 |
} // function |
103 |
|
104 |
|
105 |
|
106 |
/********************************************************** |
107 |
Function: deleteSubjectBuilder |
108 |
Author: Paul Bramscher |
109 |
Last Modified: 03.04.2004 |
110 |
*********************************************************** |
111 |
Purpose: |
112 |
Deletes an entry on an RQS page, based on a triple |
113 |
composite primary key of resource, subject and information |
114 |
type. |
115 |
**********************************************************/ |
116 |
function deleteSubjectBuilder($infotype_id, $resource_id, $subject_id) { |
117 |
|
118 |
// Find the default information type for this resource |
119 |
$sql = "DELETE FROM res_sub_infotype WHERE resource_id = " |
120 |
. $resource_id . " AND subject_id = " |
121 |
. $subject_id . " AND infotype_id = " |
122 |
. $infotype_id; |
123 |
xx_tryquery($sql); |
124 |
|
125 |
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
126 |
|
127 |
} |
128 |
|
129 |
|
130 |
/********************************************************** |
131 |
Function: deleteSubOtherSub |
132 |
Author: Paul Bramscher |
133 |
Last Modified: 03.04.2004 |
134 |
*********************************************************** |
135 |
Purpose: |
136 |
Deletes subject-othersubject associations based on the |
137 |
supplied subject id (possibly multiple) and calls |
138 |
the subject page editor back again. |
139 |
**********************************************************/ |
140 |
function deleteSubOtherSub($key_list_array, $subject_id){ |
141 |
|
142 |
// For every page in the array, delete it from the bridging table |
143 |
for ($element = 0; $element < sizeof($key_list_array); $element++) { |
144 |
|
145 |
$sql = "DELETE FROM sub_othersub WHERE subject_id = " |
146 |
. $subject_id |
147 |
. " AND othersub_id = " |
148 |
. $key_list_array[$element]; |
149 |
xx_tryquery($sql); |
150 |
} |
151 |
|
152 |
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
153 |
} |
154 |
|
155 |
|
156 |
/********************************************************** |
157 |
Function: deleteSubPage |
158 |
Author: Paul Bramscher |
159 |
Last Modified: 03.04.2004 |
160 |
*********************************************************** |
161 |
Purpose: |
162 |
Deletes subject-page associations based on the |
163 |
supplied subject id (possibly multiple) and calls |
164 |
the subject page editor back again. |
165 |
**********************************************************/ |
166 |
function deleteSubPage($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_page WHERE subject_id = " |
172 |
. $subject_id |
173 |
. " AND page_id = " |
174 |
. $key_list_array[$element]; |
175 |
xx_tryquery($sql); |
176 |
} |
177 |
|
178 |
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
179 |
} |
180 |
|
181 |
|
182 |
/********************************************************** |
183 |
Function: insertSubjectBuilder |
184 |
Author: Paul Bramscher |
185 |
Last Modified: 03.04.2004 |
186 |
*********************************************************** |
187 |
Purpose: |
188 |
Inserts a resource onto an RQS page. Note that the incoming |
189 |
parameters include a flag for whether this is a highlighted |
190 |
or "core" resource, the resource id itself, and the subject |
191 |
id. The third key in the primary composite key for the |
192 |
resource-subject-infotype is supplied by looking up the |
193 |
resource's default information type. Unless specified, |
194 |
it'll be NULL and appear initially on RQS pages under |
195 |
the (N/A) and (N/A) masterinfotype and infotype headings. |
196 |
**********************************************************/ |
197 |
function insertSubjectBuilder($highlighted, $resource_id, $subject_id) { |
198 |
|
199 |
// Continue only if a resource was selected |
200 |
if ($resource_id > 0) { |
201 |
|
202 |
// Flag to allow adding to this RQS+ page |
203 |
$allow = 1; |
204 |
|
205 |
// Find the default information type for this resource |
206 |
$sql = "SELECT infotype_id FROM resource WHERE resource_id = " . $resource_id; |
207 |
$rs = xx_tryquery($sql); |
208 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
209 |
$infotype_id = $row["infotype_id"]; |
210 |
|
211 |
// Check to see if it's already there. |
212 |
$exists = existsResSub($resource_id, $subject_id); |
213 |
|
214 |
// If already there, check to see whether the (N/A) infotype exists |
215 |
if ($exists > 0) $existsNA = existsResSubNA($resource_id, $subject_id); |
216 |
|
217 |
// If (N/A) exists, disallow adding |
218 |
if ($existsNA > 0) $allow = 0; |
219 |
|
220 |
// Else allow the adding, but force into (N/A) infotype. |
221 |
if ($exists > 0 && $existsNA < 1) $infotype_id = 1; |
222 |
|
223 |
if ($allow == 1) { |
224 |
|
225 |
// Determine if highlighted/core |
226 |
if ($highlighted == "Add Core") $highlighted = 1; |
227 |
else $highlighted = 0; |
228 |
|
229 |
// Fetch the master information type |
230 |
$masterinfotype_id = lookupField("infotype", "infotype_id", $infotype_id, "masterinfotype_id"); |
231 |
|
232 |
// Build the SQL |
233 |
$sql = "INSERT INTO res_sub_infotype (resource_id, subject_id, infotype_id, masterinfotype_id, highlighted) VALUES (" |
234 |
. $resource_id |
235 |
. ", " |
236 |
. $subject_id |
237 |
. ", " |
238 |
. $infotype_id |
239 |
. ", " |
240 |
. $masterinfotype_id |
241 |
. ", " |
242 |
. $highlighted |
243 |
. ")"; |
244 |
xx_tryquery($sql); |
245 |
|
246 |
} |
247 |
|
248 |
} |
249 |
|
250 |
header("Location: subject_builder.phtml?subject_id=" . $subject_id . "&recent=" . $resource_id . "#select"); |
251 |
|
252 |
} |
253 |
|
254 |
|
255 |
/********************************************************** |
256 |
Function: rqsPublish |
257 |
Author: Paul Bramscher |
258 |
Last Modified: 03.04.2004 |
259 |
*********************************************************** |
260 |
Purpose: |
261 |
Toggles the RQS published flag to 1 (true). |
262 |
**********************************************************/ |
263 |
function rqsPublish($subject_id){ |
264 |
|
265 |
$sql = "UPDATE subject SET rqs_published = '1' WHERE subject_id = " |
266 |
. $subject_id; |
267 |
xx_tryquery($sql); |
268 |
|
269 |
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
270 |
} |
271 |
|
272 |
|
273 |
/********************************************************** |
274 |
Function: rqsUnpublish |
275 |
Author: Paul Bramscher |
276 |
Last Modified: 03.04.2004 |
277 |
*********************************************************** |
278 |
Purpose: |
279 |
Toggles the RQS published flag to 0 (false). |
280 |
**********************************************************/ |
281 |
function rqsUnpublish($subject_id){ |
282 |
|
283 |
$sql = "UPDATE subject SET rqs_published = '0' WHERE subject_id = " |
284 |
. $subject_id; |
285 |
xx_tryquery($sql); |
286 |
|
287 |
header("Location: subject_builder.phtml?subject_id=" . $subject_id); |
288 |
} |
289 |
|
290 |
|
291 |
/********************************************************** |
292 |
Function: updateRQSUpdate |
293 |
Author: Paul Bramscher |
294 |
Last Modified: 03.04.2004 |
295 |
*********************************************************** |
296 |
Purpose: |
297 |
Modifies the RQS "last updated" fields accordingly. |
298 |
**********************************************************/ |
299 |
function updateRQSUpdate($sess_staff_account, $subject_id) { |
300 |
|
301 |
$sql = "UPDATE subject SET rqs_date_modified = now(), rqs_account_modified ='" |
302 |
. $sess_staff_account |
303 |
. "' WHERE subject_id = " |
304 |
. $subject_id; |
305 |
xx_tryquery($sql); |
306 |
} |
307 |
|
308 |
|
309 |
/********************************************************** |
310 |
Function: updateSubjectBuilder |
311 |
Author: Paul Bramscher |
312 |
Last Modified: 03.04.2004 |
313 |
*********************************************************** |
314 |
Purpose: |
315 |
Update the RQS resource-subject-infoype assignment. Note |
316 |
that the incoming variables also include a flag for whether |
317 |
the assignment is to be a highlighted or "core" resource. |
318 |
**********************************************************/ |
319 |
function updateSubjectBuilder($description, $descr_default, $highlighted, |
320 |
$infotype_id, $old_infotype_id, $resource_id, $subject_id) { |
321 |
|
322 |
// Clean up strings |
323 |
if (strlen($description) > 0) $description = textInmySQL($description); |
324 |
|
325 |
// First delete the one, as well as the newly-selected information type entry (if exists) |
326 |
$sql = "DELETE FROM res_sub_infotype WHERE resource_id = " |
327 |
. $resource_id |
328 |
. " AND subject_id = " |
329 |
. $subject_id |
330 |
. " AND (infotype_id = " |
331 |
. $old_infotype_id |
332 |
. " OR infotype_id = " |
333 |
. $infotype_id |
334 |
. ")"; |
335 |
xx_tryquery($sql); |
336 |
|
337 |
// If the user opted for default resource description, void out the incoming $description; |
338 |
if ($descr_default == 1) $description = ""; |
339 |
|
340 |
// Fetch the master information type |
341 |
$masterinfotype_id = lookupField("infotype", "infotype_id", $infotype_id, "masterinfotype_id"); |
342 |
|
343 |
// Insert the new row |
344 |
$sql = "INSERT INTO res_sub_infotype ( |
345 |
resource_id, |
346 |
subject_id, |
347 |
infotype_id, |
348 |
masterinfotype_id, |
349 |
highlighted, |
350 |
description) VALUES (" |
351 |
. $resource_id |
352 |
. ", " |
353 |
. $subject_id |
354 |
. ", " |
355 |
. $infotype_id |
356 |
. ", " |
357 |
. $masterinfotype_id |
358 |
. ", '" |
359 |
. $highlighted |
360 |
. "', '" |
361 |
. $description |
362 |
. "')"; |
363 |
xx_tryquery($sql); |
364 |
|
365 |
header("Location: subject_builder.phtml?subject_id=" . $subject_id . "#" . $resource_id); |
366 |
} |
367 |
?> |