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

	if	($mode=='delete')
	{
		User::checkToken();
		Db::i()->query("DELETE FROM ?_ad_rotator_values WHERE id=?", $_GET['var1']);
		refresh();
	}
	
	if	($mode=='toggle')
	{
		User::checkToken();
		Db::i()->query("UPDATE ?_ad_rotator_values SET active=1-active WHERE 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_values (place_id, value_name, value) VALUES(?, ?, ?)", $_GET['var1'], $_POST['name'], $_POST['var']);
			}
			elseif($mode=='edit')
			{
				Db::i()->query("UPDATE ?_ad_rotator_values SET value_name=?, value=? WHERE id=?", $_POST['name'], $_POST['var'], $_GET['var1']);
			}
			refresh();
		}
	}
	
	if ($mode=='edit' && $_SERVER['REQUEST_METHOD']=='GET')
	{
		Tpl::i()->assign('var', Db::i()->selectRow("SELECT id, place_id, value_name, value, rate, active FROM ?_ad_rotator_values WHERE id=?", $_GET['var1']));
	}
	
	