posaune
[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 whom 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 $showFiles = $user->isPluginEnabled('at');
71
72 // Elements of timesheetsForm.
73 $form = new Form('timesheetsForm');
74
75 if ($user->can('track_time')) {
76   $rank = $user->getMaxRankForGroup($group_id);
77   if ($user->can('track_own_time'))
78     $options = array('status'=>ACTIVE,'max_rank'=>$rank,'include_self'=>true,'self_first'=>true);
79   else
80     $options = array('status'=>ACTIVE,'max_rank'=>$rank);
81   $user_list = $user->getUsers($options);
82   if (count($user_list) >= 1) {
83     $form->addInput(array('type'=>'combobox',
84       'onchange'=>'document.timesheetsForm.user_changed.value=1;document.timesheetsForm.submit();',
85       'name'=>'user',
86       'style'=>'width: 250px;',
87       'value'=>$user_id,
88       'data'=>$user_list,
89       'datakeys'=>array('id','name')));
90     $form->addInput(array('type'=>'hidden','name'=>'user_changed'));
91     $smarty->assign('user_dropdown', 1);
92   }
93 }
94
95 $active_timesheets = ttTimesheetHelper::getActiveTimesheets();
96 $inactive_timesheets = ttTimesheetHelper::getInactiveTimesheets();
97
98 $showClient = $user->isPluginEnabled('cl');
99
100 $smarty->assign('active_timesheets', $active_timesheets);
101 $smarty->assign('inactive_timesheets', $inactive_timesheets);
102 $smarty->assign('show_client', $showClient);
103 $smarty->assign('show_files', $showFiles);
104 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
105 $smarty->assign('title', $i18n->get('title.timesheets'));
106 $smarty->assign('content_page_name', 'timesheets.tpl');
107 $smarty->display('index.tpl');