From dacd62b3065d38ddbec624d5b7d7306f0b61dd3a Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 23 Feb 2018 17:24:46 +0000 Subject: [PATCH] Work in progress on roles. --- WEB-INF/lib/ttRoleHelper.class.php | 68 ++++++++++++++++++++++++++++++ WEB-INF/resources/en.lang.php | 12 ++++++ WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/roles.tpl | 2 +- profile_edit.php | 7 +++ 5 files changed, 89 insertions(+), 2 deletions(-) diff --git a/WEB-INF/lib/ttRoleHelper.class.php b/WEB-INF/lib/ttRoleHelper.class.php index 14372288..9abef9df 100644 --- a/WEB-INF/lib/ttRoleHelper.class.php +++ b/WEB-INF/lib/ttRoleHelper.class.php @@ -47,4 +47,72 @@ class ttRoleHelper { return true; } + + // rolesExist - checks whether roles for team already exist. + static function rolesExist() + { + $mdb2 = getConnection(); + global $user; + + $sql = "select count(*) as count from tt_roles where team_id = $user->team_id"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + $val = $res->fetchRow(); + if ($val['count'] > 0) + return true; // Roles for team exist. + } + return false; + } + + // createDefaultRoles - creates a set of predefined roles for the team to use. + static function createDefaultRoles() + { + $mdb2 = getConnection(); + global $i18n; + global $user; + + // Active roles. + $name = $mdb2->quote($i18n->getKey('role.user.label')); + $description = $mdb2->quote($i18n->getKey('role.user.description')); + $rights = $mdb2->quote('data_entry,view_own_data,manage_own_settings,view_users'); + $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($user->team_id, $name, $description, 4, $rights, 1)"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + $name = $mdb2->quote($i18n->getKey('role.client.label')); + $description = $mdb2->quote($i18n->getKey('role.client.description')); + $rights = $mdb2->quote('data_entry,view_own_data,manage_own_settings,view_users'); // TODO: adjust rights. + $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($user->team_id, $name, $description, 16, $rights, 1)"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + $name = $mdb2->quote($i18n->getKey('role.comanager.label')); + $description = $mdb2->quote($i18n->getKey('role.comanager.description')); + $rights = $mdb2->quote('data_entry,view_own_data,manage_own_settings,view_users'); // TODO: adjust rights. + $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($user->team_id, $name, $description, 68, $rights, 1)"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + $name = $mdb2->quote($i18n->getKey('role.manager.label')); + $description = $mdb2->quote($i18n->getKey('role.manager.description')); + $rights = $mdb2->quote('data_entry,view_own_data,manage_own_settings,view_users'); // TODO: adjust rights. + $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($user->team_id, $name, $description, 324, $rights, 1)"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + // Inactive roles. + $name = $mdb2->quote($i18n->getKey('role.supervisor.label')); + $description = $mdb2->quote($i18n->getKey('role.supervisor.description')); + $rights = $mdb2->quote('data_entry,view_own_data,manage_own_settings,view_users'); // TODO: adjust rights. + $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($user->team_id, $name, $description, 12, $rights, 0)"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + return true; + } } diff --git a/WEB-INF/resources/en.lang.php b/WEB-INF/resources/en.lang.php index eae3bb69..43efde70 100644 --- a/WEB-INF/resources/en.lang.php +++ b/WEB-INF/resources/en.lang.php @@ -446,4 +446,16 @@ $i18n_key_words = array( 'form.quota.quota' => 'Quota', 'form.quota.workday_hours' => 'Hours in work day', 'form.quota.hint' => 'If values are empty, quotas are calculated automatically based on workday hours and holidays.', + +// Roles. +'role.user.label' => 'User', +'role.user.description' => 'A regular member without management rights.', +'role.supervisor.label' => 'Supervisor', +'role.supervisor.description' => 'A person with a small set of management rights.', +'role.client.label' => 'Client', +'role.client.description' => 'A client can view its own reports, charts, and invoices.', +'role.comanager.label' => 'Co-manager', +'role.comanager.description' => 'A person with an extended set of management functions, who is helping group manager with most of the work.', +'role.manager.label' => 'Manager', +'role.manager.description' => 'Group manager. Can do most of things for a group.', ); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index baedc2cb..e63b199c 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- - + diff --git a/profile_edit.php b/profile_edit.php index 412dc629..7f024fe8 100644 --- a/profile_edit.php +++ b/profile_edit.php @@ -29,6 +29,7 @@ require_once('initialize.php'); import('form.Form'); import('ttUserHelper'); +import('ttRoleHelper'); // Access check. if (!ttAccessCheck(right_data_entry|right_view_reports)) { @@ -299,6 +300,12 @@ if ($request->isPost()) { $plugins = trim($plugins, ','); + // If we use roles... No, we'll do it differently. + /* + if ($cl_roles && !ttRoleHelper::rolesExist()) { + ttRoleHelper::createDefaultRoles(); + }*/ + // Prepare config string. if ($cl_roles) $config .= ',roles'; -- 2.20.1
 Anuko Time Tracker 1.17.30.4017 | Copyright © Anuko | +  Anuko Time Tracker 1.17.30.4018 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/roles.tpl b/WEB-INF/templates/roles.tpl index 51c8d99e..ead3ad3e 100644 --- a/WEB-INF/templates/roles.tpl +++ b/WEB-INF/templates/roles.tpl @@ -47,7 +47,7 @@ {foreach $inactive_roles as $role}
{$role.name|escape}{$role.rights|escape}{$role.description|escape} {$i18n.label.edit} {$i18n.label.delete}