<script type="text/javascript">
    //if($defined($('main_form'))) {
        window.addEvent('domready', function(){
            new MultiUpload( $('main_form').defaults );
        });
    //}
</script>
<?
	if ( !isset($_GET['article']) ) {
		echo '<h3>Táto sekcia je venovaná poznámkam rôznych predmetov.</h3>';
		if ( !isset($_GET['add']) ) {
            if ( $main->is_logged($_SESSION['id_user']) && ($main->je_hlavna_sekcia($_GET['id'])) && $main->splnam_prava($_GET['id']) ) {
				echo '<h4>&raquo;&nbsp;<a href="?id=' . $_GET['id'] . '&amp;add=1" title="Pridajte vlastné poznámky">Pridajte vlastné poznámky</a></h4>';
			}
			$main->return_subjects($_GET['id']);
			echo '<div class="txt_panel">';
				$main->return_article_list('poznámok');
			echo '</div>';
		} elseif ($main->je_hlavna_sekcia($_GET['id']) && $main->splnam_prava($_GET['id']) ) {
			if ( $main->is_logged($_SESSION['id_user']) ) {
				echo '<h4>&raquo;&nbsp;<a href="' . str_replace('&add=1', '', $_SERVER['REQUEST_URI']) . '" title="Spat">Spat</a></h4>';
                echo '
                    <script src="./text_editor/js/richtext.js" type="text/javascript" language="javascript"></script>
                    <script src="./text_editor/js/config.js" type="text/javascript" language="javascript"></script>
                ';
                include("pages/edit.php");
			}
		} else {
            echo $main->return_error_text('Nemate prava na pridavanie ani editaciu clankov v tejto sekcii.');
        }
	} else {
        $rate_val = array(1,2,3,4,5); //hodnoty akceptovane pri hlasovani

        if ( isset($_GET['history']) ) {
            $sql_article = 'SELECT * FROM articles WHERE id=' . $_GET['history'] . ' AND show_web=1';  //pokial zobrazujem clanok z historie zobrazim ho
            $back = array('article');
        } else {
            $sql_article = 'SELECT * FROM articles WHERE remake_of=' . $_GET['article'] . ' AND show_web=1 ORDER BY utime DESC'; //inak zobrazim najnovsi a vsetky ktoremu predchadzali
            $back = array();
        }
        if ( isset($_GET['rate']) ) {
            if ( in_array($_GET['rate'], $rate_val) ) {
                if ( !isset($_GET['history']) ) {
                    $result_article = mysql_query($sql_article);
                    $row_article = mysql_fetch_assoc($result_article);
                    $main->rating_exe($row_article['id'],$_GET['rate']);
                } else {
                    $main->rating_exe($_GET['rated_id'],$_GET['rate']);
                }
            } else {
                echo $main->return_error_text("Daná hodnota nieje platné celé číslo &gt;= 1 a &lt;= 5  ");
            }
        }
		if ( $result_article = mysql_query($sql_article) ) {
			echo '<div class="txt_panel">';
            echo $main->back_button('id', $back);
				$row_article = mysql_fetch_assoc($result_article);

                if ( isset($_POST['edit_article_exe']) ) {
                    $main->edit_article_exe(addslashes(strip_tags($_POST['nadpis'])), addslashes($_POST['freeRTE_content']), $row_article['id_category'], $row_article['id_branch'], $row_article['remake_of'], $row_article['id']);
                }

                if ( !isset($_POST['edit_article']) ) {
                    $_SESSION['uploadnute'] = array();
                    echo '<h2>' . $row_article['nadpis'] . '</h2>';
                    echo '<div class="article_body">' . stripslashes($row_article['popis']) . '</div>';
                    echo '<div class="prilohy">prilohy:<br />' . $main->prilohy($row_article['id']) . '</div>';
                } else {
                    $main->edit_article($_GET['article']);
                }

            echo '<a id="v_slideout" style="display: none;" href="#">slide out</a>';
    		echo '<a id="v_slidein" style="display: none;" href="#">slide in</a>';
            if ( $main->is_logged($_SESSION['id_user']) ) {
                echo $main->show_hide();
                echo '<div id="vertical_slide" style="margin-top: 10px;">';
                if ( !isset($_POST['edit_article']) ) {
                    echo '<div style="float: left;">';
                    echo '<form action="' . str_replace('&','&amp;',$_SERVER['REQUEST_URI']) . '" method="post">';
                    echo    '<input name="edit_article" type="submit" value="Uprav" />';
                    echo '</form>';
                    echo '</div>';
                }
                echo '<div style="float: left; margin-left: 30px; padding: 5px;"><span style="font-weight: bold; color: #00377E;">Pridal:</span> ' . $main->get_user_name($row_article['add_by']) . '</div>';
                if ( $main->is_logged($_SESSION['id_user']) && $main->group_right($_SESSION['id_user'], 1) ) {
                    echo '<div style="float: left; margin-left: 30px; padding: 5px;"><span style="font-weight: bold; color: #00377E;"><a href="?nahlas=true&amp;main_cat=' . $_GET['id'] . '&amp;root=' . $_GET['article'] . '&amp;part=' . $row_article['id'] . '" title="">nahlásiť obsah adminovi</a></div>';
                }
                echo '<div style="float: right; margin-left: 30px;">';
                if ( $row_article['rated'] != 0 ) { //tu sa vola vypis hviezdiciek
                    if ( isset($_GET['history']) ) {
                        echo $main->rating_form($_GET['history']);
                    } else {
                        echo $main->rating_form($row_article['id']);
                    }
                    //echo $main->rating_form($row_article['rate']/$row_article['rated']);
                } else {
                    //echo $main->rating_form($_GET['article']); //tu musim doplnit id-cko !!!!!!!!!!!!!!
                    if ( isset($_GET['history']) ) {
                        echo $main->rating_form($_GET['history']);
                    } else {
                        echo $main->rating_form($row_article['id']);
                    }
                }
                echo '</div>';
                echo $main->cleaner;
                echo '</div>';
            }

			echo '</div>';
            if ( !isset($_GET['history']) ) {
                echo '<div class="history_panel">';
                echo '<h3>História úprav daného článku:</h3>';
                echo '<ul>';
                while ( $row_article = mysql_fetch_assoc($result_article) ) {
                    echo '<li><a href="?id=' . $_GET['id'] . '&amp;article=' . $_GET['article'] . '&amp;history=' . $row_article['id'] . '" title="">' . $row_article['nadpis'] . ' <span style="font-size: 10px;"><br />[ ' . $row_article['date'] . ' ]</span>' . '</a>
                            <br /><div style="float: right;">pridal: ' . $main->get_user_name($row_article['add_by']) . '</div>' . $main->cleaner . '</li>';
                }
                echo '</ul>';
                echo '</div>';
            }
            echo $main->cleaner;
		}
	}
?>