<?
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';
$ID = intval($_GET['id']);
if (isset($_GET['id']) && $_GET['id']!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum_theme` WHERE `id` = '".intval($_GET['id'])."'"),0)!=0){	
}else{
	header("Location: /");
	exit;
}
$theme = mysql_fetch_array(mysql_query("SELECT * FROM `comm_forum_theme` WHERE `id` = '".intval($ID)."' LIMIT 1"));
$ank2 = get_user($theme['id_user']);
$razdel = mysql_fetch_array(mysql_query("SELECT * FROM `comm_forum_razdel` WHERE `id` = '".intval($theme['id_razdel'])."' LIMIT 1"));
$comm = get_comm($razdel['id_comm']);
$moder = mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_user` WHERE `id_user` = '".intval($user['id'])."' AND `id_comm` = '$comm[id]' AND `level` > '0'"),0);
$set['title']='Форум сообщества '.text($comm['name']).' - '.text($theme['name']).''; // заголовок страницы
include_once '../sys/inc/thead.php';
title();
aut();
//======================Начало приватности сообщества===============================//
	if(isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_blacklist` WHERE `id_user` = '$user[id]' AND `id_comm` = '$comm[id]' && (`time_ban` > '$time' OR `navsegda` = '1')"),0)!=0){
	echo'<div class="mess">Вы были забанены ';
	$banned = mysql_fetch_array(mysql_query("SELECT * FROM `comm_blacklist` WHERE `id_user` = '$user[id]' AND `id_comm` = '$comm[id]'"));
	$bancon = mysql_fetch_array(mysql_query("SELECT * FROM `comm_user` WHERE `id_user` = '$banned[id_ban]' AND `id_comm` = '$comm[id]'"));
	if($bancon['level']==1){
		echo 'модератором ';
	}elseif($bancon['level']==2){
		echo 'администратором ';
	}elseif($bancon['level']==3){
		echo 'создателем ';
	}
	echo group($bancon['id_user']);
	echo user::nick($bancon['id_user'],1,1,1);
	if($banned['navsegda']==1){
		echo' навсегда!';
	}else{
		$timefe = $banned['time_ban']-$banned['time'];
		echo ' на ';
		if($timefe>3600){
			$timef = $timefe/3600;
			$timefe = floor($timef);
			
			$timem = $timef-$timefe;
			if($timem==0){
			echo''.$timefe.' часов!';
			}else{
				$timem = round($timem*60);
				echo''.$timefe.' часов '.$timem.' минут!';
			}
		}elseif($timefe<3600){
			$timef = $timefe/60;
			$timefe = round($timef);
			echo''.$timefe.' минут!';
		}
		echo ' <small>';
		echo vremja($banned['time']);
		echo '</small>';
	}
		echo "</div><div class='foot'><img src='/style/icons/str2.gif' alt=''/> <a href='/comm/cat.php?id=$comm[id_category]'>Назад в категорию</a></div>"; 
		include_once '../sys/inc/tfoot.php';
		exit;
	}
	//===========================================//
	if($comm['close']==1 && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_user` WHERE `id_comm` = '".intval($comm['id'])."' AND `id_user` = '$user[id]'"),0)==0){
		echo'<div class="mess">Сообщество закрыто для чтения!</div>';
		echo "<div class='foot'><img src='/style/icons/str2.gif' alt=''/> <a href='/comm/$comm[id]/'>В сообщество</a></div>";
		include_once '../sys/inc/tfoot.php';
		exit;
	}
	//================Конец приватности сообщества=====================//
if(isset($_GET['edit']) && (mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum_post` WHERE `id_them` = '$theme[id]' AND `id_razdel` = '$razdel[id]' AND `id_user` = '$user[id]' AND `id` = '".intval($_GET['edit'])."' LIMIT 1"),0)!=0 || user_access('comm_edit') && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum_post` WHERE `id_them` = '$theme[id]' AND `id_razdel` = '$razdel[id]' AND `id` = '".intval($_GET['edit'])."' LIMIT 1"),0)!=0 || $moder!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum_post` WHERE `id_them` = '$theme[id]' AND `id_razdel` = '$razdel[id]' AND `id` = '".intval($_GET['edit'])."' LIMIT 1"),0)!=0)){
	$post = mysql_fetch_array(mysql_query("SELECT * FROM `comm_forum_post` WHERE `id_them` = '$theme[id]' AND `id_razdel` = '$razdel[id]' AND `id` = '".intval($_GET['edit'])."'"));
	if($post['time']>(time()-600) || $moder!=0 || user_access('comm_edit')){
	if(isset($_GET['ok']) && isset($_POST['save']) && isset($_POST['msg'])){
		
		$msg=my_esc($_POST['msg']);

if (strlen2($msg)<2)$err='Короткое сообщение';

if (strlen2($msg)>1024)$err='Длина сообщения превышает предел в 1024 символа';



$mat=antimat($msg);

if ($mat)$err[]='В тексте сообщения обнаружен мат: '.$mat;


err();
if (!isset($err))

{



if (isset($_POST['cit']) && is_numeric($_POST['cit']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum_post` WHERE `id` = '".intval($_POST['cit'])."' AND `id_them` = '".intval($_GET['id_them'])."' AND `id_razdel` = '".intval($_GET['id_razdel'])."'"),0)==1)

$cit=intval($_POST['cit']); else $cit='null';

mysql_query("UPDATE `comm_forum_post` SET `msg` = '$msg' WHERE `id_them` = '$theme[id]' AND `id_razdel` = '$razdel[id]' AND `id_user` = '$user[id]' AND `id` = '$post[id]' LIMIT 1");
$_SESSION['message'] = 'Пост успешно изменен';
header("Location: /comm/theme/$theme[id]/");
exit;

}
		
	}
	echo "<form method='post' action='?edit=$post[id]&ok'>\n";

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

echo "Редактирование поста <b>".output_text($post['msg'])."</b>\n";

echo "</div>";



echo "<div class=\"main\">\n";


echo "Сообщение:$tPanel<textarea name=\"msg\">".text($post['msg'])."</textarea><br />\n";

echo "<input name=\"save\" value=\"Сохранить\" type=\"submit\" /> \n";

echo "<img src='/style/icons/delete.gif' alt='*'> <a href='?'>Отмена</a><br />\n";

echo "</form>\n";

echo "</div>";



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

echo "<img src='/style/icons/str2.gif' alt='*'> <a href='?'>В тему</a><br />\n";

echo "</div>";





include_once '../sys/inc/tfoot.php';

exit;

}
}
if (isset($user) && isset($_GET['new']) && isset($_POST['msg']) && ($theme['close']==0  || $theme['close']==1 && user_access('comm_edit') || $theme['close']==1 && $moder!=0))
{
$msg=my_esc($_POST['msg']);

if (strlen2($msg)<2)$err='Короткое сообщение';

if (strlen2($msg)>1024)$err='Длина сообщения превышает предел в 1024 символа';



$mat=antimat($msg);

if ($mat)$err[]='В тексте сообщения обнаружен мат: '.$mat;



if (mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum_post` WHERE `id_them` = '$theme[id]' AND `id_razdel` = '$razdel[id]' AND `id_user` = '$user[id]' AND `msg` = '".my_esc($msg)."' LIMIT 1"),0)!=0)$err='Ваше сообщение повторяет предыдущее';


err();
if (!isset($err))

{



if (isset($_POST['cit']) && is_numeric($_POST['cit']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum_post` WHERE `id` = '".intval($_POST['cit'])."' AND `id_them` = '".intval($_GET['id_them'])."' AND `id_razdel` = '".intval($_GET['id_razdel'])."'"),0)==1)

$cit=intval($_POST['cit']); else $cit='null';

mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");

mysql_query("INSERT INTO `comm_forum_post` (`id_razdel`, `id_them`, `id_user`, `msg`, `time`, `cit`) values('$razdel[id]', '$theme[id]', '$user[id]', '".my_esc($msg)."', '$time', '$cit')");



$post_id=mysql_insert_id();





unset($_SESSION['msg']);



	$ank=get_user($theme['id_user']); // Определяем автора





		mysql_query("UPDATE `user` SET `rating_tmp` = '".($user['rating_tmp']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
		mysql_query("UPDATE `comm_forum_theme` SET `time_create` = '$time' WHERE `id` = '$theme[id]' LIMIT 1");




$_SESSION['message'] = 'Сообщение успешно добавлено';

header("Location: ?page=".intval($_GET['page'])."");

exit;

}

}
if ($theme['close']==1)$err = 'Тема закрыта для обсуждения';


/*

======================================

Перемещение темы

======================================

*/

if (isset($user) && isset($_GET['act']) && $_GET['act']=='mesto' && (user_access('comm_edit') || $ank2['id']==$user['id'] || $moder!=0))

{
if(isset($_GET['ok']) && isset($_POST['razdel']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum_razdel` WHERE `id` = '".intval($_POST['razdel'])."' AND `id_comm` = '$comm[id]'"),0)==1){
	$razdel_new=mysql_fetch_assoc(mysql_query("SELECT * FROM `comm_forum_razdel` WHERE `id` = '".intval($_POST['razdel'])."' LIMIT 1"));

mysql_query("UPDATE `comm_forum_post` SET `id_razdel` = '$razdel_new[id]' WHERE `id_razdel` = '$razdel[id]' AND `id_them` = '$theme[id]'");
mysql_query("UPDATE `comm_forum_theme` SET `id_razdel` = '$razdel_new[id]' WHERE `id_razdel` = '$razdel[id]' AND `id` = '$theme[id]'");
$old_razdel=$razdel;
$razdel=mysql_fetch_assoc(mysql_query("SELECT * FROM `comm_forum_razdel` WHERE `id` = '$razdel_new[id]' LIMIT 1"));
$them=mysql_fetch_assoc(mysql_query("SELECT * FROM `comm_forum_theme` WHERE `id_razdel` = '$razdel[id]' AND `id` = '$theme[id]' LIMIT 1"));

/*(c)Кредитор & (c)ShaMan*/
$msgg='[red]Тему переместил '.$user['group_name'].' '.$user['nick'].' из раздела '.$old_razdel['name'].' в раздел '.$razdel['name'].'[/red]';
mysql_query("INSERT INTO `comm_forum_post` (`id_razdel`, `id_them`, `id_user`, `msg`, `time`) values('$razdel[id]', '$them[id]', '0', '".my_esc($msgg)."', '$time')");
/*тут конец*/


$_SESSION['message'] = 'Тема успешно перемещена';
header("Location: /comm/theme/$theme[id]/");
exit;
}
echo "<form method=\"post\" action=\"?act=mesto&ok\">\n";



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

echo "Перемещение темы <b>".output_text($theme['name'])."</b>\n";

echo "</div>";



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

echo "Раздел:<br />\n";

echo "<select name=\"razdel\">\n";


$q2 = mysql_query("SELECT * FROM `comm_forum_razdel` WHERE `id_comm` = '$comm[id]' ORDER BY `id` DESC");

while ($razdels = mysql_fetch_assoc($q2))

{

echo "<option".($razdel['id']==$razdels['id']?' selected="selected"':null)." value=\"$razdels[id]\">" . text($razdels['name']) . "</option>\n";


}


echo "</select><br />\n";



echo "<input value=\"Переместить\" type=\"submit\" /> \n";

echo "</form>\n";



echo "</div>";



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

echo "<img src='/style/icons/str2.gif' alt='*'> <a href='?'>В тему</a><br />\n";

echo "</div>";





include_once '../sys/inc/tfoot.php';

exit;

}
if (isset($user) && isset($_GET['act']) && $_GET['act']=='set' && (user_access('comm_edit') || $ank2['id']==$user['id'] || $moder!=0))
{
//--------------------------редактирование темы-----------//

if(isset($_GET['ok']) && isset($_POST['name']) && isset($_POST['msg']) && isset($_POST['save'])){
	$name=my_esc($_POST['name']);
$msg=my_esc($_POST['msg']);

if (strlen2($name)<3)$err='Слишком короткое название';
if (strlen2($name)>100)$err='Слишком длинное название';


if ($user['level']>0 || $moder!=0){
if (isset($_POST['up']) && $_POST['up']==1)
{
$up=1;
$msgg='[red]Тему закрепил '.$user['group_name'].' '.$user['nick'].'[/red]';
mysql_query("INSERT INTO `comm_forum_post` (`id_razdel`, `id_them`, `id_user`, `msg`, `time`) values('$razdel[id]', '$theme[id]', '0', '".my_esc($msgg)."', '$time')");
/*тут конец*/
}
else $up=0;
$add_q=" `up` = '$up',";
}
else $add_q=NULL;

if (isset($_POST['close']) && $_POST['close']==1 && $theme['close']==0){
$close=1;

$msgg='[red]Тему закрыл '.$user['group_name'].' '.$user['nick'].'[/red]';
mysql_query("INSERT INTO `comm_forum_post` (`id_razdel`, `id_them`, `id_user`, `msg`, `time`) values('$razdel[id]', '$theme[id]', '0', '".my_esc($msgg)."', '$time')");
/*тут конец*/

}
elseif ($theme['close']==1 && (!isset($_POST['close']) || $_POST['close']==0))
{
$close=0;
$msgg='[red]Тему открыл '.$user['group_name'].' '.$user['nick'].'[/red]';
mysql_query("INSERT INTO `comm_forum_post` (`id_razdel`, `id_them`, `id_user`, `msg`, `time`) values('$razdel[id]', '$theme[id]', '0', '".my_esc($msgg)."', '$time')");
/*тут конец*/

}

else $close=$theme['close'];


if (isset($_POST['autor']) && $_POST['autor']==1)$autor=$user['id'];else $autor=$ank2['id'];

err();
if (!isset($err)){
mysql_query("UPDATE `comm_forum_theme` SET `name` = '$name', `text` = '$msg', `id_user` = '$autor',$add_q `close` = '$close' WHERE `id` = '$theme[id]' LIMIT 1");
$_SESSION['message'] = 'Изменения успешно приняты';
header("Location: /comm/theme/$theme[id]/");
exit;
}
}

//=========================================================//
echo "<form method='post' action='?act=set&ok'>\n";

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

echo "Редактирование темы <b>".output_text($theme['name'])."</b>\n";

echo "</div>";



echo "<div class=\"main\">\n";

echo "Название:<br />\n";

echo "<input name='name' type='text' maxlength='100' value='".text($theme['name'])."' /><br />\n";



echo "Сообщение:$tPanel<textarea name=\"msg\">".text($theme['text'])."</textarea><br />\n";



if ($user['level']>0 || $moder!=0){

if ($theme['up']==1)$check=' checked="checked"';else $check=NULL;

echo "<label><input type=\"checkbox\"$check name=\"up\" value=\"1\" /> Всегда наверху</label><br />\n";

}

if ($theme['close']==1)$check=' checked="checked"';else $check=NULL;

echo "<label><input type=\"checkbox\"$check name=\"close\" value=\"1\" /> Закрыть</label><br />\n";





if ($ank2['id']!=$user['id']){

echo "<label><input type=\"checkbox\" name=\"autor\" value=\"1\" /> Забрать у автора права</label><br />\n";

}



echo "<input name=\"save\" value=\"Изменить\" type=\"submit\" /> \n";

echo "<img src='/style/icons/delete.gif' alt='*'> <a href='?'>Отмена</a><br />\n";

echo "</form>\n";

echo "</div>";



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

echo "<img src='/style/icons/str2.gif' alt='*'> <a href='?'>В тему</a><br />\n";

echo "</div>";





include_once '../sys/inc/tfoot.php';

exit;

}
if (isset($_GET['del']) && isset($user) && (user_access('comm_edit') || $ank2['id']==$user['id'] || $moder!=0 || mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum_post` WHERE `id` = '".intval($_GET['del'])."' AND `id_them` = '".intval($theme['id'])."' AND `id_razdel` = '".intval($razdel['id'])."' AND `id_user` = '".intval($user['id'])."'"),0)==1)) // удаление поста
{
			mysql_query("DELETE FROM `comm_forum_post` WHERE `id` = '" . intval($_GET['del']) . "' LIMIT 1");
			$_SESSION['message'] = 'Сообщение успешно удалено'; 
			header("Location: ?page=" . intval($_GET['page']) . "");
			exit;

}
//------------------Удаление темы--------------//
if (isset($_GET['act']) && $_GET['act']=='del' && (user_access('comm_edit') && $ank2['level']<=$user['level'] || $ank2['id']==$user['id'] || $moder!=0))

{
	if(isset($_GET['ok'])){

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_votes` WHERE `id_them` = '$theme[id]'"), 0) > 0)
{
	$qopros=mysql_fetch_array(mysql_query("SELECT * FROM `comm_votes` WHERE `id_them` = '$theme[id]'"));
	$qdelopros=mysql_query("SELECT * FROM `comm_votes_variant` WHERE `id_votes` = '$qopros[id]'");
	$qdeluser=mysql_query("SELECT * FROM `comm_votes_user` WHERE `id_votes` = '$qopros[id]'");
	while ($postu = mysql_fetch_assoc($qdeluser))
	{
		mysql_query("DELETE FROM `comm_votes_user` WHERE `id` = '$postu[id]'");
	}
			while ($posto = mysql_fetch_assoc($qdelopros))
			{
				mysql_query("DELETE FROM `comm_votes_variant` WHERE `id` = '$posto[id]'");
			}
	mysql_query("DELETE FROM `comm_votes` WHERE `id_them` = '$theme[id]'");
}
mysql_query("DELETE FROM `comm_forum_theme` WHERE `id` = '$theme[id]'");
mysql_query("DELETE FROM `comm_forum_post` WHERE `id_them` = '$theme[id]'");

$_SESSION['message'] = 'Тема успешно удалена';
header("Location: /comm/forumcat/$razdel[id]/");
exit;
	}

echo "<div class=\"mess\">\n";

echo "Подтвердите удаление темы <b>".output_text($theme['name'])."</b><br />\n";

echo "</div>\n";



echo "<div class=\"main\">\n";

echo "[<a href=\"?act=del&ok\"><img src='/style/icons/ok.gif' alt='*'> Да</a>] [<a href=\"?\"><img src='/style/icons/delete.gif' alt='*'> Нет</a>]<br />\n";

echo "</div>\n";





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

echo "<img src='/style/icons/str2.gif' alt='*'> <a href='?'>В тему</a><br />\n";

echo "</div>";





include_once '../sys/inc/tfoot.php';

exit;

}
//-----------------------------------------------//
echo "<div class='nav1'><img src='/style/icons/font.png' alt='*' /> Создана: ".vremja($theme['time'])."</div>";

echo "<div class='nav2'>".output_text($theme['text'])."</div>";
// Прекрепленные опросы
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_votes` WHERE `id_them` = '$theme[id]'"), 0) > 0){
	$votes = mysql_fetch_array(mysql_query("SELECT * FROM `comm_votes` WHERE `id_them` = '$theme[id]'"));
	echo'<div class="nav2">';
	echo'<img src="/style/icons/votes.png"> Опрос:<br />';
	echo text($votes['msg']);
	echo'</div>';
	$opros=mysql_query("SELECT * FROM `comm_votes_variant` WHERE `id_votes` = '$votes[id]' ORDER BY num ASC");
	if(mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_votes_user` WHERE `id_votes` = '$votes[id]' AND `id_user` = '$user[id]'"), 0)==0 && isset($user) && $theme['id_user']!=$user['id']){
		echo'<div class="nav1">';
		if(isset($_GET['act']) && $_GET['act']=='golos' && isset($_POST['variant']) && isset($_POST['votessave'])){
			$idvariant = intval($_POST['variant']);
			mysql_query("INSERT INTO `comm_votes_user` (`id_user`, `id_variant`, `id_votes`) values('$user[id]', '$idvariant', '$votes[id]')");
			$_SESSION['message'] = 'Вы успешно проголосовали!';
			header("Location: ?");
			exit;
		}
		echo "<form method=\"post\" name='golos' action=\"?act=golos\">";
	while ($post = mysql_fetch_assoc($opros))
	{	
		$i = intval($post['num']);
		$id = intval($post['id']);
		echo "<input name='variant'".($i==1?" checked='checked'":null)."  type='radio' value='$id' /> "; echo output_text($post['otvet']);
		echo '<br />';
	}
	echo "<input type='submit' name='votessave' value='Голосовать' />\n";
	echo "</form>\n";
	echo'</div>';
	}else{
		while ($post = mysql_fetch_assoc($opros))
		{	
			if ($num == 0)	
			{			
				echo '<div class="nav1">';		
				$num = 1;	
			}	
			elseif ($num == 1)	
			{		
				echo '<div class="nav2">';		
				$num = 0;	
			}	
			$i = intval($post['num']);
			$id = intval($post['id']);
			$allcount = mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_votes_user` WHERE `id_votes` = '$votes[id]'"), 0);
			$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_votes_user` WHERE `id_votes` = '$votes[id]' AND `id_variant` = '$id'"), 0);
			if($count != 0){
				$ret = round(($count/$allcount)*100, 2);
			}else{
				$ret = 0;
			}
			echo output_text($post['otvet']); echo' ('.$count.')';
			echo'<br/><div style="display: inline-block; height: 10px; width: 140px; border: 1px solid DodgerBlue; position: relative; background-color: White;">
	 <div style="height: 10px; width: 329%; background: LightGray; position: absolute; max-width: 100%;"></div>
	 <div style="height: 10px; width: '.$ret.'%; background: #32CD32; position: absolute;  max-width: 100%;"></div>
	 <span style="position: absolute; text-align: center; width: 100%; display: block; font-size: 9px;">'.$ret.'%</span>
	</div>';
			echo '</div>';
		}
	}
}


//------------------------------//
echo "<div class='main'>Автор: ";

echo " ".group($ank2['id'])."";echo user::nick($ank2['id'],1,1,1);

/*------------Вывод статуса-------------*/

$status=mysql_fetch_assoc(mysql_query("SELECT * FROM `status` WHERE `pokaz` = '1' AND `id_user` = '$ank2[id]' LIMIT 1"));

if ($status['msg'] && $set['st']==1)

{

echo "<div class='st_1'></div>";

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

echo "".output_text($status['msg'])."";

echo "</div>\n";

}

/*---------------------------------------*/

echo "</div>\n";





/*

======================================

Кнопки действия с темой

======================================

*/

if (isset($user) && user_access('comm_edit') || isset($user) && $ank2['id']==$user['id'] || isset($user) && $moder!=0){

echo "<div class=\"foot\">\n";



if (user_access('comm_edit') || $ank2['id']==$user['id'] || isset($user) && $moder!=0){

echo "<a href='?act=mesto'><img src='/style/forum/inc/perem.png' alt='*'></a> | \n";

echo "<a href='?act=set'><img src='/style/forum/inc/izm.png' alt='*'></a>\n";

}

if (user_access('comm_edit') && $ank2['level']<=$user['level'] || $ank2['id']==$user['id'] || $moder!=0){

echo " | <a href='?act=del'><img src='/style/forum/inc/udl.png' alt='*'></a>\n";

}

echo "</div>\n";

}



if(!isset($page))$page=0;





echo "<div class='foot'>Комментарии:</div>";





/*------------сортировка по времени--------------*/

if (isset($user)) 

{

echo "<div id='comments' class='menus'>";

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

echo "<a href='?page=$page&amp;sort=1' class='".($user['sort']==1?'activ':'')."'>Внизу</a>";

echo "</div>"; 

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

echo "<a href='/?page=$page&amp;sort=0' class='".($user['sort']==0?'activ':'')."'>Вверху</a>";

echo "</div>"; 

echo "</div>";

}
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum_post` WHERE `id_them` = '$theme[id]' AND `id_razdel` = '$razdel[id]'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
//-------------------------коментарии---------------------//
$lim=" LIMIT $start, $set[p_str]";

$q=mysql_query("SELECT * FROM `comm_forum_post` WHERE `id_them` = '$theme[id]' AND `id_razdel` = '$razdel[id]' ORDER BY `time` $sort$lim");

if (mysql_num_rows($q)==0) {

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

echo "Нет сообщений в теме\n";

echo "</div>";

}



while ($post = mysql_fetch_assoc($q))

{



$ank=get_user($post['id_user']);





/*-----------зебра-----------*/ 

if ($num==0){

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

	$num=1;

}

elseif ($num==1){

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

	$num=0;}

/*---------------------------*/



echo ''.group($ank['id']).''; echo user::nick($ank['id'],1,1,1);



	if ($theme['close']==0) // если тема закрыта, то скрываем кнопку

	{

		if (isset($user) &&  $user['id']!=$ank['id'] && $ank['id']!=0) // Кроме автора поста и системы

		{

			echo '<a href="?response='.$ank['id'].'&amp;page='.$page.'" title="Ответить '.$ank['nick'].'">[*]</a> ';

		}

	}

	

echo ' ('.vremja($post['time']).')<br />';





$postBan = mysql_result(mysql_query("SELECT COUNT(*) FROM `ban` WHERE (`razdel` = 'all' OR `razdel` = 'forum') AND `post` = '1' AND `id_user` = '$ank[id]' AND (`time` > '$time' OR `navsegda` = '1')"), 0);

if ($postBan == 0) // Блок сообщения

{	

	if ($theme['id_user'] == $post['id_user']) // Отмечаем автора темы

		echo '<font color="green">Автор темы</font><br />';	



/*------------Вывод статуса-------------*/

$status=mysql_fetch_assoc(mysql_query("SELECT * FROM `status` WHERE `pokaz` = '1' AND `id_user` = '$ank[id]' LIMIT 1"));

if ($status['id'] && $set['st']==1)

{

echo "<div class='st_1'></div>";

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

echo "".output_text($status['msg'])."";

echo "</div>\n";

}

/*---------------------------------------*/



	# Цитирование поста

	if ($post['cit']!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum_post` WHERE `id` = '$post[cit]'"),0)==1)

	{

		$cit=mysql_fetch_assoc(mysql_query("SELECT * FROM `comm_forum_post` WHERE `id` = '$post[cit]' LIMIT 1"));

		$ank_c=get_user($cit['id_user']);

		echo '<div class="cit">

		  <b>'.$ank_c['nick'].' ('.vremja($cit['time']).'):</b><br />

		  '.output_text($cit['msg']).'<br />

		  </div>';

	}

	





		



	echo output_text($post['msg']).'<br />'; // Посты темы








}else{

	echo output_text($banMess).'<br />';

}



if (isset($user))

{

echo '<div style="text-align:right;">';



	if ($theme['close']==0) // если тема закрыта, то скрываем кнопки

	{

		if ($user['id']!=$ank['id'] && $ank['id']!=0) // Кроме автора поста и системы 

		{

			echo '<a href="/mail.php?id='.$ank['id'].'" title="Личное сообщение '.$ank['nick'].'"  class="link_s"><img src="/style/icons/messagebox.png" alt="*"></a> ';

		}

	

	}

	

	if (user_access('comm_edit') && ($ank['level']<=$user['level'] || $ank['level']==$user['level'] && $ank['id']==$user['id'])) // Редактирование поста

		echo "<a href=\"?edit=$post[id]\" title='Изменить пост $ank[nick]'  class='link_s'><img src='/style/icons/edit.gif' alt='*'> </a> \n";

	elseif ($user['id']==$post['id_user'] && $post['time']>time()-600) // Редактирование поста если не прошло 10 минут

		echo "<a href=\"?edit=$post[id]\" title='Изменить мой пост'  class='link_s'><img src='/style/icons/edit.gif' alt='*'> (".($post['time']+600-time())." сек)</a> \n";




		

		if (user_access('comm_edit') || isset($user) && $moder!=0 || isset($user) && $user['id']==$post['id_user'] || isset($user) && $user['id']==$theme['id_user']) // удаление поста

		{

			echo "<a href=\"?del=$post[id]&amp;page=$page\" title='Удалить'  class='link_s'><img src='/style/icons/delete.gif' alt='*' title='Удалить'></a>\n";

		}

	

echo '</div>';

}



echo ' </div>';

}








if ($k_page>1)str("?",$k_page,$page); // Вывод страниц




//========================================================//







if(isset($user)  && ($theme['close']==0  || $theme['close']==1 && user_access('comm_edit') || $theme['close']==1 && $moder!=0)){
echo "<form method='post' name='message' action='?new&page=$page&amp;$passgen&amp;".$go_otv."'>\n";
if ($set['web'] && is_file(H.'style/themes/'.$set['set_them'].'/altername_post_form.php'))

include_once H.'style/themes/'.$set['set_them'].'/altername_post_form.php';

else

echo "$tPanel<textarea name=\"msg\">$otvet</textarea><br />\n";



echo '<input name="post" value="Отправить" type="submit" /><br />

	 </form>';

}
echo "<div class='foot'><img src='/style/icons/str2.gif' alt=''/> <a href='/comm/$comm[id]/'>".text($comm['name'])."</a> | <a href='/comm/forum/$comm[id]/'>Форум</a> | <a href='/comm/forumcat/$razdel[id]/'>".text($razdel['name'])."</a></div>";
include_once '../sys/inc/tfoot.php';
?>