1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17:
18:
19:
20: include_once XOOPS_ROOT_PATH . '/kernel/group.php';
21:
22: 23: 24: 25: 26: 27:
28: class SystemGroup extends XoopsGroup
29: {
30: 31: 32:
33: public function __construct()
34: {
35: parent::__construct();
36: }
37:
38: 39: 40: 41: 42:
43: public function getForm($action = false)
44: {
45: if ($action === false) {
46: $action = $_SERVER['REQUEST_URI'];
47: }
48:
49: if ($this->isNew()) {
50: $s_cat_value = '';
51: $a_mod_value = array();
52: $r_mod_value = array();
53: $r_block_value = array();
54: } else {
55:
56: $sysperm_handler = xoops_getHandler('groupperm');
57: $s_cat_value = $sysperm_handler->getItemIds('system_admin', $this->getVar('groupid'));
58:
59: $member_handler = xoops_getHandler('member');
60: $thisgroup = $member_handler->getGroup($this->getVar('groupid'));
61:
62: $moduleperm_handler = xoops_getHandler('groupperm');
63: $a_mod_value = $moduleperm_handler->getItemIds('module_admin', $thisgroup->getVar('groupid'));
64: $r_mod_value = $moduleperm_handler->getItemIds('module_read', $thisgroup->getVar('groupid'));
65:
66: $gperm_handler = xoops_getHandler('groupperm');
67: $r_block_value = $gperm_handler->getItemIds('block_read', $this->getVar('groupid'));
68: }
69: xoops_load('XoopsFormLoader');
70: xoops_load('XoopsLists');
71: include_once XOOPS_ROOT_PATH . '/modules/system/constants.php';
72:
73: $title = $this->isNew() ? sprintf(_AM_SYSTEM_GROUPS_ADD) : sprintf(_AM_SYSTEM_GROUPS_EDIT);
74: $form = new XoopsThemeForm($title, 'groupform', $action, 'post', true);
75: $form->setExtra('enctype="multipart/form-data"');
76:
77: $name_text = new XoopsFormText(_AM_SYSTEM_GROUPS_NAME, 'name', 30, 50, $this->getVar('name'));
78: $desc_text = new XoopsFormTextArea(_AM_SYSTEM_GROUPS_DESCRIPTION, 'desc', $this->getVar('description'));
79:
80: $system_catids = new XoopsFormElementTray(_AM_SYSTEM_GROUPS_SYSTEMRIGHTS, '');
81:
82: $s_cat_checkbox_all = new XoopsFormCheckBox('', 'catbox', 1);
83: $s_cat_checkbox_all->addOption('allbox', _AM_SYSTEM_ALL);
84: $s_cat_checkbox_all->setExtra(" onclick='xoopsCheckGroup(\"groupform\", \"catbox\" , \"system_catids[]\");' ");
85: $s_cat_checkbox_all->setClass('xo-checkall');
86: $system_catids->addElement($s_cat_checkbox_all);
87:
88: $s_cat_checkbox = new XoopsFormCheckBox('', 'system_catids', $s_cat_value);
89: $s_cat_checkbox->columns = 6;
90: $admin_dir = XOOPS_ROOT_PATH . '/modules/system/admin/';
91: $dirlist = XoopsLists::getDirListAsArray($admin_dir);
92: foreach ($dirlist as $file) {
93: include XOOPS_ROOT_PATH . '/modules/system/admin/' . $file . '/xoops_version.php';
94: if (!empty($modversion['category'])) {
95: if (xoops_getModuleOption('active_' . $file, 'system') == 1) {
96: $s_cat_checkbox->addOption($modversion['category'], $modversion['name']);
97: }
98: }
99: unset($modversion);
100: }
101: unset($dirlist);
102: $system_catids->addElement($s_cat_checkbox);
103:
104: $admin_mids = new XoopsFormElementTray(_AM_SYSTEM_GROUPS_ACTIVERIGHTS, '');
105:
106: $s_admin_checkbox_all = new XoopsFormCheckBox('', 'adminbox', 1);
107: $s_admin_checkbox_all->addOption('allbox', _AM_SYSTEM_ALL);
108: $s_admin_checkbox_all->setExtra(" onclick='xoopsCheckGroup(\"groupform\", \"adminbox\" , \"admin_mids[]\");' ");
109: $s_admin_checkbox_all->setClass('xo-checkall');
110: $admin_mids->addElement($s_admin_checkbox_all);
111:
112: $a_mod_checkbox = new XoopsFormCheckBox('', 'admin_mids[]', $a_mod_value);
113: $a_mod_checkbox->columns = 5;
114:
115: $module_handler = xoops_getHandler('module');
116: $criteria = new CriteriaCompo(new Criteria('hasadmin', 1));
117: $criteria->add(new Criteria('isactive', 1));
118: $criteria->add(new Criteria('dirname', 'system', '<>'));
119: $a_mod_checkbox->addOptionArray($module_handler->getList($criteria));
120: $admin_mids->addElement($a_mod_checkbox);
121:
122: $read_mids = new XoopsFormElementTray(_AM_SYSTEM_GROUPS_ACCESSRIGHTS, '');
123:
124: $s_mod_checkbox_all = new XoopsFormCheckBox('', 'readbox', 1);
125: $s_mod_checkbox_all->addOption('allbox', _AM_SYSTEM_ALL);
126: $s_mod_checkbox_all->setExtra(" onclick='xoopsCheckGroup(\"groupform\", \"readbox\" , \"read_mids[]\");' ");
127: $s_mod_checkbox_all->setClass('xo-checkall');
128: $read_mids->addElement($s_mod_checkbox_all);
129:
130: $r_mod_checkbox = new XoopsFormCheckBox('', 'read_mids[]', $r_mod_value);
131: $r_mod_checkbox->columns = 5;
132: $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
133: $criteria->add(new Criteria('isactive', 1));
134: $r_mod_checkbox->addOptionArray($module_handler->getList($criteria));
135: $read_mids->addElement($r_mod_checkbox);
136:
137: $criteria = new CriteriaCompo(new Criteria('isactive', 1));
138: $criteria->setSort('mid');
139: $criteria->setOrder('ASC');
140: $module_list = $module_handler->getList($criteria);
141: $module_list[0] = _AM_SYSTEM_GROUPS_CUSTOMBLOCK;
142:
143: $block_handler = xoops_getHandler('block');
144: $blocks_obj = $block_handler->getObjects(new Criteria('mid', "('" . implode("', '", array_keys($module_list)) . "')", 'IN'), true);
145:
146: $blocks_module = array();
147: foreach (array_keys($blocks_obj) as $bid) {
148: $title = $blocks_obj[$bid]->getVar('title');
149: $blocks_module[$blocks_obj[$bid]->getVar('mid')][$blocks_obj[$bid]->getVar('bid')] = empty($title) ? $blocks_obj[$bid]->getVar('name') : $title;
150: }
151: ksort($blocks_module);
152:
153: $r_block_tray = new XoopsFormElementTray(_AM_SYSTEM_GROUPS_BLOCKRIGHTS, '<br><br>');
154: $s_checkbox_all = new XoopsFormCheckBox('', 'blocksbox', 1);
155: $s_checkbox_all->addOption('allbox', _AM_SYSTEM_ALL);
156: $s_checkbox_all->setExtra(" onclick='xoopsCheckGroup(\"groupform\", \"blocksbox\" , \"read_bids[]\");' ");
157: $s_checkbox_all->setClass('xo-checkall');
158: $r_block_tray->addElement($s_checkbox_all);
159: foreach (array_keys($blocks_module) as $mid) {
160: $new_blocks_array = array();
161: foreach ($blocks_module[$mid] as $key => $value) {
162: $new_blocks_array[$key] = "<a href='" . XOOPS_URL . "/modules/system/admin.php?fct=blocksadmin&op=edit&bid={$key}' title='ID: {$key}' rel='external'>{$value}</a>";
163: }
164: $r_block_checkbox = new XoopsFormCheckBox('<strong>' . $module_list[$mid] . '</strong><br>', 'read_bids[]', $r_block_value);
165: $r_block_checkbox->columns = 5;
166: $r_block_checkbox->addOptionArray($new_blocks_array);
167: $r_block_tray->addElement($r_block_checkbox);
168: unset($r_block_checkbox);
169: }
170: if (!$this->isNew()) {
171: $form->addElement(new XoopsFormHidden('g_id', $this->getVar('groupid')));
172: $form->addElement(new XoopsFormHidden('op', 'groups_save_update'));
173: } else {
174: $form->addElement(new XoopsFormHidden('op', 'groups_save_add'));
175: }
176: $form->addElement($name_text, true);
177: $form->addElement($desc_text);
178: $form->addElement($system_catids);
179: $form->addElement($admin_mids);
180: $form->addElement($read_mids);
181: $form->addElement($r_block_tray);
182: $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
183:
184: return $form;
185: }
186: }
187:
188: 189: 190: 191: 192: 193: 194: 195: 196: 197:
198: class SystemGroupHandler extends XoopsPersistableObjectHandler
199: {
200: 201: 202:
203: public function __construct(XoopsDatabase $db)
204: {
205: parent::__construct($db, 'groups', 'SystemGroup', 'groupid', 'name');
206: }
207: }
208: