<?php
/**
* @version      $Id: admin_system_config_editor.php
* @package      Easyshop
* @copyright    Copyright (C) 2005 - 2011 TA-EDV
* @license      proprietary
* @author       Richard Kammermayer <rk@ta-edv.de>
* Easyshop is a web shop system
*/

include_once './modules/list_and_edit.class.php';

class admin_system_config_editor {
	private $base_object;
	private $config;
	
	function __construct($base_object, $layout_object) {
		$this->base_object = $base_object;
		$this->config = $base_object->config;
		$this->layout_object = $layout_object;
		$this->list_object = new ListAndEdit($base_object, $layout_object);
	}

	function run() {
		//$this->setup_info();

		//var_dump($GLOBALS);
		
		if(isset($_GET['id']) && $_GET['id']) {
			$has_id = true;
		} else if(isset($_POST['id']) && $_POST['id']) {
			$has_id = true;
		} else {
			$has_id = false;
		}
		
		if(isset($_POST['submit'])) {
			$is_submitted = true;
		} else {
			$is_submitted = false;
		}
		
		// decide what CRUD method to call and call it in ListAndEdit
		if($has_id && !$is_submitted && $_GET['mod'] != 'delete') {
			// template variable name
			$config_data['elemente'] = $this->config->get_config_elements($_GET['id']);
			$config_data['id'] = $_GET['id'];
			$this->layout_object->assign('form_data', $config_data);
		} // update
		elseif($has_id && $is_submitted && $_GET['mod'] != 'delete') {
			$this->config->update($_GET['id'], $_POST['form_field']);
			$config_data['elemente'] = $this->config->get_config_elements($_GET['id']);
			$config_data['id'] = $_GET['id'];
			$this->layout_object->assign('form_data', $config_data);
		} 
		else {

		}
		return $this->layout_object->fetch('admin_system_config_editor.tpl');
	}
	
	
}

?>