<?php
//---[CZ]: ověříme přístup
if ($login->check_access("sections")==1):

//---[CZ]: načteme potřebné třídy
include CLASSES_PATH."Sections.php";

//---[CZ]: vytvoříme instance
$sections=new Sections();

//---[CZ]: nová sekce
if (isset($_POST["submit"]) AND $_GET["tab"]=="") { $sections->add_section(); }

//---[CZ]: nová položka sloupce
if (isset($_POST["submit"]) AND $_GET["tab"]=="columns") { $sections->add_column_item(); }

//---[CZ]: smazání
if ($_GET["action"]=="delete" AND $_GET["tab"]=="") { $sections->delete_section(); }

//---[CZ]: smazání
if ($_GET["action"]=="delete" AND $_GET["tab"]=="columns") { $sections->delete_column_item(); }

//---[CZ]: editace
if (isset($_POST["submit_edit"]) AND $_GET["tab"]=="") { $sections->edit_section(); }

//---[CZ]: editace
if (isset($_POST["submit_edit"]) AND $_GET["tab"]=="columns") { $sections->edit_column_item(); }

//---[CZ]: posunutí nahoru
if ($_GET["action"]=="move_up") { $sections->move_up(); }

//---[CZ]: posunutí dolů
if ($_GET["action"]=="move_down") { $sections->move_down(); }
?>

<h2><?php echo LANG_SECTIONS; ?></h2>

<ul id="tab-bar">
<li<?php if ($_GET["tab"]=="") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=sections&amp;tab="><?php echo LANG_SECTIONS; ?></a></li>
<li<?php if ($_GET["tab"]=="columns") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=sections&amp;tab=columns"><?php echo LANG_COLUMNS; ?></a></li>
<li><span class="float-ending"><!-- --></span></li>
</ul>


<?php if ($_GET["tab"]==""): ?>

<?php if ($_GET["part"]==""): ?>

<h3><?php echo LANG_ADD_SECTION; ?></h3>

<form action="./admin.php?function=sections" method="post">

<div>

<p><strong><?php echo LANG_NAME; ?>:</strong><br /><input type="text" name="name" style="width: 150px;" /><?php if (isset($_POST["submit"]) AND $_POST["name"]=="") { echo " <span class=\"input-error\">&times;</span>"; } ?></p>

<p><input type="submit" class="greenbutton" name="submit" value="<?php echo LANG_ADD; ?>" /></p>

</div>

</form>

<table>
<tr>
<th class="table-title" colspan="5"><?php echo LANG_LIST_OF_SECTIONS; ?></th>
</tr>
<tr>
<th style="width: 45%;"><?php echo LANG_NAME; ?></th>
<th style="width: 10%;"><?php echo LANG_POSITION; ?></th>
<th style="width: 10%;"><?php echo LANG_HIGHLIGHT; ?></th>
<th style="width: 10%;"><?php echo LANG_OUTLINK; ?></th>
<th style="width: 25%;"><?php echo LANG_OPTIONS; ?></th>
</tr>
<?php $sections->output_sections(0); ?>
</table>

<?php endif; if ($_GET["part"]=="edit"): ?>

<h3><?php echo LANG_SECTION_EDITATION.": ".$sections->get("name"); ?></h3>

<form action="./admin.php?function=sections&amp;part=edit&amp;id=<?php echo($_GET["id"]); ?>" method="post">

<div>

<p><strong><?php echo LANG_NAME; ?>:</strong><br /><input type="text" name="name" style="width: 200px;" value="<?php echo $sections->get("name"); ?>" /><?php if (isset($_POST["submit_edit"]) AND $_POST["name"]=="") { echo " <span class=\"input-error\">&times;</span>"; } ?></p>

<p><strong><?php echo LANG_OPTIONS; ?>:</strong><br /><input type="checkbox" name="highlight" value="1"<?php if ($sections->get("highlight")==1) { echo " checked=\"checked\""; } ?> /> <?php echo LANG_HIGHLIGHT; ?><br />
<input type="checkbox" name="ntbl" value="1"<?php if ($sections->get("ntbl")==1) { echo " checked=\"checked\""; } ?> /> <?php echo LANG_YOU_MUST_BE_LOGGED_IN_FOR_ACCESS_TO_THIS_SECTION; ?><br />
<input type="checkbox" name="hidden" value="1"<?php if ($sections->get("hidden")==1) { echo " checked=\"checked\""; } ?> /> <?php echo LANG_HIDE; ?></p>

<p><strong><?php echo LANG_OUTLINK; ?>:</strong><br /><input type="text" name="outlink" style="width: 200px;" value="<?php echo $sections->get("outlink"); ?>" /></p>

<p><input type="button" class="yellowbutton" onclick="parent.location='./admin.php?function=sections';" value="<?php echo LANG_BACK; ?>" /> <input type="submit" name="submit_edit" class="greenbutton" value="<?php echo LANG_SAVE_CHANGES; ?>" /></p>

</div>

</form>

<h3><?php echo LANG_ADD_SUBSECTION; ?></h3>

<form action="./admin.php?function=sections&amp;part=edit&amp;id=<?php echo($_GET["id"]); ?>" method="post">

<div>

<p><strong><?php echo LANG_NAME; ?>:</strong><br /><input type="text" name="name" style="width: 150px;" /><?php if (isset($_POST["submit"]) AND $_POST["name"]=="") { echo " <span class=\"input-error\">&times;</span>"; } ?></p>

<p><input type="submit" name="submit" class="greenbutton" value="<?php echo LANG_ADD; ?>" /></p>

</div>

</form>

<table>
<tr>
<th class="table-title" colspan="5"><?php echo LANG_LIST_OF_SUBSECTIONS; ?></th>
</tr>
<tr>
<th style="width: 45%;"><?php echo LANG_NAME; ?></th>
<th style="width: 10%;"><?php echo LANG_POSITION; ?></th>
<th style="width: 10%;"><?php echo LANG_HIGHLIGHT; ?></th>
<th style="width: 10%;"><?php echo LANG_OUTLINK; ?></th>
<th style="width: 25%;"><?php echo LANG_OPTIONS; ?></th>
</tr>
<?php $sections->output_sections($_GET["id"]); ?>
</table>

<?php endif; ?>

<?php endif; ?>

<?php if ($_GET["tab"]=="columns"): ?>

<?php if ($_GET["part"]==""): ?>

<h3><?php echo LANG_ADD_ITEM; ?></h3>

<form action="./admin.php?function=sections&amp;tab=columns" method="post">

<div>

<p><strong><?php echo LANG_NAME; ?>:</strong><br /><input type="text" name="name" style="width: 150px;" /><?php if (isset($_POST["submit"]) AND $_POST["name"]=="") { echo " <span class=\"input-error\">&times;</span>"; } ?></p>

<p><strong><?php echo LANG_PROPERTIES; ?>:</strong><br /><input type="radio" name="column" value="left" checked="checked" /> <?php echo LANG_LEFT_COLUMN; ?><br /><input type="radio" name="column" value="right" /> <?php echo LANG_RIGHT_COLUMN; ?></p>

<p><input type="submit" class="greenbutton" name="submit" value="<?php echo LANG_ADD; ?>" /></p>

</div>

</form>

<table style="float: left; width: 360px;">
<tr>
<th class="table-title" colspan="3"><?php echo LANG_LEFT_COLUMN; ?></th>
</tr>
<tr>
<th style="width: 50%;"><?php echo LANG_NAME; ?></th>
<th style="width: 20%;"><?php echo LANG_POSITION; ?></th>
<th style="width: 30%;"><?php echo LANG_OPTIONS; ?></th>
</tr>
<?php $sections->output_columns("left"); ?>
</table>

<table style="float: left; width: 360px; margin-left: 10px;">
<tr>
<th class="table-title" colspan="3"><?php echo LANG_RIGHT_COLUMN; ?></th>
</tr>
<tr>
<th style="width: 50%;"><?php echo LANG_NAME; ?></th>
<th style="width: 20%;"><?php echo LANG_POSITION; ?></th>
<th style="width: 30%;"><?php echo LANG_OPTIONS; ?></th>
</tr>
<?php $sections->output_columns("right"); ?>
</table>

<div class="float-ending"><!-- --></div>

<?php endif; if ($_GET["part"]=="edit"): ?>

<h3><?php echo LANG_EDIT." &rarr; ".$sections->get("name"); ?></h3>

<form action="./admin.php?function=sections&amp;tab=columns&amp;part=edit&amp;id=<?php echo($_GET["id"]); ?>" method="post">

<div>

<p><strong><?php echo LANG_NAME; ?>:</strong><br /><input type="text" name="name" style="width: 150px;" value="<?php echo htmlspecialchars($sections->get("name")); ?>" /><?php if (isset($_POST["submit_edit"]) AND $_POST["name"]=="") { echo " <span class=\"input-error\">&times;</span>"; } ?></p>

<p><strong><?php echo LANG_PROPERTIES; ?>:</strong><br /><input type="checkbox" name="hidden" value="1"<?php if ($sections->get("hidden")==1) { echo " checked=\"checked\""; } ?> /> <?php echo LANG_HIDE; ?></p>

<p><strong><?php echo LANG_CONTENT; ?>:</strong><br /></p>

</div>

<div class="normal"><textarea name="itemcontent" class="widgEditor nothing"><?php echo $sections->get("content"); ?></textarea></div>


<div>

<p><input type="submit" class="greenbutton" name="submit_edit" value="<?php echo LANG_SAVE_CHANGES; ?>" /></p>

</div>

</form>

<?php endif; ?>

<?php endif; ?>

<?php else: $access_denied=1; endif; ?>