From aeb30899d6ec142220d83b34fd8f6c68c05e8e90 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Wed, 5 Dec 2018 20:39:25 +0000 Subject: [PATCH] Refactored mobile expenses.php for subgroups. --- WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/mobile/expenses.tpl | 20 +++++----- mobile/expenses.php | 53 +++++++++++++++++++-------- 3 files changed, 49 insertions(+), 26 deletions(-) diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 20a0db7c..14d272ea 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- @@ -189,7 +189,7 @@ function recalculateCost() { {if $user->isPluginEnabled('cl')} {/if} - {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)} + {if $show_project} {/if} @@ -200,7 +200,7 @@ function recalculateCost() { {if $user->isPluginEnabled('cl')} {/if} - {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)} + {if $show_project} {/if} @@ -210,7 +210,7 @@ function recalculateCost() {
 Anuko Time Tracker 1.18.29.4593 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4594 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/mobile/expenses.tpl b/WEB-INF/templates/mobile/expenses.tpl index d8e8612d..a6aa66d9 100644 --- a/WEB-INF/templates/mobile/expenses.tpl +++ b/WEB-INF/templates/mobile/expenses.tpl @@ -86,7 +86,7 @@ function recalculateCost() { var comment_control = document.getElementById("item_name"); var cost_control = document.getElementById("cost"); - var replaceDecimalMark = ("." != "{$user->decimal_mark}"); + var replaceDecimalMark = ("." != "{$user->getDecimalMark()}"); // Calculate cost. var dropdown = document.getElementById("predefined_expense"); @@ -102,10 +102,10 @@ function recalculateCost() { else { var expenseCost = defined_expenses[dropdown.selectedIndex - 1][2]; if (replaceDecimalMark) - expenseCost = expenseCost.replace("{$user->decimal_mark}", "."); + expenseCost = expenseCost.replace("{$user->getDecimalMark()}", "."); var newCost = (quantity_control.value * expenseCost).toFixed(2); if (replaceDecimalMark) - newCost = newCost.replace(".", "{$user->decimal_mark}"); + newCost = newCost.replace(".", "{$user->getDecimalMark()}"); cost_control.value = newCost; } } @@ -126,10 +126,10 @@ function recalculateCost() {
-{if $on_behalf_control} +{if $user_dropdown} - + {/if} {if $user->isPluginEnabled('cl')} @@ -138,7 +138,7 @@ function recalculateCost() { {/if} -{if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)} +{if $show_project} @@ -160,7 +160,7 @@ function recalculateCost() { - +
{$i18n.label.user}:{$forms.expensesForm.onBehalfUser.control}{$forms.expensesForm.user.control}
{$forms.expensesForm.client.control}
{$i18n.label.project} (*): {$forms.expensesForm.project.control}
{$i18n.label.cost} (*):{$forms.expensesForm.cost.control} {$user->currency|escape}{$forms.expensesForm.cost.control} {$user->getCurrency()|escape}
{$i18n.label.client}{$i18n.label.project}{$i18n.label.item}{$item.client|escape}{$item.project|escape}{if $item.invoice_id} {$item.item|escape} {else}{$item.item|escape}{/if}
- +
{$i18n.label.day_total}: {$user->currency|escape} {$day_total}{$i18n.label.day_total}: {$user->getCurrency()|escape} {$day_total}
{/if} diff --git a/mobile/expenses.php b/mobile/expenses.php index 84d29738..eeece003 100644 --- a/mobile/expenses.php +++ b/mobile/expenses.php @@ -50,6 +50,25 @@ if (!$user->behalf_id && !$user->can('track_own_expenses') && !$user->adjustBeha header('Location: access_denied.php'); // Trying as self, but no right for self, and noone to work on behalf. exit(); } +if ($request->isPost() && $request->getParameter('user')) { + if (!$user->isUserValid($request->getParameter('user'))) { + header('Location: access_denied.php'); // Wrong user id on post. + exit(); + } +} +// End of access checks. + +// Determine user for which we display this page. +$userChanged = $request->getParameter('user_changed'); +if ($request->isPost() && $userChanged) { + $user_id = $request->getParameter('user'); + $user->setOnBehalfUser($user_id); +} else { + $user_id = $user->getUser(); + // Handle a situation for no users in on behalf group. + if ($user->behalfGroup && $user_id == $user->id) + $user_id = null; +} // Initialize and store date in session. $cl_date = $request->getParameter('date', @$_SESSION['date']); @@ -64,8 +83,10 @@ $_SESSION['date'] = $cl_date; $prev_date = date('Y-m-d', strtotime('-1 day', strtotime($cl_date))); $next_date = date('Y-m-d', strtotime('+1 day', strtotime($cl_date))); +$tracking_mode = $user->getTrackingMode(); +$show_project = MODE_PROJECTS == $tracking_mode || MODE_PROJECTS_AND_TASKS == $tracking_mode; + // Initialize variables. -$on_behalf_id = $request->getParameter('onBehalfUser', (isset($_SESSION['behalf_id']) ? $_SESSION['behalf_id'] : $user->id)); $cl_client = $request->getParameter('client', ($request->isPost() ? null : @$_SESSION['client'])); $_SESSION['client'] = $cl_client; $cl_project = $request->getParameter('project', ($request->isPost() ? null : @$_SESSION['project'])); @@ -77,25 +98,27 @@ $cl_cost = $request->getParameter('cost'); $form = new Form('expensesForm'); if ($user->can('track_expenses')) { + $rank = $user->getMaxRankForGroup($user->getGroup()); if ($user->can('track_own_expenses')) - $options = array('status'=>ACTIVE,'max_rank'=>$user->rank-1,'include_self'=>true,'self_first'=>true); + $options = array('status'=>ACTIVE,'max_rank'=>$rank,'include_self'=>true,'self_first'=>true); else - $options = array('status'=>ACTIVE,'max_rank'=>$user->rank-1); + $options = array('status'=>ACTIVE,'max_rank'=>$rank); $user_list = $user->getUsers($options); if (count($user_list) >= 1) { $form->addInput(array('type'=>'combobox', - 'onchange'=>'this.form.submit();', - 'name'=>'onBehalfUser', + 'onchange'=>'this.form.user_changed.value=1;this.form.submit();', + 'name'=>'user', 'style'=>'width: 250px;', - 'value'=>$on_behalf_id, + 'value'=>$user_id, 'data'=>$user_list, 'datakeys'=>array('id','name'))); - $smarty->assign('on_behalf_control', 1); + $form->addInput(array('type'=>'hidden','name'=>'user_changed')); + $smarty->assign('user_dropdown', 1); } } // Dropdown for clients in MODE_TIME. Use all active clients. -if (MODE_TIME == $user->tracking_mode && $user->isPluginEnabled('cl')) { +if (MODE_TIME == $tracking_mode && $user->isPluginEnabled('cl')) { $active_clients = ttGroupHelper::getActiveClients(true); $form->addInput(array('type'=>'combobox', 'onchange'=>'fillProjectDropdown(this.value);', @@ -108,7 +131,7 @@ if (MODE_TIME == $user->tracking_mode && $user->isPluginEnabled('cl')) { // Note: in other modes the client list is filtered to relevant clients only. See below. } -if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->tracking_mode) { +if ($show_project) { // Dropdown for projects assigned to user. $project_list = $user->getAssignedProjects(); $form->addInput(array('type'=>'combobox', @@ -172,14 +195,13 @@ if ($request->isPost()) { // Validate user input. if ($user->isPluginEnabled('cl') && $user->isPluginEnabled('cm') && !$cl_client) $err->add($i18n->get('error.client')); - if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->tracking_mode) { - if (!$cl_project) $err->add($i18n->get('error.project')); - } + if ($show_project && !$cl_project) + $err->add($i18n->get('error.project')); if (!ttValidString($cl_item_name)) $err->add($i18n->get('error.field'), $i18n->get('label.item')); if (!ttValidFloat($cl_cost)) $err->add($i18n->get('error.field'), $i18n->get('label.cost')); // Prohibit creating entries in future. - if (!$user->future_entries) { + if (!$user->getConfigOption('future_entries')) { $browser_today = new DateAndTime(DB_DATEFORMAT, $request->getParameter('browser_today', null)); if ($selected_date->after($browser_today)) $err->add($i18n->get('error.future_date')); @@ -214,6 +236,8 @@ if ($request->isPost()) { } } +$smarty->assign('forms', array($form->getName()=>$form->toArray())); +$smarty->assign('show_project', $show_project); $smarty->assign('next_date', $next_date); $smarty->assign('prev_date', $prev_date); $smarty->assign('day_total', ttExpenseHelper::getTotalForDay($cl_date)); @@ -221,8 +245,7 @@ $smarty->assign('expense_items', ttExpenseHelper::getItems($cl_date)); $smarty->assign('predefined_expenses', $predefined_expenses); $smarty->assign('client_list', $client_list); $smarty->assign('project_list', $project_list); -$smarty->assign('forms', array($form->getName()=>$form->toArray())); -$smarty->assign('timestring', $selected_date->toString($user->date_format)); +$smarty->assign('timestring', $selected_date->toString($user->getDateFormat())); $smarty->assign('title', $i18n->get('title.expenses')); $smarty->assign('content_page_name', 'mobile/expenses.tpl'); $smarty->display('mobile/index.tpl'); -- 2.20.1