header('Location: access_denied.php');
exit();
}
+if ($user->behalf_id && (!$user->can('track_time') || !$user->checkBehalfId())) {
+ header('Location: access_denied.php'); // Trying on behalf, but no right or wrong user.
+ exit();
+}
+if (!$user->behalf_id && !$user->can('track_own_time') && !$user->adjustBehalfId()) {
+ header('Location: access_denied.php'); // Trying as self, but no right for self, and noone to work on behalf.
+ exit();
+}
+if ($request->isPost()) {
+ $userChanged = $request->getParameter('user_changed'); // Reused in multiple places below.
+ if ($userChanged && !($user->can('track_time') && $user->isUserValid($request->getParameter('user')))) {
+ header('Location: access_denied.php'); // Group changed, but no rght or wrong user id.
+ exit();
+ }
+}
// End of access checks.
-$user_id = $user->getUser();
+// Determine user for which we display this page.
+if ($request->isPost() && $userChanged) {
+ $user_id = $request->getParameter('user');
+ $user->setOnBehalfUser($user_id);
+} else {
+ $user_id = $user->getUser();
+}
+
+$group_id = $user->getGroup();
// Initialize and store date in session.
$cl_date = $request->getParameter('date', @$_SESSION['date']);
// Elements of timeRecordForm.
$form = new Form('timeRecordForm');
+if ($user->can('track_time')) {
+ $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);
+ else
+ $options = array('group_id'=>$group_id,'status'=>ACTIVE,'max_rank'=>$rank);
+ $user_list = $user->getUsers($options);
+ if (count($user_list) >= 1) {
+ $form->addInput(array('type'=>'combobox',
+ 'onchange'=>'document.timeRecordForm.user_changed.value=1;document.timeRecordForm.submit();',
+ 'name'=>'user',
+ 'style'=>'width: 250px;',
+ 'value'=>$user_id,
+ 'data'=>$user_list,
+ 'datakeys'=>array('id','name')));
+ $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 == $user->getTrackingMode() && $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 (MODE_PROJECTS == $user->getTrackingMode() || MODE_PROJECTS_AND_TASKS == $user->getTrackingMode()) {
// Dropdown for projects assigned to user.
$project_list = $user->getAssignedProjects();
$form->addInput(array('type'=>'combobox',
}
}
-if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode) {
+if (MODE_PROJECTS_AND_TASKS == $user->getTrackingMode()) {
$task_list = ttGroupHelper::getActiveTasks();
$form->addInput(array('type'=>'combobox',
'name'=>'task',
'datakeys'=>array('id','name'),
'empty'=>array(''=>$i18n->get('dropdown.select'))));
}
-if ((TYPE_START_FINISH == $user->record_type) || (TYPE_ALL == $user->record_type)) {
+if ((TYPE_START_FINISH == $user->getRecordType()) || (TYPE_ALL == $user->getRecordType())) {
$form->addInput(array('type'=>'text','name'=>'start','value'=>$cl_start,'onchange'=>"formDisable('start');"));
$form->addInput(array('type'=>'text','name'=>'finish','value'=>$cl_finish,'onchange'=>"formDisable('finish');"));
if ($user->punch_mode && !$user->canOverridePunchMode()) {
$form->getElement('finish')->setEnabled(false);
}
}
-if ((TYPE_DURATION == $user->record_type) || (TYPE_ALL == $user->record_type))
+if ((TYPE_DURATION == $user->getRecordType()) || (TYPE_ALL == $user->getRecordType()))
$form->addInput(array('type'=>'text','name'=>'duration','value'=>$cl_duration,'onchange'=>"formDisable('duration');"));
$form->addInput(array('type'=>'textarea','name'=>'note','style'=>'width: 250px; height: 60px;','value'=>$cl_note));
if ($user->isPluginEnabled('iv'))
if ($custom_fields) {
if (!ttValidString($cl_cf_1, !$custom_fields->fields[0]['required'])) $err->add($i18n->get('error.field'), $custom_fields->fields[0]['label']);
}
- if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->tracking_mode) {
+ if (MODE_PROJECTS == $user->getTrackingMode() || MODE_PROJECTS_AND_TASKS == $user->getTrackingMode()) {
if (!$cl_project) $err->add($i18n->get('error.project'));
}
- if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode && $user->task_required) {
+ if (MODE_PROJECTS_AND_TASKS == $user->getTrackingMode() && $user->task_required) {
if (!$cl_task) $err->add($i18n->get('error.task'));
}
if (strlen($cl_duration) == 0) {
$err->add($i18n->get('error.interval'), $i18n->get('label.finish'), $i18n->get('label.start'));
}
} else {
- if ((TYPE_START_FINISH == $user->record_type) || (TYPE_ALL == $user->record_type)) {
+ if ((TYPE_START_FINISH == $user->getRecordType()) || (TYPE_ALL == $user->getRecordType())) {
$err->add($i18n->get('error.empty'), $i18n->get('label.start'));
$err->add($i18n->get('error.empty'), $i18n->get('label.finish'));
}
- if ((TYPE_DURATION == $user->record_type) || (TYPE_ALL == $user->record_type))
+ if ((TYPE_DURATION == $user->getRecordType()) || (TYPE_ALL == $user->getRecordType()))
$err->add($i18n->get('error.empty'), $i18n->get('label.duration'));
}
} else {
$id = ttTimeHelper::insert(array(
'date' => $cl_date,
'user_id' => $user_id,
- 'group_id' => $user->getGroup(),
+ 'group_id' => $group_id,
'org_id' => $user->org_id,
'client' => $cl_client,
'project' => $cl_project,
$smarty->assign('task_list', $task_list);
$smarty->assign('forms', array($form->getName()=>$form->toArray()));
$smarty->assign('onload', 'onLoad="fillDropdowns()"');
-$smarty->assign('timestring', $selected_date->toString($user->date_format));
+$smarty->assign('timestring', $selected_date->toString($user->getDateFormat()));
$smarty->assign('title', $i18n->get('title.time'));
$smarty->assign('content_page_name', 'mobile/time.tpl');
$smarty->display('mobile/index.tpl');