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') ||
35 ttAccessAllowed('manage_own_timesheets') ||
36 ttAccessAllowed('view_timesheets') ||
37 ttAccessAllowed('manage_timesheets') ||
38 ttAccessAllowed('approve_timesheets'))) {
39 header('Location: access_denied.php');
42 if (!$user->isPluginEnabled('ts')) {
43 header('Location: feature_disabled.php');
46 if ($request->isPost()) {
47 $userChanged = $request->getParameter('user_changed');
48 if ($userChanged && !($user->can('track_time') && $user->isUserValid($request->getParameter('user')))) {
49 header('Location: access_denied.php'); // Group changed, but no rght or wrong user id.
53 // End of access checks.
55 // Determine user for whom we display this page.
56 if ($request->isPost() && $userChanged) {
57 $user_id = $request->getParameter('user');
59 $user_id = $user->getUser();
62 $group_id = $user->getGroup();
64 // Elements of timesheetsForm.
65 $form = new Form('timesheetsForm');
67 if ($user->can('view_timesheets') || $user->can('view_all_timesheets') || $user->can('manage_timesheets') || $user->can('manage_all_timesheets')) {
68 $rank = $user->getMaxRankForGroup($group_id);
69 if ($user->can('track_own_time'))
70 $options = array('group_id'=>$group_id,'status'=>ACTIVE,'max_rank'=>$rank,'include_self'=>true,'self_first'=>true);
72 $options = array('group_id'=>$group_id,'status'=>ACTIVE,'max_rank'=>$rank);
73 $user_list = $user->getUsers($options);
74 if (count($user_list) >= 1) {
75 $form->addInput(array('type'=>'combobox',
76 'onchange'=>'document.timesheetsForm.user_changed.value=1;document.timesheetsForm.submit();',
78 'style'=>'width: 250px;',
81 'datakeys'=>array('id','name')));
82 $form->addInput(array('type'=>'hidden','name'=>'user_changed'));
83 $smarty->assign('user_dropdown', 1);
90 // TODO: fix this for client access.
91 $active_timesheets = ttTimesheetHelper::getActiveTimesheets($user_id);
92 $inactive_timesheets = ttTimesheetHelper::getInactiveTimesheets($user_id);
93 $show_client = $user->isPluginEnabled('cl') && !$user->isClient();
95 $smarty->assign('active_timesheets', $active_timesheets);
96 $smarty->assign('inactive_timesheets', $inactive_timesheets);
97 $smarty->assign('show_client', $show_client);
98 $smarty->assign('show_submit_status', !$user->isClient());
99 $smarty->assign('show_approval_status', !$user->isClient());
100 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
101 $smarty->assign('title', $i18n->get('title.timesheets'));
102 $smarty->assign('content_page_name', 'timesheets.tpl');
103 $smarty->display('index.tpl');