freenetis-github/application/libraries/MY_Controller.php @ 74a7dbca
8baed187 | Michal Kliment | <?php defined('SYSPATH') or die('No direct script access.');
|
|
/*
|
|||
* This file is part of open source system FreenetIS
|
|||
* and it is released under GPLv3 licence.
|
|||
74a7dbca | Michal Kliment | *
|
|
8baed187 | Michal Kliment | * More info about licence can be found:
|
|
* http://www.gnu.org/licenses/gpl-3.0.html
|
|||
74a7dbca | Michal Kliment | *
|
|
8baed187 | Michal Kliment | * More info about project can be found:
|
|
* http://www.freenetis.org/
|
|||
74a7dbca | Michal Kliment | *
|
|
8baed187 | Michal Kliment | */
|
|
// numbers of errors
|
|||
define('ACCESS', 1);
|
|||
define('EMAIL', 2);
|
|||
define('DATABASE', 3);
|
|||
define('DATABASE_DOWNGRATE', 9);
|
|||
define('DATABASE_OLD_MECHANISM', 10);
|
|||
c1bdc1c4 | Michal Kliment | define('DATABASE_UPGRADE_NOT_ENABLED', 11);
|
|
8baed187 | Michal Kliment | define('RECORD', 4);
|
|
define('PAGE', 5);
|
|||
define('WRITABLE', 7);
|
|||
define('READONLY', 8);
|
|||
// numbers of warnings, their identifier numbers have to differ from error messages
|
|||
// for example when programmer misleads error and warning
|
|||
define('PARAMETER', 1001);
|
|||
/**
|
|||
* Main controller creates menu, handles changes in svn repository (database upgrade), ...
|
|||
*
|
|||
* BE CAREFUL HERE, CATCH EVERY EXCEPTION, OTHERWISE FREENETIS
|
|||
* WITH JUST SMALL ERROR BECOMES COMPLETELY UNUSABLE
|
|||
*/
|
|||
class Controller extends Controller_Core
|
|||
{
|
|||
/** @var integer */
|
|||
c1bdc1c4 | Michal Kliment | const ICON_ERROR = 1;
|
|
8baed187 | Michal Kliment | /** @var integer */
|
|
const ICON_GOOD = 2;
|
|||
/** @var integer */
|
|||
const ICON_HELP = 3;
|
|||
/** @var integer */
|
|||
const ICON_INFO = 4;
|
|||
/** @var integer */
|
|||
const ICON_WARNING = 5;
|
|||
/**
|
|||
* Controller singleton
|
|||
74a7dbca | Michal Kliment | *
|
|
8baed187 | Michal Kliment | * @var Controller
|
|
*/
|
|||
private static $instance;
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | /**
|
|
* Paths for which login is not required
|
|||
*
|
|||
* @var array
|
|||
*/
|
|||
private static $login_not_required = array
|
|||
(
|
|||
/* login, scheduler, instalation */
|
|||
'login',
|
|||
'forgotten_password',
|
|||
'scheduler/run',
|
|||
'installation',
|
|||
'setup_config',
|
|||
'setup_config/htaccess',
|
|||
'setup_config/setup',
|
|||
'redirect/logo',
|
|||
74a7dbca | Michal Kliment | 'email/displayed',
|
|
'email/preview',
|
|||
8baed187 | Michal Kliment | /* registration */
|
|
'registration',
|
|||
'registration/complete',
|
|||
'js/registration',
|
|||
'json/get_streets_by_town',
|
|||
c1bdc1c4 | Michal Kliment | 'json/get_address',
|
|
8baed187 | Michal Kliment | 'address_points/get_gps_by_address',
|
|
c1bdc1c4 | Michal Kliment | 'address_points/get_gps_by_address_string',
|
|
8baed187 | Michal Kliment | );
|
|
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | /** @var unknown_type */
|
|
public $arr;
|
|||
/** @var Setting_Model Settings */
|
|||
public $settings = NULL;
|
|||
/** @var integer */
|
|||
public $popup = 0;
|
|||
/** @var integer */
|
|||
public $dialog = 0;
|
|||
/** @var boolean */
|
|||
public $noredirect = FALSE;
|
|||
/** @var boolean */
|
|||
public $user_has_voip = 0;
|
|||
/** @var string */
|
|||
public $ip_address_span = '';
|
|||
/** @var integer */
|
|||
public $unread_user_mails = 0;
|
|||
/** @var integer */
|
|||
c1bdc1c4 | Michal Kliment | public $count_of_unclosed_logged_errors = 0;
|
|
8baed187 | Michal Kliment | /** @var integer */
|
|
public $devices_down_count = 0;
|
|||
c1bdc1c4 | Michal Kliment | /** @var Database_Result */
|
|
public $user_favourites_pages = NULL;
|
|||
/** @var boolean $axo_doc_access Enable access to AXO doc */
|
|||
public $axo_doc_access = FALSE;
|
|||
8baed187 | Michal Kliment | /** @var integer $member_id ID of logged member */
|
|
protected $member_id;
|
|||
/** @var integer $user_id ID of logged user */
|
|||
protected $user_id;
|
|||
/** @var integer $account_id ID of logged member account */
|
|||
protected $member_account_id = 1;
|
|||
/** @var Session */
|
|||
protected $session;
|
|||
74a7dbca | Michal Kliment | /** @var ServiceFactory */
|
|
protected $services;
|
|||
8baed187 | Michal Kliment | /** @var $groups_aro_map Groups_aro_map_Model */
|
|
private $groups_aro_map;
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | /**
|
|
* Contruct of controller, creates singleton or return it
|
|||
*/
|
|||
public function __construct()
|
|||
{
|
|||
parent::__construct();
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | // This part only needs to be run once
|
|
if (self::$instance === NULL)
|
|||
{
|
|||
// init sessions
|
|||
$this->session = Session::instance();
|
|||
74a7dbca | Michal Kliment | ||
// init services
|
|||
$this->services = new ServiceFactory();
|
|||
c1bdc1c4 | Michal Kliment | // store user ID from session
|
|
$this->user_id = $this->session->get('user_id', 0);
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // store member ID from session
|
|
$this->member_id = $this->session->get('member_id', 0);
|
|||
8baed187 | Michal Kliment | ||
// test if visitor is logged in, or he accesses public
|
|||
// controllers like registration, redirect, installation, etc.
|
|||
if (!in_array(url_lang::current(), self::$login_not_required) &&
|
|||
c1bdc1c4 | Michal Kliment | url_lang::current(1) != 'web_interface' &&
|
|
74a7dbca | Michal Kliment | url_lang::current(1) != 'api' &&
|
|
c1bdc1c4 | Michal Kliment | url_lang::current(2) != 'devices/export' &&
|
|
!$this->user_id)
|
|||
8baed187 | Michal Kliment | {
|
|
// Not logged in - redirect to login page
|
|||
$this->session->set_flash('err_message', __('Must be logged in'));
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | // Do not logout after login
|
|
c1bdc1c4 | Michal Kliment | if (url_lang::current(1) != 'login' &&
|
|
8baed187 | Michal Kliment | url_lang::current(1) != 'js')
|
|
{
|
|||
$this->session->set('referer', url_lang::current());
|
|||
}
|
|||
else
|
|||
{
|
|||
$this->session->set('referer', '');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | // Redirect to login
|
|
url::redirect('login');
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | // Die
|
|
die();
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | // init settings
|
|
$this->settings = new Settings();
|
|||
// if true, freenetis will run in popup mode (without header and menu)
|
|||
$this->popup = (isset($_GET['popup']) && $_GET['popup']) ? 1 : 0;
|
|||
// if true, freenetis will run in text mod for dialog
|
|||
$this->dialog = (isset($_GET['dialog']) && $_GET['dialog']) ? 1 : 0;
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | // if true, method redirect will not redirect
|
|
$this->noredirect = ($this->input->get('noredirect') || $this->input->post('noredirect'));
|
|||
// config file doesn't exist, we must create it
|
|||
if (!file_exists('config.php') || !file_exists('.htaccess'))
|
|||
{
|
|||
// protection before loop
|
|||
if (url_lang::current(1) == 'setup_config')
|
|||
return;
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | if (!file_exists('.htaccess'))
|
|
{
|
|||
Settings::set('index_page', 1);
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | url::redirect('setup_config');
|
|
}
|
|||
// protection before loop
|
|||
if (url_lang::current(1) == 'installation')
|
|||
{
|
|||
return;
|
|||
}
|
|||
74a7dbca | Michal Kliment | // test database connection
|
|
if (!db::test())
|
|||
{
|
|||
self::error(DATABASE);
|
|||
}
|
|||
// db schema version is null or domain not filled => we must run install
|
|||
if (!Version::get_db_version() || !Settings::get('domain'))
|
|||
{
|
|||
url::redirect('installation');
|
|||
}
|
|||
// db schema is not up to date => we must run upgrade
|
|||
else if (!Version::is_db_up_to_date())
|
|||
{
|
|||
$this->upgrade_db();
|
|||
}
|
|||
c1bdc1c4 | Michal Kliment | // load these variables only if preprocessor is enabled and user is logged
|
|
if ($this->is_preprocesor_enabled() && $this->user_id)
|
|||
8baed187 | Michal Kliment | {
|
|
// for preprocessing some variable
|
|||
try
|
|||
{
|
|||
$this->preprocessor();
|
|||
}
|
|||
catch(Exception $e)
|
|||
{
|
|||
c1bdc1c4 | Michal Kliment | Log::add_exception($e);
|
|
8baed187 | Michal Kliment | }
|
|
}
|
|||
// Singleton instance
|
|||
self::$instance = $this;
|
|||
}
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | /**
|
|
* Singleton instance of Controller.
|
|||
74a7dbca | Michal Kliment | *
|
|
8baed187 | Michal Kliment | * @author Michal Kliment
|
|
* @return Controller object
|
|||
*/
|
|||
public static function & instance()
|
|||
{
|
|||
// Create the instance if it does not exist
|
|||
empty(self::$instance) and new Controller;
|
|||
return self::$instance;
|
|||
}
|
|||
/**
|
|||
* Function shows error of given message number.
|
|||
74a7dbca | Michal Kliment | *
|
|
8baed187 | Michal Kliment | * @param integer $message_type
|
|
* @param string $content
|
|||
*/
|
|||
public static function error($message_type, $content = NULL)
|
|||
{
|
|||
c1bdc1c4 | Michal Kliment | $response_code = NULL;
|
|
$fatal = FALSE;
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | switch ($message_type)
|
|
{
|
|||
case ACCESS:
|
|||
$message = url_lang::lang('states.Access denied');
|
|||
c1bdc1c4 | Michal Kliment | $response_code = 403; // Forbidden
|
|
8baed187 | Michal Kliment | break;
|
|
case EMAIL:
|
|||
74a7dbca | Michal Kliment | $message = url_lang::lang('states.Failed to send e-mail') .
|
|
8baed187 | Michal Kliment | '<br />' . url_lang::lang('states.Please check settings.');
|
|
c1bdc1c4 | Michal Kliment | $response_code = 500; // Internal server error
|
|
8baed187 | Michal Kliment | break;
|
|
case DATABASE:
|
|||
$message = url_lang::lang('states.Failed to connect to database') .
|
|||
'<br />' . url_lang::lang('states.Please check settings.');
|
|||
c1bdc1c4 | Michal Kliment | $response_code = 500; // Internal server error
|
|
$fatal = TRUE;
|
|||
8baed187 | Michal Kliment | break;
|
|
case DATABASE_DOWNGRATE:
|
|||
$message = url_lang::lang('states.Failed to update database') .
|
|||
'<br />' . url_lang::lang('states.Downgrade not allowed.');
|
|||
c1bdc1c4 | Michal Kliment | $response_code = 500; // Internal server error
|
|
$fatal = TRUE;
|
|||
8baed187 | Michal Kliment | break;
|
|
case DATABASE_OLD_MECHANISM:
|
|||
$message = url_lang::lang('states.Failed to update database') .
|
|||
'<br /><br /><span style="font-size:12px">' .
|
|||
url_lang::lang('help.old_upgrade_system') . '</span>';
|
|||
c1bdc1c4 | Michal Kliment | $response_code = 500; // Internal server error
|
|
$fatal = TRUE;
|
|||
break;
|
|||
case DATABASE_UPGRADE_NOT_ENABLED:
|
|||
$message = url_lang::lang('states.Failed to update database');
|
|||
$response_code = 500; // Internal server error
|
|||
$fatal = TRUE;
|
|||
8baed187 | Michal Kliment | break;
|
|
case RECORD:
|
|||
$message = url_lang::lang('states.This record does not exist');
|
|||
c1bdc1c4 | Michal Kliment | $response_code = 404; // Not found
|
|
8baed187 | Michal Kliment | break;
|
|
case PAGE:
|
|||
$message = url_lang::lang('states.Page not found');
|
|||
c1bdc1c4 | Michal Kliment | $response_code = 404; // Not found
|
|
8baed187 | Michal Kliment | break;
|
|
case WRITABLE:
|
|||
$message = url_lang::lang('states.Directory or file is not writable.');
|
|||
c1bdc1c4 | Michal Kliment | $response_code = 500; // Internal server error
|
|
8baed187 | Michal Kliment | break;
|
|
case READONLY:
|
|||
$message = url_lang::lang('states.Item is read only.');
|
|||
c1bdc1c4 | Michal Kliment | $response_code = 403; // Internal server error
|
|
8baed187 | Michal Kliment | break;
|
|
default:
|
|||
$message = url_lang::lang('states.Unknown error message');
|
|||
c1bdc1c4 | Michal Kliment | $response_code = 500; // Internal server error
|
|
8baed187 | Michal Kliment | break;
|
|
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | self::showbox($message, self::ICON_ERROR, $content, $response_code, $fatal);
|
|
8baed187 | Michal Kliment | }
|
|
/**
|
|||
* Function shows warning of given message number.
|
|||
74a7dbca | Michal Kliment | *
|
|
8baed187 | Michal Kliment | * @param integer $message_type
|
|
* @param string $content
|
|||
*/
|
|||
public static function warning($message_type, $content = NULL)
|
|||
{
|
|||
c1bdc1c4 | Michal Kliment | $response_code = NULL;
|
|
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | switch ($message_type)
|
|
{
|
|||
case PARAMETER:
|
|||
$message = url_lang::lang('states.Parameter required');
|
|||
c1bdc1c4 | Michal Kliment | $response_code = 404; // Internal server error
|
|
8baed187 | Michal Kliment | break;
|
|
default:
|
|||
$message = url_lang::lang('states.Unknown warning message');
|
|||
c1bdc1c4 | Michal Kliment | $response_code = 500; // Internal server error
|
|
8baed187 | Michal Kliment | break;
|
|
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | self::showbox($message, self::ICON_WARNING, $content, $response_code);
|
|
8baed187 | Michal Kliment | }
|
|
/**
|
|||
* Function renders error and warning messages.
|
|||
74a7dbca | Michal Kliment | *
|
|
c1bdc1c4 | Michal Kliment | * @param string $message Message to display
|
|
* @param integer $type Type of message (error, info, warning, etc.)
|
|||
* @param string $content Some message that describe message in more detail way
|
|||
* @param string $http_response_code Send some response code (xxx)
|
|||
* @param boolean $fatal_error Is this error a fatal error?
|
|||
8baed187 | Michal Kliment | */
|
|
74a7dbca | Michal Kliment | private static function showbox($message, $type, $content = NULL,
|
|
c1bdc1c4 | Michal Kliment | $http_response_code = NULL, $fatal_error = FALSE)
|
|
8baed187 | Michal Kliment | {
|
|
c1bdc1c4 | Michal Kliment | if ($fatal_error)
|
|
{
|
|||
$view = new View('main_statesbox');
|
|||
}
|
|||
else
|
|||
{
|
|||
$view = new View('main');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | $view->content = new View('statesbox');
|
|
$src = NULL;
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | switch ($type)
|
|
{
|
|||
case self::ICON_ERROR:
|
|||
$view->title = __('Error');
|
|||
$src = 'media/images/states/error.png';
|
|||
break;
|
|||
case self::ICON_GOOD:
|
|||
$view->title = __('Good');
|
|||
$src = 'media/images/states/good.png';
|
|||
break;
|
|||
case self::ICON_HELP:
|
|||
$view->title = __('Help');
|
|||
$src = 'media/images/states/help.png';
|
|||
break;
|
|||
case self::ICON_INFO:
|
|||
$view->title = __('Info');
|
|||
$src = 'media/images/states/info.png';
|
|||
break;
|
|||
case self::ICON_WARNING:
|
|||
$view->title = __('Warning');
|
|||
$src = 'media/images/states/warning.png';
|
|||
break;
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | if ($http_response_code)
|
|
{
|
|||
header("HTTP/1.1 $http_response_code");
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | $view->content->icon = html::image(array
|
|
(
|
|||
'src' => $src,
|
|||
'width' => '100',
|
|||
'height' => '100',
|
|||
'alt' => 'Image',
|
|||
'class' => 'noborder'
|
|||
));
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | $view->content->message = $message;
|
|
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | if (isset($content))
|
|
{
|
|||
$view->content->content = $content;
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | $view->loading_hide = TRUE;
|
|
$view->render(TRUE);
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | // must be die() - else it will be render twice !
|
|
die();
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
/**
|
|||
* Upgrade DB to current FreenetIS version.
|
|||
*/
|
|||
private function upgrade_db()
|
|||
{
|
|||
try
|
|||
{
|
|||
$this->services->injectCoreDatabaseInit()
|
|||
->make(server::base_dir() . '/upload/mutex');
|
|||
}
|
|||
catch (InvalidArgumentException $iaex)
|
|||
{
|
|||
self::error(WRITABLE, server::base_dir() . 'upload');
|
|||
}
|
|||
catch (NotEnabledDbUpgradeException $neu)
|
|||
{
|
|||
self::error(DATABASE_UPGRADE_NOT_ENABLED, $neu->getMessage());
|
|||
}
|
|||
catch (OldMechanismDbUpgradeException $ome)
|
|||
{
|
|||
self::error(DATABASE_OLD_MECHANISM);
|
|||
}
|
|||
catch (DowngrateDbUpgradeException $dde)
|
|||
{
|
|||
self::error(DATABASE_DOWNGRATE);
|
|||
}
|
|||
catch (Exception $e)
|
|||
{
|
|||
throw new Exception(
|
|||
__('Database upgrade failed') . ': ' .
|
|||
$e->getMessage(), 0, $e
|
|||
);
|
|||
}
|
|||
}
|
|||
8baed187 | Michal Kliment | /**
|
|
* Checks if user is in ARO group
|
|||
*
|
|||
* @author Ondřej Fibich
|
|||
* @param integer $group_id ARO group ID
|
|||
* @param integer $aro_id User ID
|
|||
* @return boolean true if exists false otherwise
|
|||
*/
|
|||
public function is_user_in_group($aro_group_id, $aro_id)
|
|||
{
|
|||
74a7dbca | Michal Kliment | return $this->services->injectCoreAcl()
|
|
->is_user_in_group($aro_group_id, $aro_id);
|
|||
8baed187 | Michal Kliment | }
|
|
/**
|
|||
* Fuction checks access rights
|
|||
* Return true if currently logged user (stored in $_SESSION['user_id'])
|
|||
* may view own $axo_value object in $axo_section
|
|||
* (and in variable $member_id is his own id of member) or if currently logged user
|
|||
* may view all $axo_value object in $axo_section else return false
|
|||
74a7dbca | Michal Kliment | *
|
|
8baed187 | Michal Kliment | * @param $axo_section Group of objects to view
|
|
* @param $axo_value Object to view
|
|||
* @param $member_id Optional variable, id of other member
|
|||
74a7dbca | Michal Kliment | * who is being showed by logged member
|
|
8baed187 | Michal Kliment | * @param boolean $force_own Force to use own rules for not logged user
|
|
* Used at: Phone_invoices_Controller#user_field()
|
|||
* @return boolean returns true if member has enough access rights
|
|||
*/
|
|||
74a7dbca | Michal Kliment | public function acl_check_view($axo_section, $axo_value, $member_id = NULL,
|
|
$force_own = FALSE)
|
|||
8baed187 | Michal Kliment | {
|
|
74a7dbca | Michal Kliment | return $this->services->injectCoreAcl()
|
|
->can_view($axo_section, $axo_value, $member_id, $force_own);
|
|||
8baed187 | Michal Kliment | }
|
|
/**
|
|||
* Fuction checks access rights
|
|||
* Return true if currently logged user (stored in $_SESSION['user_id'])
|
|||
* may view own $axo_value object in $axo_section
|
|||
* (and in variable $member_id is his own id of member) or if currently logged user
|
|||
* may edit all $axo_value object in $axo_section else return false
|
|||
*
|
|||
* @param $axo_section Group of objects to edit
|
|||
* @param $axo_value Object to edit
|
|||
* @param $member_id Optional variable, id of other member
|
|||
* who is being showed by logged member
|
|||
* @param boolean $force_own Force to use own rules for not logged user
|
|||
* Used at: Phone_invoices_Controller#user_field()
|
|||
* @return boolean Returns true if member has enough access rights
|
|||
*/
|
|||
public function acl_check_edit(
|
|||
$axo_section, $axo_value, $member_id = NULL, $force_own = FALSE)
|
|||
{
|
|||
74a7dbca | Michal Kliment | return $this->services->injectCoreAcl()
|
|
->can_edit($axo_section, $axo_value, $member_id, $force_own);
|
|||
8baed187 | Michal Kliment | }
|
|
/**
|
|||
* Fuction checks access rights
|
|||
* Return true if currently logged user (stored in $_SESSION['user_id'])
|
|||
* may view own $axo_value object in $axo_section
|
|||
* (and in variable $member_id is his own id of member) or if currently logged user
|
|||
* may add all $axo_value object in $axo_section else return false
|
|||
*
|
|||
* @param $axo_section Group of objects to edit
|
|||
* @param $axo_value Object to add
|
|||
* @param $member_id Optional variable, id of other member
|
|||
* who is being showed by logged member
|
|||
* @param boolean $force_own Force to use own rules for not logged user
|
|||
* Used at: Phone_invoices_Controller#user_field()
|
|||
* @return boolean Returns true if member has enough access rights
|
|||
*/
|
|||
public function acl_check_new(
|
|||
$axo_section, $axo_value, $member_id = NULL, $force_own = FALSE)
|
|||
{
|
|||
74a7dbca | Michal Kliment | return $this->services->injectCoreAcl()
|
|
->can_create($axo_section, $axo_value, $member_id, $force_own);
|
|||
8baed187 | Michal Kliment | }
|
|
/**
|
|||
* Fuction checks access rights
|
|||
* Return true if currently logged user (stored in $_SESSION['user_id'])
|
|||
* may view own $axo_value object in $axo_section
|
|||
* (and in variable $member_id is his own id of member) or if currently logged user
|
|||
* may delete all $axo_value object in $axo_section else return false
|
|||
*
|
|||
* @param $axo_section Group of objects to edit
|
|||
* @param $axo_value Object to delete
|
|||
* @param $member_id Optional variable, id of other member
|
|||
* who is being showed by logged member
|
|||
* @param boolean $force_own Force to use own rules for not logged user
|
|||
* Used at: Phone_invoices_Controller#user_field()
|
|||
* @return boolean Returns true if member has enough access rights
|
|||
*/
|
|||
public function acl_check_delete(
|
|||
$axo_section, $axo_value, $member_id = NULL, $force_own = FALSE)
|
|||
{
|
|||
74a7dbca | Michal Kliment | return $this->services->injectCoreAcl()
|
|
->can_delete($axo_section, $axo_value, $member_id, $force_own);
|
|||
8baed187 | Michal Kliment | }
|
|
/**
|
|||
c1bdc1c4 | Michal Kliment | * This methods defines whether the preprocessor of MY_Controller is loaded
|
|
74a7dbca | Michal Kliment | * or not. By default preprocessor is loaded, for changing of this state
|
|
c1bdc1c4 | Michal Kliment | * this method should be overriden in child class. (#328)
|
|
74a7dbca | Michal Kliment | *
|
|
c1bdc1c4 | Michal Kliment | * @author Ondřej Fibich
|
|
* @return boolean Is preprocessor loaded?
|
|||
8baed187 | Michal Kliment | */
|
|
c1bdc1c4 | Michal Kliment | protected function is_preprocesor_enabled()
|
|
8baed187 | Michal Kliment | {
|
|
c1bdc1c4 | Michal Kliment | return TRUE;
|
|
8baed187 | Michal Kliment | }
|
|
/**
|
|||
* Function to preprocessing of some useful variables
|
|||
74a7dbca | Michal Kliment | *
|
|
8baed187 | Michal Kliment | * @author Michal Kliment
|
|
*/
|
|||
private function preprocessor()
|
|||
{
|
|||
// helper class
|
|||
c1bdc1c4 | Michal Kliment | $pm = new Preprocessor_Model();
|
|
$ra_ip = server::remote_addr();
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | // boolean variable if user has active voip number (for menu rendering)
|
|
c1bdc1c4 | Michal Kliment | $this->user_has_voip = (bool) $pm->has_voip_sips($this->user_id);
|
|
8baed187 | Michal Kliment | // count of unread mail messages of user
|
|
c1bdc1c4 | Michal Kliment | $this->unread_user_mails = $pm->count_all_unread_inbox_messages_by_user_id($this->user_id);
|
|
8baed187 | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // is this page favourite
|
|
$this->is_favourite = $pm->is_users_favourite($this->user_id, url_lang::current());
|
|||
// gets account id of memeber (do not use Member_Model::ASSOCIATION here!)
|
|||
8baed187 | Michal Kliment | if ($this->acl_check_view('Accounts_Controller', 'transfers', $this->member_id) &&
|
|
$this->member_id != 1)
|
|||
{
|
|||
c1bdc1c4 | Michal Kliment | $this->member_account_id = $pm->get_first_member_account_id($this->member_id);
|
|
8baed187 | Michal Kliment | }
|
|
c1bdc1c4 | Michal Kliment | ||
8baed187 | Michal Kliment | // ip address span
|
|
c1bdc1c4 | Michal Kliment | $this->ip_address_span = $ra_ip;
|
|
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | // DZOLO (2011-09-05)
|
|
// This function is wery slow, when internet connection is off.
|
|||
c1bdc1c4 | Michal Kliment | /*if (($ptr_record = dns::get_ptr_record($this->ip_address_span)) != '')
|
|
8baed187 | Michal Kliment | {
|
|
$this->ip_address_span .= ' <i>(' . $ptr_record . ')</i>';
|
|||
c1bdc1c4 | Michal Kliment | }*/
|
|
8baed187 | Michal Kliment | ||
// allowed subnets are enabled
|
|||
if (Settings::get('allowed_subnets_enabled') && $this->member_id &&
|
|||
$this->acl_check_edit(
|
|||
c1bdc1c4 | Michal Kliment | 'Allowed_subnets_Controller', 'allowed_subnet', $this->member_id
|
|
8baed187 | Michal Kliment | ))
|
|
{
|
|||
// toggle button between allowed subnets
|
|||
c1bdc1c4 | Michal Kliment | $as = $pm->get_allowed_subnet_by_member_and_ip_address(
|
|
8baed187 | Michal Kliment | $this->member_id, server::remote_addr()
|
|
);
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | // it's possible to change allowed allowed subnets
|
|
if ($as && $as->id &&
|
|||
c1bdc1c4 | Michal Kliment | $pm->count_all_disabled_allowed_subnets_by_member($this->member_id))
|
|
8baed187 | Michal Kliment | {
|
|
$uri = 'allowed_subnets/change/' .$as->id;
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | if ($as->enabled)
|
|
{
|
|||
$this->ip_address_span .= ' ' . html::anchor($uri, html::image(array
|
|||
(
|
|||
'src' => 'media/images/states/active.png',
|
|||
c1bdc1c4 | Michal Kliment | 'title' => __('Disable this subnet')
|
|
)) . ' ' . __('Disable this subnet')) . ' ' . help::hint('allowed_subnets_enabled');
|
|||
8baed187 | Michal Kliment | }
|
|
else
|
|||
{
|
|||
$this->ip_address_span .= ' ' . html::anchor($uri, html::image(array
|
|||
(
|
|||
'src' => 'media/images/states/inactive.png',
|
|||
c1bdc1c4 | Michal Kliment | 'title' => __('Enable this subnet')
|
|
)) . ' ' . __('Enable this subnet')) . ' ' . help::hint('allowed_subnets_disabled');
|
|||
8baed187 | Michal Kliment | }
|
|
}
|
|||
}
|
|||
c1bdc1c4 | Michal Kliment | // connection request staff (#143)
|
|
if (Settings::get('connection_request_enable') &&
|
|||
url_lang::current(2) != 'connection_requests/add' &&
|
|||
!$this->noredirect) // not show in dialogs
|
|||
{
|
|||
$sid = $pm->get_subnet_for_connection_request($ra_ip);
|
|||
// can user make connection request for $ra_ip?
|
|||
if ($sid)
|
|||
{ // so we will inform him!
|
|||
$url = '/connection_requests/add/' . $sid . '/' . $ra_ip;
|
|||
$link = html::anchor($url, __('register this connection'));
|
|||
$m = url_lang::lang('help.connection_request_user_pre_info', $link);
|
|||
status::minfo($m, FALSE);
|
|||
}
|
|||
}
|
|||
// log queue (#462)
|
|||
if ($this->acl_check_view('Log_queues_Controller', 'log_queue'))
|
|||
{
|
|||
74a7dbca | Michal Kliment | $this->count_of_unclosed_logged_errors =
|
|
c1bdc1c4 | Michal Kliment | $pm->count_of_unclosed_logs();
|
|
// inform box
|
|||
if ($this->count_of_unclosed_logged_errors &&
|
|||
url_lang::current(1) != 'log_queues' &&
|
|||
!$this->noredirect)
|
|||
{
|
|||
$link = html::anchor('/log_queues/show_all', __('check it'));
|
|||
status::mwarning(url_lang::lang('help.log_queues_info', $link), FALSE);
|
|||
}
|
|||
}
|
|||
// menu favourites
|
|||
$this->user_favourites_pages = $pm->get_users_favourites($this->user_id);
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // access to AXO doc
|
|
$this->axo_doc_access = (
|
|||
$this->acl_check_new('Acl_Controller', 'acl') ||
|
|||
$this->acl_check_edit('Acl_Controller', 'acl')
|
|||
);
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | /**
|
|
* Build menu
|
|||
74a7dbca | Michal Kliment | *
|
|
c1bdc1c4 | Michal Kliment | * @author Michal Kliment
|
|
* @return Menu_builder
|
|||
* @throws Exception
|
|||
*/
|
|||
public function build_menu()
|
|||
{
|
|||
$menu = new Menu_builder();
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $pm = new Preprocessor_Model();
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | /*********************** FAVOURITES ***********************/
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | if (!empty($this->user_favourites_pages) &&
|
|
$this->user_favourites_pages->count())
|
|||
{
|
|||
$menu->addGroup('favourites', __('Favourites'));
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | foreach ($this->user_favourites_pages as $fav)
|
|
{
|
|||
$default = array();
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | if ($fav->default_page)
|
|
{
|
|||
$default = array
|
|||
(
|
|||
'default' => TRUE
|
|||
);
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $menu->addItem($fav->page, $fav->title, 'favourites', $default);
|
|
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | unset($this->user_favourites_pages);
|
|
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | /*********************** MY PROFILE ***********************/
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $menu->addGroup('account', __('My profile'));
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // my profile
|
|
if ($this->session->get('user_type') == User_Model::MAIN_USER &&
|
|||
$this->acl_check_view('Members_Controller', 'members', $this->member_id))
|
|||
{
|
|||
$menu->addItem(
|
|||
'members/show/'.$this->member_id,
|
|||
__('My profile'), 'account');
|
|||
}
|
|||
elseif ($this->acl_check_view('Users_Controller', 'users', $this->member_id))
|
|||
{
|
|||
$menu->addItem(
|
|||
'users/show/'.$this->user_id,
|
|||
__('My profile'), 'account');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // my transfers
|
|
if (Settings::get('finance_enabled') && $this->member_account_id &&
|
|||
($this->acl_check_view('Accounts_Controller', 'transfers', $this->member_id) ||
|
|||
$this->acl_check_view('Members_Controller', 'currentcredit')))
|
|||
{
|
|||
$menu->addItem(
|
|||
'transfers/show_by_account/'.$this->member_account_id,
|
|||
__('My transfers'), 'account');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // my devices
|
|
if (Settings::get('networks_enabled') &&
|
|||
$this->acl_check_view('Devices_Controller', 'devices',$this->member_id))
|
|||
{
|
|||
$menu->addItem(
|
|||
'devices/show_by_user/'.$this->user_id,
|
|||
__('My devices'), 'account');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // my connection requests
|
|
if ($this->member_id != Member_Model::ASSOCIATION &&
|
|||
$this->acl_check_view('Connection_Requests_Controller', 'request', $this->member_id) &&
|
|||
Settings::get('connection_request_enable'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'connection_requests/show_by_member/'.$this->member_id,
|
|||
__('My connection requests'), 'account');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // my works
|
|
if (Settings::get('works_enabled') &&
|
|||
$this->member_id != Member_Model::ASSOCIATION &&
|
|||
$this->acl_check_view('Works_Controller', 'work', $this->member_id))
|
|||
{
|
|||
$menu->addItem(
|
|||
'works/show_by_user/'.$this->user_id,
|
|||
__('My works'), 'account');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // my work reports
|
|
if (Settings::get('works_enabled') &&
|
|||
$this->member_id != Member_Model::ASSOCIATION &&
|
|||
$this->acl_check_view('Work_reports_Controller', 'work_report', $this->member_id))
|
|||
{
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $menu->addItem('work_reports/show_by_user/'.$this->user_id,
|
|
__('My work reports'), 'account');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // my requests
|
|
74a7dbca | Michal Kliment | if (Settings::get('approval_enabled') &&
|
|
c1bdc1c4 | Michal Kliment | $this->member_id != Member_Model::ASSOCIATION &&
|
|
$this->acl_check_view('Requests_Controller', 'request', $this->member_id))
|
|||
{
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $menu->addItem('requests/show_by_user/'.$this->user_id,
|
|
__('My requests'), 'account');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // my phone invoices
|
|
if (Settings::get('phone_invoices_enabled') &&
|
|||
$this->member_id != 1 &&
|
|||
$pm->has_phone_invoices($this->user_id))
|
|||
{
|
|||
$menu->addItem(
|
|||
'phone_invoices/show_by_user/'.$this->user_id,
|
|||
__('My phone invoices'), 'account', array
|
|||
(
|
|||
'count' => $pm->count_unfilled_phone_invoices($this->user_id)
|
|||
));
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // my VoIP calls
|
|
if (Settings::get('voip_enabled') && $this->user_has_voip)
|
|||
{
|
|||
$menu->addItem(
|
|||
74a7dbca | Michal Kliment | 'voip_calls/show_by_user/'.$this->user_id,
|
|
c1bdc1c4 | Michal Kliment | __('My VoIP calls'), 'account');
|
|
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // my mail
|
|
$menu->addItem('mail/inbox', __('My mail'), 'account', array
|
|||
(
|
|||
'count' => $this->unread_user_mails
|
|||
));
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | /*********************** USERS *************************/
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $menu->addGroup('users', __('Users'));
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of members
|
|
if ($this->acl_check_view('Members_Controller', 'members'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'members/show_all', __('Members'), 'users');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | /**
|
|
* @todo Add own AXO
|
|||
*/
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of registered applicants
|
|
74a7dbca | Michal Kliment | if ((Settings::get('self_registration') || $pm->count_of_registered_members() > 0) &&
|
|
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Members_Controller', 'members'))
|
|
{
|
|||
$menu->addItem(
|
|||
'members/applicants', __('Registered applicants'),
|
|||
'users', array
|
|||
(
|
|||
'count' => $pm->count_of_registered_members()
|
|||
));
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of membership interrupts
|
|
if (Settings::get('membership_interrupt_enabled') &&
|
|||
$this->acl_check_view('Members_Controller', 'membership_interrupts'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'membership_interrupts/show_all',
|
|||
__('Membership interrupts'),
|
|||
'users');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of membership interrupts
|
|
if ($this->acl_check_view('Membership_transfers_Controller', 'membership_transfer'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'membership_transfers/show_all',
|
|||
__('Membership transfers'),
|
|||
'users');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of users
|
|
if ($this->acl_check_view('Users_Controller', 'users'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'users/show_all', __('Users'),
|
|||
'users');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | /************************** FINANCES *****************/
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $menu->addGroup('transfer', __('Finances'));
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of unidentified transfers
|
|
if (Settings::get('finance_enabled') &&
|
|||
$this->acl_check_view('Accounts_Controller', 'unidentified_transfers'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'bank_transfers/unidentified_transfers/',
|
|||
__('Unidentified transfers'), 'transfer',
|
|||
array
|
|||
(
|
|||
'count' => $pm->scount_unidentified_transfers()
|
|||
));
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of bank accounts
|
|
if (Settings::get('finance_enabled') &&
|
|||
$this->acl_check_view('Accounts_Controller', 'bank_accounts'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'bank_accounts/show_all', __('Bank accounts'),
|
|||
'transfer');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of accounts
|
|
if (Settings::get('finance_enabled') &&
|
|||
$this->acl_check_view('Accounts_Controller', 'accounts'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'accounts/show_all', __('Double-entry accounts'),
|
|||
'transfer');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | /**
|
|
* @todo Add own AXO
|
|||
*/
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of transfers
|
|
if (Settings::get('finance_enabled') &&
|
|||
$this->acl_check_view('Accounts_Controller', 'transfers'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'transfers/show_all', __('Day book'),'transfer');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | /**
|
|
* @todo Add own AXO
|
|||
*/
|
|||
if (Settings::get('finance_enabled') &&
|
|||
$this->acl_check_view('Accounts_Controller', 'invoices'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'invoices/show_all', __('Invoices'), 'transfer');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | /********************** APPROVAL ***********************/
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $menu->addGroup('approval', __('Approval'));
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of works
|
|
if (Settings::get('works_enabled') &&
|
|||
$this->acl_check_view('Works_Controller', 'work'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'works/show_all', __('Works'), 'approval',
|
|||
array
|
|||
(
|
|||
'count' => $pm->get_count_of_unvoted_works_of_voter($this->user_id)
|
|||
));
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of work reports
|
|
if (Settings::get('works_enabled') &&
|
|||
$this->acl_check_view('Work_reports_Controller', 'work_report'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'work_reports/show_all', __('Work reports'),
|
|||
'approval', array
|
|||
(
|
|||
'count' => $pm->get_count_of_unvoted_work_reports_of_voter($this->user_id)
|
|||
));
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of requests
|
|
if (Settings::get('approval_enabled') &&
|
|||
$this->acl_check_view('Requests_Controller', 'request'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'requests/show_all', __('Requests'),
|
|||
'approval', array
|
|||
(
|
|||
'count' => $pm->get_count_of_unvoted_requests_of_voter($this->user_id)
|
|||
));
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | /*********************** NETWORKS ********************/
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $menu->addGroup('networks', __('Networks'));
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of connection requests
|
|
if (Settings::get('connection_request_enable') &&
|
|||
$this->acl_check_view('Connection_Requests_Controller', 'request'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'connection_requests/show_all',
|
|||
__('Connection requests'), 'networks',
|
|||
array
|
|||
(
|
|||
'count' => $pm->count_undecided_requests()
|
|||
));
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of devices
|
|
if (Settings::get('networks_enabled') &&
|
|||
$this->acl_check_view('Devices_Controller', 'devices'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'devices/show_all', __('Devices'),
|
|||
'networks');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of ifaces
|
|
if (Settings::get('networks_enabled') &&
|
|||
$this->acl_check_view('Ifaces_Controller', 'iface'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'ifaces/show_all', __('Interfaces'),
|
|||
'networks');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of IP addresses
|
|
if (Settings::get('networks_enabled') &&
|
|||
$this->acl_check_view('Ip_addresses_Controller', 'ip_address'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'ip_addresses/show_all', __('IP addresses'),
|
|||
'networks');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of subnets
|
|
if (Settings::get('networks_enabled') &&
|
|||
$this->acl_check_view('Subnets_Controller', 'subnet'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'subnets/show_all', __('Subnets'), 'networks');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of links
|
|
if (Settings::get('networks_enabled') &&
|
|||
$this->acl_check_view('Links_Controller', 'link'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'links/show_all', __('Links'), 'networks');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of VLANs
|
|
if (Settings::get('networks_enabled') &&
|
|||
$this->acl_check_view('Vlans_Controller', 'vlan'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'vlans/show_all', __('Vlans'), 'networks');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of VoIP numbers
|
|
if (Settings::get('voip_enabled') &&
|
|||
$this->acl_check_view('VoIP_Controller', 'voip'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'voip/show_all', __('VoIP'), 'networks');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of clouds
|
|
if (Settings::get('networks_enabled') &&
|
|||
$this->acl_check_view('Clouds_Controller', 'clouds'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'clouds/show_all', __('Clouds'), 'networks');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // tools
|
|
if (Settings::get('networks_enabled') &&
|
|||
$this->acl_check_view('Tools_Controller', 'tools'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'tools/ssh', __('Tools'), 'networks');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // traffic
|
|
if (Settings::get('ulogd_enabled') && (
|
|||
$this->acl_check_view('Ulogd_Controller', 'total') ||
|
|||
$this->acl_check_view('Ulogd_Controller', 'ip_address') ||
|
|||
$this->acl_check_view('Ulogd_Controller', 'member')))
|
|||
{
|
|||
$menu->addItem(
|
|||
'traffic', __('Traffic'), 'networks');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // monitoring
|
|
if (Settings::get('monitoring_enabled') &&
|
|||
$this->acl_check_view('Monitoring_Controller', 'monitoring'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'monitoring/show_all', __('Monitoring'),
|
|||
'networks', array
|
|||
(
|
|||
'count' => $pm->count_off_down_devices(),
|
|||
'color' => 'red'
|
|||
));
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of DHCP servers
|
|
if (Settings::get('networks_enabled') &&
|
|||
$this->acl_check_view('Devices_Controller', 'devices'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'devices/show_all_dhcp_servers', __('DHCP servers'),
|
|||
'networks', array
|
|||
(
|
|||
'count' => $pm->count_inactive_dhcp_servers(),
|
|||
'color' => 'red'
|
|||
));
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
// dns server
|
|||
if (module::e('networks') &&
|
|||
$this->acl_check_view('Dns_Controller', 'zone'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'dns', __('DNS'), 'networks');
|
|||
}
|
|||
c1bdc1c4 | Michal Kliment | /***************** NOTIFICATIONS *********************/
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | if (module::e('notification'))
|
|
{
|
|||
$menu->addGroup('redirection', __('Notifications'));
|
|||
// list of messages
|
|||
if ($this->acl_check_view('Messages_Controller', 'message'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'messages/show_all', __('Messages'),
|
|||
'redirection');
|
|||
}
|
|||
// list of whitelists
|
|||
if ($this->acl_check_view('Members_whitelists_Controller', 'whitelist'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'members_whitelists/show_all', __('Whitelist'),
|
|||
'redirection');
|
|||
}
|
|||
// list of activated redirections
|
|||
if (Settings::get('redirection_enabled') &&
|
|||
$this->acl_check_view('Redirect_Controller', 'redirect'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'redirect/show_all', __('Activated redirections'),
|
|||
'redirection');
|
|||
}
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | /**************** ADMINISTRATION *******************/
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $menu->addGroup('administration', __('Administration'));
|
|
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of errors and logs
|
|
if ($this->acl_check_view('Log_queues_Controller', 'log_queue'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'log_queues/show_all', __('Errors and logs'),
|
|||
'administration',
|
|||
array
|
|||
(
|
|||
'count' => $this->count_of_unclosed_logged_errors,
|
|||
'color' => 'red'
|
|||
));
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // settings
|
|
if ($this->acl_check_view('Settings_Controller', 'info') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'system_settings') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'users_settings') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'finance_settings') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'approval_settings') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'networks_settings') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'email_settings') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'sms_settings') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'voip_settings') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'notification_settings') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'qos_settings') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'monitoring_settings') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'qos_settings') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'vtiger_settings') ||
|
|||
$this->acl_check_edit('Settings_Controller', 'logging_settings'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'settings/', __('Settings'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of address points
|
|
if ($this->acl_check_view('Address_points_Controller', 'address_point'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'address_points/show_all', __('Address points'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of SMS messages
|
|
if (Settings::get('sms_enabled') &&
|
|||
$this->acl_check_view('Sms_Controller', 'sms'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'sms/show_all', __('SMS messages'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of e-mails
|
|
if (Settings::get('email_enabled') &&
|
|||
$this->acl_check_view('Email_queues_Controller', 'email_queue'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'email_queues/show_all_unsent', __('E-mails'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of device_templates
|
|
if (Settings::get('networks_enabled') &&
|
|||
$this->acl_check_view('Device_templates_Controller', 'device_template'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'device_templates/show_all', __('Device templates'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of device_templates
|
|
if (Settings::get('networks_enabled') &&
|
|||
$this->acl_check_view('Device_active_links_Controller', 'active_links'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'device_active_links/show_all', __('Device active links'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of approval templates
|
|
if (Settings::get('approval_enabled') &&
|
|||
$this->acl_check_view('approval', 'templates'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'approval_templates/show_all', __('Approval templates'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // access rights
|
|
if ($this->acl_check_view('Acl_Controller', 'acl'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'acl/show_all', __('Access rights'),
|
|||
'administration');
|
|||
}
|
|||
else if ($this->acl_check_view('Aro_groups_Controller', 'aro_group'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'aro_groups/show_all', __('Access control groups of users'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of fees
|
|
if (Settings::get('finance_enabled') &&
|
|||
$this->acl_check_view('Fees_Controller', 'fees'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'fees/show_all', __('Fees'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of login logs
|
|
if ($this->acl_check_view('Login_logs_Controller', 'logs'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'login_logs/show_all', __('Login logs'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of action logs
|
|
if (Settings::get('action_logs_active') &&
|
|||
$this->acl_check_view('Logs_Controller', 'logs'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'logs/show_all', __('Action logs'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of stats
|
|
if ($this->acl_check_view('Stats_Controller', 'members_fees') ||
|
|||
$this->acl_check_view('Stats_Controller', 'incoming_member_payment') ||
|
|||
74a7dbca | Michal Kliment | $this->acl_check_view('Stats_Controller', 'members_growth') ||
|
|
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Stats_Controller', 'members_increase_decrease'))
|
|
{
|
|||
$menu->addItem(
|
|||
'stats', __('Stats'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of translations
|
|
if ($this->acl_check_view('Translations_Controller', 'translation'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'translations/show_all', __('Translations'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of enumerations
|
|
if ($this->acl_check_view('Enum_types_Controller', 'enum_types'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'enum_types/show_all', __('Enumerations'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of phone invoices
|
|
if (Settings::get('phone_invoices_enabled') &&
|
|||
$this->acl_check_view('Phone_invoices_Controller', 'invoices'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'phone_invoices/show_all', __('Phone invoices'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of speed classes
|
|
if ($this->acl_check_view('Speed_classes_Controller', 'speed_classes'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'speed_classes/show_all', __('Speed classes'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | // list of phone operators
|
|
if (Settings::get('sms_enabled') &&
|
|||
$this->acl_check_view('Phone_operators_Controller', 'phone_operators'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'phone_operators/show_all', __('Phone operators'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
// list of API accouts
|
|||
if (Settings::get('api_enabled') &&
|
|||
$this->acl_check_view('Api_Controller', 'account'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'api_accounts/show_all', __('API accounts'),
|
|||
'administration');
|
|||
}
|
|||
c1bdc1c4 | Michal Kliment | // list of filter queries
|
|
if ($this->acl_check_view('Filter_queries_Controller', 'filter_queries'))
|
|||
{
|
|||
$menu->addItem(
|
|||
'filter_queries/show_all', __('Filter queries'),
|
|||
'administration');
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | return $menu;
|
|
8baed187 | Michal Kliment | }
|
|
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | /**
|
|
* Return URL for controller and method
|
|||
74a7dbca | Michal Kliment | *
|
|
8baed187 | Michal Kliment | * @author Michal Kliment
|
|
c1bdc1c4 | Michal Kliment | * @param string $method
|
|
* @param string $controller
|
|||
* @return string
|
|||
8baed187 | Michal Kliment | */
|
|
public function url()
|
|||
{
|
|||
$args = func_get_args();
|
|||
$additional = '';
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | switch (func_num_args())
|
|
{
|
|||
case 0:
|
|||
// method is not set, use current
|
|||
$debug = debug_backtrace();
|
|||
$method = $debug[1]['function'];
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | // controller is not set use current
|
|
$controller = str_replace('_controller', '', strtolower(get_class($this)));
|
|||
break;
|
|||
74a7dbca | Michal Kliment | case 1:
|
|
8baed187 | Michal Kliment | $method = $args[0];
|
|
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | // controller is not set use current
|
|
$controller = str_replace('_controller', '', strtolower(get_class($this)));
|
|||
break;
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | default:
|
|
$controller = array_shift($args);
|
|||
$method = array_shift($args);
|
|||
$additional = implode('/', $args);
|
|||
if (!empty($additional))
|
|||
$additional = '/'.$additional;
|
|||
break;
|
|||
}
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | return url_lang::base(). $controller.'/'.$method.$additional;
|
|
}
|
|||
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | /**
|
|
* Redirects to uri according to attribute noredirect
|
|||
74a7dbca | Michal Kliment | *
|
|
8baed187 | Michal Kliment | * @author Michal Kliment
|
|
* @param string $uri
|
|||
c1bdc1c4 | Michal Kliment | * @param integer $id [optional]
|
|
* @param string $glue [optional]
|
|||
8baed187 | Michal Kliment | */
|
|
public function redirect($uri = NULL, $id = NULL, $glue = '/')
|
|||
74a7dbca | Michal Kliment | {
|
|
8baed187 | Michal Kliment | if (($pos = strpos($uri, url::base())) === FALSE)
|
|
{
|
|||
$url = call_user_func_array(
|
|||
array($this, 'url'),
|
|||
explode('/', trim($uri, '/'))
|
|||
);
|
|||
}
|
|||
else
|
|||
c1bdc1c4 | Michal Kliment | {
|
|
8baed187 | Michal Kliment | $url = trim($uri, '/');
|
|
c1bdc1c4 | Michal Kliment | }
|
|
74a7dbca | Michal Kliment | ||
8baed187 | Michal Kliment | if ($id)
|
|
c1bdc1c4 | Michal Kliment | {
|
|
8baed187 | Michal Kliment | $url .= $glue.$id;
|
|
c1bdc1c4 | Michal Kliment | }
|
|
8baed187 | Michal Kliment | ||
if ($this->noredirect)
|
|||
{
|
|||
die(json_encode(array
|
|||
(
|
|||
'url' => $url,
|
|||
'id' => $id
|
|||
)));
|
|||
}
|
|||
else
|
|||
c1bdc1c4 | Michal Kliment | {
|
|
8baed187 | Michal Kliment | url::redirect($url);
|
|
c1bdc1c4 | Michal Kliment | }
|
|
8baed187 | Michal Kliment | }
|
|
}
|