From aa54f082eb63cdd420733b79c5ec8a8f02def11c Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Thu, 5 Apr 2018 13:15:12 +0000 Subject: [PATCH] More refactoring in admin files. --- WEB-INF/lib/ttAdmin.class.php | 20 ++++++++++++++++++++ WEB-INF/lib/ttTeamHelper.class.php | 20 -------------------- WEB-INF/templates/footer.tpl | 2 +- admin_group_delete.php | 10 +++++----- admin_group_edit.php | 10 ++++++---- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/WEB-INF/lib/ttAdmin.class.php b/WEB-INF/lib/ttAdmin.class.php index f9b12c86..50bffb6f 100644 --- a/WEB-INF/lib/ttAdmin.class.php +++ b/WEB-INF/lib/ttAdmin.class.php @@ -332,4 +332,24 @@ class ttAdmin { return true; } + + // getGroupDetails obtains group name and its top manager details. + function getGroupDetails($group_id) { + $result = array(); + $mdb2 = getConnection(); + + $sql = "select g.name as group_name, u.id as manager_id, u.name as manager_name, u.login as manager_login, u.email as manager_email". + " from tt_groups g". + " inner join tt_users u on (u.group_id = g.id)". + " inner join tt_roles r on (r.id = u.role_id and r.rank = 512)". + " where g.id = $group_id"; + + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + $val = $res->fetchRow(); + return $val; + } + + return false; + } } diff --git a/WEB-INF/lib/ttTeamHelper.class.php b/WEB-INF/lib/ttTeamHelper.class.php index 0093e928..5091c1f9 100644 --- a/WEB-INF/lib/ttTeamHelper.class.php +++ b/WEB-INF/lib/ttTeamHelper.class.php @@ -733,26 +733,6 @@ class ttTeamHelper { return true; } - // The getTeamDetails function returns team details. - static function getTeamDetails($group_id) { - $result = array(); - $mdb2 = getConnection(); - - $sql = "select t.name as team_name, u.id as manager_id, u.name as manager_name, u.login as manager_login, u.email as manager_email - from tt_groups t - inner join tt_users u on (u.group_id = t.id) - inner join tt_roles r on (r.id = u.role_id and r.rank = 512) - where t.id = $group_id"; - - $res = $mdb2->query($sql); - if (!is_a($res, 'PEAR_Error')) { - $val = $res->fetchRow(); - return $val; - } - - return false; - } - // The insert function creates a new team. static function insert($fields) { diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 5dba9ffa..4479bc48 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.17.86.4230 | Copyright © Anuko | +  Anuko Time Tracker 1.17.86.4231 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/admin_group_delete.php b/admin_group_delete.php index 418b7fbb..7c7df615 100644 --- a/admin_group_delete.php +++ b/admin_group_delete.php @@ -28,7 +28,7 @@ require_once('initialize.php'); import('form.Form'); -import('ttTeamHelper'); +import('ttAdmin'); // Access checks. if (!ttAccessAllowed('administer_site')) { @@ -38,8 +38,10 @@ if (!ttAccessAllowed('administer_site')) { // End of access checks. $group_id = (int)$request->getParameter('id'); -$group_details = ttTeamHelper::getTeamDetails($group_id); // TODO: refactor this. -$group_name = $group_details['team_name']; + +$admin = new ttAdmin(); +$group_details = $admin->getGroupDetails($group_id); +$group_name = $group_details['group_name']; $form = new Form('groupForm'); $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$group_id)); @@ -48,8 +50,6 @@ $form->addInput(array('type'=>'submit','name'=>'btn_cancel','value'=>$i18n->get( if ($request->isPost()) { if ($request->getParameter('btn_delete')) { - import('ttAdmin'); - $admin = new ttAdmin(); $result = $admin->markGroupDeleted($group_id); if ($result) { header('Location: admin_groups.php'); diff --git a/admin_group_edit.php b/admin_group_edit.php index a1157fbe..6306bdd0 100644 --- a/admin_group_edit.php +++ b/admin_group_edit.php @@ -29,7 +29,7 @@ require_once('initialize.php'); import('form.Form'); import('ttUserHelper'); -import('ttTeamHelper'); +import('ttAdmin'); // Access checks. if (!ttAccessAllowed('administer_site')) { @@ -39,7 +39,9 @@ if (!ttAccessAllowed('administer_site')) { // End of access checks. $group_id = $request->getParameter('id'); -$group_details = ttTeamHelper::getTeamDetails($group_id); + +$admin = new ttAdmin(); +$group_details = $admin->getGroupDetails($group_id); if ($request->isPost()) { $cl_group_name = trim($request->getParameter('group_name')); @@ -51,7 +53,7 @@ if ($request->isPost()) { } $cl_manager_email = trim($request->getParameter('manager_email')); } else { - $cl_group_name = $group_details['team_name']; + $cl_group_name = $group_details['group_name']; $cl_manager_name = $group_details['manager_name']; $cl_manager_login = $group_details['manager_login']; if (!$auth->isPasswordExternal()) { @@ -77,7 +79,7 @@ if ($request->isPost()) { if ($request->getParameter('btn_save')) { // Create fields array for ttAdmin instance. $fields = array( - 'old_group_name' => $group_details['team_name'], + 'old_group_name' => $group_details['group_name'], 'new_group_name' => $cl_group_name, 'user_id' => $group_details['manager_id'], 'user_name' => $cl_manager_name, -- 2.20.1