Odyssey
admin_msg.prg
1 <?php
2 
3  $monLibrary= dirname(__FILE__) . "/../library";
4  $monIncludes= dirname(__FILE__) . "/../includes";
5  require_once("$monLibrary/cu_top.i");
6  require_once("$monLibrary/ck_hticket.i");
7  require_once("$monIncludes/cu_remote_top.prg");
8 
9  if (!CheckPerm($link, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR'])) {
10  // ** Permissions failed
11  // ** redirect to new page
12  header("Location: /hcuadm/hcu_noperm.prg");
13  exit;
14  }
15 
16 $dms_ok=array('act'=>'digits','active_date'=>'string','expires_on'=>'string',
17 'message'=>'string','msg_id'=>'string','subject'=>'string','livebatch'=>'string','o'=>'digits','d'=>'digits','msg'=>'string','Remote_Update'=>'array');
18 dms_import($dms_ok);
19 
20 
21  $self = $_SERVER['SCRIPT_NAME'];
22 
23  if (!isset($act)) $act = "2";
24 
25  if ($act == "3") {
26  // Perform the validate for saving here,
27  // Upon failure send back to the edit page,
28  // upone success go to the save code
29 
30  //Check the dates being passed
31  // ** Active Date
32  $error_msg = "";
33  if (!($active_date=mdydate($active_date))) {
34  $error_msg .= "<li>The active date does not appear to be valid.<br></li>";
35  } else {
36  $bdate = strtotime(mdydate($active_date));
37  }
38  if (strlen(trim($expires_on)) > 0) {
39  if (!($expires_on=mdydate($expires_on))) {
40  $error_msg .= "<li>The expires on date does not appear to be valid.<br></li>";
41  } else {
42  $edate = strtotime(mdydate($expires_on));
43  }
44  }
45  if ($bdate && $edate && $bdate >= $edate) {
46  $error_msg .= "<li>The expires on date should be after the start date.<br></li>";
47  }
48  if (strlen(trim($message)) == 0) {
49  $error_msg .= "<li>Why are you creating an admin message with no message, please add a message.<br></li>";
50  }else if (strlen(trim($message)) > 1000) {
51  $error_msg .= "<li>The message entered is longer than 1000. You entered " . strlen($message) . " characters.<br></li>";
52  }
53 
54  if ($error_msg == '') {
55  // Everything was validated, we now need to save the information, either insert for new or update for edited.
56 
57  $save_sql = "SELECT active_date FROM cuadmin_message WHERE id = '$msg_id'";
58  // Execute the query and find out how many rows are in the query
59  $db_result = db_query($save_sql, $link);
60 
61  $num_rows = db_num_rows($db_result);
62 
63  // Setup the expires on date
64  if ($expires_on == '')
65  $save_expires_on = "NULL";
66  else
67  $save_expires_on = "'" . prep_save($expires_on, 10) . "'";
68  if ($num_rows > 0 ) {
69  // UPDATE the information into the table
70  $qry_stmt = "UPDATE cuadmin_message
71  SET active_date = '" . prep_save($active_date, 10) . "',
72  expires_on = $save_expires_on,
73  message = '" . prep_save($message) . "',
74  subject = '" . prep_save($subject, 50) . "',
75  livebatch = '" . prep_save($livebatch, 1) . "'
76  WHERE id = '" . intval($msg_id) . "' ";
77  } else {
78  $idsql = "SELECT nextval('cuadmin_message_id_seq');";
79  $idrs = db_query($idsql, $link);
80  list($save_id) = db_fetch_array($idrs);
81  db_free_result($idrs);
82 
83  $qry_stmt = "INSERT INTO cuadmin_message
84  (id, active_date, expires_on, message, subject, livebatch)
85  VALUES
86  ( $save_id,
87  '" . prep_save($active_date, 10) . "', $save_expires_on,
88  '" . prep_save($message) . "',
89  '" . prep_save($subject, 50) . "',
90  '" . prep_save($livebatch, 1) . "') ";
91  }
92 
93  // Now pass the query to the Database
94  if (!($db_result=db_query($qry_stmt, $link))) {
95  $error_msg = "A problem occurred while saving your information, you may want to try later .";
96  $act = 1;
97  } else {
98 
99  // Only need to do this if at least one remote server was selected
100  if (Remote_Update_Selected()) {
101  if ($num_rows == 0) {
102  $remote_msg_id = intval($save_id);
103  } else {
104  $remote_msg_id = intval($msg_id);
105  }
106 
107  // ** NOW CHECK FOR SAVING TO A REMOTE SERVER
108  // ** Add Each field that will be updated
109  Remote_Field_Add("cuadmmsg", "msg_id", $remote_msg_id);
110  Remote_Field_Add("cuadmmsg", "active_date", $active_date);
111  Remote_Field_Add("cuadmmsg", "expires_on", $expires_on);
112  Remote_Field_Add("cuadmmsg", "message", $message);
113  Remote_Field_Add("cuadmmsg", "subject", $subject);
114  Remote_Field_Add("cuadmmsg", "livebatch", $livebatch);
115 
116  // ** Need to create the url I am going to send to the remote server
117  $Remote_Results = Remote_Update_Send("U", "cuadmmsg");
118 
119  }
120 
121  // Successful
122  header ("Location: $self?msg=" . urlencode("The information was saved!<br>$Remote_Results"));
123  exit;
124  }
125  } else {
126  // Error found go back to edit screen
127  $error_msg = "The following problems were found with the information given.<br>Please correct this and try again.<br><br>$error_msg";
128  $act = 1;
129  }
130 
131  } elseif ($act == "5") {
132  $sql = "DELETE FROM cuadmin_message
133  WHERE id = '" . intval($msg_id) . "' ";
134 
135  if (!($db_result=db_query($sql, $link))) {
136  header ("Location: $self?msg=" . urlencode("A problem occurred while deleting the message, you may want to try later."));
137  exit;
138  } else {
139  // ** DELETE on remote servers
140  if (Remote_Update_Selected()) {
141  // ** NOW CHECK FOR SAVING TO A REMOTE SERVER
142  // ** Add Each field that will be updated
143  Remote_Field_Add("cuadmmsg", "msg_id", intval($msg_id));
144 
145  // ** Need to create the url I am going to send to the remote server
146  $Remote_Results = Remote_Update_Send("D", "cuadmmsg");
147 
148  }
149  // Successful
150  header ("Location: $self?msg=" . urlencode("The message was deleted!"));
151  exit;
152  }
153  }
154 
155 
156 
157  switch ($act):
158  case "1": // Add/Edit Admin Messages
159  cu_header("Credit Union Admin Messages");
160 ?>
161  <form action="<?php echo $self; ?>?act=3" method="post">
162  <?php
163  // Connect to the database - get the team information from the database
164  $query = "select id, to_char(active_date, 'MM/DD/YYYY') as a_date,
165  to_char(expires_on, 'MM/DD/YYYY') as e_on, message,
166  subject, livebatch
167  from cuadmin_message
168  where id = '$msg_id'";
169 
170  $result = db_query($query, $link);
171  // Now fetch the row
172  $msg_row = db_fetch_object($result);
173  $num_rows = db_num_rows($result);
174  ?>
175  <p>&nbsp;
176  <p>
177  <?php
178  if (isset($form_err) && strlen($form_err) > 0)
179  printf("\n<font color=\"red\">Errors found before saving the information. Please review errors at bottom of screen.\n<p></font>");
180  ?>
181  <center>
182  <table width="80%" cellpadding="2" cellspacing="0" border="0" class="dmsbg"><tr><td>
183  <table width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor=white>
184  <tr>
185  <td colspan="2" class="bar" align="center">
186  <?php if($num_rows > 0): ?>
187  EDIT ADMIN MESSAGE
188  <input type="hidden" name="msg_id" value="<?php echo $msg_row->id; ?>">
189  <?php else: ?>
190  ADD ADMIN MESSAGE
191  <?php endif; ?>
192  </td>
193  </tr>
194  <?php if ($error_msg != ''): ?>
195  <tr>
196  <td colspan="2" align="center" class="err">
197  <?php echo $error_msg; ?>
198  </td>
199  </tr>
200  <?php endif; ?>
201  <tr>
202  <td nowrap align="right" class="hdr">
203  Active Date:
204  </td>
205  <td nowrap class="dtl">
206  <?php
207  if ( isset($active_date))
208  $cu_info = set_string($active_date);
209  elseif ($num_rows > 0)
210  $cu_info = htmlspecialchars(trim($msg_row->a_date));
211  else
212  $cu_info = date("m/d/Y");
213  ?>
214  <input type="text" name="active_date" size="10" maxlength="10" value="<?php echo $cu_info ?>">
215  </td>
216  </tr>
217  <tr>
218  <td nowrap align="right" class="hdr">
219  Expires On:
220  </td>
221  <td nowrap class="dtl">
222  <?php
223  $cu_info = "";
224  if ( isset($expires_on))
225  $cu_info = set_string($expires_on);
226  elseif ($num_rows > 0)
227  $cu_info = htmlspecialchars(trim($msg_row->e_on));
228  ?>
229  <input type="text" name="expires_on" size="10" maxlength="10" value="<?php echo $cu_info ?>">
230  <font size=1 color="red">Note: Leave blank for a continuous message</font>
231  </td>
232  </tr>
233  <tr>
234  <td nowrap align="right" class="hdr" valign="top">
235  Message:
236  </td>
237  <td nowrap class="dtl">
238  <?php
239  $cu_info = "";
240  if ( isset($message))
241  $cu_info = set_string($message);
242  elseif ($num_rows > 0)
243  $cu_info = htmlspecialchars(trim($msg_row->message));
244  ?>
245  <textarea name="message" rows="10" cols="40"><?php echo $cu_info; ?></textarea>
246  </td>
247  </tr>
248  <tr>
249  <td nowrap align="right" class="hdr">
250  Subject:
251  </td>
252  <td nowrap class="dtl">
253  <?php
254  $cu_info = "";
255  if ( isset($subject))
256  $cu_info = set_string($subject);
257  elseif ($num_rows > 0)
258  $cu_info = htmlspecialchars(trim($msg_row->subject));
259  ?>
260  <input type="text" name="subject" size="40" maxlength="50" value="<?php echo $cu_info ?>">
261  </td>
262  </tr>
263  <tr>
264  <td nowrap align="right" class="hdr">
265  Show on which servers?
266  </td>
267  <td nowrap class="dtl">
268  <?php
269  $cu_info = "";
270  if ( isset($livebatch))
271  $cu_info = set_string($livebatch);
272  elseif ($num_rows > 0)
273  $cu_info = htmlspecialchars(trim($msg_row->livebatch));
274  ?>
275  <select name="livebatch" size=1>
276  <option value="A" <?php echo ($cu_info == "A" ? "SELECTED" : ""); ?>>All Servers</option>
277  <option value="B" <?php echo ($cu_info == "B" ? "SELECTED" : ""); ?>>Batch Only</option>
278  <option value="L" <?php echo ($cu_info == "L" ? "SELECTED" : ""); ?>>Live Only</option>
279  </select>
280  </td>
281  </tr>
282  <tr>
283  <td class='dtl'>&nbsp;</td>
284  <td nowrap class='dtl'>
285  <?php remote_update_list(); ?>
286  </td>
287  </tr>
288  <tr>
289  <td class='dtl'>&nbsp;</td>
290  <td nowrap class='dtl' colspan="1">
291  <input type="submit" name="Save" Value="Save">
292  <input type="button" name="Cancel" Value="Cancel" onClick="document.location='<?php echo $self; ?>'">
293  </td>
294  </tr>
295  </table>
296 
297  <?php // If the error value is here then print it at the end
298  if (isset($form_err)) {
299  echo $form_err;
300  }
301 
302  echo "</td></tr></table>";
303  break;
304  case "2":
305  cu_header("CU Message List");
306  ?>
307  <form>
308 
309  <?php
310  $order_by = "";
311  $o_desc = array();
312  switch ($o) {
313  case 2:
314  $order_by = "expires_on";
315  if (!isset($d))
316  $o_desc[2] = "&d=1";
317  break;
318  case 3:
319  $order_by = "substr(message, 1, 50)";
320  if (!isset($d))
321  $o_desc[3] = "&d=1";
322  break;
323  case 4:
324  $order_by = "subject";
325  if (!isset($d))
326  $o_desc[4] = "&d=1";
327  break;
328  case 5:
329  $order_by = "livebatch";
330  if (!isset($d))
331  $o_desc[5] = "&d=1";
332  break;
333  default:
334  if (!isset($o)) {
335  $order_by = "active_date";
336  if (!isset($d))
337  $order_by .= " desc";
338 
339  } else {
340  $order_by = "active_date";
341  if (!isset($d))
342  $o_desc[1] = "&d=1";
343  }
344  break;
345  }
346  if (isset($d)) {
347  $order_by .= " desc";
348  }
349  // Connect to the data and retrieve the current list of Home CU Products
350  $query = "SELECT id, to_char(active_date, 'MM/DD/YYYY') as a_date,
351  to_char(expires_on, 'MM/DD/YYYY') as e_on, message,
352  subject, livebatch
353  FROM cuadmin_message
354  ORDER BY $order_by";
355 
356  $prod_result = db_query($query, $link);
357 
358  ?>
359 
360  <!-- Print out the top of the table -->
361 
362  <table border="0" cellpadding="2" callspacing="0" align="center" width="80%" class="dmsbg"><tr><td>
363  <table border="0" cellpadding=2 cellspacing="0" align="center" width="100%">
364  <tr>
365  <td colspan="6" class="bar" align="center">
366  CU Admin Messages List
367  </td>
368  </tr>
369  <?php if (isset($msg)): ?>
370  <tr>
371  <td colspan="6" class="err" align="center">
372  <font color="#FF8080"><?php echo $msg; ?></font>
373  </td>
374  </tr>
375  <?php endif; ?>
376  <tr>
377  <td class="hdr" align="left" valign="top" nowrap>
378  <a href="<?php echo $self; ?>?o=1<?php echo $o_desc[1]; ?>">Active Date</a>
379  </td>
380  <td class="hdr" align="left" valign="top" nowrap>
381  <a href="<?php echo $self; ?>?o=2<?php echo $o_desc[2]; ?>">Exipires On</a>
382  </td>
383  <td class="hdr" align="left" valign="top">
384  <a href="<?php echo $self; ?>?o=3<?php echo $o_desc[3]; ?>">Message</a>
385  </td>
386  <td class="hdr" align="left" valign="top">
387  <a href="<?php echo $self; ?>?o=4<?php echo $o_desc[4]; ?>">Subject</a>
388  </td>
389  <td class="hdr" align="left" valign="top">
390  <a href="<?php echo $self; ?>?o=5<?php echo $o_desc[5]; ?>">Live/Batch?</a>
391  </td>
392  <td class="hdr" align="center" valign="top">
393  Select
394  </td>
395  </tr>
396  <?php
397  $RGB = "odd";
398  $row = 0;
399  while ($prod_row = db_fetch_object($prod_result, $row)):
400  $row++;
401  ?>
402  <tr class="<?php echo $RGB; ?>_small">
403  <td nowrap valign="top">
404  <?php echo trim($prod_row->a_date) ?>
405  </td>
406  <td nowrap valign="top">
407  <?php echo trim($prod_row->e_on) ?>
408  </td>
409  <td valign="top">
410  <?php
411  echo trim(htmlspecialchars((strlen(trim($prod_row->message)) > 100 ? substr(trim($prod_row->message), 0, 100) . "..." : trim($prod_row->message))));
412  ?>
413  </td>
414  <td valign="top">
415  <?php echo trim($prod_row->subject) ?>
416  </td>
417  <td nowrap valign="top">
418  <?php
419  switch ($prod_row->livebatch) {
420  case "L":
421  echo "Live Only";
422  break;
423  case "B":
424  echo "Batch Only";
425  break;
426  case "A":
427  echo "All Servers";
428  break;
429  }
430  ?>
431  </td>
432  <td nowrap valign="top">
433  <a href="<?php echo $self; ?>?act=1&msg_id=<?php echo trim($prod_row->id) ?>">Edit</a>
434  &nbsp;|&nbsp;
435  <a href="<?php echo $self; ?>?act=4&msg_id=<?php echo trim($prod_row->id) ?>">Delete</a>
436  </td>
437  </tr>
438  <?php
439  $RGB = ($RGB == "odd" ? "even" : "odd");
440  endwhile; ?>
441 
442  <tr>
443  <td colspan="6" class="dtl">
444  <a href="<?php echo $self; ?>?act=1" target="parent">Add Admin Message</a>
445  &nbsp;|&nbsp;
446  <a href="<?php echo $infourl ?>/hcuadm/cuilist.prg" target="parent">Credit Union List</a>
447  </td>
448  </tr>
449  </table>
450  </td></tr></table>
451 <?php
452  break;
453  case "4":
454  cu_header ("Delete Admin Message");
455 ?>
456  <?php
457  // Connect to the database - get the team information from the database
458  $query = "select *
459  from cuadmin_message
460  where id = '$msg_id'";
461  $result = db_query($query, $link);
462  // Now fetch the row
463  $msg_row = db_fetch_array($result);
464  $num_rows = db_num_rows($result);
465 
466  echo "<center><table width=\"40%\" cellpadding=\"1\" cellspacing=\"1\" border=\"0\" class=\"dmsbg\"><tr><td>";
467  if ($num_rows > 0): ?>
468  <form action="<?php echo $self; ?>?act=5" method="post">
469  <input type="hidden" name="act" value="5">
470  <table width="100%" cellpadding="1" cellspacing="1" border="0">
471  <tr>
472  <td class="bar" align="center">
473  DELETE ADMIN MESSAGE
474  <input type="hidden" name="msg_id" value="<?php echo $msg_row['id']; ?>">
475  </td>
476  </tr>
477  <tr>
478  <td align="center" class="dtl">
479  Hi, you have selected to delete an admin message.<br>
480  The message contains the subject <b><?php echo htmlspecialchars(trim($msg_row['subject'])); ?></b>.<br><br>
481  Please verify this before deleting, after deleting said message, <br>you will need to reenter it if you didn't
482  mean to delete it.
483  </td>
484  </tr>
485  <tr>
486  <td nowrap class='dtl'>
487  <table width="250" align='center'><tr><td>
488  <?php remote_update_list(); ?>
489  </td></tr></table>
490  </td>
491  </tr>
492  <tr>
493  <td align="right" class="hdr" nowrap>
494  <input type='submit' name='btnSubmit' value="Please delete this message">
495  &nbsp;&nbsp;
496  <input type="button" name="btnCancel" value="I don't want to do this" onclick="document.location='<?php echo $self; ?>'">
497  </td>
498  </tr>
499  </table>
500  <?php else: ?>
501  <table width="100%" cellpadding="1" cellspacing="1" border="0">
502  <tr>
503  <td class="bar" align="center">
504  DELETE ADMIN MESSAGE - Problem Encountered
505  </td>
506  </tr>
507  <tr>
508  <td class="dtl" align="center">
509  Problem deleting your admin message. <br>
510  It appears the message has already been deleted or never existed.<br>
511  Please return to the <a href="<?php echo $self; ?>">menu</a> and try again.
512  </td>
513  </tr>
514  </table>
515  <?php endif;
516 
517  echo "</td></tr></table>";
518  break;
519  default:
520  cu_header("Error Displaying Form");
521  print ("<form>");
522  printError("Requested form not found!<br>Cancelling action.");
523  endswitch;
524  ?>
525  </form>
526  </body>
527 </html>
528