Source for file grouppermform.php
Documentation is available at grouppermform.php
// $Id: grouppermform.php 981 2007-08-11 14:07:17Z phppp $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000-2003 XOOPS.org //
// <http://www.xoops.org/> //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu) //
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
// Project: The XOOPS Project //
// ------------------------------------------------------------------------- //
die("XOOPS root path not defined");
require_once XOOPS_ROOT_PATH . '/class/xoopsform/formelement.php';
require_once XOOPS_ROOT_PATH . '/class/xoopsform/formhidden.php';
require_once XOOPS_ROOT_PATH . '/class/xoopsform/formbutton.php';
require_once XOOPS_ROOT_PATH . '/class/xoopsform/formelementtray.php';
require_once XOOPS_ROOT_PATH . '/class/xoopsform/form.php';
* Renders a form for setting module specific group permissions
* @author Kazumi Ono <onokazu@myweb.ne.jp>
* @copyright copyright (c) 2000-2003 XOOPS.org
* Tree structure of items
* Description of permission
$this->XoopsForm($title, 'groupperm_form', XOOPS_URL . '/modules/system/admin/groupperm.php', 'post');
* Adds an item to which permission will be assigned
* @param string $itemName
function addItem($itemId, $itemName, $itemParent = 0)
$this->_itemTree[$itemParent]['children'][] = $itemId;
$this->_itemTree[$itemId]['parent'] = $itemParent;
$this->_itemTree[$itemId]['name'] = $itemName;
* Loads all child ids for an item to be used in javascript
function _loadAllChildItemIds($itemId, &$childIds)
if (!empty($this->_itemTree[$itemId]['children'])) {
$first_child = $this->_itemTree[$itemId]['children'];
foreach ($first_child as $fcid) {
if (!empty($this->_itemTree[$fcid]['children'])) {
foreach ($this->_itemTree[$fcid]['children'] as $_fcid) {
$this->_loadAllChildItemIds($_fcid, $childIds);
// load all child ids for javascript codes
$this->_itemTree[$item_id]['allchild'] = array();
$this->_loadAllChildItemIds($item_id, $this->_itemTree[$item_id]['allchild']);
$glist = & $member_handler->getGroupList();
// get selected item id(s) for each group
$selected = $gperm_handler->getItemIds($this->_permName, $i, $this->_modid);
$ret .= "<form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "'" . $this->getExtra() . ">\n<table width='100%' class='outer' cellspacing='1' valign='top'>\n";
} elseif (!$elements[$i]->isHidden()) {
$ret .= "<tr valign='top' align='left'><td class='head'>" . $elements[$i]->getCaption();
if ($elements[$i]->getDescription() != '') {
$ret .= '<br /><br /><span style="font-weight: normal;">' . $elements[$i]->getDescription() . '</span>';
$ret .= "</td>\n<td class='even'>\n" . $elements[$i]->render() . "\n</td></tr>\n";
$hidden .= $elements[$i]->render();
$ret .= "</table>$hidden</form>";
* Renders checkbox options for a group permission form
* @author Kazumi Ono <onokazu@myweb.ne.jp>
* @copyright copyright (c) 2000-2003 XOOPS.org
* Sets pre-selected values
* @param mixed $value A group ID or an array of group IDs
* Sets the tree structure of items
* @param array $optionTree
* Renders checkbox options for this group
$ret = '<table class="outer"><tr><td class="odd"><table><tr>';
foreach ($this->_optionTree[0]['children'] as $topitem) {
$tree = '<td valign="top">';
$this->_renderOptionTree($tree, $this->_optionTree[$topitem], $prefix);
$ret .= '</tr></table></td><td class="even" valign="top">';
$option_ids[] = "'". $this->getName(). '[groups]['. $this->_groupId. ']['. $id. ']'. "'";
$option_ids_str = implode(', ', $option_ids);
$ret .= _ALL. " <input id=\"". $checkallbtn_id. "\" type=\"checkbox\" value=\"\" onclick=\"var optionids = new Array(". $option_ids_str. "); xoopsCheckAllElements(optionids, '". $checkallbtn_id. "');\" />";
$ret .= '</td></tr></table>';
* Renders checkbox options for an item tree
* @param array $parentIds
function _renderOptionTree(&$tree, $option, $prefix, $parentIds = array())
$tree .= $prefix . "<input type=\"checkbox\" name=\"" . $this->getName() . "[groups][" . $this->_groupId . "][" . $option['id'] . "]\" id=\"" . $this->getName() . "[groups][" . $this->_groupId . "][" . $option['id'] . "]\" onclick=\"";
// If there are parent elements, add javascript that will
// make them selecteded when this element is checked to make
// sure permissions to parent items are added as well.
foreach ($parentIds as $pid) {
$parent_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $pid . ']';
$tree .= "var ele = xoopsGetElementById('" . $parent_ele . "'); if(ele.checked != true) {ele.checked = this.checked;}";
// If there are child elements, add javascript that will
// make them unchecked when this element is unchecked to make
// sure permissions to child items are not added when there
// is no permission to this item.
foreach ($option['allchild'] as $cid) {
$child_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $cid . ']';
$tree .= "var ele = xoopsGetElementById('" . $child_ele . "'); if(this.checked != true) {ele.checked = false;}";
$tree .= ' checked="checked"';
$tree .= " />" . $option['name'] . "<input type=\"hidden\" name=\"" . $this->getName() . "[parents][" . $option['id'] . "]\" value=\"" . implode(':', $parentIds). "\" /><input type=\"hidden\" name=\"" . $this->getName() . "[itemname][" . $option['id'] . "]\" value=\"" . htmlspecialchars($option['name']). "\" /><br />\n";
if (isset ($option['children'])) {
foreach ($option['children'] as $child) {
$this->_renderOptionTree($tree, $this->_optionTree[$child], $prefix . ' -', $parentIds);
|