Odyssey
cutrans.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('trancode'=>'string','trandesc'=>'string','transpec'=>'string',
16 'Save'=>'string','form_err'=>'string','act'=>'string','tc'=>'string',
17 'msg'=>'string','Remote_Update'=>'array');
18 
19 dms_import($dms_ok);
20 
21  if (!isset($act)) $act = "2";
22 
23  switch ($act):
24  case "1": // Edit Cu Transactions
25  cu_header("Edit CU Transactions");
26 ?>
27  <form action="cutrans.prg?act=3" method="post">
28  <?php
29  // Connect to the database - get the team information from the database
30  $query = "select *
31  from cutrans
32  where trancode = '$tc'";
33  $result = db_query($query, $link);
34  // Now fetch the row
35  $cutrans_row = db_fetch_object($result);
36  $num_rows = db_num_rows($result);
37  ?>
38  <p>&nbsp;
39  <p>
40  <?php
41  if (isset($form_err) && strlen($form_err) > 0)
42  printf("\n<font color=\"red\">Errors found before saving the information. Please review errors at bottom of screen.\n<p></font>");
43  ?>
44  <center>
45  <table cellpadding="3" cellspacing="0" border="0" class="dmsbg" width="500"><tr><td>
46  <table cellpadding="2" cellspacing="0" border="0" bgcolor=white width="100%">
47  <tr>
48  <td colspan="2" class="bar" align="center">
49  <?php if($num_rows > 0): ?>
50  EDIT CU TRANSACTION CODE
51  <?php else: ?>
52  ADD CU TRANSACTION CODE
53  <?php endif; ?>
54  </td>
55  </tr>
56  <tr>
57  <td nowrap align="right" class="hdr">
58  CU Transaction Code:
59  </td>
60  <td nowrap class='dtl'>
61  <?php if ($num_rows == 0): ?>
62  <?php
63  if ( isset($trancode))
64  $cu_info = set_string($trancode);
65  else
66  $cu_info = htmlspecialchars(trim($cutrans_row->home_cu_code));
67  ?>
68  <input type="text" name="trancode" size="4" maxlength="2" value="<?php echo $cu_info ?>">
69  <?php else: ?>
70  <?php echo $cutrans_row->trancode ?>
71  <input type="hidden" name="trancode" value="<?php echo htmlspecialchars(trim($cutrans_row->trancode)) ?>">
72  <?php endif; ?>
73  </td>
74  </tr>
75  <tr>
76  <td nowrap align="right" class="hdr">
77  Description:
78  </td>
79  <td nowrap class='dtl'>
80  <?php
81  if ( isset($trandesc))
82  $cu_info = set_string($trandesc);
83  else
84  $cu_info = htmlspecialchars(trim($cutrans_row->trandesc));
85  ?>
86  <input type="text" name="trandesc" size="40" maxlength="40" value="<?php echo $cu_info ?>"><font color="green" size="2"><br>New descriptions should also be added to the message dictionary <br>for internationalized version.</font>
87  </td>
88  </tr>
89  <tr>
90  <td nowrap align="right" class="hdr">
91  Special Processing:
92  </td>
93  <td nowrap class='dtl'>
94  <?php
95  if ( isset($transpec))
96  $cu_info = set_string($transpec);
97  else
98  $cu_info = htmlspecialchars(trim($cutrans_row->specialproc));
99  ?>
100  <input type="text" name="transpec" size="4" maxlength="1" value="<?php echo $cu_info ?>"><font color="green" size="2"><br>Set to 1 for Credit Card and other payments to outside entities.</font>
101  </td>
102  </tr>
103  <tr>
104  <td class='dtl'>&nbsp;</td>
105  <td nowrap class='dtl'>
106  <?php remote_update_list(); ?>
107  </td>
108  </tr>
109  <tr>
110  <td class='dtl'>&nbsp;</td>
111  <td nowrap class='dtl'>
112  <input type="submit" name="Save" Value="Save">
113  <input type="button" name="Cancel" Value="Cancel" onClick="document.location='cutrans.prg'">
114  </td>
115  </tr>
116  <?php // If the error value is here then print it at the end
117  if (isset($form_err)) {
118  echo "<tr><td colspan=2 class='err'>$form_err</td></tr>";
119  }
120  echo "
121  </table>
122  </td></tr></table> ";
123  break;
124  case "2":
125  cu_header("CU Transaction Codes");
126  ?>
127  <form>
128 
129  <?php
130  // Connect to the data and retrieve the current list of Home CU Products
131  $query = "SELECT * FROM cutrans ORDER BY trancode";
132  $prod_result = db_query($query, $link);
133 
134  ?>
135 
136  <!-- Print out the top of the table -->
137 
138  <table border="0" cellpadding="3" cellspacing="0" align="center" width="500" class="dmsbg"><tr><td>
139  <table border="0" cellpadding="2" cellspacing="0" align="center" width="100%" bgcolor=white>
140  <tr>
141  <td colspan="4" class="bar" align="center">
142  CU TRANSACTION CODES LIST
143  </td>
144  </tr>
145  <?php if (isset($msg)): ?>
146  <tr>
147  <td colspan="5" class="msg" align="center">
148  <?php echo $msg; ?>
149  </td>
150  </tr>
151  <?php endif; ?>
152  <tr>
153  <td colspan="5" style="background:#f8f8f8;color: #ee5555;font-style:italic" align="left">
154  ** NOTE: The description for any 'Special Processing' transcation code MUST be added to the translation table
155  </td>
156  </tr>
157  <tr>
158  <td class="hdr" align="center">
159  CU Tranasction Code
160  </td>
161  <td class="hdr" align="center">
162  Description
163  </td>
164  <td class="hdr" align="center">
165  Special Processing
166  </td>
167  <td class="hdr" align="center">
168  Select
169  </td>
170  </tr>
171  <?php
172  $RGB = "odd";
173  $row = 0;
174  while ($prod_row = db_fetch_object($prod_result, $row)):
175  $row++;
176  ?>
177  <tr class="<?php echo $RGB; ?>">
178  <td nowrap >
179  <?php echo trim($prod_row->trancode) ?>
180  </td>
181  <td nowrap >
182  <?php echo trim($prod_row->trandesc) ?>
183  </td>
184  <td nowrap align='center'>
185  <?php echo (trim($prod_row->specialproc) == '0' ? '' : trim($prod_row->specialproc)) ?>
186  </td>
187  <td nowrap >
188  <a href="cutrans.prg?act=1&tc=<?php echo trim($prod_row->trancode) ?>">Edit</a>
189  <?php /*&nbsp;|&nbsp;
190  <a href="">Delete</a>
191  */ ?>
192  </td>
193  </tr>
194  <?php
195  $RGB = ($RGB == "odd" ? "even" : "odd");
196  endwhile; ?>
197 
198  <tr>
199  <td colspan="3">
200  <a href="cutrans.prg?act=1">Add CU Transaction Code</a>
201  &nbsp;|&nbsp;
202  <a href="<?php echo $infourl ?>/hcuadm/cuilist.prg" target="parent">Credit Union List</a>
203  </td>
204  </tr>
205  </table>
206  </td></tr></table>
207 <?php
208  break;
209  case "3":
210  cu_header("Save Transaction Code");
211  // Setup a function to go back to the CU Edit form, if anything went wrong
212  function save_fail($msg){
213  global $trancode;
214  printf("<script language=\"javascript\">\n");
215  printf("document.forms[0].elements[\"form_err\"].value = '%s';\n", $msg);
216  printf("document.forms[0].action=\"cutrans.prg?act=1&tc=%s\";\n", $trancode);
217  printf("document.forms[0].method=\"post\";\n");
218  printf("document.forms[0].submit();\n");
219  printf("</script>");
220  printf("\n</form>\n </body>\n </html>\n");
221  exit();
222  }
223 
224  ?>
225 
226  <form action="cutrans.prg?act=1" method="post">
227  <?php
228  $errors_found = "No";
229  $err_msg = "";
230 
231 
232  /* VALIDATE THE INFORMATION - whether it's been saved before or NOT
233  After validation fails it will send the information back to the edit form
234  So it looks like it did before, the fail information will be at the bottom of the
235  screen.
236 
237  */
238  $err_msg="";
239 
240  // Now we need to load all the fields from the CU form, and post them back
241  // So the user does not have to press the back button.
242  // Load all the Fields from the previous form into hidden fields on this form
243  ?>
244  <!-- LOAD ALL HIDDEN FIELDS -->
245 
246  <!-- Description -->
247  <input type="hidden" name="trancode" value="<?php echo set_string($trancode) ?>">
248  <input type="hidden" name="trandesc" value="<?php echo set_string($trandesc) ?>">
249  <input type="hidden" name="transpec" value="<?php echo set_string($transpec) ?>">
250 
251  <!-- Create a hidden field for the form error -->
252  <input type="hidden" name="form_err" value="">
253 
254  <?php if (strlen($err_msg) > 0): ?>
255  <?php
256  //If an error was found post the information back to the CU edit form here
257  $form_err = sprintf("<font size=\"+1\">ERROR! Problems with the credit union information found: <BR></font>");
258  $form_err .= sprintf("The following errors will need to be corrected before you will be allowed to save the form.");
259  $form_err .= sprintf("<P> <font color=red>%s</font>", $err_msg);
260  save_fail($form_err);
261  ?>
262  <?php else: ?>
263 
264  <?php
265  // Everything was validated, we now need to save the information, either insert for new or update for edited.
266 
267  $save_sql = "SELECT trancode FROM cutrans WHERE trancode = '$trancode'";
268  // Execute the query and find out how many rows are in the query
269  $db_result = db_query($save_sql, $link);
270 
271  $num_rows = db_num_rows($db_result);
272  if ($num_rows > 0 )
273  {
274  // UPDATE the information into the table
275  $qry_stmt = sprintf("UPDATE cutrans ");
276  $qry_stmt .= sprintf("SET trandesc ='%s', ",prep_save($trandesc));
277  $qry_stmt .= sprintf("specialproc ='%s' ",prep_save($transpec));
278  $qry_stmt .= sprintf("WHERE trancode = '%s'; ",$trancode);
279  }
280  else
281  {
282  $qry_stmt = sprintf("INSERT INTO cutrans ");
283  $qry_stmt .= sprintf("(trancode, trandesc, specialproc) ");
284  $qry_stmt .= sprintf(" VALUES (");
285  $qry_stmt .= sprintf("'%s', '%s', %s); ",strtoupper(prep_save($trancode)), prep_save($trandesc), prep_save($transpec));
286 
287  }
288  // Now pass the query to the Database
289  if (!($db_result=db_query($qry_stmt, $link))) {
290  // A problem was encoutered with saving the data - report the message
291  $form_err = sprintf("<br>");
292  $form_err .= sprintf("<font face=\"Arial\" size=\"2\">Unable to Save Home CU Transaction Code!</font><br>");
293  save_fail($form_err);
294  } else {
295  printError(sprintf("Transaction Code Saved Successfully.<br>
296  <a href=\"cutrans.prg?act=2\" target=\"CONTENT\">CU Transaction Code List</a>"));
297 
298 
299  if (Remote_Update_Selected()) {
300  // ** NOW CHECK FOR SAVING TO A REMOTE SERVER
301  // ** Add Each field that will be updated
302  Remote_Field_Add("cutrn", "trancode", $trancode);
303  Remote_Field_Add("cutrn", "trandesc", $trandesc);
304  Remote_Field_Add("cutrn", "transpec", $transpec);
305  // ** Need to create the url I am going to send to the remote server
306  $Remote_Results = Remote_Update_Send("U", "cutrn");
307  echo $Remote_Results;
308 
309  }
310  }
311  header ("Location: " . $_SERVER['PHP_SELF'] . "?msg=" . urlencode($Remote_Results));
312 
313 /*
314  print <<< js
315  <script language="javascript">
316  document.location = "cutrans.prg";
317  </script>
318 js;
319 */
320  ?>
321  <?php endif; ?>
322 
323  <?php
324  break;
325  default:
326  cu_header("Error Displaying Form");
327  print ("<form>");
328  printError("Requested form not found!<br>Cancelling action.");
329  endswitch;
330  ?>
331  </form>
332  </body>
333 </html>
334