<?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/constants/menu");
include("./includes/".$ver."/banned");

list($msec, $sec) = explode(chr(32), microtime());
$headtime = $sec + $msec;
$ttl="Стихи";
$ref = rand(1000, 9999);

//////////////////////////////////////////////////////////////////////////
$name = trim(htmlspecialchars(mysql_escape_string($_POST['name'])));
$article = trim(htmlspecialchars(mysql_escape_string($_POST['article'])));
$aftor = trim(htmlspecialchars(mysql_escape_string($_POST['article'])));
//////////////////////////////////////////////////////////////////////////

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-revalidate");

//AUTH
$id = intval($_SESSION['id']);
$password = mysql_escape_string($_SESSION['password']);
$q = mysql_query("SELECT `privilegii` 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=\"/wml\"><timer value=\"15\"/><p align=\"left\">\n";
echo "<small>Ошибка авторизации!<br/>\n";
echo"$wmlfoot";
list($msec, $sec) = explode(chr(32), microtime());
echo "<br/>[".round(($sec+$msec)-$headtime,5)."] sec<br/>\n";
echo "</small></p></card></wml>";
exit();
}
//END AUTH

$privilegii = mysql_result($q, 0);



//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



if($privilegii <3)
{
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=\"/wml\"><timer value=\"15\"/><p align=\"left\">\n";
echo "<small>Ошибка авторизации!<br/>\n";
echo"$wmlfoot";
list($msec, $sec) = explode(chr(32), microtime());
echo "<br/>[".round(($sec+$msec)-$headtime,5)."] sec<br/>\n";
echo "</small></p></card></wml>";
exit();
}



$date = date("d.m.y");


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=\"$ttl\"><p align=\"left\">\n";


echo "Добавление<br/>";

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

switch($case)
{
case 'add':

if(!empty($_POST))
{

if(empty($name))
{
echo "Вы не ввели название Стиха<br/>";
echo "Попробуйте ещё раз!";
break;
}
if(empty($aftor))
{
echo "Вы не ввели Автора<br/>";
echo "Попробуйте ещё раз!";
break;
}
if(empty($article))
{
echo "Вы не ввели Стих";
echo "Попробуйте ещё раз!";
break;
}
$povtor = mysql_query("SELECT name FROM article ORDER BY nomer DESC LIMIT 1;");
$povtor2 = mysql_result($povtor,0);
if($povtor2==$name)
{
echo "Такой стих уже существует<br/>";
echo "Попробуйте ещё раз!";
break;
}
}

mysql_query("INSERT INTO chat_stix SET name = '$name', article = '$article',aftor = '$aftor', date = '$date', nickname= '$nickname';") or die(mysql_error());
$_GET['ok'] = 1;
if (isset($_GET['ok']))
echo "стих добавлен";
break;

default:
echo "Введите название:<br/>";
echo "<input size=\"10\" name=\"name$ref\" value=\"\" maxlength=\"60\" emptyok=\"true\"/><br/>\n";
echo "Введите стих:<br/>";
echo "<input size=\"10\" name=\"article$ref\" value=\"\" maxlength=\"512\" emptyok=\"true\"/><br/>\n";
echo "Введите Автора:<br/>";
echo "<input size=\"10\" name=\"aftor$ref\" value=\"\" maxlength=\"512\" emptyok=\"true\"/><br/>\n";
echo "<anchor>Добавить<go href=\"/dobavst/wml/add\" method=\"post\">\n";
echo "<postfield name=\"name\" value=\"$(name$ref)\"/>\n";
echo "<postfield name=\"article\" value=\"$(article$ref)\"/>\n";
echo "<postfield name=\"aftor\" value=\"$(aftor$ref)\"/>\n";
echo "</go></anchor><br/>\n";
break;
}

echo"<br/>";

echo "• <a href=\"/menu/wml\">В прихожую</a><br/>\n";
echo"$wmlfoot";
list($msec, $sec) = explode(chr(32), microtime());
echo "[".round(($sec+$msec)-$headtime,5)."] сек.<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-revalidate");

//AUTH
$id = intval($_SESSION['id']);
$password = mysql_escape_string($_SESSION['password']);
$q = mysql_query("SELECT `privilegii` 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)."] сек.<br/>\n";
echo'</div>';
echo "</body></html>";
exit();
}
//END AUTH

$privilegii = mysql_result($q, 0);

//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



if($privilegii < 3)
{
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)."] сек.<br/>\n";
echo'</div>';
echo "</body></html>";
exit();
}




$date = date("d.m.y");

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

echo'<div class="d1">Добавление статьи</div>';

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

switch($case)
{
case 'add':

if(!empty($_POST))
{

if(empty($name))
{
echo "Вы не ввели название Стиха<br/>";
echo "Попробуйте ещё раз!";
break;
}

if(empty($aftor))
{
echo "Вы не ввели Автора<br/>";
echo "Попробуйте ещё раз!";
break;
}

if(empty($article))
{
echo "Вы не ввели статью";
echo "Попробуйте ещё раз!";
break;
}
$povtor = mysql_query("SELECT name FROM article ORDER BY nomer DESC LIMIT 1;");
$povtor2 = mysql_result($povtor,0);
if($povtor2==$name)
{
echo "Такая статья уже существует<br/>";
echo "Попробуйте ещё раз!";
break;
}
}

mysql_query("INSERT INTO chat_stix SET name = '$name', article = '$article', aftor = '$aftor', date = '$date', nickname= '$nickname';") or die(mysql_error());
$_GET['ok'] = 1;
if (isset($_GET['ok']))
echo "Стих добавлен";
break;

default:
echo "<div class=\"form\">\n";
echo "<form action=\"/dobavst/html/add\" method=\"post\">\n";
echo "Введите название:<br/>";
echo '<input name="name" value="" /><br/>';
echo "Введите Стих:<br/>";
echo '<input name="article" value="" /><br/>';
echo "Введите Автора:<br/>";
echo '<input name="aftor" value="" /><br/>';
echo '<input type="submit" value="Добавить" />';
break;
}

echo '<div class="d1">';

echo "• <a href=\"/menu/html\">В прихожую</a><br/>";
echo'</div>';
echo'<div class="d3">';
echo"$sitefoot";
list($msec, $sec) = explode(chr(32), microtime());
echo "[".round(($sec+$msec)-$headtime,5)."] сек.<br/>\n";
echo'</div>';
echo "</body></html>";

break;
}
?>