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


	class AdminLanguagesSortPage extends BackendPage {
		protected $smb;

		public function __construct( $id = "AdminLanguagesSortPage" , $parent = null ) {
			parent::__construct( $id , $parent );
			if (!AdminUserModel::isAdminLoggedIn()) return;
			$this->smb = new AdminSubmit( "smb" , $this );
			$this->smb->setValue( __("Sort") );
		}

		protected function initializeWidgets() {
			$lm = new LanguagesModel();
			$languages = $lm->getLanguageOptions( false , $this->aG["language_id"] , false );
			$this->setParam( "languages" , $languages );
			$this->setParam( "all_languages" , $languages );
		}

		public function handleEvents() {
			$this->refreshChildValuesFromArray();
			if (!$this->smb->isSubmitted()) return parent::handleEvents();

			$lm = new LanguagesModel();
			$lm->setLanguageSorting( $this->aG["language_id"] , explode( "," , $this->aP["retval"] ) );
			FNTH_redirect( "index.php" );
			return parent::handleEvents();
		}
		
		public function render() {
			if (!$this->isLoggedIn()) return parent::render();
			$this->initializeWidgets();
			FNTHPage::addUniquePageFullInit( "InitAdminLanguagesSortPage();" );
			return parent::render();
		}

	}


?>
