View file down/index.php

File size: 3.97Kb
<?php

require_once ('../includes/start.php');
require_once ('../includes/functions.php');
require_once ('../includes/header.php');
include_once ('../themes/header.php');

include_once ('core/fun.php');

$id = (isset($_GET['id'])) ? abs(intval($_GET['id'])) : 0;
$start = (isset($_GET['start'])) ? abs(intval($_GET['start'])) : 0;

$cat = DB::run()->queryFetch("SELECT * FROM `downloads_category` WHERE `id` = ? LIMIT 1;", array ($id));

if ($id == 0 || !empty($cat)) {
    if ($id > 0) {
        show_title($cat['name']);
        $config['newtitle'] = 'Загруз-центр - ' . $cat['name'];
    } else {
        show_title('Загруз-центр');
        $config['newtitle'] = 'Загруз-центр - Список разделов';
    }

    $directory_path = get_path($id);
    $navigation = get_namepath($directory_path);
    if (!empty($navigation)) {
        echo '<div class="b">' . $navigation . '</div>';
    }


    $i = 0;
    if ($start == 0) {
        $cat_sql = DB::run()->query("SELECT * FROM downloads_category WHERE id_parent = ? ORDER BY position DESC", array ($id));
        while ($row = $cat_sql->fetch()) {
            $i ++;
            $counts = DB::run()->querySingle("SELECT count(CASE WHEN status = 'active' THEN 1 END) AS count_files, count(CASE WHEN date > " . (time() - 86400) . " THEN 1 END) AS new_day FROM downloads_files WHERE `path_to_file` LIKE '%/" . $row['id'] . "/%'");
            //echo count_files($row['id']); !Дохуя запросов
            echo '<div class="b"><img src="/images/img/dir.gif" alt="image" /> ';
            echo '<a href="index.php?id=' . $row['id'] . '">' . $row['name'] . '</a> ';
            if ($counts['count_files'] > 0) {
                echo '<span class="small_text">[' . $counts['count_files'] . ']</span>' . ($counts['new_day'] > 0 ? ' <span style="color: red;">+' . $counts['new_day'] . '</span>' : '');
            }
            if (is_admin(array (101))) {
                echo ' (<a href="category.php?act=edit&amp;id=' . $row['id'] . '">Редактировать</a> / <a href="#">Удалить</a>)';
            }
            echo '</div>';
        }
    }

    $all_mod = DB::run()->querySingle("SELECT COUNT(*) as count FROM downloads_files WHERE category = ?", array ($id));
    $its_all = $all_mod['count'];

    $files_sql = DB::run()->query("SELECT * FROM downloads_files WHERE category = ? ORDER BY date DESC LIMIT " . $start . ", " . 20 . "", array ($id));

    $b = 0;
    while ($row = $files_sql->fetch()) {
        $ext = getExtension($row['file']);
        echo '<div class="b"><img src="/images/icons/' . icons($ext) . '" alt="image" /> ';
        echo '<a href="get_file.php?id=' . $row['id'] . '">' . $row['title'] . '</a> (' . formatsize($row['size']) . ')<br />';
        echo date_fixed($row['date'], 'd.m.y H:i') . ' / Скачиваний: ' . $row['count_loads'] . '<br />';
        echo '</div>';

        $b++;
    }

    page_strnavigation('index.php?id=' . $id . '&amp;', 20, $start, $its_all);


    if ($i == 0 and $b == 0) {
        show_error('В данной категории ничего нет.');
    }

    if (is_user() && $cat['upload']) {
        echo '<div class="b"><a href="add_file.php?id=' . $id . '">Добавить файл</a></div>';
    }

    if (is_admin(array (101))) {
        echo '<br /><div class="form">';
        echo '<form action="category.php?act=add&amp;id=' . $id . '&amp;token=' . $_SESSION['token'] . '" method="post">';
        echo 'Название*:<br />';
        echo '<input type="text" name="name" size="50" maxlength="50" /><br />';
        echo '<input type="checkbox" name="upload" value="1"/> разрешить загрузку файлов<br />';
        echo '<input value="Создать раздел" type="submit" /></form></div><br />';
    }
} else {
    show_error('Ошибка! Данного раздела не существует!');
}
include_once ('../themes/footer.php');