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') || ttAccessAllowed('view_client_timesheets'))) {
36 header('Location: access_denied.php');
39 if (!$user->isPluginEnabled('ts')) {
40 header('Location: feature_disabled.php');
43 if ($user->isClient()) {
44 $users_for_client = ttGroupHelper::getUsersForClient($user->client_id);
45 if (count($users_for_client) == 0) {
46 header('Location: access_denied.php'); // There are no users for client.
50 if ($request->isPost()) {
51 $userChanged = $request->getParameter('user_changed');
52 if ($userChanged && !(ttTimesheetHelper::isUserValid($request->getParameter('user')))) {
53 header('Location: access_denied.php'); // Wrong user id.
57 // End of access checks.
59 // Determine user for whom we display this page.
60 $notClient = !$user->isClient();
61 if ($request->isPost() && $userChanged) {
62 $user_id = $request->getParameter('user');
65 $user_id = $user->getUser();
67 $user_id = $users_for_client[0]['id']; // First found user for a client.
69 $group_id = $user->getGroup();
71 // Elements of timesheetsForm.
72 $form = new Form('timesheetsForm');
74 if ($user->can('view_timesheets') || $user->can('view_all_timesheets') || $user->can('view_client_timesheets')) {
75 // Prepare user list for dropdown.
77 $rank = $user->can('view_all_timesheets') ? MAX_RANK : $user->getMaxRankForGroup($group_id);
78 if ($user->can('view_own_timesheets'))
79 $options = array('max_rank'=>$rank,'include_self'=>true,'self_first'=>true);
81 $options = array('max_rank'=>$rank);
82 $user_list = $user->getUsers($options);
84 $user_list = $users_for_client; // Obtained above.
86 if (count($user_list) >= 1) {
87 $form->addInput(array('type'=>'combobox',
88 'onchange'=>'document.timesheetsForm.user_changed.value=1;document.timesheetsForm.submit();',
90 'style'=>'width: 250px;',
93 'datakeys'=>array('id','name')));
94 $form->addInput(array('type'=>'hidden','name'=>'user_changed'));
95 $smarty->assign('user_dropdown', 1);
102 // TODO: fix this for client access.
103 $active_timesheets = ttTimesheetHelper::getActiveTimesheets($user_id);
104 $inactive_timesheets = ttTimesheetHelper::getInactiveTimesheets($user_id);
105 $show_client = $user->isPluginEnabled('cl') && $notClient;
107 $smarty->assign('active_timesheets', $active_timesheets);
108 $smarty->assign('inactive_timesheets', $inactive_timesheets);
109 $smarty->assign('show_client', $show_client);
110 $smarty->assign('show_hint', $notClient);
111 $smarty->assign('show_submit_status', $notClient);
112 $smarty->assign('show_approval_status', $notClient);
113 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
114 $smarty->assign('title', $i18n->get('title.timesheets'));
115 $smarty->assign('content_page_name', 'timesheets.tpl');
116 $smarty->display('index.tpl');