Файл: msg.php
Строк: 99
<?
include_once 'system/sys.php';
if(!$cms->us['id']){ header('location: /'); }
verh('Почта','<a href="/mail.php" style="color: #fff;">Почта</a>');
include_once 'system/funcs.php';
$u = abs(intval($_GET['u']));
if($u==$cms->us['id'] or DB::$dbs->querySingle("SELECT count(id) from `us` where `id` = ? limit 1",array($u))==0){header('location:/'); exit;}
$num = 10;
if(DB::$dbs->querySingle("SELECT count(id) from `poch` where `us` = ? and `kem` = ?",array($cms->us['id'],$u))==0){
DB::$dbs->query("INSERT INTO `poch` set `us` = ?, `kem` = ?, `last` = ?",array($cms->us['id'],$u,time()));
echo'<div class="list1">Контакт успешно добавлен...</div>';
}
if(DB::$dbs->querySingle("SELECT count(id) from `poch` where `kem` = ? and `us` = ?",array($cms->us['id'],$u))==0){
DB::$dbs->query("INSERT INTO `poch` set `kem` = ?, `us` = ?, `last` = ?",array($cms->us['id'],$u,time()));
}
if(DB::$dbs->querySingle("SELECT count(id) FROM `forum_post` where `us` = ? and `del` = '0'",array($cms->us['id']))<10 or $cms->us['online']<(3600*3)){
echo '<div class="list1">Для того, чтобы писать личные сообщение Вы должны набрать 10 постов в форуме и провести на сайте 3 часа!</div>';
}else{
$ign = DB::$dbs->queryFetch("SELECT id from `ignor` where `us` = ? and `kem` = ? limit 1",array($cms->us['id'],$u));
if(isSet($_GET['ignor'])){
if($ign != 0){ DB::$dbs->query("DELETE from `ignor` where `us` = ? and `kem` = ?",array($cms->us['id'],$u)); header('location: /ignor.php'); exit; }else{
echo '<div class="lst">Вы уверены что хотите добавить '.$func->uNick($u).' в игнор-лист?<br><a href="/msg'.$u.'?ignor=da"><img src="/images/yes.png" alt="*"/></a> | <a href="/msg'.$u.'"><img src="/images/stop_2.png" alt="*"/></a></div>';
if($_GET['ignor'] == 'da'){
if(DB::$dbs->query("insert into `ignor` (`us`,`kem`) values (?,?)",array($cms->us['id'],$u))){
echo '<div class="lst">'.$func->uNick($u).' добавлен в ваш игнор-лист!</div>';
}
}
}
}
echo'<div class="list1">
<form action="?u='.$u.'&send" method="post" enctype="multipart/form-data">
Сообщение: (<a href="/msg'.$u.'">обн</a>/игнор [<a href="/msg.php?u='.$u.'&ignor">'.($ign['id'] ? 'выкл':'вкл').'</a>])<br/>
<textarea name="text"></textarea><br/>';
if($cms->us['file']==1) echo 'Файл:<br/><input type="file" name="filename"/><br/>';
echo '<input type="submit" value="Отправить"/></form></div>
<div class="rega"><a href="/kab/index.php?at=opt&dis&ms='.$u.'"><img src="/images/'.($cms->us['file']==0?'default_document':'file_broken').'.png" alt="*" class="ico"/></a> <a href="/kab/index.php?at=opt&dia&th='.$u.'"><img src="/images/mail_forward.png" alt="*" class="ico"/></a></div>';
if(isset($_GET['send'])){
$text = secure($_POST['text']);
if(!$text){
echo'<div class="list1">Вы не ввели текст сообщения...</div>';
}else{
if(file_exists($_FILES['filename']['tmp_name'])){
$exts=array('jpg','gif','png','jpeg','bmp','zip','rar','7z','txt','mp3','avi','mp4','3gp');
$ext=substr($_FILES['filename']['name'],strrpos( $_FILES['filename']['name'],".")+1);
if(in_array($ext,$exts)){
$fn=$_SERVER['HTTP_HOST'].'_'.$u.'_'.rand(111111,999999).'_'.rand(111111,999999).'.'.$ext;
move_uploaded_file($_FILES['filename']['tmp_name'],'./files/mail/'.$fn);
}
}
$poch = DB::$dbs->queryFetch("SELECT id from `poch` where `us` = ? and `kem` = ? limit 1",array($cms->us['id'],$u));
DB::$dbs->query("INSERT INTO `msg` set `us` = ?, `kem` = ?, `text` = ?, `time` = ?, `poch` = ?, file = ?",array($u,$cms->us['id'],$text,time(),$poch['id'],$fn));
DB::$dbs->query("UPDATE `poch` set `last` = ? where `kem` = ? and `us` = ? limit 1",array(time(),$cms->us['id'],$u));
DB::$dbs->query("UPDATE `poch` set `last` = ? where `us` = ? and `kem` = ? limit 1",array(time(),$cms->us['id'],$u));
header('location:/msg'.$u); exit;
}
}
}
$posts = DB::$dbs->querySingle("SELECT count(id) FROM `msg` where `us` = ? and `kem` = ? or `kem` = ? and `us` = ?",array($cms->us['id'],$u,$cms->us['id'],$u));
if($posts==0){echo'<div class="lst">Сообщений нет...</div>';}else{
$total = intval(($posts - 1) / $num) + 1;
$page = $func->num($_GET['page']);
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * $num - $num;
$mails = DB::$dbs->query("SELECT * from `msg` where `us` = ? and `kem` = ? or `kem` = ? and `us` = ? order by `time` desc limit $start,$num",array($cms->us['id'],$u,$cms->us['id'],$u));
while($mail = $mails -> fetch()){
echo'<div class="lst">'.$func->uNick($mail['kem']).' '.($mail['see']==1?'[<font color="red"><b>Непрочитанное</b></font>]':NULL).' ['.t($mail['time']).']<br/>'.$func->text($mail['text']);
if($mail['file']) echo '<br/>Файл: <a href="/files/mail/'.$mail['file'].'"><b>'.$mail['file'].'</b></a> ('.round(filesize('./files/mail/'.$mail['file'])/1024).'Kb)';
echo '</div>';
DB::$dbs->query("UPDATE `msg` set `see` = ? where `us` = ? and `kem` =? and `see` = ? limit 10",array(0,$cms->us['id'],$u,1));
}
echo '<div class="lst">';
$func->page('/msg'.$u);
echo '</div>';
}
echo '<div class="list1"><a href="/mail.php">Все диалоги</a></div>';
niz();
?>