<?
if(time()<$row['kik']){
$re = mysql_query("SELECT name FROM rooms where rm = '9'");
$inam = mysql_fetch_array ($re);
$nam = $inam['name'];
$tyu='center';
$title='Стоп!';
head();
echo $fs1;
$tleft = $row['kik'] - time();
$tleft=ceil($tleft/ 60 / 60 / 24);
$whokik = $row['whokik'];
$whykik = $row['whykik'];
echo $div1.'<b>Ошибка!</b>'.$div9;
echo '<br />Вам запрещенно писать <b>'.$tleft.' дней</b><br/>';
echo 'Причина: <b>'.$whykik.'</b><br/><br />';
echo $div1.'<a href="'.H2.'enter.php">На главную</a>'.$div9;
foot();
exit;
}

require_once'home.php';

$q1 = @mysql_query( @"select  *  from  `forum_topic` where `id`='".$id."' ;" );
$topic = @mysql_fetch_array(@$q1);
if (mysql_affected_rows() == 0){
echo $fs1;
echo '<b>Такой темы не существует!</b>';
echo $fs2;
foot();
exit;
}
$f = $topic ['section'];
$sf = $topic ['subfor'];

$que = @mysql_query( "select * from  `forum_subfor` where id='$sf';" );
$dtm = @mysql_fetch_array( @$que );
$s_name = $dtm['name'];

$que = @mysql_query( "select * from  `forum_sections` where id='$f';" );
$dtm = @mysql_fetch_array( @$que );
$f_name = $dtm['name'];

echo '<dl><dt></dt></dl><a href="'.F.'">Форумы</a>|<a href="'.F.'subfs/'.$f.'">'.$f_name.'</a>';
echo '|<a href="'.F.'temes/'.$sf.'\">'.$s_name.'</a>|<a href="'.F.'tema/'.$id.'/'.$page.'">'.$topic ['name'].'</a><br /><dl><dt></dt></dl>';

if (empty($act)){
echo $fs1;

if ($topic['close']==1)
{
echo '<div>Тема <b>'.$topic['name'].'</b> закрыта!</div>';
break;
}
$q2 = @mysql_query( @"select * from  `users` WHERE id = '$nk' ;" );
$sect2 = @mysql_fetch_array( @$q2 );

if (!empty($nk)) echo 'Сообщение для <b>'.$sect2['user'].'</b><br />';

if ($wap==2||$wap==3) echo '<form form method="post" enctype="multipart/form-data" action="?">';
echo 'Сообщение:<br/>';
echo'<textarea cols="'.$row['pole2'].'" rows="'.$row['pole1'].'" name="msg" ></textarea><br />';
if (!empty($nk)){echo '<input type="checkbox" name="privat" value="1"/> Приватно<br/>';
echo '<input type="checkbox" name="opprivat" value="1"/>Оповестить по привату<br/>';
}
if ($row['formf']==1&&$wap==2||$wap==3)echo '<b>'.H3.'Прикрепить файл (max '.round($limit_for/1024,1).' мб.):</b><br/>
<input name="file" type="file" size="20"/><br/>';


echo '<input type="hidden" name="act" value="act"/>';
echo '<input type="hidden" name="f" value="'.$f.'"/>';
echo '<input type="hidden" name="sf" value="'.$sf.'"/>';
echo '<input type="hidden" name="id" value="'.$id.'"/>';
echo '<input type="hidden" name="nk" value="'.$nk.'"/>';
echo '<input type="hidden" name="mod" value="addpost"/>';

echo "<br /><input type=\"submit\" class=\"ibutton\" value=\"Добавить\" class=\"cp\"><br /><br />";


if (!empty($nk)) echo "<b><a href=\"".H2.$nk."\">Анкета ".nik($sect2['user'])."</a></b><br /> ";
echo "<br /><img src=\"".H2."img/naz.gif\" alt=\"[N]\"/><a href=\"".F."tema/$id/$page\"><b>В тему</b></a><br />";
echo $fs2;

}else{


$q1 = @mysql_query( @"select  *  from  `forum_topic`  where `id`='".$id."' ;" );
$topic = @mysql_fetch_array( @$q1 );
if ( $topic['close'] == 1 )
{
echo "<div>Тема &#171;{$topic['name']}&#187; закрыта!</div>";

}
else
{
if (empty($msg))
{
header("Location: ?id=".$id."&mod=tema&err=1&page=end");

}
else
{
///// Добавление фообщения
$user = $row['id'];

$msg = check($_POST['msg']);
if ($row["translit"]==1) $msg = translit($msg);

$msg = iconv('utf-8', 'windows-1251', $msg);
if (($myid==10)||($myid==11))$msg=substr($msg, 0, 2000);
else $msg=substr($msg, 0, 1000);
$msg = iconv('windows-1251', 'utf-8', $msg);

$q2 = @mysql_query( @"select * from  `users` WHERE id = '$nk' ;" );
$sect2 = @mysql_fetch_array( @$q2 );
if (!empty($nk)){ $msg = "[b]".$sect2['user']."[/b], ".$msg."";
if (!empty($privat))$privat = $nk;

if ($opprivat==1){$data = date("d-M-Y [H:i]");
$kol = rand(0,99999999);
$time = time();

$message = "<b>".$row['user']."</b> ответил на ваше сообщение в теме ".F."tema/$id/end";
mysql_query("Insert into zapiski set klu4='".$kol."', who ='Сисиема', idwho ='1', message = '".$message."', towhom = '".$sect2['user']."', idtowhom = '".$nk."', time = '".$time."', readd = '0', topic = '', date='".$data."'");
}
}


if ($topic ['privat']==1){
$data = date("d-M-Y [H:i]");
$kol = rand(0,99999999);
$time = time();
$q02 = @mysql_query( @"select * from  `users` WHERE id = '".$topic ['login']."' ;" );
$sect02 = @mysql_fetch_array(@$q02);

$message = "<b>".$row['user']."</b> оставил сообщение в вашей теме ".F."tema/$id/end";
mysql_query("Insert into zapiski set klu4='".$kol."', who ='Сисиема', idwho ='1', message = '".$message."', towhom = '".$sect02['user']."', idtowhom = '".$topic ['login']."', time = '".$time."', readd = '0', topic = '', date='".$data."'");

}

if ($id == 131){
require("umnik2.php");
require("umnik3.php");
}


if ($id == 179)require("anek.php");

$prev = mysql_fetch_array( mysql_query( "select * from `forum_message` where login='".$user."' and subfor = '".$sf."'" ));
$ttime = (time()+15);
$query = @mysql_query("SELECT * FROM `forum_message` WHERE `login` = '".$user."' and topic = '".$id."' AND `time` > '".(time() + 5)."';");
if(@mysql_affected_rows() > 0){
header("Location: ?id=".$id."&mod=tema&err=2&page=end");


}

$query = @mysql_query("SELECT * FROM `forum_message` WHERE `login` = '".$user."' and topic = '".$id."' AND `msg` = '".$msg."';");
if(@mysql_affected_rows() > 0){

header("Location: ?id=".$id."&mod=tema&err=3&page=end");
}
else
{


// Добавление файла
$limit_razm=$limit_for*1024;
$newdownsize=$_FILES['file']['size']; //размер
$newdown=$_FILES['file']['name']; //имя
$newdown2=$_FILES['file']['type']; //type
$par = GetImageSize($file);
$dl=strlen($newdown);
$list=substr($newdown,$dl-3,3);
if(!empty($newdown)){
if($newdownsize>$limit_razm)$error=4;
if(empty($error))
{
$razr = array('.gif', '.jpg', '.jpeg', '.bmp', '.png', '.wbmp', '.pic', '.ani', '.pco','.zip', '.rar', '.cab', '.sis', '.sisx', '.jar', '.jad','.sis', '.sisx', '.thm', '.sdt', '.nth', '.mtf', '.col', '.scs', '.utz','.3gp', '.mp4', '.avi', '.mpeg', '.rm','.mmf', '.mid', '.amr', '.mp3', '.wav', '.aac', '.seq', '.vox', '.dxm', '.imy', '.emy', '.pmd', '.rng', '.txt');

$ext = strtolower(strrchr($_FILES['file']['name'], '.'));
if(in_array($ext, $razr)) $gi='ok';
if(empty($gi))$gi='no';
if($gi=='ok')
{



$name = "".time().$ext."";
$newdown = check_full($newdown);

copy($_FILES['file']['tmp_name'], "./fail/".$name);
@chmod("$name", 0644);
@chmod("./fail/$name", 0644);

$add = "Insert into forum_message set topic='".$id."', login ='".$user."', msg='".$msg."',time='".time()."', section='".$f."', subfor = '".$sf."', fale = '".$name."', fname = '".$newdown."', size = '".$newdownsize."', privat = '".$privat."'";
if (mysql_query($add))
{   echo $fs1;
echo "<div>Ваше сообщение добавленно!</div>";
mysql_query("update `forum_topic` set time='".time()."' where id='".$id."';");
if ($id == 5)require("tupica.php");
$postsf =  $row['postsf'];
$postsf++;
$posts =  $row['posts'];
$posts++;
$dayp =  $row['dayp'];
$dayp++;
mysql_query ("Update users set posts='".$posts."', postsf='".$postsf."', dayp='".$dayp."' where id ='".$myid."'");
header("Location: ".F."tema/$id/end");
echo $fs2;
}
else
{
echo $fs1;
echo "<div>Произошла ошибка...</div>";
echo $fs2;
}


}else{
$error = 5;
header("Location: ?id=".$id."&mod=tema&err=$error&page=end");
}

}else{
header("Location: ?id=".$id."&mod=tema&err=$error&page=end");
}
}else{


$add = "Insert into forum_message set topic='".$id."', login ='".$user."', msg='".$msg."',time='".time()."', section='".$f."', subfor = '".$sf."', privat = '".$privat."'";
if (mysql_query($add))
{   echo $fs1;
echo "<div>Ваше сообщение добавленно!</div>";
mysql_query("update `forum_topic` set time='".time()."' where id='".$id."';");
if ($id == 5)require("tupica.php");
$postsf =  $row['postsf'];
$postsf++;
$posts =  $row['posts'];
$posts++;
$dayp =  $row['dayp'];
$dayp++;
mysql_query ("Update users set posts='".$posts."', postsf='".$postsf."', dayp='".$dayp."' where id ='".$myid."'");
header("Location: ".F."tema/$id/end");
echo $fs2;
}
else
{
echo $fs1;
echo "<div>Произошла ошибка...</div>";
echo $fs2;
}

}

}
}
}

}
?>