X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttUser.class.php;h=5321e74d941d35b6250c0c5aa7b18d5fb255bd07;hb=9f4ffc38746c7d23beb7b48ba342dd0cc8e8b19a;hp=95edd6e48f9dd6dcbfa46476d4093c0955c15e47;hpb=68a5cc5aff88d6144b6db95f7d01315c15e2ebda;p=timetracker.git diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index 95edd6e4..5321e74d 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -251,12 +251,14 @@ 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"; @@ -295,4 +297,36 @@ class ttUser { } return $user_list; } + + // checkBehalfId checks whether behalf_id is appropriate. + // On behalf user must be active and have lower rank. + function checkBehalfId() { + $options = array('status'=>ACTIVE,'max_rank'=>$this->rank-1); + $users = $this->getUsers($options); + foreach($users as $one_user) { + if ($one_user['id'] == $this->behalf_id) + return true; + } + return false; + } + + // adjustBehalfId attempts to adjust behalf_id and behalf_name to a first found + // apropriate user. + // + // 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() { + $options = array('status'=>ACTIVE,'max_rank'=>$this->rank-1); + $users = $this->getUsers($options); + foreach($users as $one_user) { + // Fake loop to access first element. + $this->behalf_id = $one_user['id']; + $this->behalf_name = $one_user['name']; + $_SESSION['behalf_id'] = $this->behalf_id; + $_SESSION['behalf_name'] = $this->behalf_name; + return true; + } + return false; + } }