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('track_own_time') || ttAccessAllowed('track_time'))) {
 
  36   header('Location: access_denied.php');
 
  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.
 
  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.
 
  47 if (!$user->isPluginEnabled('ts')) {
 
  48   header('Location: feature_disabled.php');
 
  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.
 
  58 // End of access checks.
 
  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);
 
  65   $user_id = $user->getUser();
 
  68 $group_id = $user->getGroup();
 
  70 $showFiles = $user->isPluginEnabled('at');
 
  72 // Elements of timesheetsForm.
 
  73 $form = new Form('timesheetsForm');
 
  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);
 
  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();',
 
  86       'style'=>'width: 250px;',
 
  89       'datakeys'=>array('id','name')));
 
  90     $form->addInput(array('type'=>'hidden','name'=>'user_changed'));
 
  91     $smarty->assign('user_dropdown', 1);
 
  95 $active_timesheets = ttTimesheetHelper::getActiveTimesheets();
 
  96 $inactive_timesheets = ttTimesheetHelper::getInactiveTimesheets();
 
  98 $showClient = $user->isPluginEnabled('cl');
 
 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');