4 * Send emails to users with open tasks
6 * Copyright 2004 GForge, LLC
10 * This file is part of GForge.
12 * GForge is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * GForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with GForge; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
27 require_once('squal_pre.php');
28 require_once('common/pm/ProjectTasksForUser.class');
29 require_once('common/include/cron_utils.php');
33 // Get user id's from users who have open tasks
34 $res = db_query("SELECT DISTINCT u.user_id, u.realname, u.email FROM users u, project_assigned_to pat, project_task_vw ptv
35 WHERE u.user_id > 100 AND u.user_id=pat.assigned_to_id AND pat.project_task_id=ptv.project_task_id
36 AND ptv.status_id=1 ORDER BY u.user_id;");
39 $today = date("n/j/y");
41 // for every user retrieved, get its open tasks and send an email
42 for ($i=0; $i<db_numrows($res);$i++) {
44 $user_id = db_result($res, $i, 'user_id');
45 $realname = db_result($res, $i, 'realname');
46 $email = db_result($res, $i, 'email');
48 // get an object of the User with the current user_id
49 $user_object = &user_get_object($user_id);
50 if (!$user_object || !is_object($user_object)) {
51 $err .= "Could not get User object with ID: $user_id\n";
54 $projectTasksForUser = new ProjectTasksForUser($user_object);
55 if (!$projectTasksForUser || !is_object($projectTasksForUser)) {
56 $err .= "Could not get ProjectTasksForUser object for user with ID: $user_id\n";
59 // get the tasks the user should work on, today
60 $userTasks =& $projectTasksForUser->getTasksForToday();
62 // start composing the email
63 $subject = 'Tasks for '.$realname.' for '.$today;
64 if (count($userTasks) > 0) {
66 // get the data of every task and compose the email
67 foreach ($userTasks as $task) {
69 $end_date = date("n/j/y", $task->getEndDate());
71 $projectGroup =& $task->getProjectGroup();
72 if ($projectGroup && is_object($projectGroup)) {
74 $group =& $projectGroup->getGroup();
75 if ($group && is_object($group)) {
77 if ($group->getID() != $last_group) {
78 echo $group->getPublicName().":\n";
80 if ($projectGroup->getID() != $last_projectgroup) {
81 echo $projectGroup->getName().":\n";
83 echo html_entity_decode($task->getSummary()).":\n";
85 (($now>$task->getEndDate())? 'overdue' : "due $end_date").
87 echo 'http://'.$sys_default_domain.'/pm/task.php?func=detailtask&project_task_id='.
88 $task->getID().'&group_id='.$group->getID().'&group_project_id='.$projectGroup->getID();
91 $last_group = $group->getID();
92 $last_projectgroup = $projectGroup->getID();
96 $messagebody = ob_get_contents();
98 util_send_message($email, $subject, $messagebody);
99 // echo "\n\n\n***************************************************\nTo: $email\nSubject: $subject\n\n$messagebody";