<?php
/*
 * @version			$Id: index.php 10381 2008-06-01 03:35:53Z $
 * @package			Carteasy
 * @copyright		Copyright (C) 2005 - 2011 Wlanium
 * @license			proprietary
 * @author			Thomas Bartelt
 * Carteasy is a web shop system
 */
 
include_once './core/main.class.php';

class ItemType extends Main {

	public $list_table_config = array (
		'title' => 'Artikeltypen',
		'db_table' => 'item_type_definitions',
		'list_fields' => array(
			array(
				'db_field' => 'item_type_definition_name',
				'name' => 'Bezeichnung',
				'sortable' => 1
			),
			array(
				'db_field' => 'item_type_definition_text',
				'name' => 'Beschreibung',
				'sortable' => 1
			),
			array(
				'db_field' => 'item_type_definition_is_active',
				'name' => 'Status',
				'rewrite_function' => 'state_text',
				'sortable' => 1
			)
		),
		'search_fields' => array('item_type_definition_name', 'item_type_definition_text'),
		'db_id_field' => 'item_type_definition_id',
		'edit_link' => 'index.php?admin_modul=admin_object_edit&object=ItemType&object_id=',
		'toolbar' => array(
				'delete' => '1',
				'new' => 'index.php?admin_modul=admin_object_edit&object=ItemType',
				'copy' => 0,
				'select_all' => 1,
				'edit' => 0,
				'actions' => 0,
				'filter' => 0,
				'search' => 1
		),
		'edit_title' => 'Artikeltyp',
		'edit_fields' => array (
			array(
				'name' => 'Stammdaten',
				'type' => 'form_title'
			),
			array(
				'db_field' => 'item_type_definition_name',
				'name' => 'Name',
				'type' => 'text'
			),
			array(
				'db_field' => 'item_type_definition_text',
				'name' => 'Text',
				'type' => 'text'
			),
			array(
				'db_field' => 'item_type_definition_is_active',
				'name' => 'Status',
				'values' => 'state_text',
				'type' => 'int'
			),
			array(
				'db_field' => 'item_type_definition_type',
				'name' => 'Aktion',
				'values' => 'item_action_text',
				'type' => 'int'
			)
		),
		'edit_mandatory_fields' => array('name', 'text'),
		'edit_toolbar' => array(
			'close' => 'index.php?admin_modul=admin_object_list&object=ItemType',
			'copy' => 0,
			'undo' => 0,
			'redo' => 0,
			'save' => 1,
			'delete' => 1
		),
	);

	protected $base_object;
	protected $db;

	// db fields
	private $fields = array(
	);

	// generic
	private $id;
	private $error;

	public function __construct($base_object, $id = false) {
		$this->base_object = $base_object;
		$this->db = $base_object->db;
		$this->id = $id;
		$this->error = '';
	} // end constructor

	public function state_text() {
		return array (
			'1' => 'aktiv',
			'0' => 'inaktiv'
		);
	}

	public function item_action_text() {
		return array (
			'0' => '-',
			'1' => 'Angebotspreis - Zeitraum definierbar'
		);
	}

	public function set_id($id) {
		$this->id = $id;
	} // end set_id

	public function get_id() {
		return $this->id;
	} // end get_id

	public function get_error() {
		return $this->error;
	} // end get_error

	public function get_item_type_definitions() {
		$sql = 'SELECT * FROM item_type_definitions';

		$result = $this->db->query($sql);

		if ($result->num_rows > 0) {
			$data = array();
			while ($obj = $result->fetch_object()) {
				$data[$obj->item_type_definition_id] = $obj->item_type_definition_name;
			}

			return $data;
		}

		return false;
	} // end get_item_type_definitions

}