<?php
session_start();

include("natashalib.inc.php");

dbconnect();

if($_SESSION['auth'] < 8) echo "Not enough access.";
else {
  if(!isset($_POST[response])) {
    $strQuery = "SELECT `id`,`channel`,`bot`,`users`,`topic`,`service`,`nick`,`time`,`uid` FROM `request` WHERE `id` = $_GET[id] AND `status` = '0'";
    $qri = mysql_query($strQuery, $db);
    $qr = mysql_fetch_array($qri);

    $time = date("Y-m-d H:i:s", $qr[7]);
    echo "<center><h1>Handle a request</h1></center><p>\n<table width = \"50%\" border=\"0\">\n";
    echo "<tr><td width = \"10%\"><b>Id:</b></td><td width = \"80%\">$qr[0]</td></tr>\n<tr><td width = \"10%\"><b>Channel:</b></td><td width = \"80%\">$qr[1]</td></tr>\n<tr><td width = \"10%\"><b>Bot:</b></td><td width = \"80%\">$qr[2]</td></tr>\n<tr><td width = \"10%\"><b>Users:</b></td><td width = \"80%\">$qr[3]</td></tr>\n<tr><td width = \"10%\"><b>Topic:</b></td><td width = \"80%\">$qr[4]&nbsp;</td></tr>\n<tr><td width = \"10%\"><b>Service:</b></td><td width = \"80%\">$qr[5] &nbsp;</td></tr>\n<tr><td width = \"10%\"><b>Requester:</b></td><td width = \"80%\">$qr[6]</td></tr>\n<tr><td width = \"10%\"><b>Time:</b></td><td width = \"80%\">$time</td></tr>\n";

    echo "</table><p>\n\n<form method=\"POST\">";
    $strQuery = "SELECT `channels`, `status` FROM `arms` WHERE `nick` = '$qr[2]'";
    $qri2 = mysql_query($strQuery, $db);
    $qr2 = mysql_fetch_array($qri2);

    $err = 0;
    if($qr2[0] >= $max_channels) {
      $err = 1;
      echo "<font color = \"red\">Bot has become full.</font><br>";
    }
    if($qr2[1] == 0) {
      $err = 1;
      echo "<font color = \"red\">Bot is down.</font><br>";
    }

    if($err == 1) {
      echo "<SELECT NAME=\"bot\">";
      $strQuery = "SELECT `nick` FROM `arms` WHERE `type` = 30 AND `status` = 1 AND `channels` < $max_channels";
      $qri3 = mysql_query($strQuery, $db);
      while($qr3 = mysql_fetch_array($qri3)) {
        echo "<OPTION>$qr3[0]";
      }
      echo "</SELECT>\n<p>";
    } else echo "<input type = \"hidden\" name=\"bot\" value=\"$qr[2]\"</input>";
    echo "<small><b>Important: Check the channel carefully, so it doesen't violate the Quakenet rules. Be in the channel and make sure that the bot joins if you accept. Any kind of bugs must be reported to Sorcer.</b></small><p>\n";
    echo"<small>Decline reason example: <b>This channel is violating the Quakenet rules. Head to http://www.quakenet.org/rules/ to find 
out more about this.</small><p>\nDecline reason: <input name=\"reason\" value=\"\" size=\"60\"><br><input type=\"submit\" name=\"response\" value=\"Accept\">&nbsp;<input type=\"submit\" name=\"response\" value=\"Decline\"><input type = \"hidden\" name=\"id\" value=\"$_GET[id]\"</input><input type = \"hidden\" name=\"chan\" value=\"$qr[1]\"</input><input type = \"hidden\" name=\"nick\" value=\"$qr[6]\"</input><input type = \"hidden\" name=\"uid\" value=\"$qr[8]\"</input>\n</form>\n";
  }

  else if($_POST[response] == "Accept") {
    handle_accept($_SESSION['id'], $_POST[id], $_POST[chan], $_POST[nick], $_POST[bot], $_POST[uid]);
  }
  else if($_POST[response] == "Decline") {
    handle_decline($_SESSION['id'], $_POST[id], $_POST[chan], $_POST[nick], $_POST[bot], $_POST[uid]);
  }
}
mysql_close($db);
?>
