Файл: forum/topic.php
Строк: 93
<?php
define('R', $_SERVER['DOCUMENT_ROOT']);
define('S', R.'/system');
require_once(R.'/system/kernel.php');
$id = $db->guard($_GET['id']);
$tmp->header('forum');
$p=$db->fass("select * from `forum_topic` where `id` = '".$id."' "); //проверяем, существует ли наш раздел
if(!$p){
$tmp->div('block', Language::config('no_topic'));
$tmp->footer();
exit();
}
$s=$db->fass("select * from `forum_section` where `id` = '".$p['section']."'");
$r=$db->fass("select * from `forum_razdel` where `id` = '".$p['razdel']."'");
$tmp->div('title', Language::config('forum').' / '. $r['name'].' / '.$s['name']. ' / '.$p['name']);
User::panel();
$count=$db->fass("SELECT COUNT(id) as count FROM `forum_message` where `topic` = '".$id."'"); //считаем количество
$posts=$count['count'];
$total = (($posts-1)/$num)+1;
$total = intval($total);
$page = intval($page);
if(empty($page) or $page<0) $page=1;
if($page>$total) $page=$total;
$start=$page*$num-$num;
if(isset($_GET['del']))
{
$del = $db->guard($_GET['del']);
$c=$db->fass("SELECT * FROM `forum_message` where `id` ='".$del."'");
if(!$c){
$tmp->div('block', Language::config('error'));
$tmp->footer();
exit();
}
if($c['kto'] == User::ID() || User::profile('level') >=3)
$db->query("DELETE FROM `forum_message` where `id` ='".$del."'");
header('location: /forum/topic'.$id);
}
if(isset($_GET['otv'])){
$o = $db->guard($_GET['otv']);
$ot=$db->fass("SELECT * FROM `forum_message` where `id` = '".$o."'");
if(!$ot){
$tmp->div('block', Language::config('error'));
$tmp->footer();
exit();
}
if($ot['kto'] != User::ID()){
if(isset($_REQUEST['submit']))
{
$message = $db->guard($_POST['message']);
if(empty($_POST['message']) )
{
$error .= Language::config('error');
}
if( mb_strlen($_POST['message'], 'UTF-8')<2)
{
$error .= Language::config('error');
}
if(!isset($error))
{
$db->query("insert into `forum_message` set `razdel` = '".$p['razdel']."', `section` = '".$p['section']."', `topic` = '".$id."', `kto` = '".User::ID()."', `message``message` = '[b]".notv($ot['kto'])."[/b], ".$message."', `time` = '".time()."' ");
header('location: /forum/topic'.$id);
}
}
$tmp->div('block', bb(smile($ot['message'])));
error($error);
$tmp->div('menu', '<form method="POST" action="">
'.Language::config('message').':<br/>
<textarea name="message" ></textarea><br />
<input type="submit" name="submit" value="'.Language::config('send').'" /></form>');
$tmp->div('menu', '<a href="/forum/topic'.$id.'">'.Language::config('back').'</a>');
$tmp->footer();
exit();
}
else{
header('location: /forum/topic'.$id);
}
}
if(isset($_REQUEST['submit']))
{
$message = $db->guard($_POST['message']);
if(empty($_POST['message']) )
{
$error .= Language::config('error');
}
if( mb_strlen($_POST['message'], 'UTF-8')<2)
{
$error .= Language::config('error');
}
if(!isset($error))
{
$db->query("insert into `forum_message` set `razdel` = '".$p['razdel']."', `section` = '".$p['section']."', `topic` = '".$id."', `kto` = '".User::ID()."', `message` = '".$message."', `time` = '".time()."' ");
$db->query("update `forum_topic` set `last_message_time` = '".time()."' where `id` = '".$id."' ");
header('location: /forum/topic'.$id);
}
}
error($error);
$tmp->div('menu', '<a href="/forum/topic'.$id.'?'.rand(101, 999).' ">'.Language::config('refresh').'!</a> ');
$tmp->div('menu', '<form method="POST" action="">
'.Language::config('message').':<br/>
<textarea name="message"></textarea><br />
<input type="submit" name="submit" value="'.Language::config('send').'" /></form>');
$f= $db->query("SELECT * FROM `forum_message` where `topic` = '".$id."' ORDER BY time ASC LIMIT ".$start.", ".$num." ");
if($posts==0){
$tmp->div('block', Language::config('no_messages'));
$tmp->div('block', '<a href="/forum">'.Language::config('back').'</a>');
$tmp->footer();
exit();
}
else{
while($fo=$f->fetch_assoc())
{
$tmp->div('block', nick($fo['kto'], true).' ('. times($fo['time']).') '.(($fo['kto'] == User::ID() || User::profile('level') >=3) ? '<a href="/forum/topic'.$id.'/delete'.$fo['id'].'">['.Language::config('del').']</a>' : NULL) .' '.(($fo['kto'] != User::ID() ) ? '<a href="/forum/topic'.$id.'/replay'.$fo['id'].'">['.Language::config('otv').']</a>' : NULL ).'</br> '.bb(smile($fo['message'])));
}
page('?');
$tmp->div('block', '<a href="/forum/'.$p['razdel'].'/'.$p['section'].'">'.Language::config('back').'</a>');
}
$tmp->footer();
?>