<?php
session_start();
include("natashalib.inc.php");
dbconnect();

if($_POST[sub] == "Add") {
  addadmin($_POST[hand], $_POST[level], $_POST[password], $_POST[comments], $_POST[realname], $_POST[dispnick]);
} else if($_POST[sub] == "Login") {
  login($_POST[auth], $_POST[pass]);
}

if(isset($_SESSION['id'])) {
?>
<center><h1>Administration</h1></center><p>Greetings <b><?php echo $_SESSION['dispnick']; ?></b>. You have level: <b><?php echo auth_to_string($_SESSION['auth']); ?></b>.
<?php
 if($_SESSION['auth'] >= 8) {
   echo "<h2>Queue</h2><p>";
   echo "<table width=75% border=2 cellspacing=0 cellpadding=2 bordercolor=\"black\">\n";
   echo "<th>Channel<th>Bot<th>Users<th>Requester<th>Time<tr>\n\n";

   $strQuery = "SELECT `channel`,`bot`,`users`,`nick`,`time`,`id` FROM `request` WHERE `status` = 0 ORDER BY id LIMIT 0, 50";
   $qri = mysql_query($strQuery, $db);
   while($qr = mysql_fetch_array($qri)) {
     $time = date("Y-m-d H:i:s", $qr[4]);
     echo "<td width=200><a href=\"handle.php?id=$qr[5]\">$qr[0]<td>$qr[1]<td>$qr[2]<td>$qr[3]<td>$time<tr>\n";
   }
   echo "</table>";
 }

 if($_SESSION['auth'] >= 21) {
   echo "<h2>Add admins</h2><p>\n";
   echo "<form method=\"POST\">\n<label>Handle: <input name=\"hand\" value=\"\"></label><br>\n<label>Display nick: <input name=\"dispnick\" value=\"\"></label><br>\n<label>Real name: <input name=\"realname\" value=\"\"></label><br>\n<label>Password: <input name=\"password\" value=\"\"></label><br>\n<label>Comments: <input name=\"comments\" value=\"\"></label><br><label>Level: <input name=\"level\" value=\"\"></label><br><input type=\"submit\" value=\"Add\" name=\"sub\"></form>\n\n";
 }
 
} else {
?>

<center><h1>Admin login</h1></center><p>
  <form method="POST">
   <label>Q Handle: <input name="auth" value=""></label><br>
   <label>Password: <input name="pass" value="" type="password"></label><br>
   <input type="hidden" name="go" value="1">
   <p>
   <input type="submit" value="Login" name="sub">
  </form>
<?php
   }
mysql_close($db);
?>
