<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
$mod_template="edit_forum.tpl";
if ($_SERVER['REQUEST_METHOD']=="POST")
{
	User::checkToken();
	$forum_name=trim($_POST['forum_name']);
	if (!$forum_name)
	{
		LabCMS::i()->error("Не введено название форума");
	}
	if (LabCMS::i()->no_errors)
	{
		$query=array('forum_name'=>$forum_name,
					'descr'=>$_POST['descr'],
					'closed'=>($_POST['closed']?1:0));
		if ($mode=="new")
		{
			Db::i()->query("INSERT INTO ?_forum_forums SET ?a", $query);
			refresh();
		}
		elseif($mode=="edit")
		{
			Db::i()->query("UPDATE ?_forum_forums SET ?a WHERE forum_id=?", $query, $forum_info['forum_id']);
			refresh();
		}
	}
}
elseif ($mode=="edit")
{
	Tpl::i()->assign(array('forum_name'=>$forum_info['forum_name'],'descr'=>$forum_info['descr'],'closed'=>$forum_info['closed']));
}
elseif ($mode=="delete")
{
	User::checkToken();
	Db::i()->query("DELETE ff, ft, fp FROM ?_forum_forums ff LEFT JOIN ?_forum_themes ft ON ff.forum_id=ft.forum_id LEFT JOIN ?_forum_posts fp ON ft.theme_id=fp.theme_id WHERE ff.forum_id=?", $forum_info['forum_id']);
	refresh();
}
