<?php
require_once('classes/body.class.php');
require_once('classes/db.class.php');
require_once('classes/system.class.php');
$title= new Body;
$title->SetTitle(homeurl.' - Мои диалоги');
$title->GetHeader();
if ($b == false) {
header('location: /');
die();
}
$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
$array = DB::$dbs->query("SELECT `id` FROM `letters` WHERE `idwho` = ? AND `who` = ? OR `idwho` = ? AND `who` = ?", [$b['id'],$id,$id,$b['id']]);
if ($array->rowCount() == FALSE) {
header('Location: /');
die();
}
$skem = user_inf($id, 'name').'  '.user_inf($id, 'family');
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="/messages"style="text-decoration:none; color:white;"> Мои диалоги</a> :: ' . $skem . '</div></div></div>';
if (isset($_GET['delign'])) {
$row = DB::$dbs->queryFetch("SELECT * FROM ignor WHERE id_user = ? LIMIT 1", [$id]);
jurnal($id,Nick($row['user_id']).' убрал Вас с игнор-листа.',5);
DB::$dbs->query("DELETE FROM ignor WHERE id_user = ?", [$id]);
header('location: ?do=view&id='.$id);
die();
}
if (isset($_GET['ign'])) {
$row = DB::$dbs->queryFetch("SELECT * FROM blogger WHERE id = ? LIMIT 1", [$id]);
if ($row == 0) {
err('Такого мастера нет!');
} elseif ($row['id'] == $b['id']) {
err('Нельзя себя добавлять.');
} elseif (DB::$dbs->querySingle("SELECT COUNT(id) FROM ignor WHERE user_id = ? AND id_user = ?", [$b['id'],$row['id']]) > 0) {
header('Location: ?do=view&id='.$id);
} else {
DB::$dbs->query("INSERT INTO ignor SET user_id = ?, id_user = ?", [$b['id'],$row['id']]);
$mess = Nick($b['id']).' добавил Вас в игнор-лист.';
jurnal($row['id'],$mess,5);
echo '<div class="alert alert-success" role="alert">Успешно добавлено!</div>';
}
}
$all = DB::$dbs->querySingle("SELECT COUNT(id) FROM `letters` WHERE `idwho` = ? AND `who` = ? OR `idwho` = ? AND `who` = ?", [$b['id'],$id,$id,$b['id']]);

$num = 10;
$k_page = k_page($all, $num);
$page = page($k_page);
$start = $num*$page-$num;
$read = DB::$dbs->query("SELECT * FROM `letters` WHERE `idwho` = ? AND `who` = ? OR `idwho` = ? AND `who` = ? ORDER BY `id` DESC LIMIT $start,$num", [$b['id'],$id,$id,$b['id']]);
if (DB::$dbs->querySingle("SELECT COUNT(id) FROM ignor WHERE user_id = ? AND id_user = ?", [$id,$b['id']]) == 0) {
if (isset($_POST['send'])) {
$text = check($_POST['text']);
$files = ['.gif', '.jpg', '.jpeg', '.png', '.zip', '.rar', '.gz', '.gzip', '.tar', '.txt'];
$ext = strtolower(strrchr($_FILES['file']['name'], '.'));
$fnames = $_FILES['file']['name'];
if (DB::$dbs->querySingle("SELECT COUNT(id) FROM letters WHERE idwho = ? AND text = ?", [$id,$text])>0) {
$err = 'Вы уже писали это!';
}
$time = DB::$dbs->query("SELECT * FROM letters WHERE who = ? ORDER BY data DESC", [$b['id']]);
while($t = $time -> fetch()) {
if ((time() - $t['data']) < 10) {
err('Пишите не чаще чем раз в 10 секунд!');
$title->GetMenu();
$title->GetFooter();
die();
}
}
if ($id == 0) {
$err = 'Получатель не найден!';
}
if (!empty($fnames) && preg_match('/(\.php|\.pl|\.htaccess)/i', $fnames) || !empty($fnames) && !in_array($ext, $files)) {
$err = 'Запрещенный формат файла!';
}
if (!empty($fnames) && $_FILES['file']['size'] > 1024 * 10 * 1024) {
$err = 'Большой размер файла!';
}
if (empty($text)) {
$err = 'Пустое поле сообщения!';
}
if (empty($err)) {
if (!empty($fnames))
{
$path = '/files/mail/'.homeurl.'_' . mt_rand(100000, 999999) . $ext;
copy($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/'.$path);
}
else {
$path = '';
}
DB::$dbs->query("INSERT INTO `letters` SET `id` = ?, `who` = ?, `idwho` = ?, `text` = ?, `data` = ?, `read` = ?, `file` = ?", [0,$b['id'],$id,$text,time(),0,$path]);
header('Location: ?id=' . $id);
die();
}
else {
echo err($err);
}
}
}
$ign = DB::$dbs->querySingle("SELECT COUNT(id) FROM ignor WHERE user_id = ? AND id_user = ?", [$b['id'],$id]);
$ig = DB::$dbs->querySingle("SELECT COUNT(id) FROM ignor WHERE user_id = ? AND id_user = ?", [$id,$b['id']]);
if ($all != false) {
echo ($ign > 0 ? err(Nick($id).' в вашем игнор листе.') : NULL);
if (DB::$dbs->querySingle("SELECT COUNT(id) FROM ignor WHERE user_id = ? AND id_user = ?", [$id,$b['id']]) == 0) {
echo '<div class="list-group-item media"><form name="form" ENCTYPE="multipart/form-data" method="post" action="view_mess.php?id='.$id.'"></br>';
quickpaste('text');
quickpanel();
echo '</br></br><textarea name="text"class="form-control" rows="8"></textarea><br/>Прикрепить файл: (*max: 10 mb.)<br/>
<input name="file" class="form-control"type="file"/><br/><input type="submit" class="btn btn-primary btn-block" name="send" value="Отправить"/></form></div>';
} else err(Nick($id).' добавил Вас в игнор лист!');
if ($ign == 0) {
echo '<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><a href="?id='.$id.'&ign"style="text-decoration:none; color:white;"><i class="zmdi zmdi-shuffle"></i> В игнор</a></div></div></div>';
} else {
echo '<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><a href="?id='.$id.'&delign"style="text-decoration:none; color:white;"><i class="zmdi zmdi-shuffle"></i> Убрать с игнора</a></div></div></div>';
}
while($ot = $read->fetch()) {
$vfile = $_SERVER['DOCUMENT_ROOT'].$ot['file'];
$files = strtolower(strrchr($ot['file'], '.'));
$your = DB::$dbs->queryFetch("SELECT `id`, `read` FROM `letters` WHERE
`idwho` = ? AND
`who` = ? AND
`mod` = ? AND
`id` = ?", [$ot['who'],$b['id'],'i',($ot['id']-1)]);
$nicks = user_inf($ot['who'], 'name').'  '.user_inf($ot['who'], 'family');

if ($ot['read'] == 0) $NoRead = '<div class="alert alert-danger" role="alert"> ' . text($ot['text']) . ' <br/>' .($ot['file'] != '' ? '<b>Прикрепленный файл</b><br/><a href="'.$ot['file'].'"style="text-decoration:none; color:white;">'.mb_substr($ot['file'],12,27, 'UTF-8').' ('.get_size(filesize($vfile)).')</a><br/>' : '') . '';
else $NoRead = '<div class="list-group-item media"> ' . text($ot['text']) . ' <br/>' .($ot['file'] != '' ? '<b>Прикрепленный файл</b><br/><a href="'.$ot['file'].'">'.mb_substr($ot['file'],12,27, 'UTF-8').' ('.get_size(filesize($vfile)).')</a><br/>' : '') . '';
echo'<div class="list-group lg-alt">';
$ava = (!empty(user_inf($ot['who'], 'ava')) ? '<div class="pull-left"><img class="img-avatar" src="/'.user_inf($ot['who'], 'ava').'" width="45" height="45" alt="not found"/></div>':'<div class="pull-left"><img class="img-avatar" src="/assets/img/4.jpg" alt="not found"/></div>');
$online = (user_inf($ot['who'], 'last')>time()-3600 ? '<img src="/assets/images/on.gif" alt="*"/>':'');
echo'<a class="list-group-item media" href="/users/'.user_inf($ot['who'], 'id').'"> '.$ava . ' '.$nicks.'  ' . $online . '  </br>Дата отправки: ' . vr($ot['data'], 0) . '</div></a>' . $NoRead . '</div>';
}
} else err('История переписки пуста!');
DB::$dbs-> query("UPDATE `letters` SET `read` = ? WHERE `idwho` = ? AND `who` = ?", [1,$b['id'],$id]);
if ($k_page>1) {
str('?id='.$id.'&', $k_page,$page);
}
$title->GetMenu();
$title->GetFooter();
?>