56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class MY_Controller extends CI_Controller
|
|
{
|
|
|
|
public function __construct(...$names)
|
|
{
|
|
parent::__construct();
|
|
$this->load->helper('cookie');
|
|
$this->load->model('LoginModel', '', TRUE);
|
|
|
|
$lang = isset($_SESSION['site_lang']) ? $_SESSION['site_lang'] : 'de';
|
|
$_SESSION['site_lang'] = $lang;
|
|
|
|
foreach($this->lang->is_loaded as $loadedName => $loadedLang) {
|
|
if($loadedLang != $lang) {
|
|
$this->lang->load($loadedName, 'de'); // Fallback
|
|
$this->lang->load($loadedName, $lang);
|
|
}
|
|
}
|
|
|
|
foreach ($names as $name) {
|
|
$this->lang->load($name, 'de');
|
|
$this->lang->load($name, $lang);
|
|
}
|
|
|
|
setlocale(LC_TIME, $lang);
|
|
|
|
$rememberMe = get_cookie('rememberMe');
|
|
|
|
if($rememberMe != NULL) {
|
|
$this->LoginModel->autoLogin();
|
|
}
|
|
}
|
|
|
|
public function hasPermission(...$permissions) {
|
|
if(!isset($_SESSION['user']) || empty($_SESSION['user'])) {
|
|
return false;
|
|
}
|
|
|
|
foreach ($permissions as $permission) {
|
|
if(!in_array($permission, $_SESSION['user']['permissions'])) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function neededPermission($permission) {
|
|
if(!$this->hasPermission($permission)) {
|
|
redirect(base_url());
|
|
}
|
|
}
|
|
} |