<?php
#==============================================================================================#
#                                   Name  :  Imperial CHAT                                     #
#                               Made by  :  MaZaFaKa (___хакер___)                             #
#                                  MODED :  vipsds  (   BOT  )                                 #
#                                  ICQ  :  350502220 (vipsds)                                  #
#                                E-mai :  vipsds@wapnn.org                                     #
# По всем вопросам и дополнительным модам обращайтесь на выше указанные данные                 #
#==============================================================================================#
error_reporting(0);
include('start.php');
include("config.php");
include("./includes/".$ver."/banned");
$ttl = "Смена топика";
list($msec, $sec) = explode(chr(32), microtime());
$headtime = $sec + $msec;

$nocache = rand(10000, 99999);


$file = file("system/cena.dat");

$cenatop = trim($file[5]);


switch($ver)
{
////////////////////////////////////////////////////////
//WML VERSION
////////////////////////////////////////////////////////
case 'wml':
header("Content-type: text/vnd.wap.wml; charset=utf-8");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-relative");

//AUTH
$id = intval($_SESSION['id']);
$password = mysql_escape_string($_SESSION['password']);
$q = mysql_query("SELECT `monety`,'nickname' FROM `chat_users` WHERE `id` = '".$id."' AND `password` = '".md5($password)."';");
if(mysql_num_rows($q) == 0)
{
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.3//EN\" \"http://www.wapforum.org/DTD/wml13.dtd\"><wml>\n";
echo "<card title=\"ERROR\" ontimer=\"index.php?ver=wml\"><timer value=\"15\"/><p align=\"left\">\n";
echo "<small>Ошибка авторизации!<br/>\n";
echo"<br/>$wmlfoot";
list($msec, $sec) = explode(chr(32), microtime());
echo "[".round(($sec+$msec)-$headtime,5)."] sec<br/>\n";
echo "</small></p></card></wml>";
exit();
}
//END AUTH

$monety = mysql_result($q, 0);
$nickname = mysql_result($q);

if($monety <$cenatop)
{
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.3//EN\" \"http://www.wapforum.org/DTD/wml13.dtd\"><wml>\n";
echo "<card title=\"Денег Мало\" ontimer=\"menu.php?ver=wml&amp;".SID."\"><timer value=\"15\"/><p align=\"left\">\n";
echo "У вас недостаточно монет!Чтобы получить монеты сходите в <a href=\"/obmen.php?".SID."&amp;ver=html\">банк</a> нашего чата,там вы сможете обменять ваши посты на монеты.<br/><br/>\n";
echo "Монет: <b>".$monety."</b><br/>";
echo"<br/>$wmlfoot";
echo "</p></card></wml>";
exit();
}

//ONLINE
$online = time() + 60;
$update = mysql_query("UPDATE `chat_users` SET `time` = '".$online."', `place` = 0, `ip` = '".getenv('REMOTE_ADDR')."', `ua` = '".htmlspecialchars(getenv('HTTP_USER_AGENT'))."' WHERE `id` = '".$id."';");
//END ONLINE

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.3//EN\" \"http://www.wapforum.org/DTD/wml13.dtd\"><wml>\n";
echo "<card title=\"Смена Топика\"><p align=\"left\">\n";

if(isset($_GET['mod']))
{
$mod = $_GET['mod'];
}
else
{
$mod = "";
}

switch($mod)
{


case 'editroom':
if(!isset($_POST['action']))
{
$q = mysql_query("SELECT `id`, `name` FROM `chat_rooms`;");
	if(mysql_num_rows($q) == 0)
	{
	echo "Нет ни одной комнаты.<br/>\n";
	}
	else
	{
	echo "<select multiple=\"false\" name=\"room$nocache\">\n";
		while($room = mysql_fetch_array($q))
		{
		$name = $room['name'];
		$rid = $room['id'];
		echo "<option value=\"$rid\">$name</option>\n";
		}
	echo "</select><br/>\n";
	echo "<anchor>[Изменить]<go href=\"lichtop.php?nocache=$nocache&amp;ver=wml&amp;".SID."&amp;mod=editroom\" method=\"post\">\n";
	echo "<postfield name=\"room\" value=\"$(room$nocache)\"/>\n";
	echo "<postfield name=\"action\" value=\"remove\"/>\n";
	echo "</go></anchor><br/>\n";
	}
}
else
{
$room = intval($_POST['room']);
$q = mysql_query("SELECT `topic` FROM `chat_rooms` WHERE `id` = '".$room."';");

if(mysql_num_rows($q) == 0)
{
echo "Такой комнаты не существует.<br/>\n";
break;
}

$topic = mysql_result($q, 0);

echo "Заголовок:<br/>\n";
echo "<input name=\"topic$nocache\" maxlength=\"20\" value=\"$topic\" title=\"topic\"/><br/>\n";
echo "Транслитировать:<br/>\n";
echo "<select name=\"translit$nocache\" value=\"false\">\n";
echo "<option value=\"false\">Нет</option></select><br/>\n";
echo "<option value=\"true\">Да</option>\n";
echo "<anchor>[Сохранить]<go href=\"lichtop.php?nocache=$nocache&amp;ver=wml&amp;".SID."&amp;mod=uproom\" method=\"post\">\n";
echo "<postfield name=\"room\" value=\"$room\"/>\n";
echo "<postfield name=\"topic\" value=\"$(topic$nocache)\"/>\n";
echo "<postfield name=\"translit\" value=\"$(translit$nocache)\"/>\n";
echo "</go></anchor><br/>\n";
}
break;

case 'uproom':
$room = intval($_POST['room']);
$q = mysql_query("SELECT `id`, 'name' FROM `chat_rooms` WHERE `id` = '".$room."';");

if(mysql_num_rows($q) == 0)
{
echo "Такой комнаты не существует.<br/>\n";
break;
}


$ques_arr = mysql_fetch_array($q);
$name = $ques_arr['name'];


$topic = trim(mysql_escape_string(htmlspecialchars($_POST['topic'])));
$topic = str_replace('$', '$$', $topic);

if($_POST['translit'] == "true")
{
$lat = array("J", "j", "Zh", "zh", "Ch", "ch", "Ye", "ye", "Yu", "yu", "Ya", "ya", "Shc", "shc", "Sh", "sh", "Yo", "yo", "Q", "q", "'", "A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h", "I", "i", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", "P", "p", "R", "r", "S", "s", "T", "t", "U", "u", "V", "v", "X", "x", "Z", "z");
$rus = array("Й", "й", "Ж", "ж", "Ч", "ч", "Э", "э", "Ю", "ю", "Я", "я", "Щ", "щ", "Ш", "ш", "Ё", "ё", "Ь", "ь", "ъ", "А", "а", "Б", "б", "Ц", "ц", "Д", "д", "Е", "е", "Ф", "ф", "Г", "г", "Х", "х", "И", "и", "К", "к", "Л", "л", "М", "м", "Н", "н", "О", "о", "П", "п", "Р", "р", "С", "с", "Т", "т", "У", "у", "В", "в", "Х", "х", "З", "з");
$topic = str_replace($lat, $rus, $topic);
}
$ostatok= $monety-$cenatop;
$q = mysql_query("UPDATE `chat_rooms` SET `topic` = '".$topic."' WHERE `id` = '".$room."';");
@mysql_query("update `chat_users` set monety='".$ostatok."' where id='$id'");

$msgx="<b>".$nickname."</b> изменил топик в комнате! Изменен на: <b>".$topic."</b>!";

  $sql = mysql_query("SELECT `id` FROM `chat_rooms` WHERE `type` != 1;");

while($room_id = mysql_fetch_array($sql)){

	mysql_query("INSERT INTO `chat".$room_id['id']."` VALUES(0, '5', '".$bots[3]."', '".$msgx."', '0', '".date("H:i")."',".time().",0);");

}


echo "Топик комнаты изменен!<br/>\n";
break;


default:

echo "Это <b>личный отдел</b> нашего <b>магазина</b>,здесь Вы можете поменять топик в комнате.Смена топика стоит <b>$cenatop</b> монет!<br/>";
echo "У Вас монет: <b>".$monety."</b><br/>";


echo "<a href=\"lichtop.php?".SID."&amp;ver=wml&amp;mod=editroom&amp;nocache=$nocache\">Изменить топик</a><br/>\n";

break;
}

if(!empty($mod)) echo "<a href=\"lichtop.php?".SID."&amp;ver=wml\">смена топика</a><br/>\n";
echo "• <a href=\"menu.php?".SID."&amp;ver=wml\">В прихожую</a><br/>\n";
echo"<br/>$wmlfoot";
list($msec, $sec) = explode(chr(32), microtime());
echo "[".round(($sec+$msec)-$headtime,5)."] sec<br/>\n";
echo "</p></card></wml>";
break;

////////////////////////////////////////////////////////
//HTML VERSION
////////////////////////////////////////////////////////
case 'html':
header ("Content-type: text/html; charset=utf-8");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-relative");

//AUTH
$id = intval($_SESSION['id']);
$password = mysql_escape_string($_SESSION['password']);
$q = mysql_query("SELECT `monety` FROM `chat_users` WHERE `id` = '".$id."' AND `password` = '".md5($password)."';");
if(mysql_num_rows($q) == 0)
{
echo "$css";
echo'<title>'.$ttl.'</title>';
echo'<div class="d3">Ошибка</div>';
echo "<div class=\"d5\">Ошибка авторизации!</div>\n";
echo'<div class="d3">';
echo"$sitefoot";
list($msec, $sec) = explode(chr(32), microtime());
echo "[".round(($sec+$msec)-$headtime,5)."] sec<br/>\n";
echo'</div>';
echo "</body></html>";
exit();
}
//END AUTH





$monety = mysql_result($q, 0);

if($monety < $cenatop)
{
echo "$css";
echo'<title>'.$ttl.'</title>';
echo'<div class="d3">'.$ttl.'</div>';
echo "У вас недостаточно монет!Чтобы получить монеты сходите в <a href=\"/obmen.php?".SID."&amp;ver=html\">банк</a> нашего чата,там вы сможете обменять ваши посты на монеты.<br/>\n";
echo "Монет: <b>".$monety."</b><br/>";

echo'<div class="d3">';
echo"$sitefoot";
echo'</div>';
echo "</body></html>";
exit();
}



//ONLINE
$online = time() + 60;
$update = mysql_query("UPDATE `chat_users` SET `time` = '".$online."', `place` = 0 WHERE `id` = '".$id."';");
//END ONLINE

echo "$css";
echo'<title>'.$ttl.'</title>';
echo'<div class="d3">'.$ttl.'</div>';

$level = mysql_result($q, 0);




if(isset($_GET['mod']))
{
$mod = $_GET['mod'];
}
else
{
$mod = "";
}

if(isset($_GET['handler']))
{
$action = intval($_POST['mod']);

	switch($action)
	{
	case 0:
	$mod = "edit";
	break;

	case 1:
	$mod = "kick";
	break;

	case 2:
	$mod = "ban";
	break;

	case 3:
	$mod = "ipua";
	break;
	}
}

switch($mod)
{

case 'editroom':
if(!isset($_POST['action']))
{
$q = mysql_query("SELECT `id`, `name` FROM `chat_rooms`;");
	if(mysql_num_rows($q) == 0)
	{
	echo "Нет ни одной комнаты.<br/>\n";
	}
	else
	{
	echo "<div class=\"form\">\n";
	echo "<form method=\"post\" action=\"lichtop.php?nocache=$nocache&amp;ver=html&amp;".SID."&amp;mod=editroom\">\n";
	echo "<select name=\"room\">\n";
		while($room = mysql_fetch_array($q))
		{
		$name = $room['name'];
		$rid = $room['id'];
		echo "<option value=\"$rid\">$name</option>\n";
		}
	echo "</select><br/>\n";
	echo "<input type=\"hidden\" name=\"action\" value=\"edit\"/>\n";
	echo "<input type=\"submit\" value=\"Изменить\"/></form></div><br/>\n";
	}
}
else
{
$room = intval($_POST['room']);
$q = mysql_query("SELECT `topic` FROM `chat_rooms` WHERE `id` = '".$room."';");

if(mysql_num_rows($q) == 0)
{
echo "Такой комнаты не существует.<br/>\n";
break;
}

$topic = mysql_result($q, 0);

echo "<div class=\"form\">\n";
echo "<form method=\"post\" action=\"lichtop.php?nocache=$nocache&amp;ver=html&amp;".SID."&amp;mod=uproom\">\n";
echo "Заголовок:<br/>\n";
echo "<input name=\"topic\" maxlength=\"20\" value=\"$topic\" title=\"topic\"/><br/>\n";
echo "Транслитировать: <input type=\"checkbox\" name=\"translit\" value=\"true\"/><br/>\n";
echo "<input type=\"hidden\" name=\"room\" value=\"".$_POST['room']."\"/>\n";
echo "<input type=\"submit\" value=\"Сохранить\"/></form></div><br/>\n";
}
break;

case 'uproom':
$room = intval($_POST['room']);
$q = mysql_query("SELECT `id`, 'name' FROM `chat_rooms` WHERE `id` = '".$room."';");


if(mysql_num_rows($q) == 0)
{
echo "Такой комнаты не существует.<br/>\n";
break;
}

$topic = trim(mysql_escape_string(htmlspecialchars($_POST['topic'])));
$topic = str_replace('$', '$$', $topic);

if($_POST['translit'] == "true")
{
$lat = array("J", "j", "Zh", "zh", "Ch", "ch", "Ye", "ye", "Yu", "yu", "Ya", "ya", "Shc", "shc", "Sh", "sh", "Yo", "yo", "Q", "q", "'", "A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h", "I", "i", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", "P", "p", "R", "r", "S", "s", "T", "t", "U", "u", "V", "v", "X", "x", "Z", "z");
$rus = array("Й", "й", "Ж", "ж", "Ч", "ч", "Э", "э", "Ю", "ю", "Я", "я", "Щ", "щ", "Ш", "ш", "Ё", "ё", "Ь", "ь", "ъ", "А", "а", "Б", "б", "Ц", "ц", "Д", "д", "Е", "е", "Ф", "ф", "Г", "г", "Х", "х", "И", "и", "К", "к", "Л", "л", "М", "м", "Н", "н", "О", "о", "П", "п", "Р", "р", "С", "с", "Т", "т", "У", "у", "В", "в", "Х", "х", "З", "з");
$topic = str_replace($lat, $rus, $topic);
}

if(empty($topic))
{
echo "Вы не ввели топик!<br/>\n";
break;
}
 $ostatok= $monety-$cenatop;
$q = mysql_query("UPDATE `chat_rooms` SET `topic` = '".$topic."' WHERE `id` = '".$room."';");
@mysql_query("update `chat_users` set monety='".$ostatok."' where id='$id'");





$msgx="<b>".$nickname."</b> изменил топик в комнате! Изменен на: <b>".$topic."</b>!";

  $sql = mysql_query("SELECT `id` FROM `chat_rooms` WHERE `type` != 1;");

while($room_id = mysql_fetch_array($sql)){

	mysql_query("INSERT INTO `chat".$room_id['id']."` VALUES(0, '5', '".$bots[3]."', '".$msgx."', '0', '".date("H:i")."',".time().",0);");

}








echo "Настройки комнаты сохранены!<br/>\n";
break;



default:

 echo "Это <b>личный отдел</b> нашего <b>магазина</b>,здесь Вы можете поменять Топик В комнате.Смена топика  стоит <b>$cenatop</b> монет!<br/>";
echo "У Вас монет: <b>".$monety."</b><br/>";

echo "<a href=\"lichtop.php?".SID."&amp;ver=html&amp;mod=editroom\">Изменить топик</a><br/>\n";

}
if(!empty($mod)) echo "<div class=\"d1\">• <a href=\"/lichtop.php?".SID."&amp;ver=html\">Смена Топига</a></div>\n";
echo "<div class=\"d1\">• <a href=\"/menu/html\">В прихожую</a></div>";
echo'<div class="d3">';
echo"$sitefoot";
list($msec, $sec) = explode(chr(32), microtime());
echo "[".round(($sec+$msec)-$headtime,5)."] sec<br/>\n";
echo'</div>';
echo "</body></html>";
break;
}
?>