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

	class MyLanguages extends Widget {
		protected $aSelLanguages = array();
		protected $sCustomLanguage = "";

		public function setLanguage( $id ) { $this->aSelLanguages[((int)$id)]=true; }
		public function unsetLanguage( $id ) { unset( $this->aSelLanguages[$id] ); }
		public function setCustomLanguage( $s ) { $this->sCustomLanguage = $s; }
		public function getCustomLanguage( ) { return $this->sCustomLanguage; }

		public function getLanguages() { return array_keys( $this->aSelLanguages ); }

		public function refreshValueFromArray( $arr = null ) {
			if (!isset($arr)) $arr = $this->aP;
			$preid = $this->getId() . "_" ;

			$this->aSelLanguages = array();
			foreach ($arr as $k => $v) {
				if (strpos( $k , $preid )!==0) continue;
				$id = str_replace( $preid , "" , $k );
				if ($id=="custom") {
					$this->sCustomLanguage = $v;
				} else {
					$this->setLanguage( $id );
				}
			}
		}

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$langs = LanguagesModel::getLanguageOptions( false );
			$langs = fo3_xlat_horvert( $langs , 4 );
			$this->setParam( "langs" , $langs );
			$this->setParam( "sels" , $this->aSelLanguages );
			$this->setParam( "custom_language" , $this->sCustomLanguage );
			return parent::render();
		}

	}

?>
