<?php
define('MTOP', 1);
require_once ('system/connect.php');
require_once ('system/core.php');
require_once ('system/function.php');
switch($act){
default:
$title = 'Категории';
require_once ('head.php');
echo '<div class="title3"><b><a href="/index.php" class="open">TOP-100</a></b> <a href="/cat.php" class="open"><b>Категории</b></a></div>';
$cats = mysql_query("SELECT * FROM `cat` ORDER BY `position`");
while($cat = mysql_fetch_array($cats)){
$count_sites = mysql_num_rows(mysql_query("SELECT * FROM `sait` WHERE `category` = '".$cat['id']."' AND `status` = '1' AND `hosts` > '0'"));
echo '<div class = "title"><a class="link" href = "/cat.php?act=view&id='.$cat['id'].'">'.$cat['name'].'</a> <small>(Сайтов: '.$count_sites.')<br/>'.$cat['about'].'</small></div>';
}
break;

case 'view':
$isset = mysql_query("SELECT * FROM `cat` WHERE `id` = '".$id."'");
if(mysql_num_rows($isset) > 0){
$catt = mysql_fetch_array($isset);
$title = $catt['name'];
require_once ('head.php');
echo '<div class="title3">'.$catt['name'].'</div>';
$count = mysql_num_rows(mysql_query("SELECT * FROM `sait` WHERE `category` = '".$id."' AND `status` = '1' AND `hosts` > '0'"));
if($count > 0){
$total=intval(($count-1)/$page_sait)+1;
$page=abs(intval($_GET['page']));
if(empty($page) OR $page < 0) $page = 1;
if($page > $total) $page = $total;
$past=intval($count/$page_sait);
$start=$page*$page_sait-$page_sait;
$saits = mysql_query("SELECT * FROM `sait` WHERE `category` = '".$id."' AND `status` = '1' AND `ban` = '0' AND `hosts` > '0' ORDER BY `hosts` DESC LIMIT ".$start.",".$page_sait."");
while($row = mysql_fetch_array($saits)){
$start++;
echo '<div class="title">
<b><a href="/out/'.$row['id'].'.php"> '.$row['name'].'</a></b> (<b><a href="http://'.$set['home'].'/infos.php?id='.$row['id'].'">'.$row['hosts'].'/'.$row['hits'].'</a></b>)<br/>';
if(mb_strlen($row['about']) > 150){
$text = mb_substr($row['about'], 0, 150, 'utf-8');
echo ''.$text.'..';
}
else {
echo ''.$row['about'].'..';
}
echo '</div>';
}
navigation($count,$page_sait,$page,'cat.php?id='.$id.'&sort='.$sort.'&',$total);
}
else{
echo '<div class="title"><center>В данной категории нет активных сайтов</center></div>';
}
}
else{
$title = 'Ошибка';
require_once ('head.php');
echo '<div class="title3">Ошибка</div>';
echo '<div class="title"><center>Данной категории не существует</center></div>';
}
break;
}
require_once ('foot.php');
?>
