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

	$form = new HTML_QuickForm2('', 'post', array('action'=>''));
	
	$name=$form->addElement('text', 'name', null, array('label' => 'Название модуля:'));
	$name->addRule('nonempty', 'Название модуля не может быть пустым');
	$form->addElement('checkbox', 'static', null, array('label' => 'Статичный:', 'content'=>''));
	$form->addElement('hidden', 'token', array('value'=>User::i()->token));
	$form->addElement('submit', '', array('value'=>'Сохранить'));
	
	if ($form->validate())
	{
		User::checkToken();
		$query=array(	'name' => $_POST["name"],
						'static'=>($_POST["static"] ? 1 : 0));
		Db::i()->query("UPDATE ?_modules SET ?a WHERE module_id=?;", $query, $_GET['var1']);
		LabCMS::i()->reset_cache('all');
		refresh();
	}
	
	$module_info=Db::i()->selectRow("SELECT name, static, component, module FROM ?_modules WHERE module_id=?", $_GET['var1']);

	addBreadcrumb($module_info['name'], _url($module_info['module'], 'info'));
	addBreadcrumb("Редактирование модуля");

	$form->addDataSource(new HTML_QuickForm2_DataSource_Array($module_info));

	$renderer = HTML_QuickForm2_Renderer::factory('labsmarty');
	Tpl::i()->assign('form', $form->render($renderer)->toArray());
