<?php
session_start();
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;
$do = isset($_GET['do']) ? check($_GET['do']) : false;
$title->GetHeader();
$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
$array = DB::$dbs->query("SELECT * FROM forum_mess WHERE id = ? LIMIT 1", [$id]);
if ($array -> rowCount() == 0) {
header('location: /');
die();
}
$arr = $array -> fetch();
$raz = DB::$dbs->queryFetch("SELECT * FROM forum_razdel WHERE id = ? LIMIT 1", [$arr['rid']]);
$praz = DB::$dbs->queryFetch("SELECT * FROM forum_prazdel WHERE id = ? LIMIT 1", [$arr['prid']]);
$topic = DB::$dbs->queryFetch("SELECT * FROM forum_topic WHERE id = ? LIMIT 1", [$arr['tid']]);
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="/forum"style="text-decoration:none; color:white;"> Форум</a> :: Действие с сообщением</div></div></div>';
echo '<div class="list-group-item media"><a href="viewrazd.php?id='.$raz['id'].'"><i class="zmdi zmdi-comments"></i> '.$raz['name'].'</a> :: <a href="viewthem.php?id='.$praz['id'].'">'.$praz['name'].'</a> :: <a href="viewtopic.php?id='.$arr['id'].'">'.$arr['name'].'</a> :: <a href="viewtopic.php?id='.$topic['id'].'">'.$topic['name'].'</a> :: Действие с сообщением</div>';
switch($do) {
default:
header('location: /');
break;
/*
case 'nar':
if ($topic['block'] == 2) {
header('location: /');
die();
}
$user = DB::$dbs->queryFetch("SELECT * FROM blogger WHERE id = ? LIMIT 1", [$arr['user_id']]);
$title->SetTitle($topic['name'].' - Выписать нарушение');
if ($topic['type'] == 'closed') {
header('location: /');
die();
}
if ($arr['user_id'] == $b['id'] && $b['level'] < 1 && $b['level'] < user_inf($arr['user_id'], 'level')) {
header('location: /');
die();
}
$mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_mess WHERE tid = ?", [$topic['id']]);
if ($mess > 10) {
$pg = ceil($mess / 10);
$st = '?page='.$pg;
} else {
$st = '';
}
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="viewtopic.php?id='.$topic['id'].'"style="text-decoration:none; color:white;"> '.$topic['name'].'</a> :: Выписать нарушение </div></div></div>';
echo '<div class="list-group-item media"> <b>Автор:</b> '.Nick($arr['user_id']).'<br/><b>Текст на момент наказания:</b> '.$arr['text'].'<br/><a href="/rules">Ссылка на общие правила</a></div>';
if (isset($_POST['add'])) {
$form = ['text' => isset($_POST['text']) ? check($_POST['text']) : null, 'nar' => isset($_POST['nar']) ? check($_POST['nar']) : null, 'type' => isset($_POST['type']) ? abs((int)$_POST['type']) : null];
if (empty($form['text'])) {
err('Введите комментарий!');
} elseif (empty($form['type'])) {
err('Укажите тип!');
} elseif ($form['nar'] < 0) {
err('Укажите пункты правил!');
} else {
$tema = 'http://'.$_SERVER['HTTP_HOST'].'/forum/thema'.$topic['id'];
DB::$dbs->query("INSERT INTO nar SET user_id = ?, id_user = ?, text = ?, type = ?, time = ?, message = ?, nar = ?, tema= ?", [$arr['user_id'],$b['id'],$form['text'],$form['type'],time(),$arr['text'],$form['nar'],$tema]);
DB::$dbs->query("UPDATE `blogger` SET `gears` = `gears` - ? WHERE `id` = ?", [10,$arr['user_id']]);
jurnal($arr['user_id'],Nick($b['id']).' выписал вам [url=http://'.$_SERVER['HTTP_HOST'].'/info/expired.html?id='.$arr['user_id'].'][b]'.($form['type'] == 1 ? 'предупреждение':'нарушение').'[/b][/url]',5); // личная лента
lenta(Nick($b['id']).' выписал [url=http://'.$_SERVER['HTTP_HOST'].'/info/expired.html?id='.$arr['user_id'].'][b]'.($form['type'] == 1 ? 'предупреждение':'нарушение').'[/b][/url] для '.Nick($arr['user_id'])); // общая лента
header('Location: /forum/thema'.$topic['id'].$st);
die();
}
}
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i>Применение наказании </div></div></div>';
echo '<div class="list-group-item media"><form action="?do=nar&id='.$id.'" method="POST"><b>Ваш комментарий:</b><br/><textarea class="form-control" rows="3"name="text"></textarea><br/><input type="radio" name="type" value="1" checked="checked"/> Предупреждение<br/><input type="radio" name="type" value="2"/> Нарушение <br/><b>Нарушаемые пункты (* через запятую, если нет в списке - пишем 0):</b><br/> <input type="text" class="form-control" name="nar"/><br/><input type="submit" name="add" class="btn btn-primary" value="Применить"/></form></div>';
break;
*/
case 'quote':
if ($topic['block'] == 2) {
header('location: /');
die();
}
$raz = DB::$dbs->queryFetch("SELECT * FROM forum_razdel WHERE id = ? LIMIT 1", [$arr['rid']]);
$praz = DB::$dbs->queryFetch("SELECT * FROM forum_prazdel WHERE id = ? LIMIT 1", [$arr['prid']]);
$user = DB::$dbs->queryFetch("SELECT * FROM blogger WHERE id = ? LIMIT 1", [$arr['user_id']]);
$title->SetTitle($topic['name'].' - Цитируем');
if ($topic['type'] == 'closed') {
header('location: /');
die();
}
if ($arr['user_id'] == $b['id']) {
header('location: /');
die();
}
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="viewtopic.php?id='.$topic['id'].'"style="text-decoration:none; color:white;"> '.$topic['name'].'</a> :: Цитируем </div></div></div>';
$posting = $user['nick'].' ('.date('d.m.y в H:i', $arr['time']).') '.$arr['text'].'...';
echo '<div class="list-group-item media"><b>Цитируемый текст:</b><br/>'.$posting.'</div>';
$mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_mess WHERE tid = ?", [$topic['id']]);
if ($mess > 10) {
$pg = ceil($mess / 10);
$st = '?page='.$pg;
} else {
$st = '';
}
if (isset($_POST['add'])) {
$err = [];
$form = ['text' => isset($_POST['text']) ? check($_POST['text']) : null];
if (empty($form['text'])) {
$err[] = 'Введите сообщение!';
}
if (DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_mess WHERE text = ? AND tid = ?", [$form['text'],$topic['id']]) > 0) {
$err[] = 'Такое сообщение уже есть!';
}
$time = DB::$dbs->query("SELECT * FROM forum_mess WHERE user_id = ? ORDER BY time DESC", [$b['id']]);
while($t = $time -> fetch()) {
if ((time() - $t['time']) < 10) {
err('Пишите не чаще чем раз в 10 секунд!');
$title->GetMenu();
$title->GetFooter();
die();
}
}
if (empty($err)) {
$podpis = DB::$dbs -> query("SELECT * FROM `forum_podpis` WHERE `tid`=? AND `user_id` != ? order by id", [$topic['id'],$b['id']]);
if ($podpis -> rowCount() != 0){
$podp = DB::$dbs -> query("SELECT * FROM `forum_podpis` WHERE `tid` = ? order by id", [$topic['id']]);
while($pod = $podp -> fetch()) {
$mes = Nick($b['id']).' оставил сообщение в теме <a href="/forum/thema'.$topic['id'].'">'.$topic['name'].'</a>';
jurnal($pod['user_id'],$mes,2);
}
}
DB::$dbs->query("INSERT INTO forum_mess SET text = ?, user_id = ?, time = ?, rid = ?, prid = ?, tid = ?, cit = ?", [$form['text'],$b['id'],time(),$raz['id'],$praz['id'],$topic['id'],$posting]);
$m = DB::$dbs->lastInsertId();
DB::$dbs->query("UPDATE forum_topic SET last = ? WHERE id = ?", [time(),$topic['id']]);
DB::$dbs->query("UPDATE `blogger` SET `gears` = `gears` + ? WHERE id = ?", [1,$b['id']]);
DB::$dbs->query("UPDATE `blogger` SET `post` = `post` + ? WHERE id = ?", [1,$b['id']]);
if(empty($_SESSION['fpage'])){
$_SESSION['fpage']=1;
}
$mess = 'Пользователь [b]'.$b['nick'].'[/b] процитировал ваше сообщение '.$arr['text'].' в теме  [url=http://'.$_SERVER['HTTP_HOST'].'/forum/viewtopic.php?id='.$topic['id'].'&page='.$_SESSION['fpage'].']'.$topic['name'].'[/url]';
jurnal($arr['user_id'],$mess,2);
if ($_POST['addfile'] == 1) {
header('location: ?do=addfile&id='.$m);
} else {
header('location: /forum/thema'.$topic['id'].$st);
die();
}
} else {
echo '<div class="alert alert-danger" role="alert">';
foreach($err as $error) {
echo '<b>'.$error.'</b><br/>';
}
echo '</div>';
}
}
echo '<div class="list-group-item media"><form name="form" method="post" action="?do=quote&id='.$id.'" method="POST" enctype="multipart/form-data">Сообщение:<br/><br/>';
quickpaste('text');
quickpanel();
echo'<br/><br/><textarea class="form-control" rows="8" name="text"></textarea><br/><input type="checkbox" name="addfile" value="1"/> Прикрепить файл<br/><input type="submit" class="btn btn-primary" name="add" value="Написать"/></div></form>';
break;
case 'addfile':
$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
$array = DB::$dbs->query("SELECT * FROM forum_mess WHERE id = ?", [$id]);
if ($array -> rowCount() == 0) {
header('location: /');
die();
}
$arr = $array -> fetch();
if ($arr['del'] == 1 && $b['id'] != $arr['user_id']) {
header('location: /');
die();
}
$topic = DB::$dbs->queryFetch("SELECT * FROM forum_topic WHERE id = ?", [$arr['tid']]);
if ($topic['block'] == 2) {
header('location: /');
die();
}
$user = DB::$dbs->queryFetch("SELECT * FROM blogger WHERE id = ?", [$arr['user_id']]);
$title->SetTitle('Форум - '.$raz['name'].' - '.$praz['name'].' - '.$topic['name'].' - Прикрепить файл');
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="viewtopic.php?id='.$topic['id'].'"style="text-decoration:none; color:white;"> '.$topic['name'].'</a> :: Прикрепить файл </div></div></div>';
$mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_mess WHERE tid = ?", [$topic['id']]);
if ($mess > 10) {
$pg = ceil($mess / 10);
$st = '?page='.$pg;
} else {
$st = '';
}
$limit_size = 5;
// upload files
if (isset($_GET['upload'])) {
for($i=0;$i<count($_FILES['userfile']['name']);$i++){
$namefile = retrans($_FILES['userfile']['name'][$i]);
$ext = strtolower(strrchr($_FILES['userfile']['name'][$i], '.'));
$newpath = 'files/forum/';
$fname = strtolower($_FILES['userfile']['name'][$i]);
$fnames = $_FILES['userfile']['name'][$i];
$fsize = $_FILES['userfile']['size'][$i];
$ext2 = explode(".", $fnames);
$ext_file =['.exe','.msi','.jar','.jad','.sis','.sisx','.txt','.pdf','.doc','.rtf','.djvu','.xls','.jpg','.jpeg','.gif','.png','.bmp','.wmf','.zip','.rar','.7z','.tar','.gz','.3gp','.avi','.flv','.mpeg','.mp4','.mp3','.amr'];
if ($fsize >= 1024 * 5 * 1024) {
err('Вес файла превышает <b>5</b> мб.');
DB::$dbs->query("DELETE FROM forum_mess WHERE id = ?", [$id]);
}
elseif (count($ext2) != 2) {
err('Запрещены файлы не имеющие имени, расширения, или с двойным расширением.');
DB::$dbs->query("DELETE FROM forum_mess WHERE id = ?", [$id]);
}
elseif (mb_strlen($fname) > 50) {
err('Длина названия файла не должна превышать 50 символов!');
DB::$dbs->query("DELETE FROM forum_mess WHERE id = ?", [$id]);
}
elseif (!preg_match('#^[a-z0-9.()+_-]#', $fname)) {
err('В названии файла "<b>' . $fname . '</b>" присутствуют недопустимые символы. Разрешены только латинские символы, цифры и некоторые знаки ( .()+_- )<br />Запрещены пробелы.');
DB::$dbs->query("DELETE FROM forum_mess WHERE id = ?", [$id]);
}
elseif (preg_match('/(\.php|\.pl|\.htaccess)/i', $fname) || !in_array($ext, $ext_file)) {
err('Запрещенный формат файла!');
DB::$dbs->query("DELETE FROM forum_mess WHERE id = ?", [$id]);
} else {
$upfile = homeurl.'_'.mt_rand(10000,99999).'_'.$namefile;
$path = '../files/forum/'.$upfile;
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $path)) {
DB::$dbs->query("INSERT INTO forum_files SET tid = ?, files = ?, mid = ?, size = ?", [$topic['id'],$upfile,$id,$fsize]);
header('location: /forum/thema'.$topic['id'].$st);
die();
} else err('Закачка файла '.$namefile.' окончилась неудачно.');
}
}
}
echo '<div class="list-group-item media"><form action="?do=addfile&id='.$id.'&upload" method="POST" enctype="multipart/form-data">Максимальный размер каждого файла <b>'.$limit_size.' mb.</b><br/>Файл:<br/><input type="file" class="form-control"name="userfile[]"/><br/><input type="submit" class="btn btn-primary" value="Прикрепить"/></div></form>';
break;
case 'editp':
if ($topic['block'] == 2) {
header('location: /');
die();
}
$user = DB::$dbs->queryFetch("SELECT * FROM blogger WHERE id = ? LIMIT 1", [$arr['user_id']]);
$title->SetTitle($topic['name'].' - Изменить пост');
if ($arr['user_id'] != $b['id'] && $b['level'] == 0 && $b['level'] < user_inf($arr['user_id'], 'level')) {
header('location: /');
die();
}
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="viewtopic.php?id='.$topic['id'].'"style="text-decoration:none; color:white;"> '.$topic['name'].'</a> :: Изменить пост </div></div></div>';
$mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_mess WHERE tid = ?", [$topic['id']]);
if ($mess > 10) {
$pg = ceil($mess / 10);
$st = '?page='.$pg;
} else {
$st = '';
}
if (isset($_POST['add'])) {
$err = [];
$form = ['text' => isset($_POST['text']) ? check($_POST['text']) : null];
if (empty($form['text'])) {
$err[] = 'Введите сообщение!';
}
if (empty($err)) {
DB::$dbs->query("UPDATE `forum_mess` SET `text` = ?, `time_edit` = ?, `count_edit` = `count_edit` + ?, `who_edit` = ? WHERE `id` = ? LIMIT 1", [$form['text'],time(),1,$b['id'],$id]);
if ($_POST['addfile'] == 1) {
header('location: ?do=addfile&id='.$id);
} else {
header('location: /forum/thema'.$topic['id'].$st);
die();
}
} else {
echo '<div class="alert alert-danger" role="alert">';
foreach($err as $error) {
echo '<b>'.$error.'</b><br/>';
}
echo '</div>';
}
}
echo '<div class="list-group-item media"><form action="?do=editp&id='.$id.'" method="POST" enctype="multipart/form-data">Сообщение:<br/><br/>';
quickpaste('text');
quickpanel();
echo'<br/><br/><textarea class="form-control" rows="8" name="text">'.$arr['text'].'</textarea><br/><input type="checkbox" name="addfile" value="1"/> Прикрепить файл<br/> <input type="submit" class="btn btn-primary" name="add" value="Изменить"/></form></div>';
break;
case 'del_post':
$title->SetTitle($topic['name'].' - Удалить пост');
if ($b['level'] < 1) {
header('location: /');
die();
}
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="viewtopic.php?id='.$topic['id'].'"style="text-decoration:none; color:white;"> '.$topic['name'].'</a> :: Удалить пост </div></div></div>';
$mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_mess WHERE tid = ?", [$topic['id']]);
if ($mess > 10) {
$pg = ceil($mess / 10);
$st = 'page='.$pg;
} else {
$st = '';
}
if (isset($_GET['del'])) {
if ($topic['type'] == 'closed') {
header('location: /');
die();
}
DB::$dbs->query("UPDATE forum_mess SET del = ?, who_del = ? WHERE id = ? LIMIT 1", [1,$b['id'],$id]);
header('location: /forum/thema'.$topic['id'].'?'.$st);
}
echo '<div class="list-group-item media">Действительно удалить?<br/><a href="?do=del_post&id='.$id.'&del"class="btn btn-primary"> Да</a> :: <a href="/forum/thema'.$topic['id'].'?'.$st.'"class="btn btn-primary">Нет</a></div>';
break;
case 'vost_post':
$title->SetTitle($topic['name'].' - Восстановить пост');
if ($b['level'] < 4) {
header('location: /');
die();
}
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="viewtopic.php?id='.$topic['id'].'"style="text-decoration:none; color:white;"> '.$topic['name'].'</a> :: Восстановить пост </div></div></div>';
$mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_mess WHERE tid = ?", [$topic['id']]);
if ($mess > 10) {
$pg = ceil($mess / 10);
$st = 'page='.$pg;
} else {
$st = '';
}
if (isset($_GET['del'])) {
if ($topic['type'] == 'closed') {
header('location: /');
die();
}
DB::$dbs->query("UPDATE forum_mess SET del = ?, who_del = ? WHERE id = ? LIMIT 1", [2,$b['id'],$id]);
header('location: /forum/thema'.$topic['id'].'?'.$st);
}
echo '<div class="list-group-item media">Действительно восстановить?<br/><a href="?do=vost_post&id='.$id.'&del"class="btn btn-primary"> Да</a> :: <a href="/forum/thema'.$topic['id'].'?'.$st.'"class="btn btn-primary">Нет</a></div>';
break;
case 'best':
$title->SetTitle($topic['name'].' - Лучший ответ');
$mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_mess WHERE tid = ?", array($topic['id']));
if ($mess > 10) {
$pg = ceil($mess / 10);
$st = '?page='.$pg;
} else {
$st = '';
}
if ($topic['type'] == 'closed') {
header('location: /forum/thema'.$topic['id'].$st);
die();
}
if ($b['id'] == $topic['user_id'] && $topic['otvet_2'] != $arr['id'] && $topic['otvet'] == 0 && $b['id'] != $arr['user_id']) {
DB::$dbs->query("UPDATE `forum_topic` SET `otvet` = ? WHERE `id` = ?",[$id,$topic['id']]);
DB::$dbs->query("UPDATE `blogger` SET `gears` = `gears` + ? WHERE `id` = ? LIMIT 1", [1,$arr['user_id']]);
jurnal(Nick($b['id']).' отметил Ваш пост "'.$arr['text'].'" как Лучший!',$arr['user_id'],4);
header('location: /forum/thema'.$topic['id'].$st);
die();
} else {
header('location: /forum/thema'.$topic['id'].$st);
die();
}
break;
case 'worst':
$title->SetTitle(''.$topic['name'].' - Худший ответ');
$mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_mess WHERE tid = ?", [$topic['id']]);
if ($mess > 10) {
$pg = ceil($mess / 10);
$st = '?page='.$pg;
} else {
$st = '';
}
if ($topic['type'] == 'closed') {
header('location: /forum/thema'.$topic['id'].$st);
die();
}
if ($b['id'] == $topic['user_id'] && $topic['otvet_2']==0 && $topic['otvet'] != $arr['id'] && $b['id'] != $arr['user_id']){
DB::$dbs->query("UPDATE forum_topic SET otvet_2 = ? WHERE id = ? LIMIT 1", [$id,$topic['id']]);
DB::$dbs->query("UPDATE `blogger` SET `gears` = `gears` - ? WHERE `id` = ? LIMIT 1", [1,$arr['user_id']]);
jurnal(Nick($b['id']).' отметил Ваш пост "'.$arr['text'].'" как Худший!',$arr['user_id'],4);
header('location: /forum/thema'.$topic['id'].$st);
die();
} else {
header('location: /forum/thema'.$topic['id'].$st);
die();
}
break;
case 'complaint':
$title->SetTitle($topic['name'].' - Жалоба на сообщение');
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="viewtopic.php?id='.$topic['id'].'"style="text-decoration:none; color:white;"> '.$topic['name'].'</a> :: Жалоба на сообщение </div></div></div>';
$mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM forum_mess WHERE tid = ?", [$topic['id']]);
if ($mess > 10) {
$pg = ceil($mess / 10);
$st = '?page='.$pg;
} else {
$st = '';
}
if ($arr['user_id'] == $b['id']) {
header('location: /forum/thema'.$arr['tid'].$st);
die();
}
if (isset($_POST['send'])) {
$komm = check($_POST['komm']);
if (empty($komm)) {
err('Введите комментарий!');
} elseif (DB::$dbs->querySingle("SELECT COUNT(*) FROM `complaint` WHERE `id_post` = ? AND `user_id` = ?", [$id,$b['id']])>0) {
err('Вы уже жаловались на этот пост!');
} else {
$tema = 'http://'.homeurl.'/forum/thema'.$topic['id'].$st;
DB::$dbs->query("INSERT INTO `complaint` SET `id_user` = ?, `user_id` = ?, `text` = ?, `komm` = ?, `id_post` = ?, `time` = ?, `read` = ?, `type` = ?, `tema` = ?", [$arr['user_id'],$b['id'],$arr['text'],$komm,$id,time(),1,1,$tema]);
echo '<div class="alert alert-success"role="alert">Ваша жалоба отправлена модераторам на рассмотрение!</div>';
$title->GetMenu();
$title->GetFooter();
die();
}
}
echo '<div class="list-group-item media"><form action="?do=complaint&id='.$id.'" method="POST">Комментарий:<br/><textarea name="komm"class="form-control" rows="8"></textarea><br/><input type="submit" class="btn btn-primary" name="send" value="Отправить"/></form></div>';
break;
}
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-format-list-bulleted"></i>  <a href="/rules"style="text-decoration:none; color:white;">Правила</a> | <a href="/bbcodes"style="text-decoration:none; color:white;"> Справка BBcode</a> | <a href="/smiles"style="text-decoration:none; color:white;">Все смайлы</a> | <a href="search"style="text-decoration:none; color:white;">Поиск</a></div></div></div>'; 
$title->GetMenu();
$title->GetFooter();
?>