<?php
define('ROOT','../');
define('GCMS',true);
require_once (ROOT.'system/power.php');
$diz -> head('Загрузки');
$diz -> title('<b>Загрузки</b>');
if($aut==true){
$dir = $db -> query("SELECT * from `load_cat` where `id`='".$id."'")-> fetch_assoc();
$p = $db -> dbcount('COUNT(*)','load_files','`dateupload` > '.(time()-86400).'');
if ($p==0)$p=0;
else $p=$p;
$my = $db -> dbcount('COUNT(*)','load_files','`user` = '.$ya['id'].'');
if($aut==true){$msg .= '<div class="levo">'.$diz -> img('load/new.gif').' <a href="new.php">Новые файлы</a> (<span style="color:red">'.$p.'</span>)</br>
'.$diz -> img('load/edit.gif').' <a href="upload.php">Загрузить файл</a></br>
'.$diz -> img('load/my_load.png').' <a href="./my_load.php?id='.$ya['id'].'">Мои файлы</a> ('.$my.')</br>
'.$diz -> img('load/poisk.png').' <a href="./poisk.php">Поиск файлов</a></div>';}
if ($id) {$count = $db -> dbcount('COUNT(`id`)','load_files','`cat`='.$id.'');}else{
///====================
$count = $db -> dbcount('COUNT(`id`)','load_cat');}
$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;
////==================
$sqli = $db -> query("SELECT `id` FROM `load_cat` WHERE `id` = '".$id."' LIMIT 1");
if ($id!="" and $sqli -> num_rows == 0){$msg .='Папка не существует!';}else{
if ($id=='0' or $id=="") {
$sql2 = $db -> query("SELECT * from `load_cat` ORDER BY `sid` ASC LIMIT ".$start.",".$num);
if($count>0){
$i=1;
while ($row2 = $sql2 -> fetch_assoc()) {
$fz = $db -> dbcount('COUNT(*)','load_files','`cat` = '.$row2['id'].'');
$fzn = $db -> dbcount('COUNT(*)','load_files','`cat` = '.$row2['id'].' and `dateupload` > '.(time()-86400).'');
if ($fzn==0)$fzn=NULL;
else $fzn='+ '.$fzn;
if($ya['level']>=4){$adm='[<a href="func.php?mode=redraz&amp;id='.$row2['id'].'">Изменить</a>] | [<a href="func.php?mode=delr&amp;id='.$row2['id'].'">Удалить</a>]';}
$msg .='<div class="spisok">'.$diz -> img('load/'.$row2['icon'].'').' <a href="index.php?id='.$row2['id'].'">'.htmlspecialchars(str_replace('*', '', $row2['name'])).'</a> ('.$fz.''.$fzn.') '.$adm.'</div>';
                                     }
}else{$msg .='<div class="fon">Папки пока не созданы</div>';}}
if ($id) {
$sql = $db -> query("SELECT * from `load_files` where `cat`='$id' ORDER BY `dateupload` DESC LIMIT ".$start.",".$num);
$count2 = $db -> dbcount('COUNT(`id`)','load_files',"`cat`='$id'");
if($count2>0){
	while ($row = $sql -> fetch_assoc()) {		
			$ext = strtolower(pathinfo($row['infolder'], PATHINFO_EXTENSION));
$filename = pathinfo($row['infolder'], PATHINFO_BASENAME);
if ($ext == 'gif' || $ext == 'jpeg' || $ext == 'jpg' || $ext == 'png') {
$type=''.$diz -> img('load/img.gif').'';
}
else if ($ext == 'mp3' || $ext == 'wav') {
$type=''.$diz -> img('load/mp3.gif').'';
}
else if ($ext == 'jar') {
$type=''.$diz -> img('load/jar.png').'';
}
else if ($ext == 'txt') {
$type=''.$diz -> img('load/byb.gif').'';
}
else if ($ext == '3gp' || $ext == 'avi' || $ext == 'mp4' || $ext == 'flv') {
$type=''.$diz -> img('load/video.gif').'';
}
else if ($ext == 'rar') {
$type=''.$diz -> img('load/rar.png').'';
}
else if ($ext == 'zip') {
$type=''.$diz -> img('load/zip.png').'';
}
else {
$type=''.$diz -> img('load/other.gif').'';
}
$msg .= '<div class="post">'.$type.' <a href="./view/'.$row['id'].'/">'.htmlspecialchars($row['name']).'</a> ('.$func -> size(filesize($row['infolder'])).')<br/>	</table></div>';
	}
 }else{$msg .='<div class="fon">Файлов в данной папке пока нет!</div>';}
 }
if ($id) {$act = 'index.php?id='.$id.'';
}else{$act = 'index.php?';}
if($aut==true){
$msg .= $func -> pagenav($act,$page,$total);}
unset($sql);
}
$u = $db -> query("SELECT * from `load_cat` where `id`='$id'")-> fetch_assoc();
if($id!='0'){$msg .= '<div class="levo">'.$diz -> img('back.png').' <a href="./?id='.$u['ifcat'].'">Назад</a></div>';}
if ($id=='0' or $id=="") {
if($ya['level']>=4){$msg .= '<div class="tochechki">'.$diz -> img('r.png').' <a href="func.php?mode=new&amp;id='.$id.'">Создать папку</a></div>';}
}
$msg .= '<div class="levo">'.$diz -> img('home.png').'<a href="/index.php">На главную</a></div>';
#####Копирайт#######
require_once (ROOT.'system/kopy.php');
$diz -> out($msg);
}else header('location: ../aut.php');
?>