6 * send_pending_items_mail.php
8 * Sends mail out for all pending tracker and pm items
12 * ./send_pending_items_mail.php all
13 * sends mails both for tracker and pm items
15 * ./send_pending_items_mail.php tracker
16 * sends mail for tracker items
18 * ./send_pending_items_mail.php pm
19 * sends mail for pm items
21 * This file is part of GForge.
23 * GForge is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation; either version 2 of the License, or
26 * (at your option) any later version.
28 * GForge is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with GForge; if not, write to the Free Software
35 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 require ('common/include/cron_utils.php');
42 $options=$GLOBALS['argv'];
45 if (($option=='pm')|| ($option=='all')){
47 send_pending_pm_items_mail();
49 if (($option=='tracker')|| ($option=='all')){
50 echo "\nrunning tracker";
51 send_pending_tracker_items_mail();
55 function send_pending_pm_items_mail(){
58 /* first we check the tasks from the project_manager */
59 $sql='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<'.$time.' and project_task.group_project_id=project_group_list.group_project_id and project_task.status_id=1;';
60 $res = db_query($sql);
61 for($i = 0; $i < db_numrows($res); $i++) {
62 $summary= db_result($res,$i,'summary');
63 $status_name=db_result($res,$i,'status_name');
64 $user_name= db_result($res,$i,'user_name');
65 $project_task_id=db_result($res,$i,'project_task_id');
66 $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")
67 .'&group_project_id='.db_result($res,$i,"group_project_id"));
68 $sql="select * from users where users.status='A' and user_id in (".db_result($res,$i,"created_by").", (select assigned_to_id from project_assigned_to where project_task_id=".db_result($res,$i,"project_task_id")."))";
69 $userres=db_query($sql);
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 $sql = '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) < '.$time.' 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 $sql2='select * from users where user_id in '.$users.' and user_id>100';
110 $userres=db_query($sql2);
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());