<?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_version.tpl";
	
	if ($_SERVER['REQUEST_METHOD']=='POST')
	{
		User::checkToken();
		if(!trim($_POST['version'])) LabCMS::i()->error("Версия не может быть пустой");
		
		if (LabCMS::i()->no_errors)
		{
			if ($mode=='edit') Db::i()->query("UPDATE ?_bt_versions SET version=? WHERE version_id=?", $_POST['version'], $_GET['var1']);
			if ($mode=='add') Db::i()->query("INSERT INTO ?_bt_versions (version, project_id) VALUES(?, ?)", $_POST['version'], $project_id);
			refresh('', LabCMS::i()->url(false, 'versions'));
		}
	}
	
	if ($mode=='edit') Tpl::i()->assign('version', Db::i()->selectCell("SELECT version FROM ?_bt_versions WHERE version_id=?", $_GET['var1']));
	
	if ($mode=='delete')
	{
		User::checkToken();
		if (!Db::i()->selectCell("SELECT COUNT(bug_id) FROM ?_bt_bugs WHERE version_id=?", $_GET['var1']))
		{
			Db::i()->query("DELETE FROM ?_bt_versions WHERE version_id=?", $_GET['var1']);
			refresh('', LabCMS::i()->url(false, 'versions'));
		}
		else return LabCMS::i()->error("Для этой версии существуют записи");
	}