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

	class TranslatorBoxes extends Widget {
		protected $aTranslators = array();
		protected $member_ids = array();

		protected function getMemberIds() {
			$retval = array();

			$filters = array();
			$filters["expiration"]="expires_tstamp>=now()";
			// $filters["picture"]="haspicture";
			$filters["type"]="member_type='agency'";
			if ($GLOBALS["language"]!="hu") {
				$epm = new ExtendedPropertiesModel();
				$prop_id = $epm->getEPropIdFromName( "use_langsite" );
				$filters["language"]=sprintf( "member_id in (select member_id from member_extended_properties where language_id=%d and extended_property_id=%d and value='on')",
					$GLOBALS["langcode"],
					$prop_id );
			}

			$format = "select member_id from members where %s order by random() limit 1";

			$retval[]=FNTH_db_get_field( sprintf( $format , implode( " and " , $filters ) ) , "member_id" );
			$filters["type"]="member_type='freelancer'";
			$retval[]=FNTH_db_get_field( sprintf( $format , implode( " and " , $filters ) ) , "member_id" );
		
			return $retval;
		}

		public function __construct( $id , $parent ) {
			parent::__construct( $id , $parent );
			for ($i=0;$i<2;$i++)
				$this->aTranslators[] = new TranslatorBox( sprintf( "member%d" , $i ) , $this );
		}

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$this->member_ids = $this->getMemberIds();
			foreach ($this->member_ids as $i => $member_id)
				$this->aTranslators[$i]->setMemberId( $member_id );

			$this->aTranslators[0]->setTitle( __("translatorbox_Agency") );
			$this->aTranslators[0]->setMemberType( "agency" );
			$this->aTranslators[1]->setTitle( __("translatorbox_Freelancer" ) );
			$this->aTranslators[1]->setMemberType( "freelancer" );
			return parent::render();
		}
	}

?>
