<?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';
include_once './core/database.class.php';

class Language extends Main {

	public $list_table_config = array (
		'title' => 'Sprachen',
		'db_table' => 'languages',
		'list_fields' => array(
			array(
				'db_field' => 'name',
				'name' => 'Sprache',
				'sortable' => 1
			),
			array(
				'db_field' => 'iso_639_1',
				'name' => 'ISO 631-1',
				'sortable' => 1
			),
			array(
				'db_field' => 'active',
				'name' => 'Status',
				'rewrite_function' => 'state_text',
				'sortable' => 1
			)
		),
		'search_fields' => array('name', 'iso_639_1'),
		'db_id_field' => 'id',
		'db_selectable_field' => 'name',
		'edit_link' => 'index.php?admin_modul=admin_object_edit&object=Language&object_id=',
		'toolbar' => array(
			'delete' => '1',
			'new' => 'index.php?admin_modul=admin_object_edit&object=Language',
			'copy' => 0,
			'select_all' => 1,
			'edit' => 0,
			'actions' => 0,
			'filter' => 0,
			'search' => 1
		),
		'edit_title' => 'Sprache bearbeiten',
		'edit_fields' => array (
			array(
				'name' => 'Stammdaten',
				'type' => 'form_title'
			),
			array(
				'db_field' => 'name',
				'name' => 'Sprache',
				'type' => 'text'
			),
			array(
				'db_field' => 'iso_639_1',
				'name' => 'ISO 631-1',
				'type' => 'text'
			),
			array(
				'db_field' => 'price_format',
				'name' => 'Price format',
				'type' => 'text'
			),
			array(
				'db_field' => 'date_format',
				'name' => 'Date format',
				'type' => 'text'
			),
			array(
				'db_field' => 'active',
				'name' => 'Status',
				'values' => 'state_text',
				'type' => 'int'
			)
		),
		'edit_mandatory_fields' => array('name', 'iso_639_1'),
		'edit_toolbar' => array(
			'close' => 'index.php?admin_modul=admin_object_list&object=Language',
			'copy' => 0,
			'undo' => 0,
			'redo' => 0,
			'save' => 1,
			'delete' => 1
		),
	);

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

	public function get_all_active() {
		$sql = "SELECT * FROM languages WHERE active=1";
		$result = $this->db->query($sql);
		if ($this->db->error) {
			$log_object = Logger::get_instance();
			$log_object->info('Error in /core/language_class.php->get_all_active()', $this->db->error.', sql:'.$sql);
		}
		$data = array();
		if ($result) {
			while ($obj = $result->fetch_object()) {
				$data[] = $obj;
			}
		}
		return $data;
	}

}

?>