<?php
#-----------------------------------------------------#
# Зц Sea mod Ganjara                                  #
# 	 Автор : Slayer  with   Ganjar                    #
#    ICQ :   566003         993770                    #
#    Вы не имеете права распространять данный скрипт. #
# 		По всем вопросам пишите в ICQ.                  #
#-----------------------------------------------------#

define('_IN_JOHNCMS', 1);
$zc=1;
$headmod = 'load';
$textl = 'Топ';
require_once ("../incfiles/core.php");
require_once ("../incfiles/head.php");
$time = time();
$setting = mysql_query('SELECT * FROM `zc_setting`;');

while($set = mysql_fetch_assoc($setting)){
$setup[$set['name']] = $set['value'];
}

$hackmess = $setup['hackmess'];

require 'moduls/ini.php';
require 'moduls/fun.php';
###############Если топ выключен###############
if($setup['top_change'] == 0) die('Not found');
###############Проверка переменных###############

$onpage = get2ses('onpage');
$prew = get2ses('prew');
$sort = get2ses('sort');
$id = intval($_GET['id']);
$page = intval($_GET['page']);

is_num($onpage,'onpage');
is_num($prew,'prew');

if($prew != 0 and $prew != 1){
$prew = $setup['preview'];
}
if($_GET['open']==1 AND $setup['obm'] == 1) {$open=1; $endurl='&amp;open=1'; $endquery=' AND `open`=1';}else {$open=0; $endquery=' AND `open`=0';}

$valid_sort = array('load' => '','eval' =>'');
if(!isset($valid_sort[$sort])) $sort = 'load';
if($sort == 'load') $MODE = '`loads` > 0 AND `size` > 0 '.$endquery.' ORDER BY `loads` DESC';
if($sort == 'eval' and $setup['eval_change']) $MODE = '`yes` > 0 AND `size` > 0 '.$endquery.' ORDER BY `yes` DESC';
###############Готовим заголовок###################
if($setup['eval_change']==1) $eval = '<a href="top.php?sort=eval'.$endurl.'">рейтинг</a>'; else $eval='';
if ($sort == 'load') $sortlink = $eval;
if ($sort == 'eval' and $setup['eval_change']==1) $sortlink = '<a href="top.php?sort=load'.$endurl.'">популярность</a>';
###############Получаем список файлов###############
$query = mysql_query('SELECT * FROM `'.$setup['pref'].'files` WHERE '.$MODE.' LIMIT 0, '.$setup['top_num']);

while($list_sw = mysql_fetch_array($query)){
$array_id[] = $list_sw['id'];
}
$all = sizeof($array_id);
###############Вывод###############
echo '<div class="menu"><img src="dis/about.png" alt=""/>ТОП '.$setup['top_num'].' файлов: <br/>Сортировка: '.$sortlink.'</div>';
###############Cтраницы###############
if(!isset($page)) $page=1;
$n = 0;
$pages = ceil($all/$onpage);
if(!$pages) $pages = 1;
if ($page) $n = ($onpage*$page)-$onpage;
###############Если их нет...###########
if($all == 0) echo '<div class="list1">Пока пусто :(</div>';
###############Вывод списка#############
for($i=1; $i<=$onpage; $i++)
{
if(!isset($array_id[$n])){
$n++;
continue;
}
if(is_integer($n / 2)) $row = '<div class="list1">'; else $row = '<div class="list2">';
$file_info = mysql_fetch_array(mysql_query('SELECT * FROM `'.$setup['pref'].'files` WHERE `id` = '.$array_id[$n]));
$backdir = @mysql_fetch_array(mysql_query("SELECT * FROM `".$setup['pref']."files` WHERE `path` = '".clean($file_info['infolder'])."'"));
$basename = basename($file_info['path']);
$ex = pathinfo($file_info['path']);
$ext = strtolower($ex['extension']);
$name_file = str_replace('.'.$ex,'',$basename);
//Транслит
if(strpos($basename , '!') !== false){
$name_file = trans($name_file);
}
else{
$name_file = trans2($name_file);
}

//Красивый размер
if($file_info['size'] < 1024) $file_info['size'] = '('.$file_info['size'].'b)';
elseif($file_info['size'] < 1048576 and $file_info['size'] >= 1024) $file_info['size'] = '('.round($file_info['size']/1024, 2).'Kb)';
else $file_info['size'] = '('.round($file_info['size']/1024/1024, 2).'Mb)';

//Предосмотр
$pre='';
if($prew==1)
{
if($ext == 'bmp'){
$pre = 'Предосмотр невозможен<br/>';
}
elseif($ext == 'gif' or $ext == 'jpeg' or $ext == 'jpe' or $ext == 'jpg' or $ext == 'png'){
$pre = '<img style="margin: 1px;" src="im.php?bab=1&amp;id='.$file_info['id'].'" alt=""/><br/>';
}
}
$new_info='';
if ($sort=='load') $info = '[<font color="#FFFF00">'.$file_info['loads'].'</font>]';
if ($sort=='eval' and $setup['eval_change']==1) $info = '[<font color="#800000">'.$file_info['yes'].'</font>/<font color="#004080">'.$file_info['no'].'</font>]';
$filtime2 = $file_info['timeupload']+(3600*24*$setup['day_new']);
if($filtime2>=$time) $new_info = '(New)';
//Иконка к файлу
if(!file_exists("ext/$ext.png")) $ico = '<img src="ext/stand.png" alt=""/>'; else $ico = '<img src="ext/'.$ext.'.png" alt=""/>';
if($setup['ext']==1) $extension = '('.$ext.')'; else $extension = '';
//Собсвенно вывод
echo $row.$pre.' '.$ico.'<strong><a href="view.php?id='.$file_info['id'].'">'.($open==1?$file_info['name'].$file_info['tname']:$name_file).'</a></strong>'.$extension.$file_info['size'].$info.'[<a href="index.php?id='.$backdir['id'].$endurl.'">В категорию</a>]<br/></div>';
$n++;
}
//------------------------------------------------------------------------------------------
echo '
<div class="phdr">Страницы: ';
$asd = $page - 2;
$asd2 = $page + 3;
if($asd<$all && $asd>0 && $page>3) echo '<a href="top.php?page=1'.$endurl.'">1</a> ... ';
for($i=$asd; $i<$asd2;$i++)
{
if($i<$all && $i>0)
{
if ($i > $pages ) break;
if ($page==$i) 	echo '<strong>['.$i.']</strong> ';
else echo '<a href="top.php?page='.$i.$endurl.'">'.$i.'</a> ';
}
}

if ($i <= $pages)
{
if($asd2<$all) echo ' ... <a href="top.php?page='.$pages.$endurl.'">'.$pages.'</a>';
}
//------------------------------------------------------------------------------------------
echo '</div><div class="bmenu">';
//------------------------------------------------------------------------------------------
echo '<li><a href="index.php?'.$endurl.'">Загрузки</a></li>
<li><a href="'.$setup['site_url'].'">На главную</a></li>
';
echo '</div>';
require_once ("moduls/foot.php");
?>