示例#1
0
/**
 * Inserts or update a user group.
 * 
 * @param integer $iUserGroupId The _iId of the user group.
 * 
 * @return null
 */
function insertUpdateGroup($iUserGroupId)
{
    global $oUserAccessManager;
    if (empty($_POST) || !wp_verify_nonce($_POST['uamInsertUpdateGroupNonce'], 'uamInsertUpdateGroup')) {
        wp_die(TXT_UAM_NONCE_FAILURE);
    }
    if ($iUserGroupId != null) {
        $oUamUserGroup = $oUserAccessManager->getAccessHandler()->getUserGroups($iUserGroupId);
    } else {
        $oUamUserGroup = new UamUserGroup($oUserAccessManager->getAccessHandler(), null);
    }
    $oUamUserGroup->setGroupName($_POST['userGroupName']);
    $oUamUserGroup->setGroupDesc($_POST['userGroupDescription']);
    $oUamUserGroup->setReadAccess($_POST['readAccess']);
    $oUamUserGroup->setWriteAccess($_POST['writeAccess']);
    $oUamUserGroup->setIpRange($_POST['ipRange']);
    if (isset($_POST['roles'])) {
        $aRoles = $_POST['roles'];
    } else {
        $aRoles = null;
    }
    $oUamUserGroup->unsetObjects('role', true);
    if ($aRoles) {
        foreach ($aRoles as $sRole) {
            $oUamUserGroup->addObject('role', $sRole);
        }
    }
    $oUamUserGroup->save();
    $oUserAccessManager->getAccessHandler()->addUserGroup($oUamUserGroup);
}