<?php
define('_IN_JOHNCMS', 1);
require_once('../incfiles/core.php');

////////////////////////////////////////////////////////////
// ��������� ������                                       //
////////////////////////////////////////////////////////////
if ($user_id)
    $set_forum = unserialize($datauser['set_forum']);
    $set_foru['farea'] = 1;
// �������� ��-���������
if (!isset($set_forum) || empty($set_forum))
    $set_forum = array (
        'farea' => 1,
        'upfp' => 0,
        'farea_w' => 20,
        'farea_h' => 4,
        'postclip' => 1,
        'postcut' => 2
    );

////////////////////////////////////////////////////////////
// ������ ���������� ������, ����������� � ��������       //
////////////////////////////////////////////////////////////
// ����� Windows
$ext_win = array (
    'exe',
    'msi'
);
// ����� Java
$ext_java = array (
    'jar',
    'jad'
);
// ����� SIS
$ext_sis = array (
    'sis',
    'sisx'
);
// ����� ���������� � ������
$ext_doc = array (
    'txt',
    'pdf',
    'doc',
    'rtf',
    'djvu',
    'xls'
);
// ����� ��������
$ext_pic = array (
    'jpg',
    'jpeg',
    'gif',
    'png',
    'bmp',
    'wmf'
);
// ����� �������
$ext_zip = array (
    'zip',
    'rar',
    '7z',
    'tar',
    'gz'
);
// ����� �����
$ext_video = array (
    '3gp',
    'avi',
    'flv',
    'mpeg',
    'mp4'
);
// �������� �����
$ext_audio = array (
    'mp3',
    'amr'
);
// ������ ���� ������ (��� �� ����������� ����)
$ext_other = array ();

////////////////////////////////////////////////////////////
// ������������ ������ � ������                           //
////////////////////////////////////////////////////////////
$error = '';
if (!$set['mod_forum'] && $rights < 7)
    $error = '����� ������';
elseif ($set['mod_forum'] == 1 && !$user_id)
    $error = '������ �� ����� ������ ������ <a href="../login.php">��������������</a> �����������';
if ($error) {
    require_once('../incfiles/head.php');
    echo '<div class="rmenu"><p>' . $error . '</p></div>';
    require_once('../incfiles/end.php');
    exit;
}

// ������������ ������ � ������ �� ����
$error = '';
if (!$set['mod_chat'] && $rights < 7)
    $error = '����� ������';
elseif ($ban['1'] || $ban['5'])
    $error = '��� ��� ������ � ����� ������';
if ($error) {
    require_once ("../incfiles/head.php");
    echo '<div class="rmenu"><p>' . $error . '</p></div>';
    require_once ("../incfiles/end.php");
    exit;
}




$headmod = $id ? 'forum,' . $id : 'forum';

// ��������� ������
if (empty($id)) {
    $textl = '�����';
} else {
    $req = sql_query("SELECT `text` FROM `forum` WHERE `id`= '" . $id . "' LIMIT 1;");
    $res = sql_fetch_assoc($req);
    $hdr = strtr($res['text'], array (
        '&quot;' => '',
        '&amp;' => '',
        '&lt;' => '',
        '&gt;' => '',
        '&#039;' => ''
    ));
    $hdr = mb_substr($hdr, 0, 30);
    $hdr = checkout($hdr);
    $textl = mb_strlen($res['text']) > 30 ? $hdr . '...' : $hdr;
}

$array = array (
    'new',
    'who',
    'addfile',
    'file',
    'users',
    'moders',
    'addvote',
    'editvote',
    'delvote',
    'vote',
    'per',
    'ren',
    'deltema',
    'vip',
    'close',
    'editpost',
    'nt',
    'tema',
    'loadtem',
    'say',
    'post',
    'read',
    'faq',
    'trans',
    'massdel',
    'files',
    'filter',
    'restore',
    'icons',
    'postforum',
    'curators'
);
if (in_array($act, $array) && file_exists($act . '.php')) {
    require_once($act . '.php');
} else {
    require_once('../incfiles/head.php');




    // ���� ����� ������, �� ��� ������� ������� �����������
    if (!$set['mod_forum'])
        echo '<p><font color="#FF0000"><b>����� ������!</b></font></p>';
    if (!$user_id) {
        if (isset($_GET['newup']))
            $_SESSION['uppost'] = 1;
        if (isset($_GET['newdown']))
            $_SESSION['uppost'] = 0;
    }
    if ($id) {
        $type = sql_query("SELECT * FROM `forum` WHERE `id`= '" . $id . "' LIMIT 1");
        $type1 = sql_fetch_assoc($type);
        $tip = $type1['type'];
        switch ($tip) {
            case 'f':


##############################################################################################################################################

	//      ������ �������� ������

####################################################################





########################################################################
if ($theme == 'wap')
{echo '<div class="bmenu">';
forum_new(1);

'<a href="index.php">�����</a> &gt;&gt; <b>' . $type1['text'] . '</b>';

}

####################################################################

 if ($theme == 'web')
 {


echo '<div class="loop"><div class="gmeenu">';
forum_new(1);

echo '</div>';



echo '<div class="gmeenu"><a href="index.php">�����</a> &gt;&gt; <b>' . $type1['text'] . '</b></div>';
}
#######################################################################




                $req = sql_query("SELECT `id`, `text`, `soft`, `icon` FROM `forum` WHERE `type`='r' AND `refid`='$id' ORDER BY `realid`");
                $total = sql_num_rows($req);
                while ($res = sql_fetch_assoc($req))


{
					echo '<div class="frame">';
                    echo ($i % 2) ? '<div class="oddnrows">' : '<div class="evenrows">';
                    $coltem = sql_result(sql_query("SELECT COUNT(*) FROM `forum` WHERE `type` = 't' AND `refid` = '" . $res['id'] . "'"), 0);
                    echo ($user_id && $rights >= 8 ? '<a href="index.php?act=icons&amp;num=' . $res['id'] . '">' : '') . '<img src="icons/' . ($res['icon'] ? $res['icon'] : 'default.gif') . '" alt="" width="16" height="16" style="vertical-align:middle;" />' . ($user_id && $rights >= 8 ? '</a>' : '') . ' <a href="?id=' . $res['id'] . '">' . $res['text'] . '</a>';
                    if ($coltem)
                        echo " [$coltem]";
                    if (!empty($res['soft']))
                        echo '<div class="sub"><span class="gray">' . $res['soft'] . '</span></div>';
                    echo '</div>';
                    ++$i;
				echo '</div>';
}




                echo '<div class="warning">�����: ' . $total . '</div>';
                unset($_SESSION['fsort_id']);
                unset($_SESSION['fsort_users']);
                break;

            case 'r':




##############################################################################################################################################

	//      ������ ��� � ������ �� �������������

####################################################################





########################################################################
if ($theme == 'wap')
{echo '<div class="bmenu">';
forum_new(1);

'</b>';



}

####################################################################

 if ($theme == 'web')
 {


echo '<div class="loop"><div class="gmeenu">';
forum_new(1);

echo '</div>';




}
#######################################################################


                $qz = sql_query("SELECT COUNT(*) FROM `forum` WHERE `type`='t' AND `refid`='$id'" . ($rights >= 7 ? '' : " AND `close`!='1'"));
                $coltem = sql_result($qz, 0);
                $forum = sql_query("SELECT * FROM `forum` WHERE `type`='f' AND `id`='" . $type1['refid'] . "'");
                $forum1 = sql_fetch_assoc($forum);


########################################################################
if ($theme == 'wap')
{

echo '<div class="warning">';
                echo '<a href="index.php">�����</a> &gt;&gt; <a href="index.php?id=' . $type1['refid'] . '">' . $forum1['text'] . '</a> &gt;&gt; <b>' . $type1['text'] . '</b>';
                echo '</div>';


}

####################################################################

 if ($theme == 'web')
 {


echo '<div class="gmeenu">';
                echo '<a href="index.php">�����</a> &gt;&gt; <a href="index.php?id=' . $type1['refid'] . '">' . $forum1['text'] . '</a> &gt;&gt; <b>' . $type1['text'] . '</b>';
                echo '</div>';




}
#######################################################################



                if ($user_id && !$ban['1'] && !$ban['11'])
				{

echo '<div class="warning"><form action="index.php?act=nt&amp;id=' . $id . '" method="post"><input type="submit" value="����� ����" /></form></div>';
                }


                $q1 = sql_query("SELECT * FROM `forum` WHERE `type`='t'" . ($rights >= 7 ? '' : " AND `close`!='1'") . " AND `refid`='$id' ORDER BY `vip` DESC, `time` DESC LIMIT $start, $kmess");





             echo '<div class="frame">';


			echo '<table id="example">';
                while ($mass = sql_fetch_assoc($q1)) {
                    echo ($i % 2) ? '<tr class="oddnrows">' : '<tr class="evenrows">';
                    $nikuser = sql_query("SELECT `from` FROM `forum` WHERE `type` = 'm' AND `close` != '1' AND `refid` = '" . $mass['id'] . "' ORDER BY `time` DESC LIMIT 1");
                    $nam = sql_fetch_assoc($nikuser);
                    $colmes = sql_query("SELECT COUNT(*) FROM `forum` WHERE `type`='m' AND `refid`='" . $mass['id'] . "'" . ($rights >= 7 ? '' : " AND `close` != '1'"));
                    $colmes1 = sql_result($colmes, 0);
                    $cpg = ceil($colmes1 / $kmess);
                    // ������� ������ ���
                    echo '<td>';
                    if ($mass['vip'] == 1) {
                        echo '<img src="../theme/images/pt.gif" alt=""/>';
                    } elseif ($mass['edit'] == 1) {
                        echo '<img src="../theme/images/tz.gif" alt=""/>';
                    } elseif ($mass['close'] == 1) {
                        echo '<img src="../theme/images/dl.gif" alt=""/>';
                    } else {
                        $np = sql_result(sql_query("SELECT COUNT(*) FROM `cms_forum_rdm` WHERE `time` > '" . $mass['time'] . "' AND `topic_id` = '" . $mass['id'] . "' AND `user_id`='$user_id'"), 0);
                        echo '<img src="../theme/images/' . ($np ? 'op' : 'np') . '.gif" alt=""/>';
                    }
                    if ($mass['realid'] == 1)
                        echo '&nbsp;<img src="../images/rate.gif" alt=""/>';
                    echo '&nbsp;<a href="index.php?id=' . $mass['id'] . '">' . $mass['text'] . '</a>' . ($cpg > 1 ? '<a href="index.php?id=' . $mass[id] . '&amp;page=' . $cpg . '">&nbsp;&gt;&gt;</a>' : '');
                    echo '<div style="font-size:x-small;margin-top:4px;">';
                    echo $mass['from'];
                    if (!empty($nam['from'])) {
                        echo '&nbsp;/&nbsp;' . $nam['from'];
                    }
                    $vrp = $mass['time'] + $set_user['sdvig'] * 3600;
                    echo ' <font color="#777777">' . date("d.m.y / H:i", $vrp) . '</font></div>';
                    echo '</td><td align="center" width="10%">' . $colmes1 . '</td></tr>';
                    ++$i;
                }
                echo '</table>';
			echo '</div>';
                echo '<div class="warning">�����: ' . $coltem . '</div>';
                if ($coltem > $kmess) {
                    echo '<div class="menu"><p>' . pagenav('index.php?id=' . $id . '&amp;', $start, $coltem, $kmess) . '</p>';
                    echo '<p><form action="index.php" method="get"><input type="hidden" name="id" value="' . $id . '"/><input type="text" name="page" size="2"/><input type="submit" value="� �������� &gt;&gt;"/></form></p></div>';
                }
                unset($_SESSION['fsort_id']);
                unset($_SESSION['fsort_users']);
                break;

            case 't':

##############################################################################################################################################

	//      ������ ����

####################################################################


                $filter = isset($_SESSION['fsort_id']) && $_SESSION['fsort_id'] == $id ? 1 : 0;
                $sql = '';
                if ($filter && !empty($_SESSION['fsort_users'])) {
                    // �������������� ������ �� ���������� ������
                    $sw = 0;
                    $sql = ' AND (';
                    $fsort_users = unserialize($_SESSION['fsort_users']);
                    foreach ($fsort_users as $val) {
                        if ($sw)
                            $sql .= ' OR ';
                        $sortid = intval($val);
                        $sql .= "`forum`.`user_id` = '$sortid'";
                        $sw = 1;
                    }
                    $sql .= ')';
                }
                if ($user_id && !$filter) {
                    // �������� ����� ��������� ������
                    $req = sql_query("SELECT * FROM `cms_forum_rdm` WHERE `topic_id` = '$id' AND `user_id` = '$user_id' LIMIT 1");
                    if (sql_num_rows($req) > 0) {
                        $res = sql_fetch_assoc($req);
                        if ($type1['time'] > $res['time'])
                            sql_query("UPDATE `cms_forum_rdm` SET `time` = '$realtime' WHERE `topic_id`='$id' AND `user_id` = '$user_id'");
                    } else {
                        // ������ ����� � ���������
                        sql_query("INSERT INTO `cms_forum_rdm` SET  `topic_id` = '$id', `user_id` = '$user_id', `time` = '$realtime'");
                    }
                }






                // ������ �� �������������

########################################################################
if ($theme == 'wap')
{echo '<div class="bmenu">';
forum_new(1);

'</b>';



}

####################################################################

 if ($theme == 'web')
 {


echo '<div class="loop"><div class="gmeenu">';
forum_new(1);

echo '</div>';




}
#######################################################################




                if ($rights < 7 && $type1['close'] == 1)

				{
                    echo '<div class="c">   <p>���� �������!<br/><a href="?id=' . $type1['refid'] . '">
					</br>� ������</a></p></div>';
                    require_once("../incfiles/end.php");
                    exit;
                }



                // ������� ������ ����
                $colmes = sql_result(sql_query("SELECT COUNT(*) FROM `forum` WHERE `type`='m'$sql AND `refid`='$id'" . ($rights >= 7 ? '' : " AND `close` != '1'")), 0);

                // ������ ���������
                $razd = sql_fetch_assoc(sql_query("SELECT `id`, `refid`, `text` FROM `forum` WHERE `id` = '" . $type1['refid'] . "' LIMIT 1"));
                $frm = sql_fetch_assoc(sql_query("SELECT `id`, `text` FROM `forum` WHERE `id` = '" . $razd['refid'] . "' LIMIT 1"));


                echo '<div class="warning">    <a href="index.php">�����</a> &gt;&gt; <a href="index.php?id=' . $frm['id'] . '">' . $frm['text'] . '</a> &gt;&gt; <a href="index.php?id=' . $razd['id'] . '">' . $razd['text'] . '</a></div>';


                // ������� �������� ������
                echo '<div class="bmenu">    <a name="up" id="up"></a><a href="#down"><img src="../theme/images/down.png" alt="����" width="20" height="20" border="0"/></a>&nbsp;&nbsp;<b>' . $type1['text'] .
                    '</b></div>';


                // ����� �������� ����
                if ($type1['close'])
                    echo '<div class="loop"><div class="gmeenu">   ���� ������: <b>' . $type1['close_who'] . '</b></div>';


                // ����� �������� ����
                if ($type1['edit'])
                    echo '<div class="loop"><div class="gmeenu">   ���� �������</div>';

                if ($colmes > $kmess) {
                    echo '<div class="frame">    ' . pagenav('index.php?id=' . $id . '&amp;', $start, $colmes, $kmess) . '</div>';
               }



##############################################################################################################################################

	//      �����������

####################################################################



                if ($type1['realid']) {
                    if (isset($_GET['clip']))
                        $clip_forum = '&amp;clip';
                    $vote_user = sql_result(sql_query("SELECT COUNT(*) FROM `forum_vote_us` WHERE `user`='$user_id' AND `topic`='$id'"), 0);
                    $topic_vote = sql_fetch_assoc(sql_query("SELECT `name`, `time`, `count` FROM `forum_vote` WHERE `type`='1' AND `topic`='$id' LIMIT 1"));
					echo '<div  class="warning"><b>������������: &nbsp &nbsp<font color="red ">' . checkout($topic_vote['name']) . '</font></b><br />';
                    $vote_result = sql_query("SELECT `id`, `name`, `count` FROM `forum_vote` WHERE `type`='2' AND `topic`='" . $id . "' ORDER BY `id` ASC");
                    if (!isset($_GET['vote_result']) && $user_id && $vote_user == 0)

					{
                        // ������� ����� � ��������
                        echo '<form action="index.php?act=vote&amp;id=' . $id . '" method="post">';
                        while ($vote = sql_fetch_assoc($vote_result))
						{
                            echo '<input type="radio" value="' . $vote['id'] . '" name="vote"/> ' . checkout($vote['name']) . '<br />';
                        }
                        echo '<p><input type="submit" name="submit" value="����������"/><br /><a href="index.php?id=' . $id . '&amp;start=' . $start . '&amp;vote_result' . $clip_forum .
                            '">����������</a></p></form></div>';
                    }

					else
					{
                        // ������� ���������� �����������
                        echo '<small>';
                        while ($vote = sql_fetch_assoc($vote_result)) {
                            $count_vote = $topic_vote['count'] ? round(100 / $topic_vote['count'] * $vote['count']) : 0;
                            echo checkout($vote['name']) . ' [' . $vote['count'] . ']<br />';
                            echo '<img src="vote_img.php?img=' . $count_vote . '" alt="�������: ' . $count_vote . '%" /><br />';
                        }
                        echo '</small></div><div class="warning">����� �������: ';
                        if ($datauser['rights'] > 6)
                            echo '<a href="index.php?act=users&amp;id=' . $id . '">' . $topic_vote['count'] . '</a>';
                        else
                            echo $topic_vote['count'];
                        echo '</div>';
                        if ($user_id && $vote_user == 0)
                            echo '<div class="warning"><a href="index.php?id=' . $id . '&amp;start=' . $start . $clip_forum . '">����������</a></div>';
                    }
                }

                 $curators = !empty($type1['curators']) ? unserialize($type1['curators']) : array();
                $curator = false;
                if($rights  < 6 && $rights  != 3 && $user_id) {
                    if(array_key_exists($user_id, $curators)) $curator = true;
                }

                //��� ���� �������� ������� �����
                if ($filter)
                    echo '<div class="rmenu">� ���� �������� ���������� �� ������� ������</div>';
                // ������ ������� ���������� (����� ����� / ������)
                if ($user_id)
                    $order = $set_forum['upfp'] ? 'DESC' : 'ASC';
                else
                    $order = ((empty($_SESSION['uppost'])) || ($_SESSION['uppost'] == 0)) ? 'ASC' : 'DESC';
                // ������ � ����
$req = sql_query("SELECT `forum`.*, `users`.`name`, `users`.`imname`, `users`.`sex`, `users`.`rights`, `users`.`lastdate`, `users`.`total_on_site`, `users`.`medal`, `users`.`status`, `users`.`img_status`, `users`.`datereg`
                FROM `forum` LEFT JOIN `users` ON `forum`.`user_id` = `users`.`id`
                WHERE `forum`.`type` = 'm' AND `forum`.`refid` = '$id'"
                    . ($rights >= 7 ? "" : " AND `forum`.`close` != '1'") . "$sql ORDER BY `forum`.`id` $order LIMIT $start, $kmess");
######################################################################################################################################################

			/*

			// ������� ���� "��������"
                if (($user_id && !$type1['edit'] && !$set_forum['upfp']) || ($rights >= 7 && !$set_forum['upfp'])) {

                    echo '<div class="bmenu"><form  name="form2" action="index.php?act=say&amp;id=' . $id . '" method="post">';
                    if ($set_forum['farea']) {
                        echo auto_bb('form2', 'msg');
                        echo '<textarea cols="' . $set_forum['farea_w'] . '" rows="' . $set_forum['farea_h'] . '" name="msg" spellcheck="true"></textarea><br/>';
                        echo '<input type="checkbox" name="addfiles" value="1" /> �������� ����<br/>';
                        if ($set_user['translit'])
                            echo '<input type="checkbox" name="msgtrans" value="1" /> �������� ���������<br/>';
                    }
                    echo '<input type="submit" name="submit" value="��������"/>';
                    echo '</form></div>';

                }
*/
######################################################################################################################################################



			// ������ ������ ������ � ���� ��������

if ($rights == 3 || $rights >= 6)
                    echo '<form action="index.php?act=massdel" method="post">';
                $i = 1;


			while ($res = sql_fetch_assoc($req)) {


	echo '<table id="example" cellspacing="0" width="100%">';
                  $text = '';


           // ��� ����� � ������ �� ��� ������

				$color = sql_fetch_assoc(sql_query("SELECT * FROM `users` WHERE `id` = '".  $res['user_id'] ."' LIMIT 1"));

				if ($user_id && $user_id != $res['user_id'])
				{

                        $nikuser = '<span style="color:#'.$color['color_nik'].'"><a href="../str/anketa.php?id=' . $res['user_id'] . '"><b>' . $res['imname'] . ' ' . $res['name'] . '</b></a></span> ';
                    }
				else
				{
                        $nikuser = '<span style="color:#'.$color['color_nik'].'"><b>' . $res['imname'] . ' ' . $res['name'] . '</b></span> ';
                }




             // ������ �����


                  if ($set_user['avatar'])
				  {

                        if (file_exists(('../files/avatar/' . $res['user_id'] . '.png')))
                            $ava = '<br/><img src="../files/avatar/' . $res['user_id'] . '.png" width="48" height="48" alt="' . $res['from'] . '" />';
                        else
                           $ava = '<br/><img src="../images/empty.png" width="48" height="48" alt="' . $res['from'] . '" />&nbsp;';

                  }


else {$ava = '';}



				// ��� � ����� ������ �����


				if ($res['sex'])
        $sexus = '<img src="../theme/images/' . ($res['sex'] == 'm' ? 'm' : 'w') . ($res['datereg'] > $realtime - 86400 ? '_new' : ''). '_'.($realtime > $res['lastdate'] + 1200 ? 'of' : 'oon') . '.png" width="16" height="8" align="middle" />&nbsp;';
        else
            $sexus = '<img src="../theme/images/del.png" width="12" height="12" align="middle" />&nbsp;';


             // ����� �����


				$tim = ' <span class="gray">' . date("d.m.Y � H:i", $res['time'] + $set_user['sdvig'] * 3600) . '</span>';




                     ////////////////////////////////////////////////////////////
                    // ����� ������ �����                                     //
                    ////////////////////////////////////////////////////////////



				$text = $res['text'];
                    if ($set_forum['postcut'])
					{
                        // ���� ����� �������, �������� � ���� ������ �� ������ �������
                        switch ($set_forum['postcut']) {
                            case 2:
                                $cut = 5000;
                                break;

                            case 3:
                                $cut = 5000;
                                break;
                                default :
                            $cut = 500;
                        }
                    }

if ($set_forum['postcut'] && mb_strlen($text) > $cut)
					{
                        $text = mb_substr($text, 0, $cut);
                        $text = checkout($text, 1, 1);
                    	$text = table_bbcode($text);
                        if ($set_user['smileys'])
                            $text = smileys($text, $res['rights'] ? 1 : 0);
                        echo $text . '...<br /><a href="index.php?act=post&amp;id=' . $res['id'] . '">������ ��� &gt;&gt;</a>';



                    }


				else
					{
                        // ���, ������������ ���� � ������� ���� �����

                        $text = checkout($text, 1, 1);
                    	$text = table_bbcode($text);
					//echo $text;//steret`
            if ($set_user['smileys'])
                            $text = smileys($text, $res['rights'] ? 1 : 0);


                    }
                    if ($res['kedit']) {
                        // ���� ���� ��������������, ���������� ��� � �����
                        $dizm = date("d.m /H:i", $res['tedit'] + $set_user['sdvig'] * 3600);
                        echo '<br /><span class="gray"><small>���. <b>' . $res['edit'] . '</b> (' . $dizm . ') <b>[' . $res['kedit'] . ']</b></small></span>';
                    }

if ($datauser['total_on_site'] < 100){
				$id = 1;
			}

				// ���� ���� ������������� ����, ������� ��� ��������
                    $freq = sql_query("SELECT * FROM `cms_forum_files` WHERE `post` = '" . $res['id'] . "'");
                    if (sql_num_rows($freq) > 0) {
                        $fres = sql_fetch_assoc($freq);
                        $fls = round(filesize('./files/' . $fres['filename']) / 1024, 2);
                        echo '<br /><span class="gray">������������ ����:';
                        // ������������ �����������
                        $att_ext = strtolower(format('./files/' . $fres['filename']));
                        $pic_ext = array (
                            'gif',
                            'jpg',
                            'jpeg',
                            'png'
                        );
                        if (in_array($att_ext, $pic_ext)) {
                            echo '<div><a href="index.php?act=file&amp;id=' . $fres['id'] . '">';
                            echo '<img src="thumbinal.php?file=' . (urlencode($fres['filename'])) . '" alt="������� ��� ��������� �����������" /></a></div>';
                        } else {
                            echo '<br /><a href="index.php?act=file&amp;id=' . $fres['id'] . '">' . $fres['filename'] . '</a>';
                        }
                        echo ' (' . $fls . ' ��.)<br/>';
                        echo '�������: ' . $fres['dlcount'] . ' ���.</span>';
                    }

	if ((($rights == 3 || $rights >= 6 || $curator) && $rights >= $res['rights']) || ($res['user_id'] == $user_id && !$set_forum['upfp'] && ($start + $i) == $colmes && $res['time'] > $realtime - 300)
                        || ($res['user_id'] == $user_id && $set_forum['upfp'] && $start == 0 && $i == 1 && $res['time'] > $realtime - 300))
	{





                        // ������ �� �������������� / �������� ������
                        echo '<div class="sub">';
                        if ($rights == 3 || $rights >= 6)
                            echo '<input type="checkbox" name="delch[]" value="' . $res['id'] . '"/>&nbsp;';
                        echo '<a href="index.php?act=editpost&amp;id=' . $res['id'] . '">��������</a> | ';
                        if ($rights >= 7 && $res['close'] == 1)
                            echo '<a href="index.php?act=editpost&amp;do=restore&amp;id=' . $res['id'] . '">������������</a> | ';

                        if ($res['close']) {
                            echo '<div class="red">���� ������: <b>' . $res['close_who'] . '</b></div>';
                            } elseif (!empty($res['close_who'])) {
                            echo '<div class="green">���� �����������: <b>' . $res['close_who'] . '</b></div>';

                        }
                        if ($rights == 3 || $rights >= 6)
                            echo '<div class="gray">' . $res['ip'] . ' - ' . $res['soft'] . '</div>';
                        echo '</div>';
                    }
                    echo '</div>';
                    ++$i;














                 // ����� ���������
                    $user_rights = array (
                        2 => '��������� ����',
						3 => '��������� ������',
                        6 => '������� ���������',
                        7 => '��������� ������������',
                        9 => '������������ �����'
                    );



echo '<tr class="bmenu"><td align="center" valign="midle" width="100px.">'.$sexus.''.$nikuser.'</td>';
echo'<td align="left" valign="midle" width="80%">'.$tim.' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';





                    // ������ �� ����� � �����������
                    if ($user_id && $user_id != $res['user_id']) {
                        echo '<a href="index.php?act=say&amp;id=' . $res['id'] . '&amp;start=' . $start . '">��������</a>&nbsp;&nbsp;&nbsp;<a href="index.php?act=say&amp;id=' . $res['id'] . '&amp;start=' . $start . '&amp;cyt">����������</a> ';
                    }






                                        if ($rights == 3 || $rights >= 6)
										{
                    echo '&nbsp;&nbsp;(<a href="index.php?act=editpost&amp;do=del&amp;id=' . $res['id'] . '">�������</a>)</td></tr>';
										}
				else
                    {
echo'</td></tr>';
                    }


echo '<tr class="list2"><td align="center" valign="midle" width="100px.">';
 echo $user_rights[$res['rights']];
echo "$ava <br/>";










			// ���� �������
if (!$set_chat['medal'] && $res['medal'] > 0) {
$qg = sql_query("SELECT * FROM `medals` WHERE `user` = '" . $res['user_id'] . "' ORDER BY `time` DESC LIMIT 4;");
 while ($rh = sql_fetch_assoc($qg)) {
  echo '<img src="../images/medals/' . $rh['medal'] . '.png" width="10" height="10" alt="" align="middle" /> ';
 }
}
echo '<br/>';
/*** Mod by MyZik ***/

 $user = sql_fetch_assoc(sql_query("SELECT * FROM `users` WHERE `id` = '" . $res['user_id'] . "'"));
// ������
                    if ($user['postforum'] >= 0 && $user['postforum'] <= 49)
                      $Rank = '<font color="orange "><b>��������</b></font>';
                    if ($user['postforum'] >= 50 && $user['postforum'] <= 99)
                      $Rank = '<font color="green "><b>�������</b></font>';
                    if ($user['postforum'] >= 100 && $user['postforum'] <= 149)
                      $Rank = '<font color="blue "><b>��� �������</b></font>';
                    if ($user['postforum'] >= 150 && $user['postforum'] <= 199)
                      $Rank = '<font color="red "><b>����������</b></font>';
                    if ($user['postforum'] >= 200 && $user['postforum'] <= 299)
                      $Rank = '��������';
                    if ($user['postforum'] >= 300 && $user['postforum'] <= 499)
                      $Rank = '�������';
                    if ($user['postforum'] >= 500 && $user['postforum'] <= 799)
                      $Rank = '������������';
                    if ($user['postforum'] >= 800 && $user['postforum'] <= 999)
                      $Rank = '<font color="orange "><b>������ ������</b></font>';
                    if ($user['postforum'] >= 1000 && $user['postforum'] <= 99999999)
                      $Rank = '���� ������';


                   // ������
                    if ($user['postforum'] >= 150 && $user['postforum'] <= 299)
                      $Medal = '<img src="/images/rank/bronze.png" alt="" />';
                    if ($user['postforum'] >= 300 && $user['postforum'] <= 499)
                      $Medal = '<img src="/images/rank/silver.png" alt="" />';
                    if ($user['postforum'] >= 500 && $user['postforum'] <= 99999999)
                      $Medal = '<img src="/images/rank/gold.png" alt="" />';
/*** End ***/


/*** Mod by MyZik ***/


 // ����� ������
 echo '<span class="red"><img src="../images/icons/rank.png" alt="" /> ' . $Rank . '</span>';
/*** End ***/

//������ �����
        if (!$set_chat['status'] && !empty($res['img_status']))
            echo '<br /><img src="../images/icon_icq/' . $res['img_status'] . '.gif" alt="" align="middle" width="20" height="20" />' . ($user_id && $res['from'] == $user_id ? '<a href="' . $home . '/str/icq_status.php">' . $res['status'] . '</a>' : $res['status']) . '<br />';




echo'</td><td align="left" valign="top" width="80%">';
echo $text;
echo'</td></tr>';
               echo '</table>';
                 echo '<br/>';


                ++$i;
                }

	#########################################################################################







			  if ($rights == 3 || $rights >= 6) {
                    echo '<div class="rmenu"><input type="submit" value=" ������� "/></div>';
                    echo '</form>';
                }


  echo '<div class="phdr">����� ���������: ' . $colmes . '</div>';
			if ($colmes > $kmess) {
				{
				 echo '<div class="frame">';
                    echo '<p>' . pagenav('index.php?id=' . $id . '&amp;', $start, $colmes, $kmess) . '</p>';
                    echo '<p><form action="index.php" method="get"><input type="hidden" name="id" value="' . $id . '"/><input type="text" name="page" size="2"/><input type="submit" value="� �������� &gt;&gt;"/></form></p>';


            }






                // ������ ���� "��������"
                    if (($user_id && !$type1['edit'] && !$set_forum['upfp']) || ($rights >= 7 && !$set_forum['upfp'])) {





                    echo '<div class="bmenu"><form  name="form2" action="index.php?act=say&amp;id=' . $id . '" method="post">';
                    if ($set_forum['farea']) {
                        echo auto_bb('form2', 'msg');
                        echo '<textarea cols="' . $set_forum['farea_w'] . '" rows="' . $set_forum['farea_h'] . '" name="msg" spellcheck="true"></textarea><br/>';
                        echo '<input type="checkbox" name="addfiles" value="1" /> �������� ����<br/>';
                        if ($set_user['translit'])
                            echo '<input type="checkbox" name="msgtrans" value="1" /> �������� ���������<br/>';
                    }
                    echo '<input type="submit" name="submit" value="��������"/>';
                    echo '</form></div>';
 echo '</div>';
                }

}
                else {
                    echo '<br />';
                }



			// ������ �� �������� ��� � ��� ����� ��������



                if($curators) {
                    $array = array();
                    foreach($curators as $key=>$value)
                        $array[] = '<a href="../id=' . $key . '">' . $value . '</a>';
                    echo '<p><div class="warning">��������: ' . implode(', ', $array) . '</div></p>';
                }
                if ($rights == 3 || $rights >= 6) {
                    echo '<p><div class="warning">';
                    if($rights >= 7)
                        echo '<a href="index.php?act=curators&amp;id=' . $id . '&amp;start=' . $start . '">�������� ����</a><br />';
                    echo $topic_vote > 0 ? '<a href="index.php?act=editvote&amp;id=' . $id . '">�������� �����</a><br/><a href="index.php?act=delvote&amp;id=' . $id . '">������� �����</a><br/>'
                        : '<a href="index.php?act=addvote&amp;id=' . $id . '">�������� �����</a><br/>';
                    echo "<a href='index.php?act=ren&amp;id=" . $id . "'>������������� ����</a><br/>";
                    // ������� - ������� ����
                    if ($type1['edit'] == 1)
                        echo "<a href='index.php?act=close&amp;id=" . $id . "'>������� ����</a><br/>";
                    else
                        echo "<a href='index.php?act=close&amp;id=" . $id . "&amp;closed'>������� ����</a><br/>";
                    // ������� - ������������ ����
                    if ($type1['close'] == 1)
                        echo "<a href='index.php?act=restore&amp;id=" . $id . "'>������������ ����</a><br/>";
                    echo "<a href='index.php?act=deltema&amp;id=" . $id . "'>������� ����</a><br/>";
                    if ($type1['vip'] == 1)
                        echo "<a href='index.php?act=vip&amp;id=" . $id . "'>��������� ����</a>";
                    else
                        echo "<a href='index.php?act=vip&amp;id=" . $id . "&amp;vip'>��������� ����</a>";
                    echo "<br/><a href='index.php?act=per&amp;id=" . $id . "'>����������� ����</a></div></p>";
                }
                if ($user_id) {
                    $onltime = $realtime - 300;
                    $online_u = sql_result(sql_query("SELECT COUNT(*) FROM `users` WHERE `lastdate` > $onltime AND `place` = 'forum,$id'"), 0);
                    $online_g = sql_result(sql_query("SELECT COUNT(*) FROM `cms_guests` WHERE `lastdate` > $onltime AND `place` = 'forum,$id'"), 0);
                    echo '<p><div class="warning">';
					echo '<a href="index.php?act=who&amp;id=' . $id . '">��� �����?&nbsp;(' . $online_u . '&nbsp;/&nbsp;' . $online_g . ')</a><br/>';
                }
                if ($filter)
                    echo '<div><a href="index.php?act=filter&amp;id=' . $id . '&amp;do=unset">�������� ����������</a></div>';
                else
                    echo '<div><a href="index.php?act=filter&amp;id=' . $id . '&amp;start=' . $start . '">����������� ���������</a></div>';
			echo '<a href="index.php?act=tema&amp;id=' . $id . '">������� ����</a></p>';
			echo '</div>';
			break;

            default:
                echo '<p><b>������!</b><br />���� ������� ��� �� ����������!</p>';
                break;
        }











} ####################################################################



else


{
        ////////////////////////////////////////////////////////////
        // ������ ��������� ������                                //
        ////////////////////////////////////////////////////////////


########################################################################
if ($theme == 'wap') {


	echo '<div class="bmenu"><b>�����</b>';

		echo '<div class="warning122" > ';
   echo '<table border="0"  id="example" cellspacing="1" cellpadding="4">';

   echo '<tr bgcolor="ffffff">
		<td><div class="yellow"><b>';

     forum_new(1);

		 echo '</b></a></div></td>
		 <td><div class="yellow"><b><a href="search.php">����� �� ������</b></a></div></td></tr>
		 <tr>
		 <td><div class="yellow"><b><a href="/rules/forum.php">������� ������</a></b></div></td>
		 <td><b><a href="index.php?act=faq">FAQ</a></b></td>
		 </tr>
		 </table>';
		 echo ' </div>';
echo ' ';
}

####################################################################

 if ($theme == 'web') {

echo '<div class="loop"><div class="gmeenu">�����</div>';


   echo '<table border="0"  id="example" cellspacing="1" cellpadding="4">';

   echo '<tr bgcolor="ffffff">
		<td><div class="yellow"><b>';

     forum_new(1);

		 echo '</b></a></div></td>
		 <td><div class="yellow"><b><a href="search.php">����� �� ������</b></a></div></td></tr>
		 <tr>
		 <td><div class="yellow"><b><a href="/rules/forum.php">������� ������</a></b></div></td>
		 <td><b><a href="index.php?act=faq">FAQ</a></b></td>
		 </tr>
		 </table>';



}
#######################################################################










        $forum = array();
        $req_f= sql_query("SELECT `id`, `text`, `soft`, `refid`, `icon` FROM `forum` WHERE `type`='r' ORDER BY `refid`, `realid`");
        while ($res_f = sql_fetch_array($req_f)) {
               $coltem = sql_result(sql_query("SELECT COUNT(*) FROM `forum` WHERE `type` = 't' AND `refid` = '" . $res_f['id'] . "'"), 0);
               $forum[$res_f['refid']] .= ($fi % 2) ? '<tr class="oddnrows">' : '<tr class="evenrows">';
			$forum[$res_f['refid']] .= '<td>' . ($user_id && $rights >= 8 ? '<a href="index.php?act=icons&amp;num=' . $res_f['id'] . '">' : '') . '<img src="icons/' . ($res_f['icon'] ? $res_f['icon'] : '240363.png') . '" alt="" width="16" height="16" style="vertical-align:middle;" />' . ($user_id && $rights >= 8 ? '</a>' : '') . ' <a href="index.php?id=' . $res_f['id'] . '"> <font color="#3587ED "><b>' . $res_f['text'] . '</b></font></a></td><td align="center" width="10%">' . $coltem . '';
               if (!empty ($res_f['soft']))
                   $forum[$res_f['refid']] .='<div class="oddnrows"><span class="evenrows">' . $res_f['soft'] . '</span></div>';
               $forum[$res_f['refid']] .= '</td></tr>';
               ++$fi;
        }
        echo '
<table id="example">
';

        $req = sql_query("SELECT `id`, `text`, `soft` FROM `forum` WHERE `type`='f' ORDER BY `realid`");
        while ($res = sql_fetch_array($req)) {

            echo '<center><tr class="rmenu1"><td colspan="2"> <b>' . $res['text'] . '</b> </center>';
            if (!empty ($res['soft']))
                echo '<div class="sub"><span class="gray">' . $res['soft'] . '</span></div>';
            echo '</td></tr>' . $forum[$res['id']];
        }
        echo '</table>';
        $onltime = $realtime - 300;
        $online_u = sql_result(sql_query("SELECT COUNT(*) FROM `users` WHERE `lastdate` > $onltime AND `place` LIKE 'forum%'"), 0);
        $online_g = sql_result(sql_query("SELECT COUNT(*) FROM `cms_guests` WHERE `lastdate` > $onltime AND `place` LIKE 'forum%'"), 0);
        echo '<div class="warning">' . ($user_id ? '<a href="index.php?act=who">��� � ������</a>' : '��� � ������') . '&nbsp;(' . $online_u . '&nbsp;/&nbsp;' . $online_g . ')</div>';
        unset ($_SESSION['fsort_id']);
        unset ($_SESSION['fsort_users']);
    }

    ////////////////////////////////////////////////////////////
    // ������� ������ � ������ �� ���                         //
    ////////////////////////////////////////////////////////////

	{

	echo '<div class="frame">';




    $sql = ($rights == 9) ? "" : " AND `del` != '1'";
    if ($id && $tip == 'f') {
        $count = sql_result(sql_query("SELECT COUNT(*) FROM `cms_forum_files` WHERE `cat` = '$id'" . $sql), 0);
        if ($count > 0)
            echo '<p><a href="index.php?act=files&amp;c=' . $id . '">����� �������</a>&nbsp;(' . $count . ')</p>';
        else
            echo '<div class="warning"><p>������������� ������ ���</p>';
    } elseif ($id && $tip == 'r') {
        $count = sql_result(sql_query("SELECT COUNT(*) FROM `cms_forum_files` WHERE `subcat` = '$id'" . $sql), 0);
        if ($count > 0)
			echo '<a href="index.php?act=files&amp;s=' . $id . '">����� ����������</a>&nbsp;(' . $count . ')';
        else
            echo '<p>������������� ������ ���';
    } elseif ($id && $tip == 't') {
        $count = sql_result(sql_query("SELECT COUNT(*) FROM `cms_forum_files` WHERE `topic` = '$id'" . $sql), 0);
        if ($count > 0)
            echo '<p><a href="index.php?act=files&amp;t=' . $id . '">����� ������</a>&nbsp;(' . $count . ')';
        else
            echo '<p>������������� ������ ���';
		echo '</div>';
    } else {

/*        $sql = ($rights == 9) ? '' : " WHERE `del` != '1'";
        $count = sql_result(sql_query("SELECT COUNT(*) FROM `cms_forum_files`" . $sql), 0);
        if ($count > 0)
            echo '<p><a href="index.php?act=files">����� ������</a>&nbsp;(' . $count . ')</p>';
        else
            echo '<p>������������� ������ ���</p>';*/
    }
    // ��������� ����� ��������
    echo '<p>' . ($id ? '<a href="index.php">� �����</a><br />' : '') . '';

	echo '</div>';

	}






    if (!$id) {

        //echo '<a href="index.php?act=faq">FAQ</a>';
    }

    if (!$user_id) {
        if ((empty($_SESSION['uppost'])) || ($_SESSION['uppost'] == 0)) {
            echo "<a href='index.php?id=" . $id . "&amp;page=" . $page . "&amp;newup'>����� ������</a><br/>";
        } else {
            echo "<a href='index.php?id=" . $id . "&amp;page=" . $page . "&amp;newdown'>����� �����</a><br/>";
        }
    }
}

require_once("../incfiles/end.php");
?>