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');
31 import('ttGroupHelper');
32 import('ttTimesheetHelper');
35 if (!(ttAccessAllowed('view_own_timesheets') || ttAccessAllowed('view_timesheets') || ttAccessAllowed('view_all_timesheets'))) {
36 header('Location: access_denied.php');
39 if (!$user->isPluginEnabled('ts')) {
40 header('Location: feature_disabled.php');
43 if ($user->isClient()) {
44 header('Location: access_denied.php'); // No timesheets for clients.
47 if ($request->isPost()) {
48 $userChanged = $request->getParameter('user_changed'); // Reused in multiple places below.
49 if ($userChanged && !($user->can('view_timesheets') && $user->isUserValid($request->getParameter('user')))) {
50 header('Location: access_denied.php'); // Group changed, but no rght or wrong user id. TODO: research relevance of this...
54 // End of access checks.
56 // Determine user for which we display this page.
57 if ($request->isPost() && $userChanged) {
58 $user_id = $request->getParameter('user');
59 $user->setOnBehalfUser($user_id);
61 $user_id = $user->getUser();
64 $group_id = $user->getGroup();
66 // Elements of timesheetsForm.
67 $form = new Form('timesheetsForm');
69 if ($user->can('view_timesheets') || $user->can('view_all_timesheets')) {
70 $rank = $user->getMaxRankForGroup($group_id);
71 if ($user->can('view_own_timesheets'))
72 $options = array('status'=>ACTIVE,'max_rank'=>$rank,'include_self'=>true,'self_first'=>true);
74 $options = array('status'=>ACTIVE,'max_rank'=>$rank);
75 $user_list = $user->getUsers($options);
76 if (count($user_list) >= 1) {
77 $form->addInput(array('type'=>'combobox',
78 'onchange'=>'document.timesheetsForm.user_changed.value=1;document.timesheetsForm.submit();',
80 'style'=>'width: 250px;',
83 'datakeys'=>array('id','name')));
84 $form->addInput(array('type'=>'hidden','name'=>'user_changed'));
85 $smarty->assign('user_dropdown', 1);
89 $active_timesheets = ttTimesheetHelper::getActiveTimesheets($user_id);
90 $inactive_timesheets = ttTimesheetHelper::getInactiveTimesheets($user_id);
92 $showClient = $user->isPluginEnabled('cl');
93 $canEdit = $user->can('manage_own_timesheets') || $user->can('manage_timesheets') || $user->can('manage_all_timesheets');
95 $smarty->assign('active_timesheets', $active_timesheets);
96 $smarty->assign('inactive_timesheets', $inactive_timesheets);
97 $smarty->assign('show_client', $showClient);
98 $smarty->assign('can_edit', $canEdit);
99 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
100 $smarty->assign('title', $i18n->get('title.timesheets'));
101 $smarty->assign('content_page_name', 'timesheets.tpl');
102 $smarty->display('index.tpl');