<?php

/* DCMS Special
 * Дата последнего редактирования 25.09.2016
 * Модифицировал densnet
 */

$set['title'] = lang('Фотоальбомы'); // заголовок страницы

require_once H . 'sys/inc/thead.php';

aut();
err();

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery`"), 0);
$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];

#Навигация
echo "<div class='list-group-item-null list-group-item-grey'><small>";
if (isset($user)) {
    echo "<span style='float: right;'>\n";
    #Кнопка меню действий
    if (IS_WEB) {
        echo "<a data-toggle='modal' data-target='#albom_add'><span class='hint--top' data-hint='" . lang('Создать альбом') . "'><i class='fa fa-plus fa-fw fa-lg'></i></span></a>";
        echo "<a href='" . DIR_FOTO . "$user[id]/'><span class='hint--top' data-hint='" . lang('Мои альбомы') . "'><i class='fa fa-photo fa-fw fa-lg'></i></span></a>";
    } else {
        echo "<a href='" . DIR_FOTO . "$user[id]/?act=create'><span class='hint--top' data-hint='" . lang('Создать альбом') . "'><i class='fa fa-plus fa-fw fa-lg'></i></span></a>";
        echo "<a href='" . DIR_FOTO . "$user[id]/'><span class='hint--top' data-hint='" . lang('Мои альбомы') . "'><i class='fa fa-photo fa-fw fa-lg'></i></span></a>";
    }
    echo "</span>\n";
}
echo "<a href='/' class='hint--right' data-hint='" . lang('На главную') . "'><i class='fa fa-home fa-lg'></i></a> <i class='fa fa-angle-right fa-fw'></i> ";
echo "<a href='" . DIR_FOTO . "'>" . lang('Фотоальбомы') . "</a>";
echo "</small></div><br />";

#Всплывающее меню
echo "<div class='modal fade' id='albom_add' tabindex='-1' role='dialog' aria-hidden='true'>\n";
echo "<div class='modal-dialog'>\n";
echo "<div class='modal-content'>\n";
echo "<div class='modal-header'>\n";
echo "<button type='button' class='close' data-dismiss='modal' aria-label='Close'>";
echo "<span aria-hidden='true'>&times;</span>";
echo "<span class='sr-only'>Close</span>";
echo "</button>";
echo "<h5 class='modal-title'>" . lang('Новый альбом') . "</h5>";
echo "</div>";

$new_gallery_access = 'all';

echo "<form class='list-group-item-null' name='new' style='margin-top: -1px;' action='" . DIR_FOTO . "$user[id]/?act=create&amp;ok' method='post'>";
$doc->Input('name', 'Название альбома');
$doc->Textarea('opis', 'Описание альбома');

echo lang('Доступ') . ":<br />";
echo "  <label class='custom-control custom-radio'><input class='custom-control-input' value='all' name='access' type='radio' " . ($new_gallery_access == 'all' ? " checked='checked'" : null) . "><span class='custom-control-indicator'></span><span class='custom-control-description'><i class='fa fa-unlock fa-fw'></i> " . lang('Всем') . "</span></label><br />
        <label class='custom-control custom-radio'><input class='custom-control-input' value='only_me' name='access' type='radio' " . ($new_gallery_access == 'only_me' ? " checked='checked'" : null) . "><span class='custom-control-indicator'></span><span class='custom-control-description'><i class='fa fa-lock fa-fw'></i> " . lang('Только мне') . "</span></label><br />
        <label class='custom-control custom-radio'><input class='custom-control-input' value='auth' name='access' type='radio' " . ($new_gallery_access == 'auth' ? " checked='checked'" : null) . "><span class='custom-control-indicator'></span><span class='custom-control-description'><i class='fa fa-user fa-fw'></i> " . lang('Только авторизованным') . "</span></label><br />
        <label class='custom-control custom-radio'><input class='custom-control-input' value='friends' name='access' type='radio' " . ($new_gallery_access == 'friends' ? " checked='checked'" : null) . "><span class='custom-control-indicator'></span><span class='custom-control-description'><i class='fa fa-users fa-fw'></i> " . lang('Только друзьям') . "</span></label><br />
        <label class='custom-control custom-radio'><input class='custom-control-input' value='pass' name='access' type='radio' " . ($new_gallery_access == 'pass' ? " checked='checked'" : null) . "><span class='custom-control-indicator'></span><span class='custom-control-description'><i class='fa fa-key fa-fw'></i> " . lang('Только по паролю') . "</span></label><br />
    ";

$doc->Input('password', 'Пароль альбома', "" . htmlspecialchars($user['anketa_password']) . "");
echo "<br />";
$doc->Button('btn btn-primary btn-sm', 'create', null, 'Создать');

echo "</form>";

echo "</div>\n";
echo "</div>\n";
echo "</div>\n";

echo "<form method=\"post\" action=\"search.php?go\" class='list-group-item-null list-group-item-grey'>";
echo "<div class='input-group'>";
echo "<input type='text' class='form-control' name='search' placeholder='" . lang('Поиск...') . "'><span class='input-group-btn'><button class='btn btn-secondary'><i class='fa fa-search fa-fw'></i></button></span>";
echo "</div>";
echo "</form>\n";

echo "<div class='_4-u2'>";
echo "<div class='_4-u3 _g3h'><a href='" . DIR_FOTO . "rating.php' style='float:right;'><font color='#ccc'>" . lang('Все') . "</font></a> " . lang('Лучшие фото') . "</div>";

require 'include.php';

echo "</div>";

if ($k_post == 0) {
    $doc->NoResult();
}

$q = mysql_query("SELECT * FROM `gallery` WHERE `my` = '0' ORDER BY `time` DESC LIMIT $start, $set[p_str]");

while ($post = mysql_fetch_assoc($q)) {
    $ank = get_user($post['id_user']);
    $foto = mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id_gallery` = '$post[id]' ORDER BY RAND()"));

    if ($post['name'] == lang('Вложения')) {
        
    } else {
        echo "<table class='list-group-item-null'><tr><td class='icon14'>";
        if ($foto == null) {
            echo "<div class='photos'>";
            echo "<div class='photos_blok'><i class='fa fa-camera fa-fw'></i> <b>" . mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_foto` WHERE `id_gallery` = '$post[id]'"), 0) . "</b></div>";
            echo "<a href='" . DIR_FOTO . "$ank[id]/$post[id]/'><img style='width:100px;height:100px;' src='" . DIR_FOTO . "foto128/0.png' alt='" . lang('Нет фото') . "' />";
            echo "</a></div>";
        } else {
            echo "<div class='photos'>";
            echo "<div class='photos_blok'><i class='fa fa-camera fa-fw'></i> <b>" . mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_foto` WHERE `id_gallery` = '$post[id]'"), 0) . "</b></div>";
            echo "<a href='" . DIR_FOTO . "$ank[id]/$post[id]/'>";
            echo "<img style='width:100px;height:100px;' src='" . DIR_FOTO . "foto150/$foto[id].$foto[ras]' alt='Фото_$foto[id]' title='" . mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_foto` WHERE `id_gallery` = '$post[id]'"), 0) . " " . lang('фото') . "'/>";
            echo "</a></div>";
        }
        echo "</td><td class='null'>\n";
        echo "<a href='" . DIR_FOTO . "$ank[id]/$post[id]/'><i class='fa fa-photo fa-fw'></i> " . toOutput($post['name']) . "</a><br />";

        if ($post['opis'] == null) {
            echo "";
        } else {
            if ($post['opis'] == null) {
                echo lang('Без описания') . "<br />";
            } else {
                echo toOutput($post['opis']) . "<br />\n";
            }
        }

        echo "<small style='color:grey;'>";
        if ($post['access'] == 'all') {
            echo "<i class='fa fa-globe fa-fw'></i> " . lang('Доступен всем');
        } elseif ($post['access'] == 'only_me') {
            echo "<i class='fa fa-lock fa-fw'></i> " . lang('Доступен только автору');
        } elseif ($post['access'] == 'friends') {
            echo "<i class='fa fa-users fa-fw'></i> " . lang('Доступен только друзьям автора');
        } elseif ($post['access'] == 'pass') {
            echo "<i class='fa fa-key fa-fw'></i> " . lang('Доступен только по паролю');
        } elseif ($post['access'] == 'auth') {
            echo "<i class='fa fa-user fa-fw'></i> " . lang('Доступен только авторизованным');
        }

        echo "<br />";
        echo user($ank['id']);
        echo " <span title='" . date::time($post['time_create']) . "'>" . date::timek($post['time_create']) . "</span>";
        echo "</small>";
        echo "</td></tr></table>\n";
        echo "<div class='hr'></div>";
    }
}

if ($k_page > 1) {
    str('?', $k_page, $page);
}

echo "<br />";

include_once H . 'sys/inc/tfoot.php';
exit;
