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

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

$title = 'Форум';
require_once 'system/sys.php';
require_once 'system/header.php';

switch ($_GET['act']) {
	default:
		tp('Форум');
		$cats_r = mysql_query("SELECT `id`, `name` FROM `forum_cats` ORDER BY `order`");
		if (mysql_num_rows($cats_r)) {
			while ($cat = mysql_fetch_assoc($cats_r)) {
				$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 '<a href="?act=cat&amp;id='.$cat['id'].'">'.$cat['name'].'</a> ('.$f_topics.'/'.$f_msg.')<br />';
			}
		} else {
			echo 'Разделы не созданы.';
		}
		nav_main();
	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('<a href="?">Форум</a> &gt; '.$cat['name']);
			$subcats_r = mysql_query("SELECT `id`, `name` FROM `forum_subcats` WHERE `id_cat` = '$id' ORDER BY `order`");
			if (mysql_num_rows($subcats_r)) {
				while ($subcat = mysql_fetch_assoc($subcats_r)) {
					$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 '<a href="?act=subcat&amp;id='.$subcat['id'].'">'.$subcat['name'].'</a> ('.$f_topics.'/'.$f_msg.')<br />';
				}
			} else {
				echo 'Подразделы не созданы.';
			}
			nav('?');
		} else {
			error('Выбранный раздел не существует.');
			nav('?');
		}
	break;
			
	case 'subcat':
		$id = intval($_REQUEST['id']);
		$subcat = mysql_fetch_assoc(mysql_query("SELECT `id_cat`, `name` FROM `forum_subcats` WHERE `id` = '$id'"));
		if ($subcat['name']) {
			$cat = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `forum_cats` WHERE `id` = '$subcat[id_cat]'"));
			tp('<a href="?">Форум</a> &gt; <a href="?act=cat&amp;id='.$subcat['id_cat'].'">'.$cat['name'].'</a> &gt; '.$subcat['name']);
			$count_topics = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `id_subcat` = '$id'"), 0);
			if ($count_topics > 0) {
				$pages = ceil($count_topics/$config['onpage']);
				if (intval($_REQUEST['p'])) {
					$page = intval($_REQUEST['p']);
				} else {
					$page = 1;
				}
				$from = ($page-1)*$config['onpage'];
				
				$topics_r = mysql_query("SELECT * FROM `forum_topics` WHERE `id_subcat` = '$id' ORDER BY `stuck` DESC, `last_time` DESC LIMIT $from, $config[onpage]");
				while ($topic = mysql_fetch_assoc($topics_r)) {
				
				if ($topic['stuck']) echo '!';
				if ($topic['closed'] == 1 and empty($topic['stuck'])) echo '#';
				$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']);
				echo '<a href="?act=topic&amp;id='.$topic['id'].'">'.$topic['title'].'</a> ('.$t_msg.') '.login($topic['id_user']).'<a href="?act=topic&amp;id='.$topic['id'].'&amp;p='.$last_page.'">&raquo;</a><br />';
				}
				
			} else {
				echo 'В этом подразделе нет тем.<br />';
			}
			echo '<br /><form action="?act=topic_add&amp;id='.$id.'" method="post">
			<input name="" type="submit" value="Создать тему">
			</form>
			</div>';
			navig($page, '?act=subcat&amp;id='.$id.'&amp;', $pages);
			nav2('?act=cat&amp;id='.$subcat['id_cat'], $cat['name']);
		} else {
			header('location: ?');
		}			
	break;
	
	case 'topic':
		$id = intval($_REQUEST['id']);
		$topic = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topics` WHERE `id` = '$id'"));
		if ($topic['id']) {
			echo '<div class="s1">'.$topic['title'].'</div><div class="list">';
			$count_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_topic` = '$id'"), 0);
			$pages = ceil($count_msg/$config['onpage']);
			if (intval($_REQUEST['p'])) {
				$page = intval($_REQUEST['p']);
			} else {
				$page = 1;
			}
			$from = ($page-1)*$config['onpage'];
				
			$msg_r = mysql_query("SELECT * FROM `forum_msg` WHERE `id_topic` = '$id' ORDER BY `time` LIMIT $from, $config[onpage]");
			while ($msg = mysql_fetch_assoc($msg_r)) {
				if (!isset($num) ) $num = 1;  
				$num++;
				$row_class = (!($num % 2)) ? 'row1' : 'row2';	
				echo '<div class="'.$row_class.'">
				
				<a href="profile.php?id='.$msg['id_user'].'">'.login($msg['id_user']).'</a> '.online(date('d.m.y, H:i', $msg['time']), $msg['id_user']).' <a href="?act=reply&amp;id='.$msg['id'].'">Отв</a>';
				if ($u['access'] > 0 or $u['id'] == $msg['id_user'] and time() - $msg['time'] < $config['edit_time']) echo '|<a href="?act=edit&amp;id='.$msg['id'].'">Ред</a>';
				if ($u['access'] > 0) echo '|<a href="?act=del&amp;id='.$msg['id'].'">Уд</a>';
				echo '<br />'.bb($msg['text']);
				if ($msg['edit_by']) echo '<br />_______<br /><span style="font-size: 10px;">отредактировано: '.login_simple($msg['edit_by']).' ('.date('d.m.y, H:i', $msg['edit_time']).' )</span>';
				echo '</div>';
			}
			navig($page, '?act=topic&amp;id='.$id.'&amp;', $pages);
			echo '</div>';
			if ($u['id']) {
				echo '<div class="s2">Добавить(max500):<br />
				<form action="?act=msg_add&amp;id='.$id.'" method="post">
				<textarea name="text" cols="" rows="3"></textarea>';
				echo '<input name="" type="submit" value="Ok">
				</form>
				</div>';
			}
			$subcat = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `forum_subcats` WHERE `id` = '$topic[id_subcat]'"));
			nav2('?act=subcat&amp;id='.$topic['id_subcat'], $subcat['name']);
		} else {
			header('location: ?');
		}
	break;
	
	case 'topic_add':
		if ($u['id']) {
			$id = intval($_REQUEST['id']);
			$subcat = mysql_fetch_assoc(mysql_query("SELECT `id_cat`, `name` FROM `forum_subcats` WHERE `id` = '$id'"));
			if ($subcat['id_cat']) {
				if (time() > $_SESSION['antispam']) {
					if ($_REQUEST['ok']) {
						if ($_POST['title'] and $_POST['text']) {
							mb_internal_encoding('UTF-8');
							if (mb_strlen($_POST['text']) <= 750) {
								$title = check($_POST['title']);
								$text = check($_POST['text']);
								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()."'");
								mysql_query("UPDATE `users` SET `karma` = (karma+1) WHERE `id` = '$u[id]'");
								$_SESSION['antispam'] = time() + $config['antispam'];
								header('location: ?act=topic&id='.$id_topic);
							} else {
								error('Слишком длинный текст.');
								nav('?act=topic_add&amp;id='.$id);
							}
						} else {
							error('Вы не заполнили поля.');
							nav('?act=topic_add&amp;id='.$id);
						}
					} else {
						tp('Создать тему');
						echo '<form action="?act=topic_add&amp;id='.$id.'&amp;ok=1" method="post">
						Заголовок(max50):<br /><input name="title" type="text" maxlength="50" /><br />
						Сообщение(max750):<br /><textarea name="text" cols="" rows="4"></textarea>
						<input name="submit" type="submit" value="Ok" />
						</form>';
						nav2('?act=subcat&amp;id='.$id, $subcat['name']);
					}
				} else {
					error('Антиспам. Разрешено пиcать раз в '.$config['antispam'].' сек.');
					nav2('?act=subcat&amp;id='.$id, $subcat['name']);
				}
			}
		} else {
			header('location: login.php');
		}
	break;
	
	case 'msg_add':
		if ($u['id']) {
			$id = intval($_REQUEST['id']);
			$topic = mysql_fetch_assoc(mysql_query("SELECT `id_cat`, `id_subcat` FROM `forum_topics` WHERE `id` = '$id'"));
			if ($topic['id_cat']) {
				if (time() > $_SESSION['antispam']) {
					if ($_POST['text']) {
						$text = check($_POST['text']);
						mysql_query("INSERT INTO `forum_msg` SET `id_cat` = '$topic[id_cat]', `id_subcat` = '$topic[id_subcat]', `id_topic` = '$id', `id_user` = '$u[id]', `text` = '$text', `time` = '".time()."'");
						mysql_query("UPDATE `users` SET `karma` = (karma+1) WHERE `id` = '$u[id]'");
						$_SESSION['antispam'] = time() + $config['antispam'];
						$t_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_topic` = '$id'"), 0);
						$last_page = ceil($t_msg/$config['onpage']);
						header('location: ?act=topic&id='.$id.'&p='.$last_page);
					} else {
						error('Вы не заполнили поля.');
						nav('?act=topic&amp;id='.$id);
					}
				} else {
					error('Антиспам. Разрешено пиcать раз в '.$config['antispam'].' сек.');
					nav('?act=topic&amp;id='.$id);
				}
			} else {
				header('location: ?');
			}
		} else {
			header('location: login.php');
		}
	break;
	
	case 'msg_reply':
	 //
	break;
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
		
}

require_once 'system/tail.php';
?>