4 * Send emails to users with open tasks
6 * Copyright 2004 GForge, LLC
7 * Copyright (C) 2010 Alain Peyrat - Alcatel-Lucent
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge 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 along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require dirname(__FILE__).'/../www/env.inc.php';
26 require_once $gfcommon.'include/pre.php';
27 require_once $gfcommon.'pm/ProjectTasksForUser.class.php';
28 require_once $gfcommon.'include/cron_utils.php';
32 // Get user id's from users who have open tasks
33 $res = db_query_params ('SELECT DISTINCT u.user_id, u.realname, u.email FROM users u, project_assigned_to pat, project_task_vw ptv
34 WHERE u.user_id > 100 AND u.user_id=pat.assigned_to_id AND pat.project_task_id=ptv.project_task_id
35 AND ptv.status_id=1 ORDER BY u.user_id;',
39 $today = date("n/j/y");
43 // for every user retrieved, get its open tasks and send an email
44 for ($i=0; $i<db_numrows($res);$i++) {
46 $user_id = db_result($res, $i, 'user_id');
47 $realname = db_result($res, $i, 'realname');
48 $email = db_result($res, $i, 'email');
50 // get an object of the User with the current user_id
51 $user_object = user_get_object($user_id);
52 if (!$user_object || !is_object($user_object)) {
53 $err .= "Could not get User object with ID: $user_id\n";
55 $projectTasksForUser = new ProjectTasksForUser($user_object);
57 if (!$projectTasksForUser || !is_object($projectTasksForUser)) {
58 $err .= "Could not get ProjectTasksForUser object for user with ID: $user_id\n";
62 // get the tasks the user should work on, today
63 $userTasks =& $projectTasksForUser->getTasksForToday();
65 $last_projectgroup = 0;
67 // start composing the email
68 $subject = 'Tasks for '.$realname.' for '.$today;
70 if (count($userTasks) > 0) {
72 $debug_info = "************ DEBUG FOR USER: $user_id ************\n";
74 // get the data of every task and compose the email
75 foreach ($userTasks as $task) {
76 if ($task->getPercentComplete() == 100) {
77 $debug_info .= "Task ID: ".$task->getID()." complete (100%)\n------------\n";
80 $debug_info .= 'Task ID: ' . $task->getID() . "\n";
82 $end_date = date("n/j/y", $task->getEndDate());
84 $projectGroup =& $task->getProjectGroup();
85 if ($projectGroup && is_object($projectGroup)) {
87 $debug_info .= 'Project Group ID: ' . $projectGroup->getID() . "\n";
89 $group =& $projectGroup->getGroup();
90 if ($group && is_object($group)) {
92 $debug_info .= 'Group ID: ' . $group->getID() . "\n";
94 if ($group->getID() != $last_group) {
95 echo "Project: ". $group->getPublicName()."\n";
97 if ($projectGroup->getID() != $last_projectgroup) {
98 echo "Subproject Name: ". $projectGroup->getName()."\n";
100 echo "Summary: ". html_entity_decode($task->getSummary())."\n";
101 echo 'Status: ***'. (($now>$task->getEndDate())? 'overdue' : "due $end_date"). "***\n";
102 echo util_make_url('/pm/task.php?func=detailtask&project_task_id='.
103 $task->getID().'&group_id='.$group->getID().'&group_project_id='.$projectGroup->getID());
106 $last_group = $group->getID();
107 $last_projectgroup = $projectGroup->getID();
111 $debug_info .= "------------\n";
113 $messagebody = ob_get_contents();
115 if ($valid_tasks > 0) {
116 util_send_message($email, $subject, $messagebody);
119 echo $debug_info."\n";