From dc799619007c9eafdec69a70f89a2d08bb10864c Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Mon, 20 May 2019 19:37:03 +0000 Subject: [PATCH] Rewrote group dropdown fill function to include the entire tree. --- WEB-INF/lib/ttUser.class.php | 32 ++++++++++++++++++++++++++++++++ WEB-INF/templates/footer.tpl | 2 +- group_edit.php | 2 +- groups.php | 2 +- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index 62c786ce..8f9578dd 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -560,6 +560,38 @@ class ttUser { return $groups; } + // getGroupsForDropdown2 obtains an array of groups to populate the "Group" dropdown. + // It consists of the entire tree starting from user home group down. + // Group name is prefixed with additional characters to indicate subgroups level. + function getGroupsForDropdown2() { + global $user; + + // Start with user home group. + $groups = array(); + $subgroup_level = 0; + $group_id = $user->group_id; + + $this->addGroup($groups, $group_id, $subgroup_level); + return $groups; + } + + // addGroup is a recursive function to populate a tree of groups. + function addGroup(&$groups, $group_id, $subgroup_level) { + // Add indentation markup to indicate subdirectory level. + for ($i = 0; $i < $subgroup_level; $i++) { + $name .= '🛑'; // Unicode stop sign. + } + if ($subgroup_level) $name .= ' '; // Add an extra space. + $name .= ttGroupHelper::getGroupName($group_id); + + $groups[] = array('id'=>$group_id, 'name'=>$name); + + $subgroups = $this->getSubgroups($group_id); + foreach($subgroups as $subgroup) { + $this->addGroup($groups, $subgroup['id'], $subgroup_level+1); + } + } + // getSubgroups obtains a list of immediate subgroups. function getSubgroups($group_id = null) { $mdb2 = getConnection(); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index a3ce2484..14944213 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.19.4.5007 | Copyright © Anuko | +  Anuko Time Tracker 1.19.4.5008 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/group_edit.php b/group_edit.php index 1df99a1c..77b464b9 100644 --- a/group_edit.php +++ b/group_edit.php @@ -68,7 +68,7 @@ if ($request->isPost() && $groupChanged) { $user->setOnBehalfGroup($group_id); } -$groups = $user->getGroupsForDropdown(); +$groups = $user->getGroupsForDropdown2(); $group = ttGroupHelper::getGroupAttrs($group_id); $config = $user->getConfigHelper(); diff --git a/groups.php b/groups.php index f335153c..449bd636 100644 --- a/groups.php +++ b/groups.php @@ -49,7 +49,7 @@ if ($request->isPost()) { } $form = new Form('subgroupsForm'); -$groups = $user->getGroupsForDropdown(); +$groups = $user->getGroupsForDropdown2(); if (count($groups) > 1) { $form->addInput(array('type'=>'combobox', 'onchange'=>'this.form.submit();', -- 2.20.1