<?php
// check rights
if ($login->check_rights()>=2):
// loading of reqired classes
include CLASSES_PATH."Ranks.php";
// creating of instances
$ranks=new Ranks();
// add new
if ($_GET["action"]=="add" AND $_POST["name"]!="" AND $_POST["start"]!="" AND $_POST["end"]!="") { $ranks->add(); }
// delete
if ($_GET["action"]=="delete" AND isset($_GET["id"])) { $ranks->remove(); }
?>

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

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

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

<div>

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

<p><strong><?php echo LANG_FOR_POSTS; ?>:</strong><br /><input type="text" name="start" style="width: 50px;"<?php if (isset($_POST["submit"]) AND $_POST["start"]=="") { echo " class=\"input-error\""; } ?> /> &mdash; <input type="text" name="end" style="width: 50px;"<?php if (isset($_POST["submit"]) AND $_POST["end"]=="") { 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: 45%;"><?php echo LANG_NAME; ?></th>
<th style="width: 30%;"><?php echo LANG_FOR_POSTS; ?></th>
<th style="width: 25%;"><?php echo LANG_OPTIONS; ?></th>
</tr>
<?php $ranks->print_data(); ?>
</table>

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

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

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

<div>

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

<p><strong><?php echo LANG_FOR_POSTS; ?>:</strong><br /><input type="text" name="start" style="width: 50px;" value="<?php echo $ranks->rank_details("start"); ?>"<?php if (isset($_POST["submit"]) AND $_POST["start"]=="") { echo " class=\"input-error\""; } ?> /> &mdash; <input type="text" name="end" style="width: 50px;" value="<?php echo $ranks->rank_details("end"); ?>"<?php if (isset($_POST["submit"]) AND $_POST["end"]=="") { 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=ranks';" value="<?php echo LANG_BACK; ?>" /></p>

</div>

</form>

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