<?
require('ini.php');
$link=connect();
$user=login('nick, mlim, loc');
$mlim=$user['mlim'];
@$uid=intval($_GET['uid']);
@$s=intval($_GET['s']);
$select=mysql_query("select nick,online from wip_users where id='$uid';");
if(mysql_affected_rows()<1){
head('Ошибка!');
echo '<small><b>Нет такого юзера!</b><br/>';
echo '<anchor>Назад<prev/></anchor></small>';
foot();
exit();
}
$us=mysql_fetch_row($select);
//Проверка: есть ли адресат у пользователя в контактах
mysql_query("select id from wip_contacts where cid='$uid' and uid='$user[id]';");
if(mysql_affected_rows()<1){
mysql_query("insert into wip_contacts set uid='$user[id]', cid='$uid', nick='$us[0]';");
}
////
if(@$_POST['msg']){
$msg=htmlspecialchars($_POST['msg'],ENT_QUOTES);
$msg=str_replace('$','$',$msg);
$msg = mb_substr($msg, 0, 255, 'UTF-8');
//Добавление смайлов
$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 $key=>$val){
if($key!=0 and $key<=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_contacts where cid='$user[id]' and uid='$uid';");
if(mysql_affected_rows()<1){
mysql_query("insert into wip_contacts set uid='$uid', cid='$user[id]', nick='$user[nick]', msg='0';");
}
////
mysql_query("select id from wip_talk where uid='$user[id]' and `to`='$uid' and msg='$msg';");
if(mysql_affected_rows()<1){
mysql_query("insert into wip_talk set uid='$user[id]', `to`='$uid', time='".time()."', msg='$msg';");
mysql_query("update wip_contacts set `msg`=`msg`+1 where cid='$user[id]' and uid='$uid';");
}
}
mysql_query("update wip_contacts set msg='0' where cid='$uid' and uid='$user[id]';");
head('Чат: '.$us[0],false,false,true);
$onl=($us[1]>(time()-300))?'ON':'OFF';
echo '<small><a href="user.php?sid='.$sid.'&uid='.$uid.'">'.$us[0].'</a> - '.$onl.'</small><br/>';
echo '</p><p>';
echo '<input name="msg'.$ref.'" type="text" maxlength="400"/> ';
echo '<small><anchor>Отправить<go href="talk.php?sid='.$sid.'&uid='.$uid.'" method="post">';
echo '<postfield name="msg" value="$(msg'.$ref.')"/>';
echo '</go></anchor><br/>';
echo '<a href="talk.php?sid='.$sid.'&uid='.$uid.'">Обновить</a><br/>';
echo '---<br/>';
if (!$s or $s<=0) $s=1;
$all=mysql_fetch_row(mysql_query("select count(id) from wip_talk where (uid='$uid' and `to`='$user[id]') or (`to`='$uid' and uid=$user[id]);"));
$pgs=ceil($all[0]/$mlim);
if($s>$pgs) $s=$pgs;
$n=($s-1)*$mlim;
if($all[0]!=0){
$select=mysql_query("select wip_talk.id,wip_talk.read,wip_users.nick, wip_talk.uid, wip_talk.time, wip_talk.msg from wip_talk, wip_users where wip_talk.uid=wip_users.id and ((wip_talk.uid='$uid' and wip_talk.to='$user[id]') or (wip_talk.to='$uid' and wip_talk.uid=$user[id])) order by wip_talk.id desc limit $n,$mlim;");
while($res=mysql_fetch_assoc($select)){
echo '<b>['.$res['nick'].']</b> ['.date('H:i',$res['time']).'] '.$res['msg'].'<br/>';
}
//Список страниц
if ($all[0]>$mlim){
echo '---<br/>';
if ($pgs>3 and $s>2){
echo '<a href="talk.php?sid='.$sid.'&uid='.$uid.'&s=1">1</a>...';
}
$beg=$s-1; $end=$s+1;
if ($end>$pgs+1){
$end=$pgs; $beg=$beg-2;
}
elseif ($end>$pgs){
$end=$pgs; $beg=$beg-1;
}
for($m=$beg;$m<=$end;$m++){
if ($m<=0){
$end++;
}
else{
if($m==$s){
echo '<b>'.$m.'</b>';
}
else{
echo '<a href="talk.php?sid='.$sid.'&uid='.$uid.'&s='.$m.'">'.$m.'</a>';
}
if($m!=$end){
echo '-';
}
}
if ($end>$pgs) $end=$pgs;
}
if ($pgs>3 and $s<=($pgs-2)){
echo '...<a href="talk.php?sid='.$sid.'&uid='.$uid.'&s='.$pgs.'">'.$pgs.'</a>';
}
echo '<br/>';
}
/////
}
echo '---<br/>';
echo '<a href="contacts.php?sid='.$sid.'">Контакт-лист</a><br/>';
if($user['loc']) echo '<a href="'.$user['loc'].'.php?sid='.$sid.'">'.$locs[$user['loc']].'</a><br/>';
echo '<a href="enter.php?sid='.$sid.'">Главное меню</a>';
echo '</small>';
foot();
//mysql_close($link);
?>