<?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
 */

// including libs
include_once './core/logger.class.php';
include_once './core/config.class.php';
include_once './core/i18n.class.php';
include_once './core/customer.class.php';
include_once './core/customer_group.class.php';
include_once './core/admin_role.class.php';

#[\AllowDynamicProperties]
class base {

	public $logger;
	public $config;
	public $i18n;
	public $db;
	public $customer;
	public $customer_group;
	public $admin_role;

	private $document_dir;

	public function __construct() {
		// load config settings
		$confFilePath = './config.inc.php';
		if (file_exists($confFilePath)) {
			include_once($confFilePath);
		} else {
			die('<h3>easyway shop wird gerade aktualisiert.</h3>');
		}

		// needed global vars
		define('SHOP_SYSTEM', $config_shop_system['SHOP_SYSTEM']);
		define('ROOT_DIR', $config_shop_system['ROOT_DIR']);
		define('STANDARD_DIR', $config_shop_system['STANDARD_DIR']);
		define('MAIN_URL', $config_shop_system['MAIN_URL']);

		// system logger
		$this->logger = Logger::get_instance();

		// new database object
		$this->db = new mysqli(
			$config_shop_system['db_host'],
			$config_shop_system['db_user'],
			$config_shop_system['db_password'],
			$config_shop_system['db_name']
		);

		// set database default charset
		$this->db->query("SET NAMES 'utf8'");

		// other important objects
		$this->config = new config($this);
		$this->customer = new customer($this);
		$this->i18n = new i18n($this);
		$this->customer_group = new Customer_group($this);
		$this->admin_role = new Admin_role($this);

		$this->document_dir = $config_shop_system['ROOT_DIR'].'web/'.$config_shop_system['SHOP_SYSTEM'].'/documents/';
	}

	protected function setup_info() {
		$info = (object)"";
		$info->base_url = MAIN_URL;
		$info->my_url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
		$info->module_name = $this->module_name;
		$info->images = MAIN_URL.'web/'.SHOP_SYSTEM.'/documents/files/';
		$this->layout_object->assign('info', $info);
	} // end setup_info

	public function is_customer_logged_in() {
		if ($this->customer->customer_id) {
			return true;
		}

		return false;
	}

	function __destruct() {
		$this->db->close();
	}

	function get_document_dir() {
		return $this->document_dir;
	}
}

?>