Файл: vfermu.ru/sys/home/forum.php
Строк: 199
<?
$sum_num=1;
if(intval($_GET['forum'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `farm_forum` WHERE `id` = '".intval($_GET['forum'])."'"),0)!=0)$forum=mysql_fetch_array(mysql_query("SELECT * FROM `farm_forum` WHERE `id` = '".intval($_GET['forum'])."'"));
if(isset($forum) && $forum['type']=='tema')
{
echo "<title>$forum[name]</title>";
$fk=mysql_fetch_array(mysql_query("SELECT * FROM `farm_forum` WHERE `type` = 'komm' AND `mother` = '$forum[id]' ORDER BY `time` ASC LIMIT 1"));
$mother=mysql_fetch_array(mysql_query("SELECT * FROM `farm_forum` WHERE `id` = '$forum[mother]'"));
echo "<div class='event'><h1><a href='?forum=$mother[id]'>".hsc($mother['name'])."</a> / ".hsc($forum['name'])."</h1></div>";
//======================================//
echo "<div class='content'><div class='block'>";
echo "<ul>";
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `farm_forum` WHERE `type` = 'komm' AND `mother` = '$forum[id]'"),0);
if ($k_post==0)
{
echo "Список пуст...";
}
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$q=mysql_query("SELECT * FROM `farm_forum` WHERE `type` = 'komm' AND `mother` = '$forum[id]' ORDER BY `time` ASC LIMIT $start, $set[p_str]");
while($post=mysql_fetch_array($q))
{
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `farm_user` WHERE `id` = '$post[id_user]'"));
$anku=$ank;
echo "<span class='small'><span>";
echo on_k($ank['id']);
if($post['otvet']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `farm_user` WHERE `id` = '$post[otvet]'"),0)!=0)
{
$otvet=mysql_fetch_array(mysql_query("SELECT * FROM `farm_user` WHERE `id` = '$post[otvet]'"));
$otvetu=$otvet;
}
echo "".nc($ank['id'])."</span>";
echo " <span class='minor'><span>".vremja($post['time'])."</span></span></span><p>".(isset($otvet)?"".($ku['id']==$otvet['id']?"<span class='rare'>":null)."$otvetu[nick]".($ku['id']==$otvet['id']?"</span>":null).", ":null)."".output_text($post['msg'], $ank['id'])."</p><div class='small'>".($fk['id']!=$post['id']?"".($forum['locked']==0?"".($ank['id']!=$ku['id']?"<a href='?forum=$forum[id]&otv=$ank[id]'>[ответить]</a>":null)."":null)."":null)."";
if($post['id']==$forum['id']+1){echo "";}else{echo "<br><br>";}
echo "</div>";
}
echo "</ul></div>";
include "sys/home/end.php";
}
////////////////////////////////////////////////////////////
elseif(isset($forum) && $forum['type']=='razdel' && ($forum['locked']==1 && $ku['status']>0 || $forum['locked']==0))
{
echo "<title>$forum[name]</title>";
if(isset($_GET['edit']) && $ku['status']>0)
{
echo '<div class="event"><h1>Редактирование раздела</h1></div>';
if($_GET['edit']=='ok')
{
$name=$_POST['name'];
if($name==NULL)
{
echo err_game("Слишком короткое название");
$err=1;
}
if(!isset($err))
{
if($_POST['admod']==1)$admod=1;else $admod=0;
if($_POST['locked']==1)$locked=1;else $locked=0;
mysql_query("UPDATE `farm_forum` SET `name` = '".my_esc($name)."', `admod` = '$admod', `locked` = '$locked' WHERE `id` = '$forum[id]'");
header("Location:?forum=$forum[id]");
exit;
}
}
echo '<div class="content"><div class="block">';
echo "<form action='?forum=$forum[id]&edit=ok' method='post'><ul><li><label><div>Модельние:</div><div><input type='text' class='wide' value='".hsc($forum['name'])."' name='name'></div></label></li>";
echo "<input type='checkbox' name='admod' value='1'".($forum['admod']==1?" checked='checked'":null)."> <span>Создает топики только администрацыя</span><br/>";
echo "<input type='checkbox' name='locked' value='1'".($forum['locked']==1?" checked='checked'":null)."> <span>Давать доступ только администрации</span><br/>";
echo "<li><input type='submit' value='Сохранить'></li></ul></form></div>";
include "sys/home/end.php";
}
elseif(isset($_GET['del']) && $ku['status']>0)
{
if($_GET['del']=='ok')
{
$q=mysql_query("SELECT * FROM `farm_forum` WHERE `mother` = '$forum[id]' AND `type` = 'tema'");
while($post=mysql_fetch_array($q))
{
mysql_query("delete from `farm_forum` where `mother` = '$post[id]' and `type` = 'komm'");
mysql_query("delete from `farm_forum` where `id` = '$post[id]'");
}
$links = mysql_query("SELECT * FROM `farm_forum` WHERE `type` = 'razdel' AND `pos` > '$forum[pos]' ORDER BY `pos` ASC");
while ($p = mysql_fetch_array($links))
{
mysql_query("UPDATE `farm_forum` SET `pos` = '".($p['pos']-1)."' WHERE `id` = '$p[id]' LIMIT 1");
}
mysql_query("delete from `farm_forum` where `id` = '$forum[id]' and `type` = 'razdel'");
header("Location:?forum");
}
else echo '<div class="event"><h1>Подтверждение</h1></div><div class="content"><div class="block"><li><span class="title">Вы уверены?</span></li><li class="pt"><img alt="" width="16" height="16" src="images/icons/tick.png"> <a href="?forum='.$forum['id'].'&del=ok"><span>
Да, подтверждаю</span></a></li><li><img alt="" width="16" height="16" src="images/icons/cross.png"> <a href="?forum='.$forum['id'].'"><span>
Нет, отказываюсь</span></a></li></div></div>';
include "sys/home/end.php";
}
else
{
echo "<div class='event'><h1><a href='?forum'>Форум</a> / ".hsc($forum['name'])."</h1></div>";
echo '<div class="content"><div class="block"><ul>';
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `farm_forum` WHERE `type` = 'tema' AND `mother` = '$forum[id]'"),0);
if ($k_post==0)
{
echo "Список пуст...";
}
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$q=mysql_query("SELECT * FROM `farm_forum` WHERE `type` = 'tema' AND `mother` = '$forum[id]' ORDER BY `pined` DESC, `time_obnov` DESC LIMIT $start, $set[p_str]");
//======================================//
$visit=mysql_fetch_array(mysql_query("SELECT * FROM farm_forum WHERE id='".$forum['id']."'"));
$visit_array=explode(',',$visit['visit']);
$visit_num=count($visit_array)+$sum_num;
if(!in_array($ku['id'],$visit_array)){
$visit_array[$visit_num]=$ku['id'];
mysql_query("UPDATE farm_forum SET visit='".implode(',',$visit_array)."' WHERE id='".$forum['id']."'");
}
//======================================//
if(isset($_GET['proshit'])){
while($post=mysql_fetch_array($q))
{
$visit_array=explode(',',$post['visit']);
$visit_num=count($visit_array)+$sum_num;
if(!in_array($ku['id'],$visit_array)){
$visit_array[$visit_num]=$ku['id'];
mysql_query("UPDATE farm_forum SET visit='".implode(',',$visit_array)."' WHERE id='".$post['id']."'");
}
}
header("Location:?forum=".$forum['id'].""); exit;
}
/////===========================================================================================//
while($post=mysql_fetch_array($q))
{
echo "<li><div>";
$visit_array=explode(',',$post['visit']);
$visit_num=count($visit_array)+$sum_num;
if(!in_array($ku['id'],$visit_array)){echo"<img width='16' height='16' src='images/icons/forum_topic_new.png' alt='x' title='x'>";
} else {
if($post['locked']==1){echo"<img width='16' height='16' src='images/icons/forum_topic_closed.png' alt='x' title='x'>";
} else {
echo"<img width='16' height='16' src='images/icons/forum_topic.png' alt='*' title='*'>";
}
}
echo" <a href='?forum=$post[id]'><span style='font-weight:bold'>".hsc($post['name'])."</span></a>";
echo'</div></li>';
}
if ($k_page>1)str("?forum=$forum[id]&",$k_page,$page); // Вывод страниц
echo "</ul>";
echo "<li></li>";
if($ban['id'])
{
echo "<ul class='pt'>
<div>
<li class='major'><span>".($ban['izg']==1?'Изгнание':"Обет Молчания до ".vremja($ban['time']))."</span>, выдал".($us_ban['pol']==0?'a':null)." <span>";
echo on_k($us_ban['id']);
echo "<a href='?user=$us_ban[id]'>".nc($us_ban['id'])."</a></span><span>, (".output_text($ban['msg']).")</span></li></div></ul>";
}
echo "</ul></div>";
include "sys/home/end.php";
}
}
else
{
if(isset($_GET['add']) && $ku['status']>0)
{
echo '<div class="event"><h1>Создание раздела</h1></div>';
if($_GET['add']=='ok')
{
$name=$_POST['name'];
if($name==NULL)
{
echo err_game("Слишком короткое название");
$err=1;
}
if(!isset($err))
{
mysql_query("UPDATE `farm_user` SET `forum_count` = '1'");
mysql_query("UPDATE `farm_user` SET `` = '1'");
if($_POST['admod']==1)$admod=1;else $admod=0;
$pos=mysql_result(mysql_query("SELECT MAX(`pos`) FROM `farm_forum` WHERE `type` = 'razdel'"), 0)+1;
mysql_query("INSERT INTO `farm_forum` SET `name` = '".my_esc($name)."', `id_user` = '$ku[id]', `type` = 'razdel', `mother` = '0', `time` = '$time', `admod` = '$admod', `pos` = '$pos', `locked` = '".($_POST['locked']==1?"1":"0")."'");
header("Location:?forum");
exit;
}
}
echo '<div class="content"><div class="block">';
echo "<form action='?forum&add=ok' method='post'><ul><li><label><div>Модельние:</div><div><input type='text' class='wide' value='' name='name'></div></label></li>";
echo "<input type='checkbox' name='admod' value='1'> <span>Создает топики только администрацыя</span><br/>";
echo "<input type='checkbox' name='locked' value='1'> <span>Давать доступ только администрации</span><br/>";
echo "<li><input type='submit' value='Создать'></li></ul></form></div></div>";
include "sys/home/end.php";
}
else
{
if (isset($_GET['up']) && $ku['status']>0)
{
$up=mysql_fetch_assoc(mysql_query("SELECT * FROM `farm_forum` WHERE `id` = '".intval($_GET['up'])."' AND `type` = 'razdel' LIMIT 1"));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `farm_forum` WHERE `pos` < '$up[pos]' AND `type` = 'razdel' LIMIT 1"),0)!=0)
{
mysql_query("UPDATE `farm_forum` SET `pos` = '".($up['pos'])."' WHERE `pos` = '".($up['pos']-1)."' AND `type` = 'razdel' LIMIT 1");
mysql_query("UPDATE `farm_forum` SET `pos` = '".($up['pos']-1)."' WHERE `id` = '".intval($_GET['up'])."' AND `type` = 'razdel' LIMIT 1");
}
}
elseif (isset($_GET['down']) && $ku['status']>0)
{
$down=mysql_fetch_assoc(mysql_query("SELECT * FROM `farm_forum` WHERE `id` = '".intval($_GET['down'])."' AND `type` = 'razdel' LIMIT 1"));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `farm_forum` WHERE `pos` > '$down[pos]' AND `type` = 'razdel' LIMIT 1"),0)!=0)
{
mysql_query("UPDATE `farm_forum` SET `pos` = '".($down['pos'])."' WHERE `pos` = '".($down['pos']+1)."' AND `type` = 'razdel' LIMIT 1");
mysql_query("UPDATE `farm_forum` SET `pos` = '".($down['pos']+1)."' WHERE `id` = '".intval($_GET['down'])."' AND `type` = 'razdel' LIMIT 1");
}
}
echo "<title>Форум</title>";
echo '<div class="content"><div class="block"><ul>';
$q=mysql_query("SELECT * FROM `farm_forum` WHERE `type` = 'razdel' ORDER BY `pos` ASC");
while($post=mysql_fetch_array($q))
{
echo "<li>";
$visit_array=explode(',',$post['visit']);
$visit_num=count($visit_array)+$sum_num;
if(!in_array($ku['id'],$visit_array)){echo"<img width='16' height='16' src='images/icons/forum_new.png' alt='*' title='*'>";} else {echo"<img width='16' height='16' src='images/icons/forum.png' alt='*' title='*'>";}
echo " <a href='?forum=$post[id]'><span>".hsc($post['name'])."</span></a>";
if(isset($_GET['moderate']))echo "<a href='?forum&moderate&up=$post[id]'><img width='16' height='16' src='images/icons/up.png' alt='o'></a> <a href='?forum&moderate&down=$post[id]'><img width='16' height='16' src='images/icons/down.png' alt='o'></a>";
echo "</li>";
}
echo "</ul>";
echo "</ul></div>";
include "sys/home/end.php";
}
}
?>