<?

header("Cache-Control: no-cache");
if ($ver=="wml")header ("Content-type:text/vnd.wap.wml; charset=utf-8");
else header("Content-Type:text/html; charset=UTF-8");
  
require("inc.php");
$link = connect_db();
list($row, $id, $ps, $fsize1, $fsize2) = check_login($link);
require("version.php");

ob_start();
if ($ver=="wml"){
echo $xml;
echo $dtd;
echo "<wml>\n";
echo "<card id=\"statistik\" title=\"Добавить анекдот\">\n";
echo "<p align=\"center\">\n";
}else{
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
echo "<head><link rel=\"stylesheet\" type=\"text/css\" href=\"css/css.css\"/>";
echo "<title>Добавить анекдот</title>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head><body>";
echo "<div align=\"center\">\n";
}
switch($mod) {

case 'addanekdot':
if ($row["translit"]==1)$msg = trun_to_rus($msg);
## Антифлуд ##
$r6 = mysql_query("SELECT message FROM anekdot WHERE who = '".$id."' order by klu4 desc LIMIT 1");
$a6 = mysql_fetch_array($r6);
## Автоантифлуд ##
if ($a6["message"] == $msg){
echo $fsize1;
echo "Такой анекдот уже есть в БД<br/>\n";
echo $fsize2;
}else{
$msg = str_replace(chr("13"), " ", $msg);
$msg = str_replace(chr("10"), " ", $msg);
$msg = trim(" $msg ");
$msg = ereg_replace(" +"," ",$msg);
$msg = substr($msg,0,1000);
$msg = str_replace("\n", " ", $msg);  
$msg = str_replace("$", "$$", $msg);     
$msg = str_replace("", "", $msg);
$msg = str_replace("", "", $msg); 
$msg = str_replace("", "", $msg); 
$msg = str_replace("", "", $msg); 
$msg = str_replace("", "", $msg); 
$msg = str_replace("", "", $msg); 
$msg = HtmlSpecialChars($msg); 
$msg = addslashes($msg); 
if($row["translit"]==0) {
$msg = eregi_replace("((http://))((([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z;]{2,3}))|(([0-9]{1,3}\.){3}([0-9]{1,3})))((/|\?)[a-z0-9~#%&'_\+=:;\?\.-]*)*)", "<a href=\"\\0\">\\3</a>", $msg);
}
//if ($row["level"]<6) 
require("antirekl.php");
$r = mysql_query("select * from anekdot ");
$k = mysql_affected_rows()+1;
mysql_query ("Insert into anekdot set klu4= '".$k."', message='".$msg."', who='".$id."'");
if (mysql_error() == false){
echo $fsize1;
echo "Анекдот был добавлен в базу<br/>\n";
echo "Всего анекдотов: $k <br/>\n";
echo $fsize2;
} else { 
echo $fsize1;
echo "Ошибка при записи!<br/>\n";
echo $fsize2;
echo "ERROR ".mysql_error()." ";
}
}
break;

default:

echo $fsize1;
if ($ver!="wml")echo "<form method=\"POST\" action=\"addanekdot.php?mod=addanekdot&amp;$ses&amp;ref=$ref\" name=\"auth\">\n";
echo "При включенном транслите анекдот транслитерируются<br/>\n";
echo $divide;
echo "Анекдот:<br/>\n";
echo $fsize2;
echo "<input name=\"msg\" maxlength=\"500\" title=\"quest\"/><br/>\n";  
echo $fsize1;
echo $divide;
echo $fsize2;
if ($ver=="wml"){
echo $fsize1;
echo "<anchor title=\"go\">Добавить<go href=\"addanekdot.php?mod=addanekdot&amp;$ses&amp;ref=$ref\" method=\"post\">\n";
echo "<postfield name=\"msg\" value=\"$(msg)\"/>\n";  
echo "</go></anchor>\n";
echo $fsize2;
echo "<br/>\n";
}else{
echo "<input type=\"submit\" value=\"Добавить\" name=\"enter\"><br/>\n";
}
break;
}
echo $fsize1;
echo $divide;
if ((isset($rm))&&($rm!="")&&(!isset($pwd))){
echo "<a href=\"chat.php?$ses&amp;rm=$rm&amp;ref=$ref\">В чат</a><br/>\n";
}else{
if($mod) echo "<a href=\"addanekdot.php?$ses&amp;ref=$ref\">Добавить ещё</a><br/>\n";
}
echo "<a href=\"enter.php?$ses&amp;ref=$ref\">Прихожая</a><br/>\n";
echo $fsize2;
if ($ver=="wml")echo "</p></card></wml>\n";
else echo "</div></body></html>\n";
$alltraf=$row["alltraf"];
$pagesize=round((ob_get_length())/1024,1);
$alltraf=$alltraf+$pagesize;
mysql_query ("Update users set alltraf='".$alltraf."', lasttraf='".$pagesize."' where id='".$id."'");
mysql_close ($link);
ob_end_flush();
?>