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

	require_once( $GLOBALS["site_root"]."/includes/urlgen/Blueboard.inc.php" );

	class JobDetails extends Widget {
		protected $job_id = null;
		protected $job = null;
		protected $bDetails = false;
		protected $bExtendedDetails = false;
		protected $bOwnedByUser = false;
		protected $bExpired = false;
		protected $oEmailCaptcha;
		protected $bShowEmail = false;

		public function __construct( $id , $parent = null ) {
			parent::__construct( $id , $parent );
			$this->oEmailCaptcha = new CaptchaHtmlHide( "email_captcha" , $this );
			if (AdminUserModel::isAdminLoggedIn()) $this->bShowEmail = true;
		}

		public function setJobId( $v ) { $this->job_id = $v; }
		public function setJobData( $v ) { $this->job = $v; }

		public function setDetails( $v ) { $this->bDetails = $v; }
		public function setExtendedDetails( $v ) { $this->bExtendedDetails = $v; }
		public function setOwnedByUser( $v ) { $this->bOwnedByUser = $v; }

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$jm = new JobModel();
			if (!isset( $this->job )) $this->job = $jm->getJobFromId( $this->job_id , true );
			$this->setParam( "job" , $this->job );

			if (isset( $this->job["poster_user_id"] ) && $this->job["poster_user_id"] ) {
				$bp = array( "user_id" => $this->job["poster_user_id"] );
				$this->setParam( "url_blueboard" , BlueboardURL::renderURL( $bp ) );
			}

			$this->bExpired = ($this->job["job_deadline"]<fo3_date( "Y-m-d H:i:s" ));

			$this->oEmailCaptcha->setHiddenHtml( sprintf( "%s",$this->job["poster_email"] ) );
			$this->setParam( "bDetails" , $this->bDetails );
			$this->setParam( "bExtendedDetails" , $this->bExtendedDetails );
			$this->setParam( "bOwnedByUser" , $this->bOwnedByUser );
			$this->setParam( "bExpired" , $this->bExpired );

			$this->setParam( "languages" , LanguagesModel::getLanguageOptions() );
			$this->setParam( "servicetypes" , ServiceTypesModel::getServiceTypeOptions() );
			$this->setParam( "servicetypeunits" , ServiceTypesModel::getServiceTypeUnitOptions() );
			$this->setParam( "specialties" , SpecialtiesModel::getSpecialtyOptions() );
			$this->setParam( "job_recipients" ,
				fo3_render_job_recipients(
					$this->job["job_recipients"],
					$this->bExtendedDetails,
					$this->bOwnedByUser )
			);
			$this->setParam( "show_email" , $this->bShowEmail );
			return parent::render();
		}
	}
?>
