4 * send_pending_items_mail.php
6 * Sends mail out for all pending tracker and pm items
10 * ./send_pending_items_mail.php all
11 * sends mails both for tracker and pm items
13 * ./send_pending_items_mail.php tracker
14 * sends mail for tracker items
16 * ./send_pending_items_mail.php pm
17 * sends mail for pm items
19 * This file is part of GForge.
21 * GForge is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
24 * (at your option) any later version.
26 * GForge is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with GForge; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 require_once $gfcommon.'include/pre.php';
37 require $gfcommon.'include/cron_utils.php';
40 $options=$GLOBALS['argv'];
43 if (($option=='pm')|| ($option=='all')){
45 send_pending_pm_items_mail();
47 if (($option=='tracker')|| ($option=='all')){
48 echo "\nrunning tracker";
49 send_pending_tracker_items_mail();
53 function send_pending_pm_items_mail(){
56 /* first we check the tasks from the project_manager */
57 $res = db_query_params ('SELECT project_task.project_task_id, project_task.group_project_id, project_group_list.group_project_id, group_id, project_task.summary,project_task.created_by, project_task.status_id, project_task_vw.user_name, project_task_vw.status_name, project_task_vw.percent_complete FROM project_task, project_group_list NATURAL JOIN project_task_vw WHERE project_task.end_date > 0 AND project_task.end_date < $1 AND project_task.group_project_id=project_group_list.group_project_id AND project_task.status_id=1;',
59 for($i = 0; $i < db_numrows($res); $i++) {
60 $summary= db_result($res,$i,'summary');
61 $status_name=db_result($res,$i,'status_name');
62 $user_name= db_result($res,$i,'user_name');
63 $project_task_id=db_result($res,$i,'project_task_id');
64 $hyperlink=util_make_url('/pm/task.php?func=detailtask&project_task_id='.db_result($res,$i,"project_task_id").'&group_id='.db_result($res,$i,"group_id")
65 .'&group_project_id='.db_result($res,$i,"group_project_id"));
67 $userres = db_query_params ('SELECT * FROM users WHERE users.status=$1 AND (user_id = $2 OR user_id IN (SELECT assigned_to_id FROM project_assigned_to WHERE project_task_id = $3))',
69 db_result($res,$i,"created_by"),
70 db_result($res,$i,"project_task_id")));
71 /* now, for each user, send the mail */
72 for ($usercount=0;$usercount<db_numrows($userres);$usercount++){
73 $mailto=db_result($userres,$usercount,"email");
74 $language=db_result($userres,$usercount,"language");
75 setup_gettext_from_language_id($language);
76 $subject=_('Pending task manager items notification');
77 $messagebody=stripcslashes(sprintf(_('This mail is sent to you to remind you of pending/overdue tasks.
78 The task manager item #%1$s is pending:
82 Percent Complete: %6$s
84 Click here to visit the item %3$s'), $project_task_id, $summary, $hyperlink, $user_name, $status_name, db_result($res, $i,'percent_complete')));
85 util_send_message($mailto,$subject,$messagebody);
88 cron_entry(19,db_error());
92 function send_pending_tracker_items_mail(){
93 /* first, get all the items that are considered overdue */
95 $res = db_query_params ('SELECT artifact_id, submitted_by, group_id, assigned_to, summary, details, description, assigned_realname, submitted_realname, status_name, category_name, group_name, group_artifact_id, open_date FROM artifact_vw a NATURAL JOIN artifact_group_list agl WHERE (agl.due_period+a.open_date) < $1 AND a.status_id=1',
98 for ($tmp=0; $tmp<db_numrows($res); $tmp++) {
99 $realopendate=date(_('Y-m-d H:i'), db_result($res,$tmp,'open_date'));
100 $status_name=db_result($res,$tmp,'status_name');
101 $details=db_result($res,$tmp,'detail');
102 $summary= db_result($res,$tmp,'summary');
103 $users='('.db_result($res,$tmp,"submitted_by").','.db_result($res,$tmp,"assigned_to").')';
104 $hyperlink=util_make_url('/tracker/index.php?func=detail&aid='.db_result($res,$tmp,"artifact_id").'&group_id='.db_result($res,$tmp,"group_id")
105 .'&atid='.db_result($res,$tmp,"group_artifact_id"));
106 $artifact=db_result($res,$tmp,"artifact_id");
107 $opendate=db_result($res,$tmp,"open_date");
109 /* now, get all the users */
110 $userres = db_query_params ('SELECT * FROM users WHERE user_id = ANY ($1) AND user_id > 100',
111 array(db_int_array_to_any_clause ($users)));
112 for ($usercount=0;$usercount<db_numrows($userres);$usercount++){
113 $mailto=db_result($userres,$usercount,"email");
114 $language=db_result($userres,$usercount,"language");
115 setup_gettext_from_language_id($language);
116 $subject=_('Pending tracker items notification');
117 $messagebody=stripcslashes(sprintf(_('This mail is sent to you to remind you of pending/overdue tracker items. The item #%1$s is pending:
126 Click here to visit the item: %4$s'), $artifact, $opendate, $summary, $hyperlink, $status_name, $realopendate, db_result($res,$tmp,'assigned_realname'), db_result($res,$tmp,'submitted_realname'), db_result($res,$tmp,'details')));
127 /* and finally send the email */
128 util_send_message($mailto,$subject,$messagebody);
131 cron_entry(19,db_error());
136 // c-file-style: "bsd"