<?php
/**
* @version      $Id: admin_price_search_engine_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 './core/export.class.php';
include_once './core/structure.class.php';
include_once './core/customer_group.class.php';
include_once './modules/list_and_edit.class.php';

class admin_price_search_engine_editor {
	private $base_object;
	private $config;
	
	function __construct($base_object, $layout_object) {
		$this->base_object = $base_object;
		$this->config = $base_object->config_object;
		$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;
		}
		
		// get customer groups
		$customer_group_object = new Customer_group($this->base_object);
		$customer_groups = $customer_group_object->get_all_groups();
		$this->layout_object->assign('customer_groups', $customer_groups);
		
		// get all structure tree
		$structure_object = new Structure($this->base_object);
		$structure_tree = $structure_object->get_all_tree_full_path();
		$this->layout_object->assign('structure_tree', $structure_tree);
		
		// decide what CRUD method to call and call it in ListAndEdit
		// create
		$export_object = new Export($this->base_object);
		if($has_id && !$is_submitted && $_GET['mod'] != 'delete') {
			// template variable name
			$export_object->id = $_GET['id'];
			$data = $export_object->get_data();
			$this->layout_object->assign('form_data', $data);
		} // update
		elseif($has_id && $is_submitted && $_GET['mod'] != 'delete') {
			$export_object->id = $_POST['id'];
			$form_data = $export_object->data_filter($_POST['form_field']);
			$export_object->update($form_data);
			$export_object->update_selected_structure($_POST['structure_ids']);
			$data = $export_object->get_data();
			$this->layout_object->assign('form_data', $data);
		} 
		return $this->layout_object->fetch('admin_price_search_engine_editor.tpl');
	}
	
	
}

?>