6 function GetProgramName() {
7 return "aBankingCalendar";
15 function GetEmailRole() {
25 function GetCaringDate($currentYear) {
26 return "$currentYear-11-01";
34 function GetDeleteAfterYears() {
45 function GetCuEmailBody($cu, $nextYear) {
49 <img src=\"https://s3.amazonaws.com/cucommon/homecu/images/HomeCULogo_Color_Small_Trans.png\"/> 53 Dear HomeCU Digital Banking Customer, 56 You are receiving this message as part of the HomeCU Admin Portal for Digital Banking. 57 HomeCU has added the ability to set Credit Union dates in the Banking Calendar. 58 $cu has not yet entered dates for the next year ($nextYear). 59 Please enter these dates at your earliest convenience by going to Administrative Maintenance > Banking Calendar in the Admin Portal. 60 This automated reminder will stop when dates are added to the calendar. 65 Your HomeCU Support Team 89 function RetrieveCUEmailList($dbh, $thisYear, $nextYear) {
90 $SYS_TYPE_CLOSED = 64;
92 if (!isset($thisYear) || trim($thisYear) ==
"") {
93 throw new exception (
"This year is not valid.", 3);
95 if (!isset($nextYear) || trim($nextYear) ==
"") {
96 throw new exception (
"Next year is not valid.", 4);
98 $thisYear = intval($thisYear);
99 $nextYear = intval($nextYear);
100 if ($thisYear < 1000 || $thisYear > 9999) {
101 throw new exception (
"This year is not valid.", 5);
103 if ($nextYear < 1000 || $nextYear > 9999) {
104 throw new exception (
"Next year is not valid.", 6);
107 $sql =
"select a.cu, c.dates::json->>'lastnotify' as lastnotify 109 inner join cu_calendar d on a.cu = d.cu and d.year = '$thisYear' and d.dates::json->>0 is not null " .
110 "inner join cuinfo i on lower(a.cu) = i.user_name and (i.system_options & $SYS_TYPE_CLOSED) = 0 " .
111 "left join cu_calendar c on a.cu = c.cu and c.year = '$nextYear' 112 left join cuadminexclude e on a.cu = e.cu and e.program = '" . GetProgramName() .
"' 113 where e.cu is null " .
114 "and (c.cu is null or c.dates::json->>0 is null) " .
117 $sth = db_query($sql, $dbh);
119 throw new exception (
"Query is not valid.", 1);
121 $lastNotifyList = db_fetch_all($sth);
122 $lastNotifyList = $lastNotifyList ===
false ? array() : $lastNotifyList;
124 $sql =
"select cu, email from cuadmnotify where role = '" . GetEmailRole() .
"' order by cu";
125 $sth = db_query($sql, $dbh);
127 throw new exception (
"Query is not valid.", 2);
129 $emailList = db_fetch_all($sth);
131 if ($emailList !==
false) {
132 foreach($emailList as $emailRow) {
133 $cuEmailList = isset($emailRow[
"email"]) ? trim($emailRow[
"email"]) :
"";
134 if ($cuEmailList !=
"") {
135 $emailMap[trim($emailRow[
"cu"])] = $cuEmailList;
140 foreach($lastNotifyList as $i => $lastNotifyRow) {
141 $cu = trim($lastNotifyRow[
"cu"]);
142 if (HCU_array_key_exists($cu, $emailMap)) {
143 $lastNotifyList[$i][
"emails"] = $emailMap[$cu];
145 $lastNotifyList[$i][
"emails"] =
"";
149 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"data" => array(
"lastNotifyList" => $lastNotifyList));
150 }
catch (exception $e) {
151 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
167 function VerifyOpts($commandOptions) {
171 if ($commandOptions ===
false) {
172 throw new exception (
"getopt is invalid.", -1);
175 if (HCU_array_key_exists(
"help", $commandOptions)) {
176 throw new exception (
"Help is set.", -2);
179 if (HCU_array_key_exists(
"d", $commandOptions)) {
180 $date = $commandOptions[
"d"];
181 if (!isset($date) || trim($date) ==
"") {
182 throw new exception (
"Date is invalid.", 3);
184 $date = DateTime::createFromFormat(
"Y-m-d|", $commandOptions[
"d"]);
185 if ($date ===
false) {
186 throw new exception (
"Date is invalid.", 4);
189 $date =
new DateTime();
191 $date = $date->format(
"Y-m-d");
193 $dryrun = HCU_array_key_exists(
"dryrun", $commandOptions);
195 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"opts" => array(
"date" => $date,
"dryrun" => $dryrun));
196 }
catch (exception $e) {
197 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
212 function DoICare($currentDate) {
215 if (!isset($currentDate) || trim($currentDate) ==
"") {
216 throw new exception (
"Please enter the current date.", 1);
218 $currentDate = DateTime::createFromFormat(
"Y-m-d|", $currentDate);
219 if ($currentDate ===
false) {
220 throw new exception (
"Current date is invalid.", 2);
223 $currentYear = $currentDate->format(
"Y");
224 $caringDate = DateTime::createFromFormat(
"Y-m-d|", GetCaringDate($currentYear));
226 $doI = $currentDate >= $caringDate;
228 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"doICare" => $doI);
229 }
catch (exception $e) {
230 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
249 function ShouldISendEmail($currentDate, $lastNotifiedDate) {
252 if (!isset($currentDate) || trim($currentDate) ==
"") {
253 throw new exception (
"Please enter the current date.", 1);
255 $currentDate = DateTime::createFromFormat(
"Y-m-d|", $currentDate);
256 if ($currentDate ===
false) {
257 throw new exception (
"Current date is invalid.", 2);
260 $currentYear = $currentDate->format(
"Y");
262 if (!isset($lastNotifiedDate) || trim($lastNotifiedDate) ==
"") {
265 $lastNotifiedDate = DateTime::createFromFormat(
"Y-m-d|", $lastNotifiedDate);
267 if ($lastNotifiedDate ===
false) {
268 throw new exception (
"Last notified date is invalid.", 3);
271 $currentU = intval($currentDate->format(
"U"));
272 $lastU = intval($lastNotifiedDate->format(
"U"));
273 $dayDiff = ($currentU - $lastU) / 86400;
276 throw new exception (
"Last notified date cannot be after the current date.", 4);
283 $novemberOne = DateTime::createFromFormat(
"Y-m-d|",
"$currentYear-11-01");
284 $decemberOne = DateTime::createFromFormat(
"Y-m-d|",
"$currentYear-12-01");
286 if ($currentDate >= $decemberOne) {
287 $shouldI = $dayDiff >= 7;
288 }
else if ($currentDate >= $novemberOne) {
289 $shouldI = $dayDiff >= 14;
293 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"shouldISendEmail" => $shouldI);
294 }
catch (exception $e) {
295 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
311 function SendCuEmail($cu, $emails, $nextYear) {
313 if (!isset($cu) || trim($cu) ==
"") {
314 throw new exception (
"Cu is required.", 1);
317 if (!isset($nextYear)) {
318 throw new exception (
"Next Year is required.", 2);
320 $nextYear = intval($nextYear);
322 if ($nextYear < 1000 || $nextYear > 9999) {
323 throw new exception (
"Next Year is invalid.", 3);
325 $body = GetCuEmailBody($cu, $nextYear);
326 $subject =
"Please set up your calendar";
330 $notify->mailto = $emails;
331 $notify->subject = $subject;
332 $notify->htmlMsgbody = $body;
333 $notify->callingfunction = __FUNCTION__;
334 $notify->file = __FILE__;
338 $returnArray = array(
"status" =>
"000",
"error" =>
"");
339 }
catch (exception $e) {
340 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
358 function UpdateCuCalendar($dbh, $cu, $nextYear, $currentDate) {
360 if (!isset($cu) || trim($cu) ==
"") {
361 throw new exception (
"Cu is required.", 1);
364 if (!isset($nextYear)) {
365 throw new exception (
"Next Year is required.", 2);
368 if (!isset($currentDate) || trim($currentDate) ==
"") {
369 throw new exception (
"Date is required.", 6);
372 $nextYear = intval($nextYear);
374 if ($nextYear < 1000 || $nextYear > 9999) {
375 throw new exception (
"Next Year is invalid.", 3);
378 $currentDate = DateTime::createFromFormat(
"Y-m-d|", $currentDate);
379 if ($currentDate ===
false) {
380 throw new exception (
"Current date is invalid.", 7);
383 $currentDate = $currentDate->format(
"Y-m-d");
385 $dates = HCU_JsonEncode(array(
"lastnotify" => $currentDate));
387 $sql =
"select 'FOUND' from cu_calendar where cu = '" . prep_save($cu, 10) .
"' and year = '" . prep_save($nextYear, 4) .
"'";
388 $sth = db_query($sql, $dbh);
390 throw new exception (
"Query failed.", 4);
393 if (db_num_rows($sth) > 0) {
394 $sql =
"update cu_calendar set dates = '" . prep_save($dates) .
"' where cu = '" . prep_save($cu, 10) .
"' and year = '" . prep_save($nextYear, 4) .
"'";
396 $sql =
"insert into cu_calendar (cu, year, dates) values ('" . prep_save($cu, 10) .
"', '" . prep_save($nextYear, 4) .
"', '" . prep_save($dates) .
"')";
398 $sth = db_query($sql, $dbh);
400 throw new exception (
"Query failed.", 5);
403 $returnArray = array(
"status" =>
"000",
"error" =>
"");
404 }
catch (exception $e) {
405 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
420 function RemoveOldCalendars($dbh, $currentYear) {
422 if (!isset($currentYear) || trim($currentYear) ==
"") {
423 throw new exception (
"Current year is not valid.", 3);
425 $currentYear = intval($currentYear);
426 if ($currentYear < 1000 || $currentYear > 9999) {
427 throw new exception (
"Current year is not valid.", 5);
430 $removalYear = $currentYear - GetDeleteAfterYears();
432 $sql =
"delete from cu_calendar where year <= '" . prep_save($removalYear, 4) .
"'";
433 $sth = db_query($sql, $dbh);
435 throw new exception (
"Delete failed.", 6);
438 $returnArray = array(
"status" =>
"000",
"error" =>
"");
439 }
catch (exception $e) {
440 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());