View file forum/index.php

File size: 37.52Kb
<?php

require"../system/config.php";
require"../system/func.php";
if(!empty($_GET['id_them']) and !empty($_GET['id_forum'])){$qaq=mysql_fetch_assoc(mysql_query("SELECT `ftname` FROM `forum_themes` WHERE `id_them`='".$_GET['id_them']."' LIMIT 1")); $title=$qaq['ftname'];}

if(!empty($_GET['id_forum']) and empty($_GET['id_them'])){$qaq=mysql_fetch_assoc(mysql_query("SELECT `fname` FROM `forum_kategory` WHERE `id_forum`='".$_GET['id_forum']."' LIMIT 1")); $title=$qaq['fname'];}
if(empty($_GET['id_them']) or empty($_GET['id_forum'])){

$title='Форум';}
require"../system/head.php";
require"../system/error.php";
$page = abs((int)$_GET['page']);
$act = prov($_GET['act']);
switch($mod){
default:
if(isset($_GET['id_forum'])){$id_forum=cifry($_GET['id_forum']);}else{$id_forum=0;}

echo'<div class="i">Форум<br></div>';
echo'<div class="p"></a><a href="/pages/help.php">Помощь</a>|<a href="/forum/search.php?act=go">Поиск</a>|<a href="/pages/admins.php">Команда</a>|';
echo'<a href="/forum/top-list.php">Топ-лист</a>|<a href="/forum/top-themes.php">Топ-тем</a><br>';
if($vhod==1){echo'- <a href="/forum/my_themes.php">Мои темы</a><br>';}
echo'- <a href="/forum/new_themes.php">Новые темы</a></div>';
$forums=mysql_query("select * from forum_kategory where gde='0' order by id_forum desc");
$kol=mysql_num_rows($forums);
$pforums=mysql_query("select * from forum_kategory where gde='$id_forum' order by id_forum desc");
$pkol=mysql_num_rows($pforums);
if($kol==0){
echo'<div class="p">
Пока нет разделов...<br>
</div>';
}else{
while($forum=mysql_fetch_array($forums)){
$themes=mysql_num_rows(mysql_query("select * from forum_themes where id_kat='".$forum['id_forum']."'"));
$messages=mysql_num_rows(mysql_query("select * from forum_messages where id_kat='".$forum['id_forum']."'"));
echo'<div class="i"><a href="/forum/'.$forum['id_forum'].'/">'.$forum['fname'].'</a> ['.(PodTem($forum['id_forum'])+$themes).'/'.(PodMes($forum['id_forum'])+$messages).']
</div>'; 

if($id_forum==$forum['id_forum']){
if($pkol!=0){
while($pforum=mysql_fetch_array($pforums)){
$pthemes=mysql_num_rows(mysql_query("select * from forum_themes where id_kat='".$pforum['id_forum']."'"));
$pmessages=mysql_num_rows(mysql_query("select * from forum_messages where id_kat='".$pforum['id_forum']."'"));
echo'<div class="p"><img src="/design/default/act.gif" alt="-"> <a href="/forum/view/'.$pforum['id_forum'].'/">'.$pforum['fname'].'</a> ['.(PodTem($pforum['id_forum'])+$pthemes).'/'.(PodMes($pforum['id_forum'])+$pmessages).']</div>';
}}else{echo'Подфорумы не созданы';}
}

}
$onli=mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `gdeon` LIKE '/forum/%' AND `online`>'".(time()-120)."'"),0);
$guei=mysql_result(mysql_query("SELECT COUNT(*) FROM `online` WHERE `query` LIKE '/forum/%' AND `timer`>'".(time()-120)."'"),0);
$whodp=$onli+$guei;

$coufile=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_messages` WHERE `file_f`!=''"),0);
echo'<div class="p"><img src="/design/default/act.gif" alt="-"> <a href="/pages/online.php?act=forum">Online: '.$whodp.' ['.$onli.'/'.$guei.']</a><br>';
if($vhod==1){echo'<img src="/design/default/act.gif" alt="-"> <a href="/pages/menu.php">Профиль</a><br><img src="/design/default/act.gif" alt="-"> 
<a href="/pages/post.php">Приват</a><br>';}
echo'<img src="/design/default/act.gif" alt="-"> <a href="/forum/new_messages.php">Найти новые</a><br><img src="/design/default/act.gif" alt="-"> <a href="/forum/files.php">Файлы форума</a> ['.$coufile.']</div>';
}
break;
//Вывод тем раздела
case'1':
if(isset($_GET['id_forum'])){$id_forum=cifry($_GET['id_forum']);}else{$id_forum=0;}
$razdel=mysql_query("select * from forum_kategory where id_forum='$id_forum' limit 1");
if(mysql_num_rows($razdel)==0){
echo'<div class="i">Форум<br></div>';

echo'<div class="p">Ошибка! Такого раздела форума не существует!<br></div>';
}else{
$nrazdel=mysql_fetch_assoc($razdel);

echo'<div class="p"><a href="/forum/?">Форум</a>|';
if($nrazdel['gde']!=0){ $fng=mysql_fetch_assoc(mysql_query("SELECT `fname`,`id_forum` FROM `forum_kategory` WHERE `id_forum`='".$nrazdel['gde']."' AND `gde`='0' LIMIT 1")); echo'<a href="/forum/'.$fng['id_forum'].'/">'.$fng['fname'].'</a>|';} echo $nrazdel['fname'].'<br>
</div>';



$num=10;

$kol=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_themes` WHERE `id_kat`='$id_forum'"),0);
$total=$kol;
if($page < 0 || $page > $total) $page = 0;
if ($total < $page + 10) $end = $total;
else $end = $page + 10;
if($kol==0){
if($nrazdel['stat']==0){echo'<div class="p">Пока нет тем...<br></div>';}
}else{
$vforum=mysql_query("select * from forum_themes where id_kat='$id_forum' order by zakr='1' desc, updater desc limit $page,$num");
while($forum=mysql_fetch_array($vforum)){
$messages=mysql_num_rows(mysql_query("select * from forum_messages where id_them='".$forum['id_them']."'"));
echo'<div class="p">';
if($forum['zakr']==1){echo'[!] ';}
if($forum['otkr']==1){echo'[#] ';}
echo'<a href="/forum/theme/'.$id_forum.'/'.$forum['id_them'].'/">'.$forum['ftname'].'</a> ['.$messages.'] ';
if($messages==0){$nbp=mysql_fetch_assoc(mysql_query("SELECT `id_user` FROM `forum_themes` WHERE `id_them`='".$forum['id_them']."' LIMIT 1"));}else{
$res=mysql_fetch_assoc(mysql_query("SELECT `id_mes`  FROM `forum_messages` WHERE `id_them`='".$forum['id_them']."' ORDER BY `timer` DESC LIMIT 1"));
$nbp=mysql_fetch_assoc(mysql_query("SELECT `id_user` FROM `forum_messages` WHERE `id_mes`='".$res['id_mes']."' LIMIT 1"));}
echo nik_tri($nbp['id_user']).' ';
if($messages>10){
$stbud=round($messages,-1);
$skcf=strlen($messages);
$skcf=strlen($messages);
$poslc=substr($messages,($skcf-1),$skcf);
if($poslc>=5 or $poslc=='0'){
$stbud=$stbud-10;
}
echo'<a href="/forum/theme/'.$id_forum.'/'.$forum['id_them'].'/page='.$stbud.'"><b>&#187;</b></a><br>';
}else{
echo'<br>';
}
echo'</div>';
}
}
echo'</div>';
if($nrazdel['stat']==0){$coufile=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_messages` WHERE `file_f`!='' AND `id_kat`='$id_forum'"),0); echo'<div class="p"><img src="/design/default/act.gif" alt="-"> <a href="/forum/files.php?id_forum='.$id_forum.'">Файлы подфорума</a> ['.$coufile.']</div>
';}}
if($total>10){
strmpage($page, 10, $total, "/forum/view/$id_forum/");}
if($vhod==1){
echo'<div class="p"><a href="/forum/?mod=2&amp;id_forum='.$id_forum.'" class="but">Начать новую тему</a><br></div>';
}
 break;


//Форма добавления темы
case'2':
if(isset($_GET['id_forum'])){$id_forum=cifry($_GET['id_forum']);}else{$id_forum=0;}
$razdel=mysql_query("select * from forum_kategory where id_forum='$id_forum' limit 1");
if(mysql_num_rows($razdel)==0){
echo'<div class="i">Форум<br></div>';

echo'<div class="p">Ошибка! Упущены обязательные данные!<br></div>';
}else{
if($vhod==1){
echo'<div class="i">Новая тема<br></div>';
echo'<div class="p"><form action="/forum/?mod=3&amp;id_forum='.$id_forum.'" method="post">
Тема:<br>
<input type="text" name="nathem" maxlength="150" size="18" class="form"><br>
Сообщение:<br>
<textarea cols="20" rows="3" name="soob" class="form"></textarea><br>';
if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
echo'<input type="checkbox" value="1" name="zakrep" class="form"> Закрепить<br>';
}
echo'<input type="submit" value="Добавить"  class="but"><br></form></div>';
}else{
echo'<div class="i">Форум<br></div>
<div class="p">Ошибка! Добавлять темы могут только авторизованные пользователи!<br></div>';
}
}


break;


//Добавление темы
case'3':
if(isset($_GET['id_forum'])){$id_forum=cifry($_GET['id_forum']);}else{$id_forum=0;}
$prerr=mysql_num_rows(mysql_query("SELECT * FROM `forum_kategory` WHERE `id_forum`='$id_forum' AND `stat`='1' LIMIT 1"));

if($prerr!=0){ echo'В этот подфорум,запрещено добавлять темы';
require"../system/foot.php";
exit;}
$razdel=mysql_query("select * from forum_kategory where id_forum='$id_forum' limit 1");
if(mysql_num_rows($razdel)==0){
echo'<div class="i">Форум<br></div>';
echo'<div class="p">Ошибка! Упущены обязательные данные!<br></div>';
}else{
if($vhod==1){
if(isset($_POST['soob'])){$soob=prov($_POST['soob'],10000);}else{$soob='';}
if(isset($_POST['nathem'])){$nathem=prov($_POST['nathem'],150);}else{$nathem='';}
if(isset($_POST['zakrep'])){$zakrep=cifry($_POST['zakrep']);}else{$zakrep=0;}
if($zakrep==1 and ($adm_pr==2 or $adm_pr==3 or $adm_pr==4)){$zakrep=1;}else{$zakrep=0;}
echo'<div class="i">Новая тема<br></div>';
if(empty($soob) or strlen($soob)<3 or empty($nathem) or strlen($nathem)<5){
echo'<div class="p">Ошибка! Cообщение или тема слишком короткие!<br></div>';
}else{
$flud=mysql_num_rows(mysql_query("select * from forum_themes where id_user='$id_user' and timer>'".time()."'"));
$povtor=mysql_num_rows(mysql_query("select * from forum_themes where id_user='$id_user' and ftname='$nathem'"));
if($flud==0 and $povtor==0){

mysql_query("insert into forum_themes set id_kat='$id_forum', ftname='$nathem', fttext='$soob', ftdater='".date('d.m.Y - H:i:s')."', pervoe='".date('d.m.Y - H:i:s')."', timer='".(time()+8)."', id_user='$id_user', updater='".time()."', zakr='$zakrep'");
mysql_query("update users set balls=balls+1 where id_user='$id_user' limit 1");
$qm=mysql_fetch_assoc(mysql_query("SELECT `id_them`,`id_kat` FROM `forum_themes` ORDER BY `id_them` DESC LIMIT 1"));
header('Location: /forum/theme/'.$qm['id_kat'].'/'.$qm['id_them'].'/isset=yestheme');

}else{
echo'<div class="p">Ошибка! Вы слишком часто пытаетесь добавить тему либо такая тема уже есть в базе!<br></div>';
}
}
}else{
echo'<div class="i">Форум<br></div>
<div class="p">Ошибка! Добавлять темы могут только авторизованные пользователи!<br></div>';
}
}

break;
//Вывод сообщений темы
case'4':
if(isset($_GET['id_them'])){$id_them=cifry($_GET['id_them']);}else{$id_them=0;}
if(isset($_GET['id_forum'])){
$id_forum=cifry($_GET['id_forum']);}else{$id_forum=0;}
$razdel=mysql_query("select * from forum_kategory where id_forum='$id_forum' limit 1");
$tema=mysql_query("select * from forum_themes where id_them='$id_them' limit 1");
if(mysql_num_rows($tema)==0 or mysql_num_rows($razdel)==0){
echo'<div class="i">Форум<br></div>';
echo'<div class="p">Ошибка! Такой темы нет!<br></div>';
}else{
$nthem=mysql_fetch_array($tema);
$fnt=mysql_fetch_assoc($razdel);
echo'<div class="p"><a href="/forum/?">Форум</a>|';  
 if($fnt['gde']!=0){ $fng=mysql_fetch_assoc(mysql_query("SELECT `fname`,`id_forum` FROM `forum_kategory` WHERE `id_forum`='".$fnt['gde']."' AND `gde`='0' LIMIT 1")); 
echo'<a href="/forum/'.$fng['id_forum'].'/">
'.$fng['fname'].'</a>|';}
echo'<a href="/forum/view/'.$id_forum.'/">'.$fnt['fname'].'</a><br>'.vizual($nthem['ftname']).'</div>';
if($nthem['otkr']==0 and ($adm_pr==2 or $adm_pr==3 or $adm_pr==4)){
echo'<img src="/design/default/act.gif" alt="-"> <a href="/mpanel/control.php?mod=29&amp;id_them='.$id_them.'">Закрыть</a><br>';
}
if($nthem['otkr']==1){
echo'<div class="p">Тема закрыта!<br></div>';
if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
echo'<img src="/design/default/act.gif" alt="-"> <a href="/mpanel/control.php?mod=30&amp;id_them='.$id_them.'">Открыть</a><br>';
}
}

if($nthem['zakr']==0 and ($adm_pr==2 or $adm_pr==3 or $adm_pr==4)){
echo'<img src="/design/default/act.gif" alt="-"> <a href="/mpanel/control.php?mod=31&amp;id_them='.$id_them.'">Закрепить</a><br>';
}
if($nthem['zakr']==1){
echo'<div class="p">Тема закреплена!<br></div>';
if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
echo'<img src="/design/default/act.gif" alt="-"> <a href="/mpanel/control.php?mod=32&amp;id_them='.$id_them.'">Открепить</a><br>';
}
}
if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){ echo'<img src="/design/default/act.gif" alt="-"> <a href="/mpanel/control.php?mod=56&amp;id_them='.$id_them.'">Перенести</a><br><img src="/design/default/act.gif" alt="-"> <a href="/mpanel/control.php?mod=43&amp;
id_them='.$id_them.'">Удалить</a><br>';}
if($vhod==1){
$er5=mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `id_them`='$id_them' AND `id_kat`='$id_forum' AND `id_user`='$id_user'"));
$er6=mysql_num_rows(mysql_query("SELECT * FROM `forum_votes` WHERE `id_them`='$id_them' AND `id_user`='$id_user'"));
if($er5==1){
if($er6==0){ 
echo'<img src="/design/default/act.gif" alt="-"> <a href="/forum/?mod=26&amp;id_forum='.$id_forum.'&amp;id_them='.$id_them.'">Создать голосование</a><br>'; 
}}}
if($page<10){
if($vhod==1){

$er1=mysql_num_rows(mysql_query("SELECT * FROM `forum_votes` WHERE `id_them`='$id_them'"));
$er2=mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `id_them`='$id_them' AND `id_kat`='$id_forum'"));
$er3=mysql_num_rows(mysql_query("SELECT * FROM `forum_votes_otv` WHERE `id_them`='$id_them' AND `id_user`='$id_user'"));
if($er1>=1){
if($er2==1){
if($er3==0){
if($_GET['act']!="vote"){
$qw=mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_votes` WHERE `id_them`='$id_them' AND `type`='name'"));
if(time()<$qw['time']){
echo'<form action="/forum/?mod=27&amp;id_forum='.$id_forum.'&amp;id_them='.$id_them.'" method="post"><table align="center" width="100%">';

$qj=mysql_query("SELECT * FROM `forum_votes` WHERE `id_them`='$id_them' AND `type`='text' ORDER BY `id`");
echo'<tr><td><b>'.$qw['text'].'</b></td></tr>';
while($tr=mysql_fetch_array($qj)){echo'<tr><td>'.$tr['text'].'</td><td><input name="otv" type="radio" class="but" value="'.$tr['id'].'"></td></tr>';
}
echo'<tr><td><input type="submit" class="but" value="Голосовать"> [<a href="/forum/theme/'.$id_forum.'/'.$id_them.'/vote/">Результаты</a>]</td></tr></table></form>';}
}}
if($_GET['act']=="vote" or $er3>0){
echo'<table align="center" width="100%">';
$qw=mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_votes` WHERE `id_them`='$id_them' AND `type`='name'"));
$qj=mysql_query("SELECT * FROM `forum_votes` WHERE `id_them`='$id_them' AND `type`='text' ORDER BY `id`");
echo'<tr><td><b>'.$qw['text'].'</b></td></tr>';
while($tr=mysql_fetch_array($qj)){
$we=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_votes_otv` WHERE `id_them`='$id_them' AND `id_otv`='".$tr['id']."'"),0);
$wa=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_votes_otv` WHERE `id_them`='$id_them'"),0);
$proc=round(($we*100)/$wa);
echo'<tr><td>'.$tr['text'].'</td><td>'.$proc.' %</td></tr>';
}
echo'</table>';
}
}}
}
}
$num=10;
$kol=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_messages` WHERE `id_them`='$id_them'"),0);
$total=$kol;
if($page < 0 || $page > $total) $page = 0;

if ($total < $page + 10) $end = $total;
else $end = $page + 10; $vforum=mysql_query("select * from forum_messages where id_them='$id_them' order by id_mes asc limit $page,$num");
if(empty($page)){
$kolmg=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_messages` WHERE `id_user`='".$nthem['id_user']."'"),0);
echo'<div class="p"><b>1.</b>'.nik_one($nthem['id_user']).'['.$kolmg.']';
 if($id_user==$nthem['id_user'] or $adm_pr==2 or $adm_pr==3 or $adm_pr==4){echo' <a href="/forum/?mod=19&amp;id_them='.$id_them.'&amp;id_forum='.$id_forum.'">[Изм]</a>';}
echo'['.$nthem['pervoe'].']<br>
'.vizual($nthem['fttext']).'<br></div>';
}
$nomer=$page+1;
while($forum=mysql_fetch_array($vforum)){
$nomer++;
$kolms=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_messages` WHERE `id_user`='".$forum['id_user']."'"),0);
echo'<div class="p"><b>'.$nomer.'.</b> '.nik_one($forum['id_user']).'['.$kolms.']';
if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
echo' [<a href="/mpanel/control.php?mod=42&amp;id_soob='.$forum['id_mes'].'"><font color="red">Del</font></a>]<br>';}
if($vhod==1 and $forum['id_user']!=$id_user){echo'<a href="/forum/?mod=7&amp;id_uz='.$forum['id_user'].'&amp;page='.$page.'&amp;id_them='.$id_them.'&amp;id_forum='.$id_forum.'">Отв</a>|';} if($vhod==1 and $forum['id_user']==$id_user){echo'<a href="/forum/?mod=17&amp;
page='.$page.'&amp;id_mes='.$forum['id_mes'].'&amp;id_them='.$id_them.'&amp;id_forum='.$id_forum.'">Изм</a>|';} if($vhod==1 and $forum['id_user']!=$id_user){echo'<a href="/forum/?mod=7&amp;page='.$page.'&amp;id_mes='.$forum['id_mes'].'&amp;id_them='.$id_them.'&amp;
id_forum='.$id_forum.'">Цит</a>';} echo'<br>['.$forum['fmdater'].']<br>
'.vizual($forum['fmtext']);
if($forum['red_time']!=0 || $forum['red_time']!=0){echo'<br>______<br>посл.ред. '.date_fixed($forum['red_time']).'<br>Всего '.$forum['red_kol'].' раз';}
echo'<br>';
if($forum['file_f']!=""){
$namfl=str_replace('files/','',$forum['file_f']);
echo'<br/><img src="'.$dirsite.'/images/icon_clip.gif" alt=""> <a href="/forum/load.php?id_mess='.$forum['id_mes'].'">'.$namfl.'</a><br>Скачан: '.$forum['file_c'].' раз'; } echo'</div>';
}
strmpage($page, 10, $total, "/forum/theme/$id_forum/$id_them/");
$deq='/forum/index.php?mod=4&amp;id_forum='.$id_forum.'&amp;id_them='.$id_them;
$onl=mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `gdeon` LIKE '$deq%' AND `online`>'".(time()-120)."'"),0);
$coufile=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_messages` WHERE `file_f`!='' AND `id_them`='$id_them'"),0);
$gue=mysql_result(mysql_query("SELECT COUNT(*) FROM `online` WHERE `query` LIKE '$deq%' AND `timer`>'".(time()-120)."'"),0);
$whotut=$onl+$gue;
echo'<div class="p">';
if($vhod==1 and $nthem['otkr']==0){
echo'<a href="/forum/?mod=7&amp;id_forum='.$id_forum.'&amp;id_them='.$id_them.'&amp;page='.$page.'" class="but">
Ответить на тему</a><br>';} 
echo'<a href="/forum/?mod=24&amp;id_theme='.$id_them.'" class="but">
Фильтр сообщений</a><br>
<a href="/forum/txt.php?id_theme='.$id_them.'" class="but">Скачать в txt</a><br>
<a href="/forum/?mod=23&amp;id_forum='.$id_forum.'&amp;id_them='.$id_them.'">Кто тут?</a> ['.$whotut.']<br><a href="/forum/files.php?id_them='.$id_them.'">Файлы темы</a> ['.$coufile.']</div>';
}

break;
case'7':
if(isset($_GET['id_them'])){$id_them=cifry($_GET['id_them']);}else{$id_them=0;}
if(isset($_GET['id_them'])){$id_them=cifry($_GET['id_them']);}else{$id_them=0;}
if(isset($_GET['id_mes'])){$id_mes=cifry($_GET['id_mes']);}else{$id_mes='';}

if(isset($_GET['id_uz'])){$id_uz=cifry($_GET['id_uz']);}else{$id_uz='';}

if(isset($_GET['id_forum'])){$id_forum=cifry($_GET['id_forum']);}else{$id_forum=0;}
$razdel=mysql_query("select * from forum_kategory where id_forum='$id_forum' limit 1");
$tema=mysql_query("select * from forum_themes where id_them='$id_them' limit 1");
if(mysql_num_rows($tema)==0 or mysql_num_rows($razdel)==0){
echo'<div class="i">Форум<br></div>';
echo'<div class="p">Ошибка! Упущены обязательные данные!<br></div>';
}else{
echo'<div class="i">Сообщение<br></div>';
$nthem=mysql_fetch_array($tema);

if($nthem['otkr']==1){
echo'<div class="p">Ошибка! Тема закрыта!<br></div>';}



if(isset($id_uz) || isset($id_mes)){
if($id_uz!=""){  $qq=mysql_query("SELECT `login`,`id_user` FROM `users` WHERE `id_user`='$id_uz'"); if(mysql_num_rows($qq)!=0){ $dad=mysql_fetch_assoc($qq); $chto='[b]'.prov($dad['login']).'[/b], ';}else{ echo'ERROR'; require"../system/foot.php"; exit;}}

if($id_mes!=""){  $qq=mysql_query("SELECT `id_user`,`fmtext`,`fmdater` FROM `forum_messages` WHERE `id_mes`='$id_mes'");
if(mysql_num_rows($qq)!=0){

$dad=mysql_fetch_assoc($qq); $tamt=mysql_fetch_assoc(mysql_query("SELECT `login` FROM `users` WHERE `id_user`='".$dad['id_user']."'"));
$chto='[q][b]'.prov($tamt['login']).'[/b], '.prov($dad['fmdater']).' '.dec_text($dad['fmtext']).'[/q]';}else{ echo'ERROR'; require"../system/foot.php"; exit;}}}
echo'<div class="i">Ответ на тему</div>
<form action="/forum/?mod=6&amp;id_forum='.$id_forum.'&amp;id_them='.$id_them.'&amp;page='.$page.'" method="post" enctype="multipart/form-data">
Сообщение:<br>
<textarea cols="20" rows="3" name="soob" class="form">'.dec_text($chto).'</textarea><br>Прикрепить файл (max. 500кб):<br><input type="file" name="file" size="15" value="Обзор"><br>
<input type="submit" class="but" value="Написать"><br>
</form>';}
break;

//Добавление сообщения
case'6':
if(isset($_GET['id_them'])){$id_them=cifry($_GET['id_them']);}else{$id_them=0;}
if(isset($_GET['id_forum'])){$id_forum=cifry($_GET['id_forum']);}else{$id_forum=0;}
$razdel=mysql_query("select * from forum_kategory where id_forum='$id_forum' limit 1");
$tema=mysql_query("select * from forum_themes where id_them='$id_them' limit 1");
if(mysql_num_rows($tema)==0 or mysql_num_rows($razdel)==0){
echo'<div class="i">Форум<br></div>';
echo'<div class="p">Ошибка! Упущены обязательные данные!<br></div>';
}else{
if(isset($_POST['soob'])){$soob=prov($_POST['soob'],8000);}else{$soob='';}
echo'<div class="i">Сообщение<br></div>';
if(empty($soob) or strlen($soob)<3){
echo'<div class="p">Ошибка! Ваше сообщение слишком короткое!<br></div>';
}else{
$nthem=mysql_fetch_array($tema);
$flud=mysql_num_rows(mysql_query("select * from forum_messages where id_user='$id_user' and timer>'".time()."'"));
$povtor=mysql_num_rows(mysql_query("select * from forum_messages where id_user='$id_user' and fmtext='$soob'"));
if($flud==0 and $povtor==0){
if($vhod==1){
if($nthem['otkr']==1){
echo'<div class="p">Ошибка! Тема закрыта!<br></div>';
}else{ $rand=mt_rand(1111,9999);
$avat_size=$_FILES['file']['size'];
$avat_name=$_FILES['file']['name']; $av_file = $_FILES['file']['tmp_name']; $av_string = substr($av_file[0], 0, 3); $ext = strtolower(substr($avat_name, 1 + strrpos($avat_name, "."))); $mn=substr_count("$avat_name",".");
if($ext=="" || $ext=="jpg" || $ext=="gif" || $ext=="jpeg" || $ext=="png" || $ext=="mid" || $ext=="mp4" || $ext=="mp3" || $ext=="wav" || $ext=="mmf" || $ext=="wma" || $ext=="wmv" || $ext=="3gp" || $ext=="3gpp" || $ext=="zip" || $ext=="rar" || $ext=="gz" || $ext=="jar"
|| $ext=="swf" || $ext=="sis" || $ext=="jad"){  if($avat_size>=0 && $avat_size<=500000){
$avfl=explode(".",$avat_name);
if($ext!=""){ copy($_FILES['file']['tmp_name'], 'files/'.$avfl[0].'_'.$rand.'.'.$ext);
$fipe='files/'.$avfl[0].'_'.$rand.'.'.$ext;
}else{$fipe='';} $fttp=0;
$ftimer=time()+20;
mysql_query("insert into forum_messages set fmtext='$soob', id_kat='$id_forum', file_f='$fipe', file_c='$fttp', id_them='$id_them', fmdater='".date('d.m.Y - H:i:s')."', timer='$ftimer', id_user='$id_user'");
mysql_query("update users set balls=balls+1 where id_user='$id_user' limit 1");
mysql_query("update forum_themes set ftdater='".date('d.m.Y - H:i:s')."', updater='".time()."' where id_them='$id_them' limit 1");
header("Location: /forum/theme/$id_forum/$id_them/page=$page&isset=yesmess");

}else{echo'Ошибка, недопустимый вес файла! Разрешается загружать весом до 500 килобайт<br>';}}else{echo'Ошибка, недопустимое расширение файла!';}
$chtob=mysql_num_rows(mysql_query("select * from forum_messages where id_them='$id_them'"));
if($chtob>10){
$stbud=round($chtob,-1);
$skcf=strlen($chtob);
$poslc=substr($chtob,($skcf-1),$skcf);
if($poslc>=5 or $poslc=='0'){
$stbud=$stbud-10;
}
}
}
}else{
echo'<div class="p">Ошибка! Добавлять сообщения могут только авторизованные пользователи!<br></div>';
}
}else{
echo'<div class="p">Ошибка! Вы слишком часто пытаетесь добавить сообщение либо такое сообщение уже есть в базе!<br></div>';
}
}
}
break;
case'17':
if(isset($_GET['id_them'])){$id_them=cifry($_GET['id_them']);}else{$id_them=0;}


if(isset($_GET['id_mes'])){$id_mes=cifry($_GET['id_mes']);}else{$id_mes='';}

if(isset($_GET['id_forum'])){$id_forum=cifry($_GET['id_forum']);}else{$id_forum=0;}

$erqone=mysql_num_rows(mysql_query("SELECT * FROM `forum_messages` WHERE `id_mes`='$id_mes'"));
if($erqone==0){header("Location: /forum/"); exit;}

$erqtwo=mysql_num_rows(mysql_query("SELECT * FROM `forum_messages` WHERE `id_mes`='$id_mes' AND `id_user`='$id_user'"));
if($erqtwo==0){header("Location: /forum/"); exit;}
$razdel=mysql_query("select * from forum_kategory where id_forum='$id_forum' limit 1");
$tema=mysql_query("select * from forum_themes where id_them='$id_them' limit 1");
if(mysql_num_rows($tema)==0 or mysql_num_rows($razdel)==0){
echo'<div class="i">Форум<br></div>';
echo'<div class="p">Ошибка! Упущены обязательные данные!<br></div>';
}else{

$nthem=mysql_fetch_array($tema);

if($nthem['otkr']==1){
echo'<div class="p">Ошибка! Тема закрыта!<br></div>';}

$qq=mysql_fetch_array(mysql_query("SELECT `fmtext` FROM `forum_messages` WHERE `id_mes`='$id_mes'"));

$qq['fmtext']=str_replace('\r\n','[br/]',$qq['fmtext']);

$qq['fmtext']=str_replace('\r\ n','[br/]',$qq['fmtext']);
echo'<form action="/forum/?mod=18&amp;id_mes='.$id_mes.'&amp;id_forum='.$id_forum.'&amp;id_them='.$id_them.'&amp;page='.$page.'" method="post">Сообщение:<br><textarea cols="20" rows="3" name="fmtext" class="form">'.dec_text($qq['fmtext']).'</textarea>
<br><input type="submit" value="Редактировать" class="but"/></form>';
}
break;

case'18':
if(isset($_GET['id_them'])){$id_them=cifry($_GET['id_them']);}else{$id_them=0;}


if(isset($_GET['id_mes'])){$id_mes=cifry($_GET['id_mes']);}else{$id_mes='';}

if(isset($_GET['id_forum'])){$id_forum=cifry($_GET['id_forum']);}else{$id_forum=0;}
$erqone=mysql_num_rows(mysql_query("SELECT * FROM `forum_messages` WHERE `id_mes`='$id_mes'"));
if($erqone==0){header("Location: /forum/"); exit;}
$erqtwo=mysql_num_rows(mysql_query("SELECT * FROM `forum_messages` WHERE `id_mes`='$id_mes' AND `id_user`='$id_user'"));
if($erqtwo==0){header("Location: /forum/"); exit;}
$razdel=mysql_query("select * from forum_kategory where id_forum='$id_forum' limit 1");
$tema=mysql_query("select * from forum_themes where id_them='$id_them' limit 1");
if(mysql_num_rows($tema)==0 or mysql_num_rows($razdel)==0){
echo'<div class="i">Форум<br></div>';
echo'<div class="p">Ошибка! Упущены обязательные данные!<br></div>';
}else{
$fmtext=prov($_POST['fmtext']);
if($fmtext==""){echo'Сообщение пустое'; require"../system/foot.php"; exit;}
$nthem=mysql_fetch_array($tema);

if($nthem['otkr']==1){
echo'<div class="p">Ошибка! Тема закрыта!<br></div>';}
$dd=mysql_fetch_array(mysql_query("SELECT `red_kol` FROM `forum_messages` WHERE `id_mes`='$id_mes'"));
$sam=$dd['red_kol']+1;
mysql_query("UPDATE `forum_messages` SET `red_kol`='$sam', `red_time`='".time()."', `fmtext`='$fmtext' WHERE `id_mes`='$id_mes'");
header("Location: /forum/theme/$id_forum/$id_them/page=$page&isset=yesedit");

$chtob=mysql_num_rows(mysql_query("select * from forum_messages where id_them='$id_them'"));

if($chtob>10){
$stbud=round($chtob,-1);
$skcf=strlen($chtob);
$poslc=substr($chtob,($skcf-1),$skcf);
if($poslc>=5 or $poslc=='0'){
$stbud=$stbud-10;
}
}}
break;

case'19':

if(isset($_GET['id_them'])){$id_them=cifry($_GET['id_them']);}else{$id_them=0;} if(isset($_GET['id_forum'])){$id_forum=cifry($_GET['id_forum']);}else{$id_forum=0;}
$razdel=mysql_num_rows(mysql_query("SELECT * FROM `forum_kategory` WHERE `id_forum`='$id_forum' LIMIT 1"));
$azdel=mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `id_them`='$id_them' LIMIT 1"));
if($razdel==0 or $azdel==0){
echo'<div class="i">Форум<br></div>';

echo'<div class="p">Ошибка! Упущены обязательные данные!<br></div>';}else{ $prver=mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `id_user`='$id_user' AND `id_them`='$id_them' LIMIT 1"));
if($prver!=0 or $adm_pr==2 or $adm_pr==3 or $adm_pr==4){

if($vhod==1){
$qq=mysql_fetch_array(mysql_query("SELECT `fttext`,`ftname` FROM `forum_themes` WHERE `id_them`='$id_them' LIMIT 1")); echo'<div class="i">Редактирование темы<br></div>';
echo'<div class="p"><form action="/forum/?mod=20&amp;id_forum='.$id_forum.'&amp;id_them='.$id_them.'" method="post">
Тема:<br>
<input type="text" name="nathem" maxlength="150" class="form" size="18" value="'.dec_text($qq['ftname']).'"><br>
Сообщение:<br>
<textarea cols="20" rows="3" name="soob" class="form">'.dec_text($qq['fttext']).'</textarea><br>';
if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
echo'<input type="checkbox" value="1" name="zakrep" class="form"> Закрепить<br>';
}
echo'<input type="submit" value="Редактировать"  class="but"><br></form></div>';
}else{
echo'<div class="i">Форум<br></div>
<div class="p">Ошибка! Вы не авторизованы<br></div>';
}
}else{echo'<div class="i">Форум<br></div>';

echo'<div class="p">Фатальная Ошибка!<br></div>';}}

break;


//Редактирование темы
case'20':

if(isset($_GET['id_them'])){$id_them=cifry($_GET['id_them']);}else{$id_them=0;} if(isset($_GET['id_forum'])){$id_forum=cifry($_GET['id_forum']);}else{$id_forum=0;}
$razdel=mysql_num_rows(mysql_query("SELECT * FROM `forum_kategory` WHERE `id_forum`='$id_forum' LIMIT 1"));
$azdel=mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `id_them`='$id_them' LIMIT 1"));
if($razdel==0 or $azdel==0){
echo'<div class="i">Форум<br></div>';

echo'<div class="p">Ошибка! Упущены обязательные данные!<br></div>';}else{$prver=mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `id_user`='$id_user' AND `id_them`='$id_them' LIMIT 1"));  if($prver!=0 or $adm_pr==2
or $adm_pr==3 or $adm_pr==4){

if($vhod==1){
if(isset($_POST['soob'])){$soob=prov($_POST['soob'],4000);}else{$soob='';}
if(isset($_POST['nathem'])){$nathem=prov($_POST['nathem'],150);}else{$nathem='';}
if(isset($_POST['zakrep'])){$zakrep=cifry($_POST['zakrep']);}else{$zakrep=0;}
if($zakrep==1 and ($adm_pr==2 or $adm_pr==3 or $adm_pr==4)){$zakrep=1;}else{$zakrep=0;}
echo'<div class="i">Редактирование темы<br></div>';
if(empty($soob) or strlen($soob)<3 or empty($nathem) or strlen($nathem)<5){
echo'<div class="p">Ошибка! Cообщение или тема слишком короткие!<br></div>';
}else{
mysql_query("UPDATE `forum_themes` SET `ftname`='$nathem', `fttext`='$soob', zakr='$zakrep' WHERE `id_them`='$id_them'");

header("Location: /forum/theme/$id_forum/$id_them/isset=yesedit");
}
}else{
echo'<div class="i">Форум<br></div>
<div class="p">Ошибка! Вы не авторизованы!<br></div>';
}}else{echo'<div class="i">Форум<br></div>';

echo'<div class="p">Фатальная Ошибка!<br></div>';}
}
break;
case'24':
echo'<div class="i">Фильтрация постов</div>'; 
$id=(int)$_GET['id_theme']; $erg=mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `id_them`='$id' LIMIT 1")); if($erg==1){ $query=mysql_query("SELECT DISTINCT `id_user` FROM `forum_messages`
WHERE `id_them`='$id' ORDER BY `id_user`"); echo'<form action="index.php?mod=25&amp;id_theme='.$id.'" method="post">';
while($data=mysql_fetch_array($query)){
 $cou=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_messages` WHERE `id_them`='$id' AND `id_user`='".$data['id_user']."'"),0);
echo'<input type="checkbox" name="avtor[]" value="'.$data['id_user'].'"> '.nik_tri($data['id_user']).' ['.$cou.']<br>';}
echo'<div class="p">Выберите нужных авторов и нажимите "Фильтровать", для того чтобы видеть сообщения только от выбраных авторов</div><input type="submit" value="Фильтровать"
class="but"/></form>'; }else{ echo'ERROR';} break;
case'25':
if(empty($_POST['avtor'])){echo'Ничего не выбрано';}else{ $id=(int)$_GET['id_theme']; $erg=mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `id_them`='$id' LIMIT 1")); if($erg==1){
echo'<div class="i">Сообщения от</div><div class="p">'; 
foreach($_POST['avtor'] as $gm){ echo nik_tri($gm).',';

} echo'</div>'; 
foreach($_POST['avtor'] as $p){

$query=mysql_query("SELECT * FROM `forum_messages` WHERE `id_them`='$id' AND `id_user`='$p' ORDER BY `id_user`");
while($forum=mysql_fetch_array($query)){
echo'<div class="p">'.nik_one($forum['id_user']);
echo'<br>['.$forum['fmdater'].']<br>
'.vizual($forum['fmtext']);
if($forum['red_time']!=0 || $forum['red_time']!=0){echo'<br>______<br>посл.ред. '.date_fixed($forum['red_time']).'<br>Всего '.$forum['red_kol'].' раз';}
echo'<br>';
if($forum['file_f']!=""){
$namfl=str_replace('files/','',$forum['file_f']);
echo'<br/><img src="'.$dirsite.'/images/icon_clip.gif" alt=""> <a href="/forum/load.php?id_mess='.$forum['id_mes'].'">'.$namfl.'</a><br>Скачан: '.$forum['file_c'].' раз'; } echo'</div>';
}
}}else{echo'ERROR';}} break;
case'26':
if($vhod==1){

if(isset($_GET['id_forum'])){$id_forum=cifry($_GET['id_forum']);}else{$id_forum=0;}
if(isset($_GET['id_them'])){$id_them=cifry($_GET['id_them']);}else{$id_them=0;}
$er1=mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `id_them`='$id_them' AND `id_kat`='$id_forum' AND `id_user`='$id_user'"));
$er2=mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `id_them`='$id_them' AND `id_kat`='$id_forum'"));
$er3=mysql_num_rows(mysql_query("SELECT * FROM `forum_votes` WHERE `id_them`='$id_them' AND `id_user`='$id_user'"));
if($er1==1){
if($er2==1){
if($er3==0){
if(empty($_POST['vote']) or empty($_POST['otv']) or empty($_POST['time'])){
echo'<form action="/forum/?mod=26&amp;id_forum='.$id_forum.'&amp;id_them='.$id_them.'" method="post">';
if($_POST['kol']>=2){ 
$kol=(int)$_POST['kol'];
echo'Вопрос?<br><input type="text" name="vote" class="form" size="18"><br>Варианты ответов<br>';
for($i=0; $i<$kol; $i++){echo'<input type="text" name="otv[]" class="form" size="18"><br>';}
echo'Сколько дней вести голосование?<br><input type="text" name="time" class="form" size="8"><br>';
}else{
echo'Меньше двух вариантов нельзя<hr>Сколько вариантов?<br><input type="text" name="kol" class="form" size="5">';
}
echo'<input type="submit" class="but" value="OK"></form>';

}else{
$otve=$_POST['otv'];
$vote=prov($_POST['vote'],100);
$time=(int)$_POST['time'];
$tame=time()+($time*86400);
mysql_query("INSERT INTO `forum_votes` SET `id_user`='$id_user', `type`='name',`text`='$vote', `time`='$tame', `id_them`='$id_them'");
foreach($otve as $otv){
mysql_query("INSERT INTO `forum_votes` SET `type`='text',`text`='".prov($otv)."', `id_them`='$id_them'");
}
echo'<div class="p">Успешно добавлено<br><a href="/forum/theme/'.$id_forum.'/'.$id_them.'/">В тему</a>';

}



}else{echo'Уже создано';}
}else{echo'Нет такой темы';}
}else{echo'Вы не автор темы';}
}else{echo'Вы не авторизованы';}
break;
case'27';

if($vhod==1){

if(isset($_GET['id_forum'])){$id_forum=cifry($_GET['id_forum']);}else{$id_forum=0;}
if(isset($_GET['id_them'])){$id_them=cifry($_GET['id_them']);}else{$id_them=0;}
if(!empty($_POST['otv'])){$otv=cifry($_POST['otv']);}else{header('Location: /forum/theme/'.$id_forum.'/'.$id_them.'/'); exit;}

$er1=mysql_num_rows(mysql_query("SELECT * FROM `forum_votes` WHERE `id_them`='$id_them'"));
$er2=mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `id_them`='$id_them' AND `id_kat`='$id_forum'"));
$er3=mysql_num_rows(mysql_query("SELECT * FROM `forum_votes_otv` WHERE `id_them`='$id_them' AND `id_user`='$id_user'"));
if($er1>=1){
if($er2==1){
if($er3==0){
mysql_query("INSERT INTO `forum_votes_otv` SET `id_them`='$id_them', `id_user`='$id_user', `id_otv`='$otv'");
header('Location: /forum/theme/'.$id_forum.'/'.$id_them.'/');
}else{echo'Вы уже голосовали';}
}else{echo'Нет такой темы';}
}else{echo'Fatal error';}
}else{echo'Вы не авторизованы';}
break;

case'23':
echo'<div class="i">Кто в этой теме</div>';
$id_f=(int)$_GET['id_forum']; $id_t=(int)$_GET['id_them'];  $ert=mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `id_them`='$id_t' LIMIT 1")); $erf=mysql_num_rows(mysql_query("SELECT * FROM `forum_kategory` WHERE `id_forum`='$id_f' LIMIT 1"));
if($ert!=0 or $erf!=0){$deq='/forum/index.php?mod=4&amp;id_forum='.$id_f.'&amp;id_them='.$id_t;
$online=mysql_query("SELECT `id_user` FROM `users` WHERE `gdeon` LIKE '$deq%' AND `online`>'".(time()-120)."'");
$nasaj=mysql_num_rows($online);
echo'<div class="p">Зареганых: '.$nasaj.'<br></div>';
if($nasaj!=0){
while($naso=mysql_fetch_array($online)){
echo nik_tri($naso['id_user']).',';}
}
$guests=mysql_query("SELECT * FROM `online` WHERE `query` LIKE '$deq%' AND `timer`>'".(time()-120)."'");
$gkol=mysql_num_rows($guests);
echo'<div class="p">Гости: '.$gkol.'</div>';
if($gkol!=0){
$vcg=0;

while($guest=mysql_fetch_array($guests)){$vcg++;
echo'<div class="p"><b>'.$vcg.'.</b> IP: '.$guest['iper'].'<br>UA: '.$guest['uaer'];  echo'<br>';}
} echo'<div class="p"><a href="/forum/theme/'.$id_f.'/'.$id_t.'/">К теме</a></div>';}else{echo'ERROR';} break;
}

require"../system/foot.php";
?>