<?php

/**
 * @package     JohnCMS
 * @link        http://johncms.com
 * @copyright   Copyright (C) 2008-2011 JohnCMS Community
 * @license     LICENSE.txt (see attached file)
 * @version     VERSION.txt (see attached file)
 * @author      http://johncms.com/about
 */

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

require('../incfiles/head.php');

/*
-----------------------------------------------------------------
Список альбомов юзера
-----------------------------------------------------------------
*/
if (isset($_SESSION['ap']))
    unset($_SESSION['ap']);
echo '<div class="phdr"><a href="index.php"><b>Фотоальбомы</b></a> | Личные</div>';
echo '<div class="gmenu"><p>' . show_user($user, 1) . '</p></div>';

$req = mysql_query("SELECT * FROM `cms_album_cat` WHERE `user_id` = '" . $user['id'] . "' " . ($user['id'] == $user_id || $rights >= 6 ? "" : "AND `access` > 1") . " ORDER BY `sort` ASC");
$total = mysql_num_rows($req);

if ($total) {
    for ($i = 0; ($res = mysql_fetch_assoc($req)) !== false; ++$i) {
        $count = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_album_files` WHERE `album_id` = '" . $res['id'] . "'"), 0);
        echo ($i % 2 ? '<div class="list2">' : '<div class="list1">') .
            '<img src="../images/album-' . $res['access'] . '.gif" width="16" height="16" class="left" />&#160;' .
            '<a href="index.php?act=show&amp;al=' . $res['id'] . '&amp;user=' . $user['id'] . '"><b>' . checkout($res['name']) . '</b></a>&#160;(' . $count . ')';
        if ($user['id'] == $user_id || $rights >= 6 || !empty($res['description'])) {
            $menu = array(
                '<a href="index.php?act=sort&amp;mod=up&amp;al=' . $res['id'] . '&amp;user=' . $user['id'] . '">Вверх</a>',
                '<a href="index.php?act=sort&amp;mod=down&amp;al=' . $res['id'] . '&amp;user=' . $user['id'] . '">Вниз</a>',
                '<a href="index.php?act=edit&amp;al=' . $res['id'] . '&amp;user=' . $user['id'] . '">Изменить</a>',
                '<a href="index.php?act=delete&amp;al=' . $res['id'] . '&amp;user=' . $user['id'] . '">Удалить</a>'
            );
            echo '<div class="sub">' .
                (!empty($res['description']) ? '<div class="gray">' . checkout($res['description'], 1, 1) . '</div>' : '') .
                ($user['id'] == $user_id || $rights >= 6 ? display_menu($menu) : '') .
                '</div>';
        }
        echo '</div>';
        ++$i;
    }
} else {
    echo '<div class="menu"><p>Список пуст</p></div>';
}
echo '<div class="phdr">Всего: ' . $total . '</div>';
if ($user['id'] == $user_id && $total < $max_album || $rights >= 7) {
    echo '<p><a href="index.php?act=edit&amp;user=' . $user['id'] . '">Создать альбом</a></p>';
}
