4 * Send emails to users with open tasks
6 * Copyright 2004 GForge, LLC
8 * This file is part of GForge.
10 * GForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * GForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with GForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
25 require dirname(__FILE__).'/../www/env.inc.php';
26 require_once $gfwww.'include/pre.php';
27 require_once $gfcommon.'pm/ProjectTasksForUser.class.php';
28 require_once $gfcommon.'include/cron_utils.php';
33 // Set up this script to run as the site admin
35 $res = db_query_params ('SELECT user_id FROM user_group WHERE admin_flags=$1 AND group_id=$2',
44 if (db_numrows($res) == 0) {
47 $id=db_result($res,0,0);
50 // Get user id's from users who have open tasks
51 $res = db_query_params ('SELECT DISTINCT u.user_id, u.realname, u.email FROM users u, project_assigned_to pat, project_task_vw ptv
52 WHERE u.user_id > 100 AND u.user_id=pat.assigned_to_id AND pat.project_task_id=ptv.project_task_id
53 AND ptv.status_id=1 ORDER BY u.user_id;',
58 $today = date("n/j/y");
60 // for every user retrieved, get its open tasks and send an email
61 for ($i=0; $i<db_numrows($res);$i++) {
63 $user_id = db_result($res, $i, 'user_id');
64 $realname = db_result($res, $i, 'realname');
65 $email = db_result($res, $i, 'email');
67 // get an object of the User with the current user_id
68 $user_object = &user_get_object($user_id);
69 if (!$user_object || !is_object($user_object)) {
70 $err .= "Could not get User object with ID: $user_id\n";
72 $projectTasksForUser = new ProjectTasksForUser($user_object);
74 if (!$projectTasksForUser || !is_object($projectTasksForUser)) {
75 $err .= "Could not get ProjectTasksForUser object for user with ID: $user_id\n";
79 // get the tasks the user should work on, today
80 $userTasks =& $projectTasksForUser->getTasksForToday();
82 $last_projectgroup = 0;
84 // start composing the email
85 $subject = 'Tasks for '.$realname.' for '.$today;
87 if (count($userTasks) > 0) {
89 $debug_info = "************ DEBUG FOR USER: $user_id ************\n";
91 // get the data of every task and compose the email
92 foreach ($userTasks as $task) {
93 if ($task->getPercentComplete() == 100) {
94 $debug_info .= "Task ID: ".$task->getID()." complete (100%)\n------------\n";
97 $debug_info .= 'Task ID: ' . $task->getID() . "\n";
99 $end_date = date("n/j/y", $task->getEndDate());
101 $projectGroup =& $task->getProjectGroup();
102 if ($projectGroup && is_object($projectGroup)) {
104 $debug_info .= 'Project Group ID: ' . $projectGroup->getID() . "\n";
106 $group =& $projectGroup->getGroup();
107 if ($group && is_object($group)) {
109 $debug_info .= 'Group ID: ' . $group->getID() . "\n";
111 if ($group->getID() != $last_group) {
112 echo $group->getPublicName().":\n";
114 if ($projectGroup->getID() != $last_projectgroup) {
115 echo $projectGroup->getName().":\n";
117 echo html_entity_decode($task->getSummary()).":\n";
119 (($now>$task->getEndDate())? 'overdue' : "due $end_date").
121 echo util_make_url ('/pm/task.php?func=detailtask&project_task_id='.
122 $task->getID().'&group_id='.$group->getID().'&group_project_id='.$projectGroup->getID());
125 $last_group = $group->getID();
126 $last_projectgroup = $projectGroup->getID();
130 $debug_info .= "------------\n";
132 $messagebody = ob_get_contents();
134 if ($valid_tasks > 0) {
135 util_send_message($email, $subject, $messagebody);
138 echo $debug_info."\n";