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);
96 if (!ttTimesheetHelper::markSubmitted($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 'name' => $timesheet['name'],
111 'user_id' => $timesheet['user_id'],
112 'comment' => $cl_comment);
113 if (!ttTimesheetHelper::markApproved($fields))
114 $err->add($i18n->get('error.db'));
115 if ($err->no() && !ttTimesheetHelper::sendApprovedEmail($fields)) {
116 $err->add($i18n->get('error.mail_send'));
120 header('Location: timesheet_view.php?id='.$timesheet['id']);
125 if ($request->getParameter('btn_disapprove')) {
126 $fields = array('timesheet_id' => $timesheet['id'],
127 'name' => $timesheet['name'],
128 'user_id' => $timesheet['user_id'],
129 'comment' => $cl_comment);
130 if (!ttTimesheetHelper::markDisapproved($fields))
131 $err->add($i18n->get('error.db'));
132 if ($err->no() && !ttTimesheetHelper::sendDisapprovedEmail($fields)) {
133 $err->add($i18n->get('error.mail_send'));
137 header('Location: timesheet_view.php?id='.$timesheet['id']);
143 $smarty->assign('not_client', $notClient);
144 $smarty->assign('group_by_header', ttReportHelper::makeGroupByHeader($options));
145 $smarty->assign('timesheet', $timesheet);
146 $smarty->assign('subtotals', $subtotals);
147 $smarty->assign('totals', $totals);
148 $smarty->assign('show_approvers', $showApprovers);
149 $smarty->assign('show_submit', $showSubmit);
150 $smarty->assign('show_approve', $showApprove);
151 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
152 $smarty->assign('title', $i18n->get('title.timesheet').": ".$timesheet['start_date']." - ".$timesheet['end_date']);
153 $smarty->assign('content_page_name', 'timesheet_view.tpl');
154 $smarty->display('index.tpl');