<?php
if(!isset($_POST['action']))
{

$file = file("bots/bots.dat");
$bot_1 = trim($file[0]);
$bot_2 = trim($file[1]);
$bot_3 = trim($file[2]);
$bot_4 = trim($file[3]);
echo "<div class=\"form\">\n";
echo "<form method=\"post\" action=\"arnab.php?nocache=$nocache&amp;ver=html&amp;".SID."&amp;pass=$pass&amp;mod=renamebots\">\n";
echo "Quiz Bot:<br/>\n";
echo "<input type=\"text\" name=\"bot1\" maxlength=\"15\" value=\"$bot_1\"/><br/>\n";
echo "Jocker:<br/>\n";
echo "<input type=\"text\" name=\"bot2\" maxlength=\"15\" value=\"$bot_2\"/><br/>\n";
echo "Angry Quiz:<br/>\n";
echo "<input type=\"text\" name=\"bot3\" maxlength=\"15\" value=\"$bot_3\"/><br/>\n";
echo "System Bot:<br/>\n";
echo "<input type=\"text\" name=\"bot4\" maxlength=\"15\" value=\"$bot_4\"/><br/>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"save\"/>\n";
echo "<input type=\"submit\" value=\"Submit\"/></form></div><br/>\n";
}
else
{
$bot1 = trim(htmlspecialchars($_POST['bot1']));
$bot1 = str_replace('$', '$$', $bot1);
$bot2 = trim(htmlspecialchars($_POST['bot2']));
$bot2 = str_replace('$', '$$', $bot2);
$bot3 = trim(htmlspecialchars($_POST['bot3']));
$bot3 = str_replace('$', '$$', $bot3);
$bot4 = trim(htmlspecialchars($_POST['bot4']));
$bot4 = str_replace('$', '$$', $bot4);

$error = "";

$sql = mysql_query("SELECT `id` FROM `chat_users` WHERE `nickname` = '".$bot1."' AND `id` != 2;");
if(mysql_num_rows($sql) != 0) $error .= "Nickname \"$bot1\" Is Already Taken.<br/>\n";

$sql = mysql_query("SELECT `id` FROM `chat_users` WHERE `nickname` = '".$bot2."' AND `id` != 3;");
if(mysql_num_rows($sql) != 0) $error .= "Nickname \"$bot2\" Is Already Taken.<br/>\n";

$sql = mysql_query("SELECT `id` FROM `chat_users` WHERE `nickname` = '".$bot3."' AND `id` != 4;");
if(mysql_num_rows($sql) != 0) $error .= "Nickname \"$bot3\" Is Already Taken.<br/>\n";

$sql = mysql_query("SELECT `id` FROM `chat_users` WHERE `nickname` = '".$bot4."' AND `id` != 5;");
if(mysql_num_rows($sql) != 0) $error .= "Nickname \"$bot4\" Is Already Taken.<br/>\n";

if(empty($bot1)) $error .= "The first bot nick is not entered!<br/>\n";
if(empty($bot2)) $error .= "The second bot nick is not entered!<br/>\n";
if(empty($bot3)) $error .= "The third bot nick is not entered!<br/>\n";
if(empty($bot3)) $error .= "The fourth bot nick is not entered!<br/>\n";

mysql_query("UPDATE `chat_users` SET `nickname` = '".$bot1."' WHERE `id` = 2;");
mysql_query("UPDATE `chat_users` SET `nickname` = '".$bot2."' WHERE `id` = 1;");
mysql_query("UPDATE `chat_users` SET `nickname` = '".$bot3."' WHERE `id` = 4;");
mysql_query("UPDATE `chat_users` SET `nickname` = '".$bot4."' WHERE `id` = 5;");

if(!empty($error))
{
echo $error;
break;
}

$file = fopen("bots/bots.dat", "w");
$data = "$bot1\n";
$data .= "$bot2\n";
$data .= "$bot3\n";
$data .= "$bot4\n";
fwrite($file, $data);
fclose($file);

echo "Nicky bots successfully changed!<br/>\n";
}
?>