<?php
/**
 * ****************************************************************
 * Project:      *
 * Copyright:    Copyright (c) 2007
 * Company:      Thomas Niemann
 * ****************************************************************
 * Workfile:     ConfigLoader.php
 * ****************************************************************
 * Description:  provides access to all configurationSettings
 *               stored in configuration.xml                
 * ***************************************************************/
class ConfigLoader extends BasicLoader implements SingletonInterface{

	const xmlFile = 'config/configuration.xml';
	private $menuItems = array();	
	private static $instance;
	
	/****************************************************************
	 * singleton, provides only one instance
	 ****************************************************************/
	public static function getInstance()
	{
		if (!isset (self :: $instance))
		{
			$class = __CLASS__;
			self :: $instance = new $class ();
		}
		return self :: $instance;
	}
	/*****************************************************
	 * private constructor to prevent creation outside
	 * this class
	 ****************************************************/
	private function __construct() {
		$xmlHelper = new XMLHelper(self :: xmlFile);
		$this->xmlContent = $xmlHelper->getContent();
	}	
  	public function getGoogleKey ($_element) {
		return $this->xmlContent->googleMapKey->$_element;
	}	
	/*****************************************************
	 * returns configvalue by delivered element
	 ****************************************************/
	public function getAppSettings($_element) {
		return $this->xmlContent->application->$_element;
	}

	/*****************************************************
	 * returns configvalue by delivered element
	 ****************************************************/
	public function getElement($_element) {
		return $this->xmlContent->$_element;
	}

	/*****************************************************
	 * returns values for databaseConnection
	 ****************************************************/
	public function getDBConn($_application, $_element) {
		// get all available databaseConnections
		$dbConnections = $this->xmlContent->database->connection;
		
			
		// iterate to find right connection and return expected element
		foreach ($dbConnections as $dbConn) {
			if($dbConn->attributes()->application == $_application) {
				  return $dbConn->$_element;
			}
		}
	}
	
	/*****************************************************
	 * returns configvalue by delivered element
	 ****************************************************/
	public function getPHPSettings($_element) {
		return $this->xmlContent->php_settings->$_element;
	}
	
	/*****************************************************
	 * returns configPath by delivered element
	 ****************************************************/
	public function getConfigPath($_element) {
		return $this->xmlContent->configPath->$_element;
	}
	public function getTemplatePath($_element) {
		return $this->xmlContent->templatePath->$_element;
	}
	/*****************************************************
	 * returns emailAdress
	 ****************************************************/
	public function getEmail($_element) {
		return $this->xmlContent->emailAdress->$_element;
	}
	
	/*****************************************************
	 * returns configvalue by delivered element
	 ****************************************************/
	public function getConstant($_element) {
		return $this->xmlContent->constant->$_element;
	}
	public function getSmsLoginData($_element) {
		return $this->xmlContent->sms_config->$_element;
	}
	/*****************************************************
	 * returns configvalue by delivered element
	 ****************************************************/
	public function getMaxFileSize_Image($_element) {
		return $this->xmlContent->upload->$_element;
	}	
}
?>