Revize 1142
Přidáno uživatelem Ondřej Fibich před asi 13 roky(ů)
freenetis/branches/testing/application/hooks/err404.php | ||
---|---|---|
<?php
|
||
<?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.
|
||
*
|
||
* More info about licence can be found:
|
||
* http://www.gnu.org/licenses/gpl-3.0.html
|
||
*
|
||
* More info about project can be found:
|
||
* http://www.freenetis.org/
|
||
*
|
||
*/
|
||
|
||
function e404()
|
||
{
|
||
... | ... | |
}
|
||
|
||
Event::replace('system.404', array('Kohana', 'show_404'), 'e404');
|
||
|
||
?>
|
freenetis/branches/testing/application/hooks/site_lang.php | ||
---|---|---|
<?php
|
||
<?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.
|
||
*
|
||
* More info about licence can be found:
|
||
* http://www.gnu.org/licenses/gpl-3.0.html
|
||
*
|
||
* More info about project can be found:
|
||
* http://www.freenetis.org/
|
||
*
|
||
*/
|
||
|
||
// This hook sets the locale.language and locale.lang config values
|
||
// based on the language found in the first segment of the URL.
|
||
... | ... | |
|
||
function site_lang()
|
||
{
|
||
// Array of allowed languages
|
||
$locales = Config::get('allowed_locales');
|
||
// Array of allowed languages
|
||
$locales = Config::get('allowed_locales');
|
||
|
||
// Extract language from URL
|
||
$segments = explode('/',url::current());
|
||
$lang = strtolower($segments[0]);
|
||
// Extract language from URL
|
||
$segments = explode('/', url::current());
|
||
$lang = strtolower($segments[0]);
|
||
|
||
// Invalid language is given in the URL
|
||
if ( ! array_key_exists($lang, $locales))
|
||
{
|
||
// Look for default alternatives and store them in order
|
||
// of importance in the $new_langs array:
|
||
// 1. cookie
|
||
// 2. http_accept_language header
|
||
// 3. default lang
|
||
// Invalid language is given in the URL
|
||
if (!array_key_exists($lang, $locales))
|
||
{
|
||
// Look for default alternatives and store them in order
|
||
// of importance in the $new_langs array:
|
||
// 1. cookie
|
||
// 2. http_accept_language header
|
||
// 3. default lang
|
||
// Look for cookie
|
||
$new_langs[] = (string) cookie::get('lang');
|
||
|
||
// Look for cookie
|
||
$new_langs[] = (string) cookie::get('lang');
|
||
// Look for HTTP_ACCEPT_LANGUAGE
|
||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
|
||
{
|
||
foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $part)
|
||
{
|
||
$new_langs[] = substr($part, 0, 2);
|
||
}
|
||
}
|
||
|
||
// Look for HTTP_ACCEPT_LANGUAGE
|
||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
|
||
{
|
||
foreach(explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $part)
|
||
{
|
||
$new_langs[] = substr($part, 0, 2);
|
||
}
|
||
}
|
||
|
||
// Lowest priority goes to default language
|
||
// Lowest priority goes to default language
|
||
// changed to Czech Language as default by Ondřej Fibich
|
||
$new_langs[] = Config::get('lang'); // prev. value 'en'
|
||
|
||
// Now loop through the new languages and pick out the first valid one
|
||
foreach(array_unique($new_langs) as $new_lang)
|
||
{
|
||
$new_lang = strtolower($new_lang);
|
||
$new_langs[] = Config::get('lang'); // prev. value 'en'
|
||
// Now loop through the new languages and pick out the first valid one
|
||
foreach (array_unique($new_langs) as $new_lang)
|
||
{
|
||
$new_lang = strtolower($new_lang);
|
||
|
||
if (array_key_exists($new_lang, $locales))
|
||
{
|
||
$lang = $new_lang;
|
||
break;
|
||
}
|
||
}
|
||
if (array_key_exists($new_lang, $locales))
|
||
{
|
||
$lang = $new_lang;
|
||
break;
|
||
}
|
||
}
|
||
|
||
// Redirect to URL with valid language
|
||
// Redirect to URL with valid language
|
||
$index_page = (Settings::get('index_page')) ? 'index.php/' : '';
|
||
url::redirect(url::base().$index_page.$lang.url_lang::current());
|
||
}
|
||
url::redirect(url::base() . $index_page . $lang . url_lang::current());
|
||
}
|
||
|
||
// Store locale config values
|
||
Config::set('lang', $lang);
|
||
Config::set('language', $locales[$lang]);
|
||
// Store locale config values
|
||
Config::set('lang', $lang);
|
||
Config::set('language', $locales[$lang]);
|
||
|
||
// Overwrite setlocale which has already been set before in Kohana::setup()
|
||
setlocale(LC_ALL, Config::get('language').'.UTF-8');
|
||
// Overwrite setlocale which has already been set before in Kohana::setup()
|
||
setlocale(LC_ALL, Config::get('language') . '.UTF-8');
|
||
|
||
// Finally set a language cookie for 6 months
|
||
cookie::set('lang', $lang, 15768000, '/');
|
||
// Finally set a language cookie for 6 months
|
||
cookie::set('lang', $lang, 15768000, '/');
|
||
}
|
||
?>
|
freenetis/branches/testing/application/models/phone_invoice_user.php | ||
---|---|---|
'phone_connections', 'phone_calls', 'phone_fixed_calls', 'phone_pays',
|
||
'phone_roaming_sms_messages', 'phone_sms_messages', 'phone_vpn_calls'
|
||
);
|
||
|
||
/**
|
||
* Check if given user has any phone invoice
|
||
*
|
||
* @param integer $user_id User
|
||
* @return bool Has?
|
||
*/
|
||
public function has_phone_invoices($user_id)
|
||
{
|
||
return $this->db->query("
|
||
SELECT COUNT(id) AS count
|
||
FROM phone_invoice_users
|
||
WHERE user_id = ?
|
||
", $user_id)->current()->count > 0;
|
||
}
|
||
|
||
/**
|
||
* Get sum of all users phone invoices separated to cells price_company and price_private
|
freenetis/branches/testing/application/models/voip_sip.php | ||
---|---|---|
|
||
protected $belongs_to = array('user');
|
||
|
||
/**
|
||
* Check if given user has any VoIP sips
|
||
*
|
||
* @author Ondřej Fibich
|
||
* @param integer $user_id User
|
||
* @return bool Has?
|
||
*/
|
||
public function has_voip_sips($user_id)
|
||
{
|
||
return $this->db->query("
|
||
SELECT COUNT(id) AS count
|
||
FROM voip_sips
|
||
WHERE user_id = ?
|
||
", $user_id)->current()->count > 0;
|
||
}
|
||
|
||
/**
|
||
* Function counts all records.
|
||
*
|
freenetis/branches/testing/application/libraries/MY_Controller.php | ||
---|---|---|
// for example when programmer misleads error and warning
|
||
define("PARAMETER", "1001");
|
||
|
||
|
||
/**
|
||
* Main controller creates menu, handles changes in svn repository (database upgrade), ...
|
||
*
|
||
... | ... | |
class Controller extends Controller_Core
|
||
{
|
||
|
||
/** @staticvar Controller Controller singleton */
|
||
/**
|
||
* Controller singleton
|
||
*
|
||
* @var Controller
|
||
*/
|
||
private static $instance;
|
||
|
||
|
||
/**
|
||
* Paths for which login is not required
|
||
*
|
||
* @var array
|
||
*/
|
||
private static $login_not_required = array
|
||
(
|
||
'login',
|
||
'forgotten_password',
|
||
'registration',
|
||
'registration/complete',
|
||
'scheduler/run',
|
||
'installation'
|
||
);
|
||
|
||
/** @var gacl PHP GACL class */
|
||
public $gacl_class;
|
||
/** @var unknown_type */
|
||
... | ... | |
public $upgrade_sql = array();
|
||
/** @var integer */
|
||
public $current_svn_db_schema_version = 0;
|
||
/** @var integer */
|
||
public $current_svn_revision = 0;
|
||
/** @var integer */
|
||
public $popup = 0;
|
||
... | ... | |
public $user_has_phone_invoices = 0;
|
||
/** @var boolean */
|
||
public $user_has_voip = 0;
|
||
|
||
/** @var string */
|
||
public $ip_address_span = '';
|
||
|
||
/** @var array */
|
||
public $svn = array();
|
||
|
||
/** @var integer */
|
||
private $ICON_ERROR = 1;
|
||
private $ICON_ERROR = 1;
|
||
/** @var integer */
|
||
private $ICON_GOOD = 2;
|
||
private $ICON_GOOD = 2;
|
||
/** @var integer */
|
||
private $ICON_HELP = 3;
|
||
private $ICON_HELP = 3;
|
||
/** @var integer */
|
||
private $ICON_INFO = 4;
|
||
private $ICON_INFO = 4;
|
||
/** @var integer */
|
||
private $ICON_WARNING = 5;
|
||
private $ICON_WARNING = 5;
|
||
|
||
/**
|
||
* Contruct of controller, creates singleton or return it
|
||
*/
|
||
public function __construct()
|
||
{
|
||
parent::__construct();
|
||
parent::__construct();
|
||
|
||
// This part only needs to be run once
|
||
if (self::$instance === NULL)
|
||
... | ... | |
|
||
// if true, freenetis will run in text mod for dialog
|
||
$this->dialog = (isset($_GET['dialog']) && $_GET['dialog']) ? 1 : 0;
|
||
|
||
|
||
// database upgrade goes here
|
||
$this->get_current_svn_db_schema_info();
|
||
|
||
$this->current_svn_revision = (int) @shell_exec("svnversion ".dirname(__FILE__)."/../../");
|
||
|
||
// svn informations for errors and info
|
||
$this->svn_info();
|
||
|
||
// config file doesn't exist, we must create it
|
||
... | ... | |
// protection before loop
|
||
if (url_lang::current(1) == 'setup_config')
|
||
return;
|
||
url::redirect(url_lang::base().'setup_config');
|
||
|
||
url::redirect(url_lang::base() . 'setup_config');
|
||
}
|
||
|
||
// protection before loop
|
||
... | ... | |
if (!$this->settings->get('db_schema_version'))
|
||
{
|
||
// we must run install
|
||
url::redirect(url_lang::base().'installation');
|
||
url::redirect(url_lang::base() . 'installation');
|
||
}
|
||
// db schema is not up to date
|
||
else if ($this->current_svn_db_schema_version != $this->settings->get('db_schema_version'))
|
||
else if ($this->current_svn_db_schema_version !=
|
||
$this->settings->get('db_schema_version'))
|
||
{
|
||
// we must run upgrade
|
||
$this->upgrade_sql($this->settings->get('db_schema_version'));
|
||
}
|
||
|
||
// test if visitor is logged in, or he accesses public controllers like registration, redirect, installation
|
||
|
||
// test if visitor is logged in, or he accesses public
|
||
// controllers like registration, redirect, installation
|
||
if (!$this->session->get('user_id', 0) &&
|
||
url_lang::current()!='login' &&
|
||
url_lang::current()!='forgotten_password' &&
|
||
url_lang::current() != 'registration' &&
|
||
url_lang::current() != 'registration/complete' &&
|
||
url_lang::current()!='scheduler/run' &&
|
||
strpos(url_lang::current(), 'web_interface')===false &&
|
||
url_lang::current(TRUE)!='web_interface' &&
|
||
url_lang::current(TRUE)!='web_interface' &&
|
||
url_lang::current()!='installation')
|
||
!in_array(url_lang::current(), self::$login_not_required) &&
|
||
strpos(url_lang::current(), 'web_interface') === false &&
|
||
url_lang::current(true) != 'web_interface')
|
||
{
|
||
// Not logged in - redirect to login page
|
||
$this->session->set_flash('err_message', url_lang::lang('texts.Must be logged in'));
|
||
$this->session->set('referer',url_lang::current());
|
||
url::redirect(url_lang::base().'login');
|
||
$this->session->set_flash('err_message', __('Must be logged in'));
|
||
|
||
// Do not logout after login
|
||
if (url_lang::current() != 'login/logout')
|
||
{
|
||
$this->session->set('referer', url_lang::current());
|
||
}
|
||
|
||
// Redirect to login
|
||
url::redirect(url_lang::base() . 'login');
|
||
|
||
// Die
|
||
die();
|
||
}
|
||
|
||
// load these variables only for logged user
|
||
if ($this->session->get('user_id', 0))
|
||
{
|
||
// init gacl, not required :-)
|
||
$this->phpgacl_init();
|
||
|
||
/**
|
||
* @todo: after removing all direct calls made through $gacl_class,
|
||
* remove the phpgacl initialization - so components which does not
|
||
* need it would save the 1.5MB of RAM requested by phpgacl
|
||
*/
|
||
$this->phpgacl_init();
|
||
// for preprocessing some variable
|
||
$this->preprocessor();
|
||
}
|
||
|
||
// for preprocessing some variable
|
||
$this->preprocessor();
|
||
|
||
// Singleton instance
|
||
self::$instance = $this;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Singleton instance of Controller.
|
||
*
|
||
* @author Michal Kliment
|
||
* Singleton instance of Controller.
|
||
* @return Controller object
|
||
*/
|
||
public static function instance()
|
||
... | ... | |
|
||
return self::$instance;
|
||
}
|
||
|
||
|
||
/**
|
||
* Function shows error of given message number.
|
||
*
|
||
* @param $message
|
||
* @param $content
|
||
* @return unknown_type
|
||
*/
|
||
public function error($message_type, $content = NULL)
|
||
{
|
||
{
|
||
switch ($message_type)
|
||
{
|
||
case ACCESS:
|
||
$message = url_lang::lang('states.Access denied');
|
||
$this->showbox($message, $this->ICON_ERROR, $content);
|
||
break;
|
||
break;
|
||
case EMAIL:
|
||
$message = url_lang::lang('states.Failed to send e-mail').'<br />'.url_lang::lang('states.Please check settings.');
|
||
$message = url_lang::lang('states.Failed to send e-mail') . '<br />' .
|
||
url_lang::lang('states.Please check settings.');
|
||
$this->showbox($message, $this->ICON_ERROR, $content);
|
||
break;
|
||
break;
|
||
case DATABASE:
|
||
$message = url_lang::lang('states.Failed to connect to database').'<br />'.url_lang::lang('states.Please check settings.');
|
||
$message = url_lang::lang('states.Failed to connect to database') .
|
||
'<br />' . url_lang::lang('states.Please check settings.');
|
||
$this->showbox($message, $this->ICON_ERROR, $content);
|
||
break;
|
||
break;
|
||
case RECORD:
|
||
$message = url_lang::lang('states.This record does not exist');
|
||
$this->showbox($message, $this->ICON_ERROR, $content);
|
||
break;
|
||
break;
|
||
case PAGE:
|
||
$message = url_lang::lang('states.Page not found');
|
||
$this->showbox($message, $this->ICON_ERROR, $content);
|
||
break;
|
||
break;
|
||
case UPGRADE:
|
||
$message = url_lang::lang('states.Database upgrade failed');
|
||
$this->showbox($message, $this->ICON_ERROR, $content);
|
||
break;
|
||
break;
|
||
case WRITABLE:
|
||
$message = url_lang::lang('states.Directory or file is not writable.');
|
||
$this->showbox($message, $this->ICON_ERROR, $content);
|
||
break;
|
||
break;
|
||
case READONLY:
|
||
$message = url_lang::lang('states.Item is read only.');
|
||
$this->showbox($message, $this->ICON_ERROR, $content);
|
||
break;
|
||
break;
|
||
default:
|
||
$message = url_lang::lang('states.Unknown error message');
|
||
$this->showbox($message, $this->ICON_WARNING, $content);
|
||
break;
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* Function shows warning of given message number.
|
||
* @param $message
|
||
* @param $content
|
||
* @return unknown_type
|
||
*
|
||
* @param integer $message
|
||
* @param string $content
|
||
*/
|
||
public function warning($message, $content = NULL)
|
||
{
|
||
... | ... | |
|
||
/**
|
||
* Function renders error and warning messages.
|
||
* @param $message
|
||
* @param $type
|
||
* @param $content
|
||
* @return unknown_type
|
||
*
|
||
* @param string $message
|
||
* @param integer $type
|
||
* @param string $content
|
||
*/
|
||
private function showbox($message, $type, $content = NULL)
|
||
{
|
||
$view = new View('main');
|
||
$view->content = new View('statesbox');
|
||
|
||
$src = NULL;
|
||
|
||
switch ($type)
|
||
{
|
||
case $this->ICON_ERROR:
|
||
$view->title = url_lang::lang('texts.Error');
|
||
$view->content->icon = html::image(array('src' => 'media/images/states/error.png', 'width' => '100', 'height' => '100', 'alt' => 'Image', 'class' => 'noborder'));
|
||
$view->title = __('Error');
|
||
$src = 'media/images/states/error.png';
|
||
break;
|
||
case $this->ICON_GOOD:
|
||
$view->title = url_lang::lang('texts.Good');
|
||
$view->content->icon = html::image(array('src' => 'media/images/states/good.png', 'width' => '100', 'height' => '100', 'alt' => 'Image', 'class' => 'noborder'));
|
||
$view->title = __('Good');
|
||
$src = 'media/images/states/good.png';
|
||
break;
|
||
case $this->ICON_HELP:
|
||
$view->title = url_lang::lang('texts.Help');
|
||
$view->content->icon = html::image(array('src' => 'media/images/states/help.png', 'width' => '100', 'height' => '100', 'alt' => 'Image', 'class' => 'noborder'));
|
||
$view->title = __('Help');
|
||
$src = 'media/images/states/help.png';
|
||
break;
|
||
case $this->ICON_INFO:
|
||
$view->title = url_lang::lang('texts.Info');
|
||
$view->content->icon = html::image(array('src' => 'media/images/states/info.png', 'width' => '100', 'height' => '100', 'alt' => 'Image', 'class' => 'noborder'));
|
||
$view->title = __('Info');
|
||
$src = 'media/images/states/info.png';
|
||
break;
|
||
case $this->ICON_WARNING:
|
||
$view->title = url_lang::lang('texts.Warning');
|
||
$view->content->icon = html::image(array('src' => 'media/images/states/warning.png', 'width' => '100', 'height' => '100', 'alt' => 'Image', 'class' => 'noborder'));
|
||
$view->title = __('Warning');
|
||
$src = 'media/images/states/warning.png';
|
||
break;
|
||
}
|
||
|
||
$view->content->icon = html::image(array
|
||
(
|
||
'src' => $src,
|
||
'width' => '100',
|
||
'height' => '100',
|
||
'alt' => 'Image',
|
||
'class' => 'noborder'
|
||
));
|
||
|
||
$view->content->message = $message;
|
||
|
||
if (isset($content))
|
||
{
|
||
$view->content->content = $content;
|
||
}
|
||
|
||
$view->render(TRUE);
|
||
|
||
// must be die() - else it will be render twice !
|
||
die();
|
||
}
|
||
... | ... | |
/**
|
||
* Setup revision database schema.
|
||
*/
|
||
function get_current_svn_db_schema_info()
|
||
public function get_current_svn_db_schema_info()
|
||
{
|
||
require_once("application/upgrade_sql/upgrade_sql.php");
|
||
|
||
$this->current_svn_db_schema_version = get_SVN_rev();
|
||
$this->upgrade_sql[$this->current_svn_db_schema_version] = $upgrade_sql[$this->current_svn_db_schema_version];
|
||
$this->upgrade_sql[$this->current_svn_db_schema_version] =
|
||
$upgrade_sql[$this->current_svn_db_schema_version];
|
||
}
|
||
|
||
/**
|
||
* Upgrade database from current version to latest version.
|
||
*
|
||
* @param integer $from_version From which version(revision) upgrade starts
|
||
*/
|
||
function upgrade_sql($from_version = 0)
|
||
public function upgrade_sql($from_version = 0)
|
||
{
|
||
$ok = true;
|
||
$this->db = new Database();
|
||
$config = new Config_Model();
|
||
|
||
// for each revision
|
||
for ($i = ($from_version+1); $i<($this->current_svn_db_schema_version); $i++)
|
||
for ($i = ($from_version + 1); $i < ($this->current_svn_db_schema_version); $i++)
|
||
{
|
||
if (file_exists("application/upgrade_sql/upgrade_sql_".$i.".php"))
|
||
if (file_exists("application/upgrade_sql/upgrade_sql_" . $i . ".php"))
|
||
{
|
||
require("application/upgrade_sql/upgrade_sql_".$i.".php");
|
||
require("application/upgrade_sql/upgrade_sql_" . $i . ".php");
|
||
// database transaction
|
||
try
|
||
{
|
||
... | ... | |
|
||
foreach ($upgrade_sql[$i] as $query)
|
||
{
|
||
if(!$this->db->query($query))
|
||
if (!$this->db->query($query))
|
||
{
|
||
throw new Kohana_Database_Exception();
|
||
}
|
||
... | ... | |
}
|
||
}
|
||
}
|
||
// catch (Kohana_Database_Exception $e)
|
||
// {
|
||
// $message = "SVN: $i <br />"
|
||
// .url_lang::lang('texts.file').": upgrade_sql_$i.php<br /><br />
|
||
// $query";
|
||
// $this->error(UPGRADE, $message);
|
||
// }
|
||
catch (Exception $e)
|
||
{
|
||
$message = "SVN: $i <br />"
|
||
.url_lang::lang('texts.file').": upgrade_sql_$i.php<br /><br />Function: " .
|
||
$e->getMessage();
|
||
. __('file') . ": upgrade_sql_$i.php<br /><br />Function: " .
|
||
$e->getMessage();
|
||
$this->error(UPGRADE, $message);
|
||
}
|
||
// set up db schema
|
||
... | ... | |
|
||
foreach ($this->upgrade_sql[$this->current_svn_db_schema_version] as $query)
|
||
{
|
||
if(!$this->db->query($query))
|
||
if (!$this->db->query($query))
|
||
{
|
||
throw new Kohana_Database_Exception();
|
||
}
|
||
... | ... | |
catch (Kohana_Database_Exception $e)
|
||
{
|
||
$message = "SVN: $i <br />"
|
||
.url_lang::lang('texts.file').": upgrade_sql.php<br /><br />
|
||
. __('file') . ": upgrade_sql.php<br /><br />
|
||
$query";
|
||
$this->error(UPGRADE, $message);
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
$message = "SVN: $i <br />"
|
||
.url_lang::lang('texts.file').": upgrade_sql_$i.php<br /><br />Function: " .
|
||
$e->getMessage();
|
||
. __('file') . ": upgrade_sql_$i.php<br /><br />Function: " .
|
||
$e->getMessage();
|
||
}
|
||
|
||
// set up db schema
|
||
$config->set_db_schema_version($this->current_svn_db_schema_version);
|
||
}
|
||
|
||
|
||
/**
|
||
* Inicialization of PHP GACL modul.
|
||
*/
|
||
public function phpgacl_init() {
|
||
require_once(APPPATH.'vendors/phpgacl/gacl.class.php');
|
||
public function phpgacl_init()
|
||
{
|
||
require_once(APPPATH . 'vendors/phpgacl/gacl.class.php');
|
||
|
||
$this->gacl_class = new gacl();
|
||
}
|
||
|
||
/**
|
||
* acl_check_2D checks the current user's rights to access an $aco_section/$aco_value
|
||
*
|
||
* @param string $aco_section
|
||
* @param string $aco_value
|
||
* @return bool
|
||
*/
|
||
public function acl_check_2D($aco_section, $aco_value) {
|
||
if (!isset($this->gacl_class)) $this->phpgacl_init();
|
||
return $this->gacl_class->acl_check($aco_section, $aco_value, 'all', $_SESSION['username']);
|
||
public function acl_check_2D($aco_section, $aco_value)
|
||
{
|
||
if (!isset($this->gacl_class))
|
||
$this->phpgacl_init();
|
||
|
||
return $this->gacl_class->acl_check(
|
||
$aco_section, $aco_value, 'all', $_SESSION['username']
|
||
);
|
||
}
|
||
|
||
/**
|
||
* acl_check_3D checks the current user's rights to access
|
||
* an $axo_value object in ***current controller*** (!!!) by
|
||
* operation specified by $aco_section/$aco_value
|
||
*
|
||
* @param string $aco_section
|
||
* @param string $aco_value
|
||
* @param string $axo_value
|
||
* @return bool
|
||
*/
|
||
public function acl_check_3D($aco_section, $aco_value, $axo_value) {
|
||
if (!isset($this->gacl_class)) $this->phpgacl_init();
|
||
return $this->gacl_class->acl_check($aco_section, $aco_value, 'all', $_SESSION['username'],get_class($this),$axo_value);
|
||
public function acl_check_3D($aco_section, $aco_value, $axo_value)
|
||
{
|
||
if (!isset($this->gacl_class))
|
||
$this->phpgacl_init();
|
||
|
||
return $this->gacl_class->acl_check(
|
||
$aco_section, $aco_value, 'all', $_SESSION['username'],
|
||
get_class($this), $axo_value
|
||
);
|
||
}
|
||
|
||
|
||
/**
|
||
* Fuction checks access rights
|
||
* Return true if currently logged user (stored in $_SESSION['username'])
|
||
... | ... | |
public function acl_check_view($axo_section, $axo_value, $member_id = NULL)
|
||
{
|
||
$return = false;
|
||
if (!isset($this->gacl_class)) $this->phpgacl_init();
|
||
if($member_id==$_SESSION['member_id'])
|
||
|
||
if (!isset($this->gacl_class))
|
||
$this->phpgacl_init();
|
||
|
||
if ($member_id == $_SESSION['member_id'])
|
||
{
|
||
if ($this->gacl_class->acl_check('freenetis', 'view_own', 'all', $_SESSION['username'],$axo_section,$axo_value)) $return = true;
|
||
if ($this->gacl_class->acl_check(
|
||
'freenetis', 'view_own', 'all', $_SESSION['username'],
|
||
$axo_section, $axo_value
|
||
))
|
||
{
|
||
$return = true;
|
||
}
|
||
}
|
||
if ($this->gacl_class->acl_check('freenetis', 'view_all', 'all', $_SESSION['username'],$axo_section,$axo_value)) $return = true;
|
||
|
||
if ($this->gacl_class->acl_check(
|
||
'freenetis', 'view_all', 'all', $_SESSION['username'],
|
||
$axo_section, $axo_value
|
||
))
|
||
{
|
||
$return = true;
|
||
}
|
||
|
||
return $return;
|
||
}
|
||
|
||
... | ... | |
public function acl_check_edit($axo_section, $axo_value, $member_id = NULL)
|
||
{
|
||
$return = false;
|
||
if (!isset($this->gacl_class)) $this->phpgacl_init();
|
||
if($member_id==$_SESSION['member_id'])
|
||
|
||
if (!isset($this->gacl_class))
|
||
$this->phpgacl_init();
|
||
|
||
if ($member_id == $_SESSION['member_id'])
|
||
{
|
||
if ($this->gacl_class->acl_check('freenetis', 'edit_own', 'all', $_SESSION['username'],$axo_section,$axo_value)) $return = true;
|
||
if ($this->gacl_class->acl_check(
|
||
'freenetis', 'edit_own', 'all', $_SESSION['username'],
|
||
$axo_section, $axo_value
|
||
))
|
||
{
|
||
$return = true;
|
||
}
|
||
}
|
||
if ($this->gacl_class->acl_check('freenetis', 'edit_all', 'all', $_SESSION['username'],$axo_section,$axo_value)) $return = true;
|
||
|
||
if ($this->gacl_class->acl_check(
|
||
'freenetis', 'edit_all', 'all', $_SESSION['username'],
|
||
$axo_section, $axo_value
|
||
))
|
||
{
|
||
$return = true;
|
||
}
|
||
|
||
return $return;
|
||
}
|
||
|
||
... | ... | |
public function acl_check_new($axo_section, $axo_value, $member_id = NULL)
|
||
{
|
||
$return = false;
|
||
if (!isset($this->gacl_class)) $this->phpgacl_init();
|
||
if($member_id==$_SESSION['member_id'])
|
||
|
||
if (!isset($this->gacl_class))
|
||
$this->phpgacl_init();
|
||
|
||
if ($member_id == $_SESSION['member_id'])
|
||
{
|
||
if ($this->gacl_class->acl_check('freenetis', 'new_own', 'all', $_SESSION['username'],$axo_section,$axo_value)) $return = true;
|
||
if ($this->gacl_class->acl_check(
|
||
'freenetis', 'new_own', 'all', $_SESSION['username'],
|
||
$axo_section, $axo_value
|
||
))
|
||
{
|
||
$return = true;
|
||
}
|
||
}
|
||
if ($this->gacl_class->acl_check('freenetis', 'new_all', 'all', $_SESSION['username'],$axo_section,$axo_value)) $return = true;
|
||
|
||
if ($this->gacl_class->acl_check(
|
||
'freenetis', 'new_all', 'all', $_SESSION['username'],
|
||
$axo_section, $axo_value
|
||
))
|
||
{
|
||
$return = true;
|
||
}
|
||
|
||
return $return;
|
||
}
|
||
|
||
... | ... | |
public function acl_check_delete($axo_section, $axo_value, $member_id = NULL)
|
||
{
|
||
$return = false;
|
||
if (!isset($this->gacl_class)) $this->phpgacl_init();
|
||
if($member_id==$_SESSION['member_id'])
|
||
|
||
if (!isset($this->gacl_class))
|
||
$this->phpgacl_init();
|
||
|
||
if ($member_id == $_SESSION['member_id'])
|
||
{
|
||
if ($this->gacl_class->acl_check('freenetis', 'delete_own', 'all', $_SESSION['username'],$axo_section,$axo_value)) $return = true;
|
||
if ($this->gacl_class->acl_check(
|
||
'freenetis', 'delete_own', 'all',
|
||
$_SESSION['username'], $axo_section, $axo_value))
|
||
{
|
||
$return = true;
|
||
}
|
||
}
|
||
if ($this->gacl_class->acl_check('freenetis', 'delete_all', 'all', $_SESSION['username'],$axo_section,$axo_value)) $return = true;
|
||
|
||
if ($this->gacl_class->acl_check(
|
||
'freenetis', 'delete_all', 'all', $_SESSION['username'],
|
||
$axo_section, $axo_value))
|
||
{
|
||
$return = true;
|
||
}
|
||
|
||
return $return;
|
||
}
|
||
|
||
... | ... | |
*/
|
||
public function acl_check_confirm($axo_section, $axo_value, $member_id = NULL)
|
||
{
|
||
if (!isset($this->gacl_class)) $this->phpgacl_init();
|
||
if($member_id==$_SESSION['member_id'])
|
||
{
|
||
return $this->gacl_class->acl_check('freenetis', 'confirm_own', 'all', $_SESSION['username'],$axo_section,$axo_value);
|
||
}
|
||
if (!isset($this->gacl_class))
|
||
$this->phpgacl_init();
|
||
|
||
if ($member_id == $_SESSION['member_id'])
|
||
{
|
||
return $this->gacl_class->acl_check(
|
||
'freenetis', 'confirm_own', 'all', $_SESSION['username'],
|
||
$axo_section, $axo_value
|
||
);
|
||
}
|
||
else
|
||
{
|
||
return $this->gacl_class->acl_check('freenetis', 'confirm_all', 'all', $_SESSION['username'],$axo_section,$axo_value);
|
||
return $this->gacl_class->acl_check(
|
||
'freenetis', 'confirm_all', 'all', $_SESSION['username'],
|
||
$axo_section, $axo_value
|
||
);
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* Function probably assigns role to user.
|
||
* @param $user_id
|
||
... | ... | |
* @param $is_edit
|
||
* @return unknown_type
|
||
*/
|
||
public function insert_phpgacl($user_id,$username,$value,$group, $is_edit = false)
|
||
public function insert_phpgacl($user_id, $username, $value, $group, $is_edit = false)
|
||
{
|
||
$aro_group_data = new Groups_aro_map_Model();
|
||
switch ($group) {
|
||
switch ($group)
|
||
{
|
||
case 'member':
|
||
$group_id = 22;
|
||
break;
|
||
... | ... | |
break;
|
||
}
|
||
$group_arr = array();
|
||
$group_arr['group_id'] = $group_id;
|
||
$group_arr['group_id'] = $group_id;
|
||
if ($is_edit)
|
||
{
|
||
$aro_group_data->insert_data($group_arr, $user_id);
|
||
}
|
||
else
|
||
{
|
||
$group_arr['aro_id'] = $user_id;
|
||
$group_arr['aro_id'] = $user_id;
|
||
$aro_group_data->insert_data($group_arr);
|
||
}
|
||
}
|
||
... | ... | |
*/
|
||
private function svn_info()
|
||
{
|
||
$info = @shell_exec("svn info ".dirname(__FILE__)."/../../");
|
||
$info = @shell_exec("svn info " . dirname(__FILE__) . "/../../");
|
||
|
||
if ($info != '')
|
||
if ($info != '')
|
||
{
|
||
$lines = explode("\n", $info);
|
||
|
||
foreach ($lines as $line)
|
||
{
|
||
$lines = explode("\n", $info);
|
||
$segments = explode(":", $line);
|
||
$key = str_replace(" ", "_", strtolower(array_shift($segments)));
|
||
$value = implode(":", $segments);
|
||
|
||
foreach ($lines as $line)
|
||
{
|
||
$segments = explode(":", $line);
|
||
$key = str_replace(" ","_", strtolower(array_shift($segments)));
|
||
$value = implode(":", $segments);
|
||
|
||
if ($key != '')
|
||
$this->svn[$key] = trim($value);
|
||
}
|
||
if ($key != '')
|
||
$this->svn[$key] = trim($value);
|
||
}
|
||
}
|
||
|
||
// Sets revision
|
||
if (isset($this->svn['revision']))
|
||
{
|
||
$this->current_svn_revision = $this->svn['revision'];
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Function to preprocessing of some useful variables
|
||
*
|
||
* @author Michal Kliment
|
||
*/
|
||
private function preprocessor ()
|
||
private function preprocessor()
|
||
{
|
||
$this->user_id = $this->session->get('user_id');
|
||
|
||
// boolean variable if user has any phone invoices (for menu rendering)
|
||
$this->user_has_phone_invoices = ORM::factory('phone_invoice_user')->where('user_id',$this->user_id)->find_all()->count();
|
||
$this->user_has_phone_invoices = ORM::factory('phone_invoice_user')
|
||
->has_phone_invoices($this->user_id);
|
||
|
||
// boolean variable if user has active voip number (for menu rendering)
|
||
$this->user_has_voip = (bool) ORM::factory('voip_sip')->where('user_id',$this->user_id)->find_all()->count();
|
||
$this->user_has_voip = (bool) ORM::factory('voip_sip')
|
||
->has_voip_sips($this->user_id);
|
||
|
||
// ip address span
|
||
$this->ip_address_span = server::remote_addr();
|
||
if (($ptr_record = dns::get_ptr_record(server::remote_addr())) != '')
|
||
$this->ip_address_span .= ' <i>('.$ptr_record.')</i>';
|
||
|
||
if (($ptr_record = dns::get_ptr_record($this->ip_address_span)) != '')
|
||
{
|
||
$this->ip_address_span .= ' <i>(' . $ptr_record . ')</i>';
|
||
}
|
||
|
||
// allowed subnets are enabled
|
||
if (Settings::get('allowed_subnets_enabled') && $this->session->get('member_id') && $this->acl_check_edit('Devices_Controller', 'allowed_subnet', $this->session->get('member_id')))
|
||
if (Settings::get('allowed_subnets_enabled') &&
|
||
$this->session->get('member_id') &&
|
||
$this->acl_check_edit(
|
||
'Devices_Controller', 'allowed_subnet',
|
||
$this->session->get('member_id')
|
||
))
|
||
{
|
||
// toggle button between allowed subnets
|
||
$allowed_subnet_model = new Allowed_subnet_Model();
|
||
$allowed_subnet = $allowed_subnet_model->get_allowed_subnet_by_member_and_ip_address ($this->session->get('member_id'), server::remote_addr());
|
||
// it's possible to change allowed allowed subnets
|
||
if ($allowed_subnet && $allowed_subnet->id && $allowed_subnet_model->count_all_disabled_allowed_subnets_by_member($this->session->get('member_id')))
|
||
{
|
||
$this->ip_address_span .= ' '.html::anchor (
|
||
url_lang::base().'allowed_subnets/change/'.$allowed_subnet->id,
|
||
html::image (array(
|
||
'src' => url::base().'media/images/'.(($allowed_subnet->enabled) ? 'active' : 'inactive').'.png',
|
||
'title' => ($allowed_subnet->enabled) ? url_lang::lang('texts.Disable this subnet') : url_lang::lang('texts.Enable this subnet'))
|
||
)
|
||
);
|
||
$this->ip_address_span .= ' '. (($allowed_subnet->enabled) ? help::hint('allowed_subnets_enabled') : help::hint('allowed_subnets_disabled'));
|
||
}
|
||
// toggle button between allowed subnets
|
||
$allowed_subnet_model = new Allowed_subnet_Model();
|
||
|
||
$allowed_subnet = $allowed_subnet_model->get_allowed_subnet_by_member_and_ip_address(
|
||
$this->session->get('member_id'), server::remote_addr()
|
||
);
|
||
|
||
// it's possible to change allowed allowed subnets
|
||
if ($allowed_subnet &&
|
||
$allowed_subnet->id &&
|
||
$allowed_subnet_model->count_all_disabled_allowed_subnets_by_member(
|
||
$this->session->get('member_id')
|
||
))
|
||
{
|
||
$this->ip_address_span .= ' ' . html::anchor(
|
||
url_lang::base() . 'allowed_subnets/change/' . $allowed_subnet->id, html::image(array
|
||
(
|
||
'src' => url::base() . 'media/images/' . (($allowed_subnet->enabled) ? 'active' : 'inactive') . '.png',
|
||
'title' => ($allowed_subnet->enabled) ? __('Disable this subnet') : __('Enable this subnet'))
|
||
)
|
||
);
|
||
$this->ip_address_span .= ' ' . (($allowed_subnet->enabled) ?
|
||
help::hint('allowed_subnets_enabled') :
|
||
help::hint('allowed_subnets_disabled'));
|
||
}
|
||
}
|
||
|
||
// updates paths
|
||
... | ... | |
* Function to update paths
|
||
* @author Michal Kliment
|
||
*/
|
||
private function update_paths ()
|
||
private function update_paths()
|
||
{
|
||
if (!is_array($this->session->get('paths')))
|
||
$this->session->set('paths', array());
|
||
if (!is_array($this->session->get('paths')))
|
||
$this->session->set('paths', array());
|
||
|
||
$paths = $this->session->get('paths');
|
||
$paths = $this->session->get('paths');
|
||
|
||
if (url_lang::current(TRUE) != 'login' && url_lang::current(TRUE) != 'json')
|
||
if (url_lang::current(TRUE) != 'login' && url_lang::current(TRUE) != 'json')
|
||
{
|
||
if (isset($paths[$this->session->get('last_path_id')]))
|
||
{
|
||
if (isset($paths[$this->session->get('last_path_id')]))
|
||
$path = $paths[$this->session->get('last_path_id')];
|
||
|
||
if ($path[count($path) - 1] != url::base(TRUE) . url::current())
|
||
{
|
||
if (url::base() . url::previous() != $path[count($path) - 1])
|
||
{
|
||
$path = $paths[$this->session->get('last_path_id')];
|
||
|
||
if ($path[count($path)-1] != url::base(TRUE).url::current())
|
||
foreach ($paths as $id => $path)
|
||
{
|
||
if (isset($path[count($path) - 1]) && url::base() . url::previous() == $path[count($path) - 1])
|
||
{
|
||
if (url::base().url::previous() != $path[count($path)-1])
|
||
{
|
||
foreach ($paths as $id => $path)
|
||
{
|
||
if (isset($path[count($path)-1]) && url::base().url::previous() == $path[count($path)-1])
|
||
{
|
||
$this->session->set('last_path_id', $id);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
$path = NULL;
|
||
foreach ($paths[$this->session->get('last_path_id')] as $i => $url)
|
||
{
|
||
if (url::base(TRUE).url::current() == $url)
|
||
{
|
||
$path = array_slice($paths[$this->session->get('last_path_id')], 0, $i+1);
|
||
break;
|
||
}
|
||
}
|
||
if (!$path)
|
||
$paths[$this->session->get('last_path_id')][] = url::base(TRUE).url::current();
|
||
else
|
||
$paths[$this->session->get('last_path_id')] = $path;
|
||
$this->session->set('last_path_id', $id);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
$path = NULL;
|
||
foreach ($paths[$this->session->get('last_path_id')] as $i => $url)
|
||
{
|
||
if (url::base(TRUE) . url::current() == $url)
|
||
{
|
||
$path = array_slice($paths[$this->session->get('last_path_id')], 0, $i + 1);
|
||
break;
|
||
}
|
||
}
|
||
if (!$path)
|
||
$paths[$this->session->get('last_path_id')][] = url::base(TRUE) . url::current();
|
||
else
|
||
$paths[$this->session->get('last_path_id')][] = url::base(TRUE).url::current();
|
||
$paths[$this->session->get('last_path_id')] = $path;
|
||
}
|
||
}
|
||
else
|
||
$paths[$this->session->get('last_path_id')][] = url::base(TRUE) . url::current();
|
||
}
|
||
|
||
$this->session->set('paths', $paths);
|
||
$this->session->set('paths', $paths);
|
||
}
|
||
|
||
}
|
||
?>
|
Také k dispozici: Unified diff
Optimalizace MY_Controlleru:
- ziskani 50% RAM pri pozadavku, kde neni nutne prihlaseni
- zrychleno 0.13 sekundy u vsech pozadavku
Opravy a upravy:
- vycisteni hooks