2014-01-07 20:24:48 +01:00
|
|
|
<?php
|
2014-01-07 23:32:57 +01:00
|
|
|
/**
|
|
|
|
* PHP Server Monitor
|
|
|
|
* Monitor your servers and websites.
|
2014-01-07 20:24:48 +01:00
|
|
|
*
|
|
|
|
* This file is part of PHP Server Monitor.
|
|
|
|
* PHP Server Monitor is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PHP Server Monitor is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
|
2014-01-07 23:32:57 +01:00
|
|
|
*
|
|
|
|
* @package phpservermon
|
|
|
|
* @author Pepijn Over <pep@neanderthal-technology.com>
|
|
|
|
* @copyright Copyright (c) 2008-2014 Pepijn Over <pep@neanderthal-technology.com>
|
|
|
|
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
|
|
|
|
* @version Release: @package_version@
|
2014-02-10 23:48:43 +01:00
|
|
|
* @link http://www.phpservermonitor.org/
|
2014-01-07 23:32:57 +01:00
|
|
|
**/
|
2014-01-07 20:24:48 +01:00
|
|
|
|
2014-01-10 18:31:57 +01:00
|
|
|
namespace psm\Module;
|
2014-01-29 00:57:36 +01:00
|
|
|
use psm\Service\Database;
|
|
|
|
use psm\Service\Template;
|
2014-04-24 23:31:48 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2014-01-10 18:31:57 +01:00
|
|
|
|
2014-03-15 00:35:35 +01:00
|
|
|
abstract class AbstractController implements ControllerInterface {
|
2014-01-07 20:27:21 +01:00
|
|
|
|
2014-01-29 00:57:36 +01:00
|
|
|
/**
|
|
|
|
* Current action
|
|
|
|
* @var string $action
|
|
|
|
*/
|
|
|
|
protected $action;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default action
|
|
|
|
* @var string $action_default
|
|
|
|
* @see setActions()
|
|
|
|
*/
|
|
|
|
protected $action_default;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actions available for this module
|
|
|
|
* @var array $actions
|
|
|
|
* @see setActions()
|
|
|
|
* @see getAction()
|
|
|
|
*/
|
|
|
|
protected $actions = array();
|
|
|
|
|
2014-01-10 15:12:51 +01:00
|
|
|
/**
|
|
|
|
* Add footer to page?
|
|
|
|
* @var boolean $add_footer
|
2014-02-08 18:40:22 +01:00
|
|
|
* @see addFooter()
|
2014-01-10 15:12:51 +01:00
|
|
|
*/
|
|
|
|
protected $add_footer = true;
|
2014-01-07 20:27:21 +01:00
|
|
|
|
2014-02-08 18:40:22 +01:00
|
|
|
/**
|
|
|
|
* Add menu to page?
|
|
|
|
* @var boolean $add_menu
|
|
|
|
* @see addMenu()
|
|
|
|
*/
|
|
|
|
protected $add_menu = true;
|
|
|
|
|
2014-01-07 20:27:21 +01:00
|
|
|
/**
|
2014-01-29 00:57:36 +01:00
|
|
|
* Messages to show the user
|
|
|
|
* @var array $messages
|
2014-03-14 15:24:03 +01:00
|
|
|
* @see addMessage()
|
2014-01-29 00:57:36 +01:00
|
|
|
*/
|
|
|
|
protected $messages = array();
|
|
|
|
|
2014-03-28 17:00:23 +01:00
|
|
|
/**
|
|
|
|
* Sidebar to add
|
|
|
|
* @var \psm\Util\Module\Sidebar $sidebar
|
|
|
|
*/
|
|
|
|
protected $sidebar;
|
|
|
|
|
2014-04-13 02:46:31 +02:00
|
|
|
/**
|
2014-04-13 14:34:40 +02:00
|
|
|
* array of Modal to add
|
|
|
|
* @var \psm\Util\Module\ModalInterface[] $modal
|
2014-04-13 02:46:31 +02:00
|
|
|
*/
|
2014-04-13 14:34:40 +02:00
|
|
|
protected $modal = array();
|
2014-04-13 02:46:31 +02:00
|
|
|
|
2014-01-29 00:57:36 +01:00
|
|
|
/**
|
|
|
|
* Database object
|
|
|
|
* @var \psm\Service\Database $db
|
2014-01-07 20:27:21 +01:00
|
|
|
*/
|
|
|
|
protected $db;
|
|
|
|
|
|
|
|
/**
|
2014-01-29 00:57:36 +01:00
|
|
|
* Template object
|
|
|
|
* @var \psm\Service\Template $tpl
|
2014-01-07 20:27:21 +01:00
|
|
|
*/
|
|
|
|
protected $tpl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Template Id that should be added to the main template
|
|
|
|
* @var string
|
|
|
|
* @see setTemplateId() getTemplateId()
|
|
|
|
*/
|
|
|
|
protected $tpl_id;
|
2014-01-07 20:24:48 +01:00
|
|
|
|
2014-03-14 15:24:03 +01:00
|
|
|
/**
|
|
|
|
* User service
|
|
|
|
* @var \psm\Service\User $user
|
|
|
|
*/
|
|
|
|
protected $user;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Required user level for this module
|
|
|
|
* @var int $user_level_required
|
|
|
|
* @see setMinUserLevelRequired()
|
|
|
|
*/
|
|
|
|
protected $user_level_required = PSM_USER_USER;
|
|
|
|
|
2014-03-15 22:38:17 +01:00
|
|
|
/**
|
|
|
|
* Required user level for certain actions
|
|
|
|
* @var int $user_level_required_actions
|
|
|
|
* @see setMinUserLevelRequiredForAction()
|
|
|
|
*/
|
|
|
|
protected $user_level_required_actions = array();
|
|
|
|
|
2014-04-24 23:31:48 +02:00
|
|
|
/**
|
|
|
|
* XHR mode?
|
|
|
|
* @var boolean $xhr
|
|
|
|
* @see isXHR()
|
|
|
|
*/
|
|
|
|
protected $xhr = false;
|
|
|
|
|
2014-01-29 00:57:36 +01:00
|
|
|
function __construct(Database $db, Template $tpl) {
|
|
|
|
$this->db = $db;
|
|
|
|
$this->tpl = $tpl;
|
|
|
|
}
|
2014-01-07 20:24:48 +01:00
|
|
|
|
2014-01-29 00:57:36 +01:00
|
|
|
/**
|
2014-04-24 23:31:48 +02:00
|
|
|
* Initialize the controller.
|
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
2014-01-29 00:57:36 +01:00
|
|
|
*/
|
|
|
|
public function initialize() {
|
2014-03-15 22:38:17 +01:00
|
|
|
$action = psm_GET('action', psm_POST('action', $this->action_default));
|
2014-04-24 23:31:48 +02:00
|
|
|
$this->xhr = (bool) psm_GET('xhr', psm_POST('xhr', false));
|
2014-03-15 22:38:17 +01:00
|
|
|
|
2014-04-24 23:31:48 +02:00
|
|
|
if(!in_array($action, $this->actions) || !($result = $this->initializeAction($action))) {
|
|
|
|
$result = $this->initializeAction($this->action_default);
|
2014-01-29 00:57:36 +01:00
|
|
|
}
|
|
|
|
|
2014-04-24 23:31:48 +02:00
|
|
|
if($result instanceof Response) {
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no response returned from execute, create regular HTML
|
|
|
|
return $this->createHTML();
|
2014-01-29 00:57:36 +01:00
|
|
|
}
|
2014-01-07 20:27:21 +01:00
|
|
|
|
2014-01-29 00:57:36 +01:00
|
|
|
/**
|
|
|
|
* Run a specified action
|
|
|
|
*
|
2014-03-15 22:38:17 +01:00
|
|
|
* For it to run, the "execute$action" method must exist.
|
2014-01-29 00:57:36 +01:00
|
|
|
* @param string $action
|
2014-04-24 23:31:48 +02:00
|
|
|
* @return mixed FALSE when action couldnt be initialized, response otherwise
|
2014-01-29 00:57:36 +01:00
|
|
|
*/
|
|
|
|
protected function initializeAction($action) {
|
2014-03-15 22:38:17 +01:00
|
|
|
if(isset($this->user_level_required_actions[$action])) {
|
|
|
|
$ulvl = ($this->user) ? $this->user->getUserLevel() : PSM_USER_ANONYMOUS;
|
|
|
|
|
|
|
|
if($ulvl > $this->user_level_required_actions[$action]) {
|
|
|
|
// user is not allowed to access this action..
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-01-29 00:57:36 +01:00
|
|
|
$method = 'execute' . ucfirst($action);
|
|
|
|
if(method_exists($this, $method)) {
|
2014-03-15 22:38:17 +01:00
|
|
|
$this->action = $action;
|
2014-04-24 23:31:48 +02:00
|
|
|
$result = $this->$method();
|
|
|
|
// if result from execute is null, no return value given so return true to indicate a successful execute
|
|
|
|
return ($result === null) ? true : $result;
|
2014-01-29 00:57:36 +01:00
|
|
|
}
|
2014-03-15 22:38:17 +01:00
|
|
|
return false;
|
2014-01-07 20:24:48 +01:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:27:21 +01:00
|
|
|
/**
|
|
|
|
* Create the HTML code for the module.
|
2014-04-24 23:31:48 +02:00
|
|
|
*
|
2014-01-07 20:27:21 +01:00
|
|
|
* First the createHTMLLabels() will be called to add all labels to the template,
|
2014-04-24 23:31:48 +02:00
|
|
|
* Then the tpl_id set in $this->getTemplateId() will be added to the main template automatically.
|
|
|
|
* If XHR is on, no main template will be added.
|
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
2014-01-07 20:27:21 +01:00
|
|
|
*/
|
2014-01-29 00:57:36 +01:00
|
|
|
protected function createHTML() {
|
2014-04-24 23:31:48 +02:00
|
|
|
$tpl_id_content = $this->getTemplateId();
|
|
|
|
$html = '';
|
2014-03-14 15:24:03 +01:00
|
|
|
|
2014-04-24 23:31:48 +02:00
|
|
|
if($this->xhr) {
|
|
|
|
// in XHR mode, we will not add the main template
|
|
|
|
if($tpl_id_content) {
|
|
|
|
$this->createHTMLLabels();
|
|
|
|
$html = $this->tpl->display($tpl_id_content);
|
2014-04-13 14:34:40 +02:00
|
|
|
}
|
2014-04-24 23:31:48 +02:00
|
|
|
} else {
|
|
|
|
// regular request, add main frame
|
|
|
|
$tpl_data = array();
|
2014-01-07 20:27:21 +01:00
|
|
|
|
2014-04-24 23:31:48 +02:00
|
|
|
if(!empty($this->messages)) {
|
|
|
|
$this->tpl->addTemplateDataRepeat('main', 'messages', $this->messages);
|
|
|
|
}
|
|
|
|
// add menu to page?
|
|
|
|
if($this->add_menu) {
|
|
|
|
$tpl_data['html_menu'] = $this->createHTMLMenu();
|
|
|
|
}
|
|
|
|
// add modal dialog to page ?
|
|
|
|
if(sizeof($this->modal)) {
|
|
|
|
$html_modal = '';
|
|
|
|
foreach($this->modal as $modal) {
|
|
|
|
$html_modal .= $modal->createHTML();
|
|
|
|
}
|
|
|
|
$tpl_data['html_modal'] = $html_modal;
|
|
|
|
}
|
|
|
|
// add sidebar to page?
|
|
|
|
if($this->sidebar !== null) {
|
|
|
|
$tpl_data['html_sidebar'] = $this->sidebar->createHTML();
|
|
|
|
}
|
|
|
|
// add footer to page?
|
|
|
|
if($this->add_footer) {
|
|
|
|
$this->tpl->newTemplate('main_footer', 'main.tpl.html');
|
|
|
|
$tpl_data['html_footer'] = $this->tpl->getTemplate('main_footer');
|
|
|
|
$tpl_data['version'] = 'v' . PSM_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($tpl_id_content) {
|
|
|
|
$tpl_data['content'] = $this->tpl->getTemplate($tpl_id_content);
|
|
|
|
}
|
2014-01-10 17:17:41 +01:00
|
|
|
|
2014-04-24 23:31:48 +02:00
|
|
|
if(psm_update_available()) {
|
|
|
|
$tpl_data['update_available'] = str_replace('{version}', 'v'.psm_get_conf('version_update_check'), psm_get_lang('system', 'update_available'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the module's custom template to the main template to get some content
|
|
|
|
$this->setTemplateId('main');
|
|
|
|
$this->tpl->addTemplatedata($this->getTemplateId(), $tpl_data);
|
|
|
|
$this->createHTMLLabels();
|
|
|
|
$html = $this->tpl->display($this->getTemplateId());
|
2014-03-31 22:03:12 +02:00
|
|
|
}
|
|
|
|
|
2014-04-24 23:31:48 +02:00
|
|
|
$response = new Response($html);
|
2014-01-07 20:27:21 +01:00
|
|
|
|
2014-04-24 23:31:48 +02:00
|
|
|
return $response;
|
2014-01-07 20:27:21 +01:00
|
|
|
}
|
|
|
|
|
2014-03-14 15:24:03 +01:00
|
|
|
/**
|
|
|
|
* Create HTML code for the menu
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function createHTMLMenu() {
|
|
|
|
$ulvl = ($this->user) ? $this->user->getUserLevel() : PSM_USER_ANONYMOUS;
|
|
|
|
|
|
|
|
$tpl_id = 'main_menu';
|
|
|
|
$this->tpl->newTemplate($tpl_id, 'main.tpl.html');
|
|
|
|
|
|
|
|
$tpl_data = array(
|
2014-03-15 00:35:35 +01:00
|
|
|
'label_help' => psm_get_lang('menu', 'help'),
|
2014-03-15 21:47:55 +01:00
|
|
|
'label_profile' => psm_get_lang('users', 'profile'),
|
2014-03-14 15:24:03 +01:00
|
|
|
'label_logout' => psm_get_lang('login', 'logout'),
|
2014-03-15 21:47:55 +01:00
|
|
|
'url_profile' => psm_build_url(array('mod' => 'user_profile')),
|
2014-03-14 15:24:03 +01:00
|
|
|
'url_logout' => psm_build_url(array('logout' => 1)),
|
|
|
|
);
|
|
|
|
|
|
|
|
switch($ulvl) {
|
|
|
|
case PSM_USER_ADMIN:
|
2014-03-30 14:37:09 +02:00
|
|
|
$items = array('server_status', 'server', 'server_log', 'user', 'config', 'server_update');
|
2014-03-14 15:24:03 +01:00
|
|
|
break;
|
|
|
|
case PSM_USER_USER:
|
2014-03-30 14:37:09 +02:00
|
|
|
$items = array('server_status', 'server', 'server_log', 'server_update');
|
2014-03-14 15:24:03 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$items = array();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$menu = array();
|
|
|
|
foreach($items as $key) {
|
|
|
|
$menu[] = array(
|
2014-03-15 00:35:35 +01:00
|
|
|
'active' => ($key == psm_GET('mod')) ? 'active' : '',
|
|
|
|
'url' => psm_build_url(array('mod' => $key)),
|
|
|
|
'label' => psm_get_lang('menu', $key),
|
2014-03-14 15:24:03 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if(!empty($menu)) {
|
|
|
|
$this->tpl->addTemplateDataRepeat($tpl_id, 'menu', $menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($ulvl != PSM_USER_ANONYMOUS) {
|
|
|
|
$user = $this->user->getUser();
|
|
|
|
$tpl_data['label_usermenu'] = str_replace(
|
|
|
|
'%user_name%',
|
|
|
|
$user->name,
|
|
|
|
psm_get_lang('login', 'welcome_usermenu')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$this->tpl->addTemplateData($tpl_id, $tpl_data);
|
|
|
|
|
|
|
|
return $this->tpl->getTemplate($tpl_id);
|
|
|
|
}
|
|
|
|
|
2014-01-07 20:27:21 +01:00
|
|
|
/**
|
|
|
|
* Use this to add language specific labels to template
|
|
|
|
*
|
|
|
|
* @see createHTML()
|
|
|
|
*/
|
|
|
|
protected function createHTMLLabels() {
|
|
|
|
$this->tpl->addTemplateData(
|
|
|
|
'main',
|
|
|
|
array(
|
2014-01-10 18:31:57 +01:00
|
|
|
'title' => strtoupper(psm_get_lang('system', 'title')),
|
2014-02-08 18:40:22 +01:00
|
|
|
'label_back_to_top' => psm_get_lang('system', 'back_to_top'),
|
2014-01-07 20:27:21 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a template id that will be added to the main template automatically
|
|
|
|
* once you call the parent::createHTML()
|
|
|
|
*
|
|
|
|
* @param string $tpl_id
|
|
|
|
* @param string $tpl_file if given, the tpl_id will be created automatically from this file
|
|
|
|
* @see getTemplateId() createHTML()
|
|
|
|
*/
|
|
|
|
public function setTemplateId($tpl_id, $tpl_file = null) {
|
|
|
|
$this->tpl_id = $tpl_id;
|
|
|
|
|
|
|
|
if($tpl_file != null) {
|
|
|
|
// tpl_file given, try to load the template..
|
|
|
|
$this->tpl->newTemplate($tpl_id, $tpl_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the mpalte id that will be added to the main template
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @see setTemplateId()
|
|
|
|
*/
|
|
|
|
public function getTemplateId() {
|
|
|
|
return $this->tpl_id;
|
2014-01-07 20:24:48 +01:00
|
|
|
}
|
2014-01-10 15:12:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide or show the footer of the page
|
|
|
|
* @param boolean $value
|
|
|
|
*/
|
|
|
|
protected function addFooter($value) {
|
|
|
|
$this->add_footer = $value;
|
|
|
|
}
|
2014-01-29 00:57:36 +01:00
|
|
|
|
2014-02-08 18:40:22 +01:00
|
|
|
/**
|
|
|
|
* Hide or show the menu of the page
|
|
|
|
* @param boolean $value
|
|
|
|
*/
|
|
|
|
protected function addMenu($value) {
|
|
|
|
$this->add_menu = $value;
|
|
|
|
}
|
|
|
|
|
2014-01-29 00:57:36 +01:00
|
|
|
/**
|
|
|
|
* Set actions available
|
|
|
|
* @param string|array $actions
|
|
|
|
* @param string $default default action
|
|
|
|
* @param boolean $append if TRUE, the actions will be added to the current actions
|
|
|
|
* @return psm\Module\AbstractModule
|
|
|
|
* @see getAction()
|
|
|
|
*/
|
|
|
|
protected function setActions($actions, $default = null, $append = true) {
|
|
|
|
if(!is_array($actions)) {
|
|
|
|
$actions = array($actions);
|
|
|
|
}
|
|
|
|
if($append) {
|
|
|
|
$this->actions = array_merge($actions);
|
|
|
|
} else {
|
|
|
|
$this->actions = $actions;
|
|
|
|
}
|
|
|
|
if($default !== null) {
|
|
|
|
$this->action_default = $default;
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current action
|
|
|
|
* @return string
|
|
|
|
* @see setActions()
|
|
|
|
*/
|
|
|
|
public function getAction() {
|
|
|
|
return $this->action;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add one or multiple message to the stack to be displayed to the user
|
|
|
|
* @param string|array $msg
|
2014-03-28 16:24:03 +01:00
|
|
|
* @param string $shortcode info/success/warning/error
|
2014-01-29 00:57:36 +01:00
|
|
|
* @return \psm\Module\AbstractModule
|
|
|
|
*/
|
2014-03-28 16:24:03 +01:00
|
|
|
public function addMessage($msg, $shortcode = 'info') {
|
2014-01-29 00:57:36 +01:00
|
|
|
if(!is_array($msg)) {
|
|
|
|
$msg = array($msg);
|
|
|
|
}
|
2014-03-28 16:24:03 +01:00
|
|
|
switch($shortcode) {
|
|
|
|
case 'error':
|
|
|
|
$icon = 'exclamation-sign';
|
|
|
|
break;
|
|
|
|
case 'success':
|
|
|
|
$icon = 'ok-sign';
|
|
|
|
break;
|
|
|
|
case 'warning':
|
|
|
|
$icon = 'question-sign';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$icon = 'info-sign';
|
|
|
|
break;
|
2014-03-14 15:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach($msg as $m) {
|
|
|
|
$this->messages[] = array(
|
|
|
|
'message' => $m,
|
|
|
|
'shortcode' => $shortcode,
|
2014-03-28 16:24:03 +01:00
|
|
|
'icon' => $icon,
|
2014-03-14 15:24:03 +01:00
|
|
|
);
|
|
|
|
}
|
2014-01-29 00:57:36 +01:00
|
|
|
return $this;
|
|
|
|
}
|
2014-01-07 20:24:48 +01:00
|
|
|
|
2014-03-14 15:24:03 +01:00
|
|
|
/**
|
|
|
|
* Set user service
|
|
|
|
* @param \psm\Service\User $user
|
|
|
|
*/
|
|
|
|
public function setUser(\psm\Service\User $user) {
|
|
|
|
$this->user = $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-11 01:14:12 +02:00
|
|
|
* Set the minimum required user level for this controller
|
2014-03-14 15:24:03 +01:00
|
|
|
* @param int $level
|
2014-03-15 22:38:17 +01:00
|
|
|
* @return \psm\Module\AbstractController
|
2014-03-14 15:24:03 +01:00
|
|
|
*/
|
|
|
|
public function setMinUserLevelRequired($level) {
|
|
|
|
$this->user_level_required = intval($level);
|
2014-03-15 22:38:17 +01:00
|
|
|
return $this;
|
2014-03-14 15:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-11 01:14:12 +02:00
|
|
|
* Get the minimum required user level for this controller
|
2014-03-14 15:24:03 +01:00
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getMinUserLevelRequired() {
|
|
|
|
return $this->user_level_required;
|
|
|
|
}
|
2014-03-15 22:38:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the minimum required user level for a certain action.
|
|
|
|
*
|
|
|
|
* Use this only if one of the access is more restricted than the entire controller
|
|
|
|
* @param int $level
|
|
|
|
* @param string|array $actions one or more actions to set this level for
|
|
|
|
* @return \psm\Module\AbstractController
|
|
|
|
* @see setMinUserLevelRequired()
|
|
|
|
*/
|
|
|
|
public function setMinUserLevelRequiredForAction($level, $actions) {
|
|
|
|
if(!is_array($actions)) {
|
|
|
|
$actions = array($actions);
|
|
|
|
}
|
|
|
|
foreach($actions as $action) {
|
|
|
|
$this->user_level_required_actions[$action] = intval($level);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
2014-03-28 17:00:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a sidebar to the page
|
|
|
|
* @param \psm\Util\Module\SidebarInterface $sidebar
|
|
|
|
* @return \psm\Module\ControllerInterface
|
|
|
|
*/
|
|
|
|
public function setSidebar(\psm\Util\Module\SidebarInterface $sidebar) {
|
|
|
|
$this->sidebar = $sidebar;
|
|
|
|
return $this;
|
|
|
|
}
|
2014-04-13 02:46:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a modal dialog to the page
|
|
|
|
* @param \psm\Util\Module\ModalInterface $modal
|
|
|
|
* @return \psm\Module\ControllerInterface
|
|
|
|
*/
|
2014-04-13 14:34:40 +02:00
|
|
|
public function addModal(\psm\Util\Module\ModalInterface $modal) {
|
|
|
|
$this->modal[$modal->getModalID()] = $modal;
|
2014-04-13 02:46:31 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2014-04-24 23:31:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if XHR is on
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function isXHR() {
|
|
|
|
return $this->xhr;
|
|
|
|
}
|
2014-03-14 15:24:03 +01:00
|
|
|
}
|