2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 require_once('initialize.php');
30 import('ttTimesheetHelper');
31 import('ttReportHelper');
34 if (!(ttAccessAllowed('track_own_time') || ttAccessAllowed('track_time'))) {
35 header('Location: access_denied.php');
38 if (!$user->isPluginEnabled('ts')) {
39 header('Location: feature_disabled.php');
42 $cl_timesheet_id = (int)$request->getParameter('id');
43 $timesheet = ttTimesheetHelper::getTimesheet($cl_timesheet_id);
45 header('Location: access_denied.php');
48 // TODO: add other checks here for timesheet being appropriate for user role.
49 // TODO: if this is a timesheet submit, validate approver id, too.
50 // End of access checks.
52 if ($request->isPost()) {
53 $cl_comment = trim($request->getParameter('comment'));
54 $approver_id = $request->getParameter('approver');
57 $options = ttTimesheetHelper::getReportOptions($timesheet);
58 $subtotals = ttReportHelper::getSubtotals($options);
59 $totals = ttReportHelper::getTotals($options);
61 // Determine which controls to show and obtain date for them.
62 $showSubmit = !$timesheet['submit_status'];
64 $approvers = ttTimesheetHelper::getApprovers();
65 $showApprovers = count($approvers) >= 1;
67 $canApprove = $user->can('approve_timesheets') || $user->can('approve_own_timesheets');
68 $showApprove = $timesheet['submit_status'] && $timesheet['approve_status'] == null;
70 // Add a form with controls.
71 $form = new Form('timesheetForm');
72 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$timesheet['id']));
76 $form->addInput(array('type'=>'combobox',
78 'style'=>'width: 200px;',
80 'datakeys'=>array('id','name','email')));
82 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.submit')));
86 $form->addInput(array('type'=>'textarea','name'=>'comment','maxlength'=>'250','style'=>'width: 300px; height: 60px;'));
87 $form->addInput(array('type'=>'submit','name'=>'btn_approve','value'=>$i18n->get('button.approve')));
88 $form->addInput(array('type'=>'submit','name'=>'btn_disapprove','value'=>$i18n->get('button.disapprove')));
92 if ($request->isPost()) {
93 if ($request->getParameter('btn_submit')) {
94 $fields = array('timesheet_id' => $timesheet['id'],
95 'approver_id' => $approver_id); // TODO: obtain (and check) approver id above during access checks.
96 if (!ttTimesheetHelper::submitTimesheet($fields))
97 $err->add($i18n->get('error.db'));
98 if ($err->no() && !ttTimesheetHelper::sendSubmitEmail($fields)) {
99 $err->add($i18n->get('error.mail_send'));
103 header('Location: timesheet_view.php?id='.$timesheet['id']);
108 if ($request->getParameter('btn_approve')) {
109 $fields = array('timesheet_id' => $timesheet['id'],
110 'comment' => $cl_comment);
111 if (ttTimesheetHelper::approveTimesheet($fields)) {
113 header('Location: timesheet_view.php?id='.$timesheet['id']);
116 $err->add($i18n->get('error.db'));
119 if ($request->getParameter('btn_disapprove')) {
120 $fields = array('timesheet_id' => $timesheet['id'],
121 'comment' => $cl_comment);
122 if (ttTimesheetHelper::disapproveTimesheet($fields)) {
124 header('Location: timesheet_view.php?id='.$timesheet['id']);
127 $err->add($i18n->get('error.db'));
131 $smarty->assign('not_client', $notClient);
132 $smarty->assign('group_by_header', ttReportHelper::makeGroupByHeader($options));
133 $smarty->assign('timesheet', $timesheet);
134 $smarty->assign('subtotals', $subtotals);
135 $smarty->assign('totals', $totals);
136 $smarty->assign('show_approvers', $showApprovers);
137 $smarty->assign('show_submit', $showSubmit);
138 $smarty->assign('show_approve', $showApprove);
139 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
140 $smarty->assign('title', $i18n->get('title.timesheet').": ".$timesheet['start_date']." - ".$timesheet['end_date']);
141 $smarty->assign('content_page_name', 'timesheet_view.tpl');
142 $smarty->display('index.tpl');