require_once('initialize.php');
import('form.Form');
import('ttUserHelper');
+import('ttGroupHelper');
import('ttTeamHelper');
import('ttClientHelper');
import('ttTimeHelper');
$cl_billable = $_SESSION['billable'];
}
$on_behalf_id = $request->getParameter('onBehalfUser', (isset($_SESSION['behalf_id'])? $_SESSION['behalf_id'] : $user->id));
+$on_behalf_group_id = $request->getParameter('onBehalfGroup', (isset($_SESSION['behalf_group_id'])? $_SESSION['behalf_group_id'] : $user->group_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']));
// Elements of timeRecordForm.
$form = new Form('timeRecordForm');
+if (defined('SUBGROUP_DEBUG') && isTrue(SUBGROUP_DEBUG)) {
+if ($user->can('manage_subgroups')) {
+ $groups = $user->getGroups();
+ if (count($groups) > 1) {
+ $form->addInput(array('type'=>'combobox',
+ 'onchange'=>'this.form.submit();',
+ 'name'=>'onBehalfGroup',
+ 'style'=>'width: 250px;',
+ 'value'=>$on_behalf_group_id,
+ 'data'=>$groups,
+ 'datakeys'=>array('id','name')));
+ $smarty->assign('on_behalf_group_control', 1);
+ }
+}
+} // SUBGROUP_DEBUG
+
if ($user->can('track_time')) {
+ // Determine max rank.
+ $max_rank = $on_behalf_group_id == $user->group_id ? $user->rank-1 : 512; // TODO: stop using magic numbers.
if ($user->can('track_own_time'))
- $options = array('status'=>ACTIVE,'max_rank'=>$user->rank-1,'include_self'=>true,'self_first'=>true);
+ $options = array('group_id'=>$on_behalf_group_id,'status'=>ACTIVE,'max_rank'=>$max_rank,'include_self'=>true,'self_first'=>true);
else
- $options = array('status'=>ACTIVE,'max_rank'=>$user->rank-1);
+ $options = array('group_id'=>$on_behalf_group_id,'status'=>ACTIVE,'max_rank'=>$max_rank);
$user_list = $user->getUsers($options);
if (count($user_list) >= 1) {
$form->addInput(array('type'=>'combobox',
$id = ttTimeHelper::insert(array(
'date' => $cl_date,
'user_id' => $user->getActiveUser(),
+ 'group_id' => $user->getActiveGroup(),
'client' => $cl_client,
'project' => $cl_project,
'task' => $cl_task,
exit();
}
}
+ elseif ($request->getParameter('onBehalfGroup')) {
+ if($user->can('manage_subgroups')) {
+ unset($_SESSION['behalf_group_id']);
+ unset($_SESSION['behalf_group_name']);
+
+ if($on_behalf_group_id != $user->group_id) {
+ $_SESSION['behalf_group_id'] = $on_behalf_group_id;
+ $_SESSION['behalf_group_name'] = ttGroupHelper::getGroupName($on_behalf_group_id);
+ }
+ header('Location: time.php');
+ exit();
+ }
+ }
elseif ($request->getParameter('onBehalfUser')) {
- if($user->canManageTeam()) {
+ if($user->can('track_time')) {
unset($_SESSION['behalf_id']);
unset($_SESSION['behalf_name']);