Файл: forum.php
Строк: 111
<?php
$title='Форум';include_once 'system/head.php';
switch($act){
case 'last_post':
echo'<div class="menu" style="text-align:center;"><a href="/forum.php?act=last_thread">Последние темы</a> | Последние сообщения</div>';
$sex = mysql_query ("select * from `posts` ORDER BY `id` DESC LIMIT $set[p_str]");
$total = mysql_result(mysql_query("select count(*) from `posts`"),0);
if($total>0){
while ($fex = mysql_fetch_array ($sex)){
$theme = mysql_fetch_array(mysql_query('SELECT * FROM `themes` WHERE `id`='.$fex[id_theme].''));
$avtor = mysql_fetch_array(mysql_query('SELECT * FROM `user` WHERE `id`='.$fex[author_id].''));
echo'<div class="menu">'.$fex['text'].'..<br />
В теме : <a href="/forum.php?act=theme&id='.$theme['id'].'&page=end">'.$theme['name'].'</a><br>
От кого : <a href="/profile'.$avtor['id'].'">'.$avtor['login'].'</a></div>';
}
}else{echo'<div class="menu">Постов еще нет</div>';}
back('/forum.php');
break;
case 'last_thread':
echo'<div class="menu" style="text-align:center;">Последние темы | <a href="/forum.php?act=last_post">Последние сообщения</div>';
$sex = mysql_query ("select * from `themes` ORDER BY `id` DESC LIMIT $set[p_str]");
$total = mysql_result(mysql_query("select count(*) from `themes`"),0);
if($total>0){
while ($fex = mysql_fetch_array ($sex)){
$avtor = mysql_fetch_array(mysql_query('SELECT * FROM `user` WHERE `id`='.$fex[author_id].''));
echo'<div class="menu">
<a href="/forum.php?act=theme&id='.$fex['id'].'">'.$fex['name'].'</a><br>
От кого : <a href="/profile'.$avtor['id'].'">'.$avtor['login'].'</a></div>';
}
}else{echo'<div class="menu">Тем еще нет</div>';}
back('/forum.php');
break;
case 'add_theme':
if($user){
$q=mysql_fetch_assoc(mysql_query("select * from `forum` where `id`='$id'"));
if($q){
echo '<div class="head">Создание темы</div><div class="menu">';
if(!empty($_POST['name']) and !empty($_POST['text'])){
$name=nl2br(smiles(bb_code(protect($_POST['name']))));
$text=nl2br(smiles(bb_code(protect($_POST['text']))));
$text2=strlen($text);
if($text2>6){
mysql_query("INSERT INTO `themes` SET `id_forum` = '$id',`name` = '$name',`author_id` = '$user[id]',`time`= '$time',`status`='1',`avtor`='$user[id]',`time_last`='$time'");
$new = mysql_insert_id();
mysql_query("INSERT INTO `posts` SET `id_theme` = '$new',`id_forum`='$id',`author_id` = '$user[id]',`text` = '$text',`time` = '$time'");
mysql_query("UPDATE `users` SET `posts`=posts+1, `balans`=balans+2 WHERE `id` = '$user[id]'");
echo 'Тема успешно создана -> <a href="/forum.php?act=theme&id='.$new.'">Далее</a>';
}else{echo'Слишком короткий текст';}
}else{
echo'<form action="#" method="post">
Название темы:<br /><input type="text" name="name"/><br />
Текст:<br /><textarea name="text"></textarea><br />
<input type="submit" value="Создать тему">
</form><a href="/info.php?mod=bb_code">BB коды</a> | <a href="/info.php?mod=smiles">Смайлы</a>';
}
echo'</div>';
back('/forum.php?act=forum&id='.$id);
}else{echo'<div class="menu">Ошибка идентификатора</div>';}
}else{echo'<div class="menu">Ошибка авторизации</div>';}
break;
case 'theme':
$q=mysql_fetch_assoc(mysql_query("select * from `themes` where `id`='$id'"));
if($q){
if(!empty($_POST['text'])){
if($user){
$text=nl2br(smiles(bb_code(protect($_POST['text']))));
if($q['status']>0 and $user){
if($time-$user['flood']>40){
mysql_query("INSERT INTO `posts` SET `id_theme` = '$id',`id_forum`= '$q[id_forum]',
`author_id` = '$user[id]',`text` = '$text',`time` = '".time()."',`status`='1' ");
mysql_query("update `themes` set `time_last`='$time' where `id`='$id'");
mysql_query("update `user` set `flood`='$time', `balans`=`balans`+1, `posts`=`posts`+1 where `id`='$user[id]'");
echo'<div class="menu">Сообщение добавлено -> <a href="/forum.php?act=theme&id='.$id.'&page=end">Далее</a></div>';
}else{echo'<div class="menu">Разрешено писать раз в 40 секунд</div>';}
}else{echo'<div class="menu">Ошибка</div>';}
}else{echo'<div class="menu">Ошибка авторизации</div>';}
}else{
$razd=mysql_fetch_array(mysql_query("select * from `forum` where `id`='$q[id_forum]'"));
echo'<div class="head"><a href="/forum.php">Форум</a> / <a href="/forum.php?act=forum&id='.$q['id_forum'].'">'.$razd['name'].'</a> / '.$q['name'].'</div>';
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `posts` WHERE `id_theme`='$id'"),0);
$k_page=k_page($k_post,$set['p_str']);$page=page($k_page);$start=$set['p_str']*$page-$set['p_str'];
$sql=mysql_query("select * from `posts` where `id_theme`='$id' order by `time` asc limit $start, $set[p_str]");
while($res=mysql_fetch_array($sql)){
$author = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$res[author_id]' "));
echo'<div class="menu">
<b>'.$start++.' <a href="/profile'.$res['author_id'].'">'.$author['login'].'</a> ['.$author['posts'].']</b>';
if($user['level']=='1')echo' <a href="/delete.php?act=9&id='.$res['id'].'">[x]</a> ';
if($user and $q['status']>0)
echo'<a onclick="document.getElementById('text').value=''.$author['login'].', '">[Отв]</a>';
#<a onclick="document.getElementById('text').value='[quote]От : '.$author[login].' | '.$res['text'].'[/quote] '">[Цит]</a>';
echo'<br /><small>'.clock($res['time']).'</small><br />
'.$res['text'].'</div>';
}
if($q['status']>0 and $user){
if(($time-$user['flood']>40)){
echo '<div class="menu">
<form action="#" method="POST">
Собщение: <br />
<textarea name="text" rows="3" cols="25" id="text"></textarea><br />
<input type="submit" value="Отправить" />
</form></div><div class="menu">
<a href="/info.php?mod=bb_code">BB коды</a> | <a href="/info.php?mod=smiles">Смайлы</a></div>
<div class="menu">
<input name="link" value="http://'.$_SERVER['HTTP_HOST'].'/forum/theme.php?id='.$id.'" type="text"/><br/>
</div>';
}else{echo'<div class="citatka">Чтобы написать, подождите '.(40-($time-$user['flood'])).' cek.</div>';}
}
if ($k_page>1){str('/forum.php?act=theme&id='.$id.'&',$k_page,$page);}
}
back('/forum.php?act=forum&id='.$q['id_forum']);
}else{echo'<div class="menu">Ошибка идентификатора</div>';}
break;
case 'forum':
$q=mysql_fetch_assoc(mysql_query("select * from `forum` where `id`='$id'"));
if($q){
echo'<div class="head"><a href="/forum.php">Форум</a> / '.$q['name'].'</div>';
$total = mysql_result(mysql_query("select count(*) from `themes` WHERE `id_forum`='$id'"),0);
if($total){
$k_page=k_page($total,$set['p_str']);$page=page($k_page);$start=$set['p_str']*$page-$set['p_str'];
$sql=mysql_query("select * from `themes` where `id_forum`='$id' order by `time_last` desc limit $start, $set[p_str]");
while($res=mysql_fetch_array($sql)){
$posts = mysql_num_rows(mysql_query("SELECT id FROM `posts` WHERE `id_theme` = '$res[id]'"));
$authors = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$res[avtor]' "));
echo '<div class="menu">'.$start++.'. <a href="/forum.php?act=theme&id='.$res['id'].'">'.$res['name'].'</a> ('.$posts.')';
if($user['level']=='1')echo' <a href="/delete.php?act=8&id='.$res['id'].'">[del]</a>';
echo'<br/><small>Автор - <a href="/profile'.$res['avtor'].'">'.$authors['login'].'</a></small></div>';
}
if ($k_page>1)str('/forum.php?act=forum&id='.$id.'&',$k_page,$page); // Вывод страниц
}else{echo'<div class="menu">Темы еще не созданы</div>';}
echo'<div class="menu"><a href="?act=add_theme&id='.$id.'" style="display:block;">Создать тему</a></div>';
back('/forum.php');
}else{echo'<div clas="menu">Ошибка идентификатора</div>';}
break;
default:
echo'<div class="menu" style="text-align:center;"><a href="/forum.php?act=last_thread">Последние темы</a> | <a href="/forum.php?act=last_post">Последние сообщения</a></div>';
$total=mysql_num_rows(mysql_query("select * from `razdel`"));
if($total){
$sql=mysql_query("select * from `razdel` order by `id`");
while($res=mysql_fetch_assoc($sql)){
echo'<div class="menu"><b>'.$res['name'].'</b><br />';
$sql1=mysql_query("select * from `forum` where `razdel`='$res[id]'");
while($res1=mysql_fetch_assoc($sql1)){
echo'<a href="/forum.php?act=forum&id='.$res1['id'].'" style="margin:3%;text-align:center;">- '.$res1['name'].'</a><span style="float:right;">['.mysql_num_rows(mysql_query("SELECT id FROM `themes` WHERE `id_forum`='$res1[id]'")).'/'.mysql_num_rows(mysql_query("SELECT id FROM `posts` WHERE `id_forum`='$res1[id]'")).']</span><br />';
}
echo'</div>';
}
}else{echo'<div class="menu">Разделов еще нет</div>';}
if($user['level']>0)echo'<div class="menu"><a href="/index.php?mode=admin&fid=set_for" style="display:block;text-align:center;">Управление форумом</a></div>';
back('/');
}
require_once 'system/foot.php';
?>