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('ttTimesheetHelper');
34 if (!(ttAccessAllowed('view_own_timesheets') || ttAccessAllowed('view_timesheets') || ttAccessAllowed('view_all_timesheets') || ttAccessAllowed('view_client_timesheets'))) {
35 header('Location: access_denied.php');
38 if (!$user->isPluginEnabled('ts')) {
39 header('Location: feature_disabled.php');
42 if ($request->isPost()) {
43 $userChanged = $request->getParameter('user_changed');
44 if ($userChanged && !($user->can('track_time') && $user->isUserValid($request->getParameter('user')))) {
45 header('Location: access_denied.php'); // Group changed, but no rght or wrong user id.
49 // End of access checks.
51 // Determine user for whom we display this page.
52 if ($request->isPost() && $userChanged) {
53 $user_id = $request->getParameter('user');
55 $user_id = $user->getUser();
58 $group_id = $user->getGroup();
60 // Elements of timesheetsForm.
61 $form = new Form('timesheetsForm');
63 if ($user->can('view_timesheets') || $user->can('view_all_timesheets') || $user->can('manage_timesheets') || $user->can('manage_all_timesheets')) {
64 $rank = $user->getMaxRankForGroup($group_id);
65 if ($user->can('track_own_time'))
66 $options = array('group_id'=>$group_id,'status'=>ACTIVE,'max_rank'=>$rank,'include_self'=>true,'self_first'=>true);
68 $options = array('group_id'=>$group_id,'status'=>ACTIVE,'max_rank'=>$rank);
69 $user_list = $user->getUsers($options);
70 if (count($user_list) >= 1) {
71 $form->addInput(array('type'=>'combobox',
72 'onchange'=>'document.timesheetsForm.user_changed.value=1;document.timesheetsForm.submit();',
74 'style'=>'width: 250px;',
77 'datakeys'=>array('id','name')));
78 $form->addInput(array('type'=>'hidden','name'=>'user_changed'));
79 $smarty->assign('user_dropdown', 1);
86 // TODO: fix this for client access.
87 $active_timesheets = ttTimesheetHelper::getActiveTimesheets($user_id);
88 $inactive_timesheets = ttTimesheetHelper::getInactiveTimesheets($user_id);
89 $show_client = $user->isPluginEnabled('cl') && !$user->isClient();
91 $smarty->assign('active_timesheets', $active_timesheets);
92 $smarty->assign('inactive_timesheets', $inactive_timesheets);
93 $smarty->assign('show_client', $show_client);
94 $smarty->assign('show_submit_status', !$user->isClient());
95 $smarty->assign('show_approval_status', !$user->isClient());
96 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
97 $smarty->assign('title', $i18n->get('title.timesheets'));
98 $smarty->assign('content_page_name', 'timesheets.tpl');
99 $smarty->display('index.tpl');