<?php
// check rights
if ($login->check_rights()>=2):
// loading of reqired classes
include CLASSES_PATH."Categories.php";
// creating of instances
$categories=new Categories();
// add new
if ($_GET["action"]=="add" AND $_POST["name"]!="") { $categories->add(); }
// move up
if ($_GET["action"]=="move_up" AND isset($_GET["position"])) { $categories->move_up(); }
// move down
if ($_GET["action"]=="move_down" AND isset($_GET["position"])) { $categories->move_down(); }
// delete
if ($_GET["action"]=="delete" AND isset($_GET["id"])) { $categories->delete(); }
?>

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

<?php if (!isset($_GET["f2"])): ?>

<form action="./admin.php?f=categories&amp;action=add" method="post">

<div>

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

</div>

<div>

<p><input type="submit" name="submit" value="<?php echo LANG_SAVE; ?>" /></p>

</div>

</form>

<table>
<tr>
<th style="width: 65%;"><?php echo LANG_NAME; ?></th>
<th style="width: 10%;"><?php echo LANG_POSITION; ?></th>
<th style="width: 25%;"><?php echo LANG_OPTIONS; ?></th>
</tr>
<?php
$categories->print_categories();
?>
</table>

<?php endif; if (isset($_GET["f2"])): ?>

<?php
if (isset($_POST["submit"]) AND $_POST["name"]!="") {
$categories->update();
}
?>

<form action="./admin.php?f=categories&amp;f2=edit_category&amp;id=<?php echo($_GET["id"]); ?>" method="post">

<div>

<p><strong><?php echo LANG_CATEGORY_NAME; ?>:</strong><br /><input type="text" name="name" style="width: 200px;" value="<?php echo htmlspecialchars($categories->category_details("name")); ?>"<?php if (isset($_POST["submit"]) AND $_POST["name"]=="") { echo " class=\"input-error\""; } ?> /></p>

</div>

<div>

<p><input type="submit" name="submit" value="<?php echo LANG_SAVE_CHANGES; ?>" /> <input type="button" onclick="parent.location='./admin.php?f=categories';" value="<?php echo LANG_BACK; ?>" /></p>

</div>

</form>

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