Файл: mob-lave.ru/core/function/obmen.php
Строк: 187
<?php
function user_files($id_dir, $user) {
global $system, $user, $ank, $set;
$count_razdel = mysql_result(mysql_query("SELECT COUNT(*) FROM `$system[perfix]_user_files_dir` WHERE `id_dir` = '$id_dir' && `id_user` = '$ank[id]'"),0);
$count_files = mysql_result(mysql_query("SELECT COUNT(*) FROM `$system[perfix]_user_files` WHERE `id_dir` = '$id_dir' && `id_user` = '$ank[id]'"),0);
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `$system[perfix]_user_files_dir` WHERE `id_dir` = '$id_dir' && `id_user` = '$ank[id]'"),0);
$k_page_r = k_page($k_post,$set['p_str']);
$page = page($k_page_r);
$start = $set['p_str']*$page-$set['p_str'];
// --------- Разделы ---------- //
if($count_razdel == true) echo '<div class="razdel">Папки</div>';
$q = mysql_query("SELECT * FROM `$system[perfix]_user_files_dir` WHERE `id_dir` = '$id_dir' && `id_user` = '$ank[id]' LIMIT $start, $set[p_str]");
while($post = mysql_fetch_array($q)) {
echo '<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="menu_touch"><a href="/moduls/user_files/?id='.$ank['id'].'&dir='.num($post['id']).'"><div id="dark" class="icon-folder"></div> '.htmlspecialchars($post['title']).' </a></td>';
if(isset($user['id']) && $user['id'] == $ank['id']) echo '<td class="mess" style="width:1px"><a href="/moduls/user_files/?id='.$ank['id'].'&dir='.$post['id'].'&edit_dir"><div id="dark" class="icon-pencil"></div></a></td>';
echo '</tr>
</table>';
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `$system[perfix]_user_files` WHERE `id_dir` = '$id_dir' && `id_user` = '$ank[id]'"),0);
$k_page = k_page($k_post,$set['p_str']);
$page = page($k_page);
$start = $set['p_str']*$page-$set['p_str'];
// -------- Файлы -------- //
if($count_files == true) echo '<div class="razdel">Файлы</div>';
if($count_files == false && $count_razdel == false) echo '<div class="mess">Папка пуста</div>';
$q = mysql_query("SELECT * FROM `$system[perfix]_user_files` WHERE `id_dir` = '$id_dir' && `id_user` = '$ank[id]' LIMIT $start, $set[p_str]");
while($post = mysql_fetch_array($q)) {
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `$system[perfix]_user_files_komm` WHERE `id_dir` = '$post[id_dir]' && `id_user` = '$ank[id]' && `id_file` = '$post[id]'"),0);
echo '<div class="menu_touch"><a href="/moduls/user_files/file.php?id='.num($post['id_user']).'&dir='.num($post['id_dir']).'&file='.num($post['id']).'"><div id="dark" class="icon-file2"></div> '.htmlspecialchars($post['title']).' ('.size_file($post['size']).') <span class="count">'.$count.'</span></a></div>';
}
if ($k_page > 1)str('&',$k_page,$page); // Вывод страниц
}
function user_files_nav($dir = 0, $path = NULL){
global $system, $ank, $z;
$dir = mysql_fetch_assoc(mysql_query("SELECT * FROM `$system[perfix]_user_files_dir` WHERE `id` = '$dir'"));
$pat = mysql_fetch_assoc(mysql_query("SELECT * FROM `$system[perfix]_user_files_dir` WHERE `id_dir` = '$dir[id_dir]'"));
$path .= '<a href="/moduls/user_files/?id='.$ank['id'].'&dir='.$pat['id'].'">'.htmlspecialchars($pat['title']).'</a>'.$z;
if($pat['id_dir'] != 0) $path = user_files_nav($pat['id_dir'], $path);
return $path;
}
function obmen($id_dir) {
global $system, $user;
$count_razdel = mysql_result(mysql_query("SELECT COUNT(*) FROM `$system[perfix]_obmen` WHERE `id_dir` = '$id_dir'"),0);
$count_files = mysql_result(mysql_query("SELECT COUNT(*) FROM `$system[perfix]_obmen_files` WHERE `id_dir` = '$id_dir'"),0);
// --------- Разделы ---------- //
if($count_razdel == true) echo '<div class="razdel">Папки</div>';
$q = mysql_query("SELECT * FROM `$system[perfix]_obmen` WHERE `id_dir` = '$id_dir' ORDER BY `sort`");
while($post = mysql_fetch_array($q)) {
echo '<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="menu_touch"><a href="/moduls/obmen/?id='.num($post['id']).'"><div id="dark" class="icon-folder"></div> '.htmlspecialchars($post['title']).' </a></td>';
if(isset($user['id']) && user_access('obmen_edit_dir')) echo '<td class="mess" style="width:1px"><a href="/moduls/obmen/?id='.$post['id'].'&edit_dir"><div id="dark" class="icon-pencil"></div></a></td>';
echo '</tr>
</table>';
}
// -------- Файлы -------- //
if($count_files == true) echo '<div class="razdel">Файлы</div>';
$count_files = mysql_result(mysql_query("SELECT COUNT(*) FROM `$system[perfix]_obmen_files` WHERE `id_dir` = '$id_dir'"),0);
$count_razdel = mysql_result(mysql_query("SELECT COUNT(*) FROM `$system[perfix]_obmen` WHERE `id_dir` = '$id_dir'"),0);
if($count_files == false && $count_razdel == false) echo '<div class="mess">Папка пуста</div>';
$q = mysql_query("SELECT * FROM `$system[perfix]_obmen_files` WHERE `id_dir` = '$id_dir'");
while($post = mysql_fetch_array($q)) {
$file = mysql_fetch_assoc(mysql_query("SELECT * FROM `$system[perfix]_user_files` WHERE `id` = '$post[id_file]'"));
$file_komm = mysql_result(mysql_query("SELECT COUNT(*) FROM `$system[perfix]_user_files_komm` WHERE `id_dir` = '$file[id_dir]' && `id_file` = '$file[id_dir]'"),0);
echo '<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="menu_touch"><a href="/moduls/obmen/file.php?id='.num($post['id_file']).'&dir='.$id_dir.'"><div id="dark" class="icon-file3"></div> '.htmlspecialchars($file['title']).' ('.size_file($file['size']).') <span class="count">'.$file_komm.'</span></a></td>';
if(isset($user['id']) && user_access('obmen_edit_dir')) echo '<td class="mess" style="width:1px"><a href="/moduls/obmen/?id='.$post['id'].'&edit_dir"><div id="dark" class="icon-pencil"></div></a></td>';
echo '</tr>
</table>';
}
}
function obmen_plus($id_dir,$file) {
global $system, $user;
$count_razdel = mysql_result(mysql_query("SELECT COUNT(*) FROM `$system[perfix]_obmen` WHERE `id_dir` = '$id_dir'"),0);
if($count_razdel == false) echo '<div class="mess">Папка пуста</div>';
$q = mysql_query("SELECT * FROM `$system[perfix]_obmen` WHERE `id_dir` = '$id_dir' ORDER BY `sort`");
while($post = mysql_fetch_array($q)) {
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `$system[perfix]_obmen` WHERE `id_dir` = '$post[id]'"),0);
echo '<div class="menu_touch"><a href="/moduls/obmen/obmen.php?id='.num($post['id']).'&file='.$file.'"><div id="dark" class="icon-folder"></div> '.htmlspecialchars($post['title']).' <span class="count">'.$count.'</span></a></div>';
}
}
function obmen_nav_plus($dir = 0, $file, $path = NULL){
global $system, $z;
$dir = mysql_fetch_assoc(mysql_query("SELECT * FROM `$system[perfix]_obmen` WHERE `id` = '$dir'"));
$pat = mysql_fetch_assoc(mysql_query("SELECT * FROM `$system[perfix]_obmen` WHERE `id_dir` = '$dir[id_dir]' "));
$path .= '<a href="/moduls/obmen/obmen.php?id='.$pat['id'].'&file='.$file.'">'.htmlspecialchars($pat['title']).'</a>'.$z;
if($pat['id_dir'] != 0) $path = obmen_nav_plus($pat['id_dir'], $file, $path);
return $path;
}
function obmen_nav($dir = 0, $path = NULL){
global $system, $z;
$dir = mysql_fetch_assoc(mysql_query("SELECT * FROM `$system[perfix]_obmen` WHERE `id` = '$dir'"));
$pat = mysql_fetch_assoc(mysql_query("SELECT * FROM `$system[perfix]_obmen` WHERE `id_dir` = '$dir[id_dir]' "));
$path .= '<a href="/moduls/obmen/?id='.$pat['id'].'">'.htmlspecialchars($pat['title']).'</a>'.$z;
if($pat['id_dir'] != 0) $path = obmen_nav($pat['id_dir'], $path);
return $path;
}
function DownloadFile($filename, $name, $mimetype='application/octet-stream'){
if (!file_exists($filename))
die('Файл не найден');
@ob_end_clean();
$from=0;
$size=filesize($filename);
$to=$size;
if (isset($_SERVER['HTTP_RANGE'])){
if (preg_match ('#bytes=-([0-9]*)#i',$_SERVER['HTTP_RANGE'],$range)){
$from=$size-$range[1];
$to=$size;
}elseif(preg_match('#bytes=([0-9]*)-#i',$_SERVER['HTTP_RANGE'],$range)){
$from=$range[1];
$to=$size;
}elseif(preg_match('#bytes=([0-9]*)-([0-9]*)#i',$_SERVER['HTTP_RANGE'],$range)){
$from=$range[1];
$to=$range[2];
}
header('HTTP/1.1 206 Partial Content');
$cr='Content-Range: bytes '.$from .'-'.$to.'/'.$size;
}
else
header('HTTP/1.1 200 Ok');
$etag=md5($filename);
$etag=substr($etag, 0, 8) . '-' . substr($etag, 8, 7) . '-' . substr($etag, 15, 8);
header('ETag: "'.$etag.'"');
header('Accept-Ranges: bytes');
header('Content-Length: ' .($to-$from));
if (isset($cr))header($cr);
header('Connection: close');
header('Content-Type: ' . $mimetype);
header('Last-Modified: ' . gmdate('r', filemtime($filename)));
header("Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime($filename))." GMT");
header("Expires: ".gmdate("D, d M Y H:i:s", time() + 3600)." GMT");
$f=fopen($filename, 'rb');
if (preg_match('#^image/#i',$mimetype))
header('Content-Disposition: filename="'.$name.'";');
else
header('Content-Disposition: attachment; filename="'.$name.'";');
fseek($f, $from, SEEK_SET);
$size=$to;
$downloaded=0;
while(!feof($f) and !connection_status() and ($downloaded<$size)){
$block = min(1024*8, $size - $downloaded);
echo fread($f, $block);
$downloaded += $block;
flush();
}
fclose($f);
}
function size_file($filesize=0){
$filesize_ed='B';
if ($filesize>=1024){$filesize= round($filesize/1024 , 2);$filesize_ed='KB';}
if ($filesize>=1024){$filesize= round($filesize/1024 , 2);$filesize_ed='MB';}
if ($filesize>=1024){$filesize= round($filesize/1024 , 2);$filesize_ed='GB';}
if ($filesize>=1024){$filesize= round($filesize/1024 , 2);$filesize_ed='TB';}
return $filesize.$filesize_ed;
}
?>