| [ Index ] |
|
Code source de XOOPS 2.0.17.1 |
1 <?php 2 // $Id: grouppermform.php 981 2007-08-11 14:07:17Z phppp $ 3 // ------------------------------------------------------------------------ // 4 // XOOPS - PHP Content Management System // 5 // Copyright (c) 2000-2003 XOOPS.org // 6 // <http://www.xoops.org/> // 7 // ------------------------------------------------------------------------ // 8 // This program is free software; you can redistribute it and/or modify // 9 // it under the terms of the GNU General Public License as published by // 10 // the Free Software Foundation; either version 2 of the License, or // 11 // (at your option) any later version. // 12 // // 13 // You may not change or alter any portion of this comment or credits // 14 // of supporting developers from this source code or any supporting // 15 // source code which is considered copyrighted (c) material of the // 16 // original comment or credit authors. // 17 // // 18 // This program is distributed in the hope that it will be useful, // 19 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 21 // GNU General Public License for more details. // 22 // // 23 // You should have received a copy of the GNU General Public License // 24 // along with this program; if not, write to the Free Software // 25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // 26 // ------------------------------------------------------------------------ // 27 // Author: Kazumi Ono (AKA onokazu) // 28 // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ // 29 // Project: The XOOPS Project // 30 // ------------------------------------------------------------------------- // 31 if (!defined('XOOPS_ROOT_PATH')) { 32 die("XOOPS root path not defined"); 33 } 34 require_once XOOPS_ROOT_PATH . '/class/xoopsform/formelement.php'; 35 require_once XOOPS_ROOT_PATH . '/class/xoopsform/formhidden.php'; 36 require_once XOOPS_ROOT_PATH . '/class/xoopsform/formbutton.php'; 37 require_once XOOPS_ROOT_PATH . '/class/xoopsform/formelementtray.php'; 38 require_once XOOPS_ROOT_PATH . '/class/xoopsform/form.php'; 39 40 /** 41 * Renders a form for setting module specific group permissions 42 * 43 * @author Kazumi Ono <onokazu@myweb.ne.jp> 44 * @copyright copyright (c) 2000-2003 XOOPS.org 45 * @package kernel 46 * @subpackage form 47 */ 48 class XoopsGroupPermForm extends XoopsForm 49 { 50 /** 51 * Module ID 52 * 53 * @var int 54 */ 55 var $_modid; 56 /** 57 * Tree structure of items 58 * 59 * @var array 60 */ 61 var $_itemTree; 62 /** 63 * Name of permission 64 * 65 * @var string 66 */ 67 var $_permName; 68 /** 69 * Description of permission 70 * 71 * @var string 72 */ 73 var $_permDesc; 74 75 /** 76 * Constructor 77 */ 78 function XoopsGroupPermForm($title, $modid, $permname, $permdesc, $url = "") 79 { 80 $this->XoopsForm($title, 'groupperm_form', XOOPS_URL . '/modules/system/admin/groupperm.php', 'post'); 81 $this->_modid = intval($modid); 82 $this->_permName = $permname; 83 $this->_permDesc = $permdesc; 84 $this->addElement(new XoopsFormHidden('modid', $this->_modid)); 85 if ($url != "") { 86 $this->addElement(new XoopsFormHidden('redirect_url', $url)); 87 } 88 } 89 90 /** 91 * Adds an item to which permission will be assigned 92 * 93 * @param string $itemName 94 * @param int $itemId 95 * @param int $itemParent 96 * @access public 97 */ 98 function addItem($itemId, $itemName, $itemParent = 0) 99 { 100 $this->_itemTree[$itemParent]['children'][] = $itemId; 101 $this->_itemTree[$itemId]['parent'] = $itemParent; 102 $this->_itemTree[$itemId]['name'] = $itemName; 103 $this->_itemTree[$itemId]['id'] = $itemId; 104 } 105 106 /** 107 * Loads all child ids for an item to be used in javascript 108 * 109 * @param int $itemId 110 * @param array $childIds 111 * @access private 112 */ 113 function _loadAllChildItemIds($itemId, &$childIds) 114 { 115 if (!empty($this->_itemTree[$itemId]['children'])) { 116 $first_child = $this->_itemTree[$itemId]['children']; 117 foreach ($first_child as $fcid) { 118 array_push($childIds, $fcid); 119 if (!empty($this->_itemTree[$fcid]['children'])) { 120 foreach ($this->_itemTree[$fcid]['children'] as $_fcid) { 121 array_push($childIds, $_fcid); 122 $this->_loadAllChildItemIds($_fcid, $childIds); 123 } 124 } 125 } 126 } 127 } 128 129 /** 130 * Renders the form 131 * 132 * @return string 133 * @access public 134 */ 135 function render() 136 { 137 // load all child ids for javascript codes 138 foreach (array_keys($this->_itemTree)as $item_id) { 139 $this->_itemTree[$item_id]['allchild'] = array(); 140 $this->_loadAllChildItemIds($item_id, $this->_itemTree[$item_id]['allchild']); 141 } 142 $gperm_handler =& xoops_gethandler('groupperm'); 143 $member_handler =& xoops_gethandler('member'); 144 $glist =& $member_handler->getGroupList(); 145 foreach (array_keys($glist) as $i) { 146 // get selected item id(s) for each group 147 $selected = $gperm_handler->getItemIds($this->_permName, $i, $this->_modid); 148 $ele = new XoopsGroupFormCheckBox($glist[$i], 'perms[' . $this->_permName . ']', $i, $selected); 149 $ele->setOptionTree($this->_itemTree); 150 $this->addElement($ele); 151 unset($ele); 152 } 153 $tray = new XoopsFormElementTray(''); 154 $tray->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit')); 155 $tray->addElement(new XoopsFormButton('', 'reset', _CANCEL, 'reset')); 156 $this->addElement($tray); 157 $ret = '<h4>' . $this->getTitle() . '</h4>' . $this->_permDesc . '<br />'; 158 $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"; 159 $elements = $this->getElements(); 160 $hidden = ''; 161 foreach (array_keys($elements) as $i) { 162 if (!is_object($elements[$i])) { 163 $ret .= $elements[$i]; 164 } elseif (!$elements[$i]->isHidden()) { 165 $ret .= "<tr valign='top' align='left'><td class='head'>" . $elements[$i]->getCaption(); 166 if ($elements[$i]->getDescription() != '') { 167 $ret .= '<br /><br /><span style="font-weight: normal;">' . $elements[$i]->getDescription() . '</span>'; 168 } 169 $ret .= "</td>\n<td class='even'>\n" . $elements[$i]->render() . "\n</td></tr>\n"; 170 } else { 171 $hidden .= $elements[$i]->render(); 172 } 173 } 174 $ret .= "</table>$hidden</form>"; 175 $ret .= $this->renderValidationJS( true ); 176 return $ret; 177 } 178 } 179 180 /** 181 * Renders checkbox options for a group permission form 182 * 183 * @author Kazumi Ono <onokazu@myweb.ne.jp> 184 * @copyright copyright (c) 2000-2003 XOOPS.org 185 * @package kernel 186 * @subpackage form 187 */ 188 class XoopsGroupFormCheckBox extends XoopsFormElement 189 { 190 /** 191 * Pre-selected value(s) 192 * 193 * @var array; 194 */ 195 var $_value = array(); 196 /** 197 * Group ID 198 * 199 * @var int 200 */ 201 var $_groupId; 202 /** 203 * Option tree 204 * 205 * @var array 206 */ 207 var $_optionTree; 208 209 /** 210 * Constructor 211 */ 212 function XoopsGroupFormCheckBox($caption, $name, $groupId, $values = null) 213 { 214 $this->setCaption($caption); 215 $this->setName($name); 216 if (isset($values)) { 217 $this->setValue($values); 218 } 219 $this->_groupId = $groupId; 220 } 221 222 /** 223 * Sets pre-selected values 224 * 225 * @param mixed $value A group ID or an array of group IDs 226 * @access public 227 */ 228 function setValue($value) 229 { 230 if (is_array($value)) { 231 foreach ($value as $v) { 232 $this->setValue($v); 233 } 234 } else { 235 $this->_value[] = $value; 236 } 237 } 238 239 /** 240 * Sets the tree structure of items 241 * 242 * @param array $optionTree 243 * @access public 244 */ 245 function setOptionTree(&$optionTree) 246 { 247 $this->_optionTree =& $optionTree; 248 } 249 250 /** 251 * Renders checkbox options for this group 252 * 253 * @return string 254 * @access public 255 */ 256 function render() 257 { 258 $ret = '<table class="outer"><tr><td class="odd"><table><tr>'; 259 $cols = 1; 260 foreach ($this->_optionTree[0]['children'] as $topitem) { 261 if ($cols > 4) { 262 $ret .= '</tr><tr>'; 263 $cols = 1; 264 } 265 $tree = '<td valign="top">'; 266 $prefix = ''; 267 $this->_renderOptionTree($tree, $this->_optionTree[$topitem], $prefix); 268 $ret .= $tree.'</td>'; 269 $cols++; 270 } 271 $ret .= '</tr></table></td><td class="even" valign="top">'; 272 foreach (array_keys($this->_optionTree) as $id) { 273 if (!empty($id)) { 274 $option_ids[] = "'".$this->getName().'[groups]['.$this->_groupId.']['.$id.']'."'"; 275 } 276 } 277 $checkallbtn_id = $this->getName().'[checkallbtn]['.$this->_groupId.']'; 278 $option_ids_str = implode(', ', $option_ids); 279 $ret .= _ALL." <input id=\"".$checkallbtn_id."\" type=\"checkbox\" value=\"\" onclick=\"var optionids = new Array(".$option_ids_str."); xoopsCheckAllElements(optionids, '".$checkallbtn_id."');\" />"; 280 $ret .= '</td></tr></table>'; 281 return $ret; 282 } 283 284 /** 285 * Renders checkbox options for an item tree 286 * 287 * @param string $tree 288 * @param array $option 289 * @param string $prefix 290 * @param array $parentIds 291 * @access private 292 */ 293 function _renderOptionTree(&$tree, $option, $prefix, $parentIds = array()) 294 { 295 $tree .= $prefix . "<input type=\"checkbox\" name=\"" . $this->getName() . "[groups][" . $this->_groupId . "][" . $option['id'] . "]\" id=\"" . $this->getName() . "[groups][" . $this->_groupId . "][" . $option['id'] . "]\" onclick=\""; 296 // If there are parent elements, add javascript that will 297 // make them selecteded when this element is checked to make 298 // sure permissions to parent items are added as well. 299 foreach ($parentIds as $pid) { 300 $parent_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $pid . ']'; 301 $tree .= "var ele = xoopsGetElementById('" . $parent_ele . "'); if(ele.checked != true) {ele.checked = this.checked;}"; 302 } 303 // If there are child elements, add javascript that will 304 // make them unchecked when this element is unchecked to make 305 // sure permissions to child items are not added when there 306 // is no permission to this item. 307 foreach ($option['allchild'] as $cid) { 308 $child_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $cid . ']'; 309 $tree .= "var ele = xoopsGetElementById('" . $child_ele . "'); if(this.checked != true) {ele.checked = false;}"; 310 } 311 $tree .= '" value="1"'; 312 if (in_array($option['id'], $this->_value)) { 313 $tree .= ' checked="checked"'; 314 } 315 $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"; 316 if (isset($option['children'])) { 317 foreach ($option['children'] as $child) { 318 array_push($parentIds, $option['id']); 319 $this->_renderOptionTree($tree, $this->_optionTree[$child], $prefix . ' -', $parentIds); 320 } 321 } 322 } 323 } 324 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Nov 25 11:44:32 2007 | par Balluche grâce à PHPXref 0.7 |
|