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

	class SystemArticle extends Widget {
		protected $iArticleId = 0;
		protected $bOnlyBody = false;

		public function __construct( $id = "SystemArticle" , $parent = null , $name = "" ) {
			parent::__construct( $id , $parent );
			if (!empty( $name )) $this->setArticleFromName( $name );
		}

		public function setOnlyBody( $v ) { $this->bOnlyBody = $v; }


		public function setArticleFromName( $name ) {
			$query = sprintf( "select article_id from articles where article_name='%s'" , FNTH_db_addslashes( $name ) );
			$row = FNTH_db_get_row( $query );
			if ($row) $this->iArticleId = $row["article_id"];
		}

		protected function prepareContent( $str ) {
			$t = new FNTHTemplate();
			$t->setParams( $this->aParams );
			return $t->renderFromString( $str );
		}

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$query = sprintf( "select * from larticles where site_language_id=%d and article_id=%d",
				$GLOBALS["langcode"],
				$this->iArticleId );
			$row = FNTH_db_get_row( $query );
			if (!$row) return parent::render();

			$this->setParam( "title" , $this->prepareContent( $row["larticle_title"] ) );
			$this->setParam( "body" , $this->prepareContent( $row["larticle_body"] ) );
			$this->setParam( "bOnlyBody" , $this->bOnlyBody );
			return parent::render();
		}
	}

?>
