<?php
	require_once( $GLOBALS["site_root"]."/includes/widgets/Widget.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/JobsGrid.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/ArchiveJobsGrid.inc.php" );

	require_once( $GLOBALS["site_root"]."/includes/urlgen/RequestQuote.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/SystemArticle.inc.php" );
	
	require_once( $GLOBALS["site_root"]."/includes/models/MyMember.inc.php" );

	class JobsPane extends Widget {

		public function __construct( $id , $parent ) {
			parent::__construct( $id , $parent );
			$this->mymember_model = new MyMemberModel();

			$this->oJobsGrid = new JobsGrid( "JobsGrid" , $this );

			if (isset( $_SESSION["job_quote_saved"] )) {
				$this->sys_article = new SystemArticle( "sys_article" , $this );
				$this->sys_article->setOnlyBody( true );
				$this->sys_article->setArticleFromName( "sys_job_quote_sent" );
				unset( $_SESSION["job_quote_saved"] );
			}
		}

		public function modifyGetPost( &$g , &$p ) {
			$loggedin = $this->mymember_model->isMemberLoggedIn();
			if (!$loggedin) {
				$this->oArchiveJobsGrid = new SystemArticle( "ArchiveJobsGrid" , $this , "sys_error_user_has_to_login" );
				$this->oArchiveJobsGrid->setOnlyBody( true );
			} else {
				$active = $this->mymember_model->isLoggedinMemberActiveSubscriber();
				$active = true;	// temporalisan mindig "aktiv"
				if ($active) {
					// megerdemli
					$this->oArchiveJobsGrid = new ArchiveJobsGrid( "ArchiveJobsGrid" , $this );
				} else {
					$this->oArchiveJobsGrid = new SystemArticle( "ArchiveJobsGrid" , $this , "sys_error_user_has_to_be_an_active_subscriber" );
					$this->oArchiveJobsGrid->setOnlyBody( true );
				}
			}
			return parent::modifyGetPost( $g , $p );
		}

		protected function initializeWidget() {
			$fields = array( "job_bgcolor_permitted" , "job_bgcolor_disabled" , "job_bgcolor_special" , "job_bgcolor_owned" );
			foreach ($fields as $f )
				$this->setParam( $f , SystemParametersModel::getVar( $f ) );
		}

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$this->setParam( "url_request_quote" , RequestQuoteURL::renderUrl() );
			$this->initializeWidget();
			$this->setParam( "member_id" , $this->mymember_model->getLoggedinMemberId() );
			return parent::render();
		}
	}

?>
