9 function AdminSettingsReplay($pResult, $pReply, $pOperation) {
10 $pReply[
'operation'] = $pOperation;
11 isset($pResult[
'data']) && count($pResult[
'data']) ? $pReply[
'data'] = $pResult[
'data'] :
null;
12 isset($pResult[
'info']) && count($pResult[
'info']) ? $pReply[
'info'] = $pResult[
'info'] :
null;
14 print HCU_JsonEncode(array(
"Results" => $pReply));
27 function AdminUpdateSettings($pEnv, $pDbh, $pCu, $pSettings) {
28 $sqlRouting = HCU_array_key_value(
"routing", $pSettings);
29 $sqlSettings = HCU_array_key_value(
"settings", $pSettings);
35 $sqlPart =
"'$sqlSettings'::jsonb";
36 $sqlSettings ===
false ? null : $setPart[] =
"settings = CASE WHEN settings IS NULL or trim(settings) = '' THEN $sqlPart ELSE settings::jsonb || $sqlPart END";
39 $sqlRouting ===
false ? null : $setPart[] =
"rt = $sqlRouting";
41 if (count($setPart) == 0) {
42 throw new Exception(
"Failed to update credit union settings");
44 $setPart =
"SET " . implode(
", ", $setPart);
53 settings::json->>'name' AS name, 54 settings::json->>'account' AS account, 55 settings::json->>'sub_account_mask' AS sub_account_mask, 56 settings::json->>'offsetting' AS offsetting, 57 settings::json->>'cutoff' AS cutoff, 58 settings::json->>'profile' AS profile, 59 settings::json->>'achnotify' AS notify, 60 settings::json->>'type' AS type";
62 $sqlRs = db_query($sql, $pDbh);
64 throw new Exception(
"Failed to update credit union settings");
67 $sqlData = db_fetch_assoc($sqlRs);
68 $sqlReturn[
'settings'] = array(
69 "routing" => $sqlData[
'routing'],
70 "name" => $sqlData[
'name'] ===
"null" ?
null : $sqlData[
'name'],
71 "account" => $sqlData[
'account'] ===
"null" ?
null : $sqlData[
'account'],
72 "sub_account_mask" => $sqlData[
'sub_account_mask'] ===
"null" ?
null : $sqlData[
'sub_account_mask'],
73 "offsetting" => $sqlData[
'offsetting'] ===
"null" ? 0 : $sqlData[
'offsetting'],
74 "cutoff" => $sqlData[
'cutoff'] ===
"null" ?
null : $sqlData[
'cutoff'],
75 "profile" => $sqlData[
'profile'] ===
"null" ?
null : $sqlData[
'profile'],
76 "notify" => $sqlData[
'notify'] ===
"null" ?
null : $sqlData[
'notify'],
77 "type" => $sqlData[
'type'] ===
"null" ?
null : $sqlData[
'type']
79 $sqlReturn[
'message'] =
"Settings updated successfully";
92 function AdminReadSettings($pEnv, $pDbh, $pCu) {
96 TRIM(a.rt) AS routing, 97 a.settings::json->>'name' AS name, 98 a.settings::json->>'account' AS account, 99 a.settings::json->>'sub_account_mask' AS sub_account_mask, 100 a.settings::json->>'offsetting' AS offsetting, 101 a.settings::json->>'cutoff' AS cutoff, 102 a.settings::json->>'profile' AS profile, 103 a.settings::json->>'achnotify' AS notify, 104 a.settings::json->>'type' AS type 106 WHERE cu = '{$pCu}'";
107 $sqlRs = db_query($sql, $pDbh);
109 throw new Exception(
"Failed to read credit union settings");
112 $sqlData = db_fetch_assoc($sqlRs);
113 $sqlReturn[
'settings'] = array(
114 "routing" => $sqlData[
'routing'],
115 "name" => $sqlData[
'name'] ===
"null" ?
null : $sqlData[
'name'],
116 "account" => $sqlData[
'account'] ===
"null" ?
null : $sqlData[
'account'],
117 "sub_account_mask" => $sqlData[
'sub_account_mask'] ===
"null" ?
null : $sqlData[
'sub_account_mask'],
118 "offsetting" => $sqlData[
'offsetting'] ===
"null" ? 0 : $sqlData[
'offsetting'],
119 "cutoff" => $sqlData[
'cutoff'] ===
"null" ?
null : $sqlData[
'cutoff'],
120 "profile" => $sqlData[
'profile'] ===
"null" ?
null : $sqlData[
'profile'],
121 "notify" => $sqlData[
'notify'] ===
"null" ?
null : $sqlData[
'notify']
125 if (isset($sqlData[
'type']) && $sqlData[
'type'] == 1) {
126 $sqlReturn[
'settings'][
'type'] =
"1";
127 }
else if (isset($sqlData[
'type']) && $sqlData[
'type'] ==
" ") {
128 $sqlReturn[
'settings'][
'type'] =
" ";
130 $sqlReturn[
'settings'][
'type'] =
"9";
145 function AdminReadProfiles($pEnv, $pDbh, $pCu) {
146 $sqlReturn = array();
149 TRIM(profile_code) AS code, 150 TRIM(description) AS description 152 WHERE cu = '{$pCu}'";
153 $sqlRs = db_query($sql, $pDbh);
155 throw new Exception(
"Failed to read credit union profiles");
158 $sqlReturn[
'profiles'] = db_fetch_all($sqlRs);
170 function ValidateACHSettings($pEnv, $pSettings, $pJson =
false) {
171 $aValidate = array();
172 $aSettings = array();
173 $aJsonSettings = array();
175 if ($pSettings ===
null) {
176 throw new Exception(
"Settings not found");
181 $aSettings = trim($pSettings);
182 $aSettings = html_entity_decode($aSettings);
183 $aSettings = HCU_JsonDecode($aSettings);
185 $aSettings = $pSettings;
189 if (!is_array($aSettings)) {
190 throw new Exception(
"Settings data is invalid");
194 if (isset($aSettings[
'name'])) {
195 $aName = trim($aSettings[
'name']);
196 $aName = prep_save($aName, 100);
198 $aJsonSettings[
'name'] = $aName;
200 throw new Exception(
"Credit union name is missing");
204 if (isset($aSettings[
'account'])) {
205 $aAccount = trim($aSettings[
'account']);
206 $aAccount = prep_save($aAccount, 12);
208 if (strlen($aAccount) > 12) {
209 throw new Exception(
"ACH GL Account can only contain up to 12 digits");
212 $aJsonSettings[
'account'] = $aAccount;
214 throw new Exception(
"ACH GL Account is missing");
219 if (isset($aSettings[
'sub_account_mask'])) {
220 $aSubAccountMask = trim($aSettings[
'sub_account_mask']);
221 $aSubAccountMask = prep_save($aSubAccountMask, 16);
223 if (strlen($aSubAccountMask) > 16) {
224 throw new Exception(
"Sub-account mask can only contain up to 16 characters");
226 if (!preg_match(
'/^0*$/', $aSubAccountMask)) {
227 throw new Exception(
"Sub-account mask can only contain '0' characters");
230 $aJsonSettings[
'sub_account_mask'] = $aSubAccountMask;
234 if (isset($aSettings[
'offsetting'])) {
235 $aOffset = $aSettings[
'offsetting'] == 0 ? 0 : 1;
237 $aJsonSettings[
'offsetting'] = $aOffset;
239 throw new Exception(
"Micro deposit offsetting entry choice missing");
243 if (isset($aSettings[
'routing'])) {
244 $aRouting = trim($aSettings[
'routing']);
245 $aRouting = prep_save($aRouting, 9);
247 if (strlen($aRouting) < 9 || strlen($aRouting) > 9) {
248 throw new Exception(
"Routing number must be 9 digits");
251 $aValidate[
'validate'][
'routing'] = $aRouting;
253 throw new Exception(
"Routing number is missing");
257 if (isset($aSettings[
'cutoff'])) {
258 $aTime = trim($aSettings[
'cutoff']);
259 $aTime = prep_save($aTime, 4);
260 if (strlen($aTime) === 3) {
261 $aTime =
"0" . $aTime;
264 $aJsonSettings[
'cutoff'] = $aTime;
266 throw new Exception(
"Cutoff time is missing");
270 if (isset($aSettings[
'type'])) {
271 $aType = $aSettings[
'type'];
273 if ($aType !=
"9" && $aType !=
"1" && $aType !=
" ") {
274 throw new Exception(
"Company ID Type is an incorrect value.");
277 $aJsonSettings[
'type'] = $aType;
279 throw new Exception(
"Company ID Type is missing");
283 if (isset($aSettings[
'notify'])) {
284 $aNotify = trim($aSettings[
'notify']);
285 $aNotify = prep_save($aNotify);
290 $allowedKeywords = array(
'company',
'transactiontype',
'amount',
'date',
'accountname',
'routing',
'accountnumber',
'accounttype');
296 preg_match_all(
"/\{{2}(.*?)\}{2}/i", $aNotify, $foundKeywords);
297 $keywordPatterns = $foundKeywords[0];
298 $keywordValues = $foundKeywords[1];
299 foreach ($keywordValues as $key => $value) {
300 if (!in_array($value, $allowedKeywords)) {
310 $tokens = explode(
' ', $keywordPatterns[$key]);
318 $notAllowed .=
"<li>$token</li>";
324 if (strlen($notAllowed) > 0) {
325 $error =
"The Email Notification template contains one or more invalid keywords:";
326 $error .= $notAllowed;
327 throw new Exception($error);
330 $aJsonSettings[
'achnotify'] = $aNotify;
335 $aJsonSettings = HCU_JsonEncode($aJsonSettings);
336 $aJsonSettings = trim($aJsonSettings);
338 if ($aJsonSettings ===
"") {
339 throw new Exception(
"Admin settings are missing");
342 $aValidate[
'validate'][
'settings'] = $aJsonSettings;
354 function ValidateAutoSettings($pEnv, $pSettings, $pJson =
false) {
355 $aValidate = array();
356 $aSettings = array();
357 $aJsonSettings = array();
359 if ($pSettings ===
null) {
360 throw new Exception(
"Settings not found");
365 $aSettings = trim($pSettings);
366 $aSettings = html_entity_decode($aSettings);
367 $aSettings = HCU_JsonDecode($aSettings);
369 $aSettings = $pSettings;
373 if (!is_array($aSettings)) {
374 throw new Exception(
"Settings data is invalid");
378 if (isset($aSettings[
'profile'])) {
379 $aProfile = trim($aSettings[
'profile']);
380 $aProfile = strtoupper($aProfile);
381 $aProfile = prep_save($aProfile, 20);
383 $aJsonSettings[
'profile'] = $aProfile;
385 throw new Exception(
"Default profile is missing");
390 $aJsonSettings = HCU_JsonEncode($aJsonSettings);
391 $aJsonSettings = trim($aJsonSettings);
393 if ($aJsonSettings ===
"") {
394 throw new Exception(
"Admin settings are missing");
397 $aValidate[
'validate'][
'settings'] = $aJsonSettings;