From b1082e6ec27ca11586bd786b65f509d1a20220f6 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 30 Nov 2018 12:35:35 +0000 Subject: [PATCH] Refactoring in import. --- WEB-INF/lib/ttOrgImportHelper.class.php | 28 ++++++++++++++++++++++++- WEB-INF/lib/ttRoleHelper.class.php | 5 +++-- WEB-INF/templates/footer.tpl | 2 +- role_add.php | 2 -- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 345b1d2e..011f2081 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -155,7 +155,7 @@ class ttOrgImportHelper { if ($name == 'ROLE') { // We get here when processing tags for the current group. - $role_id = ttRoleHelper::insert(array( + $role_id = $this->insertRole(array( 'group_id' => $this->current_group_id, 'org_id' => $this->org_id, 'name' => $attrs['NAME'], @@ -745,6 +745,32 @@ class ttOrgImportHelper { return $last_id; } + // insertRole - inserts a role into tt_roles table. + private function insertRole($fields) + { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $name = $fields['name']; + $rank = (int) $fields['rank']; + $description = $fields['description']; + $rights = $fields['rights']; + $status = $fields['status']; + + $sql = "insert into tt_roles (group_id, org_id, name, rank, description, rights, status) + values ($group_id, $org_id, ".$mdb2->quote($name).", $rank, ".$mdb2->quote($description).", ".$mdb2->quote($rights).", ".$mdb2->quote($status).")"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + $sql = "SELECT LAST_INSERT_ID() AS last_id"; + $res = $mdb2->query($sql); + $val = $res->fetchRow(); + $last_id = $val['last_id']; + return $last_id; + } + // The insertClient function inserts a new client as well as client to project binds. private function insertClient($fields) { diff --git a/WEB-INF/lib/ttRoleHelper.class.php b/WEB-INF/lib/ttRoleHelper.class.php index 35374469..c14bc970 100644 --- a/WEB-INF/lib/ttRoleHelper.class.php +++ b/WEB-INF/lib/ttRoleHelper.class.php @@ -156,10 +156,11 @@ class ttRoleHelper { // insert - inserts an entry into tt_roles table. static function insert($fields) { + global $user; $mdb2 = getConnection(); - $group_id = (int) $fields['group_id']; - $org_id = (int) $fields['org_id']; + $group_id = $user->getGroup(); + $org_id = $user->org_id; $name = $fields['name']; $rank = (int) $fields['rank']; $description = $fields['description']; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 5879e889..9f251f40 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.28.4542 | Copyright © Anuko | +  Anuko Time Tracker 1.18.28.4543 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/role_add.php b/role_add.php index e1e16cc7..0386e5b1 100644 --- a/role_add.php +++ b/role_add.php @@ -63,8 +63,6 @@ if ($request->isPost()) { if (!$existing_role) { // Insert a role with default user rights. if (ttRoleHelper::insert(array( - 'group_id' => $user->group_id, - 'org_id' => $user->org_id, 'name' => $cl_name, 'rank' => $cl_rank, 'description' => $cl_description, -- 2.20.1