- $sql = "update tt_users set role_id = $role_id where id = $this->id and team_id = $this->team_id";
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
+
+ $skipClients = !isset($options['include_clients']);
+ $includeSelf = isset($options['include_self']);
+
+ $select_part = 'select u.id, u.name';
+ if (!isset($options['include_clients'])) $select_part .= ', r.rights';
+
+ $from_part = ' from tt_users u';
+
+ $left_joins = null;
+ if (isset($options['max_rank']) || $skipClients)
+ $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 ($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;
+ $res = $mdb2->query($sql);
+ $user_list = array();
+ if (is_a($res, 'PEAR_Error'))