<?php
session_start();

 

    require 'c/core.php';
    
    define( 'I_UPDATED' , 'Dane zostały zaktualizowane' );
    define( 'I_SAVED' , 'Dane zostały zapisane' );
    define( 'CE_LIST' , 'Brak elementów do wyświetlenia' );
    
    $admin = new admin;
    $View = new View;
    $error_text = false;
    
    css::$i->put(array(
        'css/std.css',
        'css/cp.css',
        'css/cp-mobile.css',
        'css/font-awesome.css',
        'css/bootstrap.css',
        'css/jquery.custom-scrollbar.css'
    ));
 

    js::$instance->put(array(
        'js/jquery.js',
        'js/bootstrap.js',
        'js/core.js',
        'js/jquery.custom-scrollbar.js'
    ));

    
    if($_GET['logout']==1){
        $user->logout();
        header("Location:" . core::$i->url . '/' . admin::$i->url );
        die();
    }
    
    if( core::POST() AND !empty($_REQUEST['auth_cp_mode']) ){
        
        $user->login( $_REQUEST['login'] , false , $_REQUEST['password'] );
        if( !$user->online ){
            
            if( $user->login_error_code == 4 ) statement::$i->set( l('Niepoprawny kod 2FA') );
            else statement::$i->set( l('Niepoprawny login lub hasło') );
            
        } else {
            
            header("Location:".admin::$i->url);
            exit;
            
        }
    }
    
    css::$i->put(array(
        'css/ui-smoothness/jquery-ui.css'
    ));
  
    if( $user->online and $user->mode=='admin' ){


        
        js::$i->put( 'js/cp.js' );


        if( file_exists( $admin->dir . core::$i->mode . '/index.php' ) )  include $admin->dir . core::$i->mode . '/index.php';
        else include $admin->dir . 'home/index.php';
        
        include $admin->dir . 'header.php';
        include $admin->dir . 'global.php';
        include $admin->dir . 'footer.php';
    
    } else {
        
        header("Location:".core::$i->url);
        exit;
    }
    
?>