<?php
class Put_form_Core{
	function __construct(){
	}
	//标准文本输入
	function text($name=false,$input_title=false,$value=false,$dataType=false,$msg=false,$description=false,$default_value=false,$input_lenght=false,$style=''){
		$input['title']	=	$input_title;
		$input['description']	=	$description;
		$input['input']	=	"<input name=\"{form}[$name][]\" id=\"$name\" value=\"$default_value\" type=\"text\" class=\"text\" dataType=\"$dataType\" msg=\"$msg\"";
		if($input_lenght>0){
			$input['input']	.=	" maxlength=\"$input_lenght\"";
		}
		$input['input']		.=	" style=\"$style\"/>";
		return $input;
	}
	//颜色选择器
	function color($name=false,$value=false,$dataType=false,$msg=false){
	}
	//复选框
	function checkbox($name=false,$input_title=false,$value=false,$dataType=false,$msg=false,$description=false,$default_value=false,$input_lenght=false){
		$input['title']	=	$input_title;
		$inputstring	=	'';
		if(!is_array($default_value)){
			$default_value		=	array();
			$default_value[]	=	'无';
		}
		foreach($default_value as $key=>$dvalue){
			if($key==$value){
				$checked	=	" checked='checked'";
			}
			else{
				$checked	=	"";
			}
			$inputstring		.=	"<input type='checkbox' name='{form}[$name][]' value='$key' $checked>$dvalue &nbsp;&nbsp;";
		}
		$input['input']		=	$inputstring;
		$input['description']	=	$description;
		return $input;
	}
	//单一图片上传
	function singlePicture($name=false,$input_title=false,$value=false,$dataType=false,$msg=false,$description=false,$default_value=false,$input_lenght=false){
		$input['title']			=	$input_title;
		if(file_exists($value)){
			$input['description']	=	"<img src='".BASEURL.$value."' height=100 id='preview_thumb'>";
		}
		else{
			$input['description']	=	"<img src='".BASEURL."public/share/nopic.png' height=100 id='preview_thumb'>";
		}
		$inputstring			=	"<input name=\"{form}[$name][]\" class='text' id=\"$name\" value=\"$value\" type=\"text\" dataType=\"$dataType\" msg=\"$msg\" size=\"$input_lenght\"/>";
		$inputstring			.=	"<input type=\"button\" name=\"upload\" value=\"上传图片\" rel=\"{type:'iframe',size:{w:450,h:300},url:'".BASEURI."file_upload/normal/".channel_id."/$name'}\" class='Dialog button'/>";
		$inputstring			.=	"<input type=\"button\" name=\"editimg\" value=\"站内选择\" rel=\"{type:'iframe',size:{w:700,h:450},url:'".BASEURI."file_manager/selectattach/".$name."'}\" class='Dialog button'/>";
		$input['input']			=	$inputstring;
		return $input;
	}
	//日期
	function dateText($name=false,$input_title=false,$value=false,$dataType=false,$msg=false,$description=false,$default_value=false,$input_lenght=false){
		
	}
	//单选框
	function radio($name=false,$input_title=false,$value=false,$dataType=false,$msg=false,$description=false,$default_value=false,$input_lenght=false){
		$input['title']	=	$input_title;
		$inputstring	=	'';
		if(!is_array($default_value)){
			$default_value[]	=	'无';
		}
		foreach($default_value as $key=>$dvalue){
			if($key==$value){
				$checked	=	" checked='checked'";
			}
			else{
				$checked	=	"";
			}
			$inputstring		.=	"<input type='radio' name='{form}[$name][]' value='$key' $checked>$dvalue &nbsp;&nbsp;";
		}
		$input['input']		=	$inputstring;
		$input['description']	=	$description;
		return $input;
	}
	//简易编辑器
	function simpleEdit($name=false,$input_title=false,$value=false,$dataType=false,$msg=false,$description=false,$default_value=false,$input_lenght=false){
		$inputstring	="
	<script language=\"javascript\" type=\"text/javascript\">
		tinyMCE.init({
			mode : \"exact\",
			elements : \"$name\",
			theme : \"advanced\",
			skin : \"o2k7\",
			language:\"zh\",
			theme_advanced_toolbar_location : \"top\",
			theme_advanced_toolbar_align : \"center\",
			theme_advanced_buttons1 : \"bold,italic,underline|,justifyleft,justifycenter,justifyright,justifyfull,|,fontselect,fontsizeselect\",
			theme_advanced_buttons2 : \"\",
			theme_advanced_buttons3 : \"\",
			theme_advanced_buttons4 : \"\"
		});
	</script>	
	";
		$inputstring	.=	"<textarea name='$name' id='$name' dataType='$dataType' 'msg'='$msg' style='width:350px;height:100px;' >$default_value</textarea>";
		$input['input']			=	$inputstring;
		$input['title']			=	$input_title;
		$input['description']	=	$description;
		return $input;
	}
	//高级编辑器
	function advancedEdit($name=false,$input_title=false,$value=false,$dataType=false,$msg=false,$description=false,$default_value=false,$input_lenght=false){
		$inputstring="
	<script type=\"text/javascript\">
	tinyMCE.init({
		// General options
		relative_urls: false,
		nowrap : true,
	    remove_script_host: false,
		mode : \"exact\",
		elements : \"$name\",
		theme : \"advanced\",
		language:\"zh\",
		plugins : \"safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template\",

		// Theme options
		theme_advanced_buttons1 : \"save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect\",
		theme_advanced_buttons2 : \"cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor\",
		theme_advanced_buttons3 : \"tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen\",
		theme_advanced_buttons4 : \"insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak\",
		theme_advanced_toolbar_location : \"top\",
		theme_advanced_toolbar_align : \"left\",
		theme_advanced_statusbar_location : \"bottom\",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : \"css/content.css\",
		file_browser_callback : \"mcImageManager.filebrowserCallBack\",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : \"lists/template_list.js\",
		external_link_list_url : \"lists/link_list.js\",
		external_image_list_url : \"lists/image_list.js\",
		media_external_list_url : \"lists/media_list.js\",

		// Replace values for the template plugin
		template_replace_values : {
			username : \"Some User\",
			staffid : \"991234\"
		}
	});
</script>
	";
		$inputstring.="<textarea name='{form}[$name][]' id='$name' dataType='$dataType' 'msg'='$msg' style='width:600px;height:400px;' >$value</textarea>";		
		$input['title']	=	$input_title;
		$input['input']	=	$inputstring;
		$input['description']	=	$description;
		return $input;
	}
	//模板选择器
	function tplText($name=false,$input_title=false,$value=false,$dataType=false,$msg=false,$description=false,$default_value=false,$input_lenght=false){
		$input['input']			=	"<input type=\"text\" name=\"{form}[$name][]\" value=\"$value\" id=\"$name\" class=\"text\"/><input type=\"button\" class=\"button\" onclick=\"window.open('".BASEURI."templates/select/$name')\" value='选择' />";
		$input['title']			=	$input_title;
		$input['description']	=	$description;
		return $input;
	}
	//下拉菜单选择器
	function select($name=false,$input_title=false,$defaultValue=false,$description,$inputValue="",$dataType,$error_msg){
		$tmpStr="<select name='{form}[$name][]' dataType='$dataType' msg='$error_msg'>";
		if(!is_array($defaultValue)){
			$defaultValue[]	=	'无';
		}
		foreach ($defaultValue as $key=>$value){
			if($key==$inputValue){
				$selected	=	" selected";
			}
			else{
				$selected	=	"";
			}
			@$tmpStr.="<option value='$key' $selected>".$value;
		}
		$tmpStr.="</select>";
		$input['input']	=	$tmpStr;
		$input['title']	=	$input_title;
		$input['description']	=$description;
		return $input;
	}
	//分类选择器
	function category($name=false,$input_title=false,$defaultValue=false,$description,$inputValue="",$dataType,$error_msg){
		$tmpStr="<select name='{form}[$name][]' dataType='$dataType' msg='$error_msg'>";
		if(!is_array($defaultValue)){
			$defaultValue[]	=	'无';
		}
		foreach ($defaultValue as $key=>$value){
			if($key==$inputValue){
				$selected	=	" selected";
			}
			else{
				$selected	=	"";
			}
			@$tmpStr.="<option value='$key' $selected>".$value;
		}
		$tmpStr.="</select>";
		$input['input']	=	$tmpStr."&nbsp;&nbsp;［<a href='".BASEURI."model_category/'>添加分类</a>］";
		$input['title']	=	$input_title;
		$input['description']	=$description;
		return $input;
	}
	//普通文本编辑
	function textarea($name=false,$input_title=false,$value=false,$dataType=false,$msg=false,$description=false,$default_value=false,$input_lenght=false){
		$tmpStr="<textarea name=\"{form}[$name][]\" id=\"$name\" class=\"textarea\" dataType=\"$dataType\" msg=\"$msg\"/>$default_value</textarea>";
		$input['input']	=	$tmpStr;
		$input['title']	=	$input_title;
		$input['description']	=$description;
		return $input;

	}
	//隐藏input
	function hidden(){
	}
	//密码输入框
	function password(){
	}
}