From: Nik Okuntseff Date: Wed, 12 Dec 2018 17:24:33 +0000 (+0000) Subject: Excluded clients from getActiveUsers call. X-Git-Tag: timetracker_1.19-1~428 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=fafb0ae8f7098ffafa6799627891bd40f4811a52;p=timetracker.git Excluded clients from getActiveUsers call. --- diff --git a/WEB-INF/lib/ttFavReportHelper.class.php b/WEB-INF/lib/ttFavReportHelper.class.php index 165f42a3..30bfc235 100644 --- a/WEB-INF/lib/ttFavReportHelper.class.php +++ b/WEB-INF/lib/ttFavReportHelper.class.php @@ -26,7 +26,7 @@ // | https://www.anuko.com/time_tracker/credits.htm // +----------------------------------------------------------------------+ -import('ttTeamHelper'); +import('ttGroupHelper'); // Class ttFavReportHelper is used to help with favorite report related tasks. class ttFavReportHelper { @@ -407,7 +407,7 @@ class ttFavReportHelper { $user_options = array('max_rank'=>$max_rank); $users = $user->getUsers($user_options); // Active and inactive users. } elseif ($user->isClient()) { - $users = ttTeamHelper::getUsersForClient(); // Active and inactive users for clients. + $users = ttGroupHelper::getUsersForClient(); // Active and inactive users for clients. } foreach ($users as $single_user) { $user_ids[] = $single_user['id']; @@ -417,7 +417,7 @@ class ttFavReportHelper { } else { $users_to_adjust = explode(',', $options['users']); // Users to adjust. if ($user->isClient()) { - $users = ttTeamHelper::getUsersForClient(); // Active and inactive users for clients. + $users = ttGroupHelper::getUsersForClient(); // Active and inactive users for clients. foreach ($users as $single_user) { $user_ids[] = $single_user['id']; } diff --git a/WEB-INF/lib/ttGroupHelper.class.php b/WEB-INF/lib/ttGroupHelper.class.php index ad231675..fb895c46 100644 --- a/WEB-INF/lib/ttGroupHelper.class.php +++ b/WEB-INF/lib/ttGroupHelper.class.php @@ -447,7 +447,7 @@ class ttGroupHelper { return false; } - // The getActiveUsers obtains all active users in a given group. + // The getActiveUsers obtains all active users excluding clients in a given group. static function getActiveUsers($options = null) { global $user; global $i18n; @@ -456,10 +456,12 @@ class ttGroupHelper { $group_id = $user->getGroup(); $org_id = $user->org_id; + $client_part = " and u.client_id is null"; + if (isset($options['getAllFields'])) - $sql = "select u.*, r.name as role_name, r.rank from tt_users u left join tt_roles r on (u.role_id = r.id) where u.group_id = $group_id and u.org_id = $org_id and u.status = 1 order by upper(u.name)"; + $sql = "select u.*, r.name as role_name, r.rank from tt_users u left join tt_roles r on (u.role_id = r.id) where u.group_id = $group_id and u.org_id = $org_id and u.status = 1 $client_part order by upper(u.name)"; else - $sql = "select id, name from tt_users where group_id = $group_id and org_id = $org_id and status = 1 order by upper(name)"; + $sql = "select u.id, u.name from tt_users u where u.group_id = $group_id and u.org_id = $org_id and u.status = 1 $client_part order by upper(u.name)"; $res = $mdb2->query($sql); $user_list = array(); if (is_a($res, 'PEAR_Error')) @@ -471,17 +473,6 @@ class ttGroupHelper { $user_list[] = $val; } - if (isset($options['putSelfFirst'])) { - // Put own entry at the front. - $cnt = count($user_list); - for($i = 0; $i < $cnt; $i++) { - if ($user_list[$i]['id'] == $user->id) { - $self = $user_list[$i]; // Found self. - array_unshift($user_list, $self); // Put own entry at the front. - array_splice($user_list, $i+1, 1); // Remove duplicate. - } - } - } return $user_list; } @@ -583,4 +574,28 @@ class ttGroupHelper { } return $user_list; } + + // The getUsersForClient obtains all active and inactive users in a group that are relevant to a client. + static function getUsersForClient() { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "select u.id, u.name from tt_user_project_binds upb". + " inner join tt_client_project_binds cpb on (upb.project_id = cpb.project_id and cpb.client_id = $user->client_id)". + " inner join tt_users u on (u.id = upb.user_id and u.group_id = $group_id and u.org_id = $org_id)". + " where (u.status = 1 or u.status = 0)". + " group by u.id". + " order by upper(u.name)"; + $res = $mdb2->query($sql); + $user_list = array(); + if (is_a($res, 'PEAR_Error')) + return false; + while ($val = $res->fetchRow()) { + $user_list[] = $val; + } + return $user_list; + } } diff --git a/WEB-INF/lib/ttTeamHelper.class.php b/WEB-INF/lib/ttTeamHelper.class.php index 4dd2f9aa..72070877 100644 --- a/WEB-INF/lib/ttTeamHelper.class.php +++ b/WEB-INF/lib/ttTeamHelper.class.php @@ -33,27 +33,6 @@ import('ttInvoiceHelper'); // Class ttTeamHelper - contains helper functions that operate with groups. class ttTeamHelper { - // The getUsersForClient obtains all active and inactive users in a group that are relevant to a client. - static function getUsersForClient() { - global $user; - $mdb2 = getConnection(); - - $sql = "select u.id, u.name from tt_user_project_binds upb". - " inner join tt_client_project_binds cpb on (upb.project_id = cpb.project_id and cpb.client_id = $user->client_id)". - " inner join tt_users u on (u.id = upb.user_id)". - " where (u.status = 1 or u.status = 0)". - " group by u.id". - " order by upper(u.name)"; - $res = $mdb2->query($sql); - $user_list = array(); - if (is_a($res, 'PEAR_Error')) - return false; - while ($val = $res->fetchRow()) { - $user_list[] = $val; - } - return $user_list; - } - // The swapRolesWith swaps existing user role with that of another user. static function swapRolesWith($user_id) { global $user; diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index d320e381..c00bd9f4 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -113,9 +113,9 @@ class ttUser { $this->role_id = $val['role_id']; $this->role_name = $val['role_name']; $this->rights = explode(',', $val['rights']); - $this->is_client = !in_array('track_own_time', $this->rights); $this->rank = $val['rank']; $this->client_id = $val['client_id']; + $this->is_client = $this->client_id && !in_array('track_own_time', $this->rights); $this->email = $val['email']; $this->lang = $val['lang']; $this->decimal_mark = $val['decimal_mark']; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 1caa6b55..d2754e7d 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.29.4635 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4636 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/mobile/project_add.php b/mobile/project_add.php index c8c661ed..c152006f 100644 --- a/mobile/project_add.php +++ b/mobile/project_add.php @@ -36,7 +36,7 @@ if (!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/users.php b/mobile/users.php index 594fa5bf..0c54751d 100644 --- a/mobile/users.php +++ b/mobile/users.php @@ -39,15 +39,20 @@ if (!(ttAccessAllowed('view_users') || ttAccessAllowed('manage_users'))) { } // End of access checks. -$uncompleted_indicators = $user->getConfigOption('uncompleted_indicators'); +// Prepare a list of active users. +if ($user->can('view_users')) + $options = array('status'=>ACTIVE,'include_clients'=>true,'include_login'=>true,'include_role'=>true); +else /* if ($user->can('manage_users')) */ + $options = array('status'=>ACTIVE,'max_rank'=>$user->rank-1,'include_clients'=>true,'include_self'=>true,'include_login'=>true,'include_role'=>true); +$active_users = $user->getUsers($options); -// Get users. -$active_users = ttGroupHelper::getActiveUsers(array('getAllFields'=>true)); +// Prepare a list of inactive users. if($user->can('manage_users')) { - $can_delete_manager = (1 == count($active_users)); - $inactive_users = ttTeamHelper::getInactiveUsers($user->group_id, true); + $options = array('status'=>INACTIVE,'max_rank'=>$user->rank-1,'include_clients'=>true,'include_login'=>true,'include_role'=>true); + $inactive_users = $user->getUsers($options); } +$uncompleted_indicators = $user->getConfigOption('uncompleted_indicators'); if ($uncompleted_indicators) { // Check each active user if they have an uncompleted time entry. foreach ($active_users as $key => $user) { diff --git a/reports.php b/reports.php index c3bb8809..ee82a64f 100644 --- a/reports.php +++ b/reports.php @@ -30,7 +30,6 @@ require_once('initialize.php'); import('form.Form'); import('form.ActionForm'); import('DateAndTime'); -import('ttTeamHelper'); import('ttGroupHelper'); import('Period'); import('ttProjectHelper'); @@ -165,7 +164,7 @@ if ($user->can('view_reports') || $user->can('view_all_reports') || $user->isCli $users = $user->getUsers($options); // Active and inactive users. } elseif ($user->isClient()) - $users = ttTeamHelper::getUsersForClient(); // Active and inactive users for clients. + $users = ttGroupHelper::getUsersForClient(); // Active and inactive users for clients. foreach ($users as $single_user) { $user_list[$single_user['id']] = $single_user['name']; diff --git a/users.php b/users.php index 47ec0145..77b7e552 100644 --- a/users.php +++ b/users.php @@ -50,7 +50,6 @@ if ($request->isPost()) { } else { $group_id = $user->getGroup(); } -$uncompleted_indicators = $user->getConfigOption('uncompleted_indicators'); $form = new Form('usersForm'); if ($user->can('manage_subgroups')) { @@ -80,6 +79,7 @@ if($user->can('manage_users')) { $inactive_users = $user->getUsers($options); } +$uncompleted_indicators = $user->getConfigOption('uncompleted_indicators'); if ($uncompleted_indicators) { // Check each active user if they have an uncompleted time entry. foreach ($active_users as $key => $user) {