return true;
}
+
+ // approveTimesheet marks a timesheet as approved and sends an email to submitter.
+ static function approveTimesheet($fields) {
+ global $user;
+ $mdb2 = getConnection();
+
+ $group_id = $user->getGroup();
+ $org_id = $user->org_id;
+
+ // First, mark a timesheet as approved.
+ // Even if mail part below does not work, this will get us a functioning workflow
+ // (without email notifications).
+ $timesheet_id = $fields['timesheet_id'];
+ $manager_comment = $fields['comment'];
+
+ $sql = "update tt_timesheets set approval_status = 1, manager_comment = ".$mdb2->quote($manager_comment).
+ " where id = $timesheet_id and submit_status = 1 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;
+ }
+
+ // disapproveTimesheet marks a timesheet as approved and sends an email to submitter.
+ static function disapproveTimesheet($fields) {
+ global $user;
+ $mdb2 = getConnection();
+
+ $group_id = $user->getGroup();
+ $org_id = $user->org_id;
+
+ // First, mark a timesheet as disapproved.
+ // Even if mail part below does not work, this will get us a functioning workflow
+ // (without email notifications).
+ $timesheet_id = $fields['timesheet_id'];
+ $manager_comment = $fields['comment'];
+
+ $sql = "update tt_timesheets set approval_status = 0, manager_comment = ".$mdb2->quote($manager_comment).
+ " where id = $timesheet_id and submit_status = 1 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;
+ }
}
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
- <td align="center"> Anuko Time Tracker 1.18.37.4753 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+ <td align="center"> Anuko Time Tracker 1.18.37.4754 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
<a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
<a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
<a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
<tr>
<td align="center">
<table>
- <tr><td>{$forms.timesheetForm.btn_approve.control} {$forms.timesheetForm.btn_disapprove.control}</td></tr>
+ <tr><td align="center">{$i18n.label.comment}:</td></tr>
+ <tr><td align="center">{$forms.timesheetForm.comment.control}</td></tr>
+ <tr><td align="center">{$forms.timesheetForm.btn_approve.control} {$forms.timesheetForm.btn_disapprove.control}</td></tr>
</table>
</td>
</tr>
// TODO: if this is a timeheet submit, validate approver id, too.
// End of access checks.
+if ($request->isPost()) {
+ $cl_comment = trim($request->getParameter('comment'));
+}
+
$options = ttTimesheetHelper::getReportOptions($timesheet);
$subtotals = ttReportHelper::getSubtotals($options);
$totals = ttReportHelper::getTotals($options);
$showSubmit = $notClient && !$timesheet['submit_status'];
if ($showSubmit) $approvers = ttTimesheetHelper::getApprovers($timesheet['user_id']);
$canApprove = $user->can('approve_timesheets') || $user_>can('approve_all_timesheets');
-$showApprove = $notClient && $timesheet['submit_status'] && !$timesheet['approval_status'];
+$showApprove = $notClient && $timesheet['submit_status'] && $timesheet['approval_status'] == null;
// Add a form with controls.
$form = new Form('timesheetForm');
}
if ($showApprove) {
+ $form->addInput(array('type'=>'textarea','name'=>'comment','maxlength'=>'250','style'=>'width: 300px; height: 60px;'));
$form->addInput(array('type'=>'submit','name'=>'btn_approve','value'=>$i18n->get('button.approve')));
$form->addInput(array('type'=>'submit','name'=>'btn_disapprove','value'=>$i18n->get('button.disapprove')));
}
} else
$err->add($i18n->get('error.db'));
}
+
+ if ($request->getParameter('btn_approve')) {
+ $fields = array('timesheet_id' => $timesheet['id'],
+ 'comment' => $cl_comment);
+ if (ttTimesheetHelper::approveTimesheet($fields)) {
+ // Redirect to self.
+ header('Location: timesheet_view.php?id='.$timesheet['id']);
+ exit();
+ } else
+ $err->add($i18n->get('error.db'));
+ }
+
+ if ($request->getParameter('btn_disapprove')) {
+ $fields = array('timesheet_id' => $timesheet['id'],
+ 'comment' => $cl_comment);
+ if (ttTimesheetHelper::disapproveTimesheet($fields)) {
+ // Redirect to self.
+ header('Location: timesheet_view.php?id='.$timesheet['id']);
+ exit();
+ } else
+ $err->add($i18n->get('error.db'));
+ }
}
$smarty->assign('not_client', $notClient);