Odyssey
siteSettings.data
1 <?php
2 
3 
4  /*
5  * siteSettings
6  *
7  * Configuration script for the Credit union to allow them to customize
8  * the languages, menu, content theme
9  *
10  * Possible changes to the brand.css would need to be uploaded and not done through
11  * this screen.
12  *
13  */
14 
15 
16  // ** Include these scripts, mostly to ensure that the Monitor security is maintained
17  $monLibrary= dirname(__FILE__) . "/../library";
18  require_once("$monLibrary/cu_top.i");
19  require_once("$monLibrary/ck_hticket.i");
20 
21  // ** Use the permmissions from the main script siteSettings
22  if (!CheckPerm($link, $Hu, 'siteSettings', $_SERVER['REMOTE_ADDR'])) {
23  // ** Permissions failed
24  // ** redirect to new page
25  header("Location: /hcuadm/hcu_noperm.prg");
26  exit;
27  }
28 
29 
30  /* Expecting the following fields
31  * user_name - credit union name
32  * loadSettings - This will determine which directory the settings will be saved
33  * - The options are
34  * production - saved to the production directory
35  * preview - saved to the preview directory
36  * savetoproduction - the preview hcuSettings.i will be copied to the production directory
37  * langSelect - Languages selected for Home Banking
38  * postScriptProxy - This will be a JSON string of the array for the script proxies being used
39  * postContentTheme - A string of the content theme that is selected
40  * postLogout - A JSON string containing the name to put at the footer and an http link to go to when any logout clicked
41  */
42 
43  $HB_ENV = Array();
44  $string = array("filter" => FILTER_SANITIZE_STRING);
45  $array = HCUFILTER_INPUT_ARRAY;
46  $encodedArray = array("filter" => FILTER_DEFAULT);
47  $dms_ok = Array('user_name' => $string, 'loadSettings' => $string, 'langSelect' => $array, 'postScriptProxy' => $string, 'postContentTheme' => $string,
48  "postLogout" => array('filter' => FILTER_SANITIZE_STRING, 'options' => array( "flags" => FILTER_FLAG_NO_ENCODE_QUOTES)), "postil" => $encodedArray, "operation" => $string, "fileNames" => $string);
49  HCU_ImportVars($HB_ENV, 'HCUPOST', $dms_ok);
50 
51  $username = HCU_array_key_exists("user_name", $HB_ENV["HCUPOST"]) ? trim($HB_ENV["HCUPOST"]["user_name"]) : "";
52  $operation = HCU_array_key_exists("operation", $HB_ENV["HCUPOST"]) ? trim($HB_ENV["HCUPOST"]["operation"]) : "";
53  $fileNames = HCU_array_key_exists("fileNames", $HB_ENV["HCUPOST"]) ? trim($HB_ENV["HCUPOST"]["fileNames"]) : "";
54 
55  $retStatus_ary = Array(
56  'homecuInfo' => '',
57  'homecuErrors' => Array(),
58  'homecuData' => ''
59  );
60 
61 
62  // * *use this for
63 
64  // This operation happens when you use the file uploader to upload a file.
65  if ($operation == "loadImage") {
66  try {
67 
68  $fileErrors = array(
69  "1" => "1: The file you tried to upload is just too big. The allowable limit is 10MB.",
70  "2" => "2: The file you tried to upload is just too big. The allowable limit is 10MB.",
71  "3" => "3: The file was only partially uploaded",
72  "4" => "4: no file was uploaded");
73 
74  $fileDir = "/home/$username/public_html/images/";
75  if (!is_writable($fileDir)) {
76  throw new exception("Image Directory is not set up correctly.", 1);
77  }
78 
79  $file = $_FILES['photoUpload'];
80  $filepath = $fileDir . basename($file["name"]);
81 
82  if ($file["error"] != 0) {
83  $errorInt = $file["error"];
84  throw new exception(HCU_array_key_exists($errorInt, $fileErrors) ? $fileErrors[$errorInt] : "$errorInt: Unknown error.", 2);
85  }
86 
87  $filetmp = $file['tmp_name'];
88  if (!@move_uploaded_file($filetmp, $filepath)) {
89  @unlink ($filetmp);
90  throw new exception("Couldn't post the file where it belongs.", 3);
91  }
92 
93  @chmod($filepath, 0644);
94  $returnArray = array("code" => "000");
95  } catch(exception $e) {
96  $returnArray = array("error" => $e->getMessage(), "code" => $e->getCode());
97  }
98 
99  header('Content-type: application/json');
100  print HCU_JsonEncode($returnArray);
101 
102  // This operation happens when you click on the "X" in the file upload file list.
103  } else if ($operation == "removeImage") {
104  try {
105 
106  $fileDir = "/home/$username/public_html/images/";
107  if (!is_writable($fileDir)) {
108  throw new exception("Image Directory is not set up correctly.", 1);
109  }
110 
111  $filepath = $fileDir . $fileNames;
112  if (@file_exists($filepath) && !@unlink($filepath)) { // Not a problem if the file doesn't exist to begin with.
113  throw new exception("File could not be deleted.", 2);
114  }
115 
116  $returnValue = ""; // Empty string is success.
117  } catch(exception $e) {
118  $returnValue = $e->getMessage();
119  }
120 
121  print $returnValue;
122  } else {
123 
124  try {
125  if ($HB_ENV['HCUPOST']['loadSettings'] == 'preview' || $HB_ENV['HCUPOST']['loadSettings'] == 'production') {
126  /*
127  * Create the cuSettings Array
128  *
129  */
130 
131  /*
132  * Language
133  * -- Use the master list and trim the values that were NOT posted
134  */
135  $masterLangList = returnMasterLanguageList();
136 
137  // * Ensure langSelect is an array prior to saving
138  $langSelect = HCU_array_key_value("langSelect", $HB_ENV["HCUPOST"]);
139  $langSelect = $langSelect === false || !is_array($langSelect) ? array() : $langSelect;
140  $HB_ENV["HCUPOST"]["langSelect"] = $langSelect;
141 
142  // ** I Need to push English onto this list.. BECAUSE it is a disabled checkbox
143  // * ON the form and does NOT get included in the POST
144  array_push($HB_ENV['HCUPOST']['langSelect'], 'en_US');
145 
146  $selectedLang = array_intersect_key($masterLangList, array_flip($HB_ENV['HCUPOST']['langSelect']));
147 
148  $cuSettings = Array(
149  'language' => $selectedLang,
150  'contentTheme' => $HB_ENV['HCUPOST']['postContentTheme'],
151  'Logout' => $HB_ENV['HCUPOST']['postLogout'],
152  "imageLocations" => HCU_JsonDecode($HB_ENV["HCUPOST"]["postil"])
153  );
154  } elseif ($HB_ENV['HCUPOST']['loadSettings'] == 'savetoproduction') {
155  // ** WE will be copying the preview to production
156 
157  } else {
158  // ** ERROR
159  throw new Exception('Invalid parameter setting. Action cancelled.');
160  }
161 
162  /*
163  * File system saving
164  *
165  * 1 - Keep a hidden copy of an older version
166  * a - This should be named .hcuSettings.i
167  * 2 - Save the json string the new settings to the bankingIncludes directory
168  *
169  */
170  $cuSettingsFileName = "hcuSettings.i";
171  // ** Configure location of the hcuSettings file for the Credit Union
172  $cuSettingsDir = "/home/{$HB_ENV['HCUPOST']['user_name']}/public_html/bankingIncludes/";
173  $cuPublicDir = "/home/{$HB_ENV['HCUPOST']['user_name']}/public_html/";
174 
175 
176  if ($HB_ENV['HCUPOST']['loadSettings'] == 'preview' || $HB_ENV['HCUPOST']['loadSettings'] == 'production') {
177  $cuSaveSettingsDir = $cuSettingsDir . $HB_ENV['HCUPOST']['loadSettings'] . '/';
178  // ** Configure location of the default hcuSettings
179  $cuDefaultSettingsDir = "/home/httpd/homecu/bankingIncludes/";
180  $cuLoadSettingsFile = '';
181  if (is_dir($cuSaveSettingsDir)) {
182  // ** Directory found - prepare to write
183  if (is_readable($cuSaveSettingsDir . $cuSettingsFileName)) {
184  // ** we have a current version.. make a backup
185  // ** File copy the current to a different name
186  copy($cuSaveSettingsDir . $cuSettingsFileName, $cuSaveSettingsDir . '.' . $cuSettingsFileName);
187  }
188  $fhSettings = fopen($cuSaveSettingsDir . $cuSettingsFileName, 'w');
189  fwrite($fhSettings, HCU_JsonEncode($cuSettings));
190  fclose($fhSettings);
191  $retStatus_ary['homecuInfo'] = "Credit union {$HB_ENV['HCUPOST']['loadSettings']} settings updated.";
192  } else {
193  // ** Directory NOT FOUND.. HOW is that possible
194  throw new Exception('Directory not found for the credit union.');
195  }
196  } else {
197  // ** We want to copy the preview file to the production
198  $cuSourceSettingsDir = $cuSettingsDir . 'preview/';
199  $cuDestSettingsDir = $cuSettingsDir . 'production/';
200  if (is_readable($cuSourceSettingsDir . $cuSettingsFileName)) {
201  if (is_readable($cuDestSettingsDir . $cuSettingsFileName)) {
202  // ** we have a current version.. make a backup
203  // ** File copy the current to a different name
204  copy($cuDestSettingsDir . $cuSettingsFileName, $cuDestSettingsDir . '.' . $cuSettingsFileName);
205  }
206  copy($cuSourceSettingsDir . $cuSettingsFileName, $cuDestSettingsDir . $cuSettingsFileName);
207  $retStatus_ary['homecuInfo'] = 'Credit Union Preview settings saved to production.';
208  } else {
209  throw new Exception('Preview settings not found. Unable to save to production.');
210  }
211  }
212 
213  } catch (Exception $ex) {
214  $retStatus_ary['homecuErrors'][] = "Unexpected error while saving. " . $ex->getMessage();
215  }
216  // ** Prepare the package for returning
217  header('Content-type: application/json');
218 
219  print HCU_JsonEncode(Array("Results" => Array($retStatus_ary)));
220 
221 }