<?php
/*~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!
!		!!! Разработка сайтов и отдельных модулей на PHP !!!
!	* - Автор скрипата   :  lugaro
!	* - E-mail           :  lugaro@bk.ru
!	* - Сайт             :  wapNEW.ru
!	* - ICQ              :  2000882
~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!*/
/*Просмотр альбома*/
$tpl->assign_file('mod', 'tpl/inc/albom.tpl');
$id = (int)$_GET['id'];

$albom = $db->assoc($db->query("SELECT id AS albom_id,name AS albom_name,time AS albom_time,user AS albom_user,id_user AS albom_id_user,id_dir AS albom_id_dir  FROM foto_albom WHERE id = '$id'"));
$albom['albom_time'] = date("d.m.Y / H:i", $albom['albom_time']);
$albom['linc'] = 'mod=albom&amp;id=' . $id . '&amp;page=' . (int)$_GET['page'];
$tpl->assign($albom);
if (!empty($albom['albom_name'])) {
    // Удаление фото
    if (isset($_GET['del_file']) && ($admin || $moder)) {
        $del_file = (int)$_GET['del_file'];
        $file = $db->assoc($db->query("SELECT * FROM `foto_file` WHERE `id` = '$del_file'"));
        $file = 'files/' . $file['id_dir'] . '/' . $file['id_albom'] . '/' . $file['id'] . '.' . $file['ext'];
        if (is_file($file)) unlink($file);
        $db->query("DELETE FROM `foto_file` WHERE `id` = '$del_file'");
        $com = new comments_class_by_lugaro('fotoalbom', $del_file);
		$com->del_group();
    }

    $tpl->parse('index.albom.info');
    if ($user_id == $albom['albom_id_user']) $tpl->parse('index.albom.user');
    $all = $db->result($db->query("
		SELECT COUNT(*) FROM `foto_file` WHERE
		(
			(`close` = 0 OR `close` = 1 )
			OR
			(`id_user` = '$user_id' AND close = 2)
		)
		AND
		(`id_user` = '$user_id' OR `mod` = 0)
		 AND `id_albom` = $id
	"));
    if ($all) {
        $n = new navigator($all, $konf_albom['navi'], '?mod=albom&amp;id=' . $id . '&amp;');
        $n->no_button = true;
        $tpl->assign('page', $n->page);
        // Сортировка
        $tpl->parse('index.albom.sort');
        if (isset($_GET['sort'])) $_SESSION['AlbomSort'] = $_GET['sort'];
        $sort = array('`time` DESC', '`name`', '`ocenka` DESC');
        $sort = empty($sort[(int)$_SESSION['AlbomSort']]) ? $sort[0] : $sort[(int)$_SESSION['AlbomSort']];
        // Настройки предпросмотра
        $tpl->parse('index.albom.prev');
        if (isset($_GET['prev'])) $_SESSION['AlbomPrev'] = $_GET['prev'];

        $sql = $db->query("
			SELECT *  FROM `foto_file` WHERE
			(
				(`close` = 0 OR `close` = 1 )
				OR
				(`id_user` = '$user_id' AND close = 2)
			)
			AND
			(`id_user` = '$user_id' OR `mod` = 0)
			AND `id_albom` = $id ORDER BY $sort LIMIT {$n->start()},{$konf_albom['navi']}
		");
        while (false != ($res = $db->assoc($sql))) {
            $res['color'] = $res['ocenka'] < 0 ? '#FF5353' : '#00FF80';
            $tpl->assign($res);
            if (($admin || $moder) && $vid_adm) $tpl->parse('index.albom.while.admin');
            if ($res['mod']) $tpl->parse('index.albom.while.foto_mod'); //На модерации
            $tpl->parse('index.albom.while');
        }
        $tpl->assign('navi', $n->navi());
    } else {
        $tpl->parse('index.albom.no_file');
    }
} else {
    $tpl->parse('index.albom.no_albom');
}
$tpl->parse('index.albom');

?>