Odyssey
ivr_mntc_msg.data
1 <?php
2 
3  /*
4  * ivr_mntc_msg.data
5  *
6  * Data scripts for CRUD operations needed for ivr_mntc_msg
7  *
8  */
9 
10 
11  // ** Include these scripts, mostly to ensure that the Monitor security is maintained
12 
13 $monLibrary= dirname(__FILE__) . "/../library";
14 require_once("$monLibrary/cu_top.i");
15 require_once("$monLibrary/ck_hticket.i");
16 
17  // ** Use the permmissions from the main script siteSettings
18  if (!CheckPerm($link, $Hu, 'ivr_mntc_msg', $_SERVER['REMOTE_ADDR'])) {
19  // ** Permissions failed
20  // ** redirect to new page
21  header("Location: /hcuadm/hcu_noperm.prg");
22  exit;
23  }
24 
25 
26 
27  /* Expecting the following fields
28  * action - The action to be taken
29  * new
30  * update
31  * read
32  * delete
33  * loadSettings - This will determine which directory the settings will be saved
34  * - The options are
35  * production - saved to the production directory
36  * preview - saved to the preview directory
37  * savetoproduction - the preview hcuSettings.i will be copied to the production directory
38  * langSelect - Languages selected for Home Banking
39  * postMenuOptions - This will be a JSON string of the array for the full menu
40  * postScriptProxy - This will be a JSON string of the array for the script proxies being used
41  * postContentTheme - A string of the content theme that is selected
42  * postLogout - A JSON string containing the name to put at the footer and an http link to go to when any logout clicked
43  */
44 
45  $HB_ENV = Array();
46  $dms_ok = Array('action' => 'string', 'msg_code' => 'string', 'msg_desc' => 'string',
47  'msg_filename' => 'string', 'msg_level' => 'string');
48 
49  dms_import_v2($HB_ENV, "HCUPOST", $dms_ok);
50 
51  $retStatus_ary = Array(
52  'homecuInfo' => '',
53  'homecuErrors' => Array(),
54  'homecuData' => ''
55  );
56 
57 
58  try {
59  $returnMsgData = Array();
60  switch ($HB_ENV['HCUPOST']['action']) {
61  case 'read':
62  $sql = "SELECT trim(msg_code) as msg_code,
63  trim(msg_desc) as msg_desc,
64  trim(msg_filename) as msg_filename,
65  msg_level
66  FROM ars_audio_message
67  ORDER BY msg_code ";
68  $sqlRs = db_query($sql, $link);
69  $sIdx = 0;
70  while ($msgRecord = db_fetch_assoc($sqlRs, $sIdx)) {
71  $returnMsgData[] = $msgRecord;
72  $sIdx++;
73  }
74 
75  $retStatus_ary['homecuData'] = $returnMsgData;
76  break;
77  case 'new':
78  case 'update':
79  /*
80  * Validate the data coming in
81  */
82  // ** The msg_code must not be used already
83  $sql = "SELECT count(*) as count_msg
84  FROM ars_audio_message
85  WHERE msg_code = '" . prep_save($HB_ENV['HCUPOST']['msg_code'], 3) . "' ";
86  $cntRs = db_query($sql, $link);
87  list($recordCount) = db_fetch_array($cntRs);
88  if ($HB_ENV['HCUPOST']['action'] == 'new') {
89  // ** NEW
90  if ($recordCount > 0) {
91  throw new Exception('Message code must be unique.');
92  }
93  } else {
94  // ** UPDATE - MUST EXIST **
95  if ($recordCount == 0) {
96  throw new Exception('Message code was not found.');
97  }
98  }
99 
100 
101  // ** All fields entered
102  if ($HB_ENV['HCUPOST']['msg_code'] == '' ||
103  $HB_ENV['HCUPOST']['msg_desc'] == '' ||
104  $HB_ENV['HCUPOST']['msg_filename'] == '') {
105  throw new Exception('All fields must be entered to continue.');
106  }
107 
108  // ** the msg_level must be in {1, 2, 3}
109  if (!in_array($HB_ENV['HCUPOST']['msg_level'], array('1', '2', '3'))) {
110  $retStatus_ary['homecuInfo'][] = $HB_ENV['HCUPOST'];
111  $retStatus_ary['homecuInfo'][] = $HB_ENV['HCUPOST']['msg_level'];
112  $retStatus_ary['homecuInfo'][] = array('1', '2', '3');
113  throw new Exception('Message level was not valid.');
114  }
115 
116 
117  if ($HB_ENV['HCUPOST']['action'] == 'new') {
118  $sql = "INSERT INTO ars_audio_message
119  (msg_code, msg_desc, msg_filename, msg_level)
120  VALUES
121  ('" . prep_save($HB_ENV['HCUPOST']['msg_code'], 3) . "',
122  '" . prep_save($HB_ENV['HCUPOST']['msg_desc'], 50) . "',
123  '" . prep_save($HB_ENV['HCUPOST']['msg_filename'], 20) . "',
124  '" . intval($HB_ENV['HCUPOST']['msg_level']) . "') ";
125 
126  } else {
127  $sql = "UPDATE ars_audio_message
128  SET msg_desc = '" . prep_save($HB_ENV['HCUPOST']['msg_desc'], 50) . "',
129  msg_filename = '" . prep_save($HB_ENV['HCUPOST']['msg_filename'], 20) . "',
130  msg_level = '" . intval($HB_ENV['HCUPOST']['msg_level']) . "'
131  WHERE msg_code = '" . prep_save($HB_ENV['HCUPOST']['msg_code'], 3) . "' ";
132  }
133  $updRs = db_query($sql, $link);
134  if (!$updRs) {
135  // ** FAILED
136  throw new Exception('A problem occurred saving your changes.');
137  } else {
138  // ** SUCCESS
139  $retStatus_ary['homecuInfo'][] = "Change was successfully saved.";
140  }
141  break;
142  case 'delete':
143  $sql = "SELECT count(*) as count_msg
144  FROM ars_audio_message
145  WHERE msg_code = '" . prep_save($HB_ENV['HCUPOST']['msg_code'], 3) . "' ";
146  $cntRs = db_query($sql, $link);
147  list($recordCount) = db_fetch_array($cntRs);
148  // ** UPDATE - MUST EXIST **
149  if ($recordCount == 0) {
150  throw new Exception('Message code was not found.');
151  }
152 
153  $sql = "DELETE FROM ars_audio_message
154  WHERE msg_code = '" . prep_save($HB_ENV['HCUPOST']['msg_code'], 3) . "' ";
155 
156  $updRs = db_query($sql, $link);
157  if (!$updRs) {
158  // ** FAILED
159  throw new Exception('A problem occurred saving your changes.');
160  } else {
161  // ** SUCCESS
162  $retStatus_ary['homecuInfo'][] = "Change was successfully saved.";
163  }
164 
165  break;
166  default:
167  throw new Exception('Invalid parameter setting. Action cancelled.');
168 
169  break;
170  }
171 
172  } catch (Exception $ex) {
173  $retStatus_ary['homecuErrors'][] = "Unexpected error while saving. <br/>" . $ex->getMessage();
174  }
175  // ** Prepare the package for returning
176  header('Content-type: application/json');
177 
178  print json_encode(Array("Results" => Array($retStatus_ary)));