diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php index 419c54f158e..42c2448df10 100644 --- a/application/helpers/common_helper.php +++ b/application/helpers/common_helper.php @@ -674,43 +674,30 @@ function getUserList($outputformat = 'fullinfoarray') $usercontrolSameGroupPolicy == true ) { if (isset($myuid)) { - $sDatabaseType = Yii::app()->db->getDriverName(); - if ($sDatabaseType == 'mssql' || $sDatabaseType == "sqlsrv" || $sDatabaseType == "dblib") { - $sSelectFields = 'users_name,uid,email,full_name,parent_id,CAST(password as varchar) as password'; - } else { - $sSelectFields = 'users_name,uid,email,full_name,parent_id,password'; - } - - // List users from same group as me + all my childs - // a subselect is used here because MSSQL does not like to group by text - // also Postgres does like this one better - $uquery = " SELECT {$sSelectFields} from {{users}} where uid in ( - SELECT uid from {{user_in_groups}} where ugid in ( - SELECT ugid from {{user_in_groups}} where uid={$myuid} - ) - ) - UNION - SELECT {$sSelectFields} from {{users}} v where v.parent_id={$myuid} - UNION - SELECT {$sSelectFields} from {{users}} v where uid={$myuid}"; + $userGroupList = getUserGroupList(); + $criteria = new CDBCriteria(); + $criteria->order = 'full_name, users_name, t.uid'; + $criteria->with = 'groups'; + /* users in usergroup */ + $criteria->addInCondition('groups.ugid', $userGroupList); + /* childs of this user */ + $criteria->compare('parent_id', $myuid, false, 'OR'); + /* himself */ + $criteria->compare('t.uid', $myuid, false, 'OR'); + $oUsers = User::model()->findAll($criteria); } else { return array(); // Or die maybe } } else { - $uquery = "SELECT * FROM {{users}} ORDER BY uid"; - } - - $uresult = Yii::app()->db->createCommand($uquery)->query()->readAll(); //Checked - - if (count($uresult) == 0 && !empty($myuid)) { -//user is not in a group and usercontrolSameGroupPolicy is activated - at least show their own userinfo - $uquery = "SELECT u.* FROM {{users}} AS u WHERE u.uid=" . $myuid; - $uresult = Yii::app()->db->createCommand($uquery)->query()->readAll(); //Checked + $oUsers = User::model()->findAll([ + 'order' => 'full_name, users_name, t.uid' + ]); } $userlist = array(); $userlist[0] = "Reserved for logged in user"; - foreach ($uresult as $srow) { + foreach ($oUsers as $oUser) { + $srow = $oUser->getAttributes(); if ($outputformat != 'onlyuidarray') { if ($srow['uid'] != Yii::app()->session['loginID']) { $userlist[] = array( @@ -4205,7 +4192,8 @@ function getUserGroupList() $sQuery = "SELECT distinct a.ugid, a.name, a.owner_id FROM {{user_groups}} AS a LEFT JOIN {{user_in_groups}} AS b ON a.ugid = b.ugid WHERE 1=1 "; if (shouldFilterUserGroupList()) { $userid = intval(App()->session['loginID']); - $sQuery .= "AND (b.uid = {$userid})"; + $sQuery .= " AND (b.uid = {$userid})"; + $sQuery .= " OR (a.owner_id = {$userid})"; } $sQuery .= " ORDER BY name";