+ $fields['to'] = $approver['email'];
+ $fields['subject'] = $i18n->get('form.timesheet_view.submit_subject');
+ $fields['body'] = sprintf($i18n->get('form.timesheet_view.submit_body'), $user->getName());
+
+ return ttTimesheetHelper::sendEmail($fields);
+ }
+
+ // sendApprovedEmail sends a notification to user about a timesheet approval.
+ static function sendApprovedEmail($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.approve_subject');
+ $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);
+ }
+
+ // sendEmail is a generic finction that sends a timesheet related email.
+ // TODO: perhaps make it even more generic for the entire application.
+ static function sendEmail($fields, $html = true) {
+ global $i18n;
+ global $user;
+
+ // Send email.
+ import('mail.Mailer');
+ $mailer = new Mailer();
+ $mailer->setCharSet(CHARSET);
+ if ($html)
+ $mailer->setContentType('text/html');
+ $mailer->setSender(SENDER);
+ $mailer->setReceiver($fields['to']);
+ if (!empty($user->bcc_email))
+ $mailer->setReceiverBCC($user->bcc_email);
+ $mailer->setMailMode(MAIL_MODE);
+ if (!$mailer->send($fields['subject'], $fields['body']))
+ return false;