Menu

[r13]: / alerts / daily_alert.php  Maximize  Restore  History

Download this file

236 lines (202 with data), 8.0 kB

  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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
/*
** Application name: phpCollab
** Last Edit page: 2006-09-30
** Path by root: ../alerts/daily_alert.php
** Authors: Rich Cave (cavemansf)
**
** =============================================================================
**
** phpCollab - Project Managment
**
** -----------------------------------------------------------------------------
** Please refer to license, copyright, and credits in README.TXT
**
** -----------------------------------------------------------------------------
** FILE: daily_alert.php
**
** DESC: Notifications for daily alerts triggered by a cron job
**
** HISTORY:
** -----------------------------------------------------------------------------
** TO-DO:
**
**
** =============================================================================
*/
// Define directories for include files
define("PHPCOLLAB_INC_DIR", dirname (__FILE__)."/../includes/");
define("PHPCOLLAB_LANG_DIR", dirname (__FILE__)."/../languages/");
// Include
include(PHPCOLLAB_INC_DIR."settings.php");
include(PHPCOLLAB_INC_DIR."request.class.php");
include(PHPCOLLAB_INC_DIR."notification.class.php");
if (!isset($langDefault) || ($langDefault=='')) { $langDefault = 'en'; }
include(PHPCOLLAB_LANG_DIR."lang_".$langDefault.".php");
// Check if emailAlerts is set to true
if ($emailAlerts == "false") {
// Return false
exit(1);
}
// Check that database vars are set
if (!defined('MYSERVER') || !defined('MYLOGIN') || !defined('MYPASSWORD') || !defined('MYDATABASE')) {
echo ($strings['error_server']);
exit(1);
}
// Create database requests
$alert = new request();
$alert->connectClass();
$alertSub = new request();
$alertSub->connectClass();
// Get table names
$membersTable = $tableCollab['members'];
$notificationsTable = $tableCollab['notifications'];
$tasksTable = $tableCollab['tasks'];
$subtasksTable = $tableCollab['subtasks'];
$projectsTable = $tableCollab['projects'];
// Get current date
$today = date("Y-m-d", time());
// Create new notification
$mail = new notification();
$mail->message_type = "alt";
// Get list of members and notification settings
$query = "SELECT $membersTable.id,
$membersTable.name,
$membersTable.email_work
FROM $membersTable, $notificationsTable
WHERE $membersTable.id = $notificationsTable.member
AND $notificationsTable.dailyAlert = 0";
// Gpet result
$alert->query($query);
// Loop to retrieve all rows
while ($alert->fetch()){
// Set member
$assignedTo = $row[0];
// Clear all recipients in TO array
$mail->ClearAddresses();
// Set email info
$mail->FromName = $row[1];
$mail->From = $row[2];
$mail->AddAddress($row[2], $row[1]);
$mail->Subject = $strings['daily_alert_subject'];
// Set default priority until otherwise notified
$mail->Priority = "3";
// Initialize body
$body = '';
// Initialize counts
$taskCount = 0;
$subtaskCount = 0;
// See if there are any tasks pending
$query = "SELECT $tasksTable.id,
$tasksTable.name,
$tasksTable.priority,
$tasksTable.status,
$tasksTable.completion,
$tasksTable.start_date,
$tasksTable.due_date,
$tasksTable.description,
$projectsTable.id,
$projectsTable.name
FROM $tasksTable, $projectsTable, $membersTable
WHERE $tasksTable.assigned_to = ".$assignedTo."
AND $tasksTable.status != 1
AND $tasksTable.due_date = '".$today."'
AND $tasksTable.project = $projectsTable.id
AND $tasksTable.assigned_to = $membersTable.id
ORDER BY $tasksTable.priority";
$alertSub->query($query);
// Create email body with link
while ($alertSub->fetch()){
// Set task body
if ($taskCount == 0) {
$body .= $strings['alert_daily_task']."\n";
$body .= "----------------------------------\n\n";
}
$body .= $strings['task']." : ".$row[1]." (".$row[0].") \n";
//$body .= $strings['project']." : ".$row[10]." (".$row[9].") \n";
$body .= $strings['project']." : ".$row[9]."\n";
//$body .= $strings['link']." : ".$root."/general/login.php?url=tasks/viewtask.php?id=".$row[0]."\n";
$body .= $strings['link']." : ".$root."/tasks/viewtask.php?id=".$row[0]."\n";
$body .= $strings['start_date']." : ".$row[5]."\n";
$body .= $strings['due_date']." : ".$row[6]."\n";
if ($row[4] == 0) {
$body .= $strings['completion']." : ".$row[4]."%\n";
} else {
$body .= $strings['completion']." : ".$row[4]."0%\n";
}
$body .= $strings['priority']." : ".$row[2]." - ".$priority[$row[2]]."\n";
$body .= $strings['status']." : ".$row[3]." - " .$status[$row[3]]."\n";
//$body .= $strings['description']." :\n".$row[7]."\n";
$body .= "\n\n--------\n\n";
// Set priority level if high priority
if ($row[2] == "4" || $row[2] == "5") {
$mail->Priority = "1";
}
// Update task count
$taskCount++;
}
// See if there are any subtasks pending
$query = "SELECT $subtasksTable.id,
$subtasksTable.name,
$subtasksTable.priority,
$subtasksTable.status,
$subtasksTable.completion,
$subtasksTable.start_date,
$subtasksTable.due_date,
$subtasksTable.description,
$tasksTable.id,
$tasksTable.name
FROM $subtasksTable, $tasksTable, $membersTable
WHERE $subtasksTable.assigned_to = ".$assignedTo."
AND $subtasksTable.status != 1
AND $subtasksTable.due_date = '".$today."'
AND $subtasksTable.task = $tasksTable.id
AND $subtasksTable.assigned_to = $membersTable.id
ORDER BY $subtasksTable.priority";
$alertSub->query($query);
// Create email body with link
while ($alertSub->fetch()){
// Set subtask body
if ($subtaskCount == 0) {
$body .= $strings['alert_daily_subtask']."\n";
$body .= "----------------------------------\n\n";
}
$body .= $strings['task']." : ".$row[1]." (".$row[0].") \n";
//$body .= $strings['link']." : ".$root."/general/login.php?url=subtasks/viewsubtask.php?id=".$row[0]."?task=".$row[8]."\n";
$body .= $strings['link']." : ".$root."/subtasks/viewsubtask.php?id=".$row[0]."&task=".$row[8]."\n";
$body .= $strings['task']." : ".$row[9]." (".$row[8].") \n";
$body .= $strings['start_date']." : ".$row[5]."\n";
$body .= $strings['due_date']." : ".$row[6]."\n";
if ($row[4] == 0) {
$body .= $strings['completion']." : ".$row[4]."%\n";
} else {
$body .= $strings['completion']." : ".$row[4]."0%\n";
}
$body .= $strings['priority']." : ".$row[2]." - ".$priority[$row[2]]."\n";
$body .= $strings['status']." : ".$row[3]." - " .$status[$row[3]]."\n";
//$body .= $strings['description']." :\n".$row[7]."\n";
$body .= "\n\n--------\n\n";
// Set priority level if high priority
if ($row[2] == "4" || $row[2] == "5") {
$mail->Priority = "1";
}
// Update subtask count
$subtaskCount++;
}
// If tasks found, send email alert
if ($taskCount > 0 || $subtaskCount > 0) {
// Set body
$mailBody = $mail->header;
$mailBody .= $body;
$mailBody .= "\n".$mail->footer;
$mail->Body = $mailBody;
// Send daily alert
$mail->Send();
}
}
// Close db connections
$alert->close();
$alertSub->close();
// Return successfully
exit(0);
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.