<?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;
}
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_votte` WHERE `post_id` = '$id' AND `user_id` = '$user_id' AND `votte` = '2'"), 0) > 0)
{
    require('../incfiles/head.php');
    echo functions::display_error('Bitta postga bir marta salbiy ovoz berishingiz mumkin!');
    require('../incfiles/end.php');
    exit;
}

$headmod = 'Xabarni salbiy deb baholash';
require('../incfiles/head.php');

if ($id) {
					// Запрос сообщения
$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>';

if (isset($_POST['submit'])) {
$res = mysql_fetch_array(mysql_query("SELECT * FROM `forum` WHERE `id` = '$id'"));
mysql_query("INSERT INTO `forum_votte` SET `post_id` = '$id', `user_id` = '$user_id', `tema_id` = '".$res['refid']."',`kimga` = '".$res['user_id']."', `votte` = '2'");
 
header('location: /forum/index.php?id='.$res['refid']);

        }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 functions::image(($res1['sex'] == 'm' ? 'm' : 'w') . ($res1['datereg'] > time() - 86400 ? '_new' : '') . '.png', array('class' => 'icon-inline'));
                    } else {
                        echo functions::image('del.png');
                    }

                    // Ник юзера и ссылка на его анкету
                    if ($user_id && $user_id != $res['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>';
						}
                    // Метка онлайн/офлайн
echo(time() > $res1['lastdate'] + 300 ? '<span class="red"> [Off]</span> ' : '<span class="green"> [ON]</span> ');
echo '</div>';
	 $text = $res['text'];
$text = functions::checkout($text, 1, 1);
if ($set_user['smileys']) {
$text = functions::smileys($text, $res['rights'] ? 1 : 0);
}
echo '<div class="menu"><b>Xabar matni:</b><div class="br"></div>'.$text.'</div>';

echo '<div class="menu">Xabarni salbiy deb hisoblashni tastiqlang:<div class="br"></div>
<form action="index.php?act=minus&amp;id='.$id.'" method="post">
<input type="submit" name="submit" value="Salbiy"> | <a href="/forum/index.php?id='.$id.'">Fikrimdan qaytdim</a></form></div>';
}
} else {
    header('location: index.php');
}
require('../incfiles/end.php');
?>
