Файл: forum/section.php
Строк: 89
<?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_section` where `id` = '".$id."' ");
if(!$p){
$tmp->div('block', Language::config('error'));
$tmp->div('block', '<a href="/forum/'.$p['razdel'].'">'.Language::config('back').'</a>');
$tmp->footer();
exit();
}
$r=$db->fass("select * from `forum_razdel` where `id` = '".$p['razdel']."'");
$tmp->div('title', Language::config('forum').' / '.$r['name'].' / '.$p['name']);
User::panel();
if(User::level() >=3){
if(isset($_GET['d']))
{
$db->query("DELETE FROM `forum_section` where `id` = '".$id."' limit 1 ");
$db->query("DELETE FROM `forum_topic` where `section` = '".$id."' ");
$db->query("DELETE FROM `forum_message` where `section` = '".$id."'");
header('location : /forum/'.$p['razdel']);
}
}
if(isset($_GET['nt'])){
if(isset($_REQUEST['submit'])){
$name = $db->guard($_POST['name']);
$message = $db->guard($_POST['message']);
if(empty($name)){
$error .= Language::config('error');
}
if(empty($message)){
$error .= Language::config('error');
}
if(!isset($error)){
$db->query("insert into `forum_topic` set `razdel` = '".$p['razdel']."', `section` = '".$p['id']."', `kto` = '".User::ID()."', `name` = '".$name."', `time` = '".time()."', `last_message_time` = '".time()."' ");
$lid = $db->insert_id();
$db->query("insert into `forum_message` set `razdel` = '".$p['razdel']."', `section` = '".$p['id']."', `topic` = '".$lid."', `kto` = '".User::ID()."', `message` = '".$message."', `time` = '".time()."' ");
header('location: /forum/topic'.$lid);
}
}
$tmp->div('menu', '<form method="POST" action="">
'.Language::config('name').':<br/>
<input type="text" name="name" value="'. out($_POST['name']) .'" /><br/>
'.Language::config('message').':<br/>
<textarea name="message"></textarea><br />
<input type="submit" name="submit" value="'.Language::config('add').'" /></form>');
$tmp->footer();
exit();
}
$count=$db->fass("SELECT COUNT(id) as count FROM `forum_topic` where `section` = '".$id."' ");
$posts=$count['count'];
if($posts==0){
$tmp->div('block', Language::config('no_topics'));
$tmp->div('block', '<a href="/forum/'.$p['razdel'].'/'.$p['id'].'?nt">'.Language::config('new_topic').'</a>');
if(User::profile('level') >=3){
$tmp->div('error', '<a href="/forum/'.$p['id'].'/'.$id.'?d&id='.$id.'">'.Language::config('delete_section').'</a>');
}
$tmp->div('block', '<a href="/forum/'.$p['razdel'].'">'.Language::config('back').'</a>');
$tmp->footer();
exit();
}
$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;
$f= $db->query("SELECT * FROM `forum_topic` where `section` = '".$id."' ORDER BY id ASC LIMIT ".$start.", ".$num." ");
$tmp->div('block', '<a href="/forum/'.$p['razdel'].'/'.$p['id'].'?nt">'.Language::config('new_topic').'</a>');
while($fo=$f->fetch_assoc())
{
$c=$db->fass("SELECT COUNT(id) as count FROM `forum_message` where `topic` = '".$fo['id']."'");
$tmp->div('block', '<a href="/forum/topic'.$fo['id'].'">'.$fo['name'].' ('.$c['count'].')</a>');
}
page('?');
if(User::profile('level') >=3){
$tmp->div('error', '<a href="/forum/'.$p['id'].'/'.$id.'?d&id='.$id.'">'.Language::config('delete_section').'</a>');
}
$tmp->div('block', '<a href="/forum/'.$p['razdel'].'">'.Language::config('back').'</a>');
$tmp->footer();
?>