/[libdata]/branches/paul/admin/include/subject_builder.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /branches/paul/admin/include/subject_builder.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 67 - (hide annotations)
Thu Mar 18 19:24:54 2004 UTC (20 years, 1 month ago) by dpavlin
File size: 11247 byte(s)
updated to libdata 2.00

1 dpavlin 1 <?php
2     /**********************************************************
3     Function Library: subject_builder.php
4 dpavlin 67 Original Author: Paul Bramscher <brams006@umn.edu>
5     Last Modified: 03.04.2004
6 dpavlin 1 ***********************************************************
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 dpavlin 67 Last Modified: 03.04.2004
31 dpavlin 1 ***********************************************************
32     Purpose:
33     Assigns other RQS pages (possibly multiple) to a given
34 dpavlin 67 subject and calls the subject page editor back again.
35 dpavlin 1 **********************************************************/
36 dpavlin 67 function assignSubOtherSub($subject_id_array, $subject_id) {
37 dpavlin 1
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 67 $rs = mysql_tryquery($sql);
48 dpavlin 1 if (mysql_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 dpavlin 67 mysql_tryquery($sql);
56 dpavlin 1
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 dpavlin 67 Last Modified: 03.04.2004
70 dpavlin 1 ***********************************************************
71     Purpose:
72     Assigns PageScribe pages (possibly multiple) to a given
73 dpavlin 67 subject and calls the subject page editor back again.
74 dpavlin 1 **********************************************************/
75 dpavlin 67 function assignSubPage($page_id_array, $subject_id) {
76 dpavlin 1
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 dpavlin 67 $rs = mysql_tryquery($sql);
87 dpavlin 1 if (mysql_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 dpavlin 67 mysql_tryquery($sql);
95 dpavlin 1
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 dpavlin 67 Last Modified: 03.04.2004
110 dpavlin 1 ***********************************************************
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 dpavlin 67 function deleteSubjectBuilder($infotype_id, $resource_id, $subject_id) {
117 dpavlin 1
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 dpavlin 67 mysql_tryquery($sql);
124 dpavlin 1
125     header("Location: subject_builder.phtml?subject_id=" . $subject_id);
126    
127     }
128    
129    
130     /**********************************************************
131     Function: deleteSubOtherSub
132     Author: Paul Bramscher
133 dpavlin 67 Last Modified: 03.04.2004
134 dpavlin 1 ***********************************************************
135     Purpose:
136     Deletes subject-othersubject associations based on the
137     supplied subject id (possibly multiple) and calls
138 dpavlin 67 the subject page editor back again.
139 dpavlin 1 **********************************************************/
140 dpavlin 67 function deleteSubOtherSub($key_list_array, $subject_id){
141 dpavlin 1
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 dpavlin 67 mysql_tryquery($sql);
150 dpavlin 1 }
151    
152     header("Location: subject_builder.phtml?subject_id=" . $subject_id);
153     }
154    
155    
156     /**********************************************************
157     Function: deleteSubPage
158     Author: Paul Bramscher
159 dpavlin 67 Last Modified: 03.04.2004
160 dpavlin 1 ***********************************************************
161     Purpose:
162     Deletes subject-page associations based on the
163     supplied subject id (possibly multiple) and calls
164 dpavlin 67 the subject page editor back again.
165 dpavlin 1 **********************************************************/
166 dpavlin 67 function deleteSubPage($key_list_array, $subject_id){
167 dpavlin 1
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 dpavlin 67 mysql_tryquery($sql);
176 dpavlin 1 }
177    
178     header("Location: subject_builder.phtml?subject_id=" . $subject_id);
179     }
180    
181    
182     /**********************************************************
183     Function: insertSubjectBuilder
184     Author: Paul Bramscher
185 dpavlin 67 Last Modified: 03.04.2004
186 dpavlin 1 ***********************************************************
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 dpavlin 67 function insertSubjectBuilder($highlighted, $resource_id, $subject_id) {
198 dpavlin 1
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 dpavlin 67 $rs = mysql_tryquery($sql);
208     $row = mysql_fetch_array ($rs, MYSQL_ASSOC);
209 dpavlin 1 $infotype_id = $row["infotype_id"];
210    
211     // Check to see if it's already there.
212 dpavlin 67 $exists = existsResSub($resource_id, $subject_id);
213 dpavlin 1
214     // If already there, check to see whether the (N/A) infotype exists
215 dpavlin 67 if ($exists > 0) $existsNA = existsResSubNA($resource_id, $subject_id);
216 dpavlin 1
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 dpavlin 67 $masterinfotype_id = lookupField("infotype", "infotype_id", $infotype_id, "masterinfotype_id");
231 dpavlin 1
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 dpavlin 67 mysql_tryquery($sql);
245 dpavlin 1
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 dpavlin 67 Last Modified: 03.04.2004
259 dpavlin 1 ***********************************************************
260     Purpose:
261     Toggles the RQS published flag to 1 (true).
262     **********************************************************/
263 dpavlin 67 function rqsPublish($subject_id){
264 dpavlin 1
265     $sql = "UPDATE subject SET rqs_published = '1' WHERE subject_id = "
266     . $subject_id;
267 dpavlin 67 mysql_tryquery($sql);
268 dpavlin 1
269     header("Location: subject_builder.phtml?subject_id=" . $subject_id);
270     }
271    
272    
273     /**********************************************************
274     Function: rqsUnpublish
275     Author: Paul Bramscher
276 dpavlin 67 Last Modified: 03.04.2004
277 dpavlin 1 ***********************************************************
278     Purpose:
279     Toggles the RQS published flag to 0 (false).
280     **********************************************************/
281 dpavlin 67 function rqsUnpublish($subject_id){
282 dpavlin 1
283     $sql = "UPDATE subject SET rqs_published = '0' WHERE subject_id = "
284     . $subject_id;
285 dpavlin 67 mysql_tryquery($sql);
286 dpavlin 1
287     header("Location: subject_builder.phtml?subject_id=" . $subject_id);
288     }
289    
290    
291     /**********************************************************
292     Function: updateRQSUpdate
293     Author: Paul Bramscher
294 dpavlin 67 Last Modified: 03.04.2004
295 dpavlin 1 ***********************************************************
296     Purpose:
297     Modifies the RQS "last updated" fields accordingly.
298     **********************************************************/
299 dpavlin 67 function updateRQSUpdate($sess_staff_account, $subject_id) {
300 dpavlin 1
301     $sql = "UPDATE subject SET rqs_date_modified = now(), rqs_account_modified ='"
302     . $sess_staff_account
303     . "' WHERE subject_id = "
304     . $subject_id;
305 dpavlin 67 mysql_tryquery($sql);
306 dpavlin 1 }
307    
308    
309     /**********************************************************
310     Function: updateSubjectBuilder
311     Author: Paul Bramscher
312 dpavlin 67 Last Modified: 03.04.2004
313 dpavlin 1 ***********************************************************
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 dpavlin 67 function updateSubjectBuilder($description, $descr_default, $highlighted,
320 dpavlin 1 $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 dpavlin 67 mysql_tryquery($sql);
336 dpavlin 1
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 dpavlin 67 $masterinfotype_id = lookupField("infotype", "infotype_id", $infotype_id, "masterinfotype_id");
342 dpavlin 1
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 dpavlin 67 mysql_tryquery($sql);
364 dpavlin 1
365     header("Location: subject_builder.phtml?subject_id=" . $subject_id . "#" . $resource_id);
366     }
367 dpavlin 67 ?>

  ViewVC Help
Powered by ViewVC 1.1.26