XOOPS  2.6.0
main.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 
25 // Get main instance
29 
30 // Check users rights
31 if (!$xoops->isUser() || !$xoops->isModule() || !$xoops->user->isAdmin($xoops->module->mid())) {
33 }
34 
35 $conf_ids = array();
38 
39 // TODO this needs to go!
40 if (isset($_REQUEST)) {
41  foreach ($_REQUEST as $k => $v) {
42  ${$k} = $v;
43  }
44 }
45 // Get Action type
46 $op = $system->cleanVars($_REQUEST, 'op', 'showmod', 'string');
47 // Setting type
48 $confcat_id = $system->cleanVars($_REQUEST, 'confcat_id', 0, 'int');
49 // Call Header
50 $xoops->header('admin:system/system_preferences.tpl');
51 // Define Stylesheet
52 $xoops->theme()->addStylesheet('modules/system/css/admin.css');
53 // Define scripts
54 $xoops->theme()->addScript('modules/system/js/admin.js');
55 
56 
57 
58 //Display part
59 switch ($op) {
60 
61  case 'show':
62  case 'showmod':
63  $mod = $system->cleanVars($_GET, 'mod', 1, 'int');
64  if (!$mod) {
65  $xoops->redirect('admin.php?fct=preferences', 1);
66  }
67 
68  $config_handler = $xoops->getHandlerConfig();
69  $config = $config_handler->getConfigs(new Criteria('conf_modid', $mod));
70  $count = count($config);
71  if ($count < 1) {
72  $xoops->redirect('admin.php?fct=preferences', 1);
73  }
74 
75  $module_handler = $xoops->getHandlerModule();
76  $module = $xoops->getModuleById($mod);
77  $xoops->loadLanguage('modinfo', $module->getVar('dirname'));
78 
79  // Define Breadcrumb and tips
80  $admin_page = new \Xoops\Module\Admin();
81  $admin_page->addBreadcrumbLink(SystemLocale::CONTROL_PANEL, \XoopsBaseConfig::get('url') . '/admin.php', true);
82  $admin_page->addBreadcrumbLink(XoopsLocale::PREFERENCES, $system->adminVersion('extensions', 'adminpath'));
83  $admin_page->addBreadcrumbLink($module->getVar('name'));
84  $admin_page->renderBreadcrumb();
85 
86  /* @var $form SystemPreferencesForm */
87  $form = $xoops->getModuleForm(null, 'preferences');
88  $form->getForm($config, $module);
89  $xoops->tpl()->assign('form', $form->render());
90  break;
91 
92  case 'save':
93  if (!$xoops->security()->check()) {
94  $xoops->redirect("admin.php?fct=preferences", 3, implode('<br />', $xoops->security()->getErrors()));
95  }
96  $xoopsTpl = new XoopsTpl();
97  $count = count($conf_ids);
98  $tpl_updated = false;
99  $theme_updated = false;
100  $startmod_updated = false;
101  $lang_updated = false;
102  $config_handler = $xoops->getHandlerConfig();
103  if ($count > 0) {
104  for ($i = 0; $i < $count; ++$i) {
105  $config = $config_handler->getConfig($conf_ids[$i]);
106  $new_value = isset(${$config->getVar('conf_name')}) ? ${$config->getVar('conf_name')} : null;
107  if (!is_null($new_value) && (is_array($new_value) || $new_value != $config->getVar('conf_value'))) {
108  // if language has been changed
109  if (!$lang_updated && $config->getVar('conf_catid') == XOOPS_CONF
110  && $config->getVar('conf_name') == 'locale'
111  ) {
112  $xoops->setConfig('locale', ${$config->getVar('conf_name')});
113  $lang_updated = true;
114  }
115 
116  // if default theme has been changed
117  if (!$theme_updated && $config->getVar('conf_catid') == XOOPS_CONF
118  && $config->getVar('conf_name') == 'theme_set'
119  ) {
120  $member_handler = $xoops->getHandlerMember();
121  $member_handler->updateUsersByField('theme', ${$config->getVar('conf_name')});
122  $theme_updated = true;
123  }
124 
125  // add read permission for the start module to all groups
126  if (!$startmod_updated && $new_value != '--'
127  && $config->getVar('conf_catid') == XOOPS_CONF
128  && $config->getVar('conf_name') == 'startpage'
129  ) {
130  $member_handler = $xoops->getHandlerMember();
131  $groups = $member_handler->getGroupList();
132  $moduleperm_handler = $xoops->getHandlerGroupperm();
133  $module_handler = $xoops->getHandlerModule();
134  $module = $xoops->getModuleByDirname($new_value);
135  foreach ($groups as $groupid => $groupname) {
136  if (!$moduleperm_handler->checkRight('module_read', $module->getVar('mid'), $groupid)) {
137  $moduleperm_handler->addRight('module_read', $module->getVar('mid'), $groupid);
138  }
139  }
140  $startmod_updated = true;
141  }
142 
143  $config->setConfValueForInput($new_value);
144  $config_handler->insertConfig($config);
145  }
146  unset($new_value);
147  }
148  }
149 
150  // Clean cached files, may take long time
151  // User register_shutdown_function to keep running after connection closes
152  // so that cleaning cached files can be finished
153  // Cache management should be performed on a separate page
154  $options = array(1, 2, 3); //1 goes for smarty cache, 3 goes for xoops_cache
155  register_shutdown_function(array(&$system, 'cleanCache'), $options);
156  $xoops->preload()->triggerEvent('system.preferences.save');
157  if (isset($redirect) && $redirect != '') {
159  } else {
160  $xoops->redirect("admin.php?fct=preferences", 2, XoopsLocale::S_DATABASE_UPDATED);
161  }
162  break;
163 }
164 // Call Footer
165 $xoops->footer();
$confcat_id
Definition: main.php:48
if(!$xoops->isUser()||!$xoops->isModule()||!$xoops->user->isAdmin($xoops->module->mid())) $conf_ids
Definition: main.php:35
$member_handler
Definition: main.php:41
$i
Definition: dialog.php:68
$system
Definition: main.php:26
static getInstance($fct= '')
static getInstance()
Definition: system.php:46
static getInstance()
Definition: Xoops.php:160
const XOOPS_CONF
Definition: configitem.php:28
$options['editor']
$xoopsTpl
Definition: xoops_code.php:45
$admin_page
Definition: main.php:34
const PREFERENCES
Definition: en_US.php:909
$form
Definition: xoops_code.php:21
exit
Definition: browse.php:104
$redirect
Definition: header.php:37
$session_expire
Definition: main.php:36
$op
Definition: main.php:30
if($_SERVER['REQUEST_METHOD']== 'POST') $config_handler
static get($name)
$session_name
Definition: main.php:37
$module
Definition: main.php:52
const CONTROL_PANEL
Definition: en_US.php:247
const E_NO_ACCESS_PERMISSION
Definition: en_US.php:351
$groups
return $config
$module_handler
Definition: main.php:55
$xoops
Definition: main.php:25
$system_breadcrumb
Definition: main.php:30
$moduleperm_handler
Definition: cp_header.php:31
const S_DATABASE_UPDATED
Definition: en_US.php:1024