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

	if	($mode=='delete')
	{
		User::checkToken();
		Db::i()->query("DELETE p, v FROM ?_ad_rotator_places p LEFT JOIN ?_ad_rotator_values v ON p.place_id=v.place_id WHERE p.place_id=?", $_GET['var1']);
		refresh();
	}
	
	if	($mode=='toggle')
	{
		User::checkToken();
		Db::i()->query("UPDATE ?_ad_rotator_places SET active=1-active WHERE place_id=?", $_GET['var1']);
		refresh();
	}

	if ($_SERVER['REQUEST_METHOD']=='POST')
	{
		User::checkToken();
		if (!trim($_POST['name'])) LabCMS::i()->error("Название места не может быть пустым");
		
		if (LabCMS::i()->no_errors)
		{
			if ($mode=='add')
			{
				Db::i()->query("INSERT INTO ?_ad_rotator_places (name, `describe`) VALUES(? ,?)", $_POST['name'], $_POST['describe']);
			}
			elseif($mode=='edit')
			{
				Db::i()->query("UPDATE ?_ad_rotator_places SET name=?, `describe`=? WHERE place_id=?", $_POST['name'], $_POST['describe'], $_GET['var1']);
			}
			refresh();
		}
	}
	
	if ($mode=='edit' && $_SERVER['REQUEST_METHOD']=='GET')
	{
		Tpl::i()->assign('place', Db::i()->selectRow("SELECT place_id, name, `describe`, active FROM ?_ad_rotator_places WHERE place_id=?", $_GET['var1']));
	}
	
	