XOOPS  2.6.0
GroupPermissionForm.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
12 namespace Xoops\Form;
13 
15 
28 {
34  private $modid;
35 
41  private $itemTree = array();
42 
48  private $permName;
49 
55  private $permDesc;
56 
62  private $showAnonymous;
63 
74  public function __construct($title, $modid, $permname, $permdesc, $url = '', $anonymous = true)
75  {
76  parent::__construct($title, 'groupperm_form', XOOPS_URL . '/modules/system/admin/groupperm.php', 'post');
77  $this->modid = intval($modid);
78  $this->permName = $permname;
79  $this->permDesc = $permdesc;
80  $this->addElement(new Hidden('modid', $this->modid));
81  $this->addElement(new Token($permname));
82  if ($url != "") {
83  $this->addElement(new Hidden('redirect_url', $url));
84  }
85  $this->showAnonymous = $anonymous;
86  }
87 
97  public function addItem($itemId, $itemName, $itemParent = 0)
98  {
99  $this->itemTree[$itemParent]['children'][] = $itemId;
100  $this->itemTree[$itemId]['parent'] = $itemParent;
101  $this->itemTree[$itemId]['name'] = $itemName;
102  $this->itemTree[$itemId]['id'] = $itemId;
103  }
104 
113  private function loadAllChildItemIds($itemId, &$childIds)
114  {
115  if (!empty($this->itemTree[$itemId]['children'])) {
116  $children = $this->itemTree[$itemId]['children'];
117  foreach ($children as $fcid) {
118  array_push($childIds, $fcid);
119  $this->loadAllChildItemIds($fcid, $childIds);
120  }
121  }
122  }
123 
130  public function render()
131  {
133  // load all child ids for javascript codes
134  foreach (array_keys($this->itemTree) as $item_id) {
135  $this->itemTree[$item_id]['allchild'] = array();
136  $this->loadAllChildItemIds($item_id, $this->itemTree[$item_id]['allchild']);
137  }
138  $gperm_handler = $xoops->getHandlerGroupperm();
139  $member_handler = $xoops->getHandlerMember();
140  $glist = $member_handler->getGroupList();
141  foreach (array_keys($glist) as $i) {
142  if ($i == FixedGroups::ANONYMOUS && !$this->showAnonymous) {
143  continue;
144  }
145  // get selected item id(s) for each group
146  $selected = $gperm_handler->getItemIds($this->permName, $i, $this->modid);
147  $ele = new GroupFormCheckbox($glist[$i], 'perms[' . $this->permName . ']', $i, $selected);
148  $ele->setOptionTree($this->itemTree);
149  $this->addElement($ele);
150  unset($ele);
151  }
152  $tray = new ElementTray('');
153  $tray->addElement(new Button('', 'submit', \XoopsLocale::A_SUBMIT, 'submit'));
154  $tray->addElement(new Button('', 'reset', \XoopsLocale::A_CANCEL, 'reset'));
155  $this->addElement($tray);
156 
157  $ret = '<h4>' . $this->getTitle() . '</h4>';
158  if ($this->permDesc) {
159  $ret .= $this->permDesc . '<br /><br />';
160  }
161  $ret .= '<form title="' . str_replace('"', '', $this->getTitle()) . '" name="'
162  . $this->getName() . '" id="' . $this->getName() . '" action="' . $this->getAction()
163  . '" method="' . $this->getMethod() . '"' . $this->getExtra() . '>'
164  . '<table width="100%" class="outer" cellspacing="1" valign="top">';
165  $elements = $this->getElements();
166  $hidden = '';
167  foreach (array_keys($elements) as $i) {
168  if ($elements[$i] instanceof Raw) {
169  $ret .= $elements[$i]->render();
170  } elseif (!$elements[$i]->isHidden()) {
171  $ret .= '<tr valign="top" align="left"><td class="head">' . $elements[$i]->getCaption();
172  if ($elements[$i]->getDescription() != "") {
173  $ret .= "<br /><br /><span style='font-weight: normal;'>"
174  . $elements[$i]->getDescription() . "</span>";
175  }
176  $ret .= '</td>' . '<td class="even">' . $elements[$i]->render() . '</td></tr>' . '';
177  } else {
178  $hidden .= $elements[$i]->render();
179  }
180  }
181  $ret .= '</table>' . $hidden . '</form>';
182  $ret .= $this->renderValidationJS(true);
183  return $ret;
184  }
185 }
const A_SUBMIT
Definition: en_US.php:128
if($uname== ''||$pass== '') $member_handler
Definition: checklogin.php:44
$i
Definition: dialog.php:68
static getInstance()
Definition: Xoops.php:160
addElement(Element $formElement, $required=false)
Definition: Form.php:206
getAction($encode=true)
Definition: Form.php:182
addItem($itemId, $itemName, $itemParent=0)
$gperm_handler
loadAllChildItemIds($itemId, &$childIds)
$xoops
Definition: admin.php:25
getName($encode=true)
Definition: Form.php:158
const A_CANCEL
Definition: en_US.php:82
getTitle($encode=false)
Definition: Form.php:132
getElements($recurse=false)
Definition: Form.php:232
__construct($title, $modid, $permname, $permdesc, $url= '', $anonymous=true)
$url
Definition: register.php:72
renderValidationJS($withtags=true)
Definition: Form.php:471