<?php

//ini_set('display_errors', 0);
//ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


//AUTOLOAD BEÁLLÍTÁSA
spl_autoload_register(function ($class_name) {
    $exception = array(
        'Smarty',
        'Smarty_Internal_Data',
        'SmartyException',
        'Smarty_Internal_TemplateCompilerBase',
        'Smarty_Internal_Templatelexer',
        'Smarty_Internal_Templateparser',
        'Smarty_Internal_ParseTree_Template',
        'Smarty_Internal_ParseTree',
        'Smarty_Internal_ParseTree_Tag',
        'Smarty_Internal_ParseTree_Text',
        'Smarty_Internal_Extension_CodeFrame',
        'Smarty_Internal_Write_File',
        'Smarty_Internal_Extension_CodeFrame',
        'Smarty_Internal_Extension_CodeFrame',
        'Smarty_Internal_Extension_CodeFrame',
        'Smarty_Internal_CompileBase',
        'Smarty_Undefined_Variable',
        'Smarty_Internal_ParseTree_DqContent',
        'Smarty_Internal_ParseTree_Dq'

        );
    if (!in_array($class_name, $exception)) include '_class/class_' . $class_name . '.php';
});

$months = array(
    '01' => 'január',
    '02' => 'február',
    '03' => 'március',
    '04' => 'április',
    '05' => 'május',
    '06' => 'június',
    '07' => 'július',
    '08' => 'augusztus',
    '09' => 'szeptember',
    '10' => 'október',
    '11' => 'november',
    '12' => 'december',
    );

$short_months = array(
    '01' => 'jan',
    '02' => 'feb',
    '03' => 'már',
    '04' => 'ápr',
    '05' => 'máj',
    '06' => 'jún',
    '07' => 'júl',
    '08' => 'aug',
    '09' => 'szept',
    '10' => 'okt',
    '11' => 'nov',
    '12' => 'dec',
    );

$days = array(
    '0' => 'v',
    '1' => 'h',
    '2' => 'k',
    '3' => 'sze',
    '4' => 'cs',
    '5' => 'p',
    '6' => 'szo',
    );

$error_msg = array(
    1 => 'Ezzel az e-mail címmel már regisztráltak!',
    2 => 'Sikeres regisztráció! Kérjük, jelentkezzen be a megadott adatokkal!',
    );

//SMARTY BEÁLLÍTÁSA
//require('../Smarty/Smarty.class.php');
require('../Smarty/Smarty.class.php');


$smarty = new Smarty();

$smarty->setTemplateDir('template/templates');
$smarty->setCompileDir('template/templates_c');
$smarty->setCacheDir('template/cache');
$smarty->setConfigDir('template/configs');

$smarty->assign('months', $months);
$smarty->assign('short_months', $short_months);
$smarty->assign('days', $days);
$smarty->assign('today', date('Y-m-d'));
$smarty->assign('error_msg', $error_msg);

//SQL KAPCSOLAT BEÁLLÍTÁSA
if ($_SERVER['HTTP_HOST'] == 'badmintoncoach.hu') $sql = new sql('bc_mysql','root','','badminton_coach');
else $sql = new sql('localhost','tollashodos','uprRscU8bGpJ','tollashodos');

$dev = $_SERVER['HTTP_HOST'] == 'badmintoncoach.hu';

//var_dump($sql);

//echo $_GET['page'];

$logout = false; //meg kell-e jeleníteni a kijelentkezés gombot

if ($_GET['page'] == 'admin') {
    if (isset($_COOKIE['badminton_admin_user'])) {
        $user = new user();
        $user->set_user_data_by_id($_COOKIE['badminton_admin_user']);
        $logout = true;
        $smarty->assign('user_login', $user);
        //var_dump($user);
    }
}
elseif ($_GET['page'] == 'view') {
    if (isset($_COOKIE['badminton_parent_user'])) {
        $user = new user_kid();
        $user->set_user_data_by_id($_COOKIE['badminton_parent_user']);
        $logout = true;
        $smarty->assign('user_login', $user);
        //var_dump($user);
    }
}
elseif ($_GET['page'] == 'coach') {
    if (isset($_COOKIE['badminton_coach_user'])) {
        $user = new user();
        $user->set_user_data_by_id($_COOKIE['badminton_coach_user']);
        $logout = true;
        $smarty->assign('user_login', $user);
        //var_dump($user);
    }
}
elseif ($_GET['page'] == 'preview' && (isset($_COOKIE['badminton_admin_user']))) {
    if (isset($_GET['id'])) {
        //var_dump($_GET['id']);
        $user = new user_kid();
        $user->set_user_data_by_id($_GET['id']);
        $logout = true;
        $smarty->assign('user_login', $user);
        //var_dump($user);
    }
}
elseif ($_GET['page'] == 'coach_preview' && (isset($_COOKIE['badminton_admin_user']))) {
    if (isset($_GET['id'])) {
        $user = new user();
        $user->set_user_data_by_id($_GET['id']);
        $logout = true;
        $smarty->assign('user_login', $user);
        //var_dump($user);
    }
}
elseif ($_GET['page'] == 'tabor' && (isset($_COOKIE['badminton_camp_user']))) {
        $user = new camp_user();
        $user->set_user_data_by_id($_COOKIE['badminton_camp_user']);
        $logout = true;
        $smarty->assign('user_login', $user);
        //var_dump($user);
}
elseif ($_GET['page'] == 'taborvezeto' && (isset($_COOKIE['badminton_camp_leader']))) {
        $user = new user_camp_leader();
        $user->set_user_data_by_id($_COOKIE['badminton_camp_leader']);
        $logout = true;
        $smarty->assign('user_login', $user);
        //var_dump($user);
}

$smarty->assign('can_logout', $logout);

//$page = new page();




?>
