<?
require('ini.php');
$link=connect();
@$mod = $_GET['mod'];
@$s = intval($_GET['s']);
@$uid = intval($_GET['uid']);
@$key = htmlspecialchars(trim($_GET['key']), ENT_QUOTES);
$user=login('nick, private_pass, chat_upd, chat_msgs, chat_ignor, chat_last, trans, loc');
###
header("Content-type:text/vnd.wap.wml");
echo '<?xml version="1.0" encoding="UTF-8"?>'.
'<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd">'.
'<wml><head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>';
$select = mysql_query("SELECT `nick`, `private_pass` FROM `wip_users` WHERE `id`='".$uid."';");
if(mysql_affected_rows()<1 or $uid==1){
echo '<card id="main" title="Ошибка"><p>';
echo '<small>Неверный пользователь!<br/>';
echo '<anchor>Назад<prev/></anchor></small>';
foot();
exit();
}
$us_res = mysql_fetch_assoc($select);
if(!$us_res['private_pass']){
echo '<card id="main" title="Ошибка"><p>';
echo '<small>У '.$us_res['nick'].' ещё не создана приватная комната!<br/>';
echo '<anchor>Назад<prev/></anchor></small>';
foot();
exit();
}
if($us_res['private_pass']!=$key){
echo '<card id="main" title="Приватная комната"><p>';
echo '<small>';
if($key and $us_res['private_pass']!=$key) echo '<b>Неверный пароль!</b><br/>';
echo 'Вы должны ввести пароль, чтобы войти в приватную комнату <b>'.$us_res['nick'].'</b>:</small><br/>';
echo '<input name="key'.$ref.'" type="text" maxlength="20"/><br/>';
echo '<small><a href="love_chat.php?sid='.$sid.'&uid='.$uid.'&key=$(key'.$ref.')">Войти</a><br/>';
echo '---<br/>';
echo '<a href="love.php?sid='.$sid.'">Знакомства</a><br/>';
echo '<a href="enter.php?sid='.$sid.'">Главное меню</a><br/>';
echo '</small>';
foot();
exit();
}
if($user['loc']!='private_chat_'.$uid) mysql_query("update wip_users set loc='private_chat_".$uid."' where id='$user[id]';");
$key_link='uid='.$uid.'&key='.$key.'&';
if($user['chat_upd'] and $s<2) echo '<card id="main" title="Приват '.$us_res['nick'].'" ontimer="love_chat.php?sid='.$sid.'&'.$key_link.'"><timer value="'.$user['chat_upd'].'"/>';
else echo '<card id="main" title="Приват '.$us_res['nick'].'">';
echo '<do type="options" label="Сказать"><go href="love_chat_say.php?sid='.$sid.'&'.$key_link.'"/></do>';
echo '<do type="options" label="Обновить"><go href="love_chat.php?sid='.$sid.'&'.$key_link.'"/></do>';
echo '<do type="options" label="Кто здесь?"><go href="chat_online.php?sid='.$sid.'&'.$key_link.'"/></do>';
echo '<p>';
//Отправленное сообщение
if(@$_POST['msg']){
@$to=intval($_GET['uid']);
mysql_query("select id from wip_users where id='$to';");
if(mysql_affected_rows()<1) $to=false;
@$msg = $_POST['msg'];
if($user['trans']) $msg=strtr($msg,array('A'=>'А','a'=>'а','B'=>'Б','b'=>'б','V'=>'В','v'=>'в','G'=>'Г','g'=>'г','D'=>'Д','d'=>'д','E'=>'Е','e'=>'е','yo'=>'ё','Zh'=>'Ж','zh'=>'ж','Z'=>'З','z'=>'з','I'=>'И','i'=>'и','J'=>'Й','j'=>'й','K'=>'К','k'=>'к','L'=>'Л','l'=>'л','M'=>'М','m'=>'м','N'=>'Н','n'=>'н','O'=>'О','o'=>'о','P'=>'П','p'=>'п','R'=>'Р','r'=>'р','S'=>'С','s'=>'с','T'=>'Т','t'=>'т','U'=>'У','u'=>'у','F'=>'Ф','f'=>'ф','H'=>'Х','h'=>'х','C'=>'Ц','c'=>'ц','Ch'=>'Ч','ch'=>'ч','Sh'=>'Ш','sh'=>'ш','Sch'=>'Щ','sch'=>'щ',"''"=>'ъ','Y'=>'Ы','y'=>'ы',"'"=>'ь','Ye'=>'Э','ye'=>'э','Yu'=>'Ю','yu'=>'ю','Ya'=>'Я','ya'=>'я','Yo'=>'Ё'));
$msg = mb_substr( htmlspecialchars($msg, ENT_QUOTES), 0, 400, 'UTF-8');
$msg=str_replace('$','$',$msg);
//Добавление смайлов
$msg=strtr($msg,array(':)'=>'<smile.gif>', ';)'=>'<wink.gif>', 'B)'=>'<cool.gif>', ':(('=>'<aaa.gif>', ':!'=>'<be.gif>', ':S'=>'<blin.gif>', '@='=>'<bum.gif>', ':X'=>'<close.gif>', ';('=>'<cry.gif>', ']:)'=>'<devil.gif>', '@-/-'=>'<flow.gif>', ':]'=>'<gaga.gif>', ':D'=>'<green.gif>', '=)'=>'<ha.gif>', '(:'=>'<lol.gif>', '=/'=>'<hm.gif>', '.kiss.'=>'<kiss.gif>', ':o)'=>'<kloun.gif>', '.lips.'=>'<lips.gif>', '.love.'=>'<love.gif>', '8o'=>'<mmm.gif>', '[:)'=>'<music.gif>', '=]'=>'<napolu.gif>', '.ninja.'=>'<ninja.gif>', '.down.'=>'<no.gif>', '%)'=>'<ogo.gif>', '.pirat.'=>'<pirate.gif>', '.beer.'=>'<pivo.gif>', ':['=>'<red.gif>', ':('=>'<sad.gif>', '.woot.'=>'<shok.gif>', '.zz.'=>'<spit.gif>', '=p'=>'<tong.gif>', ':T'=>'<svist.gif>', '.uuu.'=>'<uuu.gif>', '.wow.'=>'<view.gif>', ':?'=>'<vopros.gif>', '.up.'=>'<yes.gif>', ':@'=>'<angry2.gif>', ':O'=>'<angry.gif>'));
$arr=explode('<',$msg);
$msg=false;
foreach($arr as $k=>$val){
if($k!=0 and $k<=3) $msg.='<img src="smiles/'.$val;
else $msg.=$val;
}
$msg=preg_replace("/src\=\"smiles\/([a-z]+)\.gif\>/","src=\"smiles/\\1.gif\" alt=\"\\1\"/>",$msg);
$msg=eregi_replace("([a-z]+)\.gif\>","",$msg);
////
mysql_query("select id from wip_love_chat where r_uid='$uid' and uid='$user[id]' and msg='$msg';");
if(mysql_affected_rows()<1){
if(@$_POST['privat'] and $to) $privat=$to;
else $privat=0;
mysql_query("insert into wip_love_chat set r_uid='$uid', uid='$user[id]', privat='$privat', time='".time()."', msg='$msg';");
mysql_query("update wip_users set chat_posts=chat_posts+1 where id='$user[id]';");
}
}
//////
echo '<small>';
echo '<a href="love_chat_say.php?sid='.$sid.'&'.$key_link.'" accesskey="1">Сказать [1]</a> | ';
echo '<a href="love_chat.php?sid='.$sid.'&'.$key_link.'" accesskey="2">Обновить [2]</a><br/>';
echo '---<br/>';
if($user['chat_ignor']) $ignor=base64_decode($user['chat_ignor']); //Собираем условие игнора
else $ignor=false;
$mlim=$user['chat_msgs'];
if($uid == $user['id']){
$c_unread = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `wip_love_chat` WHERE `read`=1 AND `r_uid`='".$uid."';"), 0);
if($c_unread > 0) mysql_query("UPDATE `wip_love_chat` SET `read`=0;");
}
$all=mysql_fetch_row(mysql_query("select count(id) from wip_love_chat where r_uid='$uid' and (wip_love_chat.privat='$user[id]' or wip_love_chat.privat='0' or wip_love_chat.uid='$user[id]') ".$ignor.";"));
if (!$s or $s<=0) $s=1;
$pgs=ceil($all[0]/$mlim);
if($s>$pgs) $s=$pgs;
$n = ($s-1) * $mlim;
$select=mysql_query("SELECT `wip_love_chat`.`id`, `wip_love_chat`.`time`, `wip_love_chat`.`uid`, `wip_love_chat`.`privat`, `wip_users`.`nick`, `wip_love_chat`.`msg` FROM `wip_love_chat`, `wip_users` WHERE `r_uid`='".$uid."' AND `wip_love_chat`.`uid`=`wip_users`.`id` AND (`wip_love_chat`.`privat`='".$user['id']."' OR `wip_love_chat`.`privat`=0 OR `wip_love_chat`.`uid`='".$user['id']."') ".$ignor." ORDER BY `wip_love_chat`.`id` DESC LIMIT ".$n.",".$mlim.";");
$last=false;
$new=false;
if($all[0]>0){
while($res=mysql_fetch_assoc($select)){
if($res['id']==$user['chat_last'] and $last) echo '---<br/>';
if(!$last){
mysql_query("update wip_users set chat_last='$res[id]' where id='$user[id]';");
$last=true;
}
if($res['uid'] != $user['id'] and $res['uid']!=1) echo '<b><a href="love_chat_say.php?sid='.$sid.'&key='.$key.'&uid='.$uid.'&to='.$res['id'].'">'.$res['nick'].'</a></b> ';
else echo '<b>'.$res['nick'].'</b> ';
if($res['privat']) echo '<b>[приват]</b> ';
echo '['.date('H:i',$res['time']).'] '.$res['msg'].'<br/>';
}
}
if($all[0]>$mlim){
echo '---<br/>';
if($s<$pgs) echo '<a href="love_chat.php?sid='.$sid.'&r='.$r.'&s='.($s+1).'">Далее</a><br/>';
if($s!=1) echo '<a href="love_chat.php?sid='.$sid.'&r='.$r.'&s='.($s-1).'">Назад</a><br/>';
}
echo '---<br/>';
echo '<a href="love_chat.php?sid='.$sid.'&'.$key_link.'">Обновить [2]</a><br/>';
echo '<a href="love.php?sid='.$sid.'">Знакомства</a><br/>';
echo '<a href="enter.php?sid='.$sid.'">Главное меню</a><br/>';
echo '</small>';
foot();
mysql_close($link);
?>