<?php
	require_once( $GLOBALS["site_root"]."/includes/widgets/Widget.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/JobQuote.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/Member.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/User.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/urlgen/Blueboard.inc.php" );

	class QuoteDetails extends Widget {
		protected $job_quote_id = null;
		protected $job_quote = null;
		protected $bJobQuoteOwnedByMember = false;

		public function setJobQuoteOwnedByMember( $v ) { $this->bJobQuoteOwnedByMember = $v; }
		public function setJobQuoteId( $v ) { $this->job_quote_id = $v; }
		public function setJobQuoteData( $v ) { $this->job_quote = $v; }

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$jqm = new JobQuoteModel();
			if (!isset( $this->job_quote )) $this->job_quote = $jqm->getJobQuoteFromJobQuoteId( $this->job_quote_id , true );
			$mm = new MemberModel();
			$um = new UserModel();
			$member = $mm->getMemberFromMemberId( $this->job_quote["member_id"] );
			$user = $um->getUserFromUserId( $member["user_id"] );
			$bburl = new BlueboardURL();
			$url = $bburl->renderURL( array( "user_id" => $user["user_id"] ) );

			$this->setParam( "job_quote" , $this->job_quote );
			$this->setParam( "member" , $member );
			$this->setParam( "url_blueboard" , $url );
			$this->setParam( "user" , $user );
			$this->setParam( "bJobQuoteOwnedByMember" , $this->bJobQuoteOwnedByMember );
			$response = "";
			if ($this->bJobQuoteOwnedByMember) {
				if (!isset( $this->job_quote["is_accepted"] )) {
					$response =  __("myquotespage_response_not_arrived");
				} else {
					$response = ($this->job_quote["is_accepted"]=="t") ?
						sprintf( "%s (%s)" , __("myquotespage_response_accepted") , substr( $this->job_quote["accepted_at"] , 0 , 16 ) ) :
						sprintf( "%s (%s)" , __("myquotespage_response_declined") , substr( $this->job_quote["accepted_at"] , 0 , 16 ) );

					// ez itt a plusz
					if (isset( $this->job_quote["quote_accept_comment"] ) &&
						strlen( trim( $this->job_quote["quote_accept_comment"] )))
						$response.=sprintf( "<br/><br/><i>%s</i>" , nl2br( trim( $this->job_quote["quote_accept_comment"] ) ) );
				}
				$this->setParam( "job_quote_response" , $response );
			}
			return parent::render();
		}
	}

?>
