Odyssey
hcu_prod_save.prg
1 <?php
2 $monLibrary= dirname(__FILE__) . "/../library";
3 require_once("$monLibrary/cu_top.i");
4 require_once("$monLibrary/ck_hticket.i");
5 
6  if (!CheckPerm($link, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR'])) {
7  // ** Permissions failed
8  // ** redirect to new page
9  header("Location: /hcuadm/hcu_noperm.prg");
10  exit;
11  }
12 
13 $dms_ok=array('home_cu_code'=>'string','form_err'=>'string','hcu_form'=>'string','home_cu_desc'=>'string','err_msg'=>'string');
14 dms_import($dms_ok);
15 
16  // Setup a function to go back to the CU Edit form, if anything went wrong
17  function save_fail($msg){
18  global $user_name;
19  printf("<script language=\"javascript\">\n");
20  printf("document.forms[0].elements[\"form_err\"].value = '%s';\n", $msg);
21  printf("document.forms[0].action=\"hcu_prod_edit.prg?home_cu_code=%s\";\n",urlencode($home_cu_code));
22  printf("document.forms[0].method=\"post\";\n");
23  printf("document.forms[0].submit();\n");
24  printf("</script>");
25  printf("\n</form>\n </body>\n </html>\n");
26  exit();
27  }
28 
29  cu_header("HomeCU Products");
30 ?>
31 
32  <form action="hcu_prod_edit.prg" method="post">
33 
34 <?php
35  $errors_found = "No";
36  $err_msg = "";
37 
38 
39  /* VALIDATE THE INFORMATION - whether it's been saved before or NOT
40  After validation fails it will send the information back to the edit form
41  So it looks like it did before, the fail information will be at the bottom of the
42  screen.
43 
44  */
45  $err_msg="";
46 
47  // Now we need to load all the fields from the CU form, and post them back
48  // So the user does not have to press the back button.
49  // Load all the Fields from the previous form into hidden fields on this form
50 ?>
51  <!-- LOAD ALL HIDDEN FIELDS -->
52 
53  <!-- Name -->
54  <input type="hidden" name="home_cu_desc" value="<?php echo set_string($home_cu_desc) ?>">
55 
56  <!-- Create a hidden field for the form error -->
57  <input type="hidden" name="form_err" value="">
58 
59  <?php if (strlen($err_msg) > 0): ?>
60  <?php
61  //If an error was found post the information back to the CU edit form here
62  $form_err = sprintf("<font size=\"+1\">ERROR! Problems with the credit union information found: <BR></font>");
63  $form_err .= sprintf("The following errors will need to be corrected before you will be allowed to save the form.");
64  $form_err .= sprintf("<P> <font color=red>%s</font>", $err_msg);
65  save_fail($form_err);
66  ?>
67  <?php else: ?>
68 
69  <?php
70  // Everything was validated, we now need to save the information, either insert for new or update for edited.
71 
72  $cuprod_query = "SELECT home_cu_code FROM cuprodlist WHERE home_cu_code = '$home_cu_code'";
73  // Execute the query and find out how many rows are in the query
74  $db_result = db_query($cuprod_query, $link);
75 
76  $num_rows = db_num_rows($db_result);
77  if ($num_rows > 0 )
78  {
79  // UPDATE the information into the table
80  $qry_stmt = sprintf("UPDATE cuprodlist\n");
81  $qry_stmt .= sprintf("SET home_cu_desc ='%s'\n",prep_save($home_cu_desc));
82  $qry_stmt .= sprintf("WHERE home_cu_code = '%s'; \n",$home_cu_code);
83  }
84  else
85  {
86  $qry_stmt = sprintf("INSERT INTO cuprodlist \n");
87  $qry_stmt .= sprintf("(home_cu_code, home_cu_desc) \n");
88  $qry_stmt .= sprintf(" VALUES (\n");
89  $qry_stmt .= sprintf("'%s', '%s'); \n",prep_save($home_cu_code), prep_save($home_cu_desc));
90 
91  }
92 
93  // Now pass the query to the Database
94  if (!($db_result=db_query($qry_stmt, $link)))
95  {
96  // A problem was encoutered with saving the data - report the message
97  printError(sprintf("<br>"));
98  printError(sprintf("Error in executing {%s} query", $qry_stmt));
99  printError(sprintf("<font face=\"Arial\" size=\"2\">Unable to Save Home CU Product Information!</font><br>"));
100  save_fail($form_err);
101  }
102  else {
103  header ("Location: /hcuadm/hcu_prod_list.prg?msg=" . urlencode("HCU Product Saved Successfully"));
104  exit;
105  //printError(sprintf("HCU Product Saved Successfully.<br>
106  // <a href=\"hcu_prod_list\" target=\"CONTENT\">HCU Product List</a>"));
107  }
108  /*
109  <script language="javascript">
110  parent.location = "hcu_prod_list";
111  </script>
112  */
113  ?>
114  <?php endif; ?>
115 </form>
116 </body>
117 </html>