<?php
	require_once( $GLOBALS["site_root"]."/includes/widgets/Widget.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/FrontendTextbox.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/FrontendCheckbox.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/FrontendSelect.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/FrontendSubmit.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/SelectedTranslators.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/FrontendGrid.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/UserNameTag.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/FrontendKeywordAutocomplete.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/TranslatorBoxes.inc.php" );

	require_once( $GLOBALS["site_root"]."/includes/models/ServiceTypes.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/Member.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/AllUsers.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/Counties.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/Countries.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/Memberships.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/User.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/Languages.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/Specialties.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/Cat.inc.php" );

	class SearchPane extends Widget {
		protected $search_source_language;
		protected $search_target_language;
		protected $search_servicetype;
		protected $search_county;
		protected $search_country;
		protected $search_utype;
		protected $search_membership;
		protected $search_keyword;
		protected $search_submit;

		protected $search_hits;

		protected $mmm;
		protected $bActiveAgency;

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

		public function __construct( $id , $parent ) {
			parent::__construct( $id , $parent );
			$ctrlwidth = 230;
			$this->search_source_language = new FrontendSelect( "source_language" , $this );
			$this->search_source_language->setWidth( $ctrlwidth );
			$this->search_target_language = new FrontendSelect( "target_language" , $this );
			$this->search_target_language->setWidth( $ctrlwidth );
			$this->search_servicetype = new FrontendSelect( "servicetype" , $this );
			$this->search_servicetype->setWidth( $ctrlwidth );
			$this->search_county = new FrontendSelect( "megye" , $this );
			$this->search_county->setWidth( $ctrlwidth );
			$this->search_servicetype->setWidth( $ctrlwidth );
			$this->search_country = new FrontendSelect( "orszag" , $this );
			$this->search_country->setWidth( $ctrlwidth );
			$this->search_utype = new FrontendSelect( "utype" , $this );
			$this->search_utype->setWidth( $ctrlwidth );
			$this->search_membership = new FrontendSelect( "membership" , $this );
			$this->search_membership->setWidth( $ctrlwidth );
			$this->search_keyword = new FrontendKeywordAutocomplete( "keyword" , $this );
			$this->search_keyword->setWidth( $ctrlwidth );
			$this->inactive = new FrontendCheckbox( "inactive" , $this );
			$this->inactive->setAttribute( "onclick" , sprintf( "SearchInactiveHandler('%s');" , $this->getId() ) );
			$this->inactive->setCSSAttribute( "margin" , "0px" );
	
			$this->search_submit = new FrontendSubmit( "smb_search" , $this );
			$this->search_submit->setValue( __("searchpage_Search","attr") );

			$this->search_selected_translators = new SelectedTranslators( "selected_translators" , $this );
			$this->setParam( "url_search" , MemberSearchURL::renderURL() );

			$this->mmm = new MyMemberModel();
			$this->bActiveAgency = ($this->mmm->isLoggedinMemberActiveSubscriber() && $this->mmm->getLoggedInUserType()=="agency");
			$this->setParam( "active_agency" , $this->bActiveAgency );
			$this->bLoggedInMember = $this->mmm->isMemberLoggedIn();
			$this->setparam( "loggedinmember" , $this->bLoggedInMember );
			if ($this->bActiveAgency) {
				// belepett forditoiroda
				$this->search_specialty = new FrontendSelect( "specialty" , $this );
				$this->search_specialty->setWidth( $ctrlwidth );
				$this->search_cat = new FrontendSelect( "cat" , $this );
				$this->search_cat->setWidth( $ctrlwidth );
				$this->search_cat_req = new FrontendSelect( "cat_req" , $this );

				$this->search_native_language = new FrontendCheckbox( "native_language" , $this );
				$this->search_invoice = new FrontendCheckbox( "invoice" , $this );
				$this->search_certificate = new FrontendCheckbox( "certificate" , $this );
				$this->search_experience = new FrontendCheckbox( "experience" , $this );

			}

		}
		
		protected function constructHits() {
			require_once( $GLOBALS["site_root"] . "/includes/widgets/SearchHitsGrid.inc.php" );
			$this->search_hits = new SearchHitsGrid( "search_hits" , $this );
			$this->search_hits->passGetPost( $this->aG , $this->aP );
			/*
			$this->search_hits->handleEvents();
			*/
			$this->search_hits->render();
			$this->setParam( "number_of_hits" , $this->search_hits->getNumberOfRecordsAfterRender() );
		}

		protected function generateTextualFilters() {
			$retval = "";
			
			FNTH_da( $retval );
		}

		public function render() {
			$allusers = new AllUsersModel();

			$data = array();
			$data["active_freelancers"] = $allusers->getActiveFreelancers();
			$data["all_freelancers"] = $allusers->getActiveFreelancers( false );
			$data["active_agencies"] = $allusers->getActiveAgencies();
			$data["all_agencies"] = $allusers->getActiveAgencies( false );
			FNTHPage::addUniquePageFullInit( sprintf( "InitSearchPane( '%s', %s );" , $this->getId() , json_encode( $data ) ) );
	
			$this->setParam( "numoffreelancers" , $allusers->getActiveFreelancers() );
			$this->setParam( "numofagencies" , $allusers->getActiveAgencies() );
			$this->setParam( "bIsSubmitted" , $this->search_submit->isSubmitted() );

			$this->search_source_language->addOptions( LanguagesModel::getLanguageOptions() );
			$this->search_target_language->addOptions( LanguagesModel::getLanguageOptions() );
			$this->search_servicetype->addOptions( ServiceTypesModel::getServiceTypeOptions() );

			$this->search_county->addOptions( CountiesModel::getCountyOptions() );
			$this->search_country->addOptions( CountriesModel::getCountryOptions() );

			$this->search_utype->addOption( "" , __("Choose") );
			// $this->search_utype->addOption( "parttime" , __("parttime") );
			$this->search_utype->addOption( "freelancer" , __("translator") );
			$this->search_utype->addOption( "agency" , __("agency") );

			$this->search_membership->addOptions( MembershipsModel::getMembershipOptions() );

			if ($this->bActiveAgency) {
				$this->search_specialty->addOptions( SpecialtiesModel::getSpecialtyOptions() );
				$this->search_cat->addOptions( CatModel::getCatOptions() );

				$this->search_cat_req->addOptions( CatModel::getCatlevelOptions() );
			}

			if ($this->search_submit->isSubmitted()) {
				$this->constructHits();
				$p = $this->aG;
				unset( $p[$this->search_submit->getId()] );
				$url = MemberSearchURL::renderURL( $p );
				$this->setParam( "url_back" , $url );
				$this->setParam( "url_backreset" , MemberSearchURL::renderURL() );

				// SEO : title
				fo3_set_page_title( sprintf( "%s | %s" , __("seo_Search_in_translators" ) , GlobalsModel::getSiteName() ) );
				// textual filters are in SearchHitsGrid
			}

			return parent::render();
		}
	}

?>
