File size: 4.98Kb
<? $dir=''; include("../head.php");if(!isset($me) or @$me['admin']!=2)exit("Нету доступа");
if(isset($_GET['id'])){
$id=$_GET['id'];
$tema=mysql_fetch_array(mysql_query("SELECT * FROM `sh_tem` WHERE `id`='$id'"));
if(!$tema)die("Тема не найдена");
$podcat=mysql_fetch_array(mysql_query("SELECT * FROM `sh_podcat` WHERE `id`='$tema[cat]'"));
$cat=mysql_fetch_array(mysql_query("SELECT * FROM `sh_cat` WHERE id='$podcat[refid]'"));
if($podcat && $cat)echo "Форум <a href='cat.php?id=$cat[id]'>$cat[name]</a> | Категория <a href='podcat.php?id=$podcat[id]'>$podcat[name]</a><br/>Тема <b>$tema[name]</b><br/>";
if($tema['close']==1)echo "Тема закрыта <a href='tema.php?close=$id'>[открыть]</a> ";
else if($tema['close']==0)echo "Тема открыта <a href='tema.php?close=$id'>[закрыть]</a> ";
if($tema['up']==0)echo "<a href='tema.php?up=$id'>[прикрепить]</a>";
elseif($tema['up']==1)echo "<a href='tema.php?up=$id'>[открепить]</a>";
$num = 10;@$page = $_GET['page'];
$result00 = mysql_query("SELECT COUNT(*) FROM `sh_post` where `tema`='$id'");
$temp = mysql_fetch_array($result00);
$posts = $temp[0];
$total = (($posts - 1) / $num) + 1;
$total = intval($total);
$page = intval($page);
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * $num - $num;
$post_q=mysql_query("SELECT * FROM `sh_post` WHERE `tema`='$id' ORDER BY `time` LIMIT $start,$num");
if($posts !=0){echo "<div class='menu'>";
while($post=mysql_fetch_array($post_q)){
$us_q=mysql_query("SELECT * FROM `sh_user` WHERE `id`='$post[avtor]'");
$user_avtor=mysql_fetch_array($us_q);
if(mysql_num_rows($us_q)==0)echo "DELETED#$post[avtor]";
else echo "<a href='user.php?id=$post[avtor]'>$user_avtor[echologin]</a>";
$post['date']=str_replace(date("Y.m.d"), "Сегодня", $post['date']);
echo " | <a href='post.php?edit=$post[id]'>[редакт]</a> <a href='post.php?del=$post[id]'>[уд]</a> [$post[date]]<br/>$post[text]<hr color='#CCCCCC'>";}
echo "</div>";
if($total > 1)
{$nav['url']="tema.php?id=$id&page=";
echo "<br/>";
if($page > 1){$pag=$page-1;
echo "<a href='".$nav['url'].$pag."'>Назад</a>";}
if($page + 1 <= $total){$pag=$page+1;
echo "<a href='".$nav['url'].$pag."'> Далее</a>";}
echo "<br/>Страница $page из $total";
if($page>2)echo ' <a href="'.$nav['url'].'1">В начало</a>';
}
}
else echo "Сообщений нет<br/>";}
else if(isset($_GET['edit']))
{$id=abs($_GET['edit']); if(!$edit_tema=mysql_fetch_array(mysql_query("SELECT * FROM `sh_tem` WHERE `id`='$id'")))die("Не найдено");
if(!isset($_POST['sub']))echo "<form action='tema.php?edit=$id' method='post'>
Название темы<br/><input type='text' name='name' value='$edit_tema[name]'><br/><input type='submit' name='sub' value='Переименовать'></form>";
else if(trim($_POST['name'])!= '' ){$name = mysql_real_escape_string(htmlspecialchars(trim($_POST['name'])));
if(mysql_query("UPDATE `sh_tem` SET `name`='$name' WHERE `id`='$id'"))echo "Тема переименована";
else echo mysql_error().'Ошибка';}
}
else if(isset($_GET['del']))
{$id=abs($_GET['del']); if(!$tema=mysql_fetch_array(mysql_query("SELECT * FROM `sh_tem` WHERE `id`='$id'")))die("Не найдено");
$postov_v_teme=mysql_num_rows(mysql_query("SELECT * FROM `sh_post` WHERE `tema`='$id'"));
$postov_v_cate=mysql_fetch_array(mysql_query("SELECT * FROM `sh_podcat` WHERE `id`='$tema[cat]'"));
$postov_v_forume=mysql_fetch_array(mysql_query("SELECT * FROM `sh_cat` WHERE `id`='$postov_v_cate[refid]'"));
$budet_v_cate=$postov_v_cate['post']-$postov_v_teme;
$budet_v_forume=$postov_v_forume['post']-$postov_v_teme;
$budet_v_forume2=$postov_v_forume['tem']-1;
if(mysql_query("DELETE FROM `sh_tem` WHERE `id`='$id'")){echo "Тема удалена"; mysql_query("UPDATE `sh_podcat` SET `post`='$budet_v_cate' WHERE `id`='$tema[cat]'");
mysql_query("UPDATE `sh_cat` SET `post`='$budet_v_forume', `tem`='$budet_v_forume2' WHERE `id`='$postov_v_cate[refid]'");}
}
else if(isset($_GET['close']))
{$id=$_GET['close']; if(!$tema=mysql_fetch_array(mysql_query("SELECT * FROM `sh_tem` WHERE `id`='$id'")))die("Не найдено");
if($tema['close']==0){if(mysql_query("UPDATE `sh_tem` SET `close`='1' WHERE `id`='$id'"))echo "Тема закрыта";}
else if($tema['close']==1){if(mysql_query("UPDATE `sh_tem` SET `close`='0' WHERE `id`='$id'"))echo "Тема открыта";}
}
else if(isset($_GET['up']))
{$id=(int)$_GET['up']; if(!$tema=mysql_fetch_array(mysql_query("SELECT * FROM `sh_tem` WHERE `id`='$id'")))die("Не найдено");
if($tema['up']==0){if(mysql_query("UPDATE `sh_tem` SET `up`='1' WHERE `id`='$id'"))echo "Тема прикреплена";}
else if($tema['up']==1){if(mysql_query("UPDATE `sh_tem` SET `up`='0' WHERE `id`='$id'"))echo "Тема откреплена";}}
echo "<br/><a href='index.php'>В админ-меню</a>";
include("../foot.php");?>