<?php
	require_once( $GLOBALS["site_root"] . "/includes/widgets/MultiLangDataProvider.inc.php" );

	class MultiLangMultiDataProvider extends MultiLangDataProvider {
		protected $iWidth = 700;
		protected $iActiveLanguage = 1;

		protected $aValues = array();
		
		public function setWidth( $v ) { $this->iWidth = $v; }

		public function __construct( $id = "MultiLangMultiDataProvider" , $parent = null ) {
			parent::__construct( $id , $parent );
		}

		public function clearValues() { $this->aValues = array(); }
		public function setValue( $site_language_id , $val ) {
			$this->aValues[$site_language_id] = $val;
		}
		public function setValues( $data ) {
			foreach ($data as $id => $v) $this->aValues[$id]=$v;
		}

		public function getValue( $site_language_id ) {
			if (!isset( $this->aValues[$language_id] )) return false;
			return $this->aValues[$language_id];
		}	

		public function getValues( ) {
			return $this->aValues;
		}

		public function refreshChildValuesFromArray( $arr = null ) {
			parent::refreshChildValuesFromArray();
			$this->readAllChildValues();
		}

		protected function setAllChildValues() {
			foreach ($this->aSubWidgets as $site_language_id => $wdg)
				if (isset( $this->aValues[$site_language_id] ))
					$wdg->setValue( $this->aValues[$site_language_id] );
		}

		protected function readAllChildValues() {
			foreach ($this->aSubWidgets as $site_language_id => $wdg)
				$this->aValues[$site_language_id] = $wdg->getValue();
		}

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$this->setAllChildValues();
			FNTHPage::addUniquePageFullInit( sprintf( "InitMLMDP( '%s' , Array( %s ) );\n" , $this->getId() , implode( "," , array_keys( $this->aSiteLanguages ) ) ) );
			$this->setParam( "width" , $this->iWidth );
			$this->setParam( "active_language" , $this->iActiveLanguage );
			$this->setParam( "numoftabs" , count( $this->aSiteLanguages ) );
			$this->setParam( "tabwidth" , ($this->iWidth / count( $this->aSiteLanguages )) -2 );
			return parent::render();
		}

	}

?>
