<?php
 /**
 *      [XCECP] (C) COLNET Inc.
 *      This is NOT a freeware, use is subject to license terms
 */
if(!defined("IN_QKWEB")){exit("Access Denied");}
function smarty_function_serializetoform($params, $template)
{	
    $data = (isset($params['data']))?$params['data']:'';
	if(!$data){return;}
	$arr = @unserialize($data);
	if(!is_array($arr)){return false;}
	$ret = '';
	foreach($arr as $item){
		if($item['class']){$class=' '.$item['class'];}else{$class='';}
		switch($item['type']){
			case 'text':
				$ipt = '<div class="form-line"><label class="label">'.$item['label'].'：</label><div class="element"><input type="text" name="'.$item['name'].'" class="text'.$class.'" value="'.$item['value'].'" /><label class="tip">'.$item['desc'].'</label></div></div>'."\r\n";
				break;
			case 'textarea':
				$ipt = '<div class="form-line"><label class="label">'.$item['label'].'：</label><div class="element"><textarea name="'.$item['name'].'" class="text'.$class.'">'.$item['value'].'</textarea><label class="tip">'.$item['desc'].'</label></div></div>'."\r\n";
				break;
			//case 'radio':
			//	$ipt = '<div class="form-line"><label class="label">'.$item['label'].'：</label><div class="element"><textarea name="'.$item['name'].'" class="text'.$class.'">'.$item['value'].'</textarea><label class="tip">'.$item['desc'].'</label></div></div>'."\r\n";
			//	break;
			case 'radio':
				$ipt = '<div class="form-line"><label class="label">'.$item['label'].'：</label><div class="element">';
					foreach($item['values'] as $key=>$val){
						if($key==$item['value']){$checked=' checked';}else{$checked='';}
						$ipt.= '<input type="radio" name="'.$item['name'].'" value="'.$key.'"'.$checked.'/>'.$val.' ';
					}
					//<textarea name="'.$item['name'].'" class="text'.$class.'">'.$item['value'].'</textarea>
				$ipt .= '<label class="tip">'.$item['desc'].'</label></div></div>'."\r\n";
				break;
			default:$ipt='';break;
		}
		$ret .= $ipt;
	}
    return $ret;
}

?>