<?php

class LanguageManager extends RootRegistry {

	var $language;
	var $Langs = array('eng.php' => 1);
	var $Modules = array();
	var $localContent;
	var $globalContent;

	var $DB;
	var $tables = array('contentitem as l','contentitem_lang as ll','contentitemtype as lt, module as m');
	var $fields = array('lt.name','l.var','ll.value');

	function __construct($Langs = array(),$name = 'LanguageManager') {
		global $HOME_PATH, $DatabaseBroker;
		//$this->RootRegistry($name);
		parent::__construct($name);
		$this->language = $HOME_PATH;
		$this->DB = $DatabaseBroker;
		//count($Langs) and $this->Langs = $Langs;
		//count($Langs) or $this->getLangs();
		//$this->getModules();
		$this->mainContent();
	}

	function mainContent() {
		$conditions = array('l.id' => 'll.ownerid','l.module' => 1,'m.id' => 'l.module','ll.lang' => $this->Langs[$this->language],'lt.id' => 'l.contenttype');
		$this->globalContent = $this->DB->SelectLang($this->tables,$this->fields,$conditions);
		//printArray($this->globalContent);
	}

	function moduleContent($module) {
		//if(isset($this->localContent[$module])) return $this->localContent[$module];
		$conditions = array('l.id' => 'll.ownerid','ll.lang' => $this->Langs[$this->language],'lt.id' => 'l.contenttype','l.module' => $module,'m.id' => 'l.module');
		//$this->localContent[$module] = $this->DB->SelectLang($this->tables,$this->fields,$conditions);
		//return $this->localContent[$module];
		return $this->DB->SelectLang($this->tables,$this->fields,$conditions);
	}

	function getLangs() {
		$this->Langs = getValuesToKeys($this->DB->SelectGuide('language'));
	}

	function getModules() {
		$this->Modules = $this->DB->SelectGuide(array('module as g'));
	}
}
?>