-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsendAlerts.php
102 lines (80 loc) · 3.42 KB
/
sendAlerts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
**************************************************************************************************************************
** CORAL Resources Module v. 1.0
**
** Copyright (c) 2010 University of Notre Dame
**
** This file is part of CORAL.
**
** CORAL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
**
** CORAL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along with CORAL. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************************************************************
*/
session_start();
include_once 'directory.php';
$util = new Utility();
$config = new Configuration();
if ($config->settings->enableAlerts == 'Y'){
$alertDaysInAdvance = new AlertDaysInAdvance();
//returns array of all days in advance objects
$alertDaysArray = $alertDaysInAdvance->all();
$resourceIDArray = array();
//loop through each of the days, e.g. 30, 60, 90
foreach ($alertDaysArray as $alertDays){
//get resources that fit this criteria
if (is_numeric($alertDays->daysInAdvanceNumber)){
foreach($alertDays->getResourcesToAlert() as $resource){
$resourceIDArray[] = $resource->resourceID;
}
}
}
if (count($resourceIDArray) > 0){
//now get unique resource IDs out
$resourceIDArray = array_unique($resourceIDArray);
//now loop through each resource and send the email alert
foreach ($resourceIDArray as $resourceID){
$resource = new Resource(new NamedArguments(array('primaryKey' => $resourceID)));
$sendToArray = array();
//determine who to send the email to
$alertEmailAddress = new AlertEmailAddress();
foreach($alertEmailAddress->allAsArray() as $alertEmail){
$sendToArray[] = $alertEmail['emailAddress'];
}
//formulate email to be sent
$email = new Email();
$email->to = implode(", ", $sendToArray);
$email->message = $util->createMessageFromTemplate('Alert', $resourceID, $resource->titleText, '', '', '');
$email->subject = "CORAL Alert: " . $resource->titleText;
$email->send();
}
} else {
echo _("No Resources found fitting alert day criteria");
}
//Get all Issues that should be alerted today
$Issue = new Issue();
$alertableIssuesArray = $Issue->getAllAlertable();
//If we have alertable issues then loop over them
if (count($alertableIssuesArray) > 0){
foreach($alertableIssuesArray as $alertableIssue) {
//start building the email body
$emailMessage = _("This is a reminder that this issue needs to be revisited.\r\n\r\n
Body: {$alertableIssue['bodyText']}\r\n\r\n
Applies To: {$alertableIssue['appliesto']}\r\n
\r\n\r\nContacts: \r\n\r\n
{$alertableIssue['contacts']}\r\n");
foreach(explode(",", $alertableIssue['CCs']) as $emailAddr) {
mail($emailAddr, _("Reminder: {$alertableIssue['subjectText']}"),$emailMessage);
}
}
} else {
echo _("No Issues found fitting alert day criteria");
}
} else {
echo _("Alerts not enabled in configuration.ini file");
}
?>