<?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
*/

define('_IN_JOHNCMS', 1);

require('../incfiles/core.php');
$textl = 'Фотоальбомы';
$headmod = 'album';

$max_album = 10;
$max_photo = 200;
$al = isset($_REQUEST['al']) ? abs(intval($_REQUEST['al'])) : NULL;
$img = isset($_REQUEST['img']) ? abs(intval($_REQUEST['img'])) : NULL;

/*
-----------------------------------------------------------------
Закрываем от неавторизованных юзеров
-----------------------------------------------------------------
*/
if (!$user_id) {
    require('../incfiles/head.php');
    echo 'Только для зарегистрированных пользователей';
    require('../incfiles/end.php');
    exit;
}

$user = getUser(isset($_REQUEST['user']) ? abs(intval($_REQUEST['user'])) : $user_id);
if (!$user) {
    require('../incfiles/head.php');
    echo 'Пользователь не существует';
    require('../incfiles/end.php');
    exit;
}

/*
-----------------------------------------------------------------
Функция голосований за фотографии
-----------------------------------------------------------------
*/
function vote_photo($arg = null) {
    global $datauser, $user_id, $ban;

    if ($arg) {
        $rating = $arg['vote_plus'] - $arg['vote_minus'];
        if ($rating > 0)
            $color = 'C0FFC0';
        elseif ($rating < 0)
            $color = 'F196A8';
        else
            $color = 'CCC';
        $out = '<div class="gray">Рейтинг: <span style="color:#000;background-color:#' . $color . '">&#160;&#160;<big><b>' . $rating . '</b></big>&#160;&#160;</span> ' .
            '(Против: ' . $arg['vote_minus'] . ', За: ' . $arg['vote_plus'] . ')';
        if ($user_id != $arg['user_id'] && !$ban && $datauser['postforum'] > 10 && $datauser['total_on_site'] > 1200) {
            // Проверяем, имеет ли юзер право голоса
            $req = mysql_query("SELECT * FROM `cms_album_votes` WHERE `user_id` = '$user_id' AND `file_id` = '" . $arg['id'] . "' LIMIT 1");
            if (!mysql_num_rows($req))
                $out .= '<br />Голосовать: <a href="index.php?act=vote&amp;mod=minus&amp;img=' . $arg['id'] . '">&lt;&lt; -1</a> | ' .
                    '<a href="index.php?act=vote&amp;mod=plus&amp;img=' . $arg['id'] . '">+1 &gt;&gt;</a>';
        }
        $out .= '</div>';
        return $out;
    } else {
        return false;
    }
}

/*
-----------------------------------------------------------------
Переключаем режимы работы
-----------------------------------------------------------------
*/
$array = array (
    'comments' => 'includes',
    'delete' => 'includes',
    'edit' => 'includes',
    'image_delete' => 'includes',
    'image_download' => 'includes',
    'image_edit' => 'includes',
    'image_move' => 'includes',
    'image_upload' => 'includes',
    'list' => 'includes',
    'new_comm' => 'includes',
    'show' => 'includes',
    'sort' => 'includes',
    'top' => 'includes',
    'users' => 'includes',
    'vote' => 'includes'
);
$path = !empty($array[$act]) ? $array[$act] . '/' : '';
if (array_key_exists($act, $array) && file_exists($path . $act . '.php')) {
    require_once($path . $act . '.php');
} else {
    require('../incfiles/head.php');
    $albumcount = mysql_result(mysql_query("SELECT COUNT(DISTINCT `user_id`) FROM `cms_album_files`"), 0);
    $newcount = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_album_files` WHERE `time` > '" . (time() - 259200) . "' AND `access` > '1'"), 0);
    echo '<div class="phdr"><b>Фотоальбомы</b></div>' .
        '<div class="gmenu"><p>' .
        '<img src="' . $set['homeurl'] . '/images/users.png" width="16" height="16"/>&#160;<a href="index.php?act=top">Новые фотографии</a> (' . $newcount . ')<br />' .
        '<img src="' . $set['homeurl'] . '/images/guestbook.gif" width="16" height="16"/>&#160;<a href="index.php?act=top&amp;mod=last_comm">Последние комментарии</a>' .
        '</p></div>' .
        '<div class="menu">' .
        '<p><h3><img src="' . $set['homeurl'] . '/images/users.png" width="16" height="16" class="left" />&#160;Альбомы</h3><ul>' .
        '<li><a href="index.php?act=users">Список альбомов</a> (' . $albumcount . ')</li>' .
        '</ul></p>' .
        '<p><h3><img src="' . $set['homeurl'] . '/images/rate.gif" width="16" height="16" class="left" />&#160;Рейтинг</h3><ul>' .
        '<li><a href="index.php?act=top&amp;mod=votes">ТОП голосов</a></li>' .
        '<li><a href="index.php?act=top&amp;mod=downloads">ТОП загрузок</a></li>' .
        '<li><a href="index.php?act=top&amp;mod=views">ТОП просмотров</a></li>' .
        '<li><a href="index.php?act=top&amp;mod=comments">ТОП комментариев</a></li>' .
        '<li><a href="index.php?act=top&amp;mod=trash">КГ/АМ</a></li>' .
        '</ul></p>' .
        '</div>' .
        '<div class="phdr"><a href="../index.php?act=users">Пользователи</a></div>';
}
require('../incfiles/end.php');