X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/2ff04a2baeaa449ab30b822e2bb52ff792776753..dfc50841cd4b60eb8f2172044d6dd08785fe3df4:/WEB-INF/lib/ttUser.class.php diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index 85b26d51..f9edc8cc 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -251,23 +251,30 @@ class ttUser { $includeSelf = isset($options['include_self']); $select_part = 'select u.id, u.name'; + if (isset($options['include_login'])) $select_part .= ', u.login'; if (!isset($options['include_clients'])) $select_part .= ', r.rights'; + if (isset($options['include_role'])) $select_part .= ', r.name as role_name, r.rank'; $from_part = ' from tt_users u'; $left_joins = null; - if (isset($options['max_rank']) || $skipClients) + if (isset($options['max_rank']) || $skipClients || isset($options['include_role'])) $left_joins .= ' left join tt_roles r on (u.role_id = r.id)'; $where_part = " where u.team_id = $this->team_id"; - if (isset($options['status'])) $where_part .= ' and u.status = '.(int)$options['status']; + if (isset($options['status'])) + $where_part .= ' and u.status = '.(int)$options['status']; + else + $where_part .= ' and u.status is not null'; if ($includeSelf) { $where_part .= " and (u.id = $this->id || r.rank <= ".(int)$options['max_rank'].')'; } else { if (isset($options['max_rank'])) $where_part .= ' and r.rank <= '.(int)$options['max_rank']; } - $sql = $select_part.$from_part.$left_joins.$where_part; + $order_part = " order by upper(u.name)"; + + $sql = $select_part.$from_part.$left_joins.$where_part.$order_part; $res = $mdb2->query($sql); $user_list = array(); if (is_a($res, 'PEAR_Error')) @@ -296,6 +303,25 @@ class ttUser { return $user_list; } + // getUser function is used to manage users in group and returns user details. + // At the moment, the function is used for user edits and deletes. + function getUser($user_id) { + if (!$this->can('manage_users')) return false; + + $mdb2 = getConnection(); + + $sql = "select u.id, u.name, u.login, u.role_id, u.status, u.rate, u.email from tt_users u". + " left join tt_roles r on (u.role_id = r.id)". + " where u.id = $user_id and u.team_id = $this->team_id and u.status is not null". + " and (r.rank < $this->rank or (r.rank = $this->rank and u.id = $this->id))"; // Users with lesser roles or self. + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + $val = $res->fetchRow(); + return $val; + } + return false; + } + // checkBehalfId checks whether behalf_id is appropriate. // On behalf user must be active and have lower rank. function checkBehalfId() { @@ -305,14 +331,13 @@ class ttUser { if ($one_user['id'] == $this->behalf_id) return true; } - return false; } // adjustBehalfId attempts to adjust behalf_id and behalf_name to a first found - // aapropriate user. + // apropriate user. // - // Needed for situations when use does not have do_own_something right. + // Needed for situations when user does not have do_own_something right. // Example: has view_charts but does not have view_own_charts. // In this case we still allow access to charts, but set behalf_id to someone else. function adjustBehalfId() {