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 FusionForge. FusionForge is free software;
20 * you can redistribute it and/or modify it under the terms of the
21 * GNU General Public License as published by the Free Software
22 * Foundation; either version 2 of the Licence, or (at your option)
25 * FusionForge is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License along
31 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
32 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35 require_once $gfcommon.'include/pre.php';
36 require $gfcommon.'include/cron_utils.php';
39 $options=$GLOBALS['argv'];
42 if (($option=='pm')|| ($option=='all')){
44 send_pending_pm_items_mail();
46 if (($option=='tracker')|| ($option=='all')){
47 echo "\nrunning tracker";
48 send_pending_tracker_items_mail();
52 function send_pending_pm_items_mail(){
55 /* first we check the tasks from the project_manager */
56 $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;',
58 for($i = 0; $i < db_numrows($res); $i++) {
59 $summary= db_result($res,$i,'summary');
60 $status_name=db_result($res,$i,'status_name');
61 $user_name= db_result($res,$i,'user_name');
62 $project_task_id=db_result($res,$i,'project_task_id');
63 $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")
64 .'&group_project_id='.db_result($res,$i,"group_project_id"));
66 $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))',
68 db_result($res,$i,"created_by"),
69 db_result($res,$i,"project_task_id")));
70 /* now, for each user, send the mail */
71 for ($usercount=0;$usercount<db_numrows($userres);$usercount++){
72 $mailto=db_result($userres,$usercount,"email");
73 $language=db_result($userres,$usercount,"language");
74 setup_gettext_from_language_id($language);
75 $subject=_('Pending task manager items notification');
76 $messagebody=stripcslashes(sprintf(_('This mail is sent to you to remind you of pending/overdue tasks.
77 The task manager item #%1$s is pending:
81 Percent Complete: %6$s
83 Click here to visit the item %3$s'), $project_task_id, $summary, $hyperlink, $user_name, $status_name, db_result($res, $i,'percent_complete')));
84 util_send_message($mailto,$subject,$messagebody);
87 cron_entry(19,db_error());
91 function send_pending_tracker_items_mail(){
92 /* first, get all the items that are considered overdue */
94 $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',
97 for ($tmp=0; $tmp<db_numrows($res); $tmp++) {
98 $realopendate=date(_('Y-m-d H:i'), db_result($res,$tmp,'open_date'));
99 $status_name=db_result($res,$tmp,'status_name');
100 $details=db_result($res,$tmp,'detail');
101 $summary= db_result($res,$tmp,'summary');
102 $users='('.db_result($res,$tmp,"submitted_by").','.db_result($res,$tmp,"assigned_to").')';
103 $hyperlink=util_make_url('/tracker/index.php?func=detail&aid='.db_result($res,$tmp,"artifact_id").'&group_id='.db_result($res,$tmp,"group_id")
104 .'&atid='.db_result($res,$tmp,"group_artifact_id"));
105 $artifact=db_result($res,$tmp,"artifact_id");
106 $opendate=db_result($res,$tmp,"open_date");
108 /* now, get all the users */
109 $userres = db_query_params ('SELECT * FROM users WHERE user_id = ANY ($1) AND user_id > 100',
110 array(db_int_array_to_any_clause ($users)));
111 for ($usercount=0;$usercount<db_numrows($userres);$usercount++){
112 $mailto=db_result($userres,$usercount,"email");
113 $language=db_result($userres,$usercount,"language");
114 setup_gettext_from_language_id($language);
115 $subject=_('Pending tracker items notification');
116 $messagebody=stripcslashes(sprintf(_('This mail is sent to you to remind you of pending/overdue tracker items. The item #%1$s is pending:
125 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')));
126 /* and finally send the email */
127 util_send_message($mailto,$subject,$messagebody);
130 cron_entry(19,db_error());
135 // c-file-style: "bsd"