Вход Регистрация
Файл: databasr/application/core/MY_Controller.php
Строк: 77
<?php

class MY_Controller extends CI_Controller
{
    private 
$breadcrumb;

    public function 
__construct()
    {
        
parent::__construct();
        
        if(!
$this->session->username || !$this->session->password || !$this->session->database) {
            
$this->forward('login');
        }

        
// connect to database
        
$config['hostname'] = $this->config->item('databasr_host');
        
$config['username'] = $this->session->username;
        
$config['password'] = $this->session->password;
        
$config['database'] = $this->session->database;
        
$config['dbdriver'] = $this->config->item('databasr_driver');
        
$config['dbprefix'] = "";
        
$config['pconnect'] = false;
        
$config['db_debug'] = false;

        
$this->db = $this->load->database($config, true);
        
        
// get all tables
        
$tables = $this->db->list_tables();
        
$this->template->assign('globalTables', $tables);
        
        
// get active database
        
$database = $this->db->database;
        
$this->template->assign('globalDatabase', $database);

        
$this->template->assign('globalUsername', $config['username']);

        
$this->addCrumb("Dashboard", "/");

        
$this->addCrumb($database, "/databases");
    }

    public function 
addCrumb($label, $location)
    {
        
$this->breadcrumb[] = [
            
'label' => $label,
            
'location' => $location
        
];

        
$this->template->assign('breadcrumb', $this->breadcrumb);
    }

    public function 
forward($controller = null, $action = null, $params = null)
    {
        
$url = [ $controller, $action, $params ];

        
redirect(site_url($url));
    }

    public static function 
formatBytes($bytes, $precision = 2)
    {
        
$units = array('B', 'KB', 'MB', 'GB', 'TB');

        
$bytes = max($bytes, 0);
        
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
        
$pow = min($pow, count($units) - 1);

        
$bytes /= pow(1024, $pow);

        return 
round($bytes, $precision) . ' ' . $units[$pow];
    }

    public function 
alert($message, $type = 'success')
    {
        
$userdata = $this->session->all_userdata();
        if(isset(
$userdata['alerts'])) {
            
$alerts = $userdata['alerts'];
        } else {
            
$alerts = array();
        }

        if(
$type == 'error') $type = 'danger';

        
$alerts[] = array('message' => $message, 'type' => $type);
        
$this->session->set_userdata('alerts', $alerts);
    }

    public function 
displayAlert()
    {
        
$userdata = $this->session->all_userdata();

        if(isset(
$userdata['alerts'])) {
            
$this->template->assign('alerts', $userdata['alerts']);
            
$this->session->set_userdata('alerts', '');
        }
    }
}
Онлайн: 1
Реклама