<?php
/*======================================================================================
Module: Articles
======================================================================================*/

// Check authorisation
if (!isset($gCms)) exit;

// Get preferences
$urlstart = $this->GetPreference('urlstart') ? $this->GetPreference('urlstart') : 'Articles';
$mode_categories = $this->GetPreference('mode_categories') ? $this->GetPreference('mode_categories') : 'Categories';
$mode_articles = $this->GetPreference('mode_articles') ? $this->GetPreference('mode_articles') : 'Articles';
$mode_article = $this->GetPreference('mode_article') ? $this->GetPreference('mode_article') : 'Article';
$mode_cart = $this->GetPreference('mode_cart') ? $this->GetPreference('mode_cart') : 'Cart';
$mode_cartsnippet = $this->GetPreference('mode_cartsnippet') ? $this->GetPreference('mode_cartsnippet') : 'CartSnippet';
$mode_form = $this->GetPreference('mode_form') ? $this->GetPreference('mode_form') : 'Form';
$mode_summary = $this->GetPreference('mode_summary') ? $this->GetPreference('mode_summary') : 'Summary';
$mode_ack = $this->GetPreference('mode_ack') ? $this->GetPreference('mode_ack') : 'Ack';

// Smarty parameters
$inline = isset($params['inline']) ? (int)$params['inline'] : true;
if (!$inline) $inline = false;
$page_cart = isset($params['page_cart']) ? urldecode(trim($params['page_cart'])) : '';
if ($page_cart && (int)$page_cart<1) $page_cart = $db->GetOne('SELECT content_id FROM '.cms_db_prefix().'content WHERE content_alias = ?', array($page_cart));
$page_categories = isset($params['page_categories']) ? urldecode(trim($params['page_categories'])) : '';
if ($page_categories && (int)$page_categories<1) $page_categories = $db->GetOne('SELECT content_id FROM '.cms_db_prefix().'content WHERE content_alias = ?', array($page_categories));
$page_articles = isset($params['page_articles']) ? urldecode(trim($params['page_articles'])) : '';
if ($page_articles && (int)$page_articles<1) $page_articles = $db->GetOne('SELECT content_id FROM '.cms_db_prefix().'content WHERE content_alias = ?', array($page_articles));
$page_article = isset($params['page_article']) ? urldecode(trim($params['page_article'])) : '';
if ($page_article && (int)$page_article<1) $page_article = $db->GetOne('SELECT content_id FROM '.cms_db_prefix().'content WHERE content_alias = ?', array($page_article));
$template_categories = isset($params['template_categories']) ? urldecode(trim($params['template_categories'])) : 'categories';
$template_articles = isset($params['template_articles']) ? urldecode(trim($params['template_articles'])) : 'articles';
$template_article = isset($params['template_article']) ? urldecode(trim($params['template_article'])) : 'article';
$template = isset($params['template']) ? urldecode(trim($params['template'])) : '';
$returnid = isset($returnid) ? (int)$returnid : 0;
$returnid = isset($params['returnid']) ? (int)$params['returnid'] : $returnid;
// Parameters for Smarty and Requests
$sortorder = 'ASC';
if(isset($params['sortdesc']) && $params['sortdesc'] && $params['sortdesc']!='false') $sortorder = 'DESC';
$articleslimit = '987654321';
if(isset($params['articleslimit']) && $params['articleslimit'] > 0) $articleslimit = (int)$params['articleslimit'];
$cutoff = isset($params['cutoff']) ? (int)$params['cutoff'] : 0;
$cutoff = isset($params['cutoff']) ? ' AND end_date >= DATE_SUB(CURDATE(),INTERVAL '.$cutoff.' DAY'. ')' : '';
$pastonly = '';
if(isset($params['pastonly'])) $pastonly = ' AND end_date <= CURDATE()';
// Get Module-Parameters (warning - already deprecated)
$ops = cmsms()->GetModuleOperations();
$mparams = $ops->GetModuleParameters($id);
// Get Request-Module-ID
$mmact = isset($_REQUEST['mact']) ? explode(',',$_REQUEST['mact']) : array();
$mid = isset($mmact[1]) ? $mmact[1] : '';
// Parameter to set the output mode
$mode = '';
if (!isset($mparams['mode'])) $mode = isset($_REQUEST[$mid.'mode']) ? $_REQUEST[$mid.'mode'] : '';
if (!$mode && isset($params['mode']))  $mode = $params['mode']; // Available modes: categories,articles,article - default: articles
$mode = isset($params['forcemode']) ? $params['forcemode'] : $mode; // Available modes: categories,articles,article - default: articles
if (!$mode) $mode = $mode_articles;

// Get article ID
if ($this->req_ar_id) {
	$article = $this->req_ar_id;
} else {
	$article = isset($params['article']) ? urldecode($params['article']) : ''; // Wird hier eine Artikel ID mitgegeben, werden die Details dieses Artikels angezeigt
	if ($article && $article!=(int)$article) $article = (int)$db->GetOne('SELECT entry_id FROM '.cms_db_prefix().'module_articles_articles WHERE active=1 AND title = ?', array($article));
}

// Get category details
if ($this->req_cat_id) {
	$category = $this->req_cat_id;
} else {
	$category = '';
	if (!isset($mparams['category'])) $category = isset($_REQUEST[$mid.'category']) ? $_REQUEST[$mid.'category'] : '';
	if (!$category && isset($params['category']))  $category = strtolower(urldecode($params['category']));
}
if (!$category && $article) $category = (int)$db->GetOne('SELECT cat_id FROM '.cms_db_prefix().'module_articles_category_articles WHERE article_id = ? LIMIT 1', array($article)); // This statement ist not so stable, because one article could belong to more than one categories ...
$category = isset($params['forcecategory']) ? strtolower($params['forcecategory']) : $category;
if ($category && $category!=(int)$category) $category = $db->GetOne('SELECT entry_id FROM '.cms_db_prefix().'module_articles_category WHERE active=1 AND title = ?', array($category));
#if (!$category && isset($_SESSION['articles_category'])) $category = (int)$_SESSION['articles_category'];
if ($category) {
	$categoryinfos = $db->GetRow('SELECT entry_id,title,short_desc,long_desc,image_url,sort_order,returnid,seo_url,meta_title,meta_description,noindex,nofollow,noarchive,noodp,notranslate FROM '.cms_db_prefix().'module_articles_category WHERE active=1 AND entry_id = ?', array((int)$category));
	if ($categoryinfos) {
		// Build a new row
		$row = new StdClass();
		// Get data in array
		$row->category = (int)$categoryinfos['entry_id'];
		$row->title = $categoryinfos['title'];
		$row->summary = $categoryinfos['short_desc'];
		$row->image = $categoryinfos['image_url'] ? $config['image_uploads_url'].'/Articles/categories/'.$categoryinfo['entry_id'].'/'.$categoryinfo['image_url'] : '';
		$row->content = $categoryinfos['long_desc'];
		$row->order = $categoryinfos['sort_order'];
		$row->returnid = $categoryinfos['returnid'] ? $categoryinfos['returnid'] : $returnid;
		if (!$row->returnid) $row->returnid = $returnid;
		if (!$row->returnid) $row->returnid = $this->GetPreference('returnid');
		$row->seo_url = $categoryinfos['seo_url'];
		$row->meta_title = $categoryinfos['meta_title'];
		$row->meta_description = $categoryinfos['meta_description'];
		$row->noindex = $categoryinfos['noindex'];
		$row->nofollow = $categoryinfos['nofollow'];
		$row->noarchive = $categoryinfos['noarchive'];
		$row->noodp = $categoryinfos['noodp'];
		$row->notranslate = $categoryinfos['notranslate'];
		// Assign smarty vars
		$smarty->assign('categoryinfos',$row);
	} else { $categoryinfos = array(); }
	#$_SESSION['articles_category'] = $category;
}

// Testing snippet for parameters
$smarty->assign('debug','<div style="display:block;overflow:auto;background:#fff;color:#000;padding:5px;border:2px solid #f00;"><u>$_REQUEST</u>:<br />'.print_r($_REQUEST,true).'<hr /><u>$_POST</u>:<br />'.print_r($_POST,true).'<hr /><u>$_GET</u>:<br />'.print_r($_GET,true).'<hr /><u>GetModuleParameters($id=\''.$id.'\')</u>:<br />'.print_r($ops->GetModuleParameters($id),true).'<hr /><u>Variablen</u>:<br />Category: '.$category.'<br />Mode: '.$mode.'<br />Template: '.$template.'<br /><hr /><u>$params</u>:<br />'.print_r($params,true).'</div>');
$smarty->assign('debug_session','<div style="display:block;overflow:auto;background:#fff;color:#000;padding:5px;border:2px solid #f00;"><pre><u>$_SESSION</u>:<br />'.print_r($_SESSION,true).'</pre></div>');

// Show category listing
if ($mode==$mode_categories) {

	// Set template + ReturnID
	if (!$template) $template = $template_categories;
	if ($page_categories) $returnid = $page_categories;
	if (!$returnid) $returnid = $this->GetPreference('returnid');

	$rowarray = array();
	$rowclass = 'row1';
	// Get categories
	$categories = $db->GetAll('SELECT entry_id,title,short_desc,long_desc,image_url,sort_order,returnid,seo_url FROM '.cms_db_prefix().'module_articles_category WHERE active=1 ORDER by sort_order DESC,entry_id DESC', array());
	if (!is_array($categories)) $categories = array();
	foreach ($categories as $cat) {
		// Build a new row
		$row = new StdClass();
		$row->rowclass = $rowclass;
		// Get data in array
		$row->category = (int)$cat['entry_id'];
		$row->title = $cat['title'];
		$row->returnid = $cat['returnid'];
		$row->seo_url = $cat['seo_url'];
		#$row->titlelink = $this->CreateLink($id, 'default', $returnid, '', array('categories'=>urlencode($row->title)), '', true, $inline, '', false, 'shop/'.$returnid.'/'.$row->category.'/'.$this->UrlSeoDecode($row->title));
		#$row->titlelink = $this->CreateLink($id, 'default', $returnid, '', array('category'=>$row->category,'template'=>urlencode('articles')), '', true, $inline, '', false);
		#$row->categorieslink = $this->CreateLink($id, 'default', $returnid, '', array('category'=>$row->category,'mode'=>$mode_categories), '', true, $inline, '', false, $this->PageID2Url($returnid).'/'.$returnid.'/'.$mode_categories);
		if (!$page_articles || (int)$page_articles<1) $page_articles = $returnid;
		$row->articleslink = $this->CreateLink($id, 'default', $page_articles, '', array('category'=>$row->category,'mode'=>$mode_articles), '', true, $inline, '', false, $row->seo_url ? $row->seo_url : $this->PageID2Url($page_articles).'/'.$page_articles.'/'.$mode_articles.'/'.$row->category.'/'.$this->UrlSeoDecode($row->title));
		$row->summary = $cat['short_desc'];
		trigger_error("\$config['image_uploads_url'] = {$config['image_uploads_url']}");
		$row->image = $cat['image_url'] ? $config['image_uploads_url'].'/Articles/categories/'.$cat['entry_id'].'/'.$cat['image_url'] : '';
		$row->order = $cat['sort_order'];
		// Merge new domain to array
		array_push ($rowarray, $row);
		// Alternate row color
		($rowclass == 'row1' ? $rowclass = 'row2' : $rowclass = 'row1');
	}
	// Assign smarty vars
	$smarty->assign('categories',$rowarray);

}

// Show Articles
else if ($mode==$mode_articles) {

	// Set template + ReturnID
	if (!$template) $template = $template_articles;
	if ($page_articles) $returnid = $page_articles;
	if (!$returnid) $returnid = $this->GetPreference('returnid');

	$rowarray = array();
	$rowclass = 'row1';
	// Get articles
	$categoryquery = $category ? ' AND AC.cat_id='.(int)$category : '';
	if ($categoryquery) {
		$query = '	SELECT A.entry_id entry_id,A.title title,A.short_desc short_desc,A.long_desc long_desc,A.user_id user_id,A.datetime datetime,A.image_text image_text,A.gallery_id gallery_id,A.start_date start_date,A.end_date end_date,A.detail_link detail_link,A.image_url image_url,A.sort_order sort_order,A.price price,A.vat vat,A.returnid returnid,A.seo_url seo_url
					FROM '.cms_db_prefix().'module_articles_articles A,'.cms_db_prefix().'module_articles_category_articles AC,'.cms_db_prefix().'module_articles_category C
					WHERE A.entry_id=AC.article_id AND C.entry_id=AC.cat_id AND A.active=1 AND C.active=1'.$categoryquery.$pastonly.$cutoff.'
					ORDER BY A.sort_order,A.datetime ' . $sortorder . ' LIMIT ' . $articleslimit;
	} else {
		$query = 'SELECT * FROM '.cms_db_prefix().'module_articles_articles WHERE entry_id>0'.$pastonly.$cutoff.' AND active = 1 ORDER BY sort_order,datetime ' . $sortorder . ' LIMIT ' . $articleslimit;
	}
	$articles = $db->GetAll($query, array());
	if (!is_array($articles)) $articles = array();
	foreach ($articles as $ar) {
		// Build a new row
		$row = new StdClass();
		$row->rowclass = $rowclass;
		// Get data in array
		$row->article = (int)$ar['entry_id'];
		$row->user_id = (int)$ar['user_id'];
		$row->gallery_id = (int)$ar['gallery_id'];
		$row->datetime = (int)$ar['datetime'];
		$row->image_text = $ar['image_text'];
		$row->title = $ar['title'];
		$row->summary = $ar['short_desc'];
		$row->returnid = $ar['returnid'];
		if (!$row->returnid) $row->returnid = $returnid;
		$row->seo_url = $ar['seo_url'];
		$row->image = $ar['image_url'] ? $config['image_uploads_url'].'/Articles/articles/'.$ar['entry_id'].'/'.$ar['image_url'] : '';
		#$row->articleslink = $this->CreateLink($id, 'default', $returnid, '', $category ? array('category'=>$category,'mode'=>$mode_articles) : array('mode'=>'articles'), '', true, $inline, '', false, $this->PageID2Url($returnid).'/'.$returnid.'/'.$mode_articles.'/'.$categoryinfos['entry_id'].'/'.$this->UrlSeoDecode($categoryinfos['title']));
		if (!$page_article || (int)$page_article<1) $page_article = $returnid;
		$row->articlelink = $this->CreateLink($id, 'default', $page_article, '', $category ? array('article'=>$row->article,'category'=>$category,'mode'=>$mode_article) : array('article'=>$row->article,'mode'=>$mode_article), '', true, $inline, '', false, $row->seo_url ? $row->seo_url : $this->PageID2Url($page_article).'/'.$page_article.'/'.$mode_article.'/'.$row->article.'/'.$this->UrlSeoDecode($row->title));
		$row->content = $ar['long_desc'];
		if ($smarty->assign('use_price', $this->GetPreference('price_use'))) $row->price = number_format(str_replace(',','.',$ar['price']), 2, ',', '.').' '.$this->GetPreference('currency');
		#$row->vat = number_format(str_replace(',','.',($ar['price'] * ($ar['vat'] / 100))), 2, ',', '.').' '.$this->GetPreference('currency');
		if ($smarty->assign('use_price', $this->GetPreference('vat_use'))) $row->vat = number_format(str_replace(',','.',($ar['price'] - ($ar['price'] / (1 + ($ar['vat'] / 100))))), 2, ',', '.').' '.$this->GetPreference('currency');
		if ($smarty->assign('use_price', $this->GetPreference('vat_use'))) $row->vatp = $ar['vat'];
		$row->linkid = (int)$ar['detail_link'];
		$row->linkalias = $this->GetLinkAlias($row->linkid);
		$row->start = $ar['start_date'];
		$row->hcstart = strftime("%Y-%m-%dT%H:%M:%S", strtotime($ar['start_date']));
		$row->end = $ar['end_date'];
		$row->hcend = strftime("%Y-%m-%dT%H:%M:%S", strtotime($ar['end_date']));
		if(strtotime($ar['end_date']) < time()) {
			$row->past = 'true';
		} else {
			$row->past = 'false';
		}
		$row->order = $ar['sort_order'];
		// Merge new domain to array
		array_push ($rowarray, $row);
		// Alternate row color
		($rowclass == 'row1' ? $rowclass = 'row2' : $rowclass = 'row1');
	}
	// Assign smarty vars
	$smarty->assign('articles',$rowarray);
	$smarty->assign('categorytitle',$categorytitle);
	$smarty->assign('categorysummary',$categorysummary);
	if (!$page_categories || (int)$page_categories<1) $page_categories = $returnid;
	$smarty->assign('categorieslink', $this->CreateLink($id, 'default', $page_categories, '', $category ? array('category'=>$category,'mode'=>$mode_categories) : array('mode'=>$mode_categories), '', true, $inline, '', false, $this->PageID2Url($page_categories).'/'.$page_categories.'/'.$mode_categories));

}

// Show article details
else if ($mode==$mode_article) {

	// Set template + ReturnID
	if (!$template) $template = $template_article;
	if ($page_article) $returnid = $page_article;
	if (!$returnid) $returnid = $this->GetPreference('returnid');

	// build and execute query
	$articleinfo = $db->GetRow('SELECT entry_id,user_id,datetime,title,short_desc,long_desc,image_url,image_text,gallery_id,sort_order,price,vat,cart,availibility,delivery_time,shipping_costs,returnid,seo_url,meta_title,meta_description,noindex,nofollow,noarchive,noodp,notranslate,created,modified FROM '.cms_db_prefix().'module_articles_articles WHERE entry_id = ? AND active = 1', array($article));
	if (!is_array($articleinfo)) $articleinfo = array();

	// assign smarty vars
	// Build a new row
	$row = new StdClass();
	// Get data in array
	$row->article = (int)$articleinfo['entry_id'];
	$row->user_id = (int)$articleinfo['user_id'];
	$row->datetime = (int)$articleinfo['datetime'];
	$row->created = (int)$articleinfo['created'];
	$row->modified = (int)$articleinfo['modified'];
	$row->title = $articleinfo['title'];
	$row->summary = $articleinfo['short_desc'];
	$row->returnid = $articleinfo['returnid'] ? $articleinfo['returnid'] : $returnid;
	if (!$row->returnid) $row->returnid = $returnid;
	$row->seo_url = $articleinfo['seo_url'];
	$row->meta_title = $articleinfo['meta_title'];
	$row->meta_description = $articleinfo['meta_description'];
	$row->noindex = $articleinfo['noindex'];
	$row->nofollow = $articleinfo['nofollow'];
	$row->noarchive = $articleinfo['noarchive'];
	$row->noodp = $articleinfo['noodp'];
	$row->notranslate = $articleinfo['notranslate'];
	$row->image = $articleinfo['image_url'] ? $config['image_uploads_url'].'/Articles/articles/'.$articleinfo['entry_id'].'/'.$articleinfo['image_url'] : '';
	$imagepath = $articleinfo['image_url'] ? $config['image_uploads_path'].'/Articles/articles/'.$articleinfo['entry_id'].'/'.$articleinfo['image_url'] : '';
	if ($imagepath) {
		list($imgwidth, $imgheight, $imgtype, $imgattr) = getimagesize($imagepath);
		$row->image_width=$imgwidth;
		$row->image_height=$imgheight;
	} 
	$row->image_text = $articleinfo['image_text'];
	$row->gallery_id = (int)$articleinfo['gallery_id'];
	#$row->categorieslink = $this->CreateLink($id, 'default', $returnid, '', $category ? array('category'=>$category,'mode'=>'categories') : array('mode'=>'categories'), '', true, $inline, '', false);
	#$row->categorylink = $this->CreateLink($id, 'default', $returnid, '', $category ? array('category'=>$category,'mode'=>'category') : array('mode'=>'category'), '', true, $inline, '', false);
	#$row->articleslink = $this->CreateLink($id, 'default', $returnid, '', $category ? array('category'=>$category,'mode'=>'articles') : array('mode'=>'articles'), '', true, $inline, '', false);
	#$row->articlelink = $this->CreateLink($id, 'default', $returnid, '', $category ? array('article'=>$row->article,'category'=>$category,'mode'=>'article') : array('article'=>$row->article,'mode'=>'article'), '', true, false, '', false);
	$row->content = $articleinfo['long_desc'];
	$row->price = number_format(str_replace(',','.',$articleinfo['price']), 2, ',', '.').' '.$this->GetPreference('currency');
	$row->vat = number_format(str_replace(',','.',($articleinfo['price'] - ($articleinfo['price'] / (1 + ($articleinfo['vat'] / 100))))), 2, ',', '.').' '.$this->GetPreference('currency');
	$row->vatp = $articleinfo['vat'];
	#$row->vat = (float)$articleinfo['price'] * 0.19;
	#$row->vat = number_format(str_replace(',','.',$row->vat), 2, ',', '.').' '.$this->GetPreference('currency');
	$row->linkid = (int)$articleinfo['detail_link'];
	$row->linkalias = $this->GetLinkAlias($row->linkid);
	$row->start = $articleinfo['start_date'];
	$row->hcstart = strftime("%Y-%m-%dT%H:%M:%S", strtotime($articleinfo['start_date']));
	$row->end = $articleinfo['end_date'];
	$row->hcend = strftime("%Y-%m-%dT%H:%M:%S", strtotime($articleinfo['end_date']));
	if(strtotime($articleinfo['end_date']) < time()) {
		$row->past = 'true';
	} else {
		$row->past = 'false';
	}
	$row->order = $articleinfo['sort_order'];
	$row->showcart = $articleinfo['cart'];
	$row->availibility = $articleinfo['availibility'];
	$row->delivery_time = $articleinfo['delivery_time'];
	$row->shipping_costs = number_format(str_replace(',','.',$articleinfo['shipping_costs']), 2, ',', '.').' '.$this->GetPreference('currency');

	// Assign smarty vars
	$smarty->assign('article',$row);
	if (!$page_articles || (int)$page_articles<1) $page_articles = $returnid;
	$smarty->assign('articleslink', $this->CreateLink($id, 'default', $page_articles, '', array('category'=>$category,'mode'=>$mode_articles), '', true, $inline, '', false, $categoryinfos['seo_url'] ? $categoryinfos['seo_url'] : $this->PageID2Url($page_articles).'/'.$page_articles.'/'.$mode_articles.'/'.$category.'/'.$this->UrlSeoDecode($categoryinfos['title'])));
	$smarty->assign('articleslinktitle', $categoryinfos['title']);

	// build cart
	$cart = '';
	// get amount for this article
	$amount = 1;
	// Assign form smarty vars
	$smarty->assign('formid',$id);
	$smarty->assign('formstart',$this->CreateFrontendFormStart($id,$returnid,'cart','post','multipart/form-data',$inline,'',array())); // $id,$returnid,$action='default',$method='post',$enctype='',$inline=true,$idsuffix='',$params=array()
	#$smarty->assign('formstart','<form id="'.$id.'moduleform_1" method="post" action="'.$_SERVER['REQUEST_URI'].'" class="cms_form" enctype="multipart/form-data">');
    $smarty->assign('formend', $this->CreateFormEnd());
	$smarty->assign('submit', $this->CreateInputSubmit($id,'add_to_cart',$this->Lang('add_to_cart')));
	$smarty->assign('submitimage', $this->CreateInputSubmit($id,'add_to_cart','&nbsp;','','/modules/Articles/images/cartbutton.png')); // $id, $name, $value='', $addttext='', $image='', $confirmtext=''
    $smarty->assign('articleid', $this->CreateInputHidden($id,'articleid',(int)$articleinfo['entry_id'])); // $id, $name, $value='', $addttext=''
	$smarty->assign('mode', $this->CreateInputHidden($id,'mode','cartadd')); // $id, $name, $value='', $addttext=''
	$smarty->assign('amount', $this->CreateInputText($id,'amount',$amount,3,3,'class="article_amount"')); // $id, $name, $value='', $size='10', $maxlength='255', $addttext=''

}

else {
	echo '<div style="display:block;overflow:auto;background:#fff;color:#000;padding:5px;border:2px solid #f00;">ERROR: No such mode: <b>'.$mode.'</b></div>';
}

// Give Settings to Smarty
$smarty->assign('use_image', $this->GetPreference('image_use') ? true : false);
$smarty->assign('use_url', $this->GetPreference('url_use') ? true : false);
$smarty->assign('use_detailpage', $this->GetPreference('detailpage_use') ? true : false);
$smarty->assign('use_dates', $this->GetPreference('dates_use') ? true : false);
$smarty->assign('use_availibility', $this->GetPreference('availibility_use') ? true : false);
$smarty->assign('use_deliverytime', $this->GetPreference('deliverytime_use') ? true : false);
$smarty->assign('use_shippingcosts', $this->GetPreference('shippingcosts_use') ? true : false);
$smarty->assign('use_price', $this->GetPreference('price_use') ? true : false);
$smarty->assign('vat_use', $this->GetPreference('vat_use') ? true : false);
$smarty->assign('currency', $this->GetPreference('currency'));
$smarty->assign('use_cart', $this->GetPreference('cart_use') ? true : false);
$smarty->assign('use_seo', $this->GetPreference('seo_use') ? true : false);

// Get template and process it
$template_content = $template ? $this->GetTemplate($template, $this->GetName()) : '';
#$items = Array();
if($template_content) {
	//echo $this->ProcessTemplateFromData($template_content);
	echo $this->ProcessTemplateFromDatabase($template,'',true);
} else {
	echo '<div style="display:block;overflow:auto;background:#fff;color:#000;padding:5px;border:2px solid #f00;">ERROR: No such template: <b>'.$params['template'].'</b></div>';
}

// EOF