<?
# Автор движка: InstalScript
# vk.com/k.karamin  - Я Вк
# bymas.ru/id3741  - Я на бумасе
# Специально для обитателей bymas.ru
# Ток на бумасе можно найти моды для данного движка
$rulBB = '10'; // Права с которых можно использовать BB коды
$rulModer = '5'; // Права модера,


require_once($_SERVER['DOCUMENT_ROOT']."/instalscript/game/inc/function.php");

head("Форум",$uid);
/*
echo "
<div class='trnt-block mb6'>
<div class='wrap1'><div class='wrap2'><div class='wrap3'><div class='wrap4'><div class='wrap5'><div class='wrap6'><div class='wrap7'><div class='wrap8'>
<div class='wrap-content'>
<div class='white small bold sh_b mb5'>";
# */

switch($is['1']){
default:
echo "<div class = 'medium white bold cntr mt5 mb10'>Форум</div>";
echo logs();logn();


$count = mysql_result(mysql_query("SELECT COUNT(*) FROM  `forum_top` "),0);

if($count == '0'){
echo "Форум пуст";
}else{

$str = '10'; # кол-во записей для вывода
$url = "/forum"; # ссылка
$num = abs($is['1']); # текущая страница
$result = $count; # подсчёт

$forum_q = mysql_query("SELECT * FROM `forum_top` ORDER BY `id` ASC LIMIT ".page($num,$str,$result).",$str ");

$i = '1';
while($forum = mysql_fetch_assoc($forum_q)){
$i = abs($i)%100;$i2 = $i%2;
echo "
<div w:id = 'forum' ";
if($i2 == '0'){echo "class = 'odd'";}
echo ">
<a class = 'blck p5 forum' w:id = 'forumLink' href = '/forum/top/".$forum['id']."/'>
<span class = 'medium bold yellow1'><img src = '/instalscript/images/other/forum/icons/forum.png' width = '16' height = '16' alt = ''>".$forum['name']."</span><br>
<span class = 'small white'>".$forum['info']."</span>
</a>
</div>
";


$i++;
# echo "<a class='simple-but border mb1' href = '/newstore/top/".$forum['id']."/'><span><span style = 'text-align: left;'>".$forum['name']."</span></span></a>";
}
ppage($url,$num,$str,$result);
}


if($user['rules'] == '10'){echo "<div class = 'bot'><a class = 'simple-but gray mb5' href = '/forum/new/top/'><span><span>Создать топик</span></span></a></div>";}


break;
case'new':
if($is['1'] == 'new'){


if($is['2'] == 'top'){
if($user['rules'] < '10'){logi("Запрещено!");header("Location:/forum/");exit();}
else{

if($is['3'] == 'form-check'){
$name = check($_POST['postName']);
$info = check($_POST['postInfo']);
$rules = abs($_POST['postRules']);
$strlen = abs($_POST['postStrlen']);
if(empty($name)){logi("Введите название топика");header("Location:/forum/new/top/");exit();}
elseif(empty($info)){$_SESSION['forum_top_name'] = $name;logi("Введите описание");header("Location:/forum/new/top/");exit();}
$_SESSION['forum_top_name'] = null;
logi("Топик &quot;".$name."&quot; создан");
if($rules > '10'){$rules = '10';}
if($strlen > '3000'){$strlen = '3000';}

mysql_query("INSERT INTO `forum_top` SET `uid` = '".$uid."',`time` = '".(time())."',`rules` = '".$rules."',`strlen` = '".$strlen."',`name` = '".$name."',`info` = '".$info."'  ");
header("Location:/forum/");
exit();
}
# mb_strlen

echo "<div class = 'medium white bold cntr mt5 mb10'>Создание нового топа</div>";

echo logs();logn();

echo "
<form w:id = 'postForm' id = 'id1' method = 'post' action = '/forum/new/top/form-check/'>
<div style = 'width:0px;height:0px;position:absolute;left:-100px;top:-100px;overflow:hidden'>
<input type = 'hidden' name = 'id1_hf_0' id = 'id1_hf_0'></div>
<table class = 'chat-msg-panel mt10 mb6'>
<tbody>

<tr>
<td>
Название
<div class = 'trnt-block mb0'>
<div class = 'wrap1'><div class = 'wrap2'><div class = 'wrap3'><div class = 'wrap4'><div class = 'wrap5'><div class = 'wrap6'><div class = 'wrap7'><div class = 'wrap8'>
<div class = 'p5'>
<input w:id = 'postText' class = 'chat-msg bold sh_b small lh1 cyan1' value = '".$_SESSION['forum_top_name']."' type = 'text' size = '20' maxlength = '250' name = 'postName' >
</div>
</div></div></div></div></div><div></div></div></div></div>
</td>
</tr>


<tr>
<td class = 'msg'>
Описание
<div class = 'trnt-block mb0'>
<div class = 'wrap1'><div class = 'wrap2'><div class = 'wrap3'><div class = 'wrap4'><div class = 'wrap5'><div class = 'wrap6'><div class = 'wrap7'><div class = 'wrap8'>
<div class = 'p5'>
<textarea class = 'msg-textarea' name = 'postInfo'></textarea>
</div>
</div></div></div></div></div><div></div></div></div></div>
</div>
</td>
</tr>
<tr>
<td>
Права для создания темы в топе (10 - главный админ, 0 - Все)
<div class = 'trnt-block mb0'>
<div class = 'wrap1'><div class = 'wrap2'><div class = 'wrap3'><div class = 'wrap4'><div class = 'wrap5'><div class = 'wrap6'><div class = 'wrap7'><div class = 'wrap8'>
<div class = 'p5'>
<input w:id = 'postText' class = 'chat-msg bold sh_b small lh1 cyan1' value = '0' type = 'text' size = '20' maxlength = '250' name = 'postRules' >
</div>
</div></div></div></div></div><div></div></div></div></div>
</td>
</tr>

<tr>
<td>
Максимальная длина в сообщениях (в теме топа)
<div class = 'trnt-block mb0'>
<div class = 'wrap1'><div class = 'wrap2'><div class = 'wrap3'><div class = 'wrap4'><div class = 'wrap5'><div class = 'wrap6'><div class = 'wrap7'><div class = 'wrap8'>
<div class = 'p5'>
<input w:id = 'postText' class = 'chat-msg bold sh_b small lh1 cyan1' value = '250' type = 'text' size = '20' maxlength = '250' name = 'postStrlen' >
</div>
</div></div></div></div></div><div></div></div></div></div>
</td>
</tr>

</tbody></table>
<div class = 'bot'><span class = 'input-but border'><span><input class = 'w100' type = 'submit' value = 'Создать'></span></span></div>

</form>
";

}





}
elseif($is['2'] == 'theme'){
$top = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_top` WHERE `id` = '".abs($is['3'])."' "));
if($top == null){logi("Не найден топ для создания темы");header("Location:/forum/1/");exit();}
if($user['rules'] < $top['rules']){logi("Запрещено!");header("Location:/forum/1/");exit();}




if($is['4'] == 'form-check'){
$name = check($_POST['postName']);
$info = check($_POST['postInfo']);
$old_theme = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_theme` WHERE `uid` = '".$uid."' AND `time`  >= '".(time()-900)."' "));

if(empty($name)){logi("Введите название темы");header("Location:/forum/new/theme/".$top['id']."/");exit();}
elseif($old_theme != null && $user['rules'] < '6'){logi("Создать тему можно лишь через 15 минут");header("Location:/forum/new/theme/".$top['id']."/");exit();}
elseif(mb_strlen($name) > '50'){logi("Название темы не может превышать 50 символов");header("Location:/forum/new/theme/".$top['id']."/");exit();}
elseif(mb_strlen($info) > $top['strlen'] && $user['rules'] < '6'){$_SESSION['forum_theme_name'] = $name;logi("Оописание не должно быть больше ".$top['strlen']." сим.");header("Location:/forum/new/theme/".$top['id']."/");exit();}
elseif(empty($info)){$_SESSION['forum_theme_name'] = $name;logi("Введите описание");header("Location:/forum/new/theme/".$top['id']."/");exit();}
$_SESSION['forum_theme_name'] = null;
logi("Тема ".$name." создана");
if($rulBB <= $user['rules']){$admin = '1';}else{$admin = '0';}

mysql_query("INSERT INTO `forum_theme` SET `uid` = '".$uid."',`top` = '".$top['id']."',`admin` = '".$admin."',`time` = '".(time())."',`name` = '".$name."',`text` = '".$info."'  ")or die(mysql_error());
header("Location:/forum/top/".$is['3']."/1/");
exit();
}






echo "<div class = 'medium white bold cntr mt5 mb10'>Создание новой темы</div>";

if($user['rules'] >= $rulBB){
vbbcode();
}
echo logs();logn();

echo "
<form w:id = 'postForm' id = 'id1' method = 'post' action = '/forum/new/theme/".abs($is['3'])."/form-check/'>
<div style = 'width:0px;height:0px;position:absolute;left:-100px;top:-100px;overflow:hidden'>
<input type = 'hidden' name = 'id1_hf_0' id = 'id1_hf_0'></div>
<table class = 'chat-msg-panel mt10 mb6'>
<tbody>

<tr>
<td>
Название
<div class = 'trnt-block mb0'>
<div class = 'wrap1'><div class = 'wrap2'><div class = 'wrap3'><div class = 'wrap4'><div class = 'wrap5'><div class = 'wrap6'><div class = 'wrap7'><div class = 'wrap8'>
<div class = 'p5'>
<input w:id = 'postText' class = 'chat-msg bold sh_b small lh1 cyan1' value = '".$_SESSION['forum_theme_name']."' type = 'text' size = '20' maxlength = '".$top['strlen']."' name = 'postName' >
</div>
</div></div></div></div></div><div></div></div></div></div>
</td>
</tr>


<tr>
<td class = 'msg'>
Описание
<div class = 'trnt-block mb0'>
<div class = 'wrap1'><div class = 'wrap2'><div class = 'wrap3'><div class = 'wrap4'><div class = 'wrap5'><div class = 'wrap6'><div class = 'wrap7'><div class = 'wrap8'>
<div class = 'p5'>
<textarea class = 'msg-textarea' name = 'postInfo'></textarea>
</div>
</div></div></div></div></div><div></div></div></div></div>
</div>
</td>

</tr>

</tbody></table>
<div class = 'bot'><span class = 'input-but border'><span><input class = 'w100' type = 'submit' value = 'Создать'></span></span></div>

</form>
";

}
}
break;
case'edit':
if($is['1'] == 'edit'){
if($is['2'] == 'theme'){
$theme = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_theme` WHERE `id` = '".abs($is['3'])."' "));
if($theme == null){logi("Тема для редоктирования не найдена");header("Location:/forum/1/");exit();}
if($theme['uid'] != $uid){logi("Тема для редоктирования не найдена");header("Location:/forum/1/");exit();}
$top = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_top` WHERE `id` = '".$theme['top']."' "));



if($is['4'] == 'form-check'){
$name = check($_POST['postName']);
$info = check($_POST['postInfo']);

if(empty($name)){logi("Введите название темы");header("Location:/forum/edit/theme/".$theme['id']."/");exit();}
if($user['rules'] < '6'){

if(mb_strlen($info) > $top['strlen']){
$_SESSION['forum_theme_name'] = $name;
logi("Описание не должно быть больше ".$top['strlen']." сим.");
header("Location:/forum/edit/theme/".$theme['id']."/");
exit();
}

}
if(empty($info)){$_SESSION['forum_theme_name'] = $name;logi("Введите описание");header("Location:/forum/edit/theme/".$theme['id']."/");exit();}
$_SESSION['forum_theme_name'] = null;
logi("Тема ".$name." изменена");
if($rulBB <= $user['rules']){$admin = '1';}else{$admin = '0';}

mysql_query("UPDATE `forum_theme` SET `admin` = '".$admin."',`name` = '".$name."',`text` = '".$info."' WHERE `id` = '".$theme['id']."'  ")or die(mysql_error());
header("Location:/forum/theme/".$theme['id']."/1/");
exit();
}






echo "<div class = 'medium white bold cntr mt5 mb10'>Редактирование темы &quot;".$theme['name']."&quot;</div>";

if($user['rules'] >= $rulBB){
vbbcode();
}

echo logs();logn();


echo "
<form method = 'post' action = '/forum/edit/theme/".$theme['id']."/form-check/'>
<div style = 'width:0px;height:0px;position:absolute;left:-100px;top:-100px;overflow:hidden'>
<input type = 'hidden' name = 'id1_hf_0' id = 'id1_hf_0'></div>
<table class = 'chat-msg-panel mt10 mb6'>
<tbody>

<tr>
<td>
Название
<div class = 'trnt-block mb0'>
<div class = 'wrap1'><div class = 'wrap2'><div class = 'wrap3'><div class = 'wrap4'><div class = 'wrap5'><div class = 'wrap6'><div class = 'wrap7'><div class = 'wrap8'>
<div class = 'p5'>
<input class = 'chat-msg bold sh_b small lh1 cyan1' value = '".$theme['name']."' type = 'text' size = '20' maxlength = '".$top['strlen']."' name = 'postName' >
</div>
</div></div></div></div></div><div></div></div></div></div>
</td>
</tr>


<tr>
<td class = 'msg'>
Описание
<div class = 'trnt-block mb0'>
<div class = 'wrap1'><div class = 'wrap2'><div class = 'wrap3'><div class = 'wrap4'><div class = 'wrap5'><div class = 'wrap6'><div class = 'wrap7'><div class = 'wrap8'>
<div class = 'p5'>
<textarea id = 'themeInfo' class = 'msg-textarea' name = 'postInfo'>".$theme['text']."</textarea>
</div>
</div></div></div></div></div><div></div></div></div></div>
</div>
</td>
</tr>";
echo "</tbody>";
echo "</table>";
echo "<div class = 'bot'><span class = 'input-but border'><span><input class = 'w100' type = 'submit' value = 'Изменить'></span></span></div>";
echo "</form>";


}
if($is['2'] == 'delete' or $is['2'] == 'close'){
$theme = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_theme` WHERE `id` = '".abs($is['4'])."' "));
if($theme == null){logi("Тема не найдена");header("Location:/forum/1/");exit();}
if($user['rules'] >= $rulModer && user($theme['uid'],'rules' <= $rulModer)){


if($is['2'] == 'delete'){
if($is['5'] == 'yes'){
logi("Тема ".$theme['name']." успешно удалена");
mysql_query("DELETE FROM `forum_theme` WHERE `id` = '".$theme['id']."' ");
mysql_query("DELETE FROM `forum_msg` WHERE `theme` = '".$theme['id']."' ");
header("Location:/forum/1/");
exit();
}

echo "<div class = 'medium white bold cntr mt5 mb10'>Удаление темы &quot;".$theme['name']."&quot;</div>";
echo "Вы действительно хотите удалить тему &quot;".$theme['name']."&quot;";
echo "<table>";
echo "<td><a class = 'simple-but gray mb5' href = '/forum/edit/delete/theme/".$theme['id']."/yes/'><span><span>Да</span></span></a></td>";
echo "<td><a class = 'simple-but gray mb5' href = '/forum/theme/".$theme['id']."/'><span><span>Нет</span></span></a></td>";
echo "</table>";
}
if($is['2'] == 'close'){
if($theme['type'] == '1'){$type = '0';$text_close = 'открыть тему';$log_close = 'открыта';$nLog = 'Открытие';}else{$type = '1';$text_close = 'Закрыть тему';$log_close = 'закрыта';$nLog = 'Закрытие';}


if($is['5'] == 'yes'){
logi("Тема ".$theme['name']." успешно ".$log_close."");
mysql_query("UPDATE `forum_theme` SET `type` = '".$type."' WHERE `id` = '".$theme['id']."' ");
header("Location:/forum/theme/".$theme['id']."/1/");
exit();
}

echo "<div class = 'medium white bold cntr mt5 mb10'>".$nLog." темы &quot;".$theme['name']."&quot;</div>";
echo "Вы действительно хотите ".$text_close." &quot;".$theme['name']."&quot;";
echo "<table>";
echo "<td><a class = 'simple-but gray mb5' href = '/forum/edit/close/theme/".$theme['id']."/yes/'><span><span>Да</span></span></a></td>";
echo "<td><a class = 'simple-but gray mb5' href = '/forum/theme/".$theme['id']."/'><span><span>Нет</span></span></a></td>";
echo "</table>";
}

}else{
logi("Запрещено");
header("Location:/forum/1/");exit();
}
}
}
break;
case'top':
if($is['1'] == 'top'){
$top =  mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_top` WHERE `id` = '".abs($is['2'])."' "));
if($top == null){logi("Нечего не найдено");header("Location:/forum/1/");exit();}

echo "<div class = 'medium white bold cntr mt5 mb10'>".$top['name']."</div>";

echo logs();logn();



$count = mysql_result(mysql_query("SELECT COUNT(*) FROM  `forum_theme` WHERE `top` = '".$top['id']."' "),0);

if($count == '0'){
echo "Тем нету!";
}else{

$str = '20'; # кол-во записей для вывода
$url = "/forum/top/".abs($is['2']).""; # ссылка
$num = abs($is['3']); # текущая страница
$result = $count; # подсчёт

$theme_q = mysql_query("SELECT * FROM `forum_theme` WHERE `top` = '".$top['id']."'  ORDER BY `time` DESC LIMIT ".page($num,$str,$result).",$str ");

$i = '1';
while($theme = mysql_fetch_assoc($theme_q)){
$i = abs($i)%100;$i2 = $i%2;
echo "
<div w:id = 'forum' ";
if($i2 == '0'){echo "class = 'odd'";}
echo ">
<a class = 'blck p5 forum' w:id = 'forumLink' href = '/forum/theme/".$theme['id']."/'>";
if($theme['type'] == '1'){$img_theme_icon = 'topic_close';}else{$img_theme_icon = 'topic_new';}
echo "<span class = 'medium bold yellow1'><img src = '/instalscript/images/other/forum/icons/".$img_theme_icon.".png' width = '16' height = '16' alt = ''>".$theme['name']."</span><br>
</a>
</div>
";


$i++;
# echo "<a class='simple-but border mb1' href = '/newstore/top/".$forum['id']."/'><span><span style = 'text-align: left;'>".$forum['name']."</span></span></a>";
}
ppage($url,$num,$str,$result);
}

echo "<a class = 'simple-but gray mb5' href = '/forum/'><span><span>Вернуться на форум</span></span></a>";
if($user['rules'] >= $top['rules']){
echo "<div class = 'bot'><a class = 'simple-but gray mb5' href = '/forum/new/theme/".abs($is['2'])."/'><span><span>Создать тему</span></span></a></div>";
}


}
break;
case'theme':
if($is['1'] == 'theme'){
$theme = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_theme` WHERE `id` = '".abs($is['2'])."' "));
if($theme == null){logi("Нечего не найдено");header("Location:/forum/1/");exit();}
$top = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_top` WHERE `id` = '".$theme['top']."' "));
echo "<div class = 'medium white bold cntr mt5 mb10'>".$theme['name']."</div>";
echo logs();logn();
echo "
<div class = 'mb5'>
<img src = '/instalscript/images/other/forum/icons/forum.png' width = '16' height = '16' alt = ''>
<a class = 'white' href = '/forum/1/'>Форум</a> /
<a class = 'white' href = '/forum/top/".$top['id']."/'>".$top['name']."</a>
</div>
";

echo "
<a class = 'yellow1 sndr blck' w:id = 'authorLink' href = '/profile/".$theme['uid']."/'>".user($theme['uid'],'1')
."<span class = 'small fr pt2 green1' w:id = 'time'>".clock($theme['time'])."</span></a>
";
echo "<div class = 'medium ovh m5 white admin' w:id = 'message'>";
echo "<p></p>";
echo "<div class = 'cntr'>";
echo bbcode($theme['text'],$theme['admin']);
echo "</div>";
echo "</div>";

$count_commen = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_msg` WHERE `theme` = '".$theme['id']."' "),0);
echo "<div class = 'small gray1 m5'>Комментариев: ".$count_commen."</div>";

if($theme['type'] == '1' && $user['rules'] < $rulModer){
echo "
<div class = 'pb5'>
<div class = 'small bold sh_b cntr green2 mt5' w:id = 'topicClosed'>топик закрыт</div>
</div>
";
}
else{
if($theme['type'] == '1'){
echo "
<div class = 'pb5'>
<div class = 'small bold sh_b cntr green2 mt5' w:id = 'topicClosed'>топик закрыт</div>
</div>
";
}


if($is['3'] == 'form-check'){


$text = check($_POST['postText']);

$repeat_msg = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_msg` WHERE `uid` = '".$uid."'AND `theme` = '".$theme['id']."' AND`text` = '".$text."' AND `time` > '".(time()-300)."' ")); # or die(mysql_error());
if(empty($text)){logi("Пустое сообщение");header("Location:/forum/theme/".$is['2']."/1/");exit();}
if(mb_strlen($text) > '500'){logi("Сообщение не должно быть больше 500 сим.");header("Location:/forum/theme/".$is['2']."/1/");exit();}
if($text == $repeat_msg['text']){logi("Сообщение повторяет предыдущие");header("Location:/forum/theme/".$is['2']."/1/");exit();}

if($is['4'] == 'cit'){
$msg_cit = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_msg` WHERE `id` = '".abs($is['5'])."' AND `theme` = '".$theme['id']."' "));
if($msg_cit['uid'] == $uid){logi("Цитировать себя запрещено");header("Location:/forum/theme/".$theme['id']."/1/");exit();}
if($msg_cit == null){logi("Сообщение для цитирования не найдено");header("Location:/forum/theme/".$theme['id']."/1/");exit();}
mysql_query("INSERT INTO `forum_msg` SET `uid` = '".$uid."',`theme` = '".$theme['id']."',`time` = '".(time())."',`type` = '1',`did` = '".$msg_cit['id']."',`text` = '".$text."' ")or die(mysql_error());
}
elseif($is['4'] == 'otv'){
$msg_otv = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_msg` WHERE `id` = '".abs($is['5'])."' AND `theme` = '".$theme['id']."' "));
if($msg_otv['uid'] == $uid){logi("Отвечать себе запрещено");header("Location:/forum/theme/".$theme['id']."/1/");exit();}
if($msg_otv == null){logi("Сообщение для ответа не найдено");header("Location:/forum/theme/".$theme['id']."/1/");exit();}
mysql_query("INSERT INTO `forum_msg` SET `uid` = '".$uid."',`theme` = '".$theme['id']."',`time` = '".(time())."',`type` = '2',`did` = '".$msg_otv['id']."',`text` = '".$text."' ")or die(mysql_error());
}
else{
mysql_query("INSERT INTO `forum_msg` SET `uid` = '".$uid."',`theme` = '".$theme['id']."',`time` = '".(time())."',`type` = '0',`text` = '".$text."' ")or die(mysql_error());
}


header("Location:/forum/".$theme['id']."/1/");
}


if($is['4'] == 'cit'){
$msg_cit = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_msg` WHERE `id` = '".abs($is['5'])."' "));
if($msg_cit['uid'] == $uid){logi("Цитировать себя запрещено");header("Location:/forum/theme/".$is['2']."/1/");exit();}
if($msg_cit == null){logi("Сообщение для цитирования не найдено");header("Location:/forum/theme/".$is['2']."/1/");exit();}
echo "<div class = 'white cntr bold m5'>Цитировать сообщение танкиста ".user($msg_cit['uid'],'1')."</div>";
echo "
<div class = 'trnt-block mb2'>
<div class = 'wrap1'><div class = 'wrap2'><div class = 'wrap3'><div class = 'wrap4'><div class = 'wrap5'><div class = 'wrap6'><div class = 'wrap7'><div class = 'wrap8'>
<div class = 'wrap-content-mini'><div class = 'mt5 mb5 small green1 cntr'>".$msg_cit['text']."</div></div>
</div></div></div></div></div></div></div></div>
</div>
";
echo "<a class = 'simple-but gray mb5' href = '/forum/theme/".$theme['id']."/cit/".$is['5']."/'><span><span>Отменить</span></span></a>";
echo "<form w:id = 'postForm' id = 'id1' method = 'post' action = '/forum/theme/".$theme['id']."/form-check/cit/".$msg_cit['id']."'>";
}
elseif($is['4'] == 'otv'){
$msg_otv = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_msg` WHERE `id` = '".abs($is['5'])."' "));
if($msg_otv['uid'] == $uid){logi("Отвечать себе запрещено");header("Location:/forum/theme/".$is['2']."/1/");exit();}
if($msg_otv == null){logi("Сообщение для ответа не найдено");header("Location:/forum/theme/".$is['2']."/1/");exit();}
echo "<div class = 'white cntr bold m5'>Ответить на сообщение танкиста ".user($uid,'1')."</div>";
echo "
<div class = 'trnt-block mb2'>
<div class = 'wrap1'><div class = 'wrap2'><div class = 'wrap3'><div class = 'wrap4'><div class = 'wrap5'><div class = 'wrap6'><div class = 'wrap7'><div class = 'wrap8'>
<div class = 'wrap-content-mini'><div class = 'mt5 mb5 small green1 cntr'>".$msg_otv['text']."</div></div>
</div></div></div></div></div></div></div></div>
</div>
";
echo "<a class = 'simple-but gray mb5' href = '/forum/".abs($is['1'])."/'><span><span>Отменить</span></span></a>";
echo "<form w:id = 'postForm' id = 'id1' method = 'post' action = '/forum/theme/".$theme['id']."/form-check/otv/".$msg_otv['id']."'>";

}
else{
echo "<form w:id = 'postForm' id = 'id1' method = 'post' action = '/forum/theme/".$theme['id']."/form-check/'>";
}

echo "
<div style = 'width:0px;height:0px;position:absolute;left:-100px;top:-100px;overflow:hidden'>
<input type = 'hidden' name = 'id1_hf_0' id = 'id1_hf_0'></div>
<table class = 'forum-msg-panel mt10 mb6'>
<tbody><tr>
<td class = 'msg' colspan = '2'>
<div class = 'trnt-block mb0'>
<div class = 'wrap1'><div class = 'wrap2'><div class = 'wrap3'><div class = 'wrap4'><div class = 'wrap5'><div class = 'wrap6'><div class = 'wrap7'><div class = 'wrap8'>
<div class = 'p5'>
<textarea class = 'msg-textarea' name = 'postText'></textarea>
</div>
</div></div></div></div></div><div></div></div></div></div>
</div>
</td>";
echo "</tr>";
echo "<td><span class = 'input-but border'><span><input class = 'w100' type = 'submit' value = 'Отпрвить'></span></span></td>";
echo "<td class = 'w50 pr1'><a class = 'simple-but border' href = '/forum/theme/".$theme['id']."/".$is['3']."/'><span><span>Обновить</span></span></a></td>";
echo "</tbody></table>";
echo "</form>";
}


$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_msg` WHERE `theme` = '".$theme['id']."' "),0);
$str = '20'; # кол-во записей для вывода
$url = "/forum/theme/".$is['2'].""; # ссылка
$num = abs($is['3']); # текущая страница
$result = $count; # подсчёт
$msg_q = mysql_query("SELECT * FROM `forum_msg` WHERE `theme` = '".$theme['id']."' ORDER BY `time` DESC LIMIT ".page($num,$str,$result).",$str ");
while($msg = mysql_fetch_assoc($msg_q)){

if($msg['type'] == '1'){
$msg_ct = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_msg` WHERE `id` = '".$msg['did']."' "));
echo "<a class = 'yellow1 sndr blck' w:id = 'authorLink' href = '/profile/".$msg['uid']."/'>".user($msg['uid'],'1')."<span class = 'small fr pt2 green1' w:id = 'time'>".clock($msg['time'])."</span></a>";
echo " <span w:id = 'text' class = 'white sh_b bold small'>".$msg['text']."</span>";
echo " <span class = 'white'>[цит]</span> ";
echo " <span w:id = 'text' class = 'white sh_b bold small'>".$msg_ct['text']."</span>";
if($theme['type'] != '1'){
if($msg['uid'] != $uid){
echo " <a title = 'Цитировать' w:id = 'replyLink' class = 'gray1' href = '/forum/theme/".$theme['id']."/".$num."/cit/".$msg['id']."/'>[цит]</a>";
echo "<a title = 'Ответить' w:id = 'replyLink' class = 'gray1' href = '/forum/theme/".$theme['id']."/".$num."/otv/".$msg['id']."/'>[отв]</a>";
echo "<a title = 'Личное сообщение' w:id = 'replyLink' class = 'gray1' href = '/profile/new-pm/".$msg['uid']."/'>[лс]</a>";
}
}
echo "<a w:id = 'profileLink' class = 'yellow1 td_u' href = '/profile/".$msg_ct['uid']."/'>".user($msg_ct['uid'],'1')." </a>";

}
elseif($msg['type'] == '2'){
$msg_otv = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_msg` WHERE `id` = '".$msg['did']."' "));
echo "<a class = 'yellow1 sndr blck' w:id = 'authorLink' href = '/profile/".$msg['uid']."/'>".user($msg['uid'],'1')."<span class = 'small fr pt2 green1' w:id = 'time'>".clock($msg['time'])."</span></a>";

echo " <span w:id = 'text' class = 'white sh_b bold small'>".$msg['text']."</span>";
echo " <span class = 'white'>[отв]</span> ";
# echo " <span w:id = 'text' class = 'white sh_b bold small'>".user($msg_otv['uid'],'1')."</span>";
if($theme['type'] != '1'){
if($msg['uid'] != $uid){
echo " <a title = 'Цитировать' w:id = 'replyLink' class = 'gray1' href = '/forum/theme/".$theme['id']."/".$num."/cit/".$msg['id']."/'>[цит]</a>";
echo "<a title = 'Ответить' w:id = 'replyLink' class = 'gray1' href = '/forum/theme/".$theme['id']."/".$num."/otv/".$msg['id']."/'>[отв]</a>";
echo "<a title = 'Личное сообщение' w:id = 'replyLink' class = 'gray1' href = '/profile/new-pm/".$msg['uid']."/'>[лс]</a>";
}
}
echo "<a w:id = 'profileLink' class = 'yellow1 td_u' href = '/profile/".$msg_otv['uid']."/'>".user($msg_otv['uid'],'1')." </a>";

}
elseif($uid == $msg['uid']){
echo "<a class = 'yellow1 sndr blck' w:id = 'authorLink' href = '/profile/".$msg['uid']."/'>".user($msg['uid'],'1')."<span class = 'small fr pt2 green1' w:id = 'time'>".clock($msg['time'])."</span></a>";
echo " <span w:id = 'text' class = 'white sh_b bold small'>".$msg['text']."</span>";
}
else{
echo "<a class = 'yellow1 sndr blck' w:id = 'authorLink' href = '/profile/".$msg['uid']."/'>".user($msg['uid'],'1')."<span class = 'small fr pt2 green1' w:id = 'time'>".clock($msg['time'])."</span></a>";
echo " <span w:id = 'text' class = 'white sh_b bold small'>".$msg['text']."</span>";
if($theme['type'] != '1'){
echo " <a title = 'Цитировать' w:id = 'replyLink' class = 'gray1' href = '/forum/theme/".$theme['id']."/".$num."/cit/".$msg['id']."/'>[цит]</a>";
echo "<a title = 'Ответить' w:id = 'replyLink' class = 'gray1' href = '/forum/theme/".$theme['id']."/".$num."/otv/".$msg['id']."/'>[отв]</a>";
echo "<a title = 'Личное сообщение' w:id = 'replyLink' class = 'gray1' href = '/profile/new-pm/".$msg['uid']."/'>[лс]</a>";
}
}

echo "</br>";
}

ppage($url,$num,$str,$result);










if($uid == $theme['uid']){echo "<div class = 'bot'><a class = 'simple-but gray mb5' href = '/forum/edit/theme/".$theme['id']."/'><span><span>Изменить тему</span></span></a></div>";}
if($user['rules'] >= $rulModer && user($theme['uid'],'rules') >= $rulModer){
echo "<table>";
echo "<td><a class = 'simple-but gray mb5' href = '/forum/edit/delete/theme/".$theme['id']."/'><span><span>Улалить тему</span></span></a></td>";
if($theme['type'] == '1'){$text_close = 'Открыть тему';}else{$text_close = 'Закрыть тему';}
echo "<td><a class = 'simple-but gray mb5' href = '/forum/edit/close/theme/".$theme['id']."/'><span><span>".$text_close."</span></span></a></td>";
echo "</table>";
}
echo "<div class = 'bot'><a class = 'simple-but gray mb5' href = '/forum/'><span><span>Вернуться на форум</span></span></a></div>";

}
break;

}
/*
echo "
</div>
</div></div></div></div></div></div></div></div>
</div>
</div>";
# */

foot($uid);
?>