From a106b7a2db73b3e1fdab428b218212f6f38d7623 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Thu, 6 Dec 2018 13:39:13 +0000 Subject: [PATCH] Added conditional display of pages depending on subgroup active users. --- WEB-INF/lib/ttGroup.class.php | 15 +++++++++++++++ WEB-INF/lib/ttUser.class.php | 15 ++++++++++++++- WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/header.tpl | 13 +++++++------ WEB-INF/templates/mobile/header.tpl | 8 ++++---- charts.php | 7 ++++--- expenses.php | 7 ++++--- mobile/expenses.php | 7 ++++--- mobile/projects.php | 2 +- mobile/tasks.php | 6 +++--- 10 files changed, 57 insertions(+), 25 deletions(-) diff --git a/WEB-INF/lib/ttGroup.class.php b/WEB-INF/lib/ttGroup.class.php index bb03845d..fe8c8a98 100644 --- a/WEB-INF/lib/ttGroup.class.php +++ b/WEB-INF/lib/ttGroup.class.php @@ -62,6 +62,9 @@ class ttGroup { var $first_unit_threshold = 0;// Threshold for 1st unit for Work units plugin. var $unit_totals_only = 0; // Totals only option for the Work units plugin. + var $active_users = 0; // Count of active users in group. + // We need a non-zero count to display some menus. + // Constructor. function __construct($id, $org_id) { $mdb2 = getConnection(); @@ -119,5 +122,17 @@ class ttGroup { } */ } + + // Determine active user count in a separate query. + // TODO: If performance becomes an issue, ivestigate combining 2 queries in one. + // At this time we only need to know if at least 1 active user exists. + $sql = "select count(*) as user_count from tt_users". + " where group_id = $id and org_id = $org_id and status = 1"; + $res = $mdb2->query($sql); + if (is_a($res, 'PEAR_Error')) { + return; + } + $val = $res->fetchRow(); + $this->active_users = $val['user_count']; } } diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index 05081c5a..7867ac8e 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -810,7 +810,7 @@ class ttUser { return; } - // setOnBehalfUser sets on behalf user both the object and the session. + // setOnBehalfUser sets on behalf user both the object and the session. function setOnBehalfUser($user_id) { // Unset things first. @@ -833,4 +833,17 @@ class ttUser { $this->behalf_name = $onBehalfUserName; return; } + + // The exists() function determines if an active user exists in context of a page. + // If we are working as self, true. + // If we are working in a subgroup with active users, true. + // If we are working in a subgroup without active users, false. + function exists() { + if (!$this->behalfGroup) + return true; // Working as self. + else if ($this->behalfGroup->active_users) + return true; // Subgroup has users. + + return false; + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index b2cdebb7..d59ff9e7 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.29.4595 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4596 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/header.tpl b/WEB-INF/templates/header.tpl index 57e842ee..05270297 100644 --- a/WEB-INF/templates/header.tpl +++ b/WEB-INF/templates/header.tpl @@ -108,20 +108,21 @@
  - {if $user->can('track_own_time') || $user->can('track_time')} + {if $user->exists() && ($user->can('track_own_time') || $user->can('track_time'))} {$i18n.menu.time} {/if} - {if $user->isPluginEnabled('ex') && ($user->can('track_own_expenses') || $user->can('track_expenses'))} + {if $user->exists() && $user->isPluginEnabled('ex') && ($user->can('track_own_expenses') || $user->can('track_expenses'))} · {$i18n.menu.expenses} {/if} - {if $user->can('view_own_reports') || $user->can('view_reports')} + {if $user->exists() && ($user->can('view_own_reports') || $user->can('view_reports'))} · {$i18n.menu.reports} {/if} - {if $user->isPluginEnabled('iv') && ($user->can('view_own_invoices') || $user->can('manage_invoices'))} + {if $user->exists() && $user->isPluginEnabled('iv') && ($user->can('view_own_invoices') || $user->can('manage_invoices'))} · {$i18n.title.invoices} {/if} - {if ($user->isPluginEnabled('ch') && ($user->can('view_own_charts') || $user->can('view_charts'))) && ($smarty.const.MODE_PROJECTS == $user->getTrackingMode() - || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->getTrackingMode() || $user->isPluginEnabled('cl'))} + {if ($user->exists() && $user->isPluginEnabled('ch') && ($user->can('view_own_charts') || $user->can('view_charts'))) && + ($smarty.const.MODE_PROJECTS == $user->getTrackingMode() || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->getTrackingMode() || + $user->isPluginEnabled('cl'))} · {$i18n.menu.charts} {/if} {if ($user->can('view_own_projects') || $user->can('manage_projects')) && ($smarty.const.MODE_PROJECTS == $user->getTrackingMode() || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->getTrackingMode())} diff --git a/WEB-INF/templates/mobile/header.tpl b/WEB-INF/templates/mobile/header.tpl index fdded891..9e1c452d 100644 --- a/WEB-INF/templates/mobile/header.tpl +++ b/WEB-INF/templates/mobile/header.tpl @@ -73,16 +73,16 @@
  - {if $user->can('track_own_time') || $user->can('track_time')} + {if $user->exists() && ($user->can('track_own_time') || $user->can('track_time'))} {$i18n.menu.time} {/if} - {if $user->isPluginEnabled('ex') && ($user->can('track_own_expenses') || $user->can('track_expenses'))} + {if $user->exists() && $user->isPluginEnabled('ex') && ($user->can('track_own_expenses') || $user->can('track_expenses'))} · {$i18n.menu.expenses} {/if} - {if ($user->can('view_own_projects') || $user->can('manage_projects')) && ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)} + {if ($user->can('view_own_projects') || $user->can('manage_projects')) && ($smarty.const.MODE_PROJECTS == $user->getTrackingMode() || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->getTrackingMode())} · {$i18n.menu.projects} {/if} - {if ($user->can('view_own_tasks') || $user->can('manage_tasks')) && $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode} + {if ($user->can('view_own_tasks') || $user->can('manage_tasks')) && $smarty.const.MODE_PROJECTS_AND_TASKS == $user->getTrackingMode()} · {$i18n.menu.tasks} {/if} {if $user->can('view_users') || $user->can('manage_users')} diff --git a/charts.php b/charts.php index 6329e14f..862a2fad 100644 --- a/charts.php +++ b/charts.php @@ -46,6 +46,10 @@ if (!$user->isPluginEnabled('ch')) { header('Location: feature_disabled.php'); exit(); } +if (!$user->exists()) { + header('Location: access_denied.php'); // Nobody to display a chart for. + exit(); +} if ($user->behalf_id && (!$user->can('view_charts') || !$user->checkBehalfId())) { header('Location: access_denied.php'); // Trying on behalf, but no right or wrong user. exit(); @@ -69,9 +73,6 @@ if ($request->isPost() && $userChanged) { $user->setOnBehalfUser($user_id); } else { $user_id = $user->getUser(); - // Handle a situation for no users in on behalf group. - if ($user->behalfGroup && $user_id == $user->id) - $user_id = null; } $uc = new ttUserConfig(); diff --git a/expenses.php b/expenses.php index eb11e73a..9a345422 100644 --- a/expenses.php +++ b/expenses.php @@ -42,6 +42,10 @@ if (!$user->isPluginEnabled('ex')) { header('Location: feature_disabled.php'); exit(); } +if (!$user->exists()) { + header('Location: access_denied.php'); // Nobody to enter expenses for. + exit(); +} if ($user->behalf_id && (!$user->can('track_expenses') || !$user->checkBehalfId())) { header('Location: access_denied.php'); // Trying on behalf, but no right or wrong user. exit(); @@ -65,9 +69,6 @@ if ($request->isPost() && $userChanged) { $user->setOnBehalfUser($user_id); } else { $user_id = $user->getUser(); - // Handle a situation for no users in on behalf group. - if ($user->behalfGroup && $user_id == $user->id) - $user_id = null; } // Initialize and store date in session. diff --git a/mobile/expenses.php b/mobile/expenses.php index eeece003..ac565207 100644 --- a/mobile/expenses.php +++ b/mobile/expenses.php @@ -42,6 +42,10 @@ if (!$user->isPluginEnabled('ex')) { header('Location: feature_disabled.php'); exit(); } +if (!$user->exists()) { + header('Location: access_denied.php'); // Nobody to enter expenses for. + exit(); +} if ($user->behalf_id && (!$user->can('track_expenses') || !$user->checkBehalfId())) { header('Location: access_denied.php'); // Trying on behalf, but no right or wrong user. exit(); @@ -65,9 +69,6 @@ if ($request->isPost() && $userChanged) { $user->setOnBehalfUser($user_id); } else { $user_id = $user->getUser(); - // Handle a situation for no users in on behalf group. - if ($user->behalfGroup && $user_id == $user->id) - $user_id = null; } // Initialize and store date in session. diff --git a/mobile/projects.php b/mobile/projects.php index d244ae1b..6a5ac572 100644 --- a/mobile/projects.php +++ b/mobile/projects.php @@ -36,7 +36,7 @@ if (!(ttAccessAllowed('view_own_projects') || ttAccessAllowed('manage_projects') header('Location: access_denied.php'); exit(); } -if (MODE_PROJECTS != $user->tracking_mode && MODE_PROJECTS_AND_TASKS != $user->tracking_mode) { +if (MODE_PROJECTS != $user->getTrackingMode() && MODE_PROJECTS_AND_TASKS != $user->getTrackingMode()) { header('Location: feature_disabled.php'); exit(); } diff --git a/mobile/tasks.php b/mobile/tasks.php index c45f9bf0..0667bc3b 100644 --- a/mobile/tasks.php +++ b/mobile/tasks.php @@ -35,15 +35,15 @@ if (!(ttAccessAllowed('view_own_tasks') || ttAccessAllowed('manage_tasks'))) { header('Location: access_denied.php'); exit(); } -if (MODE_PROJECTS_AND_TASKS != $user->tracking_mode) { +if (MODE_PROJECTS_AND_TASKS != $user->getTrackingMode()) { header('Location: feature_disabled.php'); exit(); } // End of access checks. if($user->can('manage_tasks')) { - $active_tasks = ttTeamHelper::getActiveTasks($user->group_id); - $inactive_tasks = ttTeamHelper::getInactiveTasks($user->group_id); + $active_tasks = ttTeamHelper::getActiveTasks($user->getGroup()); + $inactive_tasks = ttTeamHelper::getInactiveTasks($user->getGroup()); } else $active_tasks = $user->getAssignedTasks(); -- 2.20.1