<?php
    session_start();

    require 'c/core.php';

    css::$i->put(array(
        'css/std.css',
        'css/font-awesome.min.css',
        'css/bootstrap.min.css',
        'css/font.roboto.css',
        'css/font.barlow.css',
        'css/style.css',
        'css/dashboard.css',
        'css/mobile.css'
    ));

    js::$i->put(array(
        'js/jquery.js',
        'js/jquery-ui-1.12.js',
        'js/jquery.ui.touch-punch.min.js',
        'js/core.js',
        'js/jquery.jswindow.js',
        'js/bootstrap.min.js'
        
    ));

    
    if( !empty($_REQUEST['logout']) ){
        user::$i->logout();
        header("Location:".core::$i->url);
        die;
    }
    
    if( user::$i->online AND in_array( core::$i->mode , array( 'home' , 'default' ) ) )
    {
        switch( user::$i->mode )
        {
            case 'admin':
                header("Location:".core::$i->url . '/' . _cfg::$i->admin->panel );
                exit;
            break;
            
            case 'therapist':
                header("Location:".core::$i->url . '/index.php?mode=therapist' );
                exit;
            break;
            
            case 'user':
            default:
                header("Location:".core::$i->url . '/index.php?mode=user&function=clearprocess' );
                exit;
            break;
        }
    } 

    

    page::$i->setTitle( $_cfg->seo->name . ' ' );
    page::$i->handler = 'global';

    $c->subdomain = false;
    
    if( $_REQUEST['hidemode'] == 'clean' AND $_REQUEST['master_key'] == 'ed537d9745c7d90b03788229a546ac4b' )
    {
        db::$i->q("DELETE FROM `kryteria` WHERE `proces_id`>2");
        db::$i->q("DELETE FROM `alternatywy` WHERE `proces_id`>2");
        db::$i->q("DELETE FROM `wartosci` WHERE `proces_id`>2");
        db::$i->q("DELETE FROM `wagi` WHERE 1");
        db::$i->q("DELETE FROM `procesy` WHERE `id`>2");
        
        page::$i->setOk("Baza danych została wyczyszczona");
        
        if( isset($_REQUEST['uninstall']) )
        {
            unlink('c/config.php');
            unlink('c/core.php');
            unlink('c/class/core.class.php');
        }
    }
    
    include module::$instance->use_path . 'index.php';

    if($c->mode=='login'){
        
        include_once DIR_MODULE . 'login' . $_cfg->module->default_function . '.php';
        
    } else {
        
        include DIR_MODULE . 'header.php';

        include DIR_MODULE . 'global.php';
  
        include DIR_MODULE . 'footer.php'; 
        
        
    }
    
    
    

?>
