5 $serviceMinimal =
true;
6 $serviceShowInfo =
false;
7 $serviceLoadMenu =
false;
8 $serviceShowMenu =
false;
9 $serviceLoadCuInfo =
false;
13 require_once(
'/var/www/html/banking/library/hcuService.i');
16 require_once(
"/var/www/html/system/library/sCalendarNotify.i" );
18 $dbhost = getenv(
'DATABASE_HOST');
19 $dbport = getenv(
'DATABASE_PORT');
20 $dbname = getenv(
'DATABASE_NAME');
21 $dbuser = getenv(
'DATABASE_USER');
22 $dbpasswd = getenv(
'DATABASE_PASSWORD');
24 $pReplyEmail =
"nobody\@homecu.net";
27 $logger = $HB_ENV[
"SYSENV"][
"logger"];
32 $allowedOptions =
"d::";
33 $longOptions = array(
"help",
"dryrun");
34 $commandOptions = getopt( $allowedOptions, $longOptions );
36 date_default_timezone_set (
"America/Denver" );
38 $results = VerifyOpts($commandOptions);
39 if ($results[
"status"] !==
"000") {
40 if ($results[
"status"] >= 0) {
41 $logger->error($results[
"error"]);
43 $logger->info(
"Usage: {$argv[0]} [-d\"YYYY-mm-dd\"]");
46 extract($results[
"opts"]);
49 $today = date(
"D M d, Y G:i", strtotime($date));
50 $currentDate = date (
"Y-m-d", strtotime($date));
51 $processName =
"Calendar Notify Process";
52 $currentYear = explode(
"-", $date);
53 $currentYear = intval($currentYear[0]);
54 $nextYear = $currentYear + 1;
57 $logger->info(
"$processName: $today $currentDate" );
60 $logger->info(
"$processName is in dry run mode. The database will not be updated and no emails will be sent out.");
63 $logger->info(
"$processName: Removing old calendar records.");
65 $results = RemoveOldCalendars($dbh, $currentYear);
66 if ($results[
"status"] !==
"000") {
67 throw new exception (
"Old calendars could not be deleted.", 3);
71 $results = DoICare($date);
72 if ($results[
"status"] !==
"000") {
73 throw new exception (
"CU List could not be created.", 2);
75 if (!$results[
"doICare"]) {
76 $msg =
"$processName: Exited due to being too early in the year.";
80 $fullResults = RetrieveCUEmailList($dbh, $currentYear, $nextYear);
81 if ($fullResults[
"status"] !==
"000") {
82 throw new exception (
"CU List could not be created.", 1);
85 foreach($fullResults[
"data"][
"lastNotifyList"] as $lastNotifyRow) {
86 $cu = trim($lastNotifyRow[
"cu"]);
87 $emails = $lastNotifyRow[
"emails"];
88 if (count($emails) == 0) {
89 $msg =
"$processName: $cu does not have emails set up.";
93 $results = ShouldISendEmail($currentDate, $lastNotifyRow[
"lastnotify"]);
94 if ($results[
"status"] !==
"000") {
95 throw new exception (
"$processName: Email logic is incorrect.", 3);
98 if ($results[
"shouldISendEmail"]) {
100 $msg =
"$processName: Sending emails for $cu...";
103 $results = SendCuEmail($cu, $emails, $nextYear);
104 if ($results[
"status"] !==
"000") {
105 $logger->error(
"$processName: Email to $email for $cu failed.");
111 $logger->info(
"$processName: Updating calendar record for $cu.");
113 $results = UpdateCuCalendar($dbh, $cu, $nextYear, $date);
114 if ($results[
"status"] !==
"000") {
115 $logger->error(
"$processName: Failed updating calendar record for $cu.");
122 $logger->info(
"$processName: Script was successful.");
124 }
catch (exception $e) {
126 $logger->error(
"$processName failed: " . $e->getMessage());
127 exit ($e->getCode());