/[libdata]/trunk/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

Diff of /trunk/admin/include/subject_builder.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 71 by dpavlin, Thu Mar 4 22:43:50 2004 UTC revision 72 by dpavlin, Thu Mar 18 20:33:37 2004 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /**********************************************************  /**********************************************************
3  Function Library: subject_builder.php  Function Library: subject_builder.php
4  Original Author: Paul Bramscher <brams006@tc.umn.edu>  Original Author: Paul Bramscher <brams006@umn.edu>
5  Last Modified: 11.04.2003  Last Modified: 03.04.2004
6  ***********************************************************  ***********************************************************
7  Comments:  Comments:
8  This small library brings together basic functionality to  This small library brings together basic functionality to
# Line 27  updateSubjectBuilder Line 27  updateSubjectBuilder
27  /**********************************************************  /**********************************************************
28  Function: assignSubOtherSub  Function: assignSubOtherSub
29  Author: Paul Bramscher  Author: Paul Bramscher
30  Last Modified: 11.04.2003  Last Modified: 03.04.2004
31  ***********************************************************  ***********************************************************
32  Purpose:  Purpose:
33  Assigns other RQS pages (possibly multiple) to a given  Assigns other RQS pages (possibly multiple) to a given
34  subject and calls formSubject back again.  subject and calls the subject page editor back again.
35  **********************************************************/  **********************************************************/
36  function assignSubOtherSub($con, $subject_id_array, $subject_id) {  function assignSubOtherSub($subject_id_array, $subject_id) {
37    
38          // For every subject, assign it to the selected subject          // For every subject, assign it to the selected subject
39          for ($subscript = 0; $subscript < sizeof($subject_id_array); $subscript++ ) {          for ($subscript = 0; $subscript < sizeof($subject_id_array); $subscript++ ) {
# Line 44  function assignSubOtherSub($con, $subjec Line 44  function assignSubOtherSub($con, $subjec
44                          . " AND othersub_id = "                          . " AND othersub_id = "
45                          . $subject_id_array[$subscript];                          . $subject_id_array[$subscript];
46    
47                  $rs = xx_query($sql);                  $rs = xx_tryquery($sql);
48                  if (xx_num_rows($rs) == 0) {                  if (xx_num_rows($rs) == 0) {
49    
50                          $sql = "INSERT INTO sub_othersub (subject_id, othersub_id) VALUES ("                          $sql = "INSERT INTO sub_othersub (subject_id, othersub_id) VALUES ("
# Line 52  function assignSubOtherSub($con, $subjec Line 52  function assignSubOtherSub($con, $subjec
52                                  . ", "                                  . ", "
53                                  . $subject_id_array[$subscript]                                  . $subject_id_array[$subscript]
54                                  . ")";                                  . ")";
55                            xx_tryquery($sql);
                         if (!xx_query($sql, $con)){  
                                 sql_err($con);  
                                 xx_query ("UNLOCK TABLES", $con);  
                                 bailout();  
                         } // bad write  
                         else {  
                                 xx_query("UNLOCK TABLES", $con);  
                           
                         } // good write of sub_othersub  
56                                                    
57                  } // other subject not already assigned                  } // other subject not already assigned
58    
# Line 75  function assignSubOtherSub($con, $subjec Line 66  function assignSubOtherSub($con, $subjec
66  /**********************************************************  /**********************************************************
67  Function: assignSubPage  Function: assignSubPage
68  Author: Paul Bramscher  Author: Paul Bramscher
69  Last Modified: 06.17.2003  Last Modified: 03.04.2004
70  ***********************************************************  ***********************************************************
71  Purpose:  Purpose:
72  Assigns PageScribe pages (possibly multiple) to a given  Assigns PageScribe pages (possibly multiple) to a given
73  subject and calls formSubject back again.  subject and calls the subject page editor back again.
74  **********************************************************/  **********************************************************/
75  function assignSubPage($con, $page_id_array, $subject_id) {  function assignSubPage($page_id_array, $subject_id) {
76    
77          // For every page, assign it to the selected subject          // For every page, assign it to the selected subject
78          for ($subscript = 0; $subscript < sizeof($page_id_array); $subscript++ ) {          for ($subscript = 0; $subscript < sizeof($page_id_array); $subscript++ ) {
# Line 92  function assignSubPage($con, $page_id_ar Line 83  function assignSubPage($con, $page_id_ar
83                          . " AND page_id = "                          . " AND page_id = "
84                          . $page_id_array[$subscript];                          . $page_id_array[$subscript];
85    
86                  $rs = xx_query($sql);                  $rs = xx_tryquery($sql);
87                  if (xx_num_rows($rs) == 0) {                  if (xx_num_rows($rs) == 0) {
88    
89                          $sql = "INSERT INTO sub_page (subject_id, page_id) VALUES ("                          $sql = "INSERT INTO sub_page (subject_id, page_id) VALUES ("
# Line 100  function assignSubPage($con, $page_id_ar Line 91  function assignSubPage($con, $page_id_ar
91                                  . ", "                                  . ", "
92                                  . $page_id_array[$subscript]                                  . $page_id_array[$subscript]
93                                  . ")";                                  . ")";
94                            xx_tryquery($sql);
                         if (!xx_query($sql, $con)){  
                                 sql_err($con);  
                                 xx_query ("UNLOCK TABLES", $con);  
                                 bailout();  
                         } // bad write  
                         else {  
                                 xx_query("UNLOCK TABLES", $con);  
                           
                         } // good write of sub_page  
95                                                    
96                  } // page not already assigned                  } // page not already assigned
97    
# Line 124  function assignSubPage($con, $page_id_ar Line 106  function assignSubPage($con, $page_id_ar
106  /**********************************************************  /**********************************************************
107  Function: deleteSubjectBuilder  Function: deleteSubjectBuilder
108  Author: Paul Bramscher  Author: Paul Bramscher
109  Last Modified: 04.21.2003  Last Modified: 03.04.2004
110  ***********************************************************  ***********************************************************
111  Purpose:  Purpose:
112  Deletes an entry on an RQS page, based on a triple  Deletes an entry on an RQS page, based on a triple
113  composite primary key of resource, subject and information  composite primary key of resource, subject and information
114  type.  type.
115  **********************************************************/  **********************************************************/
116  function deleteSubjectBuilder($con, $infotype_id, $resource_id, $subject_id) {  function deleteSubjectBuilder($infotype_id, $resource_id, $subject_id) {
117    
118          // Find the default information type for this resource          // Find the default information type for this resource
119          $sql = "DELETE FROM res_sub_infotype WHERE resource_id = "          $sql = "DELETE FROM res_sub_infotype WHERE resource_id = "
120                  . $resource_id . " AND subject_id = "                  . $resource_id . " AND subject_id = "
121                  . $subject_id . " AND infotype_id = "                  . $subject_id . " AND infotype_id = "
122                  . $infotype_id;                  . $infotype_id;
123            xx_tryquery($sql);
         if (!xx_query ($sql, $con)){  
                 sql_err($sql);  
                 xx_query ("UNLOCK TABLES", $con);  
                 bailout();  
         }  
         else {  
                 xx_query ("UNLOCK TABLES", $con);  
         }  
124    
125          header("Location: subject_builder.phtml?subject_id=" . $subject_id);          header("Location: subject_builder.phtml?subject_id=" . $subject_id);
126    
# Line 156  function deleteSubjectBuilder($con, $inf Line 130  function deleteSubjectBuilder($con, $inf
130  /**********************************************************  /**********************************************************
131  Function: deleteSubOtherSub  Function: deleteSubOtherSub
132  Author: Paul Bramscher  Author: Paul Bramscher
133  Last Modified: 11.04.2003  Last Modified: 03.04.2004
134  ***********************************************************  ***********************************************************
135  Purpose:  Purpose:
136  Deletes subject-othersubject associations based on the  Deletes subject-othersubject associations based on the
137  supplied subject id (possibly multiple) and calls  supplied subject id (possibly multiple) and calls
138  formSubject back again.  the subject page editor back again.
139  **********************************************************/  **********************************************************/
140  function deleteSubOtherSub($con, $key_list_array, $subject_id){  function deleteSubOtherSub($key_list_array, $subject_id){
141    
142          // For every page in the array, delete it from the bridging table          // For every page in the array, delete it from the bridging table
143          for ($element = 0; $element < sizeof($key_list_array); $element++) {          for ($element = 0; $element < sizeof($key_list_array); $element++) {
# Line 172  function deleteSubOtherSub($con, $key_li Line 146  function deleteSubOtherSub($con, $key_li
146                          . $subject_id                          . $subject_id
147                          . " AND othersub_id = "                          . " AND othersub_id = "
148                          . $key_list_array[$element];                          . $key_list_array[$element];
149                    xx_tryquery($sql);
                 // Failed                                
                 if (!xx_query ($sql, $con)){  
                         sql_err($sql);  
                         xx_query ("UNLOCK TABLES", $con);  
                         bailout();  
                 }  
                   
                 // Succeeded  
                 else {  
                         xx_query ("UNLOCK TABLES", $con);  
                 }  
150          }          }
151                    
152          header("Location: subject_builder.phtml?subject_id=" . $subject_id);          header("Location: subject_builder.phtml?subject_id=" . $subject_id);
# Line 193  function deleteSubOtherSub($con, $key_li Line 156  function deleteSubOtherSub($con, $key_li
156  /**********************************************************  /**********************************************************
157  Function: deleteSubPage  Function: deleteSubPage
158  Author: Paul Bramscher  Author: Paul Bramscher
159  Last Modified: 06.17.2003  Last Modified: 03.04.2004
160  ***********************************************************  ***********************************************************
161  Purpose:  Purpose:
162  Deletes subject-page associations based on the  Deletes subject-page associations based on the
163  supplied subject id (possibly multiple) and calls  supplied subject id (possibly multiple) and calls
164  formSubject back again.  the subject page editor back again.
165  **********************************************************/  **********************************************************/
166  function deleteSubPage($con, $key_list_array, $subject_id){  function deleteSubPage($key_list_array, $subject_id){
167    
168          // For every page in the array, delete it from the bridging table          // For every page in the array, delete it from the bridging table
169          for ($element = 0; $element < sizeof($key_list_array); $element++) {          for ($element = 0; $element < sizeof($key_list_array); $element++) {
# Line 209  function deleteSubPage($con, $key_list_a Line 172  function deleteSubPage($con, $key_list_a
172                          . $subject_id                          . $subject_id
173                          . " AND page_id = "                          . " AND page_id = "
174                          . $key_list_array[$element];                          . $key_list_array[$element];
175                    xx_tryquery($sql);
                 // Failed                                
                 if (!xx_query ($sql, $con)){  
                         sql_err($sql);  
                         xx_query ("UNLOCK TABLES", $con);  
                         bailout();  
                 }  
                   
                 // Succeeded  
                 else {  
                         xx_query ("UNLOCK TABLES", $con);  
                 }  
176          }          }
177                    
178          header("Location: subject_builder.phtml?subject_id=" . $subject_id);          header("Location: subject_builder.phtml?subject_id=" . $subject_id);
# Line 230  function deleteSubPage($con, $key_list_a Line 182  function deleteSubPage($con, $key_list_a
182  /**********************************************************  /**********************************************************
183  Function: insertSubjectBuilder  Function: insertSubjectBuilder
184  Author: Paul Bramscher  Author: Paul Bramscher
185  Last Modified: 04.21.2003  Last Modified: 03.04.2004
186  ***********************************************************  ***********************************************************
187  Purpose:  Purpose:
188  Inserts a resource onto an RQS page.  Note that the incoming  Inserts a resource onto an RQS page.  Note that the incoming
# Line 242  resource's default information type.  Un Line 194  resource's default information type.  Un
194  it'll be NULL and appear initially on RQS pages under  it'll be NULL and appear initially on RQS pages under
195  the (N/A) and (N/A) masterinfotype and infotype headings.  the (N/A) and (N/A) masterinfotype and infotype headings.
196  **********************************************************/  **********************************************************/
197  function insertSubjectBuilder($con, $highlighted, $resource_id, $subject_id) {  function insertSubjectBuilder($highlighted, $resource_id, $subject_id) {
198    
199          // Continue only if a resource was selected          // Continue only if a resource was selected
200          if ($resource_id > 0) {          if ($resource_id > 0) {
# Line 252  function insertSubjectBuilder($con, $hig Line 204  function insertSubjectBuilder($con, $hig
204    
205                  // Find the default information type for this resource                  // Find the default information type for this resource
206                  $sql = "SELECT infotype_id FROM resource WHERE resource_id = " . $resource_id;                  $sql = "SELECT infotype_id FROM resource WHERE resource_id = " . $resource_id;
207                  $rs = xx_query($sql, $con);                  $rs = xx_tryquery($sql);
208                  $row = xx_fetch_array ($rs);                  $row = xx_fetch_array ($rs, xx_ASSOC);
209                  $infotype_id = $row["infotype_id"];                  $infotype_id = $row["infotype_id"];
210    
211                  // Check to see if it's already there.                  // Check to see if it's already there.
212                  $exists = existsResSub($con, $resource_id, $subject_id);                  $exists = existsResSub($resource_id, $subject_id);
213    
214                  // If already there, check to see whether the (N/A) infotype exists                  // If already there, check to see whether the (N/A) infotype exists
215                  if ($exists > 0) $existsNA = existsResSubNA($con, $resource_id, $subject_id);                  if ($exists > 0) $existsNA = existsResSubNA($resource_id, $subject_id);
216                                    
217                  // If (N/A) exists, disallow adding                              // If (N/A) exists, disallow adding            
218                  if ($existsNA > 0) $allow = 0;                  if ($existsNA > 0) $allow = 0;
# Line 275  function insertSubjectBuilder($con, $hig Line 227  function insertSubjectBuilder($con, $hig
227                          else $highlighted = 0;                          else $highlighted = 0;
228    
229                          // Fetch the master information type                          // Fetch the master information type
230                          $masterinfotype_id = lookupField($con, "infotype", "infotype_id", $infotype_id, "masterinfotype_id");                          $masterinfotype_id = lookupField("infotype", "infotype_id", $infotype_id, "masterinfotype_id");
231    
232                          // Build the SQL                          // Build the SQL
233                          $sql = "INSERT INTO res_sub_infotype (resource_id, subject_id, infotype_id, masterinfotype_id, highlighted) VALUES ("                          $sql = "INSERT INTO res_sub_infotype (resource_id, subject_id, infotype_id, masterinfotype_id, highlighted) VALUES ("
# Line 289  function insertSubjectBuilder($con, $hig Line 241  function insertSubjectBuilder($con, $hig
241                                  . ", "                                  . ", "
242                                  . $highlighted                                  . $highlighted
243                                  . ")";                                  . ")";
244                            xx_tryquery($sql);
                         // Debugging  
                         // printf("sql was: %s<BR>", $sql);  
   
                         if (!xx_query ($sql, $con)){  
                                 sql_err($sql);  
                                 xx_query ("UNLOCK TABLES", $con);  
                                 bailout();  
                         }  
                         else {  
                                 xx_query ("UNLOCK TABLES", $con);  
                         }  
245    
246                  }                  }
247    
# Line 314  function insertSubjectBuilder($con, $hig Line 255  function insertSubjectBuilder($con, $hig
255  /**********************************************************  /**********************************************************
256  Function: rqsPublish  Function: rqsPublish
257  Author: Paul Bramscher  Author: Paul Bramscher
258  Last Modified: 08.27.2003  Last Modified: 03.04.2004
259  ***********************************************************  ***********************************************************
260  Purpose:  Purpose:
261  Toggles the RQS published flag to 1 (true).  Toggles the RQS published flag to 1 (true).
262  **********************************************************/  **********************************************************/
263  function rqsPublish($con, $subject_id){  function rqsPublish($subject_id){
264    
265          $sql = "UPDATE subject SET rqs_published = '1' WHERE subject_id = "          $sql = "UPDATE subject SET rqs_published = '1' WHERE subject_id = "
266                  . $subject_id;                  . $subject_id;
267            xx_tryquery($sql);
         // Failed                                
         if (!xx_query ($sql, $con)){  
                 sql_err($sql);  
                 xx_query ("UNLOCK TABLES", $con);  
                 bailout();  
         }  
   
         // Succeeded  
         else {  
                 xx_query ("UNLOCK TABLES", $con);  
         }  
268    
269          header("Location: subject_builder.phtml?subject_id=" . $subject_id);          header("Location: subject_builder.phtml?subject_id=" . $subject_id);
270  }  }
# Line 343  function rqsPublish($con, $subject_id){ Line 273  function rqsPublish($con, $subject_id){
273  /**********************************************************  /**********************************************************
274  Function: rqsUnpublish  Function: rqsUnpublish
275  Author: Paul Bramscher  Author: Paul Bramscher
276  Last Modified: 08.27.2003  Last Modified: 03.04.2004
277  ***********************************************************  ***********************************************************
278  Purpose:  Purpose:
279  Toggles the RQS published flag to 0 (false).  Toggles the RQS published flag to 0 (false).
280  **********************************************************/  **********************************************************/
281  function rqsUnpublish($con, $subject_id){  function rqsUnpublish($subject_id){
282    
283          $sql = "UPDATE subject SET rqs_published = '0' WHERE subject_id = "          $sql = "UPDATE subject SET rqs_published = '0' WHERE subject_id = "
284                  . $subject_id;                  . $subject_id;
285            xx_tryquery($sql);
         // Failed                                
         if (!xx_query ($sql, $con)){  
                 sql_err($sql);  
                 xx_query ("UNLOCK TABLES", $con);  
                 bailout();  
         }  
   
         // Succeeded  
         else {  
                 xx_query ("UNLOCK TABLES", $con);  
         }  
286    
287          header("Location: subject_builder.phtml?subject_id=" . $subject_id);          header("Location: subject_builder.phtml?subject_id=" . $subject_id);
288  }  }
# Line 372  function rqsUnpublish($con, $subject_id) Line 291  function rqsUnpublish($con, $subject_id)
291  /**********************************************************  /**********************************************************
292  Function: updateRQSUpdate  Function: updateRQSUpdate
293  Author: Paul Bramscher  Author: Paul Bramscher
294  Last Modified: 08.27.2003  Last Modified: 03.04.2004
295  ***********************************************************  ***********************************************************
296  Purpose:  Purpose:
297  Modifies the RQS "last updated" fields accordingly.  Modifies the RQS "last updated" fields accordingly.
298  **********************************************************/  **********************************************************/
299  function updateRQSUpdate($con, $sess_staff_account, $subject_id) {  function updateRQSUpdate($sess_staff_account, $subject_id) {
300    
301          $sql = "UPDATE subject SET rqs_date_modified = now(), rqs_account_modified ='"          $sql = "UPDATE subject SET rqs_date_modified = now(), rqs_account_modified ='"
302                  . $sess_staff_account                  . $sess_staff_account
303                  . "' WHERE subject_id = "                  . "' WHERE subject_id = "
304                  . $subject_id;                  . $subject_id;
305            xx_tryquery($sql);
         // Failed                                
         if (!xx_query ($sql, $con)){  
                 sql_err($sql);  
                 xx_query ("UNLOCK TABLES", $con);  
                 bailout();  
         }  
   
         // Succeeded  
         else {  
                 xx_query ("UNLOCK TABLES", $con);  
         }  
306  }  }
307    
308    
309  /**********************************************************  /**********************************************************
310  Function: updateSubjectBuilder  Function: updateSubjectBuilder
311  Author: Paul Bramscher  Author: Paul Bramscher
312  Last Modified: 05.27.2003  Last Modified: 03.04.2004
313  ***********************************************************  ***********************************************************
314  Purpose:  Purpose:
315  Update the RQS resource-subject-infoype assignment.  Note  Update the RQS resource-subject-infoype assignment.  Note
316  that the incoming variables also include a flag for whether  that the incoming variables also include a flag for whether
317  the assignment is to be a highlighted or "core" resource.  the assignment is to be a highlighted or "core" resource.
318  **********************************************************/  **********************************************************/
319  function updateSubjectBuilder($con, $description, $descr_default, $highlighted,  function updateSubjectBuilder($description, $descr_default, $highlighted,
320          $infotype_id, $old_infotype_id, $resource_id, $subject_id) {          $infotype_id, $old_infotype_id, $resource_id, $subject_id) {
321    
322          // Clean up strings          // Clean up strings
# Line 424  function updateSubjectBuilder($con, $des Line 332  function updateSubjectBuilder($con, $des
332                  . " OR infotype_id = "                  . " OR infotype_id = "
333                  . $infotype_id                  . $infotype_id
334                  . ")";                  . ")";
335                    xx_tryquery($sql);
         if (!xx_query ($sql, $con)){  
                 sql_err($sql);  
                 xx_query ("UNLOCK TABLES", $con);  
                 bailout();  
         }  
         else {  
                 xx_query ("UNLOCK TABLES", $con);  
         }  
336                                    
337          // If the user opted for default resource description, void out the incoming $description;          // If the user opted for default resource description, void out the incoming $description;
338          if ($descr_default == 1) $description = "";          if ($descr_default == 1) $description = "";
339    
340          // Fetch the master information type          // Fetch the master information type
341          $masterinfotype_id = lookupField($con, "infotype", "infotype_id", $infotype_id, "masterinfotype_id");          $masterinfotype_id = lookupField("infotype", "infotype_id", $infotype_id, "masterinfotype_id");
342                    
343          // Insert the new row          // Insert the new row
344          $sql = "INSERT INTO res_sub_infotype (          $sql = "INSERT INTO res_sub_infotype (
# Line 460  function updateSubjectBuilder($con, $des Line 360  function updateSubjectBuilder($con, $des
360                          . "', '"                          . "', '"
361                          . $description                          . $description
362                          . "')";                          . "')";
363                    xx_tryquery($sql);
         if (!xx_query ($sql, $con)){  
                 sql_err($sql);  
                 xx_query ("UNLOCK TABLES", $con);  
                 bailout();  
         }  
         else {  
                 xx_query ("UNLOCK TABLES", $con);  
         }  
364    
365          header("Location: subject_builder.phtml?subject_id=" . $subject_id . "#" . $resource_id);          header("Location: subject_builder.phtml?subject_id=" . $subject_id . "#" . $resource_id);
366  }  }
367  ?>  ?>

Legend:
Removed from v.71  
changed lines
  Added in v.72

  ViewVC Help
Powered by ViewVC 1.1.26