View file panel/forum.php

File size: 5.08Kb
<?php
// by mides, 1da.su

require_once '../system/sys.php';
require_once '../system/auth_a.php';
require_once '../system/header.php';

if ($u['access'] < 2) header('location: ../');

switch ($act) {
	default:
		tp('Форум');
		$cats_r = mysql_query("SELECT * FROM `forum_cats` ORDER BY `order`, `name`");
		while ($cat = mysql_fetch_assoc($cats_r)) {
			echo '<a href="../forum.php?act=cat&amp;id='.$cat['id'].'">'.$cat['name'].'</a> (<a href="?act=cat_edit&amp;id='.$cat['id'].'">ред</a>)<br />';
			$subcats_r = mysql_query("SELECT * FROM `forum_subcats` WHERE `id_cat` = '$cat[id]' ORDER BY `order`, `name`");
			while ($subcat = mysql_fetch_assoc($subcats_r)) {
				echo '- <a href="../forum.php?act=subcat&amp;id='.$subcat['id'].'">'.$subcat['name'].'</a> (<a href="?act=subcat_edit&amp;id='.$subcat['id'].'">ред</a>)<br />';
			}
		}
		echo '<br/>
		<form action="?act=cat_add" method="post" name="form">
		<select name="cat">
		<option value="0">Главная</option>';
		$cats_r = mysql_query("SELECT * FROM `forum_cats` ORDER BY `order`");
		while ($cat = mysql_fetch_assoc($cats_r)) {
			echo '<option value="'.$cat['id'].'">'.$cat['name'].'</option>';	
		}
		echo '</select><br />
		Название (под)раздела:<br/><input name="name" type="text" maxlength="50" /><br />
		<input name="submit" type="submit" value="Добавить"></form>';
		nav('./');
	break;
	
	case 'cat_add':
		if ($_POST['name']) {
			$cat = intval($_POST['cat']);
			$name = check($_POST['name']);
			if ($cat > 0) {
				mysql_query("INSERT INTO `forum_subcats` SET `id_cat` = '$cat', `name` = '$name'");
			} else {
				mysql_query("INSERT INTO `forum_cats` SET `name` = '$name'");
			}
		}
		header('location: ?');
	break;
	
	case 'cat_edit':
		$id = abs(intval($_GET['id']));
		$cat = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_cats` WHERE `id` = '$id'"));
		if ($cat['id']) {
			if ($_GET['ok']) {
				if ($_POST['del']) {
					// we need to make sure we don't have any subcats belonging to our cat
					$forum_subcat_r = mysql_query("SELECT `id` FROM `forum_subcats` WHERE `id_cat` = '$id'");
					if (!mysql_num_rows($forum_subcat_r)) {
						mysql_query("DELETE FROM `forum_cats` WHERE `id` = '$id'");
						header('location: ?');
						exit;
					} else {
						error('Удалите все подразделы принадлежащие этому разделу.');
					}
				} else {
					if ($_POST['name']) {
						$name = check($_POST['name']);
						mysql_query("UPDATE `forum_cats` SET `name` = '$name' WHERE `id` = '$id'");
						header('location: ?');
						exit;
					} else {
						header('location: ?act=cat_edit&id='.$id);
						exit;
					}
				}
			} else {
				tp('Редактировать подраздел');
				echo '<form action="?act=cat_edit&amp;id='.$id.'&amp;ok=1" method="post">
				Название:<br /><input name="name" type="text" maxlength="50" value="'.$cat['name'].'" /><br />
				<input name="del" type="checkbox" value="1" /> удалить (если есть подразделы, то сначала их нужно удалить)<br />
				<input name="submit" type="submit" value="Ok" />
				</form>';
			}
		} else {
			error('Раздел не существует.');
		}
		nav('?');
	break;
		
	case 'subcat_edit':
		$id = abs(intval($_GET['id']));
		$subcat = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_subcats` WHERE `id` = '$id'"));
		if ($subcat['id']) {
			if ($_GET['ok']) {
				if ($_POST['del']) {
					// we need to delete everything that belongs to our subcat
					
					$forum_msg_r = mysql_query("SELECT `id` FROM `forum_msg` WHERE `id_subcat` = '$id'");
					while ($forum_msg = mysql_fetch_assoc($forum_msg_r) ) {
						mysql_query("DELETE FROM `voting` WHERE `type` = 'forum' and `id_for` = '$forum_msg[id]'");
					}
					
					mysql_query("DELETE FROM `forum_topics` WHERE `id_subcat` = '$id'");
					mysql_query("DELETE FROM `forum_msg` WHERE `id_subcat` = '$id'");
					mysql_query("DELETE FROM `forum_subcats` WHERE `id` = '$id'");
					
					header('location: ?');
					exit;
				} else {
					if ($_POST['name']) {
						$name = check($_POST['name']);
						mysql_query("UPDATE `forum_subcats` SET `name` = '$name' WHERE `id` = '$id'");
						header('location: ?');
						exit;
					} else {
						header('location: ?act=subcat_edit&id='.$id);
						exit;
					}
				}
			} else {
				tp('Редактировать подраздел');
				echo '<form action="?act=subcat_edit&amp;id='.$id.'&amp;ok=1" method="post">
				Название:<br /><input name="name" type="text" maxlength="50" value="'.$subcat['name'].'" /><br />
				<input name="del" type="checkbox" value="1" /> удалить (все сообщения, темы в этом подразделе будут <b>удалены</b>)<br />
				<input name="submit" type="submit" value="Ok" />
				</form>';
			}
		} else {
			error('Раздел не существует.');
		}
		nav('?');
	break;
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}

require_once '../system/tail_p.php';
?>