<?php
define('ROOT','../');
define('GCMS',true);
require_once (ROOT.'system/power.php');
//Бан на форуме
$ban = $db -> query("SELECT * FROM `ban` WHERE `iduser` = '".$ya['id']."' and `serius` = 'forum' LIMIT 1");
if ($ban -> num_rows > 0) {
header('location: '.ROOT.'ban.php?mode=forum');
}
if ($id) {
$type = $db -> query("SELECT `id`,`name`,forum FROM `forum_razdel` WHERE `id` = '".$id."'");
if ($type -> num_rows > 0) $the = $type -> fetch_assoc(); else $the = false;
} else $the = false;
//Выводим темы
$diz -> head('Форум');
require_once (ROOT.'/new_mail.php');
$f_name = $db -> dbcount('name','forums',"`id` = '".$the['forum']."'");
$diz -> title("<a href='./'>Форум</a>/<a href='forum.php?id=$the[forum]'>".$f_name."</a>/<b>".$the['name']."</b>");
if ($type -> num_rows > 0){
$count = $db -> dbcount('COUNT(`id`)','forum_tems',"`razdel` = '".$id."'");
$msg .= '<div class="end">Темы:</div>';
if ($count > 0) {
$num = isset($ya['num']) ? $ya['num'] : 10;
$total = intval(($count - 1) / $num) + 1; 
if (!isset($_GET['page']) || !is_numeric($_GET['page']) || $_GET['page'] < 1 )
{
$page = 1;
} elseif($_GET['page'] > $total)
{ $page = $total;
} else $page = (int)$_GET['page'];
$start = $page * $num - $num;
$for = $db -> query("SELECT * FROM `forum_tems` WHERE `razdel` = '".$id."' and `var`=1  ORDER BY `uptime` DESC  LIMIT ".$start.",".$num);
while ($assoc = $for -> fetch_assoc()) {
$p = $db -> query("SELECT * FROM `forum_posts` WHERE `tema` = '".$assoc['id']."'")-> fetch_assoc();

$col = $db -> dbcount('COUNT(`id`)','golos',"`where`='forum' and `id_w` = '".$assoc['id']."'");
if($col>0){$st=$diz -> img('golos.png');}else{$st=null;}
if($assoc['status']==0){$status =''.$diz -> img('r.png').' '.$st.'';}
elseif($assoc['status']==1){$status=''.$sta.''.$diz -> img('close.png').''.$st.'';}

$usmax = $db -> dbcount('max(`id`)','forum_posts','`tema`='.$assoc['id'].'');
$max = $db -> query("SELECT * FROM `forum_posts` where `id`='$usmax'")-> fetch_assoc();
$usmin = $db -> dbcount('min(`id`)','forum_posts','`tema`='.$assoc['id'].'');
$min = $db -> query("SELECT * FROM `forum_posts` where `id`='$usmin'")-> fetch_assoc();
$user = $db -> query("SELECT * FROM `users` where `id`='".$max['user']."' ")-> fetch_assoc();
$autor = $db -> query("SELECT * FROM `users` where `id`='".$min['user']."' ")-> fetch_assoc();
$cid = $db -> dbcount('COUNT(`id`)','forum_posts'," `tema` = '".$assoc['id']."'");
$tot = intval(($cid - 1) / $num) + 1;
$msg .= '<div class="spisok">'.$diz -> img('zak.png').''.$status.' <a href="tema'.$assoc['id'].'">'.$assoc['name'].'</a>('.$cid.')
<a href="tema.php?id='.$assoc['id'].'&amp;page='.$tot.'">>></a><br/>
<a href="../my/id'.$autor['id'].'">'.$autor['login'].'</a>/<a href="../my/id'.$user['id'].'">'.$user['login'].'</a> ('.$func -> vremja($max['time']).')</div>';
}
$for = $db -> query("SELECT * FROM `forum_tems` WHERE `razdel` = '".$id."' and `var`=0  ORDER BY `uptime` DESC  LIMIT ".$start.",".$num);
while ($assoc = $for -> fetch_assoc()) {
$p = $db -> query("SELECT * FROM `forum_posts` WHERE `tema` = '".$assoc['id']."'")-> fetch_assoc();

$col = $db -> dbcount('COUNT(`id`)','golos',"`where`='forum' and `id_w` = '".$assoc['id']."'");
if($col>0){$st=$diz -> img('golos.png');}else{$st=null;}
if($assoc['status']==0){$status =''.$diz -> img('r.png').' '.$st.'';}
if($assoc['var']==1){$sta =''.$diz -> img('zak.png').'';}
elseif($assoc['status']==1){$status=''.$sta.''.$diz -> img('close.png').''.$st.'';}

$usmax = $db -> dbcount('max(`id`)','forum_posts','`tema`='.$assoc['id'].'');
$max = $db -> query("SELECT * FROM `forum_posts` where `id`='$usmax'")-> fetch_assoc();
$usmin = $db -> dbcount('min(`id`)','forum_posts','`tema`='.$assoc['id'].'');
$min = $db -> query("SELECT * FROM `forum_posts` where `id`='$usmin'")-> fetch_assoc();
$user = $db -> query("SELECT * FROM `users` where `id`='".$max['user']."' ")-> fetch_assoc();
$autor = $db -> query("SELECT * FROM `users` where `id`='".$min['user']."' ")-> fetch_assoc();
$cid = $db -> dbcount('COUNT(`id`)','forum_posts'," `tema` = '".$assoc['id']."'");
$tot = intval(($cid - 1) / $num) + 1;
$msg .= '<div class="spisok">'.$status.' <a href="tema'.$assoc['id'].'">'.$assoc['name'].'</a>('.$cid.')
<a href="tema.php?id='.$assoc['id'].'&amp;page='.$tot.'">>></a><br/><a href="../my/id'.$autor['id'].'">'.$autor['login'].'</a>/<a href="../my/id'.$user['id'].'">'.$user['login'].'</a> ('.$func -> vremja($max['time']).')</div>';
}
$act = 'razdel.php?id='.$id;
$msg .= ''.$func -> pagenav($act,$page,$total).'';
} else {
$msg.='<div class="fon">Нет созданных тем!</div>';
}
}else{$msg.='<div class="fon">Раздел не существует!</div>';}
if ($aut) $msg .= '<div class="tochechki"><a href="newtheme.php?id='.$id.'">Новая тема</a></div>';
require_once ('foot.php');
$msg .= '<div class="levo">'.$diz -> img('home.png').'<a href="/index.php">На главную</a></div>';
#####Копирайт#######
require_once (ROOT.'system/kopy.php');
$diz -> out($msg);
?>