Просмотр файла tema.php

Размер файла: 2.72Kb
<? include("head.php");
if(!isset($_GET['id']))exit();
$id = (int)$_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>";
if($tema['close']==1)echo "(закрыто)";

$num = 10;@$page = (int)$_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'>";
if($page==1)echo "<ol>";
else {$abcdef=$page*$num-1;echo "<ol start='".$abcdef."'>";}
while($post=mysql_fetch_array($post_q)){echo "<li>";
$us_q=mysql_query("SELECT * FROM `sh_user` WHERE `id`='$post[avtor]'");
$user_avtor=mysql_fetch_array($us_q);
$date=date("ndHis"); 
$time=$user_avtor['time']; 
if ($time+45 > $date) $st_on = "<span style='color:green'>[ON]</span>"; 
else $st_on = "<span style='color:red'>[OFF]</span>";

if(mysql_num_rows($us_q)==0)echo "DELETED#$post[avtor]";
else echo "<a href='user.php?id=$post[avtor]'>$user_avtor[echologin]</a> $st_on";
$post['date']=str_replace(date("Y.m.d"), "Сегодня", $post['date']);
echo " [$post[date]]<br/>$post[text]</li><hr color='#CCCCCC'>";}
echo "</ol></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/>Сообщений нет<br/>";

if(isset($_SESSION['user_id']) and $_SESSION['user_id']!='' and $tema['close']==0)echo '<br/>Добавить сообщение<br/><form action="post-add.php" method="post"><input name="tema" type="hidden" value="'.$id.'" /><textarea name="text" cols="25" rows="4"></textarea><br/>
<input name="" type="submit" value="Написать" /></form>
<a href="/bb_code.php">BB коды</a> | <a href="/smiles.php">Смайлы</a>';

include("foot.php");?>