<?php

defined('_IN_JOHNCMS') or die('Error: restricted access');
require('../incfiles/head.php');

if (!$al) {
    echo functions::display_error($lng['error_wrong_data']);
    require('../incfiles/end.php');
    exit;
}

$req = mysql_query("SELECT * FROM `album_cat` WHERE `id` = '$al'");
if (!mysql_num_rows($req)) {
    echo functions::display_error($lng['error_wrong_data']);
    require('../incfiles/end.php');
    exit;
}
$album = mysql_fetch_assoc($req);
$view = isset($_GET['view']);

/*
-----------------------------------------------------------------
Просмотр альбома и фотографий
-----------------------------------------------------------------
*/
if ($view) {
    $kmess = 1;
    $start = (mysql_result(mysql_query("SELECT COUNT(*) FROM `album_files` WHERE `album_id` = '$al' AND `id` > '$img'"), 0));
    // Обрабатываем ссылку для возврата
    if (empty($_SESSION['ref']))
        $_SESSION['ref'] = htmlspecialchars($_SERVER['HTTP_REFERER']);
} else {
    unset($_SESSION['ref']);
}

echo '<div class="menu"><a href="/"><img src="/ico/home.png"></a> » <a href="/album/">Foto Galareya</a> » <a href="?act=show&amp;al=' . $al . '">' . functions::checkout($album['name']) . '</a></div>';
echo '<div class="phdr"><center>'.($view ? '<b>' . functions::checkout($album['name']) . '</b>' : '<b>' . functions::checkout($album['name']) . '</b>').'</center></div>';
$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `album_files` WHERE `album_id` = '$al' AND `moder` = '0'"), 0);
if ($total) {
    $req = mysql_query("SELECT * FROM `album_files` WHERE `album_id` = '$al' AND `moder` = '0' ORDER BY `id` DESC LIMIT $start, $kmess");
    while (($res = mysql_fetch_assoc($req)) !== FALSE) {
        if ($view) {
            /*
            -----------------------------------------------------------------
            Предпросмотр отдельного изображения
            -----------------------------------------------------------------
            */
echo '<div class="menu"><center><img src="../files/album/' . $res['tmb_name'] . '" width="180" height="140" style="background: #ffffff; padding: 3px;border: 1px solid #CCCCE5;border-radius: 2px;" alt="."></center>';
            // Счетчик просмотров
            if (!mysql_result(mysql_query("SELECT COUNT(*) FROM `album_views` WHERE `file_id` = '" . $res['id'] . "'"), 0)) {
                mysql_query("INSERT INTO `album_views` SET `file_id` = '" . $res['id'] . "', `time` = '" . time() . "'");
                $views = mysql_result(mysql_query("SELECT COUNT(*) FROM `album_views` WHERE `file_id` = '" . $res['id'] . "'"), 0);
                mysql_query("UPDATE `album_files` SET `views` = '$views' WHERE `id` = '" . $res['id'] . "'");
            }
        if ($rights == 9) {
		echo '<div class="sub">';
            echo functions::display_menu(array(
                '<a href="?act=image_edit&amp;img=' . $res['id'] . '">' . $lng['edit'] . '</a>',
                '<a href="?act=image_move&amp;img=' . $res['id'] . '">' . $lng['move'] . '</a>',
                '<a href="?act=image_delete&amp;img=' . $res['id'] . '">' . $lng['delete'] . '</a>'
            ));
			echo '</div>';
        }
echo '<center>
<b>Joylandi:</b> <font color="red">' . functions::display_date($res['time']) . '</font><hr>
<a href="?act=image_download&amp;img=' . $res['id'] . '"><img src="/ico/load.gif" alt="*" /> <b>Yuklab olish!</b></a><hr>

<div class="menu" align="center">
<!-- LikeBtn.com BEGIN -->
<span class="likebtn-wrapper" data-theme="custom" data-icon_l_c="#ffffff" data-icon_l_c_v="#ffffff" data-icon_d_c="#ffffff" data-icon_d_c_v="#ffffff" data-label_c="#ffffff" data-label_c_v="#ffffff" data-counter_l_c="#ffffff" data-counter_d_c="#ffffff" data-bg_c="#9f3089" data-bg_c_v="#9f3089" data-brdr_c="#db54f3" data-i18n_like="Yoqdi" data-identifier="nwEnt2362" data-show_dislike_label="true" data-share_enabled="false" data-share_size="small" data-loader_show="true"   data-i18n_dislike="Yoqmadi" data-i18n_after_like="Yoqdi" data-i18n_after_dislike="Yoqmadi" data-i18n_like_tooltip="Menga bu yoqdi" data-i18n_dislike_tooltip="Menga bu yoqmadi" data-i18n_unlike_tooltip="Menga endi yoqmaydi" data-i18n_undislike_tooltip="Rad etish"></span>
<script>(function(d,e,s){if(d.getElementById("likebtn_wjs"))return;a=d.createElement(e);m=d.getElementsByTagName(e)[0];a.async=1;a.id="likebtn_wjs";a.src=s;m.parentNode.insertBefore(a, m)})(document,"script","//w.likebtn.com/js/w/widget.js");</script>
<!-- LikeBtn.com END -->
</div><hr><center><b>Do\'stlaringizga ulashing </b></center>
<div class="it-share-93f60bacb3f5ffd3f41380e5a80d44fc horizontal center"></div><script type="text/javascript" async charset="utf-8" src="//share.itraffic.su/share.js?buttons=tg,wa,vi,ok,fb,vk,bm&size=normal&theme=1&align=center&direction=horizontal&add=0&key=93f60bacb3f5ffd3f41380e5a80d44fc"></script>
<hr><b>Bo\'lim:</b> ' . functions::checkout($album['name']) . '<br>
Ko\'rildi: <b>' . $res['views'] . '</b> |
Yuklandi: <b>' . $res['downloads'] . '</b></center></div>' .
'</div>';
			
echo '<div class="phdr"><b><center> O\'xshash rasmlar</center></b></div><div class="menu">';
    $oxshash = mysql_query("SELECT * FROM `album_files` WHERE `album_id` = '$al' AND `moder` = '0' ORDER BY RAND() LIMIT 5");
    while (($ohshash = mysql_fetch_assoc($oxshash)) !== FALSE) {
echo '<a href="?act=show&amp;al=' . $al . '&amp;img=' . $ohshash['id'] . '&amp;view"><img width="80" height="80" src="../files/album/' . $ohshash['tmb_name'] . '" style="background: #ffffff; padding: 3px;border: 1px solid #CCCCE5;border-radius: 2px;" alt="."> </a>';
	}
	echo '</div>';
        } else {
            /*
            -----------------------------------------------------------------
            Предпросмотр изображения в списке
            -----------------------------------------------------------------
            */
echo '<div class="menu">';
echo '<center><a href="?act=show&amp;al=' . $al . '&amp;img=' . $res['id'] . '&amp;view"><img src="../files/album/' . $res['tmb_name'] . '" width="180" height="140"  style="background: #ffffff; padding: 3px;border: 1px solid #CCCCE5;border-radius: 2px;" alt="."></a><br><a href="?act=image_download&amp;img=' . $res['id'] . '"><img src="/ico/load.gif" alt="*" /> <b>Yuklab olish!</b></a></center>';
echo'</div>';
        }
    }
} else {
    echo '<div class="menu"><p>' . $lng['list_empty'] . '</p></div>';
}
if (!$view) {
if ($total > $kmess) {
echo '<div class="menu"><center>' . functions::display_pagination('?act=show&amp;al=' . $al . '&amp;' . ($view ? 'view&amp;' : ''), $start, $total, $kmess) . '</center></div>';
}
}
