<?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.tpl";

if ($_SERVER['REQUEST_METHOD']=='POST')
{
	User::checkToken();
	if (!trim($_POST['name']))
	{
		LabCMS::i()->error("Введите название блока");
	}

	if (LabCMS::i()->no_errors)
	{
		if ($mode=="edit")
		{
			Db::i()->query("UPDATE ?_blocks_static SET name=?, `data`=? WHERE block_id=?", $_POST['name'], $_POST['data'], $_GET['var1']);
		}
		elseif($mode=="add")
		{
			Db::i()->query("INSERT INTO ?_blocks_static (name, `data`, visible) VALUES(? ,? ,1)", $_POST['name'], $_POST['data']);
		}
		LabCMS::i()->reset_cache('all');
		refresh();
	}
}

if ($mode=='edit')	Tpl::i()->assign(Db::i()->selectRow("SELECT block_id, name, `data` FROM ?_blocks_static WHERE block_id=?", $_GET['var1']));

if ($mode=='toggle')
{
	User::checkToken();
	Db::i()->query("UPDATE ?_blocks_static SET visible=1-visible WHERE block_id=?", $_GET['var1']);
	LabCMS::i()->reset_cache('all');
	refresh();
}

if ($mode=='delete')
{
	User::checkToken();
	Db::i()->query("DELETE FROM ?_blocks_static WHERE block_id=?", $_GET['var1']);
	LabCMS::i()->reset_cache('all');
	refresh();
}
