Файл: my/mail.php
Строк: 277
<?
define('ROOT','../');
require_once (ROOT.'system/power.php');
$fuser->aut();
$diz -> head('Личные сообщения');
switch($act) {
///Удаление диалога
case 'deldialog':
$sql = $db -> query("SELECT `id` FROM `dialogs` WHERE `id` = '".$id."' and `oid`='$ya[id]' or `id` = '".$id."' and `user`='$ya[id]' LIMIT 1");
if ($sql -> num_rows > 0) {
if (!isset($_GET['true'])) {
$diz -> title('Удаление диалога');
echo '<div class="fon">'.language('Вы подтверждаете это действие').'?</div>';
echo '<div class="dialog">
<a class="dialog_m" href="mail.php?act=deldialog&id='.$id.'&true">'.language('Да').'</a>
<a class="dialog_m" href="'.ROOT.'mail">'.language('Нет').'</a>
</div>';
} else {
$db -> query("DELETE FROM `dialogs` WHERE `id`='".$id."'");
$db -> query("DELETE FROM `mail` WHERE `dialog`='".$id."'");
header('location: '.ROOT.'mail');
}
} else header('location: '.ROOT.'mail');
echo '<div class="levo"><a href="/mail" class="levo_tuch">'.$diz -> icon('back.png').' '.language('Сообщения').'</a></div>';
break;
///Чистка диалога
case 'clear':
$sql = $db -> query("SELECT `id` FROM `dialogs` WHERE `id` = '".$id."' and `oid`='$ya[id]' or `id` = '".$id."' and `user`='$ya[id]' LIMIT 1");
if ($sql -> num_rows > 0) {
if (!isset($_GET['true'])) {
$diz -> title('Удаление диалога');
echo '<div class="fon">'.language('Вы подтверждаете это действие').'?</div>';
echo '<div class="dialog">
<a class="dialog_m" href="mail.php?act=clear&id='.$id.'&true">'.language('Да').'</a>
<a class="dialog_m" href="mail.php?act=read&id='.$id.'">'.language('Нет').'</a>
</div>';
} else {
$db -> query("DELETE FROM `mail` WHERE `dialog`='".$id."'");
$db -> query("DELETE FROM `dialogs` WHERE `id`='".$id."'");
header('location: '.ROOT.'mail');
}
} else header('location: '.ROOT.'mail');
break;
//Пишем новое сообщение
case 'new':
$diz -> title('Новое сообщение');
if(isset($id) and abs(intval($id))>0){
$value_login='value="'.$fuser->login($id,0).'"';
if(isset($_GET['message']))$_POST['login']=$fuser->login($id,0);
$url_root=ROOT.'id'.$id;
}else $url_root=ROOT.'my/mail.php';
if(isset($_SESSION['textrea_text']))$_POST['text']=$_SESSION['textrea_text'];
if (!isset($_POST['text']) and !isset($_POST['login'])) {
echo '<div class="fon"><form action="?act=new&id='.$id.'" method="post">
'.language('Кому').':<br/>
<input name="login" type="text" list="list" placeholder="'.language('Введите пользователя').'" required autocomplete="off" '.$value_login.'><br/>';
$sql = $db -> query("SELECT * FROM `nuts` where `time`<>'0' and `idwh`='".$ya['id']."' and `where`='frends' ORDER BY `id`");
if($sql->num_rows>0){
echo '<datalist id="list">';
while ($fr = $sql -> fetch_assoc()) {
echo '<option value="'.$fuser->famname($fr['user'],0).' (id'.$fr['user'].')">id'.$fr['user'].'</option>';
}
echo '</datalist>';
}
echo language('Сообщение').':<br/><textarea id="mail" name="text" required></textarea><br/>';
if($db->settings('emoji')==true and $_COOKIE['version']=='web'){
?>
<html>
<div id="container"></div>
<script type="text/javascript">
$(document).ready(function() {
$("#mail").emojioneArea({
container: "#container",
hideSource: true,
});
});
</script>
</html>
<?
require_once (ROOT.'system/lib/emojiarea/include.php');
}
echo '<input type="submit" value="'.language('Отправить').'"/></form></div>';
echo '<div class="levo"><a href="'.$url_root.'" class="levo_tuch">'.$diz -> icon('back.png').' '.language('Назад').'</a></div>';
}elseif(mb_strlen($func -> delprobel($_POST['text'])) < 2){
echo '<div class="fon">'.language('Ошибка').'</div>';
echo '<div class="levo"><a href="?act=new&id='.$id.'" class="levo_tuch">'.$diz -> icon('back.png').' '.language('Назад').'</a></div>';
} else {
if(is_numeric($_POST['login'])==true){
$id_user = abs(intval($_POST['login']));
$sql = $db -> query("SELECT `id`,`login`,`mail` FROM `users` WHERE `id` = '".$id_user."' LIMIT 1");
}elseif(strpos(trim($_POST['login']), 0x20)){
$id_user = preg_replace('#(.*)([0-9])(.*)#si', '2', $_POST['login']);
$sql = $db -> query("SELECT `id`,`login`,`mail` FROM `users` WHERE `id`='".$id_user."' LIMIT 1");
}else{
$id_user = shit($_POST['login']);
$sql = $db -> query("SELECT `id`,`login`,`mail` FROM `users` WHERE `login` = '".$id_user."' LIMIT 1");
}
if ($sql -> num_rows > 0) {
$otpr = $sql -> fetch_assoc();
if($otpr['mail']==0 and $ya['id']!=$otpr['id']){
if ($fuser->ignor($otpr['id'],$ya['id'])==false) {
/////////////////
$mtime = $db -> query("SELECT * FROM `mail` WHERE `oid` = '".$ya['id']."' order by `time` DESC")->fetch_assoc();
if($mtime['time']+$db->settings('floodpm')<=time()){
//////////////
$mesg = shit($_POST['text']);
$sql_dialog = $db -> query("SELECT `id` FROM `dialogs` WHERE `user`='".$otpr['id']."' and `oid`='".$ya['id']."' or `user`='".$ya['id']."' and `oid`='".$otpr['id']."'");
if ($sql_dialog->num_rows == 0) {
$db -> query("INSERT INTO `dialogs` (`user`,`oid`,`time`) VALUES ('".$otpr['id']."','".$ya['id']."','".time()."')");
$dialog = $db -> insert_id;
$db -> query("INSERT INTO `mail` (`fid`,`oid`,`dialog`,`text`,`time`) VALUES ('".$otpr['id']."','".$ya['id']."','".$dialog."','".$mesg."','".time()."')");
}else{
$dialog_select=$sql_dialog->fetch_assoc();
$dialog=$dialog_select['id'];
$db -> query("INSERT INTO `mail` (`fid`,`oid`,`dialog`,`text`,`time`) VALUES ('".$otpr['id']."','".$ya['id']."','".$dialog."','".$mesg."','".time()."')");
$db -> query("Update `dialogs` set `time`='".time()."' where `id`='".$dialog."'");
}
$_SESSION['textrea_text']=null;
header('location: ?act=read&id='.$dialog);
}else{
echo '<div class="fon">'.language('Попробуйте повторить это действие через').' '.$settings('floodpm').'</div>';
echo '<div class="levo"><a href="mail.php?act=new&id='.$id.'" class="levo_tuch">'.$diz -> icon('back.png').' '.language('Назад').'</a></div>';
}
}else{
echo '<div class="fon">'.language('Пользователь вас игнорирует').'</div>';
echo '<div class="levo"><a href="mail.php?act=new" class="levo_tuch">'.$diz -> icon('back.png').' '.language('Назад').'</a></div>';
}
}else{
echo '<div class="fon">'.language('Вы не можете писать данному пользователю').'</div>';
echo '<div class="levo"><a href="mail.php?act=new" class="levo_tuch">'.$diz -> icon('back.png').' '.language('Назад').'</a></div>';
}
}else header('Location: '.ROOT.'id'.$id_user);
echo '<div class="levo"><a href="'.ROOT.'my/mail.php" class="levo_tuch">'.$diz -> icon('back.png').' '.language('Сообщения').'</a></div>';
}
break;
///обработка кнопок
case 'input_read':
$_SESSION['textrea_text']=$_POST['text'];
switch($_POST['submit']){
case language('Обновить'):
$_SESSION['textrea_text']=null;
header('Location: ?id='.$sid.'&act=read');
break;
case language('Очистить'):
$_SESSION['textrea_text']=null;
header('Location: ?id='.$sid.'&act=clear');
break;
case language('Отправить'):
$_SESSION['textrea_text']=$_POST['text'];
header('Location: ?act=new&id='.$id.'&message');
break;
case language('Жалоба'):
$mess=null;
$for = $db -> query("SELECT `time`,`oid`,`text`,`id`,`fid` FROM `mail` where `fid`='".$ya['id']."' and `dialog`='".$sid."' or `oid`='".$ya['id']."' and `dialog`='".$sid."'");
while ($assoc = $for -> fetch_assoc()) {
if(isset($_POST['mess'.$assoc['id']])){
$mess=$mess.$fuser->famname($assoc['oid'],0).' [id'.$assoc['oid'].'] ('.$func -> vremja($assoc['time']).')<br/>'.$assoc['text'].'<br/>';
}
if($assoc['oid']==$ya['id'])$id=$assoc['fid']; else $id=$assoc['oid'];
}
header('Location: ./report.php?id='.$id.'&sid='.$sid.'&do=mail&mess='.$mess);
break;
//удаляем выделенные сообщения
case language('Удалить'):
$for = $db -> query("SELECT `id` FROM `mail` where `fid`='".$ya['id']."' and `dialog`='".$sid."' or `oid`='".$ya['id']."' and `dialog`='".$sid."' ORDER BY `time` desc");
while ($assoc = $for -> fetch_assoc()) {
echo $_POST['mess'.$assoc['id']];
if(isset($_POST['mess'.$assoc['id']])){
$db -> query("DELETE FROM `mail` WHERE `id`='".$assoc['id']."'");
}
}
header('Location: ?act=read&id='.$sid);
break;
default: header('Location: ?');
}
break;
//Чтение входящих сообщений
case 'read':
$di = $db -> dbcount('COUNT(`id`)','dialogs','`id` = '.$id.' and `user` = '.$ya['id'].' or `id` = '.$id.' and `oid` = '.$ya['id'].'');
if($di>0){
$count = $db -> dbcount('COUNT(`id`)','mail','`dialog` = '.$id.' and `fid` = '.$ya['id'].' or `dialog` = '.$id.' and `oid` = '.$ya['id'].'');
$num = isset($ya['num']) ? $ya['num'] : 10;
$total = intval(($count - 1) / $num) + 1;
if (!isset($_GET['page']) || !is_numeric($_GET['page']) || $_GET['page'] < 1 )
{
$page = 1;
} elseif($_GET['page'] > $total)
{ $page = $total;
} else $page = (int)$_GET['page'];
$start = $page * $num - $num;
$d = $db -> query("SELECT `oid`,`user` FROM `dialogs` WHERE `id`='".$id."'")-> fetch_assoc();
if($d['oid']==$ya['id'])$clo=$d['user']; else $clo=$d['oid'];
$diz -> title($fuser->famname($clo,0));
echo '<div class="fon">'.$fuser->avatar($clo,36,36).' '.language('Диалог с').' '.$fuser->famname($clo).' '.$fuser->online($clo).'</div>';
echo '<div class="podmenu">
<form action="'.ROOT.'my/mail.php?act=input_read&id='.$clo.'&sid='.$id.'" method="post">
<div class="row">
<textarea id="mail" name="text" cols="'.$ya['width'].'" rows="'.$ya['height'].'">'.$_SESSION['textrea_text'].'</textarea><br/>';
if($db->settings('emoji')==true and $_COOKIE['version']=='web'){
?>
<html>
<div id="container"></div>
<script type="text/javascript">
$(document).ready(function() {
$("#mail").emojioneArea({
container: "#container",
hideSource: true,
});
});
</script>
</html>
<?
}
echo '</div>';
echo '<input name="submit" type="submit" value="'.language('Отправить').'"/>
<input name="submit" type="submit" value="'.language('Обновить').'"/>
<input name="submit" type="submit" value="'.language('Очистить').'"/>';
echo '</form></div>';
echo '<div class="fon" id="form_mess" style="display:none;">
<form action="'.ROOT.'my/mail.php?act=input_read&id='.$clo.'&sid='.$id.'" method="post">
'.language('С выделенными').'
<input name="submit" type="submit" value="'.language('Удалить').'"/>
<input name="submit" type="submit" value="'.language('Жалоба').'"/></div>';
if ($count > 0) {
$sql = $db -> query("SELECT * FROM `mail` WHERE `dialog`='".$id."' ORDER BY `time` desc LIMIT ".$start.",".$num);
while ($arr = $sql -> fetch_assoc()) {
if($arr['oid']==$ya['id']){
$user=$arr['fid'];
$ava=$arr['oid'];
$mail=$fuser->famname($ya['id']);
}else{
$user=$arr['oid'];
$ava=$arr['oid'];
$mail=$fuser->famname($user);
}
require_once (ROOT.'system/lib/emojiarea/include.php');
if($arr['read']=='no')$st='<span class="chet">('.language('не прочитано').')</span>'; else $st=null;
echo'<div class="fon"><table width="100%"><tr>
<td valign="top" onclick="checkbox(mess'.$arr['id'].')" align="center">'.$fuser->avatar($ava).'<br/>
<div class="checkbox">
<input class="check" type="checkbox" id="mess'.$arr['id'].'" name="mess'.$arr['id'].'" value="id="mess'.$arr['id'].'">
<label for="check2"></label></div></td>
<td width=100% style="padding-left:5px;">
'.$mail.' '.$st.' <br /><span class="date">'.$func -> vremja($arr['time'],$ya['gmt']).'</span><hr>
<div id="emoji_unicode'.$arr['id'].'">'.$func->tags($func->antipost($arr['text'])).'</div><br/>';
echo '</td></tr></table></div>';
if ($arr['fid'] == $ya['id']) {
$db -> query("UPDATE `mail` SET `read` = 'yes' WHERE `id` = '".$arr['id']."' and `fid`='".$ya['id']."' LIMIT 1");
}
if($db->settings('emoji')==true and $_COOKIE['version']=='web'){
?>
<script>
$("#emoji_unicode"+<?echo $arr['id'];?>).each(function() {
$(this).html(emojione.shortnameToImage($(this).html()));
});
</script>
<?
}
}
echo '</form>';
$act = ROOT.'my/mail.php?act=read&id='.$id;
echo $func -> pagenav($act,$page,$total);
}else echo '<div class="fon">'.language('Диалог пуст').'</div>';
}else header('location: '.ROOT.'my/mail.php');
echo '<div class="levo"><a href="./mail.php" class="levo_tuch">'.$diz -> icon('back.png').' '.language('Сообщения').'</a></div>';
break;
default:
$diz -> title('Личные сообщения');
echo '<div class="menu"><a href="/my/mail.php?act=new" class="menutuch">'.$diz -> icon('mail.png').' '.language('Новое сообщение').'</a></div>';
?>
<script>
var page = "<?echo $page?>";
function mail_index()
{
$.ajax({
type: "GET",
url: "/my/mail_ajax.php",
data: {page:page},
cache: false,
success: function(html){
$("#mail_index").html(html);
}
});
}
$(document).ready(function(){
mail_index();
setInterval('mail_index()',5000);
});
</script>
<span id="mail_index"></span>
<?
}
echo '<div class="levo"><a href="/my/" class="levo_tuch">'.$diz -> icon('back.png').' '.language('Мой кабинет').'</a></div>';
echo '<div class="levo"><a href="'.ROOT.'" class="levo_tuch">'.$diz -> icon('home.png').' '.language('На главную').'</a></div>';
#####Копирайт#######
$diz -> out($msg);
?>