<?php

/*
////////////////////////////////////////////////////////////////////////////////
// JohnCMS                Mobile Content Management System                    //
// Project site:          http://johncms.com                                  //
// Support site:          http://gazenwagen.com                               //
////////////////////////////////////////////////////////////////////////////////
// Lead Developer:        Oleg Kasyanov   (AlkatraZ)  alkatraz@gazenwagen.com //
// Development Team:      Eugene Ryabinin (john77)    john77@gazenwagen.com   //
//                        Dmitry Liseenko (FlySelf)   flyself@johncms.com     //
////////////////////////////////////////////////////////////////////////////////
*/

defined('_IN_JOHNCMS') or die('Error: restricted access');
if (!$user_id) {
    require('../incfiles/head.php');
    echo functions::display_error($lng['access_guest_forbidden']);
    require('../incfiles/end.php');
    exit;
}

// Проверка на флуд
$flood = functions::antiflood();
if ($flood) {
    require('../incfiles/head.php');
    echo functions::display_error($lng['error_flood'] . ' ' . $flood . $lng['sec'] . ', <a href="index.php?id=' . $id . '&amp;start=' . $start . '">' . $lng['back'] . '</a>');
    require('../incfiles/end.php');
    exit;
}


$headmod = 'Xabarga arz qilish';
require('../incfiles/head.php');

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_arz` WHERE `post_id` = '$id' AND `arzchi_id` = '$user_id'"), 0) > 0)
{
    echo functions::display_error('Bitta postga bir marta arz qilishingiz mumkin!');
    require('../incfiles/end.php');
    exit;
}

					// Запрос сообщения
$req = mysql_query("SELECT `forum`.*, `users`.`sex`, `users`.`rights`, `users`.`lastdate`, `users`.`status`, `users`.`datereg`
FROM `forum` LEFT JOIN `users` ON `forum`.`user_id` = `users`.`id`
WHERE `forum`.`type` = 'm' AND `forum`.`id` = '$id'" . ($rights >= 7 ? "" : " AND `forum`.`close` != '1'") . " LIMIT 1");
$res = mysql_fetch_array($req);

$f = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum` WHERE `type` = 'r' AND `refid` = '" . $res['realid'] . "'"));
$f1 = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum` WHERE `type` = 'f' AND `refid` = '" . $f['realid'] . "'"));
$f2 = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum` WHERE `type` = 'r' AND `refid` = '" . $f1['id'] . "'"));

echo '<div class="menu"><a href="/"><b>'.$f1['text'].'</b></a> | <a href="/forum/index.php?id='.$f2['id'].'"><b>'.$f2['text'].'</b></a></div>';

// Запрос темы
$them = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum` WHERE `type` = 't' AND `id` = '" . $res['refid'] . "'"));
echo '<div class="menu"><b>' . $lng_forum['topic'] . ':</b> ' . $them['text'] . '</div>';

echo '<div class="phdr">'.$headmod.'</div>';
$tekst = isset($_POST['tekst']) ? functions::check(mb_substr(trim($_POST['tekst']), 0, 100)) : '';
$r = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum` WHERE `id` = '$id'"));
$sms = '[c]'.$res['from'].' yozdi:\r\n'.$res['text'].'[/c]';

if (isset($_POST['submit'])) {
mysql_query("INSERT INTO `forum_arz` SET `post_id` = '$id', `user_id` = '".$r['user_id']."', `arzchi_id` = '$user_id', `arz` = '".$sms."".mysql_real_escape_string($tekst)."', `time` = '" . time() . "'");
echo '<div class="menu">Sizning shikoyatingiz mamuryatga yuborildi!</div>';
echo '<div class="menu"><a href="index.php?id='.$them['id'].'">Davom etish</a></div>';
}else{

$res2 = mysql_fetch_array(mysql_query("SELECT * FROM `forum` WHERE `id` = '$id'"));
$res1 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$res2['user_id']."'"));
			echo '<div class="menu">';
			// Метка пола
                    if ($res1['sex']) {
echo (time() > $res1['lastdate'] + 300 ? '<img src="/images/' . ($res1['sex'] == 'm' ? 'man' : 'woman') . ($res1['rights'] > 7 && $res1['rights'] < 10 ? '_sv' : '') . ($res1['rights'] > 6 && $res1['rights'] < 9 ? '_adm' : '') . ($res1['rights'] > 5 && $res1['rights'] < 7 ? '_smod' : '') . ($res1['rights'] > 4 && $res1['rights'] < 6 ? '_lmod' : '') . ($res1['rights'] > 3 && $res1['rights'] < 5 ? '_dmod' : '') . ($res1['rights'] > 2 && $res1['rights'] < 4 ? '_fmod' : '') . '_off.gif" width="14" height="14" align="middle" alt=""/>&#160;' : '<img src="/images/' . ($res1['sex'] == 'm' ? 'man' : 'woman') . ($res1['rights'] > 7 && $res1['rights'] < 10 ? '_sv' : '') . ($res1['rights'] > 6 && $res1['rights'] < 9 ? '_adm' : '') . ($res1['rights'] > 5 && $res1['rights'] < 7 ? '_smod' : '') . ($res1['rights'] > 4 && $res1['rights'] < 6 ? '_lmod' : '') . ($res1['rights'] > 3 && $res1['rights'] < 5 ? '_dmod' : '') . ($res1['rights'] > 2 && $res1['rights'] < 4 ? '_fmod' : '') . '_on.gif" width="14" height="14" align="middle" alt=""/> ');
                    } else {
                        echo functions::image('del.png');
                    }

                    // Ник юзера и ссылка на его анкету
                    if ($user_id && $user_id != $res1['user_id']) {
echo '<a href="../users/profile.php?user=' . $res1['id'] . '"><b>'.$res1['name'].'</b></a> ';
$u_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum` WHERE `type`='m' AND `user_id`='".$res1['id']."'" . ($rights >= 7 ? '' : " AND `close`!='1'")), 0);
echo '<span style="color: #525252; font-weight: bold;"> ['.$u_p.']</span>';
                    } else {
                        echo '<b>' . $res1['from'] . '</b> ';
$u_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum` WHERE `type`='m' AND `user_id`='".$res1['id']."'" . ($rights >= 7 ? '' : " AND `close`!='1'")), 0);
echo '<span style="color: #525252; font-weight: bold;"> ['.$u_p.']</span>';
						}
                    // Метка онлайн/офлайн
$sek= time()-$res1['lastdate']; if($sek==0){$bbb='<span class="green"> [ON]</span>  ';}elseif($sek<60){$bbb='<span class="green"> ['.$sek.'s]</span>  ';}elseif($sek>60&&$sek<120){$bbb='<span class="green"> [1m]</span>  ';}elseif($sek>120&&$sek<180){$bbb='<span class="green"> [2m]</span>  ';}elseif($sek>180&&$sek<240){$bbb='<span class="green"> [3m]</span>  ';}elseif($sek>240&&$sek<300){$bbb='<span class="green"> [4m]</span>  ';}elseif($sek>300&&$sek<360){$bbb='<span class="green"> [5m]</span>  ';}elseif($sek>360&&$sek<420){$bbb='<span class="green"> [6m]</span>  ';}elseif($sek>420&&$sek<480){$bbb='<span class="green"> [7m]</span>  ';}elseif($sek>480&&$sek<540){$bbb='<span class="green"> [8m]</span>  ';}elseif($sek>540&&$sek<600){$bbb='<span class="green"> [9m]</span>  '; }echo( time()>$res1['lastdate']+300 ? '<span class="red"> [Off]</span>':'<span class="black">'.$bbb.'</span></a>');
echo '</div>';
echo '<div class="menu"><b>Xabar matni:</b><div class="br"></div>'.$res['text'].'</div>';

echo '<div class="menu">Nima sababdan arz qilmoqchisiz?<div class="br"></div>
<form action="index.php?act=arz&amp;id='.$id.'" method="post">
<textarea name="tekst"></textarea><br>
<input type="submit" name="submit" value="Arz"> | <a href="/forum/index.php?id='.$id.'">Fikrimdan qaytdim</a></form></div>';
}
require('../incfiles/end.php');
?>