Skip to content

Commit

Permalink
Remaining bit of refactor by Noostra for usergroups
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11932 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Jan 5, 2012
1 parent 21cb748 commit 76df4ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
25 changes: 7 additions & 18 deletions application/controllers/admin/usergroups.php
Expand Up @@ -355,37 +355,29 @@ function addusertogroup($ugid)
{
Yii::app()->loadHelper('database');
$clang = Yii::app()->lang;
$postuserid = CHttpRequest::getPost('uid');

$addsummary = "<div class=\"header\">".$clang->gT("Adding User to group")."...</div>\n";
$addsummary .= "<div class=\"messagebox\">\n";

$postuserid = CHttpRequest::getPost('uid');
if (Yii::app()->session['USER_RIGHT_SUPERADMIN'] == 1)
{
$query = "SELECT ugid, owner_id FROM {{user_groups}} WHERE ugid = " . $ugid . " AND owner_id = ".Yii::app()->session['loginID']." AND owner_id != ".$postuserid;
$result = db_execute_assoc($query); //Checked
if($result->count() > 0)
{
if(User_groups::model()->isGroupDataValid($ugid, Yii::app()->session['loginID']) && (int)Yii::app()->session['loginID'] != (int)$postuserid)
{
if($postuserid > 0)
if((int)$postuserid > -1)
{
$isrresult = User_in_groups::model()->insert(array('ugid' => $ugid, 'uid' => $postuserid)); //Checked

if($isrresult)
{
$addsummary .= "<div class=\"successheader\">".$clang->gT("User added.")."</div>\n";
list($aViewUrls, $aData) = $this->index($ugid, array("type" => "success", "message" => $clang->gT("User added.")));
}
else // ToDo: for this to happen the keys on the table must still be set accordingly
{
// Username already exists.
$addsummary .= "<div class=\"warningheader\">".$clang->gT("Failed to add user.")."</div>\n" . "<br />" . $clang->gT("Username already exists.")."<br />\n";
list($aViewUrls, $aData) = $this->index($ugid, array("type" => "warning", "message" => $clang->gT("Failed to add user.")."<br />".$clang->gT("Username already exists.")));
}
}
else
{
$addsummary .= "<div class=\"warningheader\">".$clang->gT("Failed to add user.")."</div>\n" . "<br />" . $clang->gT("No Username selected.")."<br />\n";
list($aViewUrls, $aData) = $this->index($ugid, array("type" => "warning", "message" => $clang->gT("Failed to add user.")."<br />".$clang->gT("No username selected.")));
}
$addsummary .= "<br/><input type=\"submit\" onclick=\"window.location='" . $this->getController()->createUrl('admin/usergroups/view/ugid/') . '/' . $ugid . "'\" value=\"".$clang->gT("Continue")."\"/>\n";

}
else
{
Expand All @@ -397,9 +389,6 @@ function addusertogroup($ugid)
die('access denied');
}

$addsummary .= "</div>\n";
$aViewUrls['output'] = $addsummary;

$this->_renderWrappedTemplate($aViewUrls);
}

Expand Down
23 changes: 23 additions & 0 deletions application/models/User_groups.php
Expand Up @@ -211,5 +211,28 @@ function delete($condition)
{
return (bool) $this->db->delete('user_groups', $condition);
}*/

/**
* Verifies that the given groupdata is correct
* @param int $ugid The Usergroup to check
* @param int $ownerid The $ownerid of teh given group to check
* @return bool false if group values do not match, true if they match
* @throws exception Inconsistent database if more then (1) row found
*/
function isGroupDataValid($ugid, $ownerid)
{
if($ownerid)
{
$query = "SELECT ugid, owner_id FROM {{user_groups}} WHERE ugid = " . $ugid . " AND owner_id = ".$ownerid;
}
$result = db_execute_assoc($query);
if ((int)$result->count() == 1)
return true;
elseif ((int)$result->count() == 0)
return false;
else {
throw new Exception("Inconsistent database: More then (1) row with identical ugid and ownerid");
}
}

}

0 comments on commit 76df4ba

Please sign in to comment.