Revize 127
Přidáno uživatelem Tomáš Dulík před asi 16 roky(ů)
freenetis/trunk/kohana/application/libraries/MY_Controller.php | ||
---|---|---|
<?php
|
||
|
||
class Controller extends Controller_Core {
|
||
public $gacl_class;
|
||
private $myMenu;
|
||
public $arr;
|
||
|
||
public function __construct(){
|
||
|
||
parent::__construct();
|
||
//authentication goes here for example
|
||
|
||
public $gacl_class;
|
||
private $myMenu;
|
||
public $arr;
|
||
|
||
public function __construct(){
|
||
|
||
parent::__construct();
|
||
//authentication goes here for example
|
||
|
||
if (!$this->session->get('user_id', 0) && url_lang::current()!='login' && url_lang::current()!='registration' && url_lang::current()!='accounts/parse_ebank_account')
|
||
{
|
||
// Not logged in - redirect to login page
|
||
$this->session->set_flash('err_message', url_lang::lang('texts.Must be logged in'));
|
||
$this->session->set_flash('err_message', url_lang::lang('texts.Must be logged in'));
|
||
url::redirect(url_lang::base().'login');
|
||
die();
|
||
die();
|
||
}
|
||
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
|
||
* @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
|
||
*/
|
||
public function acl_check_2D($aco_section, $aco_value) {
|
||
return $this->gacl_class->acl_check($aco_section, $aco_value, 'all', $_SESSION['username']);
|
||
}
|
||
$this->phpgacl_init();
|
||
}
|
||
|
||
/**
|
||
* 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
|
||
*/
|
||
|
||
public function acl_check_3D($aco_section, $aco_value, $axo_value) {
|
||
return $this->gacl_class->acl_check($aco_section, $aco_value, 'all', $_SESSION['username'],get_class($this),$axo_value);
|
||
}
|
||
|
||
/* public function do_something(){
|
||
//method available in all controllers
|
||
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
|
||
*/
|
||
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
|
||
*/
|
||
|
||
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 do_something(){
|
||
//method available in all controllers
|
||
}*/
|
||
|
||
public function render_menu ($active = null)
|
||
... | ... | |
|
||
//verze 2
|
||
/*$this->myMenu = '';
|
||
$model = new Menu_Model;
|
||
$i = 0;
|
||
foreach($model->find_all() as $menu){
|
||
$model = new Menu_Model;
|
||
$i = 0;
|
||
foreach($model->find_all() as $menu){
|
||
$arr[$i]['name'] = $menu->name;
|
||
$arr[$i]['url'] = $menu->url;
|
||
$arr[$i]['id'] = $menu->id;
|
||
$arr[$i]['master_id'] = $menu->master_id;
|
||
$i++;
|
||
}
|
||
$myMenu = $this->create_menu($arr,0);
|
||
return str_replace('<ul></ul>', '', $myMenu);*/
|
||
}
|
||
$myMenu = $this->create_menu($arr,0);
|
||
return str_replace('<ul></ul>', '', $myMenu);*/
|
||
|
||
if ($this->session->get('member_login')==$this->session->get('username')) $url = 'members/show/'.$this->session->get('member_id');
|
||
else $url = 'users/show/'.$this->session->get('user_id');
|
||
... | ... | |
<ul>
|
||
<li>'.html::anchor(url_lang::base().$url, url_lang::lang('texts.My profile')).'</li>';
|
||
|
||
if ($this->acl_check_2D('menu', 'my_users')) $myMenu .= '<li>'.html::anchor(url_lang::base().'members/users/'.$this->session->get('member_id'), url_lang::lang('texts.My users')).'</li>';
|
||
if ($this->acl_check_2D('menu', 'my_users')) $myMenu .= '<li>'.html::anchor(url_lang::base().'members/users/'.$this->session->get('member_id'), url_lang::lang('texts.My users')).'</li>';
|
||
|
||
if ($this->acl_check_2D('menu', 'my_transfers')) $myMenu .= '<li>'.html::anchor(url_lang::base().'accounts/transfers/'.$this->session->get('member_id'), url_lang::lang('texts.My transfers')).'</li>';
|
||
if ($this->acl_check_2D('menu', 'my_transfers')) $myMenu .= '<li>'.html::anchor(url_lang::base().'accounts/transfers/'.$this->session->get('member_id'), url_lang::lang('texts.My transfers')).'</li>';
|
||
if ($this->acl_check_2D('menu', 'my_devices')) $myMenu .= ' <li>'.html::anchor(url_lang::base().'devices/show_my', url_lang::lang('texts.My devices')).'</li>';
|
||
$myMenu .= ' </ul>
|
||
</li>';
|
||
$acc_menu = '';
|
||
if ($this->acl_check_2D('menu', 'unconfirmed_works'))
|
||
$acc_menu = '<li>'.html::anchor(url_lang::base().'works/uncorfirmed/', url_lang::lang('texts.Unconfirmed works')).'</li>';
|
||
if ($this->acl_check_2D('menu', 'unconfirmed_works'))
|
||
$acc_menu = '<li>'.html::anchor(url_lang::base().'works/uncorfirmed/', url_lang::lang('texts.Unconfirmed works')).'</li>';
|
||
|
||
if ($this->acl_check_2D('menu', 'unidentified_transfers'))
|
||
$acc_menu .= '<li style="padding-bottom:8px;">'.html::anchor(url_lang::base().'accounts/unidentified_transfers/', url_lang::lang('texts.Unidentified transfers')).'</li>';
|
||
if ($this->acl_check_2D('menu', 'unidentified_transfers'))
|
||
$acc_menu .= '<li style="padding-bottom:8px;">'.html::anchor(url_lang::base().'accounts/unidentified_transfers/', url_lang::lang('texts.Unidentified transfers')).'</li>';
|
||
|
||
if ($this->acl_check_2D('menu', 'accounts'))
|
||
$acc_menu .= '<li>'.html::anchor(url_lang::base().'accounts/main_accounts/master', url_lang::lang('texts.Bank account')).'</li>
|
||
if ($this->acl_check_2D('menu', 'accounts'))
|
||
$acc_menu .= '<li>'.html::anchor(url_lang::base().'accounts/main_accounts/master', url_lang::lang('texts.Bank account')).'</li>
|
||
<li>'.html::anchor(url_lang::base().'accounts/main_accounts/infrastructure', url_lang::lang('texts.Infrastructure account')).'</li>
|
||
<li>'.html::anchor(url_lang::base().'accounts/main_accounts/operating', url_lang::lang('texts.Operating account')).'</li>
|
||
<li>'.html::anchor(url_lang::base().'money_transfers', url_lang::lang('texts.Money transfers')).'</li>';
|
||
... | ... | |
</ul>
|
||
</li>';
|
||
|
||
if ($this->acl_check_2D('menu', 'users_members'))
|
||
$myMenu .= '<li class="users"><h2>'.url_lang::lang('texts.Users').'</h2>
|
||
if ($this->acl_check_2D('menu', 'users_members'))
|
||
$myMenu .= '<li class="users"><h2>'.url_lang::lang('texts.Users').'</h2>
|
||
<ul>
|
||
<li>'.html::anchor(url_lang::base().'members', url_lang::lang('texts.Members')).'</li>
|
||
<li>'.html::anchor(url_lang::base().'users', url_lang::lang('texts.Users')).'</li>
|
||
</ul>
|
||
</li>';
|
||
if ($this->acl_check_2D('menu', 'network'))
|
||
$myMenu .= '<li class="networks"><h2>'.url_lang::lang('texts.Networks').'</h2>
|
||
if ($this->acl_check_2D('menu', 'network'))
|
||
$myMenu .= '<li class="networks"><h2>'.url_lang::lang('texts.Networks').'</h2>
|
||
<ul>
|
||
<li>'.html::anchor(url_lang::base().'devices', url_lang::lang('texts.Devices')).'</li>
|
||
<li>'.html::anchor(url_lang::base().'segments', url_lang::lang('texts.Segments')).'</li>
|
||
... | ... | |
|
||
|
||
public function error($message = null)
|
||
{
|
||
if (is_numeric($message))
|
||
{
|
||
switch ($message) {
|
||
case 1:
|
||
$message = url_lang::lang('texts.You dont have the permissions.');
|
||
break;
|
||
{
|
||
if (is_numeric($message))
|
||
{
|
||
switch ($message) {
|
||
case 1:
|
||
$message = url_lang::lang('texts.You dont have the permissions.');
|
||
break;
|
||
|
||
}
|
||
}
|
||
if (!isset($message)) $message = url_lang::lang('texts.ID is required.');
|
||
}
|
||
}
|
||
if (!isset($message)) $message = url_lang::lang('texts.ID is required.');
|
||
|
||
$view = new View('template');
|
||
$view->header = new View('base/header');
|
||
$view->header->title = url_lang::lang('texts.Error'.' - '.$message);
|
||
$view->header->menu = Controller::render_menu();
|
||
$view = new View('template');
|
||
$view->header = new View('base/header');
|
||
$view->header->title = url_lang::lang('texts.Error'.' - '.$message);
|
||
$view->header->menu = Controller::render_menu();
|
||
|
||
$view->content = new View('errors');
|
||
$view->content->required = $message;
|
||
$view->content = new View('errors');
|
||
$view->content->required = $message;
|
||
|
||
$view->footer = new View('base/footer');
|
||
$view->footer = new View('base/footer');
|
||
|
||
$view->render(TRUE);
|
||
exit;
|
||
}
|
||
|
||
public function insert_phpgacl($user_id,$username,$value,$group, $is_edit = false)
|
||
{
|
||
// $aro_data = new Aro_Model();
|
||
$aro_group_data = new Group_aro_map_Model();
|
||
switch ($group) {
|
||
case 'member':
|
||
$group_id = 22;
|
||
break;
|
||
case 'wannabe':
|
||
$group_id = 23;
|
||
break;
|
||
default:
|
||
$group_id = 33;
|
||
break;
|
||
}
|
||
$view->render(TRUE);
|
||
exit;
|
||
}
|
||
|
||
public function insert_phpgacl($user_id,$username,$value,$group, $is_edit = false)
|
||
{
|
||
// $aro_data = new Aro_Model();
|
||
$aro_group_data = new Group_aro_map_Model();
|
||
switch ($group) {
|
||
case 'member':
|
||
$group_id = 22;
|
||
break;
|
||
case 'wannabe':
|
||
$group_id = 23;
|
||
break;
|
||
default:
|
||
$group_id = 33;
|
||
break;
|
||
}
|
||
|
||
$group_arr = array();
|
||
/*
|
||
$aro = array();
|
||
$aro['value'] = $value;
|
||
$aro['name'] = $username;
|
||
$aro['section_value'] = 'all';
|
||
*/
|
||
$group_arr['group_id'] = $group_id;
|
||
|
||
if ($is_edit)
|
||
{
|
||
// editation of phpgacl ARO
|
||
// $aro_data->insert_aro($aro,$user_id);
|
||
$group_arr = array();
|
||
/*
|
||
$aro = array();
|
||
$aro['value'] = $value;
|
||
$aro['name'] = $username;
|
||
$aro['section_value'] = 'all';
|
||
*/
|
||
$group_arr['group_id'] = $group_id;
|
||
|
||
$aro_group_data->insert_data($group_arr, $user_id);
|
||
}
|
||
else
|
||
{
|
||
/* $aro['id'] = $user_id;
|
||
$aro_data->insert_aro($aro);
|
||
*/
|
||
$group_arr['aro_id'] = $user_id;
|
||
$aro_group_data->insert_data($group_arr);
|
||
}
|
||
}
|
||
if ($is_edit)
|
||
{
|
||
// editation of phpgacl ARO
|
||
// $aro_data->insert_aro($aro,$user_id);
|
||
|
||
$aro_group_data->insert_data($group_arr, $user_id);
|
||
}
|
||
else
|
||
{
|
||
/* $aro['id'] = $user_id;
|
||
$aro_data->insert_aro($aro);
|
||
*/
|
||
$group_arr['aro_id'] = $user_id;
|
||
$aro_group_data->insert_data($group_arr);
|
||
}
|
||
}
|
||
|
||
}
|
||
?>
|
Také k dispozici: Unified diff
Drobné změny, které už si nepamatuju...(sory)