<?
header("Cache-Control: no-cache");
header("Content-type:text/vnd.wap.wml");
$ref=rand(10000,1000000);
require("inc.php");
function getmicrotime() //Микровремя
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$link = @mysql_pconnect ($MySQL_Hostname, $MySQL_Username, $MySQL_Password)
or die ("<wml>
<card id=\"error\" title=\"error\">
<do type=\"prev\" label=\"Back\"><prev/></do><p align=\"center\">Can not connect to MySQL</p>
</card>
</wml>");
@mysql_select_db($MySQLDatabasename) or die ("<wml>
<card id=\"error\" title=\"error\">
<do type=\"prev\" label=\"Back\"><prev/></do><p align=\"center\">error select the database...</p>
</card>
</wml>");
$result = @mysql_query ("Select pass,user,level,translit,friends,fsize from users where id='".$id."'");
if (mysql_affected_rows() == 0) {
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">\n";
echo "<wml>\n";
echo "<card id=\"error\" title=\"Ошибка\" ontimer=\"index.php?ref=$ref\"><timer value=\"15\"/>\n";
echo "<p align=\"center\">\n";
echo "User was not found\n";
echo "</p>\n";
echo "</card>\n";
echo "</wml>\n";
mysql_close($link);
exit;
}
$row = mysql_fetch_array ($result);
if ($ps !== $row["pass"]){
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">\n";
echo "<wml>\n";
echo "<card id=\"error\" title=\"Ошибка\" ontimer=\"index.php?ref=$ref\"><timer value=\"15\"/>\n";
echo "<p align=\"center\">\n";
echo "Your login failed\n";
echo "</p>\n";
echo "</card>\n";
echo "</wml>\n";
mysql_close($link);
exit;
}
if($row['fsize'] == "small") { $fsize1 = "<small>"; $fsize2 = "</small>"; }
elseif($row['fsize'] == "big") { $fsize1 = "<big>"; $fsize2 = "</big>"; }
else { $fsize1 = ""; $fsize2 = ""; }
$us=$row["user"];
if(!@$go){
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">\n";
echo "<wml>\n";
echo "<head><meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/></head>\n";
echo "<card id=\"send\" title=\"Написать\">\n";
echo "<p>\n";
$message = $topic = $towhom = "";
if (isset($im)){
$r = mysql_query ("SELECT towhom,topic,message FROM zapiski WHERE klu4 = '".$im."'");
$a = mysql_fetch_array($r);
$towhom = $a ["towhom"];
$topic = $a ["topic"];
$message = $a ["message"];
} else {
if (isset($who)){
$r = mysql_query ("SELECT who FROM zapiski WHERE klu4 = '".$who."'");
$a = mysql_fetch_array($r);
$towhom = $a ["who"];
}
}
if (isset($tofr))$towhom = $tofr;
if($message!=""){
if(strstr($message,"<img src=\""))
{
$tend = strpos($message,"\"/>");
$t=strlen($message);
$msgend=substr($message,$tend+3,$t);
$msgtemp=substr($message,0,$tend);
$t1=strpos($msgtemp,"<img src=\"");
$msgfirst=substr($msgtemp,0,$t1);
$t2=strlen($msgtemp);
$t3=strpos($msgtemp,"alt=\"");
$msgaver=substr($msgtemp,$t3+5,$t2);
$message=$msgfirst.$msgaver.$msgend;
}
if(strstr($message,"<a href=\""))
{
$tend = strpos($message,"</a>");
$t=strlen($message);
$msgend=substr($message,$tend+4,$t);
$tend2 = strpos($message,"\">");
$msgtemp=substr($message,0,$tend2);
$t1=strpos($msgtemp,"<a href=\"");
$msgfirst=substr($msgtemp,0,$t1);
$t2=strlen($msgtemp);
$t3=strpos($msgtemp,"<a href=\"");
$msgaver=substr($msgtemp,$t3+9,$t2);
$message=$msgfirst.$msgaver.$msgend;
}
}
echo $fsize1;
echo "РљРѕРјСѓ:<br/>\n";
echo $fsize2;
if (isset($who)) {
echo "<input name=\"nick$ref\" maxlength=\"30\" value=\"$towhom\" title=\"komu\"/><br/>\n";
} elseif (isset($tofr)) {
echo "<input name=\"nick$ref\" maxlength=\"30\" value=\"$tofr\" title=\"komu\"/><br/>\n";
} else {
echo "<input name=\"nick$ref\" maxlength=\"30\" value=\"$to\" title=\"komu\"/><br/>\n";
}
echo $fsize1;
echo "Тема:<br/>\n";
echo $fsize2;
echo "<input name=\"topic$ref\" maxlength=\"30\" value=\"$topic\" title=\"topic\"/><br/>\n";
echo $fsize1;
echo "РџРёСЃСЊРјРѕ:<br/>\n";
echo $fsize2;
echo "<input name=\"message$ref\" maxlength=\"600\" value=\"$message\" title=\"message\"/><br/>\n";
echo $fsize1;
if ((isset($rm))&&($rm!=""))echo "<anchor title=\"go\">Отправить<go href=\"send.php?go=pn&id=$id&ps=$ps&rm=$rm\" method=\"post\">\n";
else echo "<anchor title=\"go\">Отправить<go href=\"send.php?go=pn&id=$id&ps=$ps\" method=\"post\">\n";
echo "<postfield name=\"towhom\" value=\"$(nick$ref)\"/>\n";
echo "<postfield name=\"topic\" value=\"$(topic$ref)\"/>\n";
echo "<postfield name=\"message\" value=\"$(message$ref)\"/>\n";
echo "</go></anchor>\n";
echo $fsize2;
echo "<br/>\n";
echo $fsize1;
echo "---<br/>\n";
echo $fsize2;
echo $fsize1;
if ((isset($rm))&&($rm!="")) echo "<anchor title=\"go\">Отправить всем друзьям<go href=\"send.php?go=all&id=$id&ps=$ps&rm=$rm\" method=\"post\">\n";
else echo "<anchor title=\"go\">Отправить всем друзьям<go href=\"send.php?go=all&id=$id&ps=$ps\" method=\"post\">\n";
echo "<postfield name=\"topic\" value=\"$(topic$ref)\"/>\n";
echo "<postfield name=\"message\" value=\"$(message$ref)\"/>\n";
echo "</go></anchor>\n";
echo $fsize2;
echo "<br/>\n";
echo $fsize1;
echo "---<br/>\n";
echo $fsize2;
echo $fsize1;
if ((isset($rm))&&($rm!="")) echo "<a href=\"chat.php?id=$id&ps=$ps&rm=$rm\">← В чат</a><br/>\n";
echo "<a href=\"chatmail.php?id=$id&ps=$ps\">Ваша почта</a><br/>\n";
echo "<a href=\"enter.php?id=$id&ps=$ps&ref=$ref\">Прихожая</a><br/>\n";
echo $fsize2;
echo "</p>\n";
echo "</card>\n";
echo "</wml>\n";
mysql_close ($link);
exit;
}
function trun_to_rus($str){
$str=str_replace("ch","С‡",$str);
$str=str_replace("sc","С‰",$str);
$str=str_replace("ye","СЌ",$str);
$str=str_replace("yu","СЋ",$str);
$str=str_replace("ya","СЏ",$str);
$str=str_replace("CH","Р§",$str);
$str=str_replace("SC","Р©",$str);
$str=str_replace("""","РЄ",$str);
$str=str_replace(""","СЉ",$str);
$str=str_replace("‘‘","Р¬",$str);
$str=str_replace("‘","СЊ",$str);
$str=str_replace("YE","Р",$str);
$str=str_replace("YU","Р®",$str);
$str=str_replace("YA","РЇ",$str);
$str=strtr($str,array("a"=>"Р°","b"=>"Р±","v"=>"РІ","g"=>"Рі","d"=>"Рґ","e"=>"Рµ","j"=>"Р¶","z"=>"Р·","i"=>"Рё","y"=>"Р№","k"=>"Рє","l"=>"Р»","m"=>"Рј","n"=>"РЅ","o"=>"Рѕ","p"=>"Рї","r"=>"СЂ","s"=>"СЃ","t"=>"С‚","u"=>"Сѓ","f"=>"С„","h"=>"С…","c"=>"С†","w"=>"С€","x"=>"С‹","A"=>"Рђ","B"=>"Р‘","V"=>"Р’","G"=>"Р“","D"=>"Р”","E"=>"Р•","J"=>"Р–","Z"=>"Р—","I"=>"Р?","Y"=>"Р™","K"=>"Рљ","L"=>"Р›","M"=>"Рњ","N"=>"Рќ","O"=>"Рћ","P"=>"Рџ","R"=>"Р ","S"=>"РЎ","T"=>"Рў","U"=>"РЈ","F"=>"Р¤","H"=>"РҐ","C"=>"Р¦","W"=>"РЁ","X"=>"Р«"));
return $str;
}
function check($message){
$message = str_replace("\\n", " ", $message);
$message = str_replace("\n", " ", $message);
$message = trim(" $message ");
$message = ereg_replace(" +"," ",$message);
$message = str_replace("$", "$$", $message);
$message=strtr($message,array(chr("0")=>"",chr("1")=>"",chr("2")=>"",chr("3")=>"",chr("4")=>"",chr("5")=>"",chr("6")=>"",chr("7")=>"",chr("8")=>"",chr("9")=>"",chr("10")=>"",chr("11")=>"",chr("12")=>"",chr("13")=>"",chr("14")=>"",chr("15")=>"",chr("16")=>"",chr("17")=>"",chr("18")=>"",chr("19")=>"",chr("20")=>"",chr("21")=>"",chr("22")=>"",chr("23")=>"",chr("24")=>"",chr("25")=>"",chr("26")=>"",chr("27")=>"",chr("28")=>"",chr("29")=>"",chr("30")=>"",chr("31")=>""));
$message = HtmlSpecialChars($message);
$message = str_replace("\"", """, $message);
$message = str_replace("|", "¦", $message);
$message = str_replace("'", "‘", $message);
$message = str_replace("\\", "", $message);
$message=addslashes($message);
return $message;
}
$message = check($message);
$topic = check($topic);
if ($go!="all"){
function rus_to_k($str){
$str = str_replace("Р°","a",$str);
$str = str_replace("Р±","b",$str);
$str = str_replace("РІ","v",$str);
$str = str_replace("Рі","g",$str);
$str = str_replace("Рґ","d",$str);
$str = str_replace("Рµ","e",$str);
$str = str_replace("С‘","e",$str);
$str = str_replace("Р¶","j",$str);
$str = str_replace("Р·","z",$str);
$str = str_replace("Рё","i",$str);
$str = str_replace("Р№","y",$str);
$str = str_replace("Рє","k",$str);
$str = str_replace("Р»","l",$str);
$str = str_replace("Рј","m",$str);
$str = str_replace("РЅ","n",$str);
$str = str_replace("Рѕ","o",$str);
$str = str_replace("Рї","p",$str);
$str = str_replace("СЂ","r",$str);
$str = str_replace("СЃ","s",$str);
$str = str_replace("С‚","t",$str);
$str = str_replace("Сѓ","u",$str);
$str = str_replace("С„","f",$str);
$str = str_replace("С…","h",$str);
$str = str_replace("С‡","c",$str);
$str = str_replace("С†","q",$str);//ч
$str = str_replace("С€","w",$str);
$str = str_replace("С‰",">",$str);//щ
$str = str_replace("СЊ","<",$str);//ъ
$str = str_replace("С‹","x",$str);//ы
$str = str_replace("СЉ",".",$str);//ь
$str = str_replace("СЌ",":",$str);//э
$str = str_replace("СЋ",";",$str);//ю
$str = str_replace("СЏ","}",$str);//я
$str = str_replace("Рђ","a",$str);
$str = str_replace("Р‘","b",$str);
$str = str_replace("Р’","v",$str);
$str = str_replace("Р“","g",$str);
$str = str_replace("Р”","d",$str);
$str = str_replace("Р•","e",$str);
$str = str_replace("РЃ","e",$str);
$str = str_replace("Р–","j",$str);
$str = str_replace("Р—","z",$str);
$str = str_replace("Р?","i",$str);
$str = str_replace("Р™","y",$str);
$str = str_replace("Рљ","k",$str);
$str = str_replace("Р›","l",$str);
$str = str_replace("Рњ","m",$str);
$str = str_replace("Рќ","n",$str);
$str = str_replace("Рћ","o",$str);
$str = str_replace("Рџ","p",$str);
$str = str_replace("Р ","r",$str);
$str = str_replace("РЎ","s",$str);
$str = str_replace("Рў","t",$str);
$str = str_replace("РЈ","u",$str);
$str = str_replace("Р¤","f",$str);
$str = str_replace("РҐ","h",$str);
$str = str_replace("Р§","c",$str);
$str = str_replace("Р¦","q",$str);
$str = str_replace("РЁ","w",$str);
$str = str_replace("Р©",">",$str);
$str = str_replace("Р¬","<",$str);
$str = str_replace("Р«","x",$str);
$str = str_replace("РЄ",".",$str);
$str = str_replace("Р",":",$str);
$str = str_replace("Р®",";",$str);
$str = str_replace("РЇ","}",$str);
return $str;
}
$towhom=trim($towhom);
if($towhom=="")$towhom=0;
$latuser=strtolower($towhom);
$ruser = rus_to_k($towhom);
if($ruser==$towhom){
$r = mysql_query ("Select id,avtootvet from users where latuser = '".$latuser."'");
} else {
$r = mysql_query ("select id,avtootvet from users where ruser = '".$ruser."'");
}
if (mysql_affected_rows() == 0) {
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">\n";
echo "<wml>\n";
echo "<head><meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/></head>\n";
if ((isset($rm))&&($rm!="")) echo "<card id=\"error\" title=\"error\" ontimer=\"send.php?id=$id&ps=$ps&ref=$ref&rm=$rm\"><timer value=\"10\"/>\n";
else echo "<card id=\"error\" title=\"error\" ontimer=\"send.php?id=$id&ps=$ps&ref=$ref\"><timer value=\"10\"/>\n";
echo "<p align=\"center\">\n";
echo $fsize1;
echo "Пользователя с ником $towhom не сушествует\n";
echo $fsize2;
echo "</p>\n";
echo "</card>\n";
echo "</wml>\n";
mysql_close ($link);
exit;
}
if ($row["translit"]==1) $topic = trun_to_rus($topic);
$time = time();
$data = date("H:i(d-M)");
$msg = $message;
require("smile.php");
$minpos = 1200; $nm = 1200;
for ($j=0;$j<=count($smiles)-1;$j++){
$tmpp = strpos($msg,$smiles[$j]);
if (($tmpp < $minpos)&&($tmpp !== false)){
$minpos = $tmpp; $nm = $j;};
};
if ($minpos !=1200){
if ($row["translit"]!=1){
$st1 = substr($msg,0,$minpos+strlen($smiles[$nm]));
$st2 = substr($msg,$minpos+strlen($smiles[$nm]),strlen($msg)-strlen($st1));
$st1 = str_replace($smiles[$nm],$replaces[$nm],$st1);
$msg = $st1.$st2;
} else {
$st1 = substr($msg,0,$minpos);
$st2 = substr($msg,$minpos, strlen($smiles[$nm]));
$st3 = substr($msg,$minpos+strlen($smiles[$nm]),strlen($msg)-strlen($st1)-strlen($st2));
$st1 = trun_to_rus($st1);
$st2 = $replaces[$nm];
$st3 = trun_to_rus($st3);
$msg = $st1.$st2.$st3;
}
}
else if ($row["translit"]==1) $msg = trun_to_rus($msg);
Unset($smiles);
unset($replaces);
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);
$message = $msg;
//////////////////////////////////////\\
$a = mysql_fetch_array($r);
$idtowhom=$a["id"];
$avtootvet=$a["avtootvet"];
$kol = rand(0,99999999);
$time = time();
$data = date("d M Y [H:i]");
$times = getmicrotime();
//Антифлуд
mysql_query("Select readd from zapiski WHERE (who='".$us."')and(idwho ='".$id."')and(message = '".$message."')and(towhom = '".$towhom."')and(idtowhom = '".$idtowhom."')and(topic = '".$topic."')");
if (mysql_affected_rows()===0){
mysql_query("Insert into zapiski set klu4='".$kol."', who ='".$us."', idwho ='".$id."', message = '".$message."', towhom = '".$towhom."', idtowhom = '".$idtowhom."', time = '".$times."', readd = '0', topic = '".$topic."', date='".$data."'")&&mysql_query ("Update users set onl='".$times."', room='letters' where id ='".$id."'");
}
if (mysql_error() == false){
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">\n";
echo "<wml>\n";
echo "<head><meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/></head>\n";
if ((isset($rm))&&($rm!="")) echo "<card id=\"done\" title=\"Отправлено\" ontimer=\"chat.php?id=$id&ps=$ps&rm=$rm\"><timer value=\"60\"/>\n";
else echo "<card id=\"done\" title=\"Done!\" ontimer=\"chatmail.php?id=$id&ps=$ps\"><timer value=\"60\"/>\n";
echo "<p align =\"center\">\n";
echo $fsize1;
echo "Ваше сообщение для <b>$towhom</b> успешно отправлено!<br/>\n";
echo $fsize2;
//Автоответчик
if($avtootvet!=""){
echo $fsize1;
echo "---<br/>\n";
echo "Автоответчик: $avtootvet<br/>\n";
echo $fsize2;
}
/////////////
echo $fsize1;
echo "---<br/>\n";
echo "<a href=\"chatmail.php?id=$id&ps=$ps\">Ваша почта</a><br/>\n";
echo "<a href=\"enter.php?id=$id&ps=$ps&ref=$ref\">Прихожая</a><br/>\n";
echo $fsize2;
echo "</p>\n";
echo "</card>\n";
echo "</wml>\n";
} else {
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">\n";
echo "<wml>\n";
echo "<head><meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/></head>\n";
if ((isset($rm))&&($rm!="")) echo "<card id=\"error\" title=\"error\" ontimer=\"send.php?id=$id&ps=$ps&rm=$rm\"><timer value=\"20\"/>\n";
else echo "<card id=\"error\" title=\"error\" ontimer=\"send.php?id=$id&ps=$ps\"><timer value=\"20\"/>\n";
echo "<p align=\"center\">\n";
echo $fsize1;
echo "Ошибка при отправке письма! Попробуйте еще раз.<br/>\n";
echo $fsize2;
echo "ERROR ".mysql_error()." ";
echo "</p>\n";
echo "</card>\n";
echo "</wml>\n";
}
mysql_close ($link);
} else {
if ($row["translit"]==1) $topic = trun_to_rus($topic);
$fr = $row["friends"];
$time = time();
$data = date("H:i(d-M)");
$msg = $message;
require("smile.php");
$minpos = 1200; $nm = 1200;
for ($j=0;$j<=count($smiles)-1;$j++){
$tmpp = strpos($msg,$smiles[$j]);
if (($tmpp < $minpos)&&($tmpp !== false)){
$minpos = $tmpp; $nm = $j;};
};
if ($minpos !=1200){
if ($row["translit"]!=1){
$st1 = substr($msg,0,$minpos+strlen($smiles[$nm]));
$st2 = substr($msg,$minpos+strlen($smiles[$nm]),strlen($msg)-strlen($st1));
$st1 = str_replace($smiles[$nm],$replaces[$nm],$st1);
$msg = $st1.$st2;
} else {
$st1 = substr($msg,0,$minpos);
$st2 = substr($msg,$minpos, strlen($smiles[$nm]));
$st3 = substr($msg,$minpos+strlen($smiles[$nm]),strlen($msg)-strlen($st1)-strlen($st2));
$st1 = trun_to_rus($st1);
$st2 = $replaces[$nm];
$st3 = trun_to_rus($st3);
$msg = $st1.$st2.$st3;
}
}
else if ($row["translit"]==1) $msg = trun_to_rus($msg);
Unset($smiles);
unset($replaces);
if($row["level"]>6)$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);
$message = $msg;
$alls="";
if (strpos ($fr,"|") !== false){
$s1 = substr($fr,0,strpos($fr,"|"));
while (strpos ($fr,"|") !== false){
$name = $s1;
$fr = substr ($fr, strpos($fr,"|")+1, strlen($fr)-strlen($s1)+1);
$s1 = substr($fr,0,strpos($fr,"|"));
$w = mysql_query ("select id,user from users where user = '".$name."'");
if (mysql_affected_rows() == 0) continue;
$b = mysql_fetch_array($w);
$idtowhom=$b["id"];
$towhom=$b["user"];
$kol = rand(0,99999999);
mysql_query("Insert into zapiski set klu4='".$kol."', who ='".$us."', idwho ='".$id."', message = '".$message."', towhom = '".$towhom."', idtowhom = '".$idtowhom."', time = '".$time."', readd = '0', topic = '".$topic."', date='".$data."'")&&mysql_query ("Update users set onl='".$time."', room='letters' where id ='".$id."'");
if (mysql_error() != false)continue;
$alls=$alls."$towhom, ";
}
}
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">\n";
echo "<wml>\n";
echo "<head><meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/></head>\n";
if ((isset($rm))&&($rm!="")) echo "<card id=\"done\" title=\"Отправлено\" ontimer=\"chat.php?id=$id&ps=$ps&rm=$rm\"><timer value=\"15\"/>\n";
else echo "<card id=\"done\" title=\"Отправлено\" ontimer=\"chatmail.php?id=$id&ps=$ps\"><timer value=\"15\"/>\n";
echo "<p align =\"center\">\n";
echo $fsize1;
echo "Ваше письмо успешно отправлено следующим пользователям: $alls";
echo $fsize2;
echo "</p>\n";
echo "</card>\n";
echo "</wml>\n";
mysql_close ($link);
}
?>