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'));
56 $options = ttTimesheetHelper::getReportOptions($timesheet);
57 $subtotals = ttReportHelper::getSubtotals($options);
58 $totals = ttReportHelper::getTotals($options);
60 // Determine which controls to show and obtain date for them.
61 $showSubmit = !$timesheet['submit_status'];
63 $approvers = ttTimesheetHelper::getApprovers($timesheet['user_id']);
64 $showApprovers = count($approvers) >= 1;
66 $canApprove = $user->can('approve_timesheets') || $user->can('approve_own_timesheets');
67 $showApprove = $timesheet['submit_status'] && $timesheet['approve_status'] == null;
69 // Add a form with controls.
70 $form = new Form('timesheetForm');
71 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$timesheet['id']));
75 $form->addInput(array('type'=>'combobox',
77 'style'=>'width: 200px;',
79 'datakeys'=>array('id','name')));
81 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.submit')));
85 $form->addInput(array('type'=>'textarea','name'=>'comment','maxlength'=>'250','style'=>'width: 300px; height: 60px;'));
86 $form->addInput(array('type'=>'submit','name'=>'btn_approve','value'=>$i18n->get('button.approve')));
87 $form->addInput(array('type'=>'submit','name'=>'btn_disapprove','value'=>$i18n->get('button.disapprove')));
91 if ($request->isPost()) {
92 if ($request->getParameter('btn_submit')) {
93 $fields = array('timesheet_id' => $timesheet['id'],
94 'approver_id' => $approver_id); // TODO: obtain (and check) approver id above during access checks.
95 if (ttTimesheetHelper::submitTimesheet($fields)) {
97 header('Location: timesheet_view.php?id='.$timesheet['id']);
100 $err->add($i18n->get('error.db'));
103 if ($request->getParameter('btn_approve')) {
104 $fields = array('timesheet_id' => $timesheet['id'],
105 'comment' => $cl_comment);
106 if (ttTimesheetHelper::approveTimesheet($fields)) {
108 header('Location: timesheet_view.php?id='.$timesheet['id']);
111 $err->add($i18n->get('error.db'));
114 if ($request->getParameter('btn_disapprove')) {
115 $fields = array('timesheet_id' => $timesheet['id'],
116 'comment' => $cl_comment);
117 if (ttTimesheetHelper::disapproveTimesheet($fields)) {
119 header('Location: timesheet_view.php?id='.$timesheet['id']);
122 $err->add($i18n->get('error.db'));
126 $smarty->assign('not_client', $notClient);
127 $smarty->assign('group_by_header', ttReportHelper::makeGroupByHeader($options));
128 $smarty->assign('timesheet', $timesheet);
129 $smarty->assign('subtotals', $subtotals);
130 $smarty->assign('totals', $totals);
131 $smarty->assign('show_approvers', $showApprovers);
132 $smarty->assign('show_submit', $showSubmit);
133 $smarty->assign('show_approve', $showApprove);
134 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
135 $smarty->assign('title', $i18n->get('title.timesheet').": ".$timesheet['start_date']." - ".$timesheet['end_date']);
136 $smarty->assign('content_page_name', 'timesheet_view.tpl');
137 $smarty->display('index.tpl');