| 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 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @copyright    XOOPS Project https://xoops.org/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @license      GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @package | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @since | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @author       XOOPS Development Team, Kazumi Ono (AKA onokazu) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | require_once XOOPS_ROOT_PATH . '/class/xoopsform/formelement.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | require_once XOOPS_ROOT_PATH . '/class/xoopsform/formhidden.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | require_once XOOPS_ROOT_PATH . '/class/xoopsform/formhiddentoken.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | require_once XOOPS_ROOT_PATH . '/class/xoopsform/formbutton.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | require_once XOOPS_ROOT_PATH . '/class/xoopsform/formelementtray.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | require_once XOOPS_ROOT_PATH . '/class/xoopsform/form.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * Renders a form for setting module specific group permissions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * @author       Kazumi Ono    <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * @copyright    copyright (c) 2000-2003 XOOPS.org | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  * @package      kernel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  * @subpackage   form | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 37 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | class MyXoopsGroupPermForm extends \XoopsForm | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * Module ID | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      * @var int | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |     public $_modid; | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |      * Tree structure of items | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |      * @var array | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     public $_itemTree = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      * Name of permission | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      * @var string | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |     public $_permName; | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |      * Description of permission | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      * @var string | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     public $_permDesc; | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |      * Appendix | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |      * @var array ('permname'=>,'itemid'=>,'itemname'=>,'selected'=>) | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |     public $_appendix = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |      * Constructor | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |      * @param string $title | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |      * @param string $modid | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |      * @param string $permname | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |      * @param string $permdesc | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     public function __construct($title, $modid, $permname, $permdesc) | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |         //      $this->XoopsForm($title, 'groupperm_form', XOOPS_URL.'/modules/system/admin/groupperm.php', 'post'); GIJ | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |         parent::__construct($title, 'groupperm_form', '', 'post'); | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |         $this->_modid    = (int)$modid; | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |         $this->_permName = $permname; | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |         $this->_permDesc = $permdesc; | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |         $this->addElement(new \XoopsFormHidden('modid', $this->_modid)); | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |         $this->addElement(new \XoopsFormHiddenToken($permname)); | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |      * Adds an item to which permission will be assigned | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |      * @param string $itemName | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |      * @param int    $itemId | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |      * @param int    $itemParent | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |      * @access public | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |     public 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 |  |  |      * Add appendix | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |      * @access public | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |      * @param $permName | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |      * @param $itemId | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |      * @param $itemName | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |     public function addAppendix($permName, $itemId, $itemName) | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |         $this->_appendix[] = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |             'permname' => $permName, | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |             'itemid'   => $itemId, | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |             'itemname' => $itemName, | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |             'selected' => false, | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |      * Loads all child ids for an item to be used in javascript | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |      * @param int   $itemId | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |      * @param array $childIds | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |      * @access private | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |     public function _loadAllChildItemIds($itemId, &$childIds) | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |         if (!empty($this->_itemTree[$itemId]['children'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |             $first_child = $this->_itemTree[$itemId]['children']; | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |             foreach ($first_child as $fcid) { | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |                 $childIds[] = $fcid; | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |                 if (!empty($this->_itemTree[$fcid]['children'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |                     foreach ($this->_itemTree[$fcid]['children'] as $_fcid) { | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |                         $childIds[] = $_fcid; | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |                         $this->_loadAllChildItemIds($_fcid, $childIds); | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |                     } | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |      * Renders the form | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |      * @access public | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     public function render() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         // load all child ids for javascript codes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         foreach (array_keys($this->_itemTree) as $item_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             $this->_itemTree[$item_id]['allchild'] = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             $this->_loadAllChildItemIds($item_id, $this->_itemTree[$item_id]['allchild']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         $grouppermHandler = xoops_getHandler('groupperm'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         $memberHandler    = xoops_getHandler('member'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         $glist            = $memberHandler->getGroupList(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         foreach (array_keys($glist) as $i) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             // get selected item id(s) for each group | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |             $selected = $grouppermHandler->getItemIds($this->_permName, $i, $this->_modid); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |             $ele      = new MyXoopsGroupFormCheckBox($glist[$i], 'perms[' . $this->_permName . ']', $i, $selected); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             $ele->setOptionTree($this->_itemTree); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |             foreach ($this->_appendix as $key => $append) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |                 $this->_appendix[$key]['selected'] = $grouppermHandler->checkRight($append['permname'], $append['itemid'], $i, $this->_modid); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |             $ele->setAppendix($this->_appendix); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |             $this->addElement($ele); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |             unset($ele); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         // GIJ start | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |         $jstray          = new \XoopsFormElementTray('   '); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         $jsuncheckbutton = new \XoopsFormButton('', 'none', _NONE, 'button'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |         $jsuncheckbutton->setExtra("onclick=\"with(document.groupperm_form){for (i=0;i<length;i++) {if (elements[i].type=='checkbox') {elements[i].checked=false;}}}\""); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         $jscheckbutton = new \XoopsFormButton('', 'all', _ALL, 'button'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         $jscheckbutton->setExtra("onclick=\"with(document.groupperm_form){for (i=0;i<length;i++) {if(elements[i].type=='checkbox' && (elements[i].name.indexOf('module_admin')<0 || elements[i].name.indexOf('[groups][1]')>=0)) {elements[i].checked=true;}}}\""); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         $jstray->addElement($jsuncheckbutton); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         $jstray->addElement($jscheckbutton); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         $this->addElement($jstray); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         // GIJ end | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         $tray = new \XoopsFormElementTray(''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         $tray->addElement(new \XoopsFormButton('', 'reset', _CANCEL, 'reset')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |         $tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |         $this->addElement($tray); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |         $ret      = '<h4>' . $this->getTitle() . '</h4>' . $this->_permDesc . '<br>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         $ret      .= "<form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "'" . $this->getExtra() . ">\n<table width='100%' class='outer' cellspacing='1'>\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         $elements = &$this->getElements(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         foreach (array_keys($elements) as $i) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |             if (!is_object($elements[$i])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |                 $ret .= $elements[$i]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |             } elseif ($elements[$i]->isHidden()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |                 $ret .= $elements[$i]->render(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |                 $ret .= "<tr valign='top' style='text-align: left;'><td class='head'>" . $elements[$i]->getCaption(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |                 if ('' !== $elements[$i]->getDescription()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |                     $ret .= '<br><br><span style="font-weight: normal;">' . $elements[$i]->getDescription() . '</span>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |                 $ret .= "</td>\n<td class='even'>\n" . $elements[$i]->render() . "\n</td></tr>\n"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |         $ret .= '</table>' . $GLOBALS['xoopsSecurity']->getTokenHTML() . '</form>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 212 |  |  |         return $ret; | 
            
                                                                        
                                                                
            
                                    
            
            
                | 213 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 214 |  |  | } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 215 |  |  |  | 
            
                                                                        
                                                                
            
                                    
            
            
                | 216 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |  * Renders checkbox options for a group permission form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |  * @author       Kazumi Ono    <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |  * @copyright    copyright (c) 2000-2003 XOOPS.org | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |  * @package      kernel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |  * @subpackage   form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | class MyXoopsGroupFormCheckBox extends \XoopsFormElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |      * Pre-selected value(s) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |      * @var array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |     public $_value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |      * Group ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |      * @var int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |     public $_groupId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |      * Option tree | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |     public $_optionTree; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |      * Appendix | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |      * @var array ('permname'=>,'itemid'=>,'itemname'=>,'selected'=>) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |     public $_appendix = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |      * Constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |      * @param      $caption | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |      * @param      $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |      * @param      $groupId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |      * @param null $values | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |     public function __construct($caption, $name, $groupId, $values = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |         $this->setCaption($caption); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |         $this->setName($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |         if (isset($values)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |             $this->setValue($values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |         $this->_groupId = $groupId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |      * Sets pre-selected values | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |      * @param mixed $value A group ID or an array of group IDs | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |     public function setValue($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         if (is_array($value)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |             foreach ($value as $v) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |                 $this->setValue($v); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |             $this->_value[] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |      * Sets the tree structure of items | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |      * @param array $optionTree | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |     public function setOptionTree(&$optionTree) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |         $this->_optionTree = &$optionTree; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |      * Sets appendix of checkboxes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |      * @param $appendix | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |     public function setAppendix($appendix) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |         $this->_appendix = $appendix; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |      * Renders checkbox options for this group | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |     public function render() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |         $ret = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |         if (count($this->_appendix) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |             $ret  .= '<table class="outer"><tr>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |             $cols = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |             foreach ($this->_appendix as $append) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |                 if ($cols > 4) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |                     $ret  .= '</tr><tr>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |                     $cols = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |                 $checked = $append['selected'] ? 'checked' : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |                 $name    = 'perms[' . $append['permname'] . ']'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |                 $itemid  = $append['itemid']; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |                 $itemid  = $append['itemid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |                 $ret     .= "<td class=\"odd\"><input type=\"checkbox\" name=\"{$name}[groups][$this->_groupId][$itemid]\" id=\"{$name}[groups][$this->_groupId][$itemid]\" value=\"1\" $checked>{$append['itemname']}<input type=\"hidden\" name=\"{$name}[parents][$itemid]\" value=\"\"><input type=\"hidden\" name=\"{$name}[itemname][$itemid]\" value=\"{$append['itemname']}\"><br></td>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |                 ++$cols; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |             $ret .= '</tr></table>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |         $ret  .= '<table class="outer"><tr>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |         $cols = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |         if (!empty($this->_optionTree[0]['children'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |             foreach ($this->_optionTree[0]['children'] as $topitem) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |                 if ($cols > 4) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |                     $ret  .= '</tr><tr>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |                     $cols = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |                 $tree   = '<td class="odd">'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |                 $prefix = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |                 $this->_renderOptionTree($tree, $this->_optionTree[$topitem], $prefix); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |                 $ret .= $tree . '</td>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |                 ++$cols; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |         $ret .= '</tr></table>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |         return $ret; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |      * Renders checkbox options for an item tree | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |      * @param string $tree | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |      * @param array  $option | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |      * @param string $prefix | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |      * @param array  $parentIds | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |      * @access private | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |     public function _renderOptionTree(&$tree, $option, $prefix, $parentIds = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |         $tree .= $prefix . '<input type="checkbox" name="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" onclick="'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |         // If there are parent elements, add javascript that will | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |         // make them selecteded when this element is checked to make | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |         // sure permissions to parent items are added as well. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |         foreach ($parentIds as $pid) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |             $parent_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $pid . ']'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |             $tree       .= "var ele = xoopsGetElementById('" . $parent_ele . "'); if (ele.checked !== true) {ele.checked = this.checked;}"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |         // If there are child elements, add javascript that will | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |         // make them unchecked when this element is unchecked to make | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |         // sure permissions to child items are not added when there | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |         // is no permission to this item. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |         foreach ($option['allchild'] as $cid) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |             $child_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $cid . ']'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |             $tree      .= "var ele = xoopsGetElementById('" . $child_ele . "'); if (this.checked !== true) {ele.checked = false;}"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |         $tree .= '" value="1"'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  |         if (isset($this->_value) && in_array($option['id'], $this->_value)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  |             $tree .= ' checked'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |         $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( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |                 $option['name'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  |                 ENT_QUOTES | ENT_HTML5 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |             ) . "\"><br>\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |         if (isset($option['children'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |             foreach ($option['children'] as $child) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |                 $parentIds[] = $option['id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |                 $this->_renderOptionTree($tree, $this->_optionTree[$child], $prefix . ' -', $parentIds); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 401 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 402 |  |  |  |