mirror of
https://github.com/Mibew/mibew.git
synced 2025-02-08 00:34:42 +03:00
Replace "operator/features.php" with a controller
This commit is contained in:
parent
46e329471c
commit
862d94d35d
@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright 2005-2014 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mibew\Controller\Settings;
|
||||||
|
|
||||||
|
use Mibew\Controller\AbstractController;
|
||||||
|
use Mibew\Settings;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains actions which are related with features system settings.
|
||||||
|
*/
|
||||||
|
class FeaturesController extends AbstractController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Builds a page with form for features system settings.
|
||||||
|
*
|
||||||
|
* @param Request $request Incoming request.
|
||||||
|
* @return string Rendered page content.
|
||||||
|
*/
|
||||||
|
public function showFormAction(Request $request)
|
||||||
|
{
|
||||||
|
set_csrf_token();
|
||||||
|
|
||||||
|
$operator = $request->attributes->get('_operator');
|
||||||
|
$page = array(
|
||||||
|
'agentId' => '',
|
||||||
|
'errors' => array(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Settings::get('featuresversion') != FEATURES_VERSION) {
|
||||||
|
Settings::set('featuresversion', FEATURES_VERSION);
|
||||||
|
Settings::update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load all needed options and fill form with them.
|
||||||
|
$options = $this->getOptionsList();
|
||||||
|
foreach ($options as $opt) {
|
||||||
|
$page['form' . $opt] = (Settings::get($opt) == '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
$page['canmodify'] = is_capable(CAN_ADMINISTRATE, $operator);
|
||||||
|
$page['stored'] = $request->query->get('stored');
|
||||||
|
$page['title'] = getlocal('settings.title');
|
||||||
|
$page['menuid'] = 'settings';
|
||||||
|
$page = array_merge($page, prepare_menu($operator));
|
||||||
|
$page['tabs'] = setup_settings_tabs(1);
|
||||||
|
|
||||||
|
return $this->render('settings_features', $page);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes submitting of the form which is generated in
|
||||||
|
* {@link \Mibew\Controller\Settings\FeaturesController::showFormAction()}
|
||||||
|
* method.
|
||||||
|
*
|
||||||
|
* @param Request $request Incoming request.
|
||||||
|
* @return string Rendered page content.
|
||||||
|
*/
|
||||||
|
public function submitFormAction(Request $request)
|
||||||
|
{
|
||||||
|
csrf_check_token($request);
|
||||||
|
|
||||||
|
// Update options in the database.
|
||||||
|
$options = $this->getOptionsList();
|
||||||
|
foreach ($options as $opt) {
|
||||||
|
$value = $request->request->get($opt) == 'on' ? '1' : '0';
|
||||||
|
Settings::set($opt, $value);
|
||||||
|
}
|
||||||
|
Settings::update();
|
||||||
|
|
||||||
|
// Redirect the current operator to the same page using GET method.
|
||||||
|
$redirect_to = $this->generateUrl(
|
||||||
|
'settings_features',
|
||||||
|
array('stored' => true)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->redirect($redirect_to);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns list with names of all features options.
|
||||||
|
*
|
||||||
|
* @return array Features options names.
|
||||||
|
*/
|
||||||
|
protected function getOptionsList()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'enableban',
|
||||||
|
'usercanchangename',
|
||||||
|
'enablegroups',
|
||||||
|
'enablegroupsisolation',
|
||||||
|
'enablestatistics',
|
||||||
|
'enabletracking',
|
||||||
|
'enablessl',
|
||||||
|
'forcessl',
|
||||||
|
'enablepresurvey',
|
||||||
|
'surveyaskmail',
|
||||||
|
'surveyaskgroup',
|
||||||
|
'surveyaskmessage',
|
||||||
|
'enablepopupnotification',
|
||||||
|
'showonlineoperators',
|
||||||
|
'enablecaptcha',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -377,6 +377,22 @@ settings_common_save:
|
|||||||
_access_permissions: [CAN_ADMINISTRATE]
|
_access_permissions: [CAN_ADMINISTRATE]
|
||||||
methods: [POST]
|
methods: [POST]
|
||||||
|
|
||||||
|
settings_features:
|
||||||
|
path: /operator/settings/features
|
||||||
|
defaults:
|
||||||
|
_controller: Mibew\Controller\Settings\FeaturesController::showFormAction
|
||||||
|
_access_check: Mibew\AccessControl\Check\PermissionsCheck
|
||||||
|
_access_permissions: [CAN_ADMINISTRATE]
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
settings_features_save:
|
||||||
|
path: /operator/settings/features
|
||||||
|
defaults:
|
||||||
|
_controller: Mibew\Controller\Settings\FeaturesController::submitFormAction
|
||||||
|
_access_check: Mibew\AccessControl\Check\PermissionsCheck
|
||||||
|
_access_permissions: [CAN_ADMINISTRATE]
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
settings_performance:
|
settings_performance:
|
||||||
path: /operator/settings/performance
|
path: /operator/settings/performance
|
||||||
defaults:
|
defaults:
|
||||||
|
@ -32,7 +32,7 @@ function setup_settings_tabs($active)
|
|||||||
? (MIBEW_WEB_ROOT . "/operator/settings")
|
? (MIBEW_WEB_ROOT . "/operator/settings")
|
||||||
: ""),
|
: ""),
|
||||||
getlocal("page_settings.tab.features") => ($active != 1
|
getlocal("page_settings.tab.features") => ($active != 1
|
||||||
? (MIBEW_WEB_ROOT . "/operator/features.php")
|
? (MIBEW_WEB_ROOT . "/operator/settings/features")
|
||||||
: ""),
|
: ""),
|
||||||
getlocal("page_settings.tab.performance") => ($active != 2
|
getlocal("page_settings.tab.performance") => ($active != 2
|
||||||
? (MIBEW_WEB_ROOT . "/operator/settings/performance")
|
? (MIBEW_WEB_ROOT . "/operator/settings/performance")
|
||||||
|
@ -1,87 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* Copyright 2005-2014 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Import namespaces and classes of the core
|
|
||||||
use Mibew\Settings;
|
|
||||||
use Mibew\Style\PageStyle;
|
|
||||||
|
|
||||||
// Initialize libraries
|
|
||||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
|
||||||
|
|
||||||
$operator = check_login();
|
|
||||||
csrf_check_token();
|
|
||||||
|
|
||||||
$page = array(
|
|
||||||
'agentId' => '',
|
|
||||||
'errors' => array(),
|
|
||||||
);
|
|
||||||
|
|
||||||
$options = array(
|
|
||||||
'enableban',
|
|
||||||
'usercanchangename',
|
|
||||||
'enablegroups',
|
|
||||||
'enablegroupsisolation',
|
|
||||||
'enablestatistics',
|
|
||||||
'enabletracking',
|
|
||||||
'enablessl',
|
|
||||||
'forcessl',
|
|
||||||
'enablepresurvey',
|
|
||||||
'surveyaskmail',
|
|
||||||
'surveyaskgroup',
|
|
||||||
'surveyaskmessage',
|
|
||||||
'enablepopupnotification',
|
|
||||||
'showonlineoperators',
|
|
||||||
'enablecaptcha',
|
|
||||||
);
|
|
||||||
|
|
||||||
if (Settings::get('featuresversion') != FEATURES_VERSION) {
|
|
||||||
Settings::set('featuresversion', FEATURES_VERSION);
|
|
||||||
Settings::update();
|
|
||||||
}
|
|
||||||
$params = array();
|
|
||||||
foreach ($options as $opt) {
|
|
||||||
$params[$opt] = Settings::get($opt);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_POST['sent'])) {
|
|
||||||
if (is_capable(CAN_ADMINISTRATE, $operator)) {
|
|
||||||
foreach ($options as $opt) {
|
|
||||||
Settings::set($opt, (verify_param($opt, "/^on$/", "") == "on" ? "1" : "0"));
|
|
||||||
}
|
|
||||||
Settings::update();
|
|
||||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/features.php?stored");
|
|
||||||
exit;
|
|
||||||
} else {
|
|
||||||
$page['errors'][] = "Not an administrator";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$page['canmodify'] = is_capable(CAN_ADMINISTRATE, $operator);
|
|
||||||
$page['stored'] = isset($_GET['stored']);
|
|
||||||
foreach ($options as $opt) {
|
|
||||||
$page["form$opt"] = $params[$opt] == "1";
|
|
||||||
}
|
|
||||||
|
|
||||||
$page['title'] = getlocal("settings.title");
|
|
||||||
$page['menuid'] = "settings";
|
|
||||||
|
|
||||||
$page = array_merge($page, prepare_menu($operator));
|
|
||||||
|
|
||||||
$page['tabs'] = setup_settings_tabs(1);
|
|
||||||
|
|
||||||
$page_style = new PageStyle(PageStyle::getCurrentStyle());
|
|
||||||
$page_style->render('features', $page);
|
|
@ -35,7 +35,7 @@ $page = array(
|
|||||||
'profilePage' => MIBEW_WEB_ROOT . "/operator/operator/" . $operator['operatorid'] . '/edit',
|
'profilePage' => MIBEW_WEB_ROOT . "/operator/operator/" . $operator['operatorid'] . '/edit',
|
||||||
'updateWizard' => MIBEW_WEB_ROOT . "/install/",
|
'updateWizard' => MIBEW_WEB_ROOT . "/install/",
|
||||||
'newFeatures' => Settings::get('featuresversion') != FEATURES_VERSION,
|
'newFeatures' => Settings::get('featuresversion') != FEATURES_VERSION,
|
||||||
'featuresPage' => MIBEW_WEB_ROOT . "/operator/features.php",
|
'featuresPage' => MIBEW_WEB_ROOT . "/operator/settings/features",
|
||||||
'isOnline' => $is_online,
|
'isOnline' => $is_online,
|
||||||
'warnOffline' => true,
|
'warnOffline' => true,
|
||||||
'title' => getlocal("topMenu.admin"),
|
'title' => getlocal("topMenu.admin"),
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<div id="formmessage">{{l10n "features.saved"}}</div>
|
<div id="formmessage">{{l10n "features.saved"}}</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<form name="features" method="post" action="{{mibewRoot}}/operator/features.php">
|
<form name="features" method="post" action="{{mibewRoot}}/operator/settings/features">
|
||||||
{{csrfTokenInput}}
|
{{csrfTokenInput}}
|
||||||
<input type="hidden" name="sent" value="true"/>
|
<input type="hidden" name="sent" value="true"/>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user