<?php
session_name("e_learning");
session_start();

/**** CHANGE HEADER ****/
if ( isset($_GET['rate']) ) {
    header('Location:' . str_replace('&rated_id=' . $_GET['rated_id'], '', str_replace('&rate=' . $_GET['rate'], '', $_SERVER['REQUEST_URI'])));
}

/**** LOGIN: START ****/

include_once('./class/sql.class.php');
include_once('./class/main.class.php');
include_once('./class/rs.class.php');
include_once('./class/file_upload.class.php');
include_once('./class/admin.class.php');
if ( $_GET['id'] == 3 ) {
	include_once('./class/reg.class.php');
	$reg = new Reg();
}
	
echo strpos($_SERVER['REQUEST_URI'], 'praca/');

$sql = new sql(); 	// inicializacia objektu pre pracu s db
$main = new Main();	// inicializacia hlavneho objektu
$rs = new Rs();	// inicializacia objektu rs na pridavanie clankov
$file = new File();	// inicializacia objektu na uploadovanie suborov
$admin = new Admin();

if ( isset($_SESSION['id_user']) && $main->is_logged($_SESSION['id_user']) ) {
    $main->refresh_login($_SESSION['id_user']);
}

if ( ( isset($_SESSION['id_user']) && !empty($_SESSION['id_user']) && isset($_POST['logout']) ) && $main->is_logged($_SESSION['id_user']) ) {
	$main->logout($_SESSION['id_user']);
	$_SESSION = array();
	session_destroy();
} elseif ( isset($_POST['login']) && isset($_POST['log_name']) && (trim($_POST['log_name'])!='') && isset($_POST['log_pass']) && (trim($_POST['log_pass'])!='') ) {
	$main->login($_POST['log_name'], $_POST['log_pass']);
}
	
if ( !isset($_GET['add']) && !isset($_GET['article']) ) {
	$_SESSION['uploadnute'] = array();
}

/**** LOGIN: END ****/
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>E-learning project</title>
	<link rel="stylesheet" type="text/css" href="style.css" />
    <link rel="stylesheet" type="text/css" href="rating/star/star_rating.css" />
	<script type="text/javascript" src="mootools/mootools.js"></script>
	<script type="text/javascript" src="mootools/slide/slide.js"></script>
    <link rel="stylesheet" type="text/css" media="screen" href="mootools/multi_upload/Stickman.MultiUpload.css" />
	<script type="text/javascript" src="mootools/multi_upload/Stickman.MultiUpload.js"></script>
    <script type="text/javascript" src="mootools/multi_upload/mootools1.1.js"></script>
    <?php if ( $_GET['id'] == 18 ) { echo '<link href="mootools/sortable_table/sortableTable.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="mootools/sortable_table/sortableTable.js"></script>'; } ?>
    <?php if ( $_GET['id'] == 12 ) { echo '<script type="text/javascript" src="scroll.js"></script>'; } ?>
</head>

<body <?php if ( $_GET['id'] == 12 ) { echo 'onload="loadScroll()" onunload="saveScroll()"'; } ?>>

<?
	include('head.php');

	echo '<div class="content">';
		if ( $main->include != '' )
			{
                include($main->include);
			} elseif ( isset($_GET['nahlas']) && $_GET['nahlas'] ) {
                if ( $main->is_logged($_SESSION['id_user']) && $main->group_right($_SESSION['id_user'], 1) ) {
                    if ( isset($_POST['nahlas']) && isset($_POST['dovod']) && (trim($_POST['dovod'])!='') ) {
                        $main->report_content($_SESSION['id_user'], $_GET['main_cat'], $_GET['root'], $_GET['part'], addslashes(nl2br($_POST['dovod'])) );
                    } else {
                        echo '
                            <h3>Nahlásenie príspevku administrátorovi:</h3>
                            <form action="' . $main->form_action . '" method="post">
                                <div style="float: left; margin-right: 5px;"><textarea style="font-size: 11px; border: 1px solid #00377E;" rows="5" cols="35" name="dovod" onfocus="this.value=\'\'">sem zadajte dôvod nahlásenia obsahu administrátorovi...</textarea></div>
                                <div style="float: left; width: 200px; font-size: 10px; color: #00377E;">* administrátorovi budú odoslané údaje na správnu identifikáciu nahláseného príspevku, text dôvodu a váš identifikátor</div>
                                ' . $main->cleaner . '
                                <br /><input type="submit" name="nahlas" value="Nahlás" />
                            </form>
                        ';
                    }
                } else {
                    echo $main->return_error_text('Pre nahlasovanie obsahu administrátorovi musíte byť prihlásený a musíte byť zo skupiny učiteľov.');
                }
            } else {
                $main->top_10('SELECT nadpis,id_branch,id,date,add_by,remake_of FROM articles WHERE id_root=1 GROUP BY remake_of ORDER BY utime DESC LIMIT 0,10', $main->vrat_nazov_korena(1));
                $main->top_10('SELECT nadpis,id_branch,id,date,add_by,remake_of FROM articles WHERE id_root=2 GROUP BY remake_of ORDER BY utime DESC LIMIT 0,10', $main->vrat_nazov_korena(2));
                $main->top_10('SELECT nadpis,id_branch,id,date,add_by,remake_of FROM articles WHERE id_root=14 GROUP BY remake_of ORDER BY utime DESC LIMIT 0,10', $main->vrat_nazov_korena(14));
                echo $main->cleaner;
                $main->top_5_rate();
                echo $main->cleaner;
                $main->forum_najnovsie();
            }
	echo '</div>';
?>

</body>
</html>