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(_('This mail is sent to you to remind you of pending/overdue tasks.') . ' '
77 . sprintf(_('The task manager item #%s is pending'), $project_task_id)._(': ') . "\n"
78 . _('Task Summary')._(': ') . $summary . "\n"
79 . _('Submitted by')._(': ') . $user_name . "\n"
80 . _('Status')._(': ') . $status_name . "\n"
81 . _('Percent Complete')._(': ') . db_result($res, $i,'percent_complete') . "\n\n"
82 . sprintf(_('Click here to visit the item %s'), $hyperlink));
83 util_send_message($mailto,$subject,$messagebody);
86 cron_entry(19,db_error());
89 function send_pending_tracker_items_mail(){
90 /* first, get all the items that are considered overdue */
92 $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',
95 for ($tmp=0; $tmp<db_numrows($res); $tmp++) {
96 $realopendate=date(_('Y-m-d H:i'), db_result($res,$tmp,'open_date'));
97 $status_name=db_result($res,$tmp,'status_name');
98 $detail=db_result($res,$tmp,'detail');
99 $summary= db_result($res,$tmp,'summary');
100 $users='('.db_result($res,$tmp,"submitted_by").','.db_result($res,$tmp,"assigned_to").')';
101 $hyperlink=util_make_url('/tracker/index.php?func=detail&aid='.db_result($res,$tmp,"artifact_id").'&group_id='.db_result($res,$tmp,"group_id")
102 .'&atid='.db_result($res,$tmp,"group_artifact_id"));
103 $artifact=db_result($res,$tmp,"artifact_id");
104 $opendate=db_result($res,$tmp,"open_date");
106 /* now, get all the users */
107 $userres = db_query_params ('SELECT * FROM users WHERE user_id = ANY ($1) AND user_id > 100',
108 array(db_int_array_to_any_clause ($users)));
109 for ($usercount=0;$usercount<db_numrows($userres);$usercount++){
110 $mailto=db_result($userres,$usercount,"email");
111 $language=db_result($userres,$usercount,"language");
112 setup_gettext_from_language_id($language);
113 $subject=_('Pending tracker items notification');
114 $messagebody = stripcslashes(_('This mail is sent to you to remind you of pending/overdue tracker items.') . ' '
115 . sprintf(_('The item #%s is pending'), $artifact)._(': ') . "\n"
116 . _('Summary')._(': ') . $summary . "\n"
117 . _('Status')._(': ') . $status_name . "\n"
118 . _('Open Date')._(': ') . $realopendate . "\n"
119 . _('Assigned to')._(': ') . db_result($res,$tmp,'submitted_realname') . "\n"
120 . _('Submitted by')._(': ') . db_result($res,$tmp,'submitted_realname') . "\n"
121 . _('Details')._(': ') . $detail . "\n\n"
122 . sprintf(_('Click here to visit the item %s'), $hyperlink));
123 /* and finally send the email */
124 util_send_message($mailto,$subject,$messagebody);
127 cron_entry(19,db_error());
132 // c-file-style: "bsd"