return ($this->behalfGroup ? $this->behalfGroup->tracking_mode : $this->tracking_mode);
}
+ // getRecordType returns record type for active group.
+ function getRecordType() {
+ return ($this->behalfGroup ? $this->behalfGroup->record_type : $this->record_type);
+ }
+
// getPlugins returns plugins string for active group.
function getPlugins() {
return ($this->behalfGroup ? $this->behalfGroup->plugins : $this->plugins);
// isPluginEnabled checks whether a plugin is enabled for user.
function isPluginEnabled($plugin)
{
- return in_array($plugin, explode(',', $this->plugins));
+ return in_array($plugin, explode(',', $this->getPlugins()));
}
// getAssignedProjects - returns an array of assigned projects.
return true;
}
+ // isUserValid determines if a user is valid for on behalf work.
+ function isUserValid($user_id) {
+ if ($user_id == $this->id)
+ return true;
+
+ $user_details = $this->getUser($user_id); // TODO: this will probably not work for higher ranks.
+ // In this case we'll need another function.
+ // Or adjust getUser for max rank.
+ if (!$user_details)
+ return false;
+
+ return true;
+ }
+
// isGroupValid determines if a group is valid for user.
function isGroupValid($group_id) {
if ($group_id == $this->group_id)
// Do not do anything if we don't have rights.
if (!$this->can('manage_subgroups')) return;
- // No need to set if the group is our home group.
+ // No need to set if group is our home group.
if ($group_id == $this->group_id) return;
- // No need to set if the subgroup is not valid.
+ // No need to set if subgroup is not valid.
if (!$this->isSubgroupValid($group_id)) return;
// We are good to set on behalf group.
$this->adjustBehalfId();
return;
}
+
+ // setOnBehalfUser sets on behalf user both the object and the session.
+ function setOnBehalfUser($user_id) {
+
+ // Unset things first.
+ $this->behalf_id = null;
+ $this->behalf_name = null;
+ unset($_SESSION['behalf_id']);
+ unset($_SESSION['behalf_name']);
+
+ // No need to set if user is us.
+ if ($user_id == $this->id) return;
+
+ // No need to set if user id is not valid.
+ if (!$this->isUserValid($user_id)) return;
+
+ // We are good to set on behalf user.
+ $onBehalfUserName = ttUserHelper::getUserName($user_id);
+ $_SESSION['behalf_id'] = $user_id;
+ $_SESSION['behalf_name'] = $onBehalfUserName;
+ $this->behalf_id = $user_id;
+ $this->behalf_name = $onBehalfUserName;
+ return;
+ }
}
header('Location: access_denied.php'); // Trying as self, but no right for self, and noone to work on behalf.
exit();
}
+if ($request->isPost()) {
+ $groupChanged = $request->getParameter('group_changed'); // Reused in multiple places below.
+ if ($groupChanged && !($user->can('manage_subgroups') && $user->isGroupValid($request->getParameter('group')))) {
+ header('Location: access_denied.php'); // Group changed, but no rght or wrong group id.
+ exit();
+ }
+ $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 group id.
+ exit();
+ }
+}
// End of access checks.
+// Determine group for which we display this page.
+if ($request->isPost() && $groupChanged) {
+ $group_id = $request->getParameter('group');
+ $user->setOnBehalfGroup($group_id);
+} else {
+ $group_id = $user->getGroup();
+}
+// 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->getActiveUser();
+}
+
// Initialize and store date in session.
$cl_date = $request->getParameter('date', @$_SESSION['date']);
$selected_date = new DateAndTime(DB_DATEFORMAT, $cl_date);
// Use custom fields plugin if it is enabled.
if ($user->isPluginEnabled('cf')) {
require_once('plugins/CustomFields.class.php');
- $custom_fields = new CustomFields($user->group_id);
+ $custom_fields = new CustomFields($user->getGroup());
$smarty->assign('custom_fields', $custom_fields);
}
if (isset($_SESSION['billable']))
$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));
+//$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 (isTrue(SUBGROUP_DEBUG)) {
+// Group dropdown.
if ($user->can('manage_subgroups')) {
$groups = $user->getGroupsForDropdown();
if (count($groups) > 1) {
$form->addInput(array('type'=>'combobox',
- 'onchange'=>'this.form.submit();',
- 'name'=>'onBehalfGroup',
+ 'onchange'=>'document.timeRecordForm.group_changed.value=1;document.timeRecordForm.submit();',
+ 'name'=>'group',
'style'=>'width: 250px;',
- 'value'=>$on_behalf_group_id,
+ 'value'=>$group_id,
'data'=>$groups,
'datakeys'=>array('id','name')));
- $smarty->assign('on_behalf_group_control', 1);
+ $form->addInput(array('type'=>'hidden','name'=>'group_changed'));
+ $smarty->assign('group_dropdown', 1);
}
}
-} // SUBGROUP_DEBUG
-
if ($user->can('track_time')) {
- $rank = $user->getMaxRankForGroup($on_behalf_group_id);
+ $rank = $user->getMaxRankForGroup($group_id);
if ($user->can('track_own_time'))
- $options = array('group_id'=>$on_behalf_group_id,'status'=>ACTIVE,'max_rank'=>$rank,'include_self'=>true,'self_first'=>true);
+ $options = array('group_id'=>$group_id,'status'=>ACTIVE,'max_rank'=>$rank,'include_self'=>true,'self_first'=>true);
else
- $options = array('group_id'=>$on_behalf_group_id,'status'=>ACTIVE,'max_rank'=>$rank);
+ $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'=>'this.form.submit();',
- 'name'=>'onBehalfUser',
+ 'onchange'=>'document.timeRecordForm.user_changed.value=1;document.timeRecordForm.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')) {
- $active_clients = ttTeamHelper::getActiveClients($user->group_id, true);
+if (MODE_TIME == $user->getTrackingMode() && $user->isPluginEnabled('cl')) {
+ $active_clients = ttTeamHelper::getActiveClients($user->getGroup(), true);
$form->addInput(array('type'=>'combobox',
'onchange'=>'fillProjectDropdown(this.value);',
'name'=>'client',
// 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',
// Dropdown for clients if the clients plugin is enabled.
if ($user->isPluginEnabled('cl')) {
- $active_clients = ttTeamHelper::getActiveClients($user->group_id, true);
+ $active_clients = ttTeamHelper::getActiveClients($user->getGroup(), true);
// We need an array of assigned project ids to do some trimming.
foreach($project_list as $project)
$projects_assigned_to_user[] = $project['id'];
}
}
-if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode) {
- $task_list = ttTeamHelper::getActiveTasks($user->group_id);
+if (MODE_PROJECTS_AND_TASKS == $user->getTrackingMode()) {
+ $task_list = ttTeamHelper::getActiveTasks($user->getGroup());
$form->addInput(array('type'=>'combobox',
'name'=>'task',
'style'=>'width: 250px;',
}
// Add other controls.
-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');"));
if (!defined('NOTE_INPUT_HEIGHT'))
define('NOTE_INPUT_HEIGHT', 40);
exit();
}
}
- elseif ($request->getParameter('onBehalfUser') || $request->getParameter('onBehalfGroup')) {
- // User changed either on behalf user or group.
- // TODO: Organize this code into a separate function.
-
- // We get here if one of the dropdowns changed. Handle these 2 situations differently.
- // 1) User changed. Determine if user changed. Then do exactly as before.
- //
- // Group changed. Determine if group changed.
- // Adjust group info.
- // Adjust user info to first user in group (or self if we are in home group now).
- //
- // Determine if user was changed.
- if ($request->getParameter('onBehalfUser')) {
- $request_user_id = $request->getParameter('onBehalfUser');
- $session_user_id = $_SESSION['behalf_id'];
- $user_changed = !(($session_user_id == null && ($user->id == $request_user_id))
- || ($session_user_id != null && ($request_user_id == $session_user_id)));
- if ($user_changed && $user->can('track_time')) {
- unset($_SESSION['behalf_id']);
- unset($_SESSION['behalf_name']);
-
- if($request_user_id != $user->id) {
- $_SESSION['behalf_id'] = $request_user_id;
- $_SESSION['behalf_name'] = ttUserHelper::getUserName($request_user_id);
- }
- }
- }
-
- if ($request->getParameter('onBehalfGroup')) {
- // Determine if group was changed.
- $request_group_id = $request->getParameter('onBehalfGroup');
- $session_group_id = $_SESSION['behalf_group_id'];
- $group_changed = !(($session_group_id == null && ($user->group_id == $request_group_id))
- || ($session_group_id != null && ($request_group_id == $session_group_id)));
-
- if ($group_changed && $user->can('manage_subgroups')) {
- unset($_SESSION['behalf_group_id']);
- unset($_SESSION['behalf_group_name']);
- if ($request_group_id == $user->group_id)
- $user->behalf_group_id = null;
-
- if (($request_group_id != $user->group_id) && $user->isSubgroupValid($request_group_id)) {
- $_SESSION['behalf_group_id'] = $request_group_id;
- $_SESSION['behalf_group_name'] = ttGroupHelper::getGroupName($request_group_id);
- $user->behalf_group_id = $request_group_id;
- }
-
- unset($_SESSION['behalf_id']);
- unset($_SESSION['behalf_name']);
- if ($request_group_id != $user->group_id)
- $user->adjustBehalfId();
- }
- }
- header('Location: time.php');
- exit();
- }
} // isPost
$week_total = ttTimeHelper::getTimeForWeek($user->getActiveUser(), $selected_date);