Forgot to check in one file.
[timetracker.git] / timesheets.php
1 <?php
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.
10 // |
11 // | There are only two ways to violate the license:
12 // |
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).
16 // |
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).
20 // |
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
23 // |
24 // +----------------------------------------------------------------------+
25 // | Contributors:
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
28
29 require_once('initialize.php');
30 import('form.Form');
31 import('ttGroupHelper');
32 import('ttTimesheetHelper');
33
34 // Access checks.
35 if (!(ttAccessAllowed('track_own_time') || ttAccessAllowed('track_time'))) {
36   header('Location: access_denied.php');
37   exit();
38 }
39 if ($user->behalf_id && (!$user->can('track_time') || !$user->checkBehalfId())) {
40   header('Location: access_denied.php'); // Trying on behalf, but no right or wrong user.
41   exit();
42 }
43 if (!$user->behalf_id && !$user->can('track_own_time') && !$user->adjustBehalfId()) {
44   header('Location: access_denied.php'); // Trying as self, but no right for self, and noone to work on behalf.
45   exit();
46 }
47 if (!$user->isPluginEnabled('ts')) {
48   header('Location: feature_disabled.php');
49   exit();
50 }
51 if ($request->isPost()) {
52   $userChanged = $request->getParameter('user_changed'); // Reused in multiple places below.
53   if ($userChanged && !($user->can('track_time') && $user->isUserValid($request->getParameter('user')))) {
54     header('Location: access_denied.php'); // Group changed, but no rght or wrong user id.
55     exit();
56   }
57 }
58 // End of access checks.
59
60 // Determine user for which we display this page.
61 if ($request->isPost() && $userChanged) {
62   $user_id = $request->getParameter('user');
63   $user->setOnBehalfUser($user_id);
64 } else {
65   $user_id = $user->getUser();
66 }
67
68 $group_id = $user->getGroup();
69
70 // Elements of timesheetsForm.
71 $form = new Form('timesheetsForm');
72
73 if ($user->can('track_time')) {
74   $rank = $user->getMaxRankForGroup($group_id);
75   if ($user->can('track_own_time'))
76     $options = array('status'=>ACTIVE,'max_rank'=>$rank,'include_self'=>true,'self_first'=>true);
77   else
78     $options = array('status'=>ACTIVE,'max_rank'=>$rank);
79   $user_list = $user->getUsers($options);
80   if (count($user_list) >= 1) {
81     $form->addInput(array('type'=>'combobox',
82       'onchange'=>'document.timesheetsForm.user_changed.value=1;document.timesheetsForm.submit();',
83       'name'=>'user',
84       'style'=>'width: 250px;',
85       'value'=>$user_id,
86       'data'=>$user_list,
87       'datakeys'=>array('id','name')));
88     $form->addInput(array('type'=>'hidden','name'=>'user_changed'));
89     $smarty->assign('user_dropdown', 1);
90   }
91 }
92
93 $active_timesheets = ttTimesheetHelper::getActiveTimesheets();
94 $inactive_timesheets = ttTimesheetHelper::getInactiveTimesheets();
95
96 $showClient = $user->isPluginEnabled('cl');
97
98 $smarty->assign('active_timesheets', $active_timesheets);
99 $smarty->assign('inactive_timesheets', $inactive_timesheets);
100 $smarty->assign('show_client', $showClient);
101 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
102 $smarty->assign('title', $i18n->get('title.timesheets'));
103 $smarty->assign('content_page_name', 'timesheets.tpl');
104 $smarty->display('index.tpl');