13 function GetTemporaryEmail() {
14 return "unattended@homecu.com";
34 function UpdateVerifiedEmailList($dbh, $Cu, $emailList) {
38 $results = _TransformKendoEmailList($emailList);
39 if ($results [
"status"] !==
"000") {
40 throw new exception($results [
"error"], 12);
42 extract($results[
"data"]);
45 $results = CheckIfEmailIsUsed($dbh, $Cu, $allEmails);
46 if ($results[
"status"] !==
"000") {
47 throw new exception ($results[
"error"], 9);
50 $results = _ModifyVerifiedEmailListWithUsedEmails ($results[
"usedEmailList"], $verifiedEmailList, $deletedEmails);
51 if ($results [
"status"] !==
"000") {
52 throw new exception ($results[
"error"], 14);
54 extract($results[
"data"]);
56 if (count($unverifiedEmails) > 0) {
58 $pyFile = dirname(__FILE__) .
"/../../shared/scripts/verifySESEmail.py";
59 $pyAction =
"verifyEmails";
60 $cmd =
"python3 $pyFile -a $pyAction -e " .
'"' . implode(
" ", $unverifiedEmails) .
'"';
61 $response = HCU_JsonDecode(exec($cmd));
62 if ($response[
"status"] !==
"000") {
63 throw new exception ($response[
"error"], 8);
67 if (count($deletedEmails) > 0) {
69 $pyFile = dirname(__FILE__) .
"/../../shared/scripts/verifySESEmail.py";
70 $pyAction =
"removeEmails";
71 $cmd =
"python3 $pyFile -a $pyAction -e " .
'"' . implode(
" ", $deletedEmails) .
'"';
72 $response = HCU_JsonDecode(exec($cmd));
73 if ($response[
"status"] !==
"000") {
74 throw new exception ($response[
"error"], 10);
79 $sql =
"select email from cuadmnotify where cu = '" . prep_save($Cu, 10) .
"' and role = 'SES'";
80 $sth = db_query($sql, $dbh);
82 throw new exception(
"Email query failed.", 5);
86 if (db_num_rows($sth) > 0) {
89 $sql =
"update cuadmnotify set email = '" . prep_save(HCU_JsonEncode(array_values($databaseEmailList))) .
"' 90 where cu = '" . prep_save($Cu, 10) .
"' and role = 'SES'";
91 $sth = db_query($sql, $dbh);
93 throw new exception (
"Update query failed.", 6);
100 $sql =
"insert into cuadmnotify (cu, role, email) values ('" . prep_save($Cu, 10) .
"', 'SES', '" .
101 prep_save(HCU_JsonEncode(array_values($databaseEmailList))) .
"')";
102 $sth = db_query($sql, $dbh);
104 throw new exception (
"Insert query failed.", 7);
109 ksort($verifiedEmailList);
111 $results = _GetInfoForEmailList($deletedEmails, $unverifiedEmails);
112 if ($results [
"status"] !==
"000") {
113 throw new exception ($results [
"error"], 13);
115 extract($results [
"data"]);
117 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"verifiedEmailList" => array_values($verifiedEmailList),
"info" => $info,
"operation" =>
"update");
118 }
catch (exception $e) {
120 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage(),
"operation" =>
"update");
121 $results = ReadVerifiedEmailList($dbh, $Cu);
122 $returnArray[
"verifiedEmailList"] = $results[
"verifiedEmailList"];
140 function _ModifyVerifiedEmailListWithUsedEmails ($usedEmailList, $verifiedEmailList, $deletedEmails) {
142 if (!isset($usedEmailList) || !is_array($usedEmailList) || !isset($verifiedEmailList) || !is_array($verifiedEmailList)
143 || !isset($deletedEmails) || !is_array($deletedEmails)) {
144 throw new exception (
"Inputs are not valid.", 12);
147 foreach($usedEmailList as $emailKey => $emailRow) {
148 if (!HCU_array_key_exists(
"email", $emailRow) || !HCU_array_key_exists(
"used", $emailRow)) {
149 throw new exception (
"UsedEmailList is not valid.", 13);
151 $email = $emailRow[
"email"];
152 $used = $emailRow[
"used"];
153 if (!validateEmail($email)) {
154 throw new exception (
"One or more emails are not valid.", 14);
156 if (HCU_array_key_exists($emailKey, $verifiedEmailList)) {
157 $verifiedEmailList[$emailKey][
"used"] = $used;
158 }
else if ($used && HCU_array_key_exists($emailKey, $deletedEmails)) {
159 throw new exception (
"Cannot delete an email in use.", 11);
163 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"data" => array(
"verifiedEmailList" => $verifiedEmailList));
164 }
catch (exception $e) {
165 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
182 function _GetInfoForEmailList($deletedEmails, $unverifiedEmails) {
186 $info[] =
"Email list saved successfully.";
187 if (count ($unverifiedEmails) > 0) {
189 $info[] =
"Verification emails were sent to:";
190 $info = array_merge($info, array_keys($unverifiedEmails));
193 if (count($deletedEmails) > 0) {
195 $info[] =
"The following emails were removed:";
196 $info = array_merge($info, array_keys($deletedEmails));
199 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"data" => array(
"info" => $info));
200 }
catch (exception $e) {
201 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
224 function _TransformKendoEmailList($emailList) {
225 $verifiedEmailList = array();
226 $databaseEmailList = array();
227 $unverifiedEmails = array();
228 $deletedEmails = array();
229 $allEmails = array();
230 $validStatuses = array(
"Success",
"Pending",
"Failed",
"TemporaryFailure",
"NotStarted",
"");
233 $emailList = HCU_JsonDecode($emailList);
234 if (!is_array($emailList) || count($emailList) == 0) {
235 throw new exception (
"Email list is not valid.", 1);
238 foreach($emailList as $emailRow) {
239 if (!HCU_array_key_exists(
"email", $emailRow) || !HCU_array_key_exists(
"status", $emailRow)) {
240 throw new exception (
"Email list is not valid.", 2);
242 $email = $emailRow[
"email"];
243 $status = $emailRow[
"status"];
244 $emailKey = strtolower($email);
246 if (!in_array($status, $validStatuses)) {
247 throw new exception (
"Email list is not valid.", 3);
250 if (!validateEmail($email)) {
251 throw new exception (
"Email list is not valid.", 4);
255 if (trim(strtolower($email)) == GetTemporaryEmail()) {
259 $allEmails[] = prep_save($email);
260 if (!HCU_array_key_value(
"deleted", $emailRow)) {
262 $unverifiedEmails [$emailKey] = str_replace(
'"',
'\x22', $emailKey);
264 $verifiedEmailList [$emailKey] = array(
"email" => $emailKey,
"status" =>
"Pending");
266 $date =
new DateTime(
"now",
new DateTimeZone(
"UTC"));
267 $date = $date->format(
"U");
268 $databaseEmailList [$emailKey] = array(
"email" => $emailKey,
"verified" =>
false,
"date" => intval($date));
269 }
else if ($status ==
"Success") {
270 $verifiedEmailList [$emailKey] = array(
"email" => $emailKey,
"status" => $status);
271 $databaseEmailList [$emailKey] = array(
"email" => $emailKey,
"verified" =>
true);
273 $verifiedEmailList [$emailKey] = array(
"email" => $emailKey,
"status" => $status);
274 $databaseEmailList [$emailKey] = array(
"email" => $emailKey,
"verified" =>
false);
276 }
else if (!HCU_array_key_value(
"itsNew", $emailRow)) {
277 $deletedEmails [$emailKey] = str_replace(
'"',
'\x22', $emailKey);
282 foreach ($deletedEmails as $email => $value) {
283 if (HCU_array_key_exists($email, $verifiedEmailList)) {
284 unset($deletedEmails[$email]);
288 $returnArray = array(
"status" =>
"000",
"error" =>
"",
289 "data" => array(
"allEmails" => $allEmails,
"unverifiedEmails" => $unverifiedEmails,
"verifiedEmailList" => $verifiedEmailList,
290 "databaseEmailList" => $databaseEmailList,
"deletedEmails" => $deletedEmails));
291 }
catch (exception $e) {
292 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
311 function ReadVerifiedEmailList($dbh, $Cu) {
312 $verifiedEmailList = array();
313 $databaseEmailList = array();
314 $updateDatabase =
false;
316 $approvedEmails = array();
320 $sql =
"select email from cuadmnotify where cu = '" . prep_save($Cu, 10) .
"' and role = 'SES'";
321 $sth = db_query($sql, $dbh);
323 throw new exception(
"Email query failed.", 1);
327 if (db_num_rows($sth) > 0) {
329 $results = _TransformDatabaseEmailList(db_fetch_assoc($sth, 0)[
"email"]);
330 if ($results [
"status"] !==
"000") {
331 throw new exception ($results [
"error"], 13);
333 extract($results [
"data"]);
336 $results = CheckIfEmailIsUsed($dbh, $Cu, $allEmails);
337 if ($results[
"status"] !==
"000") {
338 throw new exception ($results[
"error"], 9);
340 foreach($results[
"usedEmailList"] as $emailRow) {
341 $key = strtolower($emailRow[
"email"]);
342 $verified = $databaseEmailList[$key][
"verified"];
343 $verifiedEmailList[$key][
"used"] = $emailRow[
"used"] && $verified;
347 if (count($unverifiedEmails) > 0) {
348 $pyFile = dirname(__FILE__) .
"/../../shared/scripts/verifySESEmail.py";
349 $pyAction =
"getVerification";
351 $cmd =
"python3 $pyFile -a $pyAction -e " .
'"' . implode(
" ", $unverifiedEmails) .
'"';
352 $response = exec($cmd);
354 $results = _ValidateAWSStatusReturn($response);
355 if ($results [
"status"] !==
"000") {
356 throw new exception ($results [
"error"], 14);
358 extract($results [
"data"]);
360 $results = _TransformEmailStatuses($emailStatuses, $verifiedEmailList, $databaseEmailList);
361 if ($results [
"status"] !==
"000") {
362 throw new exception ($results [
"error"], 15);
364 extract($results [
"data"]);
368 if ($updateDatabase) {
370 foreach($databaseEmailList as $datum) {
371 if ($datum[
"verified"]) {
372 $approvedEmails[] = array(
"email" => $datum[
"email"]);
375 $sql =
"update cuadmnotify set email = '" . prep_save(HCU_JsonEncode(array_values($databaseEmailList))) .
376 "' where cu = '" . prep_save($Cu, 10) .
"' and role = 'SES'";
377 $sth = db_query($sql, $dbh);
379 throw new exception (
"Update query failed.", 10);
387 $results = ReadEmailNotify($dbh, $Cu);
388 if ($results[
"status"] !==
"000") {
389 throw new exception($results[
"error"], 7);
391 $dataFromNotifies = $results [
"data"][
"gridData"];
394 $sql =
"select distinct trim(tmpl_email) as email from cuadmemailtmpl where cu = '" . prep_save($Cu, 10) .
"'";
395 $sth = db_query($sql, $dbh);
397 throw new exception (
"Email template failed.", 12);
399 $dataFromTemplate = db_fetch_all($sth);
401 $results = _TransformEmailsNoSES($dataFromNotifies, $dataFromTemplate);
402 if ($results [
"status"] !==
"000") {
403 throw new exception ($results [
"error"], 16);
406 extract($results[
"data"]);
410 $approvedEmails[] = array(
"email" => GetTemporaryEmail());
412 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"approvedEmails" => $approvedEmails);
413 }
catch (exception $e) {
414 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage(),
"approvedEmails" => $approvedEmails);
418 ksort($verifiedEmailList);
419 $returnArray [
"verifiedEmailList"] = array_values($verifiedEmailList);
420 $returnArray [
"isNew"] = $isNew;
421 $returnArray [
"operation"] =
"read";
438 function _TransformEmailsNoSES($dataFromNotifies, $dataFromTemplate) {
439 $verifiedEmailList = array();
441 foreach($dataFromNotifies as $emailRow) {
443 if (!$emailRow[
"single"]) {
447 $email = trim($emailRow[
"email"]);
448 $emailKey = strtolower($email);
451 if ($emailKey == GetTemporaryEmail()) {
455 if ($email !=
"" && !HCU_array_key_exists($emailKey, $verifiedEmailList)) {
456 $verifiedEmailList[$emailKey] = array(
"email" => $emailKey,
"status" =>
"",
"used" =>
true,
"isDirty" =>
true);
460 if ($dataFromTemplate) {
461 foreach($dataFromTemplate as $row) {
462 $email = $row[
"email"];
463 $emailKey = strtolower($email);
465 if (!HCU_array_key_exists($emailKey, $verifiedEmailList)) {
466 $verifiedEmailList[$emailKey] = array(
"email" => $emailKey,
"status" =>
"",
"used" =>
true,
"isDirty" =>
true);
471 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"data" => array(
"verifiedEmailList" => $verifiedEmailList));
473 }
catch (exception $e) {
474 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
493 function _TransformEmailStatuses($emailStatuses, $verifiedEmailList, $databaseEmailList) {
494 $updateDatabase =
false;
496 foreach($emailStatuses as $email => $emailRow) {
497 $emailKey = strtolower($email);
498 $status = HCU_array_key_value(
"VerificationStatus", $emailRow);
500 if ($status !==
false) {
501 $verifiedEmailList[$emailKey][
"status"] = $status;
502 $databaseEmailList[$emailKey][
"email"] = $emailKey;
504 if ($status ==
"Success") {
505 $databaseEmailList[$emailKey][
"verified"] =
true;
506 $verifiedEmailList[$emailKey][
"resend"] =
false;
507 unset($databaseEmailList[$emailKey][
"date"]);
509 $updateDatabase =
true;
513 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"data" => array(
"verifiedEmailList" => $verifiedEmailList,
"databaseEmailList" => $databaseEmailList,
514 "updateDatabase" => $updateDatabase));
515 }
catch (exception $e) {
516 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
536 function _TransformDatabaseEmailList($emailList) {
537 $unverifiedEmails = array();
538 $allEmails = array();
539 $verifiedEmailList = array();
540 $databaseEmailList = array();
543 $emailList = HCU_JsonDecode($emailList);
545 $utc =
new DateTimeZone(
"UTC");
546 $hourAgo =
new DateTime(
"now", $utc);
547 $hourAgo->modify(
'-1 hour');
550 foreach($emailList as $emailRow) {
551 $email = trim($emailRow[
"email"]);
552 $emailKey = strtolower($email);
554 if (!HCU_array_key_exists($emailKey, $verifiedEmailList)) {
555 if (!validateEmail($emailKey)) {
556 throw new exception (
"Email list is not valid.", 8);
560 if ($emailKey == GetTemporaryEmail()) {
565 $emailRow[
"email"] = $emailKey;
567 $date = HCU_array_key_value(
"date", $emailRow);
568 if ($date ===
false) {
571 $date = DateTime::createFromFormat(
"U", $date, $utc);
572 $resend = $date < $hourAgo;
575 $verifiedEmailList[$emailKey] = array(
"email" => $emailKey,
"status" =>
"",
"used" =>
false,
"resend" => $resend);
576 $allEmails[$emailKey] = prep_save($emailKey);
577 if ($emailRow[
"verified"] ===
true) {
578 $verifiedEmailList[$emailKey][
"status"] =
"Success";
579 $verifiedEmailList[$emailKey][
"resend"] =
false;
581 $unverifiedEmails[$emailKey] = str_replace(
'"',
'\x22', $emailKey);
584 $databaseEmailList[$emailKey] = $emailRow;
588 $returnArray = array(
"status" =>
"000",
"error" =>
"",
589 "data" => array(
"unverifiedEmails" => $unverifiedEmails,
"allEmails" => $allEmails,
"verifiedEmailList" => $verifiedEmailList,
590 "databaseEmailList" => $databaseEmailList));
591 }
catch (exception $e) {
592 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
608 function _ValidateAWSStatusReturn($response) {
611 if ($response ==
"") {
612 throw new exception (
"Invalid response from script.", 11);
614 $response = HCU_JsonDecode($response);
615 if (count($response) == 0) {
616 throw new exception(
"Invalid response from script.", 3);
618 if (!HCU_array_key_exists(
"status", $response) || !HCU_array_key_exists(
"error", $response) || !HCU_array_key_exists(
"response", $response)) {
619 throw new exception(
"Invalid response from script.", 5);
621 if ($response[
"status"] !==
"000") {
622 throw new exception($response[
"error"], 4);
625 $emailStatuses = HCU_array_key_value(
"VerificationAttributes", $response[
"response"]);
626 if ($emailStatuses ===
false) {
627 throw new exception(
"Invalid response from script.", 6);
630 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"data" => array(
"emailStatuses" => $emailStatuses));
631 }
catch (exception $e) {
632 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
650 function CheckIfEmailIsUsed($dbh, $Cu, $emailList) {
651 $usedEmailList = array();
653 if (count($emailList) > 0) {
654 $results = _GetInvalidRoles(GetEmailNotifyRoles());
655 if ($results [
"status"] !==
"000") {
656 throw new exception ($results [
"error"], 2);
658 extract($results[
"data"]);
660 if (count($invalidRoles) > 0) {
661 $sql =
"select distinct a.email, b.email is not null or e.tmpl_id is not null as used 662 from (values ('" . implode(
"'), ('", $emailList) .
"')) as a (email) 663 left join (select regexp_split_to_table ( trim ( email ), E'\\\\s*;\\\\s*' ) from cuadmnotify 664 where cu = '" . prep_save($Cu, 10) .
"' and role not in ('" . implode(
"', '", $invalidRoles) .
"')) as b (email) 665 on trim(lower(a.email)) = trim(lower(b.email)) 666 left join cuadmemailtmpl e on trim(lower(a.email)) = trim(lower(e.tmpl_email)) and e.cu = '" . prep_save($Cu, 10) .
"'";
668 $sth = db_query($sql, $dbh);
670 throw new exception (
"Used query failed.", 1);
673 $results = _TransformUsedEmailList(db_fetch_all($sth));
674 if ($results [
"status"] !==
"000") {
675 throw new exception ($results [
"error"], 2);
677 extract($results[
"data"]);
681 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"usedEmailList" => $usedEmailList);
682 }
catch (exception $e) {
683 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
699 function _TransformUsedEmailList($usedEmailData) {
700 $usedEmailList = array();
702 if ($usedEmailData) {
703 foreach($usedEmailData as $row) {
704 $email = trim($row[
"email"]);
705 $emailKey = strtolower($email);
706 $used = trim($row[
"used"]) ==
"t";
707 $usedEmailList[$emailKey] = array(
"email" => $emailKey,
"used" => $used);
711 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"data" => array(
"usedEmailList" => $usedEmailList));
712 }
catch (exception $e) {
713 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
728 function _GetInvalidRoles($roles) {
729 $invalidRoles = array();
731 $invalidRoles = array();
732 foreach($roles as $role => $roleRow) {
733 if (HCU_array_key_value(
"hidden", $roleRow) || !HCU_array_key_value(
"single", $roleRow)) {
734 $invalidRoles [] = prep_save($role, 15);
738 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"data" => array(
"invalidRoles" => $invalidRoles));
739 }
catch (exception $e) {
740 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
758 function ReadEmailNotify($dbh, $Cu) {
760 $approvedEmails = array();
763 $roles = GetEmailNotifyRoles();
764 $sql =
"select role, email from cuadmnotify where cu = '" . prep_save($Cu, 10) .
"'";
765 $sth = db_query($sql, $dbh);
767 throw new exception (
"Role query failed.", 1);
769 $roleData = db_fetch_all($sth);
770 $featureList = FetchMenuFeatureList( array(
"dbh" => $dbh), array(
"Cu" => $Cu) );
773 $results = _TransformReadEmailNotify($roles, $roleData, $featureList);
774 if ($results [
"status"] !==
"000") {
775 throw new exception ($results [
"error"], 2);
777 extract($results[
"data"]);
779 usort($records,
"SortEmailNotify");
781 $results = RetrieveApprovedEmails($dbh, $Cu);
782 if ($results[
"status"] !==
"000") {
783 throw new exception (
"Verified query failed.", 3);
785 $approvedEmails = $results[
"approvedEmails"];
787 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"data" => array(
"gridData" => $records,
"approvedEmails" => $approvedEmails),
789 }
catch (exception $e) {
790 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage(),
"action" =>
"read",
791 "data" => array(
"gridData" => array(),
"approvedEmails" => array()));
807 function RetrieveApprovedEmails($dbh, $Cu) {
809 $sql =
"select trim(r.email) as email from json_to_recordset((select a.email from cuadmnotify a where a.role = 'SES' 810 and a.cu = '" . prep_save($Cu, 10) .
"')::json) 811 as r (email varchar, verified boolean) where r.verified = true order by 1";
812 $sth = db_query($sql, $dbh);
814 throw new exception (
"Verified query failed.", 3);
816 $approvedEmails = db_fetch_all($sth);
817 $approvedEmails = $approvedEmails ===
false ? array() : $approvedEmails;
820 $approvedEmails[] = array(
"email" => GetTemporaryEmail());
822 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"approvedEmails" => $approvedEmails);
823 }
catch (exception $e) {
824 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
837 function SortEmailNotify($a, $b) {
838 $cmp = $a[
"single"] ? ($b[
"single"] ? 0 : -1) : ($b[
"single"] ? 1 : 0);
854 function _TransformReadEmailNotify($roles, $roleData, $featureList) {
860 $featureMenuHasCommercial =
false;
861 if (in_array(
"ACHPMT", $featureList[
'data']) || in_array(
"ACHCOL", $featureList[
'data'])) {
862 $featureMenuHasCommercial =
true;
865 foreach($roleData as $row) {
866 $emailMap[trim($row[
"role"])] = trim($row[
"email"]);
869 foreach($roles as $roleKey => $roleArray) {
871 if (!$featureMenuHasCommercial && $roleKey ==
"achnotify") {
875 if (isset($roleArray[
"hidden"]) && $roleArray[
"hidden"]) {
878 $email = HCU_array_key_value($roleKey, $emailMap);
879 $email = $email ===
false ?
"" : trim($email);
880 $clear = HCU_array_key_value(
"clear", $roleArray);
881 $single = HCU_array_key_value(
"single", $roleArray);
882 $record = array(
"roleId" => $roleKey,
"roleText" => $roleArray[
"desc"],
"required" => !$clear && $email !=
"",
"single" => $single,
"email" => $email);
883 $records[] = $record;
886 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"data" => array(
"records" => $records));
887 }
catch (exception $e) {
888 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
904 function GetEmailNotifyRoles() {
907 "upload" => [
"desc" =>
"File Upload Confirmations"],
908 "alert" => [
"desc" =>
"Alerts From / Returned To",
"single" =>
true],
909 "esload" => [
"desc" =>
"eStatement Upload"],
910 "agree" => [
"desc" =>
"eStatement Signups / Stops"],
911 "preset" => [
"desc" =>
"Password Reset CU Copy To"],
912 "presetfrom" => [
"desc" =>
"Password Reset Mailed From",
"single" =>
true],
913 "transfernotify" => [
"desc" =>
"Transfers / Repeating Txn Failures"],
916 "onldepnotify" => [
"desc" =>
"Loan System Notifications"],
917 "securenotify" => [
"desc" =>
"Secure Message Notification",
"clear" =>
true],
918 "securemsgfrom" => [
"desc" =>
"Secure Message Notification Mailed From",
"single" =>
true],
919 "securitychgfrom" => [
"desc" =>
"Security Settings Changed Mailed From",
"single" =>
true],
920 "enrollnotify" => [
"desc" =>
"Enrollment Form Notification",
"clear" =>
true,
"delete" =>
true],
921 "txtbanking" => [
"desc" =>
"TXT Banking Email",
"clear" =>
true,
"hidden" =>
true],
922 "twtralert" => [
"desc" =>
"Twitter Alert Account",
"clear" =>
true,
"hidden" =>
true],
923 "achnotify" => [
"desc" =>
"ACH Notifications",
"single" =>
true],
924 "hcunotice" => [
"desc" =>
"HomeCU Special Notifications<br><font size=1>(Planned outages, special updates, etc.)</font>"],
925 "ccemail" => [
"desc" =>
"Credit Card Payment Request",
"hidden" =>
true],
927 "SES" => [
"hidden" =>
true]
949 function UpdateEmailNotify($dbh, $Cu, $Cn, $role, $email, $specialEmailUpdate) {
950 $roles = GetEmailNotifyRoles();
953 $results = _TransformRoleForUpdate($role, $roles, $email);
954 if ($results [
"status"] !==
"000") {
955 throw new exception ($results [
"error"], 9);
957 extract($results[
"data"]);
959 $sql =
"select 'FOUND' from cuadmnotify where cu = '" . prep_save($Cu, 10) .
"' and role = '" . prep_save($role, 15) .
"'";
960 $sth = db_query($sql, $dbh);
962 throw new exception(
"notify find query failed.", 6);
964 $recordExists = db_num_rows($sth) > 0;
966 $sql =
"select email from cuadminusers where user_name = '$Cn' and cu = '$Cu'";
967 $sth = db_query($sql, $dbh);
969 throw new exception(
"Email query failed.", 7);
971 $userEmail = db_fetch_row($sth)[0];
973 $results = _CreateUpdateTableForUpdateAudit($Cu, $role, $returnRecord[
"email"], $recordExists, $userEmail, $specialEmailUpdate);
974 if ($results [
"status"] !==
"000") {
975 throw new exception ($results [
"error"], 10);
977 extract($results[
"data"]);
979 if (DataAdminTableUpdate($dbh, array(
"cu" => $Cu), $updateTable, $Cn, $shortLabel,
"notificationMaintenance.prg",
"A",
980 $longLabel, $Cn, $userEmail, trim($_SERVER[
"REMOTE_ADDR"])) ===
false) {
981 throw new exception(
"Update failed.", 8);
984 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"record" => array($returnRecord),
"info" =>
"Email has been updated successfully",
"action" =>
"update");
985 }
catch(exception $e) {
986 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage(),
"action" =>
"update");
1003 function _TransformRoleForUpdate($role, $roles, $email) {
1006 $roleRecord = HCU_array_key_value($role, $roles);
1007 if ($roleRecord ===
false) {
1008 throw new exception(
"role record not found.", 1);
1011 if (trim($email) ==
"" && !(isset($roleRecord[
"clear"]) && $roleRecord[
"clear"])) {
1012 throw new exception(
"Email cannot be cleared.", 2);
1017 foreach (preg_split(
'/[;, ]/',$email) as $ema) {
1021 if (!validateEmail($ema)) {
1022 throw new exception(
"One of the emails is invalid.", 3);
1025 $emails[] = strtolower(trim($ema));
1030 $email = implode(
";", $emails);
1032 if ($numEmails == 0) {
1033 throw new exception(
"Email cannot be cleared.", 4);
1036 if ($numEmails > 1 && isset($roleRecord[
"single"]) && $roleRecord[
"single"]) {
1037 throw new exception(
"Only one address is allowed.", 5);
1040 $returnRecord = array(
"roleId" => $role,
"roleText" => $roleRecord[
"desc"],
"email" => $email,
1041 "required" => trim($email) !=
"" && !(isset($roleRecord[
"clear"]) && $roleRecord[
"clear"]),
"recordExists" =>
"Y");
1043 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"data" => array(
"returnRecord" => $returnRecord));
1044 }
catch (exception $e) {
1045 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
1047 return $returnArray;
1065 function _CreateUpdateTableForUpdateAudit($Cu, $role, $email, $recordExists, $userEmail, $specialEmailUpdate) {
1070 $updateTable = array(
"cu" => $Cu,
"role" => $role,
"email" => $email);
1071 if ($recordExists) {
1072 $updateTable[
"_action"] =
"update";
1074 if ($specialEmailUpdate) {
1075 $shortLabel =
"UPD_SNOTI";
1076 $longLabel =
"Update Special Email Notification";
1078 $shortLabel =
"UPD_NOTI";
1079 $longLabel =
"Update Notification Emails";
1082 $updateTable[
"_action"] =
"insert";
1084 if ($specialEmailUpdate) {
1085 $shortLabel =
"ADD_SNOTI";
1086 $longLabel =
"Add Special Email Notification";
1088 $shortLabel =
"ADD_NOTI";
1089 $longLabel =
"Add Notification Emails";
1093 $updateTable = array(
"cuadmnotify" => array($updateTable));
1095 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"data" => array(
"updateTable" => $updateTable,
"shortLabel" => $shortLabel,
"longLabel" => $longLabel));
1096 }
catch (exception $e) {
1097 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
1099 return $returnArray;
1115 function ResendEmail($dbh, $Cu, $email) {
1119 if (!validateEmail($email)) {
1120 throw new exception(
"Email is invalid.", 1);
1123 $email = trim(strtolower($email));
1125 $encoded = trim(str_replace(
'"',
'\x22', $email));
1129 $pyFile = dirname(__FILE__) .
"/../../shared/scripts/verifySESEmail.py";
1130 $pyAction =
"verifyEmails";
1131 $cmd =
"python3 $pyFile -a $pyAction -e " .
'"' . $encoded .
'"';
1132 $response = HCU_JsonDecode(exec($cmd));
1133 if ($response[
"status"] !==
"000") {
1134 throw new exception ($response[
"error"], 2);
1138 $sql =
"select email from cuadmnotify where cu = '" . prep_save($Cu, 10) .
"' and role = 'SES'";
1139 $sth = db_query($sql, $dbh);
1141 throw new exception (
"Select query failed.", 3);
1144 $emailArray = db_num_rows($sth) > 0 ? db_fetch_row($sth, 0)[0] :
"[]";
1145 $emailArray = HCU_JsonDecode($emailArray);
1148 foreach($emailArray as $i => $emailRow) {
1149 $checkEmail = HCU_array_key_value(
"email", $emailRow);
1150 $checkEmail = $checkEmail ===
false ?
"" : trim(strtolower($checkEmail));
1152 $newEmailRow = $emailRow;
1153 $newEmailRow[
"email"] = $checkEmail;
1154 if ($checkEmail == $email) {
1155 $date =
new DateTime(
"now",
new DateTimeZone(
"UTC"));
1156 $date = $date->format(
"U");
1157 $newEmailRow[
"date"] = intval($date);
1160 $emailArray[$i] = $newEmailRow;
1163 $emailArray = HCU_JsonEncode($emailArray);
1165 $sql =
"update cuadmnotify set email = '" . prep_save($emailArray) .
"' 1166 where cu = '" . prep_save($Cu, 10) .
"' and role = 'SES'";
1167 $sth = db_query($sql, $dbh);
1169 throw new exception (
"Update query failed.", 4);
1172 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"email" => $email,
"info" =>
"Email was resent to $email.");
1173 }
catch (exception $e) {
1174 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
1176 return $returnArray;