<?php if(!defined('master_script')) die();

/**
 * Save widget config
 *
 * @category   Backend (actions)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   1.0
 */
 	
	// Global data
 	$configs_folder = $system_data['folder']['settings'] . 'widgets/';
 	$widget_config_folder = $configs_folder . $_GET['name'] . '/';
	$config_file = $widget_config_folder . '/config.php';
	
	// Requirements
	if(!file_exists($configs_folder)) mkdir($configs_folder);
	if(!file_exists($widget_config_folder)) mkdir($widget_config_folder);
	
	// Get configs
	file_exists($config_file) ? include($config_file) : $widget_config = array();
	
	// Change position
	if(isset($_GET['left']) && isset($_GET['top']))
		$widget_config['position'] = ($_GET['top'] < 0 ? 0 : $_GET['top']) . ',' . ($_GET['left'] < 0 ? 0 : $_GET['left']);
	
	// Save config file
	$config_keys = array_keys($widget_config);
	$config_content = array();
	
	$config_content[] = '<?php';
	foreach($config_keys as $key) $config_content[] = '	$widget_config["' . $key . '"] = "' . $widget_config[$key] . '";';
	$config_content[] = '?>';
	
	file_put_contents($config_file, implode("\n", $config_content));

?>