<?php
define('ROOT','../');
define('GCMS',true);
require_once (ROOT.'system/power.php');
$diz -> head('Обменник файлов');
$diz -> title('<b>Обменник файлов</b>');
if($aut==true){
$p = $db -> dbcount('COUNT(*)','obmen_files','`dateupload` > '.(time()-86400).'');
if ($p==0)$p=0;
else $p=$p;
$my = $db -> dbcount('COUNT(*)','obmen_files','`user` = '.$ya['id'].'');
if($aut==true){$msg .= '<div class="levo">'.$diz -> img('obmen/new.gif').' <a href="new.php">Новые файлы</a> (<span style="color:red">'.$p.'</span>)</br>
'.$diz -> img('obmen/edit.gif').' <a href="upload.php">Загрузить файл</a></br>
'.$diz -> img('obmen/my_load.png').' <a href="./my_load.php?id='.$ya['id'].'">Мои файлы</a> ('.$my.')</br>
'.$diz -> img('obmen/poisk.png').' <a href="./poisk.php">Поиск файлов</a></div>';}
$count = $db -> dbcount('COUNT(`id`)','obmen_files');
$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;
////==================
$sql = $db -> query("SELECT * from `obmen_files` ORDER BY `dateupload` DESC LIMIT ".$start.",".$num);
$count2 = $db -> dbcount('COUNT(`id`)','obmen_files');
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('obmen/img.gif').'';
}
else if ($ext == 'mp3' || $ext == 'wav') {
$type=''.$diz -> img('obmen/mp3.gif').'';
}
else if ($ext == 'jar') {
$type=''.$diz -> img('obmen/jar.png').'';
}
else if ($ext == 'txt') {
$type=''.$diz -> img('obmen/byb.gif').'';
}
else if ($ext == '3gp' || $ext == 'avi' || $ext == 'mp4' || $ext == 'flv') {
$type=''.$diz -> img('obmen/video.gif').'';
}
else if ($ext == 'rar') {
$type=''.$diz -> img('obmen/rar.png').'';
}
else if ($ext == 'zip') {
$type=''.$diz -> img('obmen/zip.png').'';
}
else {
$type=''.$diz -> img('obmen/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);
$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');
?>