Ejemplo n.º 1
0
        echo sprintf('Session variable not set. Setting as: %s', $var) . '<br />';
        $sessionHelper->set('fred', $var);
    }
}
echo '<h2>Permission demo</h2>';
$permissionHelper = new Permission();
if ($permissionHelper) {
    // this is the name and item we are going to work with
    $permissionName = 'fred';
    $permissionItemId = 1;
    // if this is a post operation get the input and save it
    if ('POST' === Request::getMethod()) {
        echo $xoops->alert('success', 'Permission updated');
        // save the data
        $name = $permissionHelper->defaultFieldName($permissionName, $permissionItemId);
        $groups = Request::getVar($name, array(), 'POST');
        $permissionHelper->savePermissionForItem($permissionName, $permissionItemId, $groups);
    }
    // build a form for our permission
    $form = new Xoops\Form\ThemeForm("Permission Form (for the permission named '{$permissionName}')", 'form', '', 'POST');
    $groupElement = $permissionHelper->getGroupSelectFormForItem($permissionName, $permissionItemId, "Groups with '{$permissionName}' permission", null, true);
    $form->addElement($groupElement);
    $form->addElement(new Xoops\Form\Button('', 'submit', 'Save', 'submit'));
    echo $form->render();
    // check it the current user has the permission
    if ($permissionHelper->checkPermission($permissionName, $permissionItemId)) {
        echo "<p>You have the <strong>'{$permissionName}'</strong> permission for the 'codex' module.</p>";
    } else {
        echo "<p>You <em>DO NOT</em> have the <strong>'{$permissionName}'</strong> " . "permission for the 'codex' module.</p>";
    }
}