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

	class AdminJobPreview extends Widget {
		protected $job_id = 0;
		protected $job;

		public function __construct( $id , $parent = null ) {
			parent::__construct( $id , $parent );
			$this->oJobDetails = new JobDetails( "JobDetails" , $this );
		}

		public function setId( $v ) { $this->job_id = $v; }

		protected function getNumberOfQuotes() {
			$query = sprintf( "select count(*) as num from job_quotes where job_id=%d" , $this->job_id );
			return FNTH_db_get_field( $query , "num" );
		}

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

			$this->oJobDetails->setJobId( $this->job_id );
			$this->oJobDetails->setJobData( $this->job );
			$this->oJobDetails->setDetails( true );
			$this->oJobDetails->setExtendedDetails( true );

 			$this->setParam( "job" , $this->job );
			$this->setParam( "number_of_quotes" , $this->getNumberOfQuotes() );
			$content = parent::render();
			return FNTHPage::renderPage( $content );	
		}

	}
?>
