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");
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;
}
}
<tr>
<td valign="top">
<table>
-{if $on_behalf_control}
+{if $user_dropdown}
<tr>
<td align="right">{$i18n.label.user}:</td>
- <td>{$forms.expensesForm.onBehalfUser.control}</td>
+ <td>{$forms.expensesForm.user.control}</td>
</tr>
{/if}
{if $user->isPluginEnabled('cl')}
<td>{$forms.expensesForm.client.control}</td>
</tr>
{/if}
-{if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
+{if $show_project}
<tr>
<td align="right">{$i18n.label.project} (*):</td>
<td>{$forms.expensesForm.project.control}</td>
</tr>
<tr>
<td align="right">{$i18n.label.cost} (*):</td>
- <td>{$forms.expensesForm.cost.control} {$user->currency|escape}</td>
+ <td>{$forms.expensesForm.cost.control} {$user->getCurrency()|escape}</td>
</tr>
</table>
</td>
{if $user->isPluginEnabled('cl')}
<td width="20%" class="tableHeader">{$i18n.label.client}</td>
{/if}
- {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
+ {if $show_project}
<td class="tableHeader">{$i18n.label.project}</td>
{/if}
<td class="tableHeader">{$i18n.label.item}</td>
{if $user->isPluginEnabled('cl')}
<td valign="top">{$item.client|escape}</td>
{/if}
- {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
+ {if $show_project}
<td valign="top">{$item.project|escape}</td>
{/if}
<td valign="top">{if $item.invoice_id} {$item.item|escape} {else}<a href="expense_edit.php?id={$item.id}">{$item.item|escape}</a>{/if}</td>
</table>
<table border="0" cellpadding="3" cellspacing="1" width="100%">
<tr>
- <td nowrap align="right">{$i18n.label.day_total}: {$user->currency|escape} {$day_total}</td>
+ <td nowrap align="right">{$i18n.label.day_total}: {$user->getCurrency()|escape} {$day_total}</td>
</tr>
</table>
{/if}
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']);
$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']));
$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);',
// 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',
// 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'));
}
}
+$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));
$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');