+
+ // setOnBehalfGroup sets on behalf group for the user in both the object and the session.
+ function setOnBehalfGroup($group_id) {
+
+ // Unset things first.
+ $this->behalf_group_id = null;
+ $this->behalf_group_name = null;
+ $this->behalf_id = null;
+ $this->behalf_name = null;
+ unset($_SESSION['behalf_group_id']);
+ unset($_SESSION['behalf_group_name']);
+ unset($_SESSION['behalf_id']);
+ unset($_SESSION['behalf_name']);
+
+ // 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.
+ if ($group_id == $this->group_id) return;
+
+ // No need to set if the subgroup is not valid.
+ if (!$this->isSubgroupValid($group_id)) return;
+
+ // We are good to set on behalf group.
+ $onBehalfGroupName = ttGroupHelper::getGroupName($group_id);
+ $_SESSION['behalf_group_id'] = $group_id;
+ $_SESSION['behalf_group_name'] = $onBehalfGroupName;
+ $this->behalf_group_id = $group_id;
+ $this->behalf_group_name = $onBehalfGroupName;
+
+ unset($this->behalfGroup);
+ $this->behalfGroup = new ttGroup($this->behalf_group_id, $this->org_id);
+
+ // Adjust on behalf user.
+ $this->adjustBehalfId();
+ return;
+ }