<?php

defined('_IN_JOHNCMS') or die('Error: restricted access');

switch ($mod) {
    case 'views':
        /*
        -----------------------------------------------------------------
        ТОП просмотров
        -----------------------------------------------------------------
        */
        $title = $lng_profile['top_views'];
        $select = "";
        $join = "";
        $where = "`album_files`.`views` > '0'" . (core::$user_rights >= 6 ? "" : " AND `album_files`");
        $order = "`views` DESC";
        $link = '&amp;mod=views';
        break;

    case 'downloads':
        /*
        -----------------------------------------------------------------
        ТОП скачиваний
        -----------------------------------------------------------------
        */
        $title = $lng_profile['top_downloads'];
        $select = "";
        $join = "";
        $where = "`album_files`.`downloads` > 0" . (core::$user_rights >= 6 ? "" : " AND `album_files`");
        $order = "`downloads` DESC";
        $link = '&amp;mod=downloads';
        break;

    default:
        /*
        -----------------------------------------------------------------
        Новые изображения
        -----------------------------------------------------------------
        */
        $title = $lng_profile['new_photo'];
        $select = "";
        $join = "";
        $where = "`album_files`.`time` > '" . (time() - 259200) . "' AND `album_files`";
        $order = "`album_files`.`time` DESC";
        $link = '';
}

/*
-----------------------------------------------------------------
Показываем список фотографий, отсортированных по рейтингу
-----------------------------------------------------------------
*/
unset($_SESSION['ref']);
require('../incfiles/head.php');
echo '<div class="phdr"><a href=""><b>' . $lng['photo_albums'] . '</b></a> | ' . $title . '</div>';

if ($total) {

    $req = mysql_query("
      SELECT `album_files`.*, `name` AS `album_cat`.`name` $select
      FROM `album_files`
      LEFT JOIN `album_cat` ON `album_files`.`album_id` = `album_cat`.`id`
      $join
      WHERE $where
      ORDER BY $order
      LIMIT $start, $kmess
    ");
    $i = 0;
    for ($i = 0; ($res = mysql_fetch_assoc($req)) !== false; ++$i) {
        echo $i % 2 ? '<div class="list2">' : '<div class="list1">';

        if (rights >= 7) {
            // Если доступ открыт всем, или смотрит Администратор
            echo '<a href="?act=show&amp;al=' . $res['album_id'] . '&amp;img=' . $res['id'] . '&amp;view"><img src="../files/album/' . $res['tmb_name'] . '" /></a>';
        }

        echo '<div class="sub">';
        if ($rights == 9) {
            echo '<div class="gray">' . $lng['count_views'] . ': ' . $res['views'] . ', ' . $lng['count_downloads'] . ': ' . $res['downloads'] . '</div>' .
                '<div class="gray">' . $lng['date'] . ': ' . functions::display_date($res['time']) . '</div>' .
                '<br /><a href="?act=image_download&amp;img=' . $res['id'] . '">' . $lng['download'] . '</a>';
        }

        echo '</div></div>';
    }
} else {
    echo '<div class="menu"><p>' . $lng['list_empty'] . '</p></div>';
}

echo '<div class="phdr">' . $lng['total'] . ': ' . $total . '</div>';

if ($total > $kmess) {
    echo '<div class="topmenu">' . functions::display_pagination('?act=top' . $link . '&amp;', $start, $total, $kmess) . '</div>';
}