<?php
	FNTH_class( "Migrator" );

	class AdminMigrate extends FNTHMigrator {
		protected $oProgressBarName = "pb1";
		protected $olddb;

		// global functions
		protected function renderForm( $postfix , $params = array() ) {
			if (!empty( $params )) $this->setParams( $params );
			$this->passGetPost( $this->aG , $this->aP );
			$this->handleChildEvents();
			$this->renderWidgets();

			$filename = $this->getTemplateFilename( $postfix );
			$content = $this->renderFromTemplate( $filename );
			$this->interactiveForm( $content );
		}

		protected function initAdminMigrate( $max = 100 ) {
			$this->addProgressBar( $this->oProgressBarName , 0 , $max , 0 );
		}

		protected function finishAdminMigrate() {
			$this->interactiveForm( "<a href=\"/admin/migrate/new.php\">&laquo; BACK</a>" );
		}
		

		protected function getMigrateMenu() {
			return array(
				array( "name" => "specialties" ),
				array( "name" => "jobs" ),
				array( "name" => "members" ),
				array( "name" => "forum" )
			);
		}

		public function connectOldDatabase() {
			$db = array();
			$db["dbtype"]="MySQL";
			$db["database"]="fordit_v2";
			$db["username"]="fordit_v2";
			$db["password"]="kakukk321";
			$this->olddb = FNTH_db_connect( $db );
			FNTH_db_free_result( FNTH_db_query( "set names utf8" , $this->olddb ) );
		}

		public function handleMigratorEvent() {
			$this->initAdminMigrate();
			$p = array();
			$p["menu"]=$this->getMigrateMenu();
			$this->renderForm( ".menu" , $p );
			return false;
		}
	
		protected function fakeInit() { }	


		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$this->fakeInit();
			return parent::render();
		}

		public function __construct( $id = "AdminMigrator" , $parent = null ) {
			$this->addMediaDirectory( $GLOBALS["site_root"] , $GLOBALS["site_www"] , "design/rp/","widgets/");
			parent::__construct( $id , $parent );
			$this->bAutoStart = true;
			$this->connectOldDatabase();
		}
	}

?>
