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');
32 // Set up this script to run as the site admin
34 $res = db_query("SELECT user_id FROM user_group WHERE admin_flags='A' AND group_id='1'");
40 if (db_numrows($res) == 0) {
43 $id=db_result($res,0,0);
46 // Get user id's from users who have open tasks
47 $res = db_query("SELECT DISTINCT u.user_id, u.realname, u.email FROM users u, project_assigned_to pat, project_task_vw ptv
48 WHERE u.user_id > 100 AND u.user_id=pat.assigned_to_id AND pat.project_task_id=ptv.project_task_id
49 AND ptv.status_id=1 ORDER BY u.user_id;");
52 $today = date("n/j/y");
54 // for every user retrieved, get its open tasks and send an email
55 for ($i=0; $i<db_numrows($res);$i++) {
57 $user_id = db_result($res, $i, 'user_id');
58 $realname = db_result($res, $i, 'realname');
59 $email = db_result($res, $i, 'email');
61 // get an object of the User with the current user_id
62 $user_object = &user_get_object($user_id);
63 if (!$user_object || !is_object($user_object)) {
64 $err .= "Could not get User object with ID: $user_id\n";
66 $projectTasksForUser = new ProjectTasksForUser($user_object);
68 if (!$projectTasksForUser || !is_object($projectTasksForUser)) {
69 $err .= "Could not get ProjectTasksForUser object for user with ID: $user_id\n";
73 // get the tasks the user should work on, today
74 $userTasks =& $projectTasksForUser->getTasksForToday();
76 $last_projectgroup = 0;
78 // start composing the email
79 $subject = 'Tasks for '.$realname.' for '.$today;
81 if (count($userTasks) > 0) {
83 $debug_info = "************ DEBUG FOR USER: $user_id ************\n";
85 // get the data of every task and compose the email
86 foreach ($userTasks as $task) {
87 if ($task->getPercentComplete() == 100) {
88 $debug_info .= "Task ID: ".$task->getID()." complete (100%)\n------------\n";
91 $debug_info .= 'Task ID: ' . $task->getID() . "\n";
93 $end_date = date("n/j/y", $task->getEndDate());
95 $projectGroup =& $task->getProjectGroup();
96 if ($projectGroup && is_object($projectGroup)) {
98 $debug_info .= 'Project Group ID: ' . $projectGroup->getID() . "\n";
100 $group =& $projectGroup->getGroup();
101 if ($group && is_object($group)) {
103 $debug_info .= 'Group ID: ' . $group->getID() . "\n";
105 if ($group->getID() != $last_group) {
106 echo $group->getPublicName().":\n";
108 if ($projectGroup->getID() != $last_projectgroup) {
109 echo $projectGroup->getName().":\n";
111 echo html_entity_decode($task->getSummary()).":\n";
113 (($now>$task->getEndDate())? 'overdue' : "due $end_date").
115 echo 'http://'.$sys_default_domain.'/pm/task.php?func=detailtask&project_task_id='.
116 $task->getID().'&group_id='.$group->getID().'&group_project_id='.$projectGroup->getID();
119 $last_group = $group->getID();
120 $last_projectgroup = $projectGroup->getID();
124 $debug_info .= "------------\n";
126 $messagebody = ob_get_contents();
128 if ($valid_tasks > 0) {
129 util_send_message($email, $subject, $messagebody);
132 echo $debug_info."\n";