Odyssey
siteSetColor.data
1 <?php
2 
3 
4  /*
5  * siteSetColor.data
6  *
7  * Script to save any changes to the brand.css file for the credit union
8  *
9  */
10 
11 
12  // ** Include these scripts, mostly to ensure that the Monitor security is maintained
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, 'siteSetColor', $_SERVER['REMOTE_ADDR'])) {
19  // ** Permissions failed
20  // ** redirect to new page
21  header("Location: /hcuadm/hcu_noperm.prg");
22  exit;
23  }
24 
25 
26  /* Expecting the following fields
27  * user_name - credit union name
28  * langSelect - Languages selected for Home Banking
29  * postStyleSettings - These are the settings in a JSON string for the purposne
30  * -- of saving
31  */
32  $array = array("filter" => FILTER_DEFAULT);
33  $string = array("filter" => FILTER_SANITIZE_STRING);
34  $HB_ENV = array();
35  $homecuOkay = array('user_name' => $string, 'loadSettings' => $string, 'postStyleSettings' => $array);
36 
37  HCU_ImportVars($HB_ENV, 'HCUPOST', $homecuOkay);
38 
39 
40  $retStatus_ary = Array(
41  'homecuInfo' => '',
42  'homecuErrors' => Array(),
43  'homecuData' => ''
44  );
45 
46  $styleDefaults = array(
47  "fontFamily" => "Helvetica, \"Helvetica Neue\", Arial, sans-serif",
48  "headerBackground" => "#24417A",
49  "headerForeground" => "#FFFFFF",
50  "headerBorder" => "#2A2D33",
51  "footerBackground" => "#E7E8EA",
52  "footerForeground" => "#777777",
53  "menuGroupBackground" => "#1B8DD6",
54  "menuGroupBackgroundLighter" => "#2198E3",
55  "menuGroupForeground" => "#FFFFFF",
56  "menuForeground" => "#337AB7",
57  "menuForegroundHover" => "#23527C",
58  "menuBackgroundHover" => "#EEEEEE",
59  "menuBackground" => "#F8F8F8",
60  "slideinBackground" => "#808080",
61  "slideinForeground" => "#FFFFFF",
62  "contentBackground" => "#FFFFFF",
63  "contentForeground" => "#333333",
64  "logoHeightDesktop" => "75px",
65  "logoHeightMobile" => "35px",
66  "logoBackground" => "transparent",
67  "contentBorderWidth" => "0px",
68  "contentBorderStyle" => "solid",
69  "contentBorderColor" => "#000000",
70  "navBadgeColor" => "#777777",
71  "navIconColor" => "#9D9D9D",
72  "navIconColorHover" => "#FFFFFF",
73  "navBackground" => "transparent",
74  "navForeground" => "#FFFFFF",
75  "navActiveBorder" => "#FF0000",
76  "bannerBackground" => "#161620",
77  "bannerHeight" => "60px",
78  "bannerWidth" => "100%"
79  );
80 
81  // * *use this for
82  try {
83  $cuSettingsFileName = "brand.css";
84  $cuSettingsFileProdName = "brand.{$HB_ENV['HCUPOST']['user_name']}.css";
85  // ** Configure location of the hcuSettings file for the Credit Union
86  $cuSettingsDir = "/home/{$HB_ENV['HCUPOST']['user_name']}/public_html/bankingIncludes/";
87  $cuPublicDir = "/home/{$HB_ENV['HCUPOST']['user_name']}/public_html/";
88  $templateSettingsDir = "/home/homecu/public_html/bankingIncludes/css/";
89 
90  if ($HB_ENV['HCUPOST']['loadSettings'] == 'preview' || $HB_ENV['HCUPOST']['loadSettings'] == 'production') {
91  /*
92  * File system saving
93  *
94  * 1 - Keep a hidden copy of an older version
95  * a - This should be named .brand.css
96  * 2 - Save the json string the new settings to the bankingIncludes directory
97  *
98  */
99  $cuSaveSettingsDir = $cuSettingsDir . $HB_ENV['HCUPOST']['loadSettings'] . '/css/';
100 
101  // ** Configure location of the default hcuSettings
102  $cuDefaultSettingsDir = "/home/httpd/homecu/bankingIncludes/";
103  $cuLoadSettingsFile = '';
104  if (is_dir($cuSaveSettingsDir) && is_writable($cuSaveSettingsDir)) {
105  // ** Directory found - prepare to write
106  $filename = $HB_ENV['HCUPOST']['loadSettings'] == 'production' ? $cuSaveSettingsDir . $cuSettingsFileProdName : $cuSaveSettingsDir . $cuSettingsFileName;
107  if (is_readable($filename)) {
108  // ** we have a current version.. make a backup
109  // ** File copy the current to a different name
110  copy($filename, $cuSaveSettingsDir . '.' . $cuSettingsFileName);
111  }
112 
113  if (is_readable($templateSettingsDir . $cuSettingsFileName)) {
114  $brandOptions = HCU_JsonDecode($HB_ENV['HCUPOST']['postStyleSettings']);
115  $styleContent = file_get_contents($templateSettingsDir . $cuSettingsFileName);
116 
117  foreach($styleDefaults as $key => $value) {
118  $value = HCU_array_key_exists($key, $brandOptions) ? $brandOptions[$key] : $value;
119  $value = isset($value) ? trim($value) : "inherit"; // Colors without values (null) will be pulled into the CSS with the value "inherit."
120  $styleContent = str_replace('{{' . $key . '}}', $value, $styleContent);
121  }
122 
123  // Add customContent back
124  $styleContent = explode('/* customBranding */', $styleContent, 2);
125  $styleContent = trim($styleContent[0]); // Remove and readd.
126  if ($brandOptions["customBranding"] != "") {
127  $styleContent .= "\n\n" . '/* customBranding */' . "\n" . $brandOptions["customBranding"];
128  }
129 
130  // ** we have new file contents
131  $fhSettings = fopen($filename, 'w');
132  fwrite($fhSettings, $styleContent);
133  fclose($fhSettings);
134  $retStatus_ary['homecuInfo'] = "Credit union {$HB_ENV['HCUPOST']['loadSettings']} branding updated.";
135 
136  } else {
137  throw new Exception('Template file not found.');
138  }
139  } else {
140  // ** Directory NOT FOUND.. HOW is that possible
141  throw new Exception("Directory {$cuSaveSettingsDir} not found for the credit union.");
142  }
143  } elseif ($HB_ENV['HCUPOST']['loadSettings'] == 'savetoproduction') {
144  // ** WE will be copying the preview to production
145  // ** We want to copy the preview file to the production
146  $cuSourceSettingsDir = $cuSettingsDir . 'preview/css/';
147  $cuDestSettingsDir = $cuSettingsDir . 'production/css/';
148  if (is_readable($cuSourceSettingsDir . $cuSettingsFileName)) {
149  if (is_readable($cuDestSettingsDir . $cuSettingsFileProdName)) {
150  // ** we have a current version.. make a backup
151  // ** File copy the current to a different name
152  copy($cuDestSettingsDir . $cuSettingsFileProdName, $cuDestSettingsDir . '.' . $cuSettingsFileName);
153  }
154  copy($cuSourceSettingsDir . $cuSettingsFileName, $cuDestSettingsDir . $cuSettingsFileProdName);
155  $retStatus_ary['homecuInfo'] = 'Credit Union Preview branding saved to production.';
156  } else {
157  throw new Exception('Preview branding file not found. Unable to save to production.');
158  }
159  } else {
160  // ** ERROR
161  throw new Exception('Invalid parameter setting. Action cancelled.');
162  }
163  } catch (Exception $ex) {
164 
165  $retStatus_ary['homecuErrors'][] = "Unexpected error while saving. " . $ex->getMessage();
166  }
167  // ** Prepare the package for returning
168  header('Content-type: application/json');
169 
170  print HCU_JsonEncode(Array("Results" => Array($retStatus_ary)));