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

	require_once( $GLOBALS["site_root"]."/includes/models/Articles.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/Articlecategories.inc.php" );

	class ArticleWithAd extends Widget {
		protected $iArticleId = 0;
		protected $article_model;
		protected $ac_model;
		protected $oAd;

		public function __construct( $id , $parent = null ) {
			parent::__construct( $id , $parent );
			$this->article_model = new ArticlesModel();
			$this->ac_model = new ArticlecategoriesModel();
			$this->oAd = new Openads( $id."_awaad" , $this );
			switch ($GLOBALS["language"]) {
			default:
			case "hu":
				$this->oAd->setZoneId( 21 );
				break;
			case "en":
				$this->oAd->setZoneId( 47 );
				break;
			case "de":
				$this->oAd->setZoneId( 181 );
				break;
			}
		}

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$article = $this->article_model->getLatestArticleFromCategory( 
				$this->ac_model->getArticleCategoryIdFromName( array( "--news--" , "--profinfo--" ) ),
				$GLOBALS["langcode"] );
			$this->setParam( "article" , $article );
			$this->setParam( "larticle" , $article["larticle"] );
			$this->setParam( "adname" , $this->oAd->getId() );
			$retval = parent::render();
			// FNTH_da( $this->getParams() );
			return $retval;
		}

	}
?>
