Odyssey
cuprogmntc.prg
1 <?php
2  $monLibrary= dirname(__FILE__) . "/../library";
3  $monIncludes= dirname(__FILE__) . "/../includes";
4  require_once("$monLibrary/cu_top.i");
5  require_once("$monLibrary/ck_hticket.i");
6  require_once("$monIncludes/cu_remote_top.prg");
7 
8  if (!CheckPerm($link, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR'])) {
9  // ** Permissions failed
10  // ** redirect to new page
11  header("Location: /hcuadm/hcu_noperm.prg");
12  exit;
13  }
14 
15 $dms_ok=array('act'=>'string','pc'=>'string','program'=>'string','displaytext'=>'string','sort_order'=>'string','description'=>'string','def_set'=>'string','form_err'=>'string','msg'=>'string','Remote_Update'=>'array');
16 
17 dms_import($dms_ok);
18 
19  if (!isset($act)) $act = "2";
20 
21  switch ($act){
22  case "1": // Edit Program Entry
23  cu_header("Edit Program Entry");
24  print '<form action="cuprogmntc.prg?act=3" method="post">
25  <p>&nbsp;<p>';
26  $query = "select *
27  from cuadminprogs
28  where program = '$pc'";
29  $result = db_query($query, $link);
30  $cuprog_row = db_fetch_object($result);
31  $num_rows = db_num_rows($result);
32 
33  print "<center><table cellpadding=3 cellspacing=0 border=0 class='dmsbg' width=500><tr><td>";
34  print '<table cellpadding="1" cellspacing="0" border="0" width="100%" bgcolor=white><tr>
35  <td colspan="2" class="bar" align="center">';
36  if($num_rows > 0){
37  print "EDIT CU PROGRAM ENTRY";
38  } else {
39  print "ADD CU PROGRAM ENTRY";
40  }
41  print "
42  </td>
43  </tr> ";
44  if (isset($form_err) && strlen($form_err) > 0)
45  printf("
46  <tr>
47  <td colspan=2 class='err'>
48  Errors found before saving the information. Please review errors at bottom of screen.
49  </td>
50  </tr> ");
51  print <<< EOF
52  <tr>
53  <td nowrap align="right" class="hdr">
54  Program:
55  </td>
56  <td nowrap class='dtl'>
57 EOF;
58  if ($num_rows == 0){
59  if ( isset($program)){
60  $cu_info = set_string($program);
61  } else {
62  $cu_info = htmlspecialchars(trim($cuprog_row->program));
63  }
64  print <<<EOF
65  <input type="text" name="program" size="20" maxlength="20" value="$cu_info">
66 EOF;
67  } else {
68  echo $cuprog_row->program;
69  print '<input type="hidden" name="program" value="' . htmlspecialchars(trim($cuprog_row->program)) . '">';
70  }
71  print <<<EOF
72  </td>
73  </tr>
74  <tr>
75  <td nowrap align="right" class="hdr">
76  Name:
77  </td>
78  <td nowrap class='dtl'>
79 EOF;
80  if ( isset($displaytext))
81  $cu_info = set_string($displaytext);
82  else
83  $cu_info = htmlspecialchars(trim($cuprog_row->displaytext));
84 print <<<EOF
85  <input type="text" name="displaytext" size="30" maxlength="30" value="$cu_info">
86  </td>
87  </tr>
88  <tr>
89  <td nowrap align="right" class="hdr">
90  Order Value:
91  </td>
92  <td nowrap class='dtl'>
93 EOF;
94  if ( isset($displaytext))
95  $cu_info = set_string($sort_order);
96  else
97  $cu_info = htmlspecialchars(trim($cuprog_row->sort_order));
98 print <<<EOF
99  <input type="text" name="sort_order" size="4" maxlength="4" value="$cu_info">
100  </td>
101  </tr>
102  <tr>
103  <td nowrap align="right" class="hdr">
104  Default Settings:
105  </td>
106  <td nowrap class='dtl'>
107 EOF;
108  if ( isset($displaytext))
109  $cu_info = set_string($def_set);
110  else
111  $cu_info = htmlspecialchars(trim($cuprog_row->def_set));
112 ?>
113  <select name="def_set" size="1">
114  <option value="0" <?php echo ($cu_info == 0 ? "SELECTED" : "") ?>>Off</option>
115  <option value="1" <?php echo ($cu_info == 1 ? "SELECTED" : "") ?>>On</option>
116  </select>
117  </td>
118  </tr>
119  <tr>
120  <td nowrap align="right" class="hdr" valign="top">
121  Comments:
122  </td>
123  <td nowrap class='dtl'>
124 <?php
125  if(isset($description))
126  $cu_info=set_string($description);
127  else
128  $cu_info=htmlspecialchars(trim($cuprog_row->description));
129 print <<<EOF
130  <textarea name="description" rows=5 cols=40 wrap="physical">$cu_info</textarea>
131  </td>
132  </tr>
133  <tr>
134  <td class='dtl'>&nbsp;</td>
135  <td nowrap class='dtl'>
136 EOF;
137  remote_update_list();
138 print <<<EOF
139  </td>
140  </tr>
141  <tr>
142  <td class='dtl'>&nbsp;</td>
143  <td nowrap class='dtl'>
144  <input type="submit" name="Save" Value="Save">
145  <input type="button" name="Cancel" Value="Cancel" onClick="document.location='cuprogmntc.prg'">
146  </td>
147  </tr>
148 EOF;
149 
150  // If the error value is here then print it at the end
151  if (isset($form_err)) {
152  echo "<tr><td class='err' colspan='2'>$form_err</td></tr>";
153  }
154  echo "
155  </table>
156  </td></tr></table> ";
157  break;
158  case "2":
159  cu_header("CU Admin Programs");
160 print "<form>";
161 
162  // Connect to the data and retrieve the current list of Home CU Products
163  $query = "SELECT program, displaytext, sort_order, def_set
164  FROM cuadminprogs ORDER BY sort_order, program";
165  $prod_result = db_query($query, $link);
166  print <<<EOF
167 
168  <table border="0" cellpadding="3" cellspacing="1" align="center" class='dmsbg' width=500><tr><td>
169  <table border="0" cellpadding="2" cellspacing="0" align="center" bgcolor=white width="100%">
170  <tr>
171  <td colspan="5" class="bar" align="center">
172  CU ADMIN PROGRAMS LIST
173  </td>
174  </tr>
175 EOF;
176  if (isset($msg)) {
177  print "
178  <tr>
179  <td colspan=\"5\" class=\"msg\" align=\"center\"> " .
180  $msg
181  . "</td>
182  </tr> ";
183  }
184 print <<<EOF
185  <tr>
186  <td class="hdr" align="left">
187  Program
188  </td>
189  <td class="hdr" align="left">
190  Display Text
191  </td>
192  <td class="hdr" align="left">
193  Order Value
194  </td>
195  <td class="hdr" align="left">
196  Default
197  </td>
198  <td class="hdr" align="center">
199  Select
200  </td>
201  </tr>
202 EOF;
203  $RGB = "odd";
204  $row = 0;
205  while ($prod_row = db_fetch_object($prod_result, $row)){
206  $row++;
207  $disp_def_set = ($prod_row->def_set == "1" ? "On" : "Off");
208  print <<<EOF
209  <tr class="$RGB">
210  <td nowrap >
211  {$prod_row->program}
212  </td>
213  <td nowrap >
214  {$prod_row->displaytext}
215  </td>
216  <td nowrap >
217  {$prod_row->sort_order}
218  </td>
219  <td nowrap >
220  $disp_def_set
221  </td>
222  <td nowrap >
223  <a href="cuprogmntc.prg?act=1&pc={$prod_row->program}">Edit</a>
224  </td>
225  </tr>
226 EOF;
227  $RGB = ($RGB == "odd" ? "even" : "odd");
228  }
229 
230 print <<<EOF
231  <tr>
232  <td colspan="4">
233  <a href="cuprogmntc.prg?act=1">Add Admin Program</a>
234  &nbsp;|&nbsp;
235  <a href="$infourl/hcuadm/cuilist.prg" target="parent">Credit Union List</a>
236  </td>
237  </tr>
238  </table>
239  </td></tr></table>
240 EOF;
241  break;
242  case "3":
243  cu_header("Save Admin Program");
244  // Setup a function to go back to the CU Edit form, if anything went wrong
245  function save_fail($msg){
246  global $program;
247  printf("<script language=\"javascript\">\n");
248  printf("document.forms[0].elements[\"form_err\"].value = '%s';\n", $msg);
249  printf("document.forms[0].action=\"cuprogmntc.prg?act=1&pc=%s\";\n", $program);
250  printf("document.forms[0].method=\"post\";\n");
251  printf("document.forms[0].submit();\n");
252  printf("</script>");
253  printf("\n</form>\n </body>\n </html>\n");
254  exit();
255  }
256 
257 
258  print '<form action="cuprogmntc?act=1" method="post">';
259  $errors_found = "No";
260  $err_msg = "";
261 
262 
263  /* VALIDATE THE INFORMATION - whether it's been saved before or NOT
264  After validation fails it will send the information back to the edit form
265  So it looks like it did before, the fail information will be at the bottom of the
266  screen.
267 
268  */
269  $err_msg="";
270 
271  // Now we need to load all the fields from the CU form, and post them back
272  // So the user does not have to press the back button.
273  // Load all the Fields from the previous form into hidden fields on this form
274  print <<<EOF
275  <!-- LOAD ALL HIDDEN FIELDS -->
276 
277  <!-- Description -->
278  <input type="hidden" name="program" value="$program">
279  <input type="hidden" name="displaytext" value="$displaytext">
280  <input type="hidden" name="sort_order" value="$sort_order">
281  <input type="hidden" name="description" value="$description">
282  <input type="hidden" name="def_set" value="$def_set">
283 
284  <!-- Create a hidden field for the form error -->
285  <input type="hidden" name="form_err" value="">
286 EOF;
287  if (strlen($err_msg) > 0){
288  //If an error was found post the information back to the CU edit form here
289  $form_err = sprintf("<font size=\"+1\">ERROR! Problems with the credit union information found: <BR></font>");
290  $form_err .= sprintf("The following errors will need to be corrected before you will be allowed to save the form.");
291  $form_err .= sprintf("<P> <font color=red>%s</font>", $err_msg);
292  save_fail($form_err);
293  } else {
294 
295  // Everything was validated, we now need to save the information, either insert for new or update for edited.
296 
297  $save_sql = "SELECT program FROM cuadminprogs
298  WHERE program = '$program'";
299  // Execute the query and find out how many rows are in the query
300  $db_result = db_query($save_sql, $link);
301 
302  $num_rows = db_num_rows($db_result);
303  $set_default_off = false;
304  if ($num_rows > 0 ) {
305  // UPDATE the information into the table
306  $qry_stmt = sprintf("UPDATE cuadminprogs ");
307  $qry_stmt .= sprintf("SET displaytext ='%s', ",prep_save($displaytext));
308  $qry_stmt .= sprintf("sort_order ='%s', ",intval($sort_order));
309  $qry_stmt .= sprintf("description = '%s', ", prep_save($description));
310  $qry_stmt .= sprintf("def_set = '%s' ", prep_save($def_set));
311  $qry_stmt .= sprintf("WHERE program = '%s'; ",$program);
312  } else {
313  $qry_stmt = sprintf("INSERT INTO cuadminprogs ");
314  $qry_stmt .= sprintf("(program, displaytext, sort_order, description, def_set) ");
315  $qry_stmt .= sprintf(" VALUES (");
316  $qry_stmt .= sprintf("'%s', '%s', '%s', '%s', '%s'); ",
317  prep_save($program),
318  prep_save($displaytext),
319  intval($sort_order),
320  prep_save($description),
321  prep_save($def_set));
322 
323  if (intval($def_set) != 1)
324  $set_default_off = true; // if this is set, then go thru ALL CU's and add this new form to the cuadminexclude table
325  }
326  // Now pass the query to the Database
327 
328  if (!($db_result=db_query($qry_stmt, $link))) {
329  // A problem was encoutered with saving the data - report the message
330  $form_err = sprintf("<br>");
331  $form_err .= sprintf("<font face=\"Arial\" size=\"2\">Unable to Save Record!</font><br>");
332  save_fail($form_err);
333  } else {
334  printError(sprintf("Record Saved Successfully.<br>
335  <a href=\"cuprogmntc.prg?act=2\" target=\"CONTENT\">CU Admin Program List</a>"));
336 
337  // Only need to do this if at least one remote server was selected
338  if (Remote_Update_Selected()) {
339  // ** NOW CHECK FOR SAVING TO A REMOTE SERVER
340  // ** Add Each field that will be updated
341  Remote_Field_Add("cuprg", "program", $program);
342  Remote_Field_Add("cuprg", "displaytext", $displaytext);
343  Remote_Field_Add("cuprg", "sort_order", $sort_order);
344  Remote_Field_Add("cuprg", "description", $description);
345  Remote_Field_Add("cuprg", "def_set", $def_set);
346  // ** Need to create the url I am going to send to the remote server
347  $Remote_Results = Remote_Update_Send("U", "cuprg");
348 
349  // RESET THE FIELDS FOR POSSIBLE USE BELOW
350  Remote_Fields_Reset();
351 
352  }
353 
354  if ($set_default_off) {
355  // Now add the option for all cu's to the exclude list
356  // use an insert from the cuadmin table -- this will be the credit unions for each individual server where the script is executed
357  $sql = "INSERT INTO cuadminexclude (cu, user_name, program)
358  (SELECT cu, trim(user_name), '" . trim(prep_save($program)) . "'
359  FROM cuadmin) ";
360  $update_rs = db_query($sql, $link);
361  db_free_result($update_rs);
362  if (Remote_Update_Selected()) {
363  Remote_Field_Add("cuprg", "program", $program);
364  // *** THIS IS A SPECIAL ROUTINE
365  $Remote_Results .= Remote_Update_Special("excludelist");
366 
367  }
368 
369  }
370  echo $Remote_Results;
371 
372  header ("Location: " . $_SERVER['PHP_SELF'] . "?msg=" . urlencode($Remote_Results));
373 /*
374  print <<< js
375  <script language="javascript">
376  document.location = "cuprogmntc.prg";
377  </script>
378 js;
379 */
380  }
381  }
382 
383  break;
384  default:
385  cu_header("Error Displaying Form");
386  print ("<form>");
387  printError("Requested form not found!<br>Cancelling action.");
388  }
389  print "</form></body></html>";
390