XOOPS  2.6.0
index.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
13 
23 include dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'mainfile.php';
24 
27 
28 if (!$xoops->isUser()) {
29  $xoops->redirect($xoops->url('index.php'), 3, _MD_USERCONFIGS_NOACCESS);
30 }
31 
32 $mid = Request::getInt('mid', 0);
33 $uid = $xoops->user->getVar('uid');
34 $op = Request::getCmd('op', 'show');
35 
36 $xoops->header('module:userconfigs/list.tpl');
37 $xoops->tpl()->assign('welcome', sprintf(_MD_USERCONFIGS_WELCOME, XoopsUserUtility::getUnameFromId($xoops->user->getVar('uid'), true)));
38 
39 //Display part
40 switch ($op) {
41  case 'showmod':
42  if (!$mid) {
43  $xoops->redirect($xoops->url('index.php'), 3, _MD_USERCONFIGS_NOMOD);
44  }
45 
46  $module = $xoops->getModuleById($mid);
47 
48  /* @var $plugin UserconfigsPluginInterface */
49  if (!$plugin = \Xoops\Module\Plugin::getPlugin($module->getVar('dirname'), 'userconfigs')) {
50  $xoops->redirect($xoops->url('index.php'), 3, _MD_USERCONFIGS_NOPLUGIN);
51  }
52  $config_handler = $helper->getHandlerConfig();
53  $criteria = new CriteriaCompo();
54  $criteria->add(new Criteria('conf_modid', $module->getVar('mid')));
55  $criteria->add(new Criteria('conf_uid', $uid));
56  $configs = $config_handler->getConfigs($criteria);
57 
58  if (empty($configs) || (count($configs) != count($plugin->configs()))) {
59  foreach (array_keys($configs) as $i) {
60  $config_handler->deleteConfig($configs[$i]);
61  }
62  $config_handler->createDefaultUserConfigs($uid, $module);
63  $configs = $config_handler->getConfigs($criteria);
64  }
65 
66  /* @var $form UserconfigsConfigsForm */
67  $form = $helper->getForm(null, 'configs');
68  $form->getForm($configs, $module);
69  $xoops->tpl()->assign('form', $form->render());
70  /* @var $form UserconfigsModulesForm */
71  $form = $helper->getForm(null, 'modules');
72  $form->getModulesForm($module);
73  $xoops->tpl()->assign('modules_form', $form->render());
74  break;
75  case 'show':
76  if (!$mid) {
77  $module = null;
78  } else {
79  $module = $xoops->getModuleById($mid);
80  }
81 
82  /* @var $form UserconfigsModulesForm */
83  $form = $helper->getForm(null, 'modules');
84  $form->getModulesForm($module);
85  $xoops->tpl()->assign('modules_form', $form->render());
86  break;
87  case 'save':
88  if (!$xoops->security()->check()) {
89  $helper->redirect("index.php", 3, implode('<br />', $xoops->security()->getErrors()));
90  }
91 
92  $conf_ids = array();
93  if (isset($_REQUEST)) {
94  foreach ($_REQUEST as $k => $v) {
95  ${$k} = $v;
96  }
97  }
98 
99  $xoopsTpl = new XoopsTpl();
100  $count = count($conf_ids);
101  $config_handler = $helper->getHandlerConfig();
102  if ($count > 0) {
103  for ($i = 0; $i < $count; ++$i) {
104  $config = $config_handler->getConfig($conf_ids[$i]);
105  $new_value = isset(${$config->getVar('conf_name')}) ? ${$config->getVar('conf_name')} : null;
106  if (!is_null($new_value) && (is_array($new_value) || $new_value != $config->getVar('conf_value'))) {
107  $config->setConfValueForInput($new_value);
108  $config_handler->insertConfig($config);
109  }
110  unset($new_value);
111  }
112  }
113  $xoops->redirect("index.php?mid={$mid}&amp;op=showmod", 2, _MD_USERCONFIGS_UPDATED);
114  break;
115 }
116 $xoops->footer();
$mid
Definition: index.php:39
static getUnameFromId($userid, $usereal=false, $linked=false)
if(!$xoops->isUser()||!$xoops->isModule()||!$xoops->user->isAdmin($xoops->module->mid())) $conf_ids
Definition: main.php:35
$op
Definition: index.php:33
static getInstance()
Definition: Xoops.php:160
const _MD_USERCONFIGS_WELCOME
Definition: main.php:26
$xoopsTpl
Definition: xoops_code.php:45
$i
Definition: index.php:14
const _MD_USERCONFIGS_NOMOD
Definition: main.php:22
const _MD_USERCONFIGS_UPDATED
Definition: main.php:23
static getInstance()
Definition: helper.php:36
$form
Definition: xoops_code.php:21
defined('DS') or define('DS' DIRECTORY_SEPARATOR
Definition: common.php:41
const _MD_USERCONFIGS_NOACCESS
Definition: main.php:19
const _MD_USERCONFIGS_NOPLUGIN
Definition: main.php:21
if($_SERVER['REQUEST_METHOD']== 'POST') $config_handler
$criteria
Definition: index.php:30
$module
Definition: main.php:52
if(!$xoops->isUser()) $uid
Definition: index.php:31
$configs
Definition: config.php:27
$helper
Definition: index.php:25
return $config
$count
Definition: index.php:36
if(file_exists($mainfile)) elseif(file_exists(__DIR__. '/install/index.php')) $xoops
Definition: index.php:36