X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=WEB-INF%2Flib%2FttTeamHelper.class.php;h=bbca70e841d495df671a4c1c05a441703067eed4;hb=074e8daef75c2b729e75f350b52935a6b7ecfba8;hp=2ae75923fd4be432a368f2efefb7379b3f9031de;hpb=983bd79a9542306ecbd0f1be372d7006e7b337e1;p=timetracker.git diff --git a/WEB-INF/lib/ttTeamHelper.class.php b/WEB-INF/lib/ttTeamHelper.class.php index 2ae75923..bbca70e8 100644 --- a/WEB-INF/lib/ttTeamHelper.class.php +++ b/WEB-INF/lib/ttTeamHelper.class.php @@ -71,10 +71,11 @@ class ttTeamHelper { // The getActiveUsers obtains all active users in a given team. static function getActiveUsers($options = null) { global $user; + global $i18n; $mdb2 = getConnection(); if (isset($options['getAllFields'])) - $sql = "select * from tt_users where team_id = $user->team_id and status = 1 order by upper(name)"; + $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.team_id = $user->team_id and u.status = 1 order by upper(u.name)"; else $sql = "select id, name from tt_users where team_id = $user->team_id and status = 1 order by upper(name)"; $res = $mdb2->query($sql); @@ -82,6 +83,9 @@ class ttTeamHelper { 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->getKey('role.top_manager.label'); $user_list[] = $val; } @@ -121,7 +125,7 @@ class ttTeamHelper { $mdb2 = getConnection(); if ($all_fields) - $sql = "select * from tt_users where team_id = $team_id and status = 0 order by upper(name)"; + $sql = "select u.*, r.name as role_name from tt_users u left join tt_roles r on (u.role_id = r.id) where u.team_id = $team_id and u.status = 0 order by upper(u.name)"; else $sql = "select id, name from tt_users where team_id = $team_id and status = 0 order by upper(name)"; $res = $mdb2->query($sql); @@ -135,25 +139,6 @@ class ttTeamHelper { return false; } - // The getAllUsers obtains all users in a given team. - static function getAllUsers($team_id, $all_fields = false) { - $mdb2 = getConnection(); - - if ($all_fields) - $sql = "select * from tt_users where team_id = $team_id order by upper(name)"; - else - $sql = "select id, name from tt_users where team_id = $team_id order by upper(name)"; - $res = $mdb2->query($sql); - $result = array(); - if (!is_a($res, 'PEAR_Error')) { - while ($val = $res->fetchRow()) { - $result[] = $val; - } - return $result; - } - return false; - } - // getActiveProjects - returns an array of active projects for team. static function getActiveProjects($team_id) { @@ -263,17 +248,40 @@ class ttTeamHelper { return false; } + // getActiveRolesForUser - returns an array of relevant active roles for user with rank less than self. + // "Relevant" means that client roles are filtered out if Client plugin is disabled. + static function getActiveRolesForUser() + { + global $user; + $result = array(); + $mdb2 = getConnection(); + + $sql = "select id, name, description, rank, rights from tt_roles where team_id = $user->team_id and rank < $user->rank and status = 1 order by rank"; + $res = $mdb2->query($sql); + $result = array(); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $val['is_client'] = in_array('track_own_time', explode(',', $val['rights'])) ? 0 : 1; // Clients do not have data entry right. + if ($val['is_client'] && !$user->isPluginEnabled('cl')) + continue; // Skip adding a client role. + $result[] = $val; + } + } + return $result; + } + // getActiveRoles - returns an array of active roles for team. static function getActiveRoles($team_id) { $result = array(); $mdb2 = getConnection(); - $sql = "select id, name, rights from tt_roles where team_id = $team_id and status = 1 order by upper(name)"; + $sql = "select id, name, description, rank, rights from tt_roles where team_id = $team_id and status = 1 order by rank"; $res = $mdb2->query($sql); $result = array(); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { + $val['is_client'] = in_array('track_own_time', explode(',', $val['rights'])) ? 0 : 1; // Clients do not have data entry right. $result[] = $val; } } @@ -286,12 +294,34 @@ class ttTeamHelper { $result = array(); $mdb2 = getConnection(); - $sql = "select id, name, rights from tt_roles - where team_id = $team_id and status = 0 order by upper(name)"; + $sql = "select id, name, rank, description from tt_roles + where team_id = $team_id and status = 0 order by rank"; + $res = $mdb2->query($sql); + $result = array(); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $result[] = $val; + } + } + return $result; + } + + // getInactiveRolesForUser - returns an array of relevant active roles for user with rank less than self. + // "Relevant" means that client roles are filtered out if Client plugin is disabled. + static function getInactiveRolesForUser() + { + global $user; + $result = array(); + $mdb2 = getConnection(); + + $sql = "select id, name, description, rank, rights from tt_roles where team_id = $user->team_id and rank < $user->rank and status = 0 order by rank"; $res = $mdb2->query($sql); $result = array(); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { + $val['is_client'] = in_array('track_own_time', explode(',', $val['rights'])) ? 0 : 1; // Clients do not have data entry right. + if ($val['is_client'] && !$user->isPluginEnabled('cl')) + continue; // Skip adding a client role. $result[] = $val; } } @@ -369,7 +399,7 @@ class ttTeamHelper { $result = array(); $mdb2 = getConnection(); - if (ROLE_CLIENT == $user->role && $user->client_id) + if ($user->isClient()) $client_part = " and i.client_id = $user->client_id"; $sql = "select i.id, i.name, i.date, i.client_id, i.status, c.name as client_name from tt_invoices i @@ -520,23 +550,6 @@ 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(); @@ -672,10 +685,10 @@ class ttTeamHelper { $result = array(); $mdb2 = getConnection(); - $role_manager = ROLE_MANAGER; $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_teams t - inner join tt_users u on (u.team_id = t.id and u.role = $role_manager) + inner join tt_users u on (u.team_id = t.id) + inner join tt_roles r on (r.id = u.role_id and r.rank = 512) where t.id = $team_id"; $res = $mdb2->query($sql); @@ -1031,7 +1044,7 @@ class ttTeamHelper { static function enablePlugin($plugin, $enable = true) { global $user; - if (!$user->canManageTeam()) + if (!$user->can('manage_features')) return false; $plugin_array = explode(',', $user->plugins);