Вход Регистрация
Файл: forum.php
Строк: 838
<?

include_once 'system/sys.php';
include 
'system/funcs.php';
if(!
$cms->us['id']){
verh('Oops...','Форум закрыт для гостей, авторизируйтесь.'); niz();
exit;
}
$mod=htmlspecialchars($_GET['mod']);
switch(
$mod){
# Главная
default: case 'index':
verh('Форум','<a href="/index.php" style="color: #fff;">Главная</a> | Форум');
echo 
'<div class="list1"><img src="/design/tema.png" alt="*" align="middle"/>Темы: <a href="/forum?mod=stat&my_thems">Мои</a> <small>|</small> <a href="/forum?mod=stat&new_thems">Новые</a> <small>|</small> <a href="/forum?mod=stat&obn_thems">Обновлённые</a><br/>
<img src="/design/npost.png" alt="*" align="middle"/>Посты: <a href="/posts'
.$cms->us['id'].'/page1">Мои</a> <small>|</small> <a href="/forum?mod=stat&new_posts">Новые</a></div>';
$razds DB::$dbs->query("SELECT * FROM `forum_razd` order by `id`");
while(
$razd $razds -> fetch()){
echo 
'<div class="menu2"><img src="/design/inet.png" alt="*" align="middle"/> <a href="/forum/razd'.$razd['id'].'" style="text-decoration:none; color:white;"><b>'.$razd['name'].'</b></a> ('.DB::$dbs->querySingle("select count(id) from `forum_thema` where `razd`=? ".($cms->us['level']>0?NULL:' and `del`='0'')."",array($razd['id'])).'/'.DB::$dbs->querySingle("select count(id) from `forum_post` where `razd`=? ".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($razd['id'])).')</div>';
if(
DB::$dbs->querySingle("select count(id) from `forum_podrazd` where `razd`=?",array($razd['id'])) > 0){
$podrazds DB::$dbs->query("SELECT * FROM `forum_podrazd` where (`razd`=?) order by `id`",array($razd['id']));
echo 
'<div class="navg">';
while(
$podrazd $podrazds->fetch()){
echo 
'<img src="/design/categ.png" alt="*" align="middle"/><a href="/forum/'.$razd['id'].'/'.$podrazd['id'].'">'.$podrazd['name'].'</a> ('.DB::$dbs->querySingle("select count(id) from `forum_thema` where `razd`=? and `podrazd`=? ".($cms->us['level']>0?NULL:' and `del`='0'')."",array($razd['id'],$podrazd['id'])).'/'.DB::$dbs->querySingle("select count(id) from `forum_post` where `razd`=? and `podrazd`=? ".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($razd['id'],$podrazd['id'])).')<br>';
}
echo 
'</div>';

if(
DB::$dbs->querySingle("select count(`id`) from `forum_thema` where `razd`=?",array($razd['id'])) > 0){

$lt DB::$dbs->queryFetch("SELECT * from `forum_thema` where `razd` = ? order by `last` limit 1",array($razd['id']));
$lt_podrazd DB::$dbs->queryFetch("SELECT * from `forum_podrazd` where `id` = ?",array($lt['podrazd']));
echo 
'<div class="list1"><small>Подраздел: <a href="/forum/'.$lt['razd'].'/'.$lt['podrazd'].'">'.$lt_podrazd['name'].'</a><br><img src="/design/'.($lt['type'] == 'prikrep':($lt['type'] == 'closed':'the')).'.png" alt="*"/> <a href="/forum/thema'.$lt['id'].'">'.$lt['name'].'</a> ('.DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ? ".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($lt['id'])).') <a href="/forum/thema'.$lt['id'].'/page'.ceil(DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ? ".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($lt['id']))/10).'">></a><br>'.$func->uNick($lt['author']).'/'.$func->uNick($lt['last_us']).' ('.t($lt['time']).')</small></div>';
}
}else echo 
'<div class="navg">Подразделов нет!</div>';
echo 
'</div>';
}
echo 
'<div class="menu2"><img src="/design/alll.png" alt="*" align="middle"/> <a href="/all/rulls.php?all" style="text-decoration:none; color:white;">Правила</a> | <img src="/design/emoc.png" alt="*" align="middle"/> <a href="/all/smiles_r.php" style="text-decoration:none; color:white;">Смайлы</a> | <img src="/design/cod.png" alt="*" align="middle"/> <a href="/all/bb.php" style="text-decoration:none; color:white;">ББ коды</a> | <img src="/design/usear.png" alt="*" align="middle"/> <a href="/fsearch.php" style="text-decoration:none; color:white;">Поиск</a></div>';
break;
# Раздел
case 'razd':
$id=$func->num($_GET['id']);
if(!
$id){
header('location:/forum');
exit;
}
$razd DB::$dbs->queryFetch("SELECT * FROM `forum_razd` where `id` = ?",array($id));
verh('Раздел '.$razd['name'],'<a href="/forum" style="color: #fff;">Форум</a> | '.$razd['name']);
if(
DB::$dbs->querySingle("select count(id) from `forum_podrazd` where `razd` = ? ",array($razd['id']))==0){ echo '<div class="list1">Подразделов нет!</div>'; }else{
$podrazds DB::$dbs->query("SELECT * from `forum_podrazd` where `razd` = ?",array($razd['id']));
while(
$podrazd $podrazds->fetch()){
$lt DB::$dbs->queryFetch("SELECT * from `forum_thema` where `razd` = ? and `podrazd` = ? ".($cms->us['level']>0?NULL:' and `del`='0'')." order by `last` limit 1",array($razd['id'],$podrazd['id']));
echo 
'<div class="menu2"><img src="/design/categ.png" alt="*" align="middle"/><a href="/forum/'.$razd['id'].'/'.$podrazd['id'].'" style="text-decoration:none; color:white;">'.$podrazd['name'].'</a> ('.DB::$dbs->querySingle("select count(id) from `forum_thema` where `razd`=? and `podrazd`=?",array($razd['id'],$podrazd['id'])).'/'.DB::$dbs->querySingle("select count(id) from `forum_post` where `razd`=? and `podrazd`=?".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($razd['id'],$podrazd['id'])).')</div>';
if(!empty(
$lt['id'])){
echo 
'<div class="navg"><img src="/design/'.($lt['top'] == 'prikrep':($lt['type'] == 'closed':'the')).'.png" alt="*"/> <a href="/forum/thema'.$lt['id'].'">'.$lt['name'].'</a> ('.DB::$dbs->querySingle("select count(id) from `forum_post` where `razd`=? and `podrazd`=? and `thema` = ? ".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($razd['id'],$podrazd['id'],$lt['id'])).') <a href="/forum/thema'.$lt['id'].'/page'.ceil(DB::$dbs->querySingle("select count(id) from `forum_post` where `razd`=? and `podrazd`=? and `thema` = ?".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($razd['id'],$podrazd['id'],$lt['id']))/10).'">></a><br>'.$func->uNick($lt['author']).'/'.$func->uNick($lt['last_us']).' ('.t($lt['last']).')</div>';
}
}
}
break;
# Подраздел
case 'podrazd':
$id=$func->num($_GET['id']);
if(!
$id){
header('location:/forum');
exit;
}
$podrazd DB::$dbs->queryFetch("SELECT * FROM `forum_podrazd` where `id` = ?",array($id));
$razd DB::$dbs->queryFetch("SELECT * FROM `forum_razd` where `id` = ?",array($podrazd['razd']));
if(empty(
$razd['id']) or empty($podrazd['id'])){
header('location:/');
exit;
}
verh('Подраздел '.$podrazd['name'],'<a href="/forum" style="color: #fff;">Форум</a> | <a href="/forum/razd'.$razd['id'].'" style="color: #fff;">'.$razd['name'].'</a> | '.$podrazd['name'].'');
echo 
'<div class="menu2"><img src="/design/nt.png" alt="*" align="middle"/> <a href="/forum/'.$razd['id'].'/'.$podrazd['id'].'?nt" style="text-decoration:none; color:white;">Новая тема</a></div>';
# Новая тема
if(isSet($_GET['nt'])){
if(isSet(
$_GET['add'])){
$name secure($_POST['name']);
$text secure($_POST['text']);
if(empty(
$name)){ echo '<div class="list1">Недопустимая длина названия темы!</div>'; }elseif(empty($text)){ echo '<div class="list1">Слишком короткая длина текста!</div>'; }elseif(DB::$dbs->querySingle("SELECT count(id) from `forum_thema` where `author` = ? and `time` > ?",array($cms->us['id'],time()-(60*15))) != 0){
echo 
'<div class="list1">Вы не можете создавать темы так часто!</div>';
}else{
DB::$dbs->query("INSERT INTO `forum_thema` set `razd` = ?,`podrazd` = ?,`name` = ?,`author` = ?,`time` = ?,`last` = ?,`last_us` = ?",array($razd['id'],$podrazd['id'],$name,$cms->us['id'],time(),time(),$cms->us['id']));
$id DB::$dbs->lastInsertId();
DB::$dbs->query("INSERT INTO `forum_post` (`razd`,`podrazd`,`thema`,`us`,`text`,`time`) values (?,?,?,?,?,?) ",array($razd['id'],$podrazd['id'],$id,$cms->us['id'],$text,time()));
$podpis $func->num($_POST['podpis']);
if(
$podpis == 1){ DB::$dbs->query("insert into `forum_podp` (`thema`,`us`) values (?,?)",array($id,$cms->us['id'])); }

header('location: /forum/thema'.$id);

}}else{
echo 
'<form action="/forum/'.$razd['id'].'/'.$podrazd['id'].'?nt&add" method="post"><div class="list1">
Тема:<br/><input type="text" name="name"/><br>
Текст:<br><textarea name="text" rows="10"></textarea><br>
<input type="radio" value="1" name="podpis"/>Оповещать о оставленных сообщениях<br/>
Ознакомьтесь с <a href="/forum/rulls'
.$podrazd['id'].'">правилами</a> п.д!<br/><input type="submit" value="Добавить"/></form></div>';
}
}else{
$posts DB::$dbs->querySingle("SELECT count(id) from `forum_thema` where `razd` = ? and `podrazd` = ? ".($cms->us['level']>0?NULL:' and `del`='0'')."",array($razd['id'],$podrazd['id']));
$num 10;
if(
$posts==0){
echo
'<div class="lst">Тем нет!</div>';
}else{
$total intval(($posts 1) / $num) + 1;
$page abs(intval($_GET['page']));
if(empty(
$page) or $page 0$page 1;
if(
$page $total$page $total;
$start $page $num $num;
$themes DB::$dbs->query("SELECT * from `forum_thema` where `razd` = ? and `podrazd` = ? ".($cms->us['level']>0?NULL:' and `del`='0'')." order by `top` desc,`id` desc limit $start,$num",array($razd['id'],$podrazd['id']));
while(
$thema $themes->fetch()){
echo 
'<div class="navg"><img src="/design/'.($thema['top'] == 'prikrep':($thema['type'] == 'closed':'the')).'.png" alt="*"/> <a href="/forum/thema'.$thema['id'].'">'.$thema['name'].'</a> ('.DB::$dbs->querySingle("select count(id) from `forum_post` where `razd`=? and `podrazd`=? and `thema` = ? ".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($razd['id'],$podrazd['id'],$thema['id'])).') <a href="/forum/thema'.$thema['id'].'/page'.ceil(DB::$dbs->querySingle("select count(id) from `forum_post` where `razd`=? and `podrazd`=? and `thema` = ? ".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($razd['id'],$podrazd['id'],$thema['id']))/10).'">></a><br/>';
$files DB::$dbs->querySingle("SELECT count(id) from `forum_file` where `thema` = ? ",array($thema['id']));
if(
$files>0) echo '<img src="/images/page_white_get.png" alt="*" align="middle"/> Файлов: <a href="/forum/files'.$thema['id'].'">'.$files.'</a><br/>';
echo 
$func->uNick($thema['author']).'/'.$func->uNick($thema['last_us']).' ('.t($thema['last']).')</div>';
}
echo 
'<div class="lst">';
$func->page('/forum/'.$razd['id'].'/'.$podrazd['id'].'?');
echo 
'</div>';
}
}
echo 
'<div class="menu2"><img src="/design/alll.png" alt="*" align="middle"/> Правила: <a href="/all/rulls.php?all" style="text-decoration:none; color:white;">сайта</a>/<a href="/forum/rulls'.$podrazd['id'].'" style="text-decoration:none; color:white;">подраздела</a>  | <img src="/design/emoc.png" alt="*" align="middle"/> <a href="/all/smiles_r.php" style="text-decoration:none; color:white;">Смайлы</a> | <img src="/design/cod.png" alt="*" align="middle"/> <a href="/all/bb.php" style="text-decoration:none; color:white;">ББ коды</a> | <img src="/design/usear.png" alt="*" align="middle"/> <a href="/fsearch.php" style="text-decoration:none; color:white;">Поиск</a></div>';
break;
# Тема
case 'thema':
$thema DB::$dbs->queryFetch("SELECT * FROM `forum_thema` where `id` = ?",array($func->num($_GET['id'])));
$thema_author DB::$dbs->queryFetch("SELECT * from `us` where `id` = ?",array($thema['author']));
$podrazd DB::$dbs->queryFetch("SELECT * FROM `forum_podrazd` where `id` = ?",array($thema['podrazd']));
$razd DB::$dbs->queryFetch("SELECT * FROM `forum_razd` where `id` = ?",array($thema['razd']));
if(!
$thema['id'] or !$razd['id'] or !$podrazd['id']){
header('location:/forum');
exit;
}
verh($thema['name'],'<a href="/forum" style="color: #fff;">Форум</a> | <a href="/forum/razd'.$razd['id'].'" style="color: #fff;">'.$razd['name'].'</a> | <a href="/forum/'.$razd['id'].'/'.$podrazd['id'].'" style="color: #fff;">'.$podrazd['name'].'</a> | '.$thema['name'].'');
if(
DB::$dbs->querySingle("SELECT count(id) from `forum_visit` where `thema` = ? and `us` = ?",array($thema['id'],$cms->us['id'])) == 0){
DB::$dbs->query("insert into `forum_visit` (`thema`,`us`,`last`) values (?,?,?)",array($thema['id'],$cms->us['id'],time()));
}else{
DB::$dbs->query("update `forum_visit` set `last` = ? where `thema` = ? and `us` = ?",array(time(),$thema['id'],$cms->us['id']));
}
if(
$thema['del']==1){
echo 
'<div class="list1">Тема удалена!</div>';
if(
$cms->us['level']>0){
if(isset(
$_GET['up'])){
DB::$dbs->query('UPDATE `forum_thema` set `del`="0" where `id`=?',array($thema['id']));
header('location:/forum/thema'.$thema['id']);
}
echo 
'<div class="list1"><a href="/forum/thema'.$thema['id'].'=up">Восстановить</a></div>';
}
}else{


$posts DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `razd` = ? and `podrazd` = ? and `thema` = ? ".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($razd['id'],$podrazd['id'],$thema['id']));
$num 10;
$total intval(($posts 1) / $num) + 1;
$page abs(intval($_GET['page']));
if(empty(
$page) or $page 0$page 1;
if(
$page $total$page $total;
$start $page $num $num;
if(
$page == 1$i $page;
elseif(
$page == 2$i = ($page+9);
else 
$i = ($page*10)-9;


# Ответ
if(isSet($_GET['otv'])){
$otv $func->num($_GET['otv']);
if(!empty(
$otv) && $otv != $cms->us['id']){
$u DB::$dbs->queryFetch('SELECT * from `us` where `id` = ?',array($otv));
if(
$u != 0){
echo 
'<div class="list1"><form action="/forum/thema'.$thema['id'].'=otv_i'.$otv.'" method="post" enctype="multipart/form-data">Сообщение:<br/>
<textarea name="msg">[b]'
.$u['nick'].'[/b], </textarea><br>';
if(
$cms->us['file']==1) echo 'Файл:<br/><input type="file" name="filename"/><br/>';
echo 
'<div class="rega">Прикрепление файлов: <a href="/kab/index.php?at=opt&diss&th='.$thema['id'].'&p='.$page.'">'.($cms->us['file']==0?'вкл':'выкл').'</a></div>
<input type="submit" value="Написать"/> <input type="button" value="Назад" onClick="history.go(-1);" /></form></div>'
;
if(isSet(
$_POST['msg'])){
$msg secure($_POST['msg']);
if(!
$msg){
echo 
'<div class="list1"><b>Недопустимая длина сообщения!</b></div>';
}else{
$repost DB::$dbs->queryFetch('SELECT * from `forum_post` where `us` = ? and `thema`=? and `text`=?',array($cms->us['id'],$thema['id'],$msg));
if(
$repost['id']){
echo 
'<div class="list1"><b>Вы уже писали подобное..</b></div>';
}else{
$lastpost DB::$dbs->queryFetch('SELECT * from `forum_post` where `thema`=? order by `id` desc limit 1',array($thema['id']));
$usposts DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `us` = ?".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($cms->us['id']));
if(
$usposts<100 && $lastpost['us']==$cms->us['id']){
echo 
'<div class="list1"><b>Вы можете писать 1 раз в минуту пока не наберете 100 постов в форуме!</b></div>';
}else{
DB::$dbs->query("insert into `forum_post` (`razd`,`podrazd`,`thema`,`us`,`text`,`time`,`otv`) values (?,?,?,?,?,?,?)",array($razd['id'],$podrazd['id'],$thema['id'],$cms->us['id'],$msg,time(),$otv));
$post_id=DB::$dbs->lastInsertId();
DB::$dbs->query("INSERT INTO `action` set `value` = ?, `t` = ?, `us` = ?, `see` = ?",array('[url=/us'.$cms->us['id'].']'.$cms->us['nick'].'[/url] ответил вам в теме [url=/forum/thema'.$thema['id'].'/page'.ceil($posts/10).']'.$thema['name'].'[/url]!',time(),$otv,1));
$podp_users DB::$dbs->query("SELECT * from `forum_podp` where `thema` = ? and `us` != ?",array($thema['id'],$cms->us['id']));
while(
$podp_us $podp_users->fetch()){
DB::$dbs->query("INSERT INTO `action` set `value` = ?, `t` = ?, `us` = ?, `see` = ?",array('[url=/us'.$cms->us['id'].']'.$cms->us['nick'].'[/url] ответил в теме [url=/forum/thema'.$thema['id'].'/page'.ceil($posts/10).']'.$thema['name'].'[/url]!',time(),$podp_us['us'],1)); 
}
DB::$dbs->query("UPDATE `forum_thema` set `last` = ?,`last_us` = ? where (`id`=?)",array(time(),$cms->us['id'],$thema['id']));

if(
file_exists($_FILES['filename']['tmp_name'])){
$ext=substr($_FILES['filename']['name'],strrpos($_FILES['filename']['name'],".")+1);
if(
in_array($ext,array('jpg','gif','png','jpeg','bmp','zip','rar','7z','txt'))){
$fn=$_SERVER['HTTP_HOST'].'_'.$cms->us['id'].'_'.$post_id.'.'.$ext;
move_uploaded_file($_FILES['filename']['tmp_name'],'./files/forum/'.$fn);
DB::$dbs->query("insert into `forum_file` (`thema`,`post`,`name`) values (?,?,?)",array($thema['id'],$post_id,$fn));
}
}

header('location: /forum/thema'.$thema['id'].'/page'.ceil($posts/10));
}
}
}
}
}else{
header('location: /forum/thema'.$thema['id'].'/page'.ceil($posts/10));
}
}else{
header('location: /forum/thema'.$thema['id'].'/page'.ceil($posts/10));
}
# Цитата
}elseif(isSet($_GET['cit'])){
$cit $func->num($_GET['cit']);
if(
$cit){
$cit DB::$dbs->queryFetch('SELECT * from `forum_post` where `id` = ?',array($cit));
$cit_u DB::$dbs->queryFetch('SELECT * from `us` where `id` = ?',array($cit['us']));
if(
$cit_u['id']==$cms->us['id']){
header('location: /forum/thema'.$thema['id'].'/page'.ceil($posts/10));
exit;
}
echo 
'<div class="list1">Цитата:<div class="cit"><font color="red"><b>'.$cit_u['nick'].'</b></font>: '.$func->text($cit['text']).'</div>
<form action="/forum/thema'
.$thema['id'].'=cit'.$cit['id'].'" method="post">Сообщение:<br/><textarea name="msg"></textarea><br/>';
if(
$cms->us['file']==1) echo 'Файл:<br/><input type="file" name="filename"/><br/>';
echo 
'<div class="rega">Прикрепление файлов: <a href="/kab/index.php?at=opt&diss&th='.$thema['id'].'&p='.$page.'">'.($cms->us['file']==0?'вкл':'выкл').'</a></div>
<input type="submit" value="Написать"/> <input type="button" value="Назад" onClick="history.go(-1);" /></form></div>'
;
if(isSet(
$_POST['msg'])){
$msg secure($_POST['msg']);
if(!
$msg){
echo 
'<div class="list1"><b>Недопустимая длина сообщения!</b></div>';
}else{
$repost DB::$dbs->queryFetch('SELECT * from `forum_post` where `us` = ? and `thema`=? and `text`=?',array($cms->us['id'],$thema['id'],$msg));
if(
$repost['id']){
echo 
'<div class="list1"><b>Вы уже писали подобное..</b></div>';
}else{
$lastpost DB::$dbs->queryFetch('SELECT * from `forum_post` where `thema`=? order by `id` desc limit 1',array($thema['id']));
$usposts DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `us` = ?".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($cms->us['id']));
if(
$usposts<100 && $lastpost['us']==$cms->us['id']){
echo 
'<div class="list1"><b>Вы можете писать 1 раз в минуту пока не наберете 100 постов в форуме!</b></div>';
}else{
DB::$dbs->query("insert into `forum_post` (`razd`,`podrazd`,`thema`,`us`,`text`,`time`,`cit`) values (?,?,?,?,?,?,?)",array($razd['id'],$podrazd['id'],$thema['id'],$cms->us['id'],$msg,time(),$cit['id']));
$post_id=DB::$dbs->lastInsertId();
DB::$dbs->query("INSERT INTO `action` set `value` = ?, `t` = ?, `us` = ?, `see` = ?",array('[url=/us'.$cms->us['id'].']'.$cms->us['nick'].'[/url] процитировал ваш пост:[br]'.$cit['text'].' в теме [url=/forum/thema'.$thema['id'].'/page'.ceil($posts/10).']'.$thema['name'].'[/url]!',time(),$cit['us'],1));
$podp_users DB::$dbs->query("SELECT * from `forum_podp` where `thema` = ? and `us` != ?",array($thema['id'],$cms->us['id']));
while(
$podp_us $podp_users->fetch()){
DB::$dbs->query("INSERT INTO `action` set `value` = ?, `t` = ?, `us` = ?, `see` = ?",array('[url=/us'.$cms->us['id'].']'.$cms->us['nick'].'[/url] ответил в теме [url=/forum/thema'.$thema['id'].'/page'.ceil($posts/10).']'.$thema['name'].'[/url]!',time(),$podp_us['us'],1));
}
DB::$dbs->query("UPDATE `forum_thema` set `last` = ?,`last_us` = ? where (`id`=?)",array(time(),$cms->us['id'],$thema['id']));
if(
file_exists($_FILES['filename']['tmp_name'])){
$ext=substr($_FILES['filename']['name'],strrpos($_FILES['filename']['name'],".")+1);
if(
in_array($ext,array('jpg','gif','png','jpeg','bmp','zip','rar','7z','txt'))){
$fn=$_SERVER['HTTP_HOST'].'_'.$cms->us['id'].'_'.$post_id.'.'.$ext;
move_uploaded_file($_FILES['filename']['tmp_name'],'./files/forum/'.$fn);
DB::$dbs->query("insert into `forum_file` (`thema`,`post`,`name`) values (?,?,?)",array($thema['id'],$post_id,$fn));
}
}
header('location: /forum/thema'.$thema['id'].'/page'.ceil($posts/10));
}
}
}
}
}
}else{

echo 
'<div class="list1"><small><a href="/forum/thema'.$thema['id'].'/page'.ceil(DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ?",array($thema['id']))/10).'">Обновить</a> | ';

# Подписка
$podp DB::$dbs->queryFetch("SELECT * from `forum_podp` where `thema` = ? and `us` = ?",array($thema['id'],$cms->us['id']));
if(!
$podp['id']){
echo 
'<a href="/forum/thema'.$thema['id'].'/page'.ceil(DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ?",array($thema['id']))/10).'=podpis">Подписаться</a>';
if(isSet(
$_GET['podpis'])){
DB::$dbs->query("insert into `forum_podp` (`thema`,`us`) values (?,?)",array($thema['id'],$cms->us['id']));
header('location:/forum/thema'.$thema['id'].'/page'.$page);
}
}else{
echo 
'<a href="/forum/thema'.$thema['id'].'/page'.ceil(DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ?",array($thema['id']))/10).'=otpis">Отписаться</a>';
if(isSet(
$_GET['otpis'])){
DB::$dbs->query("DELETE from `forum_podp` where `thema` = ? and `us` = ?",array($thema['id'],$cms->us['id']));
header('location:/forum/thema'.$thema['id'].'/page'.$page);
}
}
if(
$thema['type'] != 1){
if(
$thema['author'] == $cms->us['id'] OR $cms->us['level'] > 1){
if(isSet(
$_GET['close'])){
DB::$dbs->query("UPDATE `forum_thema` set `type` = ?,`last` = ?,`last_us` = ? where `id` = ?",array(1,time(),$cms->us['id'],$thema['id']));
DB::$dbs->query("insert into `forum_post` (`razd`,`podrazd`,`thema`,`us`,`text`,`time`) values (?,?,?,?,?,?)",array($razd['id'],$podrazd['id'],$thema['id'],$cms->us['id'],'[b]Тема закрыта для обсуждения![/b] :-)',time())); header('location: /forum/thema'.$thema['id'].'/page'.ceil(DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ?",array($thema['id']))/10)); exit;
}
echo 
' | <a href="/forum/thema'.$thema['id'].'=close">Закрыть</a>';
}
}elseif(
$thema['type']==1){
if(
$cms->us['level'] > 1){
if(isSet(
$_GET['open'])){
DB::$dbs->query("UPDATE `forum_thema` set `type` = ?,`last` = ?,`last_us` = ? where `id` = ?",array(0,time(),$cms->us['id'],$thema['id']));
DB::$dbs->query("insert into `forum_post` (`razd`,`podrazd`,`thema`,`us`,`text`,`time`) values (?,?,?,?,?,?)",array($razd['id'],$podrazd['id'],$thema['id'],$cms->us['id'],'[b]Тема открыта для обсуждения![/b] :-)',time())); header('location: /forum/thema'.$thema['id'].'/page'.ceil(DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ?",array($thema['id']))/10)); exit;
}
echo 
' | <a href="/forum/thema'.$thema['id'].'=open">Открыть</a>';
}
}
if(
$cms->us['level']>0){
if(isSet(
$_GET['top'])){
DB::$dbs->query("UPDATE `forum_thema` set `top` = ? where `id` = ?",array(($thema['top']==0?1:0),$thema['id']));
header('location:/forum/thema'.$thema['id'].'/page'.$page);
}
echo 
' | <a href="/forum/thema'.$thema['id'].'=top">'.($thema['top']==0?'Прикрепить':'Открепить').'</a>';
}

if(
$cms->us['level']>&& $cms->us['level']>=$thema_us['level']){
if(isset(
$_GET['del'])){
DB::$dbs->query('UPDATE `forum_thema` set `del`="1" where `id`=?',array($thema['id']));
header('location:/forum/thema'.$thema['id']);
}
echo 
' | <a href="/forum/thema'.$thema['id'].'=del">Удалить</a>';
}

# Голосование
if($thema['author']==$cms->us['id'] or $cms->us['level']>&& $cms->us['level']>=$thema_us['level']){
$op DB::$dbs->queryFetch("SELECT * from `forum_op` where `thema` = ?",array($thema['id']));

if(!
$op['id']) echo ' | <a href="/forum.php?mod=op_add&amp;thema='.$thema['id'].'">Добавить опрос</a>';
}
echo 
'</small></div>';
if(
$op['id']){
echo 
'<div class="post2">Вопрос: '.$op['vopros'].'<br/>';
if(
DB::$dbs->querySingle('select count(`id`) from `forum_op_otv_vote` where (`thema`=? and `us`=?)',array($thema['id'],$cms->us['id']))==0){

$op_otvs DB::$dbs->query("SELECT * from `forum_op_otv` where `op` = ?",array($op['id']));
echo 
'<form action="/forum/thema'.$thema['id'].'=opr" method="post" style="margin: 0;">Ответ:
<select name="opr"><option selected disabled> Выбери<br/>'
;
while(
$op_otv $op_otvs->fetch()){
echo 
'<option value="'.$op_otv['id'].'">'.$op_otv['otv'].'</option>';
}
echo
'</select><input type="submit" value="Проголосовать"></form>';

if(isSet(
$_GET['opr'])){
$opr=$func->num($_POST['opr']);
if(
DB::$dbs->querySingle('select count(`id`) from `forum_op_otv` where (`id`=? and `op`=?)',array($opr,$op['id']))!=0){
DB::$dbs->query('insert into `forum_op_otv_vote` (`thema`,`op`,`otv`,`us`) values (?,?,?,?)',array($thema['id'],$op['id'],$opr,$cms->us['id']));
}
header('location:/forum/thema'.$thema['id'].'/page'.$total);
}

}else{

$op_otvs DB::$dbs->query("SELECT * from `forum_op_otv` where `op` = ?",array($op['id']));
while(
$op_otv $op_otvs->fetch()){
echo 
'<b>'.$op_otv['otv'].'</b> (голосов: '.DB::$dbs->querySingle('select count(`id`) from `forum_op_otv_vote` where (`otv`=?)',array($op_otv['id'])).')<br/>';
}


}
if(
$thema['author']==$cms->us['id'] or $cms->us['level']>0){

echo 
'- <a href="/forum.php?mod=vop_add&thema='.$thema['id'].'&amp;op='.$op['id'].'">Добавить</a> | <a href="/forum.php?mod=redop&thema='.$thema['id'].'&amp;op='.$op['id'].'">удалить</a> варианты<br/>
- <a href="/forum.php?mod=thema&id='
.$thema['id'].'&amp;delo">Удалить опрос</a>';
if(isSet(
$_GET['delo'])){
$op_otvs DB::$dbs->query("SELECT * from `forum_op_otv` where `op` = ?",array($op['id']));
while(
$op_otv $op_otvs->fetch()){
DB::$dbs->query('delete from `forum_op_otv` where (`id`=?)',array($op_otv['id']));
}
$op_otv_votes DB::$dbs->query("SELECT * from `forum_op_otv_vote` where `op` = ?",array($op['id']));
while(
$op_otv_vote $op_otv_votes->fetch()){
DB::$dbs->query('delete from `forum_op_otv_vote` where (`id`=?)',array($op_otv_vote['id']));
}
DB::$dbs->query('delete from `forum_op` where (`id`=?)',array($op['id']));
header('location:/forum/thema'.$thema['id'].'/page'.$page);
}
}
echo 
'</div>';
}

if(
$thema['type'] == '1') echo '<div class="post2"><img src="/design/closed.png" alt="*" align="middle"/> <b>Тема закрыта!</b></div>';
if(
$posts==0){
echo
'<div class="lst">Сообщений нет!</div>';
}else{
$posts DB::$dbs->query("SELECT * from `forum_post` where `razd` = ? and `podrazd` = ? and `thema` = ? ".($cms->us['level']>0?NULL:'and `del` = '0'')." order by `id` limit $start,$num",array($razd['id'],$podrazd['id'],$thema['id']));
while(
$post $posts->fetch()){
$post_us DB::$dbs->queryFetch("SELECT * from `us` where `id` = ?",array($post['us']));
$post_ups DB::$dbs->queryFetch("SELECT * from `us` where `id` = ?",array($post['ups']));
$post_del DB::$dbs->queryFetch("SELECT * from `us` where `id` = ?",array($post['del']));
echo 
'<div class="lst">'.$i++.'. '.$func->uNick($post['us']).' '.($post['us']==$thema['author']?'<b><font color="green">[автор]</font></b>':NULL).' ('.t($post['time']).') '.($post['del']?' <font color="red"><b>пост удалил</b></font> '.$func->uNick($post['del'].' '):($post['ups']?' <font color="green"><b>пост восстановил</b></font> '.$func->uNick($post['ups'].' '):NULL));
if(
$post['us'] == $cms->us['id']) echo ($thema['type']==0?' [<a href="/forum/redk'.$post['id'].'"">ред</a>] ':($cms->us['level']>0?' [<a href="/forum/redk'.$post['id'].'"">ред</a>] ':NULL)).($cms->us['level'] > ' [<a href="/forum.php?mod=post&post='.$post['id'].'&page='.$page.'">'.($post['del']!=0?'вос':'x').'</a>] ':NULL); else echo ($cms->us['level'] > ? ($thema['type']==0?' [<a href="/forum/redk'.$post['id'].'">ред</a>]':($cms->us['level']>&& $cms->us['level']>=$post_us['level']?' [<a href="/forum/redk'.$post['id'].'">ред</a>]':NULL)):NULL).' '.($thema['type']==&& $post['del']==0?'[<a href="/forum/thema'.$thema['id'].'=otv_i'.$post['us'].'">отв</a>] [<a href="/forum/thema'.$thema['id'].'=cit'.$post['id'].'">цит</a>]':NULL).($post['del']==0?' [<a href="/forum/jal'.$post['id'].'/page'.$page.'">жал</a>] ':'').($cms->us['level']>&& $cms->us['level'] > $post_us['level'] ? ($post['del']==0?'[<a href="/forum/bn'.$post['id'].'/page'.$page.'">нар</a>]':'').' [<a href="/forum.php?mod=post&post='.$post['id'].'&page='.$page.'">'.($post['del']!=0?'вос':'x').'</a>]':NULL).' '.($post['del']==0?DB::$dbs->querySingle('select count(id) from `forum_post_vote` where (`thema`=? and `us`=? and `kem`=?)',array($thema['id'],$post['us'],$cms->us['id']))==0?'<a href="/forum.php?mod=vote&id='.$post['id'].'&vot=za&v='.$post['us'].'&page='.$page.'">+1</a> | <a href="/forum.php?mod=vote&id='.$post['id'].'&vot=protiv&v='.$post['us'].'&page='.$page.'">-1</a>':NULL:NULL);
echo 
' (<font color="green">'.DB::$dbs->querySingle('select count(id) from `forum_post_vote` where (`thema`=? and `us`=? and `vote`="1" and `post`=?)',array($thema['id'],$post['us'],$post['id'])).'</font>/<font color="red">'.DB::$dbs->querySingle('select count(id) from `forum_post_vote` where (`thema`=? and `us`=? and `vote`="2" and `post`=?)',array($thema['id'],$post['us'],$post['id'])).'</font>)<br/>';
if(!empty(
$post['otv'])){
$otv DB::$dbs->queryFetch("SELECT * from `us` where `id` = ?",array($post['otv']));
if(!
$otv['id']) echo '<b>'.$otv['nick'].'</b>, ';
}

if(!empty(
$post['cit'])){
$cit DB::$dbs->queryFetch("SELECT * from `forum_post` where `id` = ?",array($post['cit']));
echo 
'Цитата:<div class="cit">';
if(!
$cit['id'] or $cit['del']==1){ echo '<b>Сообщение удалено!</b>'; }else{
$cit_us DB::$dbs->queryFetch("SELECT * from `us` where `id` = ?",array($cit['us']));
if(!
$cit_us['id']) echo '[Удалён]'; else echo '<font color="red"><b>'.$cit_us['nick'].'</b></font>: '.$func->text($cit['text']);
}
echo 
'</div>';
}

echo 
$func->text($post['text']).'<br/>';

# Прикрепленные файлы
$files=DB::$dbs->querySingle("SELECT count(`id`) from `forum_file` where `post` = ?",array($post['id']));
if(
$files>0){
$files DB::$dbs->query("SELECT * from `forum_file` where `post` = ? order by `id`",array($post['id']));
while(
$file $files->fetch()){
echo 
'<br/>Прикрепленные файлы:<br/><a href="/files/forum/'.$file['name'].'"><b>'.$file['name'].'</b></a> ('.round(filesize('./files/forum/'.$file['name'])/1024).'Kb)'.($cms->us['level']>1?' [<a href="/forum.php?mod=file&id='.$file['id'].'&page='.$page.'">x</a>]':NULL).'<br/>';
}
}

$redk=DB::$dbs->querySingle("SELECT count(`id`) from `forum_post_redk` where `post` = ?",array($post['id']));
if(
$redk>0){
$last_redk=DB::$dbs->queryFetch('SELECT * FROM `forum_post_redk` where `post` = ? order by `id` desc limit 1',array($post['id']));
echo 
'<br/><small><i>Изменено <a href="/forums/reds.php?id='.$post['id'].'">'.$redk.' раз.</a></i> Посл. ред. '.$func->uNick($last_redk['us']).' ('.t($last_redk['time']).')</small>';
}

if(
$post_us['status']) echo '<hr/><b>Статус: '.$post_us['status'].'</b>';

echo 
'</div>';

}}
if(
$thema['type'] != 1){
echo 
'<div class="list1"><form action="/forum/thema'.$thema['id'].'/page'.$page.'" method="post" enctype="multipart/form-data">Сообщение:<br/>
<textarea name="msg"></textarea><br>'
;
if(
$cms->us['file']==1) echo 'Файл:<br/><input type="file" name="filename"/><br/>';
echo 
'<div class="rega">Прикрепление файлов: <a href="/kab/index.php?at=opt&diss&th='.$thema['id'].'&p='.$page.'">'.($cms->us['file']==0?'вкл':'выкл').'</a></div>
<input type="submit" value="Написать"/> <input type="button" value="Назад" onClick="history.go(-1);" /></form></div>'
;
if(isSet(
$_POST['msg'])){
$msg secure($_POST['msg']);
if(!
$msg){
echo 
'<div class="list1"><b>Недопустимая длина сообщения!</b></div>';
}elseif(
DB::$dbs->querySingle("SELECT * from `forum_post` where `thema` = ? and `us` = ? and `text` = ?",array($thema['id'],$cms->us['id'],$msg)) != 0){
echo 
'<div class="list1"><b>Вы уже писали подобное..</b></div>';
}else{
$lastpost DB::$dbs->queryFetch('SELECT * from `forum_post` where `thema`=? order by `id` desc limit 1',array($thema['id']));
$usposts DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `us` = ?".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($cms->us['id']));
if(
$usposts<100 && $lastpost['us']==$cms->us['id']){
echo 
'<div class="list1"><b>Вы можете писать 1 раз в минуту пока не наберете 100 постов в форуме!</b></div>';
}else{
DB::$dbs->query("insert into `forum_post` (`razd`,`podrazd`,`thema`,`us`,`text`,`time`) values (?,?,?,?,?,?)",array($razd['id'],$podrazd['id'],$thema['id'],$cms->us['id'],$msg,time()));
$post_id=DB::$dbs->lastInsertId();
$podp_users DB::$dbs->query("SELECT * from `forum_podp` where `thema` = ? and `us` != ?",array($thema['id'],$cms->us['id']));
while(
$podp_us $podp_users->fetch()){
DB::$dbs->query("INSERT INTO `action` set `value` = ?, `t` = ?, `us` = ?, `see` = ?",array('[url=/us'.$cms->us['id'].']'.$cms->us['nick'].'[/url] ответил в теме [url=/forum/thema'.$thema['id'].'/page'.$total.']'.$thema['name'].'[/url]!',time(),$podp_us['us'],1));
}
DB::$dbs->query("UPDATE `forum_thema` set `last` = ?,`last_us` = ? where (`id`=?)",array(time(),$cms->us['id'],$thema['id']));

if(
file_exists($_FILES['filename']['tmp_name'])){
$ext=substr($_FILES['filename']['name'],strrpos($_FILES['filename']['name'],".")+1);
if(
in_array($ext,array('jpg','gif','png','jpeg','bmp','zip','rar','7z','txt'))){
$fn=$_SERVER['HTTP_HOST'].'_'.$cms->us['id'].'_'.$post_id.'.'.$ext;
move_uploaded_file($_FILES['filename']['tmp_name'],'./files/forum/'.$fn);
DB::$dbs->query("insert into `forum_file` (`thema`,`post`,`name`) values (?,?,?)",array($thema['id'],$post_id,$fn));
}
}

header('location: /forum/thema'.$thema['id'].'/page'.ceil(DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `razd` = ? and `podrazd` = ? and `thema` = ? ".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($razd['id'],$podrazd['id'],$thema['id']))/10));
}
}
}
}
if(
$posts>0){
echo 
'<div class="lst">';
$func->page('/forum/thema'.$thema['id']);
echo 
'</div>';
}
echo 
'<div class="list1">В теме: <a href="/forum/who'.$thema['id'].'">'.DB::$dbs->querySingle("SELECT count(id) from `forum_visit` where `thema`= ? and `last` > ?",array($thema['id'],(time()-60))).' человек</a>, <a href="/forum/visit'.$thema['id'].'">'.DB::$dbs->querySingle("SELECT count(id) from `forum_visit` where `thema` = ?",array($thema['id'])).'</a> заходили<br><img src="/images/download.png" alt="*" align="middle"/> <a href="/dthema.php?id='.$thema['id'].'&do">Скачать тему</a> | <img src="/images/files.png" alt="*" align="middle"/> <a href="/forum.php?mod=filez&id='.$thema['id'].'">Файлы темы</a></div>
<div class="menu2"><img src="/design/alll.png" alt="*" align="middle"/> Правила: <a href="/all/rulls.php?all" style="text-decoration:none; color:white;">сайта</a>/<a href="/forum/rulls'
.$podrazd['id'].'" style="text-decoration:none; color:white;">подраздела</a>  | <img src="/design/emoc.png" alt="*" align="middle"/> <a href="/all/smiles_r.php" style="text-decoration:none; color:white;">Смайлы</a> | <img src="/design/cod.png" alt="*" align="middle"/> <a href="/all/bb.php" style="text-decoration:none; color:white;">ББ коды</a> | <img src="/design/usear.png" alt="*" align="middle"/> <a href="/fsearch.php" style="text-decoration:none; color:white;">Поиск</a></div>';
}

}
break;
# Кто в теме
case 'who':
$thema DB::$dbs->queryFetch("SELECT * FROM `forum_thema` where `id` = ?",array($func->num($_GET['id'])));
if(!
$thema['id'] or $thema['del']==1){
header('location:/forum');
exit;
}
$posts DB::$dbs->querySingle("SELECT count(id) from `forum_visit` where `thema` = ? and `last` > ?",array($thema['id'],time()-60));
verh('В теме '.$posts,'В теме "'.$thema['name'].'" '.$posts.' человек');
$num 10;
if(
$posts==0){echo'<div class="lst">В теме никого нет!</div>';}else{
$total intval(($posts 1) / $num) + 1;
$page abs(intval($_GET['page']));
if(empty(
$page) or $page 0$page 1;
if(
$page $total$page $total;
$start $page $num $num;
echo 
'<div class="list1">';
$visits DB::$dbs->query("SELECT * from `forum_visit` where `thema` = ? and `last` > ? order by `last` desc limit $start,$num",array($thema['id'],time()-60));
while(
$visit $visits->fetch()){
echo 
$func->uNick($visit['us']).', ';
}
echo 
'</div><div class="lst">';
$func->page('/forum/who'.$thema['id'].'?');
echo 
'</div>';
}
echo 
'<div class="navg"><a href="/forum/thema'.$thema['id'].'">Вернуться</a></div>';
break;
# Кто был в теме
case 'visit':
$thema DB::$dbs->queryFetch("SELECT * FROM `forum_thema` where `id` = ?",array($func->num($_GET['id'])));
if(!
$thema['id'] or $thema['del']==1){
header('location:/forum');
exit;
}
$posts DB::$dbs->querySingle("SELECT count(id) from `forum_visit` where `thema` = ?",array($thema['id']));
verh('В теме '.$posts,'В тему "'.$thema['name'].'" зашло '.$posts.' человек');
$num 10;
if(
$posts==0){
echo
'<div class="lst">В теме никого небыло!</div>';
}else{
$total intval(($posts 1) / $num) + 1;
$page abs(intval($_GET['page']));
if(empty(
$page) or $page 0$page 1;
if(
$page $total$page $total;
$start $page $num $num;
echo 
'<div class="list1">';
$visits DB::$dbs->query("SELECT * from `forum_visit` where `thema` = ? order by `last` desc limit $start,$num",array($thema['id']));
while(
$visit $visits->fetch()){
echo 
$func->uNick($visit['us']).' ('.t($visit['last']).')<br>';
}
echo 
'</div><div class="lst">';
$func->page('/forum/visit'.$thema['id'].'?');
echo 
'</div>';
}
echo 
'<div class="navg"><a href="/forum/thema'.$thema['id'].'">Вернуться</a></div>';
break;
# Действие с постом
case 'post':
$post DB::$dbs->queryFetch("SELECT * FROM `forum_post` where `id` = ?",array($func->num($_GET['post'])));
if(
$post['id']){
$post_us DB::$dbs->queryFetch("SELECT * from `us` where `id` = ?",array($post['us']));
if(
$cms->us['level']>&& $cms->us['level']>=$post_us['level']){
$thema DB::$dbs->queryFetch("SELECT * FROM `forum_thema` where `id` = ?",array($post['thema']));
if(
$thema['id'] && $thema['del']==0){
if(
$post['del']){
DB::$dbs->query("UPDATE `forum_post` set `del`= '', `ups` = ? WHERE (`id`=?)",array($cms->us['id'],$post['id']));
}else{
DB::$dbs->query("UPDATE `forum_post` set `del` = ? WHERE (`id`=?)",array($cms->us['id'],$post['id']));
}
header('location:/forum/thema'.$thema['id'].'/page'.$func->num($_GET['page']));
exit;
}
}
}
header('location:/forum');
break;
# Редактирование сообщения
case 'redk':
$post DB::$dbs->queryFetch("SELECT * FROM `forum_post` where `id` = ?",array($func->num($_GET['id'])));
if(!
$post['id']){
header('location:/forum');
exit;
}
$post_us DB::$dbs->queryFetch("SELECT * from `us` where `id` = ?",array($post['us']));
if(
$post['id'] && $post['us']==$cms->us['id'] or $post['id'] && $cms->us['level']>&& $cms->us['level']>=$post_us['level']){
$thema DB::$dbs->queryFetch("SELECT * FROM `forum_thema` where `id` = ?",array($post['thema']));
if(
$thema['id'] && $thema['del']==0){
verh('Редактирование сообщения',$thema['name']);
$thema_p DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ? ".($cms->us['level']>0?'and `del`='0'':NULL)."",array($thema['id']));
echo 
'<div class="list1"><form action="/forum/redk'.$post['id'].'?ok" method="post">
<textarea name="msg">'
.$post['text'].'</textarea><br/><input type="submit" value="Сохранить"/> <input type="button" value="Назад" onClick="history.go(-1);" />
</form></div>'
;

if(isSet(
$_GET['ok'])){
$msg=secure($_POST['msg']);
if(!
$msg){
echo 
'<div class="list1">Вы не ввели текст сообщения...</div>';
}else{
if(
$msg!=$post['text'])
{
DB::$dbs->query("UPDATE `forum_post` set `text` = ? WHERE (`id`=?)",array($msg,$post['id']));
DB::$dbs->query("INSERT INTO `forum_post_redk` (`post`,`us`,`time`) values (?,?,?)",array($post['id'],$cms->us['id'],time()));
}
header('location:/forum/thema'.$thema['id'].'/page'.ceil($thema_p/10));
exit;
}
}
}else{
header('location:/forum');
}
}else{
header('location:/forum');
}
break;
# Голосование за пост
case 'vote':
$vot=secure($_GET['vot']);
if(
$vot=='za'$vot=1;
if(
$vot=='protiv'$vot=2;
else 
$vot=1;
$v DB::$dbs->queryFetch("SELECT * FROM `us` where `id` = ?",array($func->num($_GET['v'])));
if(
$v['id'] && $v['id']!=$cms->us['id']){
$page=$func->num($_GET['page']);
$post DB::$dbs->queryFetch("SELECT * FROM `forum_post` where `id` = ?",array($func->num($_GET['id'])));
if(
$post['del']==0){
if(
$post['id'] && DB::$dbs->queryFetch('select * from `forum_post_vote` where (`thema`=? and `us`=? and `kem`=?)',array($post['thema'],$v['id'],$cms->us['id']))==0){
$thema DB::$dbs->queryFetch("SELECT * FROM `forum_thema` where `id` = ?",array($post['thema']));
if(
$thema['id'] && $thema['type']==0){
$thema_p DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ? ".($cms->us['level']>0?'and `del`='0'':NULL)."",array($thema['id']));
DB::$dbs->query("UPDATE `us` set `rating` = ? WHERE (`id`=?)",array($v['rating']+0.1,$v['id']));
DB::$dbs->query("INSERT INTO `action` set `value` = ?, `t` = ?, `us` = ?, `see` = ?",array('[url=/us'.$cms->us['id'].']'.$cms->us['nick'].'[/url]  [b]'.($vot==1?'положительно':'отрицательно').'[/b] оценил ваш пост:[br]'.$post['text'].' в теме [url=/forum/thema'.$thema['id'].'/page'.ceil($thema_p/10).']'.$thema['name'].'[/url]!',time(),$v['id'],1));
DB::$dbs->query("INSERT INTO `forum_post_vote` (`thema`,`us`,`kem`,`vote`,`post`) values (?,?,?,?,?)",array($thema['id'],$v['id'],$cms->us['id'],$vot,$post['id']));
header('location:/forum/thema'.$thema['id'].'/page'.$func->num($_GET['page']));
exit;
}
}
}
}
header('location:/forum');
break;
# Темы юзера
case 'thems':
$us=DB::$dbs->queryFetch("SELECT * FROM `us` where `id` = ?",array($func->num($_GET['id'])));
if(!
$us['id']){
header('location:/forum');exit;
}
verh('Темы '.$us['nick'],'<a href="/forum" style="color:#ffffff;">Форум</a> | Темы '.$func->uNick($us['id']));
$posts DB::$dbs->querySingle("SELECT count(`id`) from `forum_thema` where `author` = ?".($cms->us['level']>0?NULL:' and `del`='0'')."",array($us['id']));
echo 
'<div class="menu2">Вcего '.$posts.' тем</div>';
$num 10;
if(
$posts==0){
echo
'<div class="lst">'.$func->uNick($us['id']).' не создавал тем на форуме!</div>';
}else{
$total intval(($posts 1) / $num) + 1;
$page abs(intval($_GET['page']));
if(empty(
$page) or $page 0$page 1;
if(
$page $total$page $total;
$start $page $num $num;
$thems DB::$dbs->query("SELECT * from `forum_thema` where `author` = ? ".($cms->us['level']>0?NULL:' and `del`='0'')." order by `id` desc limit $start,$num",array($us['id']));
while(
$thema $thems->fetch()){
$razd=DB::$dbs->queryFetch("SELECT * FROM `forum_razd` where `id` = ?",array($thema['razd']));
$podrazd=DB::$dbs->queryFetch("SELECT * FROM `forum_podrazd` where `id` = ?",array($thema['podrazd']));
if(
$cms->us['level']>0){
$thema_p DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ?",array($thema['id']));
}else{
$thema_p DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ? and `del`='0'",array($thema['id']));
}
echo 
'<div class="lst">Раздел: <a href="/forum/'.$thema['razd'].'">'.$razd['name'].'</a><br/>
Подраздел: <a href="/forum/'
.$thema['razd'].'/'.$thema['podrazd'].'">'.$podrazd['name'].'</a><br/>
<img src="/design/'
.($thema['top'] == 'prikrep':($thema['type'] == 'closed':'the')).'.png" alt="*"/> Тема: <a href="/forum/thema'.$thema['id'].'">'.$thema['name'].'</a> ('.$thema_p.') <a href="/forum/thema'.$thema['id'].'/page'.ceil($thema_p/10).'">></a><br/>'.$func->uNick($thema['author']).'/'.$func->uNick($thema['last_us']).' ('.t($thema['last']).')</div>';
}
echo 
'<div class="lst">';
$func->page('/thems'.$us['id']);
echo 
'</div>';
}
break;
# Посты юзера
case 'posts':
$us=DB::$dbs->queryFetch("SELECT * FROM `us` where `id` = ?",array($func->num($_GET['id'])));
if(!
$us['id']){
header('location:/forum');exit;
}
verh('Посты '.$us['nick'],'<a href="/forum" style="color:#ffffff;">Форум</a> | Посты '.$func->uNick($us['id']));
$posts DB::$dbs->querySingle("SELECT count(*) from `forum_post` where `us` = ? ".($cms->us['level']>0?NULL:'and `del` = '0'')."",array($us['id']));
echo 
'<div class="menu2">Вcего '.$posts.' постов</div>';
$num 10;
if(
$posts==0){
echo
'<div class="lst">'.$func->uNick($us['id']).' не оставлял постов на форуме!</div>';
}else{
$total intval(($posts 1) / $num) + 1;
$page abs(intval($_GET['page']));
if(empty(
$page) or $page 0$page 1;
if(
$page $total$page $total;
$start $page $num $num;
$posts DB::$dbs->query("SELECT * from `forum_post` where `us` = ? order by `id` desc limit $start,$num",array($us['id']));
while(
$post $posts->fetch()){
$thema=DB::$dbs->queryFetch("SELECT * FROM `forum_thema` where `id` = ?",array($post['thema']));
echo 
'<div class="lst"><img src="/design/'.($thema['top'] == 'prikrep':($thema['type'] == 'closed':'the')).'.png" alt="*"/> Тема: <a href="/forum/thema'.$thema['id'].'">'.$thema['name'].'</a><br/>
'
.$func->uNick($post['us']).' ('.t($post['time']).') (<font color="green">'.DB::$dbs->querySingle('select count(id) from `forum_post_vote` where (`thema`=? and `us`=? and `vote`="1" and `post`=?)',array($thema['id'],$post['us'],$post['id'])).'</font>/<font color="red">'.DB::$dbs->querySingle('select count(id) from `forum_post_vote` where (`thema`=? and `us`=? and `vote`="2" and `post`=?)',array($thema['id'],$post['us'],$post['id'])).'</font>)<br/>';
if(!empty(
$post['otv'])){
$otv DB::$dbs->queryFetch("SELECT * from `us` where `id` = ?",array($post['otv']));
if(!
$otv['id']) echo '<b>'.$otv['nick'].'</b>, ';
}
if(
$post['cit']){
$cit DB::$dbs->queryFetch("SELECT * from `forum_post` where `id` = ?",array($post['cit']));
echo 
'Цитата:<div class="cit">';
if(!
$cit['id'] or $cit['del']==1){ echo '<b>Сообщение удалено!</b>'; }else{
$cit_us DB::$dbs->queryFetch("SELECT * from `us` where `id` = ?",array($cit['us']));
if(
$cit['us'] == 0) echo '[Удалён]'; else echo '<font color="red"><b>'.$cit_us['nick'].'</b></font>: '.$func->text($cit['text']);
}
echo 
'</div>';
}
echo 
$func->text($post['text']).'</div>';
}
echo 
'<div class="lst">';
$func->page('/posts'.$us['id']);
echo 
'</div>';
}
break;
# Нарущение
case 'nar':
$page=$func->num($_GET['page']);
$post DB::$dbs->queryFetch("SELECT * FROM `forum_post` where `id` = ?",array($func->num($_GET['id'])));
if(
$post['del']!=0){
header('location:/forum/thema'.$post['thema']);
exit;
}
$thema DB::$dbs->queryFetch("SELECT * FROM `forum_thema` where `id` = ?",array($post['thema']));
$post_us DB::$dbs->queryFetch("SELECT * FROM `us` where `id` = ?",array($post['us']));
$thema_p DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ?".($cms->us['level']>0?NULL:'and `del`='0'')."",array($thema['id']));
verh('Запись нарушения',$thema['name']);
if(
$post['id'] && $post['us']==$cms->us['id'] && $post['del']==or $post['id'] && $cms->us['level']>&& $cms->us['level']>=$post_us['level'] && $post['del']==0){
if(
$thema['id'] && $thema['del']==0){
$post_usDB::$dbs->queryFetch("SELECT * FROM `us` where `id` = ?",array($post['us']));
echo 
'<div class="menu">'.$thema['name'].'</div><div class="list1">Сообщение:<div class="cit"><font color="red"><b>'.($post_us['id']?$post_us['nick']:'[Удален]').'</b></font>: '.$func->text($post['text']).'</div></div><div class="list1">
<form action="/forum/bn'
.$post['id'].'/page'.$page.'?ok" method="post">
Причниа:<br/><textarea name="text"></textarea><br/>
<input name="submit" type="submit" value="Добавить"/>
</form></div>'
;
if(isSet(
$_GET['ok'])){
$text secure($_POST['text']);
if(!
$text){
echo
'<div class="list1">Вы не ввели причину нарушения..</div>';
}else{
DB::$dbs->query("INSERT INTO `nar` set `us` = ?, `kem`=?, `why` = ?, `type` = ?, `time` = ?",array($post['us'],$cms->us['id'],$text,2,time()));
DB::$dbs->query("INSERT INTO `action` set `value` = ?, `t` = ?, `us` = ?, `see` = ?",array('[url=/us'.$cms->us['id'].']'.$cms->us['nick'].'[/url] записал вам [url=/nar'.$post['us'].']нарушение[/url]!',time(),$post['us'],1));
echo
'<div class="list1">Нарушение добавлено!</div>';
header('refresh:1; url=/forum/thema'.$thema['id'].'/page'.ceil($thema_p/10));

}
}
}else{
header('location:/forum');
}
}else{
header('location:/forum/thema'.$thema['id'].'/page'.ceil($thema_p/10));
}

break;
# Файлы темы
case 'filez':
$thema DB::$dbs->queryFetch("SELECT * FROM `forum_thema` where `id` = ?",array($func->num($_GET['id'])));
if(!
$thema['id'] or $thema['del']==1){
header('location:/');
exit;
}
$posts DB::$dbs->querySingle("SELECT count(`id`) from `forum_file` where `thema` = ?",array($thema['id']));
verh('В теме '.$posts.' файлов','В теме "'.$thema['name'].'" '.$posts.' файлов');
$num 10;
if(
$posts==0){
echo
'<div class="list1">В этой теме файлов нет!</div>';
}else{
$total intval(($posts 1) / $num) + 1;
$page abs(intval($_GET['page']));
if(empty(
$page) or $page 0$page 1;
if(
$page $total$page $total;
$start $page $num $num;
$files DB::$dbs->query("SELECT * from `forum_file` where `thema` = ? order by `id` desc limit $start,$num",array($thema['id']));
while(
$file $files->fetch()){
echo 
'<div class="list1">Файл: <a href="/files/forum/'.$file['name'].'">'.$file['name'].'</a> ('.round(filesize('./files/forum/'.$file['name'])/1024).'Kb)</div>';
}
echo 
'<div class="lst">';
$func->page('/forum/visit'.$thema['id'].'?');
echo 
'</div>';
}
echo 
'<div class="navg"><a href="/forum/thema'.$thema['id'].'">Вернуться</a></div>';
break;
# Добавление голосования
case 'op_add':
$th DB::$dbs->queryFetch("SELECT * FROM `forum_thema` where `id` = ?",array($func->num($_GET['thema'])));
$th_us DB::$dbs->queryFetch("SELECT * FROM `us` where `id` = ?",array($th_us['id']));
if(!
$th['id'] or $th['del']==or $thema['author']!=$cms->us['id'] && $cms->us['level']==or $thema['author']!=$cms->us['id'] && $cms->us['level']<$th_us['level']){
header('location:/forum?');
exit;
}
$thema_p DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ?".($cms->us['level']>0?NULL:'and `del`='0'')."",array($th['id']));
verh('Добавление голосования',$th['name']);

$op DB::$dbs->queryFetch("SELECT * FROM `forum_op` where `thema` = ?",array($th['id']));
if(
$op['id']){
echo 
'<div class="list1">В этой теме опрос уже существует!</div>';
}else{
echo 
'<div class="list1"><form action="/forum.php?mod=op_add&thema='.$th['id'].'&ok" method="post">
Вопрос:<br/><input type="text" name="vopros"/><br/>
Вариант ответа 1:<br/><input type="text" name="otv1"/><br/>
Вариант ответа 2:<br/><input type="text" name="otv2"/><br/>
Вариант ответа 3:<br/><input type="text" name="otv3"/><br/>
Вариант ответа 4:<br/><input type="text" name="otv4"/><br/>
Вариант ответа 5:<br/><input type="text" name="otv5"/><br/>
Вариант ответа 6:<br/><input type="text" name="otv6"/><br/>
Вариант ответа 7:<br/><input type="text" name="otv7"/><br/>
Вариант ответа 8:<br/><input type="text" name="otv8"/><br/>
<input type="submit" value="Добавить опрос"> <input type="button" value="Назад" onClick="history.go(-1);" />
</form></div>'
;
if(isset(
$_GET['ok'])){
$vopros=secure($_POST['vopros']);
if(!
$vopros){
echo 
'<div class="list1">Вы забыли написать вопрос!</div>';
}else{
$otv1=secure($_POST['otv1']);
$otv2=secure($_POST['otv2']);
$otv3=secure($_POST['otv3']);
$otv4=secure($_POST['otv4']);
$otv5=secure($_POST['otv5']);
$otv6=secure($_POST['otv6']);
$otv7=secure($_POST['otv7']);
$otv8=secure($_POST['otv8']);
DB::$dbs->query('insert into `forum_op` (`thema`,`vopros`) values (?,?)',array($th['id'],$vopros));
$op_id=DB::$dbs->lastInsertId();
if(
$otv1DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op_id,$otv1));
if(
$otv2DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op_id,$otv2));
if(
$otv3DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op_id,$otv3));
if(
$otv4DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op_id,$otv4));
if(
$otv5DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op_id,$otv5));
if(
$otv6DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op_id,$otv6));
if(
$otv7DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op_id,$otv7));
if(
$otv8DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op_id,$otv8));
header('location:/forum/thema'.$th['id'].'/page'.ceil($thema_p/10));
}
}
}
break;
# Добавление ответов в голосование
case 'vop_add':
$th DB::$dbs->queryFetch("SELECT * FROM `forum_thema` where `id` = ?",array($func->num($_GET['thema'])));
$th_us DB::$dbs->queryFetch("SELECT * FROM `us` where `id` = ?",array($th_us['id']));
if(!
$th['id'] or $th['del']==or $thema['author']!=$cms->us['id'] && $cms->us['level']==or $thema['author']!=$cms->us['id'] && $cms->us['level']<$th_us['level']){
header('location:/forum?');
exit;
}
$thema_p DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ?".($cms->us['level']>0?NULL:'and `del`='0'')."",array($th['id']));
verh('Добавление пунктов',$th['name']);

$op DB::$dbs->queryFetch("SELECT * FROM `forum_op` where `thema` = ?",array($th['id']));
if(!
$op['id']){
echo 
'<div class="list1">В этой теме нет голосования!</div>';
}else{
echo 
'<div class="list1"><form action="/forum.php?mod=vop_add&thema='.$th['id'].'&ok" method="post">
Вариант ответа 1:<br/><input type="text" name="otv1"/><br/>
Вариант ответа 2:<br/><input type="text" name="otv2"/><br/>
Вариант ответа 3:<br/><input type="text" name="otv3"/><br/>
Вариант ответа 4:<br/><input type="text" name="otv4"/><br/>
Вариант ответа 5:<br/><input type="text" name="otv5"/><br/>
Вариант ответа 6:<br/><input type="text" name="otv6"/><br/>
Вариант ответа 7:<br/><input type="text" name="otv7"/><br/>
Вариант ответа 8:<br/><input type="text" name="otv8"/><br/>
<input type="submit" value="Добавить варианты"/> <input type="button" value="Назад" onClick="history.go(-1);" />
</form></div>'
;
if(isset(
$_GET['ok'])){
$otv1=secure($_POST['otv1']);
$otv2=secure($_POST['otv2']);
$otv3=secure($_POST['otv3']);
$otv4=secure($_POST['otv4']);
$otv5=secure($_POST['otv5']);
$otv6=secure($_POST['otv6']);
$otv7=secure($_POST['otv7']);
$otv8=secure($_POST['otv8']);


if(
$otv1DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op['id'],$otv1));
if(
$otv2DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op['id'],$otv2));
if(
$otv3DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op['id'],$otv3));
if(
$otv4DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op['id'],$otv4));
if(
$otv5DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op['id'],$otv5));
if(
$otv6DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op['id'],$otv6));
if(
$otv7DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op['id'],$otv7));
if(
$otv8DB::$dbs->query('insert into `forum_op_otv` (`op`,`otv`) values (?,?)',array($op['id'],$otv8));
header('location:/forum/thema'.$th['id'].'/page'.ceil($thema_p/10));
}
}
break;
# Удаление ответов в голосовании
case 'redop':
$th DB::$dbs->queryFetch("SELECT * FROM `forum_thema` where `id` = ?",array($func->num($_GET['thema'])));
$th_us DB::$dbs->queryFetch("SELECT * FROM `us` where `id` = ?",array($th_us['id']));
if(!
$th['id'] or $th['del']==or $thema['author']!=$cms->us['id'] && $cms->us['level']==or $thema['author']!=$cms->us['id'] && $cms->us['level']<$th_us['level']){
header('location:/forum?');
exit;
}
$thema_p DB::$dbs->querySingle("SELECT count(id) from `forum_post` where `thema` = ?".($cms->us['level']>0?NULL:'and `del`='0'')."",array($th['id']));
verh('Удаление пунктов',$th['name']);

$op DB::$dbs->queryFetch("SELECT * FROM `forum_op` where `id` = ?",array($func->num($_GET['op'])));
if(!
$op['id']){
echo 
'<div class="list1">В этой теме нет голосования!</div>';
}else{


}
break;

}
niz();
?>
Онлайн: 0
Реклама