<?php
define('_IN_JOHNCMS', 1);
require_once '../incfiles/core.php';
require_once '../incfiles/head.php';
include 'functions.php'; 
   $totalcat = mysql_result(mysql_query("SELECT COUNT(*) FROM `downpath` WHERE `refid` = '" . $cat ."'"), 0);

    if ($totalcat > 0) {
        $zap = mysql_query("SELECT * FROM `downpath` WHERE `refid` = '" . $cat . "' ORDER BY `position` ASC LIMIT " . $start . "," . $kmess);
        $cachetime = time()-$down_setting['cachetime']*3600; // Время кэширования

        if(is_file('cache/'.$cat.'.dat') && filemtime('cache/'.$cat.'.dat') > $cachetime)
        {
            $count_cache = file_get_contents('cache/'.$cat.'.dat');
            $count_cache = unserialize($count_cache);
            $opencache = 'true';
        }else{
            $count_cache = array();
        }
        $i = 0;
        while ($zap2 = mysql_fetch_array($zap))
        {
            echo ($i % 2) ? '<div class="list1">' : '<div class="list2">';
            ++$i;
            if(!$count_cache[$zap2['id']])
            {
                ////////// счётчики //////////
                $countf = mysql_result(mysql_query("SELECT COUNT(*) FROM `downfiles` WHERE `type` != 1 AND `status` = 1 && `way` LIKE '" . $zap2['way'] ."%' "), 0);
                $old = time() - (3 * 24 * 3600);
                $countnf = mysql_result(mysql_query("SELECT COUNT(*) FROM `downfiles` WHERE `type` != 1 AND `status` = 1 && `time` > '".$old."' && `way` LIKE '" . $zap2['way'] ."%' "), 0);

                //$countp = mysql_result(mysql_query("SELECT COUNT(*) FROM `downpath` WHERE `way` LIKE '" . $zap2['way'] ."%';"), 0);
                //$countp--; // Счётчик папок. Раскомментировать если нужен.

                if($countnf){ $countnf = '/<span class="red">+'.$countnf.'</span>'; }else{ $countnf = ''; }
                $count_cache[$zap2['id']] = $countf.$countnf; // Сюда вставлять $countp если нужен счётчик папок.
            }
            echo '<img src="img/dir.png" alt="."/> <a href="dir_' . $zap2['id'] . '.html">' . $zap2['name'] .'</a> ('.$count_cache[$zap2['id']].')<br/>';
            if($zap2['desc'])
            {
                echo'<div class="sub">' . $zap2['desc'] .'</div>';
            }
            echo'</div>';
        }
        echo '<div class="phdr">Всего папок: ' . $totalcat . '</div>';
        if ($totalcat > $kmess){
            echo'<div class="topmenu">';
            echo '' . functions::display_pagination('uuu.php?cat='.$cat.'&amp;', $start, $totalcat, $kmess) . '</div>';
}
require_once '../incfiles/end.php';
?>