From 10e652b9628722c1aad1ab875a3bda1007167c31 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 23 Nov 2018 21:03:09 +0000 Subject: [PATCH] Fixed adding subgroups with a proper parent group. --- WEB-INF/lib/ttUser.class.php | 35 ++++++++++++++++++++++++++++++++++- WEB-INF/templates/footer.tpl | 2 +- groups.php | 1 + 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index 25cc83f7..e50d9a3e 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -419,7 +419,7 @@ class ttUser { if (!$group_id) $group_id = $this->getActiveGroup(); $sql = "select id, name, description from tt_groups where org_id = $this->org_id". - " and parent_id = $group_id and status is not null"; + " and parent_id = $group_id and status is not null order by upper(name)"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { @@ -672,4 +672,37 @@ class ttUser { } return $user_part; } + + // 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; + unset($_SESSION['behalf_group_id']); + unset($_SESSION['behalf_group_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; + + // Question remains whether or not we need to adjust on behalf user. + // Adjusting for now. Test it and redesign if necessary. + unset($_SESSION['behalf_id']); + unset($_SESSION['behalf_name']); + $this->adjustBehalfId(); + return; + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index ec0063a3..425975da 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.27.4504 | Copyright © Anuko | +  Anuko Time Tracker 1.18.27.4505 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/groups.php b/groups.php index 279e5083..172dd329 100644 --- a/groups.php +++ b/groups.php @@ -43,6 +43,7 @@ if ($request->isPost() && !$user->isGroupValid($request->getParameter('group'))) if ($request->isPost()) { $group_id = $request->getParameter('group'); + $user->setOnBehalfGroup($group_id); } else { $group_id = $user->getActiveGroup(); } -- 2.20.1