<?php
/*~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!
!		!!! Разработка сайтов и отдельных модулей на PHP !!!
!	* - Автор скрипата   :  lugaro
!	* - E-mail           :  lugaro@bk.ru
!	* - Сайт             :  wapNEW.ru
!	* - ICQ              :  2000882
~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!~!*/
/*Топ коментируемых*/
$tpl->assign_file('mod', 'tpl/inc/top_com.tpl');
$tpl->assign('linc', 'mod=top_com&amp;page=' . (int)$_GET['page']);
// Удаление фото
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();
}

$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 count_com > 0 LIMIT 100
	"));

if ($all) {
    $n = new navigator($all, $konf_albom['navi'], '?mod=top_com&amp;');
    $n->no_button = true;
    $tpl->assign('page', $n->page);
    // Настройки предпросмотра
    $tpl->parse('index.top_com.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 count_com > 0
			ORDER BY `count_com` DESC 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.top_new.while.admin');
        if ($res['mod']) $tpl->parse('index.top_com.while.foto_mod'); //На модерации
        $tpl->parse('index.top_com.while');
    }
    $tpl->assign('navi', $n->navi());
} else {
    $tpl->parse('index.top_com.no_file');
}

$tpl->parse('index.top_com');

?>