From: Nik Okuntseff Date: Sun, 9 Dec 2018 14:51:25 +0000 (+0000) Subject: Refactoring - ongoing. X-Git-Tag: timetracker_1.19-1~445 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=01654e65fdac375c1db8317a956b727987c98c04;p=timetracker.git Refactoring - ongoing. --- diff --git a/WEB-INF/lib/ttGroupHelper.class.php b/WEB-INF/lib/ttGroupHelper.class.php index 4ba7805e..8298627a 100644 --- a/WEB-INF/lib/ttGroupHelper.class.php +++ b/WEB-INF/lib/ttGroupHelper.class.php @@ -446,4 +446,42 @@ class ttGroupHelper { } return false; } + + // The getActiveUsers obtains all active users in a given group. + static function getActiveUsers($options = null) { + global $user; + global $i18n; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + 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)"; + 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)"; + $res = $mdb2->query($sql); + $user_list = array(); + if (is_a($res, 'PEAR_Error')) + return false; + while ($val = $res->fetchRow()) { + // Localize top manager role name, as it is not localized in db. + if ($val['rank'] == 512) + $val['role_name'] = $i18n->get('role.top_manager.label'); + $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; + } } diff --git a/WEB-INF/lib/ttProjectHelper.class.php b/WEB-INF/lib/ttProjectHelper.class.php index b5fb74dc..87d75c62 100644 --- a/WEB-INF/lib/ttProjectHelper.class.php +++ b/WEB-INF/lib/ttProjectHelper.class.php @@ -28,6 +28,7 @@ import('ttTeamHelper'); import('ttUserHelper'); +import('ttGroupHelper'); // Class ttProjectHelper is used to help with project related tasks. class ttProjectHelper { @@ -216,7 +217,7 @@ class ttProjectHelper { $last_id = $mdb2->lastInsertID('tt_projects', 'id'); // Bind the project to users. - $active_users = ttTeamHelper::getActiveUsers(array('getAllFields'=>true)); + $active_users = ttGroupHelper::getActiveUsers(array('getAllFields'=>true)); foreach ($active_users as $u) { if(in_array($u['id'], $users)) { $sql = "insert into tt_user_project_binds (project_id, user_id, group_id, org_id, status, rate) values( diff --git a/WEB-INF/lib/ttTeamHelper.class.php b/WEB-INF/lib/ttTeamHelper.class.php index cf455405..2aab936a 100644 --- a/WEB-INF/lib/ttTeamHelper.class.php +++ b/WEB-INF/lib/ttTeamHelper.class.php @@ -54,44 +54,6 @@ class ttTeamHelper { return $user_list; } - // The getActiveUsers obtains all active users in a given group. - static function getActiveUsers($options = null) { - global $user; - global $i18n; - $mdb2 = getConnection(); - - $group_id = $user->getGroup(); - $org_id = $user->org_id; - - 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)"; - 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)"; - $res = $mdb2->query($sql); - $user_list = array(); - if (is_a($res, 'PEAR_Error')) - return false; - while ($val = $res->fetchRow()) { - // Localize top manager role name, as it is not localized in db. - if ($val['rank'] == 512) - $val['role_name'] = $i18n->get('role.top_manager.label'); - $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; - } - // The swapRolesWith swaps existing user role with that of another user. static function swapRolesWith($user_id) { global $user; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index d6037b02..dff1dd79 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.29.4619 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4620 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/mobile/project_add.php b/mobile/project_add.php index a7a540d0..a6ed2e8d 100644 --- a/mobile/project_add.php +++ b/mobile/project_add.php @@ -30,6 +30,7 @@ require_once('../initialize.php'); import('form.Form'); import('ttProjectHelper'); import('ttTeamHelper'); +import('ttGroupHelper'); // Access checks. if (!ttAccessAllowed('manage_projects')) { @@ -42,7 +43,7 @@ if (MODE_PROJECTS != $user->tracking_mode && MODE_PROJECTS_AND_TASKS != $user->t } // End of access checks. -$users = ttTeamHelper::getActiveUsers(); +$users = ttGroupHelper::getActiveUsers(); foreach ($users as $user_item) $all_users[$user_item['id']] = $user_item['name']; diff --git a/mobile/project_edit.php b/mobile/project_edit.php index 88794615..ec8c53ba 100644 --- a/mobile/project_edit.php +++ b/mobile/project_edit.php @@ -30,6 +30,7 @@ require_once('../initialize.php'); import('form.Form'); import('ttProjectHelper'); import('ttTeamHelper'); +import('ttGroupHelper'); // Access checks. if (!ttAccessAllowed('manage_projects')) { @@ -48,7 +49,7 @@ if (!$project) { } // End of access checks. -$users = ttTeamHelper::getActiveUsers(); +$users = ttGroupHelper::getActiveUsers(); foreach ($users as $user_item) $all_users[$user_item['id']] = $user_item['name']; diff --git a/mobile/users.php b/mobile/users.php index 874b0763..594fa5bf 100644 --- a/mobile/users.php +++ b/mobile/users.php @@ -29,6 +29,7 @@ require_once('../initialize.php'); import('form.Form'); import('ttTeamHelper'); +import('ttGroupHelper'); import('ttTimeHelper'); // Access checks. @@ -41,7 +42,7 @@ if (!(ttAccessAllowed('view_users') || ttAccessAllowed('manage_users'))) { $uncompleted_indicators = $user->getConfigOption('uncompleted_indicators'); // Get users. -$active_users = ttTeamHelper::getActiveUsers(array('getAllFields'=>true)); +$active_users = ttGroupHelper::getActiveUsers(array('getAllFields'=>true)); if($user->can('manage_users')) { $can_delete_manager = (1 == count($active_users)); $inactive_users = ttTeamHelper::getInactiveUsers($user->group_id, true); diff --git a/project_add.php b/project_add.php index 9800b721..53cad4bc 100644 --- a/project_add.php +++ b/project_add.php @@ -30,6 +30,7 @@ require_once('initialize.php'); import('form.Form'); import('ttProjectHelper'); import('ttTeamHelper'); +import('ttGroupHelper'); // Access checks. if (!ttAccessAllowed('manage_projects')) { @@ -42,7 +43,7 @@ if (MODE_PROJECTS != $user->getTrackingMode() && MODE_PROJECTS_AND_TASKS != $use } // End of access checks. -$users = ttTeamHelper::getActiveUsers(); +$users = ttGroupHelper::getActiveUsers(); foreach ($users as $user_item) $all_users[$user_item['id']] = $user_item['name']; diff --git a/project_edit.php b/project_edit.php index 542fb464..14f319e9 100644 --- a/project_edit.php +++ b/project_edit.php @@ -30,6 +30,7 @@ require_once('initialize.php'); import('form.Form'); import('ttProjectHelper'); import('ttTeamHelper'); +import('ttGroupHelper'); // Access checks. if (!ttAccessAllowed('manage_projects')) { @@ -48,7 +49,7 @@ if (!$project) { } // End of access checks. -$users = ttTeamHelper::getActiveUsers(); +$users = ttGroupHelper::getActiveUsers(); foreach ($users as $user_item) $all_users[$user_item['id']] = $user_item['name'];