<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

function smarty_function_form_element($params, $template)
{
	if (!$params['item']) return;
	switch($params['item']->getType()) {
		case('select'):
			$type='select';
			break;
		case('checkbox'):
			$type='checkbox';
			break;
		case('textarea'):
			$type='textarea';
			break;
		case('hidden'):
			$type='hidden';
			break;
		case('script'):
			$type='script';
			break;
		case('static'):
			$type='static';
			break;
		case('submit'):
			$type='submit';
			break;
		case('text'):
		case('password'):
		case('email'):
		case('date'):
			$type='text';
			break;
		case('file'):
			$type='file';
			break;
		case('fieldset'):
			$type='fieldset';
			break;
		case('form'):
			$type='form';
			break;
		default:
			die('form_element no type: '.$params['item']->getType());
	}
	$module=($params['module'])?$params['module']:'forms';
	
	return $template->getSubTemplate(
		$module."/".$type.".tpl", $template->cache_id,
		$template->compile_id, null, null,
		$params, Smarty::SCOPE_LOCAL
	);
}