<?php
include $_SERVER['DOCUMENT_ROOT']."/anti_ hacker.php"; 
if(isset($_POST['msg']) && isset($user) && (mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' AND `invit`='0' AND `activate`='0' LIMIT 1"),0)==1 || $user['id']==$soo['admid'])){
	$msg=$_POST['msg'];

if(isset($_POST['translit']) && $_POST['translit']==1){
	$msg=translit($msg);
	}

if(strlen2($msg)>1024){
	$err='Сообщение слишком длинное';
	}else if(strlen2($msg)<2){
		$err='Короткое сообщение';
		}else if(mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_obmen_komm` WHERE `id_file` = '$file_id[id]' AND `id_user` = '$user[id]' AND `msg` = '".my_esc($msg)."' AND `id_soo` = '$soo[id]' LIMIT 1"),0)!=0){
			$err='Ваше сообщение повторяет предыдущее';
			}else{
				$msg=mysql_escape_string($msg);
				mysql_query("INSERT INTO `soo_obmen_komm` (`id_soo`, `id_file`, `id_user`, `time`, `msg`) values('$soo[id]', '$file_id[id]', '$user[id]', '$time', '$msg')");
				mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
				msg('Сообщение успешно добавлено');
				}
				}



err();
aut();


$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_obmen_komm` WHERE `id_file` = '$file_id[id]' AND `id_soo` = '$soo[id]'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];

echo '<table class="post">';

if($k_post==0){
	echo '<tr><td class="p_t">Нет комментариев</td></tr>';
	}

$q=mysql_query("SELECT * FROM `soo_obmen_komm` WHERE `id_file` = '$file_id[id]' AND `id_soo` = '$soo[id]' ORDER BY `id` DESC LIMIT $start, $set[p_str]");
while ($post = mysql_fetch_array($q)){
$ank=get_user($post['id_user']);

echo '<tr><td class="icon14">';
echo '<img src="/style/themes/'.$set['set_them'].'/user/'.$ank['pol'].'.png" alt="" />';
echo '</td><td class="p_t">';

echo ' <a href="/info.php?id='.$ank['id'].'"><span style="color:'.$ank['ncolor'].'">'.$ank['nick'].'</span></a> '.online($ank['id']).' ('.vremja($post['time']).')';
echo'</td>';
echo'</tr>';
echo '<tr>';
echo '<td class="p_m" colspan="2">';
echo output_text($post['msg']).'';

if(isset($user) && ($soo['admid']==$user['id'] || $user['id']==$file_id['id_user'])){
	echo '<br/><a href="?s='.$soo['id'].'&amp;komm&amp;page='.$page.'&amp;del_post='.$post['id'].'&amp;d='.$dir_id['dir'].'&amp;f='.urlencode($file_id['name']).'.'.$file_id['ras'].'">Удалить</a>';
	}

echo'</td>';
echo'</tr>';
}

echo '</table>';

if($k_page>1){
	str('?s='.$soo['id'].'&amp;d='.$dir_id['dir'].'&amp;f='.urlencode($file_id['name']).'.'.$file_id['ras'].'&amp;komm&amp;',$k_page,$page);
	}

if(isset($user) && (mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' AND `invit`='0' AND `activate`='0' LIMIT 1"),0)==1 || $user['id']==$soo['admid'])){
	echo '<form method="post" name="message" action="?s='.$soo['id'].'&amp;d='.$dir_id['dir'].'&amp;f='.urlencode($file_id['name']).'.'.$file_id['ras'].'&amp;komm">';
    echo 'Сообщение:<br/><textarea name="msg"></textarea><br/>';

if($user['set_translit']==1){
	echo '<label><input type="checkbox" name="translit" value="1"/> Транслит</label><br/>';
	}

echo '<input value="Отправить" type="submit"/></form>';
}
?>