X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/3ad837214ca361fdaac5363d9e702d3d40d04b17..88bd95ec82e6b715f84b6bd09c04aebbdb4b5e4d:/timesheets.php diff --git a/timesheets.php b/timesheets.php index 82a83074..cc43f0dd 100644 --- a/timesheets.php +++ b/timesheets.php @@ -32,7 +32,7 @@ import('ttGroupHelper'); import('ttTimesheetHelper'); // Access checks. -if (!(ttAccessAllowed('view_own_timesheets') || ttAccessAllowed('view_timesheets') || ttAccessAllowed('view_all_timesheets') || ttAccessAllowed('view_client_timesheets'))) { +if (!(ttAccessAllowed('view_own_timesheets') || ttAccessAllowed('view_timesheets') || ttAccessAllowed('view_all_timesheets'))) { header('Location: access_denied.php'); exit(); } @@ -41,44 +41,37 @@ if (!$user->isPluginEnabled('ts')) { exit(); } if ($user->isClient()) { - $users_for_client = ttGroupHelper::getUsersForClient($user->client_id); - if (count($users_for_client) == 0) { - header('Location: access_denied.php'); // There are no users for client. - exit(); - } + header('Location: access_denied.php'); // No timesheets for clients. + exit(); } if ($request->isPost()) { - $userChanged = $request->getParameter('user_changed'); - if ($userChanged && !(ttTimesheetHelper::isUserValid($request->getParameter('user')))) { - header('Location: access_denied.php'); // Wrong user id. + $userChanged = $request->getParameter('user_changed'); // Reused in multiple places below. + if ($userChanged && !($user->can('view_timesheets') && $user->isUserValid($request->getParameter('user')))) { + header('Location: access_denied.php'); // Group changed, but no rght or wrong user id. TODO: research relevance of this... exit(); } } // End of access checks. -// Determine user for whom we display this page. -$notClient = !$user->isClient(); +// Determine user for which we display this page. if ($request->isPost() && $userChanged) { $user_id = $request->getParameter('user'); + $user->setOnBehalfUser($user_id); } else { - if ($notClient) - $user_id = $user->getUser(); - else - $user_id = $users_for_client[0]['id']; // First found user for a client. + $user_id = $user->getUser(); } - $group_id = $user->getGroup(); // Elements of timesheetsForm. $form = new Form('timesheetsForm'); -if ($user->can('view_timesheets') || $user->can('view_all_timesheets') || $user->can('manage_timesheets') || $user->can('manage_all_timesheets')) { +if ($user->can('view_timesheets') || $user->can('view_all_timesheets')) { $rank = $user->getMaxRankForGroup($group_id); - if ($user->can('track_own_time')) - $options = array('group_id'=>$group_id,'status'=>ACTIVE,'max_rank'=>$rank,'include_self'=>true,'self_first'=>true); + if ($user->can('view_own_timesheets')) + $options = array('status'=>ACTIVE,'max_rank'=>$rank,'include_self'=>true,'self_first'=>true); else - $options = array('group_id'=>$group_id,'status'=>ACTIVE,'max_rank'=>$rank); + $options = array('status'=>ACTIVE,'max_rank'=>$rank); $user_list = $user->getUsers($options); if (count($user_list) >= 1) { $form->addInput(array('type'=>'combobox', @@ -93,20 +86,16 @@ if ($user->can('view_timesheets') || $user->can('view_all_timesheets') || $user- } } - - - -// TODO: fix this for client access. $active_timesheets = ttTimesheetHelper::getActiveTimesheets($user_id); $inactive_timesheets = ttTimesheetHelper::getInactiveTimesheets($user_id); -$show_client = $user->isPluginEnabled('cl') && $notClient; + +$showClient = $user->isPluginEnabled('cl'); +$canEdit = $user->can('manage_own_timesheets') || $user->can('manage_timesheets') || $user->can('manage_all_timesheets'); $smarty->assign('active_timesheets', $active_timesheets); $smarty->assign('inactive_timesheets', $inactive_timesheets); -$smarty->assign('show_client', $show_client); -$smarty->assign('show_hint', $notClient); -$smarty->assign('show_submit_status', $notClient); -$smarty->assign('show_approval_status', $notClient); +$smarty->assign('show_client', $showClient); +$smarty->assign('can_edit', $canEdit); $smarty->assign('forms', array($form->getName()=>$form->toArray())); $smarty->assign('title', $i18n->get('title.timesheets')); $smarty->assign('content_page_name', 'timesheets.tpl');