<?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="core.tpl";
	
	$config=array();
	//получаем настройки движка
	include(LAB_PATH_DATA.'/configs/core.conf');
	$xml = simplexml_load_file(LAB_PATH_KERNEL.'/install/config.xml');
	$core_cfg=array();
	include_once LAB_PATH_KERNEL.'/functions/config.func.php';
	//$xml=get_object_vars($xml);
	
	$i=0;
	$all_settings=array();
	foreach($xml->configs as $key=>$group)
	{
		$core_cfg[$i]['name']=(string)$group->attributes()->name;
		foreach($group as $cfg)
		{
			$cfg=get_object_vars($cfg);
			if (!isset($config[$cfg['name']])) $val=$cfg['default'];
			else $val=$config[$cfg['name']];
			$core_cfg[$i]['config'][$cfg['name']]=array('val'=>$val, 'title'=>$cfg['title'], 'describe'=>$cfg['describe'], 'type'=>$cfg['type'], 'default'=>$cfg['default']);
			$all_settings[$cfg['name']]=array('type'=>$cfg['type'], 'default'=>$cfg['default']);
			
			if (!empty($cfg['values']))
			{
				$tmp=get_object_vars($cfg['values']);
				$core_cfg[$i]['values'][$cfg['name']]=array_combine($tmp['value'], $tmp['value']);
			}
			elseif (!empty($cfg['callback']))
			{
				//тут вызываем функцию возвращающую возможные значения
				$core_cfg[$i]['values'][$cfg['name']]=$cfg['callback']();
			}
		}
		$i++;
	}
	
	if ($_SERVER['REQUEST_METHOD']=='POST')
	{
		User::checkToken();
		//print_r($_POST);
		Tpl::i()->clearAssign("config_tmp");
		$config_tmp=array();
		foreach($all_settings as $conf=>$conf_info)
		{
			//если значение пустое и поле не булевое, то подставляем значение по умолчанию
			if (trim($_POST['core'][$conf])=='' && $conf_info['type']!='boolean') $config_tmp[$conf]=$conf_info['default'];
			else $config_tmp[$conf]=$_POST['core'][$conf];
		}
		Tpl::i()->assign('config_tmp', $config_tmp);
		LabConfig::save(Tpl::i()->fetch(LAB_PATH_TEMPLATE.'/default/admin_groups/conf.tpl'));
		LabCMS::i()->reset_cache('objects');
		refresh();
	}
	
	Tpl::i()->assign('core_cfg', $core_cfg);
