From 1ad0313b11df884c04ca0354abcbc18e4b334537 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Wed, 21 Feb 2018 17:50:40 +0000 Subject: [PATCH] Implemented export and import of roles and improved a comment for tt_roles table. --- WEB-INF/lib/ttExportHelper.class.php | 12 +++++++ WEB-INF/lib/ttImportHelper.class.php | 13 +++++++- WEB-INF/lib/ttRoleHelper.class.php | 50 ++++++++++++++++++++++++++++ WEB-INF/lib/ttTeamHelper.class.php | 17 ++++++++++ WEB-INF/templates/footer.tpl | 2 +- mysql.sql | 21 +++++++----- 6 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 WEB-INF/lib/ttRoleHelper.class.php diff --git a/WEB-INF/lib/ttExportHelper.class.php b/WEB-INF/lib/ttExportHelper.class.php index 0e116478..cce9246e 100644 --- a/WEB-INF/lib/ttExportHelper.class.php +++ b/WEB-INF/lib/ttExportHelper.class.php @@ -289,6 +289,18 @@ class ttExportHelper { fwrite($file, "\n"); unset($fav_reports); + // Write roles. + fwrite($file, "\n"); + $roles = ttTeamHelper::getRoles($user->team_id); + foreach ($roles as $role) { + fwrite($file, "\t\n"); + fwrite($file, "\t\t\n"); + fwrite($file, "\t\n"); + } + fwrite($file, "\n"); + unset($roles); + // Cleanup. unset($users); $this->userMap = array(); diff --git a/WEB-INF/lib/ttImportHelper.class.php b/WEB-INF/lib/ttImportHelper.class.php index 9b1aad2a..b6c7b8b3 100644 --- a/WEB-INF/lib/ttImportHelper.class.php +++ b/WEB-INF/lib/ttImportHelper.class.php @@ -36,6 +36,7 @@ import('ttClientHelper'); import('ttCustomFieldHelper'); import('ttFavReportHelper'); import('ttExpenseHelper'); +import('ttRoleHelper'); // ttImportHelper - this class is used to import team data from a file. class ttImportHelper { @@ -83,7 +84,8 @@ class ttImportHelper { || $name == 'INVOICE_HEADER' || $name == 'USER_PROJECT_BIND' || $name == 'EXPENSE_ITEM' - || $name == 'FAV_REPORT') { + || $name == 'FAV_REPORT' + || $name == 'ROLE') { $this->currentElement = $attrs; } $this->currentTag = $name; @@ -310,6 +312,15 @@ class ttImportHelper { 'group_by' => $this->currentElement['GROUP_BY'], 'chtotalsonly' => (int) $this->currentElement['SHOW_TOTALS_ONLY'])); } + + if ($name == 'ROLE' && $this->canImport) { + ttRoleHelper::insert(array( + 'team_id' => $this->team_id, + 'name' => $this->currentElement['NAME'], + 'rank' => $this->currentElement['RANK'], + 'rights' => $this->currentElement['RIGHTS'], + 'status' => $this->currentElement['STATUS'])); + } $this->currentTag = ''; } diff --git a/WEB-INF/lib/ttRoleHelper.class.php b/WEB-INF/lib/ttRoleHelper.class.php new file mode 100644 index 00000000..14372288 --- /dev/null +++ b/WEB-INF/lib/ttRoleHelper.class.php @@ -0,0 +1,50 @@ +quote($name).", $rank, ".$mdb2->quote($rights).", ".$mdb2->quote($status).")"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + return true; + } +} diff --git a/WEB-INF/lib/ttTeamHelper.class.php b/WEB-INF/lib/ttTeamHelper.class.php index e88492e5..3b01415e 100644 --- a/WEB-INF/lib/ttTeamHelper.class.php +++ b/WEB-INF/lib/ttTeamHelper.class.php @@ -485,6 +485,23 @@ class ttTeamHelper { return false; } + // getRoles - obtains all roles defined for team. + static function getRoles($team_id) { + $mdb2 = getConnection(); + + $result = array(); + $sql = "select * from tt_roles where team_id = $team_id"; + $res = $mdb2->query($sql); + $result = array(); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $result[] = $val; + } + return $result; + } + return false; + } + // getExpenseItems - obtains all expense items for all users in team. static function getExpenseItems($team_id) { $mdb2 = getConnection(); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index ccc935f2..27ad8494 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.17.28.4007 | Copyright © Anuko | +  Anuko Time Tracker 1.17.28.4008 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/mysql.sql b/mysql.sql index 3c52aefc..8bfc2219 100644 --- a/mysql.sql +++ b/mysql.sql @@ -386,18 +386,23 @@ ALTER TABLE `tt_monthly_quotas` # Structure for table tt_roles. This table stores customized team roles. # CREATE TABLE `tt_roles` ( - `id` int(11) NOT NULL auto_increment, # role id - `team_id` int(11) NOT NULL, # team id - `name` varchar(80) default NULL, # role name - may be used to rename standard roles - `rank` int(11) default 0, # Role rank and identifier in comparison with other roles, - # used to determine what "lesser roles" are - # and also identifies a role within a team, used as role in tt_users. + `id` int(11) NOT NULL auto_increment, # Role id. Identifies roles for all groups on the server. + `team_id` int(11) NOT NULL, # Team id the role is defined for. + `name` varchar(80) default NULL, # Role name - custom role name. In case we are editing a + # predefined role (USER, etc.), we can rename the role here. + `rank` int(11) default 0, # Role rank, an integer value between 0-324. Predefined role ranks: + # USER - 4, CLIENT - 16, COMANAGER - 68, MANAGER - 324. + # Rank is used to determine what "lesser roles" are in each group + # for sutuations such as "manage_users". + # It also identifies a role within a team (by its "rank"). + # Value of rank is to be used in role field in tt_users table, + # just like standard roles now. `rights` text default NULL, # Comma-separated list of rights assigned to a role. # NULL here for predefined roles (4, 16, 68, 324 - manager) # means a hard-coded set of default access rights. - `status` tinyint(4) default 1, # role status + `status` tinyint(4) default 1, # Role status. PRIMARY KEY (`id`) ); -# Create an index that guarantees unique active and inactive role ranks per team. +# Create an index that guarantees unique active and inactive role ranks in each group. create unique index role_idx on tt_roles(team_id, rank, status); -- 2.20.1