Просмотр файла forum/index.php

Размер файла: 12.48Kb
<?php 
// by mides, wmclub.mobi

$title = 'Форум';
require('../config.php');
require('../includes/sys.php');
require('../includes/start.php');
require('../includes/header.php');

switch($_GET['act']){

###############################################################################
##                           Главная страница                                ##
###############################################################################
default:

tp('Форум');

$result_cats = mysql_query("SELECT * FROM `forum_cats` ORDER BY `order`");
while($cat = mysql_fetch_assoc($result_cats)){
	$f_topics = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `id_cat` = '$cat[id]'"), 0);
	$f_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_cat` = '$cat[id]'"), 0);
	echo '<img src="../images/forumcat.gif" alt="forum" /> <a href="index.php?act=cat&amp;id='.$cat['id'].'">'.$cat['name'].'</a> ('.$f_topics.'/'.$f_msg.')<br/>';
}
echo '<hr />
	<img src="../images/newposts.png" alt="newposts.png" /> <a href="index.php?act=newposts">Новые сообщения</a><br />
	<img src="../images/home.gif" alt="home.gif" /> <a href="../">На главную</a>
	</div>';

break;

###############################################################################
##                        Просмотр выбранного раздела                        ##
###############################################################################
case 'cat':

$id = intval($_REQUEST['id']);
$cat = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `forum_cats` WHERE `id` = '$id'"));
if($cat['name']){
	tp($cat['name']);
	$r_subcats = mysql_query("SELECT * FROM `forum_subcats` WHERE `id_cat` = '$id' ORDER BY `order`");
	if(mysql_num_rows($r_subcats)){
		while($subcat = mysql_fetch_assoc($r_subcats)){
			$f_topics = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `id_subcat` = '$subcat[id]'"), 0);
			$f_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_subcat` = '$subcat[id]'"), 0);
			echo '<img src="../images/forum_subcat.gif" alt=""> <a href="index.php?act=subcat&amp;id='.$subcat['id'].'">'.$subcat['name'].'</a> ('.$f_topics.'/'.$f_msg.')<br />';
		}
	}else{
		echo 'Подразделы еще не созданы!';
	}
}else{
	error('Раздел не существует!');
}
nav('?');

break;

###############################################################################
##                       Просмотр выбранного подраздела                      ##
###############################################################################
case 'subcat':

$id = intval($_REQUEST['id']);
$subcat = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_subcats` WHERE `id` = '$id'"));
if($subcat['id']){
	tp($subcat['name']);
	$all_topics = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `id_subcat` = '$subcat[id]'"), 0);
	if($all_topics > 0){
		$pages = ceil($all_topics/$config['onpage']);
		if(intval($_REQUEST['page'])){
			$page = intval($_REQUEST['page']);
		}else{
			$page = 1;
		}
		$from = ($page-1)*$config['onpage'];
		
		$r_topics = mysql_query("SELECT `id`, `title`, `stuck`, `closed` FROM `forum_topics` WHERE `id_subcat` = '$subcat[id]' ORDER BY `last_time` DESC LIMIT $from, $config[onpage]");
		while($topic = mysql_fetch_assoc($r_topics)){
			$t_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_topic` = '$topic[id]'"), 0);
			if($topic['stuck'] == 1){
				echo '!';
			}elseif($topic['closed'] == 1){
				echo '#';
			}
			$last_id_user = mysql_fetch_assoc(mysql_query("SELECT `id_user` FROM `forum_msg` WHERE `id_topic` = '$topic[id]' ORDER BY `time` DESC LIMIT 1"));
			$last_page = ceil($t_msg/$config['onpage']);
			echo '<img src="../images/ftopic.png" alt="ftopic.png" /> <a href="topic.php?id='.$topic['id'].'">'.$topic['title'].'</a> ('.$t_msg.') '.login($last_id_user['id_user']).'<a href="topic.php?id='.$topic['id'].'&amp;page='.$last_page.'">&raquo;</a><br />';
		}
	}else{
		echo 'Тем пока нет :(<br />';
	}
	
	if($u['id']){
		echo '<br />';
		echo '<a href="?act=topic_add&amp;id='.$id.'" class="button">Создать тему</a><br />';
	}
	
	echo '<hr />';
	
	navig($page, '?act=cat&amp;id='.$cat['id'].'&amp;', $pages);
	echo '<a href="?act=cat&amp;id='.$subcat['id_cat'].'">Назад</a><br />
		 <a href="../">На главную</a><br />
		 </div>';
}else{
	error('Выбранный раздел не существует!');
	nav('?');
}

break;

###############################################################################
##                        Форма создания новой темы                          ##
###############################################################################
case 'topic_add':

if($u['id']){
	if($_SESSION['spam'] < time()){
		$id = intval($_REQUEST['id']);
		$subcat = mysql_fetch_assoc(mysql_query("SELECT `id_cat` FROM `forum_subcats` WHERE `id` = '$id'"));
		if($subcat['id_cat']){
			tp('Начать новую тему');
			echo '<form action="?act=topic_add_do&amp;id='.$id.'" method="post" name="form">
				 Заголовок(max50):<br /><input name="title" type="text" maxlength="50" /><br />
				 Сообщение(max1000):<br /><textarea name="text" cols="" rows="5"></textarea><br />';
			if($u['user_access'] > 1){
				echo '<input name="stuck" type="checkbox" value="1" /> Закрепить<br />
					 <input name="closed" type="checkbox" value="1" /> Закрыть<br />';
			}
			echo '<input name="submit" type="submit" value="Ok" />
				 </form>';
			nav('?act=subcat&amp;id='.$id);
		}else{
			error('Подраздел не существует!');
			nav('?');
		}
	}else{
		error('Вы не можете писать чаще, чем раз в '.$config['antispam'].' сек.!');
		nav('?act=subcat&amp;id='.$id);
	}
}else{
	error('Вы не <a href="../pages/login.php">авторизованы</a> для создания новой темы :(');
	nav('?act=subcat&amp;id='.$id);
}

break;

###############################################################################
##                           Создание новой темы                             ##
###############################################################################
case 'topic_add_do':

$id = intval($_REQUEST['id']);

if($u['id']){
	if($_SESSION['spam'] < time()){
		$subcat = mysql_fetch_assoc(mysql_query("SELECT `id_cat` FROM `forum_subcats` WHERE `id` = '$id'"));
		if($subcat['id_cat']){
			if(!empty($_POST['title']) and !empty($_POST['text'])){
				$title = check($_POST['title']);
				$text = check($_POST['text']);
				mb_internal_encoding('UTF-8');
				if(mb_strlen($text) <= 1000){
					$stuck = intval($_POST['stuck']);
					$closed = intval($_POST['closed']);
					mysql_query("INSERT INTO `forum_topics` SET `id_cat` = '$subcat[id_cat]', `id_subcat` = '$id', `title` = '$title', `id_user` = '$u[id]', `last_time` = '".time()."', `stuck` = '$stuck', `closed` = '$closed'");
					$id_topic = mysql_insert_id();
					mysql_query("INSERT INTO `forum_msg` SET `id_cat` = '$subcat[id_cat]', `id_subcat` = '$id', `id_topic` = '$id_topic', `id_user` = '$u[id]', `text` = '$text', `time` = '".time()."'") or die(mysql_error());
					mysql_query("UPDATE `users` SET `user_points` = (user_points+2) WHERE `id` = '$u[id]'");
					$_SESSION['spam'] = $config['antispam'] + time();
					info('Тема успешно создана!');
					nav('topic.php?id='.$id_topic);
					echo '<meta http-equiv="refresh" content="0;URL=topic.php?id='.$id_topic.'" />';
				}else{
					error('Текст не может содержать больше 1000 символов!');
					nav('?act=topic_add&amp;id='.$id);
				}
			}else{
				error('Вы не заполнили поля!');
				nav('?act=topic_add&amp;id='.$id);
			}
		}else{
			error('Подраздел не существует!');
			nav('?');
		}
	}else{
		error('Вы не можете писать чаще, чем раз в '.$config['antispam'].' сек.!');
		nav('?act=subcat&amp;id='.$id);
	}
}else{
	error('Вы не <a href="../pages/login.php">авторизованы</a> для создания новой темы :(');
	nav('?act=subcat&amp;id='.$id);
}

break;

###############################################################################
##                       Просмотр выбранного подраздела                      ##
###############################################################################
case 'subcat':

$id = intval($_REQUEST['id']);
$subcat = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_subcats` WHERE `id` = '$id'"));
if($subcat['id']){
	tp($subcat['name']);
	$all_topics = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `id_subcat` = '$subcat[id]'"), 0);
	if($all_topics > 0){
		$pages = ceil($all_topics/$config['onpage']);
		if(intval($_REQUEST['page'])){
			$page = intval($_REQUEST['page']);
		}else{
			$page = 1;
		}
		$from = ($page-1)*$config['onpage'];
		
		$r_topics = mysql_query("SELECT `id`, `title`, `stuck`, `closed` FROM `forum_topics` WHERE `id_subcat` = '$subcat[id]' ORDER BY `last_time` DESC LIMIT $from, $config[onpage]");
		while($topic = mysql_fetch_assoc($r_topics)){
			$t_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_topic` = '$topic[id]'"), 0);
			if($topic['stuck'] == 1){
				echo '!';
			}elseif($topic['closed'] == 1){
				echo '#';
			}
			$last_id_user = mysql_fetch_assoc(mysql_query("SELECT `id_user` FROM `forum_msg` WHERE `id_topic` = '$topic[id]' ORDER BY `time` DESC LIMIT 1"));
			$last_page = ceil($t_msg/$config['onpage']);
			echo '<a href="topic.php?id='.$topic['id'].'">'.$topic['title'].'</a> ('.$t_msg.') '.login($last_id_user['id_user']).'<a href="topic.php?id='.$topic['id'].'&amp;page='.$last_page.'">&raquo;</a><br />';
		}
	}else{
		echo 'Тем пока нет :(<br />';
	}
	
	if($u['id']){
		echo '<br />';
		echo '<a href="?act=topic_add&amp;id='.$id.'" class="button">Создать тему</a><br />';
	}
	
	echo '<hr />';
	
	navig($page, '?act=cat&amp;id='.$cat['id'].'&amp;', $pages);
	echo '<a href="?act=cat&amp;id='.$subcat['id_cat'].'">Назад</a><br />
		 <a href="../">На главную</a><br />
		 </div>';
}else{
	error('Выбранный раздел не существует!');
	nav('?');
}

break;

###############################################################################
##                               Новые сообщения                             ##
###############################################################################
case 'newposts':

$all_topics = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `last_time` > '".(time()-43200)."'"), 0);
if($all_topics > 0){
	$pages = ceil($all_topics/$config['onpage']);
	if(intval($_REQUEST['page'])){
		$page = intval($_REQUEST['page']);
	}else{
		$page = 1;
	}
	$from = ($page-1)*$config['onpage'];
	
	tp('Новые сообщения за 12 часов');
	$r_topics = mysql_query("SELECT `id`, `id_subcat`, `title`, `last_time` FROM `forum_topics` WHERE `last_time` > '".(time()-43200)."' ORDER BY `last_time` DESC LIMIT $from, $config[onpage]");
	while($topic = mysql_fetch_assoc($r_topics)){
		$last_id_user = mysql_fetch_assoc(mysql_query("SELECT `id_user` FROM `forum_msg` WHERE `id_topic` = '$topic[id]' ORDER BY `time` DESC LIMIT 1"));
		$t_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_topic` = '$topic[id]'"), 0);
		$last_page = ceil($t_msg/$config['onpage']);
		$subcat = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `forum_subcats` WHERE `id` = '$topic[id_subcat]'"));
		echo '<a href="?act=subcat&amp;id='.$topic['id_subcat'].'">'.$subcat['name'].'</a>&gt;<a href="topic.php?id='.$topic['id'].'">'.$topic['title'].'</a> ('.login($last_id_user['id_user']).' <a href="topic.php?id='.$topic['id'].'&amp;page='.$last_page.'">&raquo;</a>, '.date('d.m, H:i', $topic['last_time']).')<br />';
	}
	
	echo '<hr />';
	
	navig($page, '?act=newposts&amp;', $pages);
	echo '<a href="?">Назад</a><br />
		 <a href="../">На главную</a><br />
		 </div>';
}else{
	error('Новых сообщений пока нет :(');
	nav('?');
}

break;





































}

require('../includes/tail.php');
?>