From: Nik Okuntseff Date: Tue, 5 Mar 2019 17:03:41 +0000 (+0000) Subject: Timesheet email workflow done. X-Git-Tag: timetracker_1.19-1~220 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=53c471451a8cb9e0fefd6d5907220bafdd77b53e;p=timetracker.git Timesheet email workflow done. --- diff --git a/WEB-INF/lib/ttTimesheetHelper.class.php b/WEB-INF/lib/ttTimesheetHelper.class.php index ca837fe7..240d9131 100644 --- a/WEB-INF/lib/ttTimesheetHelper.class.php +++ b/WEB-INF/lib/ttTimesheetHelper.class.php @@ -333,7 +333,24 @@ class ttTimesheetHelper { $fields['to'] = $email; $fields['subject'] = $i18n->get('form.timesheet_view.approve_subject'); - $fields['body'] = sprintf($i18n->get('form.timesheet_view.approve_body'), htmlspecialchars($fields['name'])); + $fields['body'] = sprintf($i18n->get('form.timesheet_view.approve_body'), htmlspecialchars($fields['name']), htmlspecialchars($fields['comment'])); + + return ttTimesheetHelper::sendEmail($fields); + } + + // sendDisapprovedEmail sends a notification to user about a timesheet disapproval. + static function sendDisapprovedEmail($fields) { + global $i18n; + global $user; + + // Obtain user email. + $user_details = $user->getUserDetails($fields['user_id']); + $email = $user_details['email']; + if (!$email) return true; // No email to send to, nothing to do. + + $fields['to'] = $email; + $fields['subject'] = $i18n->get('form.timesheet_view.disapprove_subject'); + $fields['body'] = sprintf($i18n->get('form.timesheet_view.disapprove_body'), htmlspecialchars($fields['name']), htmlspecialchars($fields['comment'])); return ttTimesheetHelper::sendEmail($fields); } @@ -379,8 +396,8 @@ class ttTimesheetHelper { return (!is_a($affected, 'PEAR_Error')); } - // disapproveTimesheet marks a timesheet as approved and sends an email to submitter. - static function disapproveTimesheet($fields) { + // markDisapproved marks a timesheet as not approved. + static function markDisapproved($fields) { global $user; $mdb2 = getConnection(); @@ -388,19 +405,13 @@ class ttTimesheetHelper { $group_id = $user->getGroup(); $org_id = $user->org_id; - // First, mark timesheet as disapproved. - // Even if mail part below does not work, this will get us a functioning workflow - // without email notification. $timesheet_id = $fields['timesheet_id']; $comment = $fields['comment']; $sql = "update tt_timesheets set approve_status = 0, approve_comment = ".$mdb2->quote($comment). " where id = $timesheet_id and submit_status = 1 and user_id = $user_id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); - if (is_a($affected, 'PEAR_Error')) return false; - - // TODO: send email to submitter here... - return true; + return (!is_a($affected, 'PEAR_Error')); } // The timesheetItemsExist determines whether tt_log records exist in the specified period diff --git a/WEB-INF/resources/en.lang.php b/WEB-INF/resources/en.lang.php index fdf72ae6..18d87eec 100644 --- a/WEB-INF/resources/en.lang.php +++ b/WEB-INF/resources/en.lang.php @@ -557,7 +557,7 @@ $i18n_key_words = array( 'form.timesheet_view.submit_subject' => 'Timesheet approval request', 'form.timesheet_view.submit_body' => "A new timesheet requires approval.

User: %s.", 'form.timesheet_view.approve_subject' => 'Timesheet approved', -'form.timesheet_view.approve_body' => "Your timesheet %s was approved.", +'form.timesheet_view.approve_body' => "Your timesheet %s was approved.

%s", 'form.timesheet_view.disapprove_subject' => 'Timesheet not approved', -'form.timesheet_view.disapprove_subject' => "Your timesheet %s was not approved.", +'form.timesheet_view.disapprove_body' => "Your timesheet %s was not approved.

%s", ); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 1a85ccfc..e4384ddb 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.52.4825 | Copyright © Anuko | +  Anuko Time Tracker 1.18.53.4826 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/timesheet_view.php b/timesheet_view.php index f6e8aac7..c8d7048a 100644 --- a/timesheet_view.php +++ b/timesheet_view.php @@ -124,13 +124,19 @@ if ($request->isPost()) { if ($request->getParameter('btn_disapprove')) { $fields = array('timesheet_id' => $timesheet['id'], + 'name' => $timesheet['name'], + 'user_id' => $timesheet['user_id'], 'comment' => $cl_comment); - if (ttTimesheetHelper::disapproveTimesheet($fields)) { + if (!ttTimesheetHelper::markDisapproved($fields)) + $err->add($i18n->get('error.db')); + if ($err->no() && !ttTimesheetHelper::sendDisapprovedEmail($fields)) { + $err->add($i18n->get('error.mail_send')); + } + if ($err->no()) { // Redirect to self. header('Location: timesheet_view.php?id='.$timesheet['id']); exit(); - } else - $err->add($i18n->get('error.db')); + } } }