<?

header('Cache-Control: no-store, no-cache, must-revalidate');
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");
$mid = intval($mid);
$us = $row["user"]; 
$translit = $row["translit"];

$message = check($message);

if ($ver=="wml"){
echo $xml;
echo $dtd;
echo "<wml>\n";
echo "<card title=\"Свадьбы чата\">\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>";
}


switch($go) {

default:
if ($ver=="wml") echo "<p align=\"center\">";
else echo "<div align=\"center\">";
echo "<img src=\"smilean/love10.gif\" alt=\"Love\"/><br/>";
echo $fsize1;
echo $divide;
echo $fsize2;
$print = mysql_query("select * from `svadbi` order by id desc;");
if (mysql_affected_rows() == 0) {
echo $fsize1;
echo "Свадеб нет(<br/>";
echo $fsize2;
}
while($arr = @mysql_fetch_array($print)) {
print $fsize1;
print "Свадьба <b><a href=\"svadbi.php?$ses&amp;go=view&amp;mid=".$arr['id']."\">".$arr['zhenih']." &amp; ".$arr['nevesta']."</a></b> (".$arr['date'].")<br/>";
print $fsize2; 
}   
break;

case 'view':
$select = @mysql_query ("Select * from `svadbi` where id='".$mid."';");
$inf = mysql_fetch_array ($select);
$zhenih = $inf["zhenih"];
$nevesta = $inf["nevesta"];
$frzhenih = $inf["frzhenih"];
$frnevesta = $inf["frnevesta"];
$days = $inf["date"];
$times = $inf["vremya"];
$organizatory = $inf["organizatory"];
if ($ver=="wml") echo "<p align=\"center\">";
else echo "<div align=\"center\">";
echo "<img src=\"smilean/love10.gif\" alt=\"Love\"/><br/>";
if ($ver=="wml") echo "</p><p align=\"left\">";
else echo "</div><div align=\"left\">";
echo $fsize1;
echo "Приглашаем всех чатлан на свадьбу между двумя любящими сердацми <b>".$zhenih."</b> и <b>".$nevesta."</b>, которая состоится <b>".$days."</b> в <b>".$times."</b> в нашем чате в комнате <b>ЗАГС</b>.<br/>";
echo $divide;
echo "<u>Друзья жениха:</u> ".$frzhenih."<br/>";
echo "<u>Подруги невесты:</u> ".$frnevesta."<br/>";
echo $divide;
echo "Организатор: ".$organizatory."<br/>";
echo $divide;
echo $fsize2;
echo $fsize1;
echo "<a href=\"svadbi.php?$ses&amp;mid=$mid&amp;ref=$ref&amp;go=send&amp;mod=ok\">Послать им поздравление</a>\n";
echo $fsize2;
echo "<br/>\n";
break;

case 'send':
if ($ver=="wml") echo "<p align=\"center\">";
else echo "<div align=\"center\">";
//Проверка на существование ника жениха
if (isset($mod)){
$select = @mysql_query ("Select * from `svadbi` where id='".$mid."';");
$inf = mysql_fetch_array ($select);
$zhenih = $inf["zhenih"];
$nevesta = $inf["nevesta"];

$latuser=strtolower($zhenih);
$ruser = rus_to_k($zhenih);
if($ruser==$zhenih){
$result1 = mysql_query ("Select id,user from users where latuser = '".$latuser."'"); 
} else {
$result1 = mysql_query ("select id,user from users where ruser = '".$ruser."'");
}
if (mysql_affected_rows() == 0) {
print $fsize1;
print "<u>Парня с ником <b>".$zhenih."</b> не сущетвует.</u><br/>";
print $fsize2;
break;
}
$row1 = mysql_fetch_array ($result1);
$nkm = $row1["id"];
$loginm  = $row1["user"];

//Проверка на существование ника невесты
$latuser=strtolower($nevesta);
$ruser = rus_to_k($nevesta);
if($ruser==$nevesta){
$result2 = mysql_query ("Select id,user from users where latuser = '".$latuser."'"); 
} else {
$result2 = mysql_query ("select id,user,pass from users where ruser = '".$ruser."'");
}
if (mysql_affected_rows() == 0) {
print $fsize1;
print "<u>Девушки с ником <b>".$nevesta."</b> не сущетвует.</u><br/>";
print $fsize2;
break;
}
$row2 = mysql_fetch_array ($result2);
$nkz = $row2["id"]; 
$loginz = $row2["user"];

echo $fsize1;
echo "<img src=\"smilean/love10.gif\" alt=\"Love\"/><br/>";
echo "Поздравление со свадьбой для <b>".$loginm."</b> и <b>".$loginz."</b><br/>\n";
$loginm = UrlEncode($loginm);
$loginz = UrlEncode($loginz);
echo $divide;
echo $fsize2;
if ($ver=="wml"){
echo "<input name=\"message$ref\" maxlength=\"600\" value=\"$message\" title=\"message\"/><br/>\n"; 
echo $fsize1;
echo "<anchor title=\"go\">Отправить<go href=\"svadbi.php?$ses&amp;ref=$ref&amp;go=send\" method=\"post\">\n";
echo "<postfield name=\"message\" value=\"$(message$ref)\"/>\n";
echo "<postfield name=\"loginm\" value=\"$loginm\"/>\n";
echo "<postfield name=\"loginz\" value=\"$loginz\"/>\n";
echo "<postfield name=\"nkm\" value=\"$nkm\"/>\n";
echo "<postfield name=\"nkz\" value=\"$nkz\"/>\n"; 
echo "</go></anchor>\n";
echo $fsize2;
echo "<br/>\n";
}else{
echo "<form action=svadbi.php method=post\">\n";
echo "<input type=hidden name=ver value=$ver />\n";
echo "<input type=hidden name=id value=$id />\n";
echo "<input type=hidden name=amp value=$amp />\n";
echo "<input type=hidden name=ps value=$ps />\n";
echo "<input type=hidden name=go value=send />\n";
echo "<input type=hidden  name=loginm value=$loginm />\n";
echo "<input type=hidden  name=loginz value=$loginz />\n";
echo "<input type=hidden  name=nkm value=$nkm />\n";
echo "<input type=hidden  name=nkz value=$nkz />\n"; 
echo "<input type=text name=message maxlength=\"600\"><br/>\n";
echo "<input type=submit value=\"Отправить\"/></form>\n";
}
break;
}
if(empty($message)){
echo $fsize1;
echo "<u>Поле поздравления не заполнено.</u><br/>";
echo $fsize2;
break;
}

$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;  

$nkm = trim(" $nkm ");
$loginm = trim(" $loginm ");
$nkz = trim(" $nkz ");
$loginz = trim(" $loginz ");
$data = date("d-M-Y [H:i]");
$kol = rand(0,99999999);
$kol2 = rand(0,99999999);
$time = time();
$topic = "Поздравление со свадьбой!!!";
if (mysql_query("Insert into zapiski set klu4='".$kol."', who ='".$us."', idwho ='".$id."', message = '".$message."', towhom = '".$loginm."', idtowhom = '".$nkm."', time = '".$time."', readd = '0', topic = '".$topic."', date='".$data."'")){
echo "<img src=\"smilean/love10.gif\" alt=\"Love\"/><br/>";
$loginm = UrlDecode($loginm);
$loginz = UrlDecode($loginz);
echo $fsize1;
echo "Жених <b>".$loginm."</b> получил Ваше поздравление.<br/>";
echo $fsize2;
}else{
echo $fsize1;
echo "Ошибка. <b>".$loginm."</b> не получил поздравление.<br/>";
echo $fsize2;
}	
if (mysql_query("Insert into zapiski set klu4='".$kol2."', who ='".$us."', idwho ='".$id."', message = '".$message."', towhom = '".$loginz."', idtowhom = '".$nkz."', time = '".$time."', readd = '0', topic = '".$topic."', date='".$data."'")){
echo "<img src=\"smilean/love10.gif\" alt=\"Love\"/><br/>";
echo $fsize1;
echo "Невеста <b>".$loginz."</b> получила Ваше поздравление.<br/>";
echo $fsize2;
}else{
echo $fsize1;
echo "Ошибка. <b>".$loginz."</b> не получила поздравление.<br/>";
echo $fsize2;
}
break;
}
echo $fsize1;
echo $divide;
echo $fsize2;
if($go) {
echo $fsize1;
echo "<a href=\"svadbi.php?$ses&amp;ref=$ref\">&#8592; Свадьбы</a><br/>\n"; 
echo $fsize2;
}
echo $fsize1;
echo "<a href=\"enter.php?$ses&amp;ref=$ref\">&#8592; Прихожая</a><br/>";
echo $fsize2; 
if ($ver=="wml")echo "</p></card></wml>";
else echo "</div></body></html>";
mysql_close($link);
?>