<?php

/*
@ Coding by ДжундуЛлаh
*/

define('_IN_JOHNCMS', 1);
$headmod = 'forumspam';
$textl = 'Arzlar';
require_once ("../incfiles/core.php");
require_once ("../incfiles/head.php");
// Закрываем доступ для гостей
if (!$user_id) {
    echo display_error('Faqat sayt a\'zolariga');
    require_once('../incfiles/end.php');
    exit;
}
$t[0] = date('jmy');
$t[1] = date('jmy',time() - 86400);
$t[2] = date('jmy',time() - 172800);

function sdata($i){ global $t;
	if ( $t[0] == date('jmy',$i) ) { $i = 'Bugun: '.date('H:i',$i); }
		elseif ( $t[1] == date('jmy',$i) ){ $i = 'Kecha: '.date('H:i',$i); }
			elseif( $t[2] == date('jmy',$i) ){ $i = 'Kechadan oldin: '.date('H:i',$i); }
				else{ $i = date('j.m.Y / H:i',$i); } return $i; }

if (!empty($_GET['act'])) {
    $act = ($_GET['act']);
}
$postreq = mysql_query("SELECT * FROM `forum` WHERE `id` = '$id'");
$postres = mysql_fetch_assoc($postreq);
switch ($act) {
case 'add':
     //Добавляем уведомление о спаме
		$ms = $postres['refid'];
	 // Вычисляем, на какой странице сообщение?
$page = ceil(mysql_result(mysql_query("SELECT COUNT(*) FROM `forum` WHERE `refid` = '$ms' AND `id` " . ($set_forum['upfp'] ? ">=" : "<=") . " '$id'"), 0) / $kmess);

      // Проверяем, не повторяется ли жалоба о спаме?
        $req = mysql_query("SELECT * FROM `cms_forum_spam` WHERE `post` = '$id'");
        if (mysql_num_rows($req) > 0) {
        $res = mysql_fetch_array($req);
        if ($msg == $res['text']) 
echo functions::display_error($lng['error_message_exists'], '<a href="index.php?id=' . $res['topic'] . '&amp;page=' . $page . '">' . $lng['back'] . '</a>');
            require_once ('../incfiles/end.php');
            exit;
            }
        // Добавляем жалобу в базу
        mysql_query("INSERT INTO `cms_forum_spam` SET
		`topic` = '$ms',
        `post` = '$id',
        `time` = '" . $postres['time'] . "',
		`vrem` = '".time()."',
        `avtor` = '$login'");
        echo '<div class="gmenu">Arzingiz moderatsiyaga yuborildi<br><a href="index.php?id=' . $postres['refid'] . '&amp;page=' . $page . '">Mavzuga qaytish</a></div>';
break;

case 'massdel':
// Масовое удаление выбранных жалоб
     if ($rights == 3 || $rights >= 6) {
     require_once("../incfiles/head.php");
     if (isset($_GET['yes'])) {
          $dc = $_SESSION['dc'];
          $prd = $_SESSION['prd'];
     foreach ($dc as $delid) {
     mysql_query("DELETE FROM `cms_forum_spam` WHERE `id`='" . intval($delid) . "';");
	 mysql_query("OPTIMIZE TABLE `cms_forum_spam`");
     } 
     echo "<div class='gmenu'>Belgilangan arzlar o\'chirildi<br/><a href='" . $prd . "'>Orqaga</a></p></div>";
     } else {
     if (empty($_POST['delch'])) {
     echo display_error('Tanlamadingiz<br/><a href="' . htmlspecialchars(getenv("HTTP_REFERER")) . '">Orqaga</a>');
     require_once("../incfiles/end.php");
     exit;
     } 
     foreach ($_POST['delch'] as $v) {
          $dc[] = intval($v);
     } 
     $_SESSION['dc'] = $dc;
     $_SESSION['prd'] = htmlspecialchars(getenv("HTTP_REFERER"));
     echo '<div class="rmenu">O\'chirasizmi?<br/><a href="spam.php?act=massdel&amp;yes">Xa</a> | <a href="' . htmlspecialchars(getenv("HTTP_REFERER")) . '">Yo\'q</a></div>';
            } 
        } 
		else {
    echo functions::display_error($lng['access_forbidden']);
}

break;
default:
// Выводим список жалоб
 if ($rights == 3 || $rights >= 6) {
    $count = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_spam` "), 0);
	echo '<div class="phdr"><b>Arzlar</b></div>';
    if ($count > 0) {
			echo '<form action="spam.php?act=massdel" method="post">';
            echo '<div class="topmenu">';
            echo '<input type="checkbox" name="all" onchange="for (i in this.form.elements) this.form.elements[i].checked = this.checked" /> <b>Hammasini belgilash</b>';
            echo '</div>';

    $req = mysql_query("SELECT `cms_forum_spam`.*, `forum`.`user_id`, `forum`.`text`, `topicname`.`text` AS `topicname`
        FROM `cms_forum_spam`
        LEFT JOIN `forum` ON `cms_forum_spam`.`post` = `forum`.`id`
        LEFT JOIN `forum` AS `topicname` ON `cms_forum_spam`.`topic` = `topicname`.`id`
        WHERE `cms_forum_spam`.`time` ORDER BY `time` DESC LIMIT $start,$kmess");
        while ($res = mysql_fetch_assoc($req)) {
            $req_u = mysql_query("SELECT `id`, `name`, `sex`, `rights`, `lastdate`, `status`, `datereg` FROM `users` WHERE `id` = '" . $res['user_id'] . "'");
            $res_u = mysql_fetch_assoc($req_u);
            echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
			if ($res_u['sex'])
            echo '<img src="../theme/' . $userskin . '/images/' . ($res_u['sex'] == 'm' ? 'm' : 'w') . ($res_u['datereg'] > time() - 86400 ? '_new' : '') . '.png" width="16" height="16" align="middle" />&#160;';
            else
             echo '<img src="../images/del.png" width="12" height="12" align="middle" />&#160;';

			 echo '<a href="../users/profile.php?user=' . $res['user_id'] . '">' . $res_u['name'] . '</a> ';
			 echo ' <span class="gray">(' . date("d.m.Y / H:i", $res['time'] + $set['timeshift'] * 3600) . ')</span><br/>';
		    $text = mb_substr($res['text'], 0, 500);
            $text = functions::checkout($text, 1, 0);
            $text = preg_replace('#\[c\](.*?)\[/c\]#si', '', $text);
	        if ($set_user['smileys'])
            $text = functions::smileys($text, $res['rights'] >= 1 ? 1 : 0);
            echo nl2br($text);

$page = ceil(mysql_result(mysql_query("SELECT COUNT(*) FROM `forum` WHERE `refid` = '" . $res['topic'] . "' AND `id` " . ($set_forum['upfp'] ? ">=" : "<=") . " '" . $res['post'] . "'"), 0) / $kmess);
 echo '<br /><input type="checkbox" name="delch[]" value="' . $res['id'] . '"/>&nbsp;<a href="index.php?id=' . $res['topic'] . '&amp;page=' . $page . '">Mavzuga</a> 
 | <a href="index.php?act=post&amp;id=' . $res['post'] . '">Xabarga</a>';
 // Дата и кто сообщил
	echo '<div class="sub">Arz qildi: <b>' . $res['avtor'] . '</b>&nbsp;(&nbsp;' . sdata($res['vrem'] + $set['timeshift'] * 3600) . ')</div>';
     echo '</div>';
      ++$i;
        }
                 echo '<div class="rmenu"><input type="submit" value=" O\'chirish "/></div>';
                echo '</form>';
        } else {
            echo '<div class="menu">Arzlar yo\'q</div>';
        } 
}
		else {
    echo functions::display_error($lng['access_forbidden']);
}

}
require_once ("../incfiles/end.php");


?>