1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: |
|
19: | include_once __DIR__ . '/admin_header.php';
|
20: | xoops_cp_header();
|
21: | $indexAdmin = new ModuleAdmin();
|
22: |
|
23: | $indexAdmin->addItemButton(_ADD . ' ' . _PROFILE_AM_FIELD, 'field.php?op=new', 'add', '');
|
24: |
|
25: | echo $indexAdmin->addNavigation(basename(__FILE__));
|
26: | echo $indexAdmin->renderButton('right', '');
|
27: |
|
28: | $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : (isset($_REQUEST['id']) ? 'edit' : 'list');
|
29: |
|
30: | $profilefield_handler = xoops_getModuleHandler('field');
|
31: |
|
32: | switch ($op) {
|
33: | default:
|
34: | case 'list':
|
35: | $fields = $profilefield_handler->getObjects(null, true, false);
|
36: |
|
37: |
|
38: | $module_handler = xoops_getHandler('module');
|
39: | $modules = $module_handler->getObjects(null, true);
|
40: |
|
41: |
|
42: | $cat_handler = xoops_getModuleHandler('category');
|
43: | $criteria = new CriteriaCompo();
|
44: | $criteria->setSort('cat_weight');
|
45: | $cats = $cat_handler->getObjects($criteria, true);
|
46: | unset($criteria);
|
47: |
|
48: | $categories[0] = _PROFILE_AM_DEFAULT;
|
49: | if (count($cats) > 0) {
|
50: | foreach (array_keys($cats) as $i) {
|
51: | $categories[$cats[$i]->getVar('cat_id')] = $cats[$i]->getVar('cat_title');
|
52: | }
|
53: | }
|
54: | $GLOBALS['xoopsTpl']->assign('categories', $categories);
|
55: | unset($categories);
|
56: | $valuetypes = array(
|
57: | XOBJ_DTYPE_ARRAY => _PROFILE_AM_ARRAY,
|
58: | XOBJ_DTYPE_EMAIL => _PROFILE_AM_EMAIL,
|
59: | XOBJ_DTYPE_INT => _PROFILE_AM_INT,
|
60: | XOBJ_DTYPE_TXTAREA => _PROFILE_AM_TXTAREA,
|
61: | XOBJ_DTYPE_TXTBOX => _PROFILE_AM_TXTBOX,
|
62: | XOBJ_DTYPE_URL => _PROFILE_AM_URL,
|
63: | XOBJ_DTYPE_OTHER => _PROFILE_AM_OTHER,
|
64: | XOBJ_DTYPE_MTIME => _PROFILE_AM_DATE);
|
65: |
|
66: | $fieldtypes = array(
|
67: | 'checkbox' => _PROFILE_AM_CHECKBOX,
|
68: | 'group' => _PROFILE_AM_GROUP,
|
69: | 'group_multi' => _PROFILE_AM_GROUPMULTI,
|
70: | 'language' => _PROFILE_AM_LANGUAGE,
|
71: | 'radio' => _PROFILE_AM_RADIO,
|
72: | 'select' => _PROFILE_AM_SELECT,
|
73: | 'select_multi' => _PROFILE_AM_SELECTMULTI,
|
74: | 'textarea' => _PROFILE_AM_TEXTAREA,
|
75: | 'dhtml' => _PROFILE_AM_DHTMLTEXTAREA,
|
76: | 'textbox' => _PROFILE_AM_TEXTBOX,
|
77: | 'timezone' => _PROFILE_AM_TIMEZONE,
|
78: | 'yesno' => _PROFILE_AM_YESNO,
|
79: | 'date' => _PROFILE_AM_DATE,
|
80: | 'datetime' => _PROFILE_AM_DATETIME,
|
81: | 'longdate' => _PROFILE_AM_LONGDATE,
|
82: | 'theme' => _PROFILE_AM_THEME,
|
83: | 'autotext' => _PROFILE_AM_AUTOTEXT,
|
84: | 'rank' => _PROFILE_AM_RANK);
|
85: |
|
86: | foreach (array_keys($fields) as $i) {
|
87: | $fields[$i]['canEdit'] = $fields[$i]['field_config'] || $fields[$i]['field_show'] || $fields[$i]['field_edit'];
|
88: | $fields[$i]['canDelete'] = $fields[$i]['field_config'];
|
89: | $fields[$i]['fieldtype'] = $fieldtypes[$fields[$i]['field_type']];
|
90: | $fields[$i]['valuetype'] = $valuetypes[$fields[$i]['field_valuetype']];
|
91: | $categories[$fields[$i]['cat_id']][] = $fields[$i];
|
92: | $weights[$fields[$i]['cat_id']][] = $fields[$i]['field_weight'];
|
93: | }
|
94: |
|
95: | foreach (array_keys($categories) as $i) {
|
96: | array_multisort($weights[$i], SORT_ASC, array_keys($categories[$i]), SORT_ASC, $categories[$i]);
|
97: | }
|
98: | ksort($categories);
|
99: | $GLOBALS['xoopsTpl']->assign('fieldcategories', $categories);
|
100: | $GLOBALS['xoopsTpl']->assign('token', $GLOBALS['xoopsSecurity']->getTokenHTML());
|
101: | $template_main = 'profile_admin_fieldlist.tpl';
|
102: | break;
|
103: |
|
104: | case 'new':
|
105: | include_once dirname(__DIR__) . '/include/forms.php';
|
106: | $obj = $profilefield_handler->create();
|
107: | $form = profile_getFieldForm($obj);
|
108: | $form->display();
|
109: | break;
|
110: |
|
111: | case 'edit':
|
112: | $obj = $profilefield_handler->get($_REQUEST['id']);
|
113: | if (!$obj->getVar('field_config') && !$obj->getVar('field_show') && !$obj->getVar('field_edit')) {
|
114: | redirect_header('field.php', 2, _PROFILE_AM_FIELDNOTCONFIGURABLE);
|
115: | }
|
116: | include_once dirname(__DIR__) . '/include/forms.php';
|
117: | $form = profile_getFieldForm($obj);
|
118: | $form->display();
|
119: | break;
|
120: |
|
121: | case 'edit-option-strings':
|
122: | $obj = $profilefield_handler->get($_REQUEST['id']);
|
123: | $fieldOptions = $obj->getVar('field_options');
|
124: | if (empty($fieldOptions)) {
|
125: | redirect_header('field.php', 2, _PROFILE_AM_FIELDNOTCONFIGURABLE);
|
126: | }
|
127: | include_once dirname(__DIR__) . '/include/forms.php';
|
128: | $form = profile_getFieldOptionForm($obj);
|
129: | $form->display();
|
130: | break;
|
131: |
|
132: | case 'reorder':
|
133: | if (!$GLOBALS['xoopsSecurity']->check()) {
|
134: | redirect_header('field.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
|
135: | }
|
136: | if (isset($_POST['field_ids']) && count($_POST['field_ids']) > 0) {
|
137: | $oldweight = $_POST['oldweight'];
|
138: | $oldcat = $_POST['oldcat'];
|
139: | $category = $_POST['category'];
|
140: | $weight = $_POST['weight'];
|
141: | $ids = array();
|
142: | foreach ($_POST['field_ids'] as $field_id) {
|
143: | if ($oldweight[$field_id] != $weight[$field_id] || $oldcat[$field_id] != $category[$field_id]) {
|
144: |
|
145: | $ids[] = (int)$field_id;
|
146: | }
|
147: | }
|
148: | if (count($ids) > 0) {
|
149: | $errors = array();
|
150: |
|
151: |
|
152: | $field_handler = xoops_getModuleHandler('field');
|
153: | $fields = $field_handler->getObjects(new Criteria('field_id', '(' . implode(',', $ids) . ')', 'IN'), true);
|
154: | foreach ($ids as $i) {
|
155: | $fields[$i]->setVar('field_weight', (int)$weight[$i]);
|
156: | $fields[$i]->setVar('cat_id', (int)$category[$i]);
|
157: | if (!$field_handler->insert($fields[$i])) {
|
158: | $errors = array_merge($errors, $fields[$i]->getErrors());
|
159: | }
|
160: | }
|
161: | if (count($errors) == 0) {
|
162: |
|
163: | redirect_header('field.php', 2, sprintf(_PROFILE_AM_SAVEDSUCCESS, _PROFILE_AM_FIELDS));
|
164: | } else {
|
165: | redirect_header('field.php', 3, implode('<br>', $errors));
|
166: | }
|
167: | }
|
168: | }
|
169: | break;
|
170: |
|
171: | case 'save':
|
172: | if (!$GLOBALS['xoopsSecurity']->check()) {
|
173: | redirect_header('field.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
|
174: | }
|
175: | $redirect_to_edit = false;
|
176: | if (isset($_REQUEST['id'])) {
|
177: | $obj = $profilefield_handler->get($_REQUEST['id']);
|
178: | if (!$obj->getVar('field_config') && !$obj->getVar('field_show') && !$obj->getVar('field_edit')) {
|
179: | redirect_header('admin.php', 2, _PROFILE_AM_FIELDNOTCONFIGURABLE);
|
180: | }
|
181: | } else {
|
182: | $obj = $profilefield_handler->create();
|
183: | $obj->setVar('field_name', $_REQUEST['field_name']);
|
184: | $obj->setVar('field_moduleid', $GLOBALS['xoopsModule']->getVar('mid'));
|
185: | $obj->setVar('field_show', 1);
|
186: | $obj->setVar('field_edit', 1);
|
187: | $obj->setVar('field_config', 1);
|
188: | $redirect_to_edit = true;
|
189: | }
|
190: | $obj->setVar('field_title', $_REQUEST['field_title']);
|
191: | $obj->setVar('field_description', $_REQUEST['field_description']);
|
192: | if ($obj->getVar('field_config')) {
|
193: | $obj->setVar('field_type', $_REQUEST['field_type']);
|
194: | if (isset($_REQUEST['field_valuetype'])) {
|
195: | $obj->setVar('field_valuetype', $_REQUEST['field_valuetype']);
|
196: | }
|
197: | $options = $obj->getVar('field_options');
|
198: |
|
199: | if (isset($_REQUEST['removeOptions']) && \is_array($_REQUEST['removeOptions'])) {
|
200: | foreach ($_REQUEST['removeOptions'] as $index) {
|
201: | unset($options[$index]);
|
202: | }
|
203: | $redirect_to_edit = true;
|
204: | }
|
205: |
|
206: | if (!empty($_REQUEST['addOption'])) {
|
207: | foreach ($_REQUEST['addOption'] as $option) {
|
208: | if (empty($option['value'])) {
|
209: | continue;
|
210: | }
|
211: | $options[$option['key']] = $option['value'];
|
212: | $redirect_to_edit = true;
|
213: | }
|
214: | }
|
215: | $obj->setVar('field_options', $options);
|
216: | }
|
217: | if ($obj->getVar('field_edit')) {
|
218: | $required = isset($_REQUEST['field_required']) ? $_REQUEST['field_required'] : 0;
|
219: | $obj->setVar('field_required', $required);
|
220: | if (isset($_REQUEST['field_maxlength'])) {
|
221: | $obj->setVar('field_maxlength', $_REQUEST['field_maxlength']);
|
222: | }
|
223: | if (isset($_REQUEST['field_default'])) {
|
224: | $field_default = $obj->getValueForSave($_REQUEST['field_default']);
|
225: |
|
226: | if (is_array($field_default)) {
|
227: | $obj->setVar('field_default', serialize($field_default));
|
228: | } else {
|
229: | $obj->setVar('field_default', $field_default);
|
230: | }
|
231: | }
|
232: | }
|
233: |
|
234: | if ($obj->getVar('field_show')) {
|
235: | $obj->setVar('field_weight', $_REQUEST['field_weight']);
|
236: | $obj->setVar('cat_id', $_REQUEST['field_category']);
|
237: | }
|
238: | if (
|
239: | isset($_REQUEST['step_id'])
|
240: | ) {
|
241: | $obj->setVar('step_id', $_REQUEST['step_id']);
|
242: | }
|
243: | if ($profilefield_handler->insert($obj)) {
|
244: |
|
245: | $groupperm_handler = xoops_getHandler('groupperm');
|
246: |
|
247: | $perm_arr = array();
|
248: | if ($obj->getVar('field_show')) {
|
249: | $perm_arr[] = 'profile_show';
|
250: | $perm_arr[] = 'profile_visible';
|
251: | }
|
252: | if ($obj->getVar('field_edit')) {
|
253: | $perm_arr[] = 'profile_edit';
|
254: | }
|
255: | if ($obj->getVar('field_edit') || $obj->getVar('field_show')) {
|
256: | $perm_arr[] = 'profile_search';
|
257: | }
|
258: | if (count($perm_arr) > 0) {
|
259: | foreach ($perm_arr as $perm) {
|
260: | $criteria = new CriteriaCompo(new Criteria('gperm_name', $perm));
|
261: | $criteria->add(new Criteria('gperm_itemid', (int)$obj->getVar('field_id')));
|
262: | $criteria->add(new Criteria('gperm_modid', (int)$GLOBALS['xoopsModule']->getVar('mid')));
|
263: | if (isset($_REQUEST[$perm]) && \is_array($_REQUEST[$perm])) {
|
264: | $perms = $groupperm_handler->getObjects($criteria);
|
265: | if (count($perms) > 0) {
|
266: | foreach (array_keys($perms) as $i) {
|
267: | $groups[$perms[$i]->getVar('gperm_groupid')] =& $perms[$i];
|
268: | }
|
269: | } else {
|
270: | $groups = array();
|
271: | }
|
272: | foreach ($_REQUEST[$perm] as $groupid) {
|
273: | $groupid = (int)$groupid;
|
274: | if (!isset($groups[$groupid])) {
|
275: | $perm_obj = $groupperm_handler->create();
|
276: | $perm_obj->setVar('gperm_name', $perm);
|
277: | $perm_obj->setVar('gperm_itemid', (int)$obj->getVar('field_id'));
|
278: | $perm_obj->setVar('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'));
|
279: | $perm_obj->setVar('gperm_groupid', $groupid);
|
280: | $groupperm_handler->insert($perm_obj);
|
281: | unset($perm_obj);
|
282: | }
|
283: | }
|
284: | $removed_groups = array_diff(array_keys($groups), $_REQUEST[$perm]);
|
285: | if (count($removed_groups) > 0) {
|
286: | $criteria->add(new Criteria('gperm_groupid', '(' . implode(',', $removed_groups) . ')', 'IN'));
|
287: | $groupperm_handler->deleteAll($criteria);
|
288: | }
|
289: | unset($groups);
|
290: | } else {
|
291: | $groupperm_handler->deleteAll($criteria);
|
292: | }
|
293: | unset($criteria);
|
294: | }
|
295: | }
|
296: | $url = $redirect_to_edit ? 'field.php?op=edit&id=' . $obj->getVar('field_id') : 'field.php';
|
297: | redirect_header($url, 3, sprintf(_PROFILE_AM_SAVEDSUCCESS, _PROFILE_AM_FIELD));
|
298: | }
|
299: | include_once dirname(__DIR__) . '/include/forms.php';
|
300: | echo $obj->getHtmlErrors();
|
301: | $form = profile_getFieldForm($obj);
|
302: | $form->display();
|
303: | break;
|
304: |
|
305: | case 'save-option-strings':
|
306: | if (!$GLOBALS['xoopsSecurity']->check()) {
|
307: | redirect_header('field.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
|
308: | }
|
309: | $obj = $profilefield_handler->get($_REQUEST['id']);
|
310: | $fieldOptions = \Xmf\Request::getArray('field_options');
|
311: | if (empty($fieldOptions)) {
|
312: | redirect_header('field.php', 2, _PROFILE_AM_FIELDNOTCONFIGURABLE);
|
313: | }
|
314: | $obj->setVar('field_options', $fieldOptions);
|
315: | if ($profilefield_handler->insert($obj)) {
|
316: | redirect_header('field.php', 2, sprintf(_PROFILE_AM_SAVEDSUCCESS, _PROFILE_AM_FIELD));
|
317: | }
|
318: | redirect_header('field.php', 2, implode(',', $obj->getErrors()));
|
319: | break;
|
320: |
|
321: | case 'delete':
|
322: | $obj = $profilefield_handler->get($_REQUEST['id']);
|
323: | if (!$obj->getVar('field_config')) {
|
324: | redirect_header('index.php', 2, _PROFILE_AM_FIELDNOTCONFIGURABLE);
|
325: | }
|
326: | if (isset($_REQUEST['ok']) && $_REQUEST['ok'] == 1) {
|
327: | if (!$GLOBALS['xoopsSecurity']->check()) {
|
328: | redirect_header('field.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
|
329: | }
|
330: | if ($profilefield_handler->delete($obj)) {
|
331: | redirect_header('field.php', 3, sprintf(_PROFILE_AM_DELETEDSUCCESS, _PROFILE_AM_FIELD));
|
332: | } else {
|
333: | echo $obj->getHtmlErrors();
|
334: | }
|
335: | } else {
|
336: | xoops_confirm(array(
|
337: | 'ok' => 1,
|
338: | 'id' => $_REQUEST['id'],
|
339: | 'op' => 'delete'), $_SERVER['REQUEST_URI'], sprintf(_PROFILE_AM_RUSUREDEL, $obj->getVar('field_title')));
|
340: | }
|
341: | break;
|
342: |
|
343: | case 'toggle':
|
344: | if (isset($_REQUEST['field_id'])) {
|
345: | $field_id = (int)$_REQUEST['field_id'];
|
346: | if (isset($_REQUEST['field_required'])) {
|
347: | $field_required = (int)$_REQUEST['field_required'];
|
348: | profile_visible_toggle($field_id, $field_required);
|
349: | }
|
350: | }
|
351: | break;
|
352: | }
|
353: |
|
354: | if (isset($template_main)) {
|
355: | $GLOBALS['xoopsTpl']->display("db:{$template_main}");
|
356: | }
|
357: |
|
358: | |
359: | |
360: | |
361: |
|
362: | function profile_visible_toggle($field_id, $field_required)
|
363: | {
|
364: | $field_required = ($field_required == 1) ? 0 : 1;
|
365: | $this_handler = xoops_getModuleHandler('field', 'profile');
|
366: | $obj = $this_handler->get($field_id);
|
367: | $obj->setVar('field_required', $field_required);
|
368: | if ($this_handler->insert($obj, true)) {
|
369: | redirect_header('field.php', 1, _PROFILE_AM_REQUIRED_TOGGLE_SUCCESS);
|
370: | } else {
|
371: | redirect_header('field.php', 1, _PROFILE_AM_REQUIRED_TOGGLE_FAILED);
|
372: | }
|
373: | }
|
374: |
|
375: | include_once __DIR__ . '/admin_footer.php';
|
376: | |