<?php
define('NTOP', 1);
$title = 'Категории';
require_once ('../system/connect.php');
require_once ('../system/core.php');
require_once ('../system/function.php');
require_once ('head.php');
switch($act){
default:
$count_mod = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait` WHERE `status` = '0' AND `ban` = '0' AND `hosts` > '0'"));
$top = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait` WHERE `status` = '1' AND `ban` = '0' AND `hosts` > '0'"));
$kk = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait` WHERE `ban` = '0' AND `hosts` > '0' AND `status` = '1' AND `plus` >= '15'"));
echo '<div class="topik">Разделы сайтов</div>';
$cats = mysql_query("SELECT * FROM `".$prefix."cat` ORDER BY `id`");
echo'<div class="rek"><a href="/index.php" ><b>Top 100</b></a>  ('.$top.')<br>
<a href="/str/cat.php?act=mod" ><b>Новые сайты</b></a> ('.$count_mod.')<br>
<a href="/str/vip.php"><b>Vip сайты</b></a> ('.$kk.')</div><div class="stat">';
while($cat = mysql_fetch_array($cats)){
$count_sites = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait` WHERE `category` = '".$cat['id']."' AND `status` = '1' AND `hosts` > '0'"));
echo '<img src="/images/icon.png" alt=""> <a href = "/str/cat.php?act=view&id='.$cat['id'].'">'.$cat['name'].'</a>
('.$count_sites.')<br>';}
echo'</div>';
break;

case 'view':
if($_COOKIE['version'] == 'web'){
$count = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait` WHERE `category` = '".$id."' AND `status` = '1' AND `ban` = '0' AND `hosts` > '0'"));
if($count == 0){
echo '<div class="stat">Сайтов в данной категории нет!<br><a href="/str/cat.php">К списку категорий</a></div>';
exit;
}
$isset = mysql_query("SELECT * FROM `".$prefix."cat` WHERE `id` = '".$id."'");
if(mysql_num_rows($isset) == 0){
echo '<div class="stat">Ошибка!Данной категории не существует!<br><a href="/str/cat.php">К списку категорий</a></div>';
exit;
}
$catt = mysql_fetch_array($isset);
echo '<table class="stata"><tr>
                	<th class="left0 top0">#</th>
                	<th class="top0">Сайты из категории '.$catt['name'].'</th>
                	<th class="top0">Хосты</th>
                	<th class="top0">Хиты</th>
                	<th class="top0">В топ</th>
                	<th class="top0">Из</th>
                	<th class="right0 top0">?</th></tr>';

$total=intval(($count-1)/15)+1;
$page=abs(intval($_GET['page']));
if(empty($page) OR $page < 0){
$page = 1;
}
if($page > $total){
$page = $total;
}
if($sait or $sait >= 1){
$result = mysql_query("SELECT `hosts` FROM `".$prefix."sait` WHERE `id` = '".$sait."' AND `category` = '".$id."' AND `status` = '1' AND `ban` = '0' AND `hosts` > '0' LIMIT 1;");
$row = mysql_fetch_array($result);
$host_today = $row['hosts'];
$topt = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait` WHERE `category` = '".$id."' AND `status` = '1' AND `ban` = '0' AND `hosts`>= '".$host_today."' ORDER BY `hosts` DESC;"));
$page = ceil($topt/20);
}
$past=intval($count/20);
$start=$page*20-20;
$saits = mysql_query("SELECT * FROM `".$prefix."sait` WHERE `category` = '".$id."' AND `status` = '1' AND `ban` = '0' AND `hosts` > '0' ORDER BY `hosts` DESC LIMIT ".$start.",20");
while($row = mysql_fetch_array($saits)){
$start++;
echo '<tr class="tr2"><td class="num bold left0">'.$start.'</td>';
if($row['id'] == $sait){
echo'<td class="site"><a href="/out.php?id='.$row['id'].'"><font color="red">'.$row['url'].'</font></a>';
} else {
echo'<td class="site"><a href="/out.php?id='.$row['id'].'">'.$row['url'].'</a>';
}
echo'<br><small>'.$row['about'].'</small></td>
<td>'.stats($row['hosts']).'</td>
<td>'.stats($row['hits']).'</td>
<td>'.$row['in'].'</td>
<td>'.$row['out'].'</td>';
if($row['mem'] == 0){echo'<td class="more right0"><a href="/str/infos.php?id='.$row['id'].'"><img src="/images/s.gif" alt="?" style="padding:2px;padding-top:4px;"></a></td></tr>';
}else{echo'<td class="more right0"><img src="/images/d.gif" alt="?" style="padding:2px;padding-top:4px;"></td></tr>';}}
echo'</table>';
navigation($count,20,$page,'/str/cat.php?act=view&id='.$id.'&',$total);

}else{

$isset = mysql_query("SELECT * FROM `".$prefix."cat` WHERE `id` = '".$id."'");
if(mysql_num_rows($isset) > 0){
$catt = mysql_fetch_array($isset);
echo '<div class="topik"><a href="/str/cat.php">В категории</a>: '.$catt['name'].'</div>';

$count = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait` WHERE `category` = '".$id."' AND `status` = '1' AND `ban` = '0' AND `hosts` > '0'"));
if($count > 0)
{
$total=intval(($count-1)/$page_sait)+1;
$page=abs(intval($_GET['page']));
if($sait OR $sait >= 1){
$result = mysql_query("SELECT `hosts` FROM `".$prefix."sait` WHERE `id` = '".$sait."' AND `category` = '".$id."' AND `status` = '1' AND `ban` = '0' AND `hosts` > '0' LIMIT 1;");
$row = mysql_fetch_array($result);
$host_today = $row['hosts'];
$topt = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait` WHERE `status` = '1' AND `category` = '".$id."' AND `ban` = '0' AND `hosts`>= '".$host_today."' ORDER BY `hosts` DESC;"));
$page = ceil($topt/$page_top);
}
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 `".$prefix."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)){
if($row['id'] == $sait){
$start++;
echo '<div class="ico"><b><font color="red"><div class="topni">'.$start.'.</font></b> <a href="/out.php?id='.$row['id'].'"><span class="site"><b><font color=red>'.$row['url'].'</font></b></span></a> <small><b>('.$row['hosts'].'/'.$row['hits'].'</b>';
//echo <b>($row['hits'] > 999 ? round($row['hits']/1000).'К' : $row['hits'])</b>;
if($row['mem'] == 0){
echo'<b>)</b></small> <a href="/str/infos.php?id='.$row['id'].'"><img src="/images/s.gif" alt="?"></a>';}else{echo'<b>)</b></small> <img src="/images/d.gif" alt="*"></div>';}
} else {
$start++;
echo '<div class="ico"><b><font color="red"><div class="topni">'.$start.'.</b></font> <a href="/out.php?id='.$row['id'].'"><span class="site"><b>'.$row['url'].'</b></span></a> <small><b>('.$row['hosts'].'/'.$row['hits'].'</b>';
//echo <b>($row['hits'] > 999 ? round($row['hits']/1000).'К' : $row['hits'])</b>;
if($row['mem'] == 0){
echo'<b>)</b></small> <a href="/str/infos.php?id='.$row['id'].'"><img src="/images/s.gif" alt="?"></a>';}else{echo'<b>)</b></small> <img src="/images/d.gif" alt="*">';}}
echo'<div class="info">'.$row['about'].'</div></div></div>';

}
navigation($count,$page_sait,$page,'/str/cat.php?act=view&id='.$id.'&',$total);
}else{
echo '<div class="stat">';
echo 'Сайтов в данной категории нет!<br/>';
echo '<a href="/str/cat.php">К списку категорий</a><br/>';
echo '</div>';
}}else{
echo '<div class="stat">';
echo 'Ошибка!Данной категории не существует!<br/>';
echo '<a href="/str/cat.php">К списку категорий</a><br/>';
echo '</div>';
}}
break;
case 'mod':
if($_COOKIE['version'] == 'web'){

echo '<table class="stata"><tr>
                	<th class="left0 top0">#</th>
                	<th class="top0">Сайты из категории На модерации</th>
                	<th class="top0">Хосты</th>
                	<th class="top0">Хиты</th>
                	<th class="top0">В топ</th>
                	<th class="top0">Из</th>
                	<th class="right0 top0">?</th></tr>';
$isset = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait` WHERE `status` = '0' AND `hosts` > '0' AND `ban` = '0'"));
if($isset != 0){
$total=intval(($isset-1)/15)+1;
$page=abs(intval($_GET['page']));
if(empty($page) OR $page < 0){
$page = 1;
}
if($page > $total){
$page = $total;
}
if($id OR $id >= 1){
$result = mysql_query("SELECT `hosts` FROM `".$prefix."sait` WHERE `id` = '".$id."' AND `status` = '0' AND `ban` = '0' AND `hosts` > '0' LIMIT 1;");
$row = mysql_fetch_array($result);
$host_today = $row['hosts'];
$topt = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait` WHERE `status` = '0' AND `ban` = '0' AND `hosts`>= '".$host_today."' ORDER BY `hosts` DESC;"));
$page = ceil($topt/20);
}
$past=intval($isset/20);
$start=$page*20-20;
$saits = mysql_query("SELECT * FROM `".$prefix."sait` WHERE `status` = '0' AND `hosts` > '0' AND `ban` = '0' ORDER BY `hosts` DESC LIMIT ".$start.",20");
while($row = mysql_fetch_array($saits)){
$start++;
echo '<tr class="tr2"><td class="num bold left0">'.$start.'</td>';
if($row['id'] == $sait){
echo'<b><td class="site"><a href="/out.php?id='.$row['id'].'"><font color="red">'.$row['url'].'</b></font></a>';
} else {
echo'<b><td class="site"><a href="/out.php?id='.$row['id'].'">'.$row['url'].'</b></a>';
}
echo'<br><small>'.$row['about'].'</small></td>
<td>'.stats($row['hosts']).'</td>
<td>'.stats($row['hits']).'</td>
<td>'.$row['in'].'</td>
<td>'.$row['out'].'</td>';
if($row['mem'] == 0){echo'<td class="more right0"><a href="/str/infos.php?id='.$row['id'].'"><img src="/images/s.gif" alt="?" style="padding:2px;padding-top:4px;"></a></td></tr>';
}else{echo'<td class="more right0"><img src="/images/d.gif" alt="?" style="padding:2px;padding-top:4px;"></td></tr>';}}
echo'</table>';
navigation($isset,20,$page,'/str/cat.php?act=mod&',$total);
} else {
echo '<div class="stat">Сайтов в данной категории нет!<br/>
<a href="/str/cat.php">К списку категорий</a></div>';}

}else{

echo '<div class="topik"><a href="/str/cat.php">В категории</a>: Новые</div>';
$isset = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait` WHERE `status` = '0' AND `hosts` > '0' AND `ban` = '0'"));
if($isset != 0){
$total=intval(($isset-1)/$page_sait)+1;
$page=abs(intval($_GET['page']));
if(empty($page) OR $page < 0){
$page = 1;
}
if($page > $total){
$page = $total;
}
if($id OR $id >= 1){
$result = mysql_query("SELECT `hosts` FROM `".$prefix."sait` WHERE `id` = '".$id."' AND `status` = '0' AND `ban` = '0' AND `hosts` > '0' LIMIT 1;");
$row = mysql_fetch_array($result);
$host_today = $row['hosts'];
$topt = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait` WHERE `status` = '0' AND `ban` = '0' AND `hosts`>= '".$host_today."' ORDER BY `hosts` DESC;"));
$page = ceil($topt/$page_sait);
}
$past=intval($isset/$page_sait);
$start=$page*$page_sait-$page_sait;
$saits = mysql_query("SELECT * FROM `".$prefix."sait` WHERE `status` = '0' AND `hosts` > '0' AND `ban` = '0' ORDER BY `hosts` DESC LIMIT ".$start.",".$page_sait."");
while($row = mysql_fetch_array($saits)){
if($row['id'] == $id){
$start++;
echo '<b><font color="red"><div class="topni">'.$start.'.</b></font> <b><a href="/out.php?id='.$row['id'].'"><span class="site"><b><font color=red>'.$row['url'].'</font></b></span></a> <small>('.$row['hosts'].'/'.$row['hits'].'</b>';
//echo <b>($row['hits'] > 999 ? round($row['hits']/1000).'К' : $row['hits'])</b>;
if($row['mem'] == 0){
echo'<b>)</b></small> <a href="/str/infos.php?id='.$row['id'].'"><img src="/images/s.gif" alt="?"></a>';}else{echo'<b>)</b></small> <img src="/images/d.gif" alt="*">';}
} else {
$start++;
echo '<b><font color="red"><div class="topni">'.$start.'.</b></font><b> <a href="/out.php?id='.$row['id'].'"><span class="site">'.$row['url'].'</span></a> <small>('.$row['hosts'].'/'.$row['hits'].'</b>';
//echo <b>($row['hits'] > 999 ? round($row['hits']/1000).'К' : $row['hits'])</b>;
if($row['mem'] == 0){
echo'<b>)</b></small> <a href="/str/infos.php?id='.$row['id'].'"><img src="/images/s.gif" alt="?"></a>';}else{echo'<b>)</b></small> <img src="/images/d.gif" alt="*">';}}
echo'<div class="info">'.$row['about'].'</div></div>';
}
navigation($isset,$page_sait,$page,'/str/cat.php?act=mod&',$total);
} else {
echo '<div class="stat">Сайтов в данной категории нет!<br/>
<a href="/str/cat.php">К списку категорий</a></div>';
}}
break;
}

require_once ('foot.php');
?>