<?php
/*
 +----------------------------------------------------------------------
 | TEMMOKUMVC [ NO BEST, ONLY BETTER ]
 +----------------------------------------------------------------------
 | Copyright (c) 2018~2019 https://www.temmoku.cn All rights reserved.
 +----------------------------------------------------------------------
 | Author: 张宗强 Email:webmaster@temmoku.cn QQ:158726877 516669373 TEL:17895221001 微信:temmokumvc
 +---------------------------------------------------------------------- 
*/
namespace temmoku\lib;
class custom_model{
	protected $_ModelDB=[];
	protected $_id;
	protected $_data=[];
	protected $_Return='';
	protected $_Model=[];
	protected $make_html=false;
	protected $admin=''; //来自后台还是前台true 为后台
	protected $from_module=''; //来自哪个模块
	public function Custom_Model_Get($id,$Model=[],$data=[],$make_html=false,$admin='admin',$from_module=''){
		$this->make_html=$make_html;
		$this->admin=$admin;
		$this->from_module=$from_module;
		$this->_id		=	$id;
		$this->_ModelDB	=	$Model;
		$this->_data	=	$data;
		foreach($this->_ModelDB AS $data){
			if($data['setting']){
				$data['setting']=unserialize($data['setting']);
			}
			$this->_Model		=	$data;
			$arr[]=	$this->Custom_Model_Distinguish_Type();
		}
		return implode("",$arr);
	}

	public function Custom_Model_Distinguish_Type(){
		switch ($this->_Model['type'])
		{
			case 'Checkbox':
				return	$this->Custom_Model_Checkbox();
				break;  
			case 'Date':
			  	return  $this->Custom_Model_Date();
			  	break;
			case 'File':
			  	return $this->Custom_Model_File();
			  	break;
			case 'Files':
			  	return $this->Custom_Model_Files();
			  	break;
			case 'Radio':
			  	return $this->Custom_Model_Radio();
			  	break;
			case 'Select':
			  	return $this->Custom_Model_Select();
			  	break;
			case 'Text':
			  	return	$this->Custom_Model_Text();
			  	break;
			case 'Textarea':
			  	return $this->Custom_Model_Textarea();
			  	break;
			case 'Price':
			  	return $this->Custom_Model_Price();
			  	break;
			default:
				return $this->Custom_Model_Ueditor();
		}
	}
	
	public function Custom_Model_Price(){
		$html='';
		$price_select_html.='<li id="li_%s_%s">
			<span><select name="_post[%s][text][]">%s</select></span>
			<span><select name="_post[%s][type][]"><option value="1" %s>原有价格直接增加</option><option value="0" %s>以新价格</option></select></span>
			<span>属性价格：<input type="text" value="%s"  name="_post[%s][price][]"  class="layui-input my-input" />&nbsp;&nbsp;&nbsp;&nbsp;元</span>
			<span>库存：<input type="text" value="%s"  name="_post[%s][stock][]"  class="layui-input my-input" /></span>
			<input type="hidden" value="%s"  name="_post[%s][attr_id][]"  />
			<span>	<a href="javascript:" class="layui-btn layui-btn-xs" onclick="del_%s_price(%s)">删除</a></span></li>';
		$price_check_html.='<li id="li_%s_%s"><span><input type="text" placeholder="请输入名称" value="%s" name="_post[%s][text][]"  class="layui-input my-input" /></span>
			<span><select name="_post[%s][type][]"><option value="1" %s>原有价格直接增加</option><option value="0" %s>以新价格</option></select></span>
			<span>	属性价格：<input value="%s" type="text" name="_post[%s][price][]"  class="layui-input my-input" />&nbsp;&nbsp;&nbsp;&nbsp;元</span>
			<span>	库存：<input value="%s" type="text" name="_post[%s][stock][]"  class="layui-input my-input" /></span>
			<span>	<a href="javascript:" class="layui-btn layui-btn-xs" onclick="del_%s_price(%s)">删除</a></span></li>';
			
		if($this->make_html){
			$module_html="
								\$ziduan_neirong=explode(PHP_EOL,\$field['".$this->_Model['field']."']['value']);
								\$selected=\"<option value=\\\"\\\">请选择...</option>\";
								foreach(\$ziduan_neirong AS \$_VALUE){
									\$_VALUE=trim(\$_VALUE);
									\$_selected='';
									if(\$text==\$_VALUE){
										\$_selected=' selected';
									}
									\$selected.=\"<option value=\\\"\$_VALUE\\\" \$_selected>\$_VALUE</option>\";
								}"
			;
			$this_module_html='';
			if($this->_Model['value']){
				$ziduan_neirong=explode(PHP_EOL,$this->_Model['value']);
				$selected="<option value=\"\">请选择...</option>";
				foreach($ziduan_neirong AS $VALUE){
					$VALUE=trim($VALUE);
					$selected.="<option value=\"$VALUE\">$VALUE</option>";
				}
				$this_module_html=$module_html;
				$this_html=addslashes(sprintf($price_select_html,$this->_Model['field'],"\$key",$this->_Model['field'],"\$selected",$this->_Model['field'],"\$_type[1]","\$_type[0]","\$price",$this->_Model['field'],"\$stock",$this->_Model['field'],"\$attr_id",$this->_Model['field'],$this->_Model['field'],"\$key"));
			}else{
				$this_html=addslashes(sprintf($price_check_html,$this->_Model['field'],'$key','$text',$this->_Model['field'],$this->_Model['field'],'$_type[1]','$_type[0]','$price',$this->_Model['field'],'$stock',$this->_Model['field'],$this->_Model['field'],'$key'));
			}
			$html.="
					<?php 
						unset(\$text,\$type,\$price,\$stock,\$attr_id,\$_type['1'],\$_type['0'],\$_type[\$type]);
						if(\$edit && \$edit['".$this->_Model['field']."']){
							\$".$this->_Model['field']."= unserialize(\$edit['".$this->_Model['field']."']);
							\$num=count(\$".$this->_Model['field'].");
							\$html_".$this->_Model['field']."='';
							foreach(\$".$this->_Model['field']." AS \$key=>\$row){
								\$text=\$row['name'];
								\$type=\$row['type'];
								\$price=\$row['price'];
								\$stock=\$row['stock'];
								\$attr_id=\$row['attr_id'];
								\$_type['1']='';
								\$_type['0']='';
								\$_type[\$type]='selected';
								$this_module_html
								\$html_".$this->_Model['field'].".=\"$this_html\";
							}
						}else{
							$this_module_html
							\$html_".$this->_Model['field'].".=\"$this_html\";
						}
					php?>
				";
				$price_html ="<?php echo  \$html_".$this->_Model['field']." ?>";
		}else{
			if($this->_data[$this->_Model['field']]){
				
				$priceDB=unserialize($this->_data[$this->_Model['field']]);
				$num=count($priceDB);
				$price_html='';
				foreach($priceDB AS $key=>$row){
					$text=$row['name'];
					$type=$row['type'];
					$price=$row['price'];
					$stock=$row['stock'];
					$attr_id=$row['attr_id'];
					$_type['1']='';
					$_type['0']='';
					$_type[$type]='selected';
					if($this->_Model['value']){
						$ziduan_neirong=explode(PHP_EOL,$this->_Model['value']);
						$selected="<option value=\"\">请选择...</option>";
						foreach($ziduan_neirong AS $_VALUE){
							$_VALUE=trim($_VALUE);
							$_selected='';
							if($text==$_VALUE){
								$_selected=' selected';
							}
							$selected.="<option value=\"$_VALUE\" $_selected>$_VALUE</option>";
						}
						$price_html.=sprintf($price_select_html,$this->_Model['field'],$key,$this->_Model['field'],$selected,$this->_Model['field'],$_type[1],$_type[0],$price,$this->_Model['field'],$stock,$this->_Model['field'],$attr_id,$this->_Model['field'],$this->_Model['field'],$key);
					}else{
						$price_html.=sprintf($price_check_html,$this->_Model['field'],$key,$text,$this->_Model['field'],$this->_Model['field'],$_type[1],$_type[0],$price,$this->_Model['field'],$stock,$this->_Model['field'],$this->_Model['field'],$key);
					}
				}
			}else{
				$num='1';
				if($this->_Model['value']){
					$ziduan_neirong=explode(PHP_EOL,$this->_Model['value']);
					$selected[]="<option value=\"\">请选择...</option>";
					foreach($ziduan_neirong AS $VALUE){
						$VALUE=trim($VALUE);
						$selected[]="<option value=\"$VALUE\">$VALUE</option>";
					}
					$selected=implode('',$selected);
					$price_html.=sprintf($price_select_html,$this->_Model['field'],'0',$this->_Model['field'],$selected,$this->_Model['field'],'','','',$this->_Model['field'],'',$this->_Model['field'],$attr_id,$this->_Model['field'],$this->_Model['field'],'0');
				}else{
					$price_html=sprintf($price_check_html,$this->_Model['field'],"0","",$this->_Model['field'],$this->_Model['field'],$_type[1],$_type[0],"",$this->_Model['field'],$stock,$this->_Model['field'],$this->_Model['field'],"0");
				}
			}
		}
		if($this->_Model['value']){
			$java='<li id="li_'.$this->_Model['field'].'_\'+num+\'"><span><select name="_post['.$this->_Model['field'].'][text][]">'.$selected.'</select></span><span><select name="_post['.$this->_Model['field'].'][type][]"><option value="1">原有价格直接增加</option><option value="0">以新价格</option></select></span><span>属性价格：<input type="text" name="_post['.$this->_Model['field'].'][price][]"  class="layui-input my-input" />&nbsp;&nbsp;&nbsp;&nbsp;元 </span><span>库存：<input type="text" name="_post['.$this->_Model['field'].'][stock][]"  class="layui-input my-input" /></span><span><a href="javascript:" class="layui-btn layui-btn-xs" onclick="del_'.$this->_Model['field'].'_price(\'+num+\')">删除</a></span></li>';
		}else{
			$java='<li id="li_'.$this->_Model['field'].'_\'+num+\'"><span><input type="text" placeholder="请输入名称" name="_post['.$this->_Model['field'].'][text][]"  class="layui-input my-input" /></span><span><select name="_post['.$this->_Model['field'].'][type][]"><option value="1">原有价格直接增加</option><option value="0">以新价格</option></select></span><span>属性价格：<input type="text" name="_post['.$this->_Model['field'].'][price][]"  class="layui-input my-input" />&nbsp;&nbsp;&nbsp;&nbsp;元 </span><span>库存：<input type="text" name="_post['.$this->_Model['field'].'][stock][]"  class="layui-input my-input" /></span><span><a href="javascript:" class="layui-btn layui-btn-xs" onclick="del_'.$this->_Model['field'].'_price(\'+num+\')">删除</a></span></li>';
		}
		$html.='
				<div class="layui-form-item">
					<label class="layui-form-label">'.$this->_Model[name].'：<p>(<a href="javascript:" style="color:red;font-size:12px" onclick="add_'.$this->_Model['field'].'_price()">添加一组</a>)</p></label>
					<div class="layui-input-block">
						<div id="'.$this->_Model['field'].'_price" class="price000">
							'.$price_html.'
						</div>
						<p class="msg">价格为空或者为0会被过滤掉</p>
					</div>
				</div>
					<script>
						var num=\''.$num.'\';
						function add_'.$this->_Model['field'].'_price(){
							num++;
							var html=\''.$java.'\';
							$("#'.$this->_Model['field'].'_price").append(html);
							layui.use([\'form\'], function(){
								var form = layui.form;
								form.render();
							})
						}
						function del_'.$this->_Model['field'].'_price(a){
							$("#li_'.$this->_Model['field'].'_"+a).remove();
						}
					</script>
		';
		return $html;
	}
	
	public function Custom_Model_template($content){
		$bt='';
		if($this->_Model['is_required']){
			$bt="<i style=' color:red'>(*)</i>";
		}
		if($this->_Model['msg']){
			$msg="<div class=\"ziduan_tishi\">".$this->_Model['msg']."</div>";
		}
		if($this->_Model['unit']){
			$unit="<span class=\"unit\">".$this->_Model['unit']."</span>";
		}
		$content="<div class=\"ziduan_content\">".$content.$unit."</div>";
		$html=	'<div class="layui-form-item">
				<label class="layui-form-label">'.$this->_Model['name'].$bt.'</label>
				<div class="layui-input-block">
					'.$content.$msg.'
				</div>
			</div>';

		return $html;
	}
	//生成html发布页时要进行判断
	protected function make_html_url(){
		if($this->make_html){
			if($this->admin=='admin'){
				if($this->from_module){
					$url=WEBURL."/admin/index/modular/".$this->from_module.'/upfile/up';
				}else{
					$url='/admin/upfile/up';
				}
			}else{
				if($this->from_module){
					$url=WEBURL."/user/index/modular/".$this->from_module.'/upfile/up';
				}else{
					$url='/user/upfile/up';
				}
			}
		}else{//这个是不生成的,直接动态调用的
			if(from_upfile_custiom_model=='admin'){
				if(defined('admin_module_url')==true){
					$url=admin_module_url.'upfile/up';
				}else{
					$url='/admin/upfile/up';
				}
				
			}else{
				if(defined('user_module_url')==true){
					$url=user_module_url.'upfile/up';
				}else{
					$url='/user/upfile/up';
				}
			}
		}
		
		
		return $url;
	}
	
	public function Custom_Model_File(){

		$exts=str_replace(".","",implode('|', explode(' ',$this->_Model['value'])));
		$size=intval($this->_Model['setting']['size']);
		if(!$size){
			$size='1';
		}
		$ziduan_key=$this->_Model['field'];
		
		
		$url=$this->make_html_url();
		
		
		if($this->make_html){
			$value="<?php echo \$edit['".$this->_Model['field']."'] ;?>";
		}else{
			$value=$this->_data[$this->_Model['field']];
		}
		$size=$size*1024;
		$html='
				<input name="_post['.$this->_Model['field'].']" value="'.$value.'" placeholder="'.$this->_Model['msg'].'" id="add_model_'.$this->_Model['field'].'" class="layui-input my-input" type="text">
			    <button type="button" class="layui-btn layui-btn-normal" id="select_up_add_model_'.$this->_Model['field'].'">选择文件上传</button>
			    <script>
			    	layui.use(["upload"], function(){
			    		var $ = layui.jquery
						  	,upload = layui.upload;
						upload.render({
						    elem: "#select_up_add_model_'.$this->_Model['field'].'",
						    url: "'.$url.'",
						    auto: true,
						    data:{\'mid\':"'.$this->_id.'",\'keys\':"'.$ziduan_key.'"},
						    accept:"'.$this->_Model['setting']['up_type'].'",
						    exts: "'.$exts.'",
						    multiple: false, //是否允许多文件上传。设置 true即可开启。不支持ie8/9
						    size:"'.$size.'",//设置文件最大可允许上传的大小，单位 KB。不支持ie8/9
						    before: function(obj){
						    	files = obj.pushFile(); //将每次选择的文件追加到文件队列
						    	loading = layer.load();
						    },
						    done: function(res, index, upload){
						    	layer.close(loading);
							    if(res.code !=0){
							    	layer.msg(res.text);
							    }else{
							      	$("#add_model_'.$this->_Model['field'].'").val(res.url); 
							    }
							    delete files[index]; //删除对应的文件
						    }
						});
			    	})
			    </script>
		';
			
		return $this->Custom_Model_template($html);
	}
	
	public function Custom_Model_Files(){

		$list_html='				
								<tr id="upload-%s%s">
									<td>
										<input type="text" class="layui-input" name="_post[%s][name][]" value="%s">
									</td>
									<td>
										<input type="text" readonly class="layui-input" name="_post[%s][url][]" value="%s" >
									</td>
									<td></td>
									<td>已上传</td>
									<td>
									<a class="layui-btn layui-btn-mini layui-btn-danger" onclick="delete_%s(%s)">删除</a>
									</td>
								</tr>';
								
								
		//修改内容需要重新设置下
		$html='';
		if($this->make_html){
			$html.="
					<?php
						\$list_url=\"\";
						if(\$edit['".$this->_Model['field']."']){
							\$".$this->_Model['field']."=explode('|||',\$edit['".$this->_Model['field']."']);
							unset(\$url,\$name);
							foreach(\$".$this->_Model['field']." AS \$key=>\$value){
								list(\$url,\$name)=explode('@@@',\$value);
								\$list_url.=\"".addslashes(sprintf($list_html,$this->_Model['field'],'$key',$this->_Model["field"],'$name',$this->_Model["field"],'$url',$this->_Model['field'],'$key'))."\";
							}
						}
					?>
				";
			$list_url="<?php echo \$list_url ?>";
		}else{
			$num=0;
			if($this->_data[$this->_Model['field']]){
				$edit_value=explode('|||',$this->_data[$this->_Model['field']]);
				$list_url="";
				foreach($edit_value AS $key=>$value){
					list($url,$name)=explode('@@@',$value);
					$list_url.=sprintf($list_html,$this->_Model['field'],$key,$this->_Model["field"],$name,$this->_Model["field"],$url,$this->_Model['field'],$key);
				}
				$num=count($edit_value);
			}
		}
		$exts=str_replace(".","",implode('|', explode(' ',$this->_Model['value'])));
		$size=intval($this->_Model['setting']['size']);
		if(!$size){
			$size='1';
		}
		$size=$size*1024;
		$ziduan_key=$this->_Model['field'];
		
		$url=$this->make_html_url();
		
		$html.=	"	<div class='layui-upload'>
					<div class='layui-upload-drag' id='add_model_".$this->_Model['field']."'>
				  		<i class='layui-icon'></i>
				  		<p>点击上传，或将文件拖拽到此处</p>
					</div>
						<div class='layui-upload-list'>
						    <table class='layui-table'>
							    <thead>
							        <tr>
							        	<th style='width:35%'>文件名</th>
							        	<th style='width:35%'>文件地址</th>
								        <th style='width:10%'>大小</th>
								        <th style='width:10%'>状态</th>
								        <th style='width:10%'>操作</th>
								    </tr>
							    </thead>
							    <tbody id='Up_List_".$this->_Model['field']."'>$list_url</tbody>
						    </table>
						</div>
					<button type='button' class='layui-btn' id='add_model_up_".$this->_Model['field']."'>点击上传</button>
				</div> 
				
				<script>
					function delete_".$this->_Model['field']."(index){
						\$(\"#upload-".$this->_Model['field']."\"+index).remove();
						return false;
					}

					layui.use(['upload'], function(){
						var $ = layui.jquery
						  	,upload = layui.upload;
						//多图片上传
						upload.render({
						    elem: '#add_model_".$this->_Model['field']."',
						    url: '".$url."',
						    accept:'".$this->_Model['setting']['up_type']."',//指定允许上传的文件类型，可选值有：images（图片）、file（所有文件）、video（视频）、audio（音频）
						    exts: '".$exts."',//允许上传的文件后缀。一般结合 accept 参数类设定。假设 accept 为 file 类型时，那么你设置 exts: 'zip|rar|7z' 即代表只允许上传压缩格式的文件。如果 accept 未设定，那么限制的就是图片的文件格式
						    multiple: true, //是否允许多文件上传。设置 true即可开启。不支持ie8/9
						    data:{'mid':'".$this->_id."','keys':'".$ziduan_key."'},
						    auto: false, //是否选完文件后自动上传。如果设定 false，那么需要设置 bindAction 参数来指向一个其它按钮提交上传
						    drag:true,//是否接受拖拽的文件上传，设置 false 可禁用。不支持ie8/9
						    size:'".$size."',//设置文件最大可允许上传的大小，单位 KB。不支持ie8/9
						    bindAction: '#add_model_up_".$this->_Model['field']."',
						    choose: function(obj){
							    files = obj.pushFile(); //将每次选择的文件追加到文件队列
							    //读取本地文件
							    obj.preview(function(index, file, result){
							        var tr = $(['<tr id=\"upload-'+ index +'\">'
									          ,'<td>'+ file.name +'</td>'
									          ,'<td></td>'
									          ,'<td>'+ (file.size/1014).toFixed(1) +'kb</td>'
									          ,'<td>等待上传</td>'
									          ,'<td>'
									            ,'<button class=\"layui-btn layui-btn-mini  layui-btn-sm reload_".$this->_Model['field']." layui-hide\">重传</button>'
									            ,'<button class=\"layui-btn layui-btn-mini  layui-btn-sm layui-btn-danger delete_".$this->_Model['field']."\">删除</button>'
									          ,'</td>'
									        ,'</tr>'].join(''));
							        //单个重传
							        tr.find('.reload_".$this->_Model['field']."').on('click', function(){
							          obj.upload(index, file);
							          return false;
							        });
							        
							        //删除
							        tr.find('.delete_".$this->_Model['field']."').on('click', function(){
							          delete files[index]; //删除对应的文件
							          tr.remove();
							        });
							       $('#Up_List_".$this->_Model['field']."').append(tr);
							    });
						    },
						    done: function(res, index, upload){
						       	if(res.code == '0'){ //上传成功
						        	var tr =  $('#Up_List_".$this->_Model['field']."').find('tr#upload-'+ index)
						        	,tds = tr.children();
						        	tds.eq(1).html('<input readonly type=\'text\' id=\'field_".$this->_Model['field']."_'+index+'\' name=\'_post[".$this->_Model['field']."][url][]\' value=\"'+res.url+'\" class=\"layui-input\">');
						        	tds.eq(3).html('<span style=\"color: #5FB878;\">上传成功</span>');
						        	tds.eq(0).html('<input type=\'text\' class=\"layui-input\" name=\'_post[".$this->_Model['field']."][name][]\' value=\"'+res.name+'\">'); //清空操作
						        	delete files[index]; //删除文件队列已经上传成功的文件
						        	return;
						      	}else{
						      		layer.msg(res.text);
						      	}
						     	this.error(index, upload);
						    },
						    error: function(index, upload){
							    var tr = $('#Up_List_".$this->_Model['field']."').find('tr#upload-'+ index)
							    ,tds = tr.children();
							    tds.eq(3).html('<span style=\"color: #FF5722;\">上传失败</span>');
							    tds.eq(4).find('.reload_".$this->_Model['field']."').removeClass('layui-hide'); //显示重传
						    }
						});
					})
				</script>
			";
		return $this->Custom_Model_template($html);
	}
	public function Custom_Model_Ueditor(){
		if('0'===$this->_Model['setting']['Ueditor_type']){
			$Ueditor_type=",toolbars: [['fullscreen', 'source', 'undo', 'redo','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']]";
		}elseif('2'===$this->_Model['setting']['Ueditor_type']){
			$Ueditor_type=",toolbars: [". json_encode(C('UEDITOR_CONFIG.function')) ."]";
		}else{
			$Ueditor_type=",toolbars: [[
						             'source', '|', 'undo', 'redo', '|',
						            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
						            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
						            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
						            'directionalityltr', 'directionalityrtl', 'indent', '|',
						            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
						            'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
						            'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
						            'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
						            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
						            'print', 'preview', 'searchreplace', 'drafts', 'help'
						        ]]";
		}
		
		if($this->make_html){
			if($this->admin=='admin'){
				$serverUrl='/admin/index/plugin/ueditor/setting/ueditor_config/';
			}else{
				$serverUrl='/user/index/plugin/ueditor/setting/ueditor_config/';
			}
		}else{//这个是不生成的,直接动态调用的
			if(MODULE=='admin'){
				$serverUrl='/admin/index/plugin/ueditor/setting/ueditor_config/';
			}else{
				$serverUrl='/user/index/plugin/ueditor/setting/ueditor_config/';
			}
		}
		
		
		
		if(!$this->_Model['height']){
			$this->_Model['height']=200;
		}
		if($this->make_html){
			$value="<?php \$edit['".$this->_Model['field']."']=str_replace  ( 'WWW_TEMMOKU_CN'  , WEBURL.'/'.C('upfiles_Catalog') ,  htmlspecialchars_decode(\$edit['".$this->_Model['field']."'],ENT_QUOTES));  echo \$edit['".$this->_Model['field']."']; ?>";
		}else{
			$value=$this->_data[$this->_Model['field']];
			$value=str_replace  ( 'WWW_TEMMOKU_CN'  , WEBURL.'/'.C('upfiles_Catalog') ,  htmlspecialchars_decode($value,ENT_QUOTES));
		}
		$html="
			<textarea  name='_post[{$this->_Model[field]}]' id='add_model_{$this->_Model[field]}' placeholder='{$this->_Model[msg]}' style='height:{$this->_Model['height']}px;width:85%'>".$value."</textarea>
			<script type='text/javascript'>
				UE.getEditor('add_model_{$this->_Model[field]}',{
					zIndex : 900,
					height:200,
					autoHeightEnabled:false,
			        // 服务器统一请求接口路径
			        serverUrl: \"{$serverUrl}\"
			        $Ueditor_type
		        });
			</script>";
		return $this->Custom_Model_template($html);
	}
	
	
	public function Custom_Model_Select(){

			$a=explode(PHP_EOL,$this->_Model['value']);
			$f=[];
			$html='';
			if($this->make_html){
				$html.="
						<?php
							if(\$edit && \$edit['".$this->_Model['field']."']){
								\$".$this->_Model['field']."=[];
								foreach(explode(\"|||\",\$edit['".$this->_Model['field']."']) AS \$value){
									\$".$this->_Model['field']."[\$value] = 'selected';
								}
							}else{
								\$".$this->_Model['field']."=[];
								\$_".$this->_Model['field']."=explode(PHP_EOL,\$field['".$this->_Model['field']."']['value']);//此行于-1行都不能更改，系统自动生成，否则无法格式化
								foreach(\$_".$this->_Model['field']." AS \$_".$this->_Model['field']."_value){
									list(\$a,\$b)=explode('@@@',\$_".$this->_Model['field']."_value);
									list(\$c,\$d)=explode('|||',\$a);
									\$b ? \$".$this->_Model['field']."[\$c] = 'selected' : '';
								}
							}
						?>
					";
			}
			foreach($a AS $v){
				list($b,$c)=explode("@@@",$v);
				list($d,$e)=explode("|||",$b);
				$check="";
				if($this->make_html){
					$selected="<?php echo \$".$this->_Model['field']."['".$d."'] ?>";
					$e = $e ? $e : $d;
				}else{
					$selected="";
					//如果是修改的就不能使用默认的选择了
					if($this->_data[$this->_Model['field']]){
						if($d==$this->_data[$this->_Model['field']]){
							$selected="selected";
						}
					}else{
						if($c){$selected="selected";}
					}
					if(!$e){
						$e=$d;
					}
				}
				$f[]="<option value='$d' title='$d'  $selected>$e</option>\r\n";
			}
			$f=implode("",$f);
			$html.="<select name=\"_post[{$this->_Model[field]}]\"  lay-filter=\"aihao\">$f</select>";
			return $this->Custom_Model_template($html);
	}
	
	public function Custom_Model_Text(){
		$bt="";
		if($this->_Model['is_required']){
			$bt="lay-verify=\"required|".$this->_Model['field']."\"";
		}
		if($this->make_html){
			$value="<?php echo \$edit['".$this->_Model['field']."'] ?>";
		}else{
			$value=$this->_data[$this->_Model['field']];
		}
		$v=	"<input name='_post[".$this->_Model['field']."]' placeholder='".$this->_Model['msg']."' $bt id='".$this->_Model['field']."' value=\"".$value."\" class='layui-input my-input' type='text'>
			<script>
			layui.use(['form'], function(){
				var form = layui.form;
				form.verify({
				    ".$this->_Model['field'].": function(value,item){
						console.log(value);
					  	if(!value){
						    return '{$this->_Model[name]}必须填写';  
						}
				    }
			  	});
			})</script>
			";
		return $this->Custom_Model_template($v);
	}
	
	public function Custom_Model_Textarea(){
		$bt="";
		if($this->_Model['is_required']){
			$bt="lay-verify=\"required|{$this->_Model[field]}\"";
		}
		if($this->make_html){
			$value="<?php echo \$edit['".$this->_Model['field']."'] ?>";
		}else{
			$value=$this->_data[$this->_Model['field']];
		}
		$v="<textarea  name='_post[{$this->_Model[field]}]' placeholder='{$this->_Model[msg]}' $bt style='height:{$this->_Model['height']}px' class='layui-textarea'>".$value."</textarea>
			<script>
			layui.use(['form'], function(){
				var form = layui.form;
				form.verify({
				    {$this->_Model[field]}: function(value){
					   if(!value){
						    return '{$this->_Model[name]}必须填写';  
						}
				    }
			  	});
			})</script>
		";
		return $this->Custom_Model_template($v);
	}
	
	public function Custom_Model_Date(){

		$bt="";
		if($this->_Model['is_required']){
			$bt="lay-verify=\"required|{$this->_Model[field]}\"";
		}
		if($this->make_html){
			$edit_value="<?php echo \$edit['".$this->_Model['field']."'] ? date(\"".$this->_Model['value']."\",\$edit['".$this->_Model['field']."']) : '' ;?>";
		}else{
			if($this->_data[$this->_Model['field']]){
				$edit_value=date($this->_Model['value'],$this->_data[$this->_Model['field']]);
			}
		}
		
		$v="<input name='_post[{$this->_Model[field]}]' $bt placeholder='{$this->_Model[msg]}' id='{$this->_Model[field]}' value=\"$edit_value\" class='layui-input  my-input' type='text'> 
			<script>
				layui.use(['laydate','form'], function(){
					var laydate = layui.laydate;
					var form = layui.form;
					laydate.render({
					    elem: '#{$this->_Model[field]}'
					    ,type: 'datetime'
					});
					form.verify({
					    {$this->_Model[field]}: function(value){
					    	if(!value){
						   		return '{$this->_Model[name]}必须填写';  
						   	}
					    }
				  	});
				})
			</script>
			";
		return $this->Custom_Model_template($v);
	}

	public function Custom_Model_Checkbox(){
			$a=explode(PHP_EOL,$this->_Model['value']);
			$f=array();
			$html=$check="";
			if($this->make_html){
				$html.="<?php
							if(\$edit && \$edit['".$this->_Model['field']."']){
								\$".$this->_Model['field']."=[];
								foreach(explode(\"|||\",\$edit['".$this->_Model['field']."']) AS \$value){
									\$".$this->_Model['field']."[\$value] = 'checked';
								}
							}else{
								\$".$this->_Model['field']."=[];
								\$_".$this->_Model['field']."=explode(PHP_EOL,\$field['".$this->_Model['field']."']['value']);//此行于-1行都不能更改，系统自动生成，否则无法格式化
								foreach(\$_".$this->_Model['field']." AS \$_".$this->_Model['field']."_value){
									list(\$a,\$b)=explode('@@@',\$_".$this->_Model['field']."_value);
									list(\$c,\$d)=explode('|||',\$a);
									\$b ? \$".$this->_Model['field']."[\$c] = 'checked' : '';
									
								}
							}
						?>";
			}
			
			foreach($a AS $v){
				list($b,$c)=explode("@@@",$v);
				list($d,$e)=explode("|||",$b);
				$check="";
				if($this->make_html){
					$check="<?php echo  \$".$this->_Model['field']."['".$d."']?>";
					$e = $e ? $e : $d;
				}else{
					//修改文章时进行特殊处理
					if($this->_data[$this->_Model['field']]){
						foreach(explode("|||",$this->_data[$this->_Model['field']]) AS $value){
							if($d==$value){
								$check="checked";
							}
						}
					}else{
						if($c){$check="checked";}
					}
					if(!$e){
						$e=$d;
					}
				}
				$f[]='<input name="_post['.$this->_Model['field'].'][]" value="'.$d.'" title="'.$e.'" type="'.$this->_Model['type'].'" '.$check.'> '."\r\n";
			}
			$html.=implode("",$f);
			return $this->Custom_Model_template($html);
	}

	public function Custom_Model_Radio(){
			$a=explode(PHP_EOL,$this->_Model['value']);
			$f=[];
			$html='';
			if($this->make_html){
				$html.="
						<?php
							if(\$edit && \$edit['".$this->_Model['field']."']){
								\$".$this->_Model['field']."[\$edit['".$this->_Model['field']."']] = 'checked';
							}else{
								\$".$this->_Model['field']."=[];
								\$_".$this->_Model['field']."=explode(PHP_EOL,\$field['".$this->_Model['field']."']['value']);//此行于-1行都不能更改，系统自动生成，否则无法格式化
								foreach(\$_".$this->_Model['field']." AS \$_".$this->_Model['field']."_value){
									list(\$a,\$b)=explode('@@@',\$_".$this->_Model['field']."_value);
									list(\$c,\$d)=explode('|||',\$a);
									\$b ? \$".$this->_Model['field']."[\$c] = 'checked' : '';
								}
							}
						?>
					";
			}
			foreach($a AS $v){
				list($b,$c)=explode("@@@",$v);
				list($d,$e)=explode("|||",$b);
				$check="";
				if($this->make_html){
					$check="<?php echo \$".$this->_Model['field']."['".$d."'] ?>";
					$e = $e ? $e : $d;
				}else{
					//修改文章时进行特殊处理
					if($this->_data[$this->_Model['field']]){
						if($d==$this->_data[$this->_Model['field']]){
							
							$check="checked";
						}
					}else{
						if($c){$check="checked";}
					}
					if(!$e){
						$e=$d;
					}
				}
				$f[]='<input name="_post['.$this->_Model['field'].']" value="'.$d.'" title="'.$e.'" type="radio" '.$check.'> '."\r\n";
			}
			$html.=implode("",$f);
			return $this->Custom_Model_template($html);
	}
	
	public function Custom_Model_Type($type='',$arr=[]){
		$v='';
	 	if($type=="Checkbox" ||$type=="Radio" ||$type=="Select"){
	 		!isset($arr['value']) && $arr['value']="值|||名称@@@1";
	 		
	 		$v='<div class="layui-form-item" id="Checkbox">
		    		<label class="layui-form-label">选项列表</label>
		    		<div class="layui-input-block">
		    			 <textarea name="post[value]" id="ziduan_neirong" class="layui-textarea">'.$arr['value'].'</textarea>
		    			 <p>如：值|||名称，请正确填写，否则无法解析。多个选项请ENTER换行。默认“值”等同于“值|||值”</p>
		    			 <p>如需要设置默认选择项，请填写"值|||名称@@@1"或者"值@@@1"</p>
		    		</div>
		    	</div>';
	 	}elseif($type=="array"){
	 		!isset($arr['value']) && $arr['value']="键|||名称";
	 		
	 		$v='<div class="layui-form-item" id="Checkbox">
		    		<label class="layui-form-label">选项列表</label>
		    		<div class="layui-input-block">
		    			 <textarea name="post[value]" id="ziduan_neirong" class="layui-textarea">'.$arr['value'].'</textarea>
		    			 <p>如：type|||名称，请正确填写，否则无法解析。多个选项请ENTER换行。</p>
		    			 <p>如需要设置默认选择项，请填写"值|||名称@@@1"或者"值@@@1"</p>
		    		</div>
		    	</div>';
	 	}elseif($type=="Date"){
	 		!isset($arr['value']) && $arr['value']="Y-m-d H:i:s";

		 	$v='<div class="layui-form-item" id="Date">
		    		<label class="layui-form-label">日期显示格式</label>
		    		<div class="layui-input-block">
		    			<input name="post[value]" id="ziduan_neirong" value="'.$arr['value'].'"  class="layui-input layui-input-my" type="text">
		    			<p>如：Y-m-d H:i:s或Y-m-d H:i或Y-m-d或Y-m</p>
		    		</div>
		    	</div>';
	 	}elseif($type=="File" || $type=='Files'){
	 		!isset($arr['value']) && $arr['value']=".gif .jpg .jpeg .zip .png .rar";
	 		
	 		if($arr['setting']['up_type']){
	 			$uptype[$arr['setting']['up_type']]="checked";
	 		}else{
	 			$uptype['images']="checked";
	 		}
	 		if($arr['setting']['is_down']){
	 			$dis_none='';
		 		$ziduan_is_down[$arr['setting']['is_down']]="checked";
		 	}else{
		 		$ziduan_is_down['0']="checked";
		 		$dis_none='style="display: none;"';
		 	}

			if($ar['setting']['up_type']=='audio' || $arr['setting']['up_type']=='video'){
			 	if($arr['setting']['is_play'] || $arr['setting']['is_play']=='0'){
			 		$dis_play='';
					$ziduan_is_play[$arr['setting']['is_play']]="checked";
				 }else{
					$ziduan_is_play['0']="checked";
				 	$dis_play='style="display: none;"';
				}

				if($arr['setting']['play']){
				 	$ziduan_play[$arr['setting']['play']]='selected';
				}
				$dis_none='style="display: none;"';
			}else{
			 	$dis_play='style="display: none;"';
			}
			 	
			if($type=="File"){
	 			$down='
		 			<div class="layui-form-item" id="ziduan_is_down" '.$dis_none.'>
				   		<label class="layui-form-label">是否为下载</label>
				   		<div class="layui-input-block">
				   			<input lay-filter="ziduan_is_down" name="post[setting][is_down]" value="1" title="是" type="radio" 		'.$ziduan_is_down['1'].'>
				   			<input lay-filter="ziduan_is_down" name="post[setting][is_down]" value="0"  title="不是" type="radio" 	'.$ziduan_is_down['0'].'>
				   		</div>
				   	</div>
				    <div class="layui-form-item" id="ziduan_down_url_list" '.$dis_none.'>
				    	<label class="layui-form-label">远程地址</label>
				    	<div class="layui-input-block">
				    		<textarea style="width:50%"  class="layui-textarea" name="post[setting][ziduan_down_url_list]">'.$arr['ziduan_down_url_list'].'</textarea>
				    		<p>如：http://www.baidu.com/||百度电信</p>
				    		<p>网址||名称</p>
				    		<p>下载地址为一行一个。地址必须指向到附件目录无需指向到attachment</p>
				    	</div>
				   	</div>
	 			';
	 		}
			
		 	$down.='
			 	<div class="layui-form-item" id="ziduan_play" '.$dis_play.'>
				    <label class="layui-form-label">是否为在线播放</label>
					<div class="layui-input-block">
				    	<input lay-filter="ziduan_is_play" name="post[setting][is_play]" value="1" title="是" type="radio" 		'.$ziduan_is_play['1'].'>
					   	<input lay-filter="ziduan_is_play" name="post[setting][is_play]" value="0"  title="不是" type="radio" 	'.$ziduan_is_play['0'].'>
					   	<p>如果选择了下载就不会在播放</p>
					</div>
				</div>
				<div class="layui-form-item" id="ziduan_play1" '.$dis_play.'>
					<label class="layui-form-label">请选择播放器</label>
					<div class="layui-input-block">
					    <select name="post[setting][play]">
				    		<option value="jplayer" '.$ziduan_play['jplayer'].'>jplayer</option>
				    		<option value="ckplayer" '.$ziduan_play['ckplayer'].'>ckplayer</option>
				    	</select>
				  </div>
				</div>
		 	';
	 		
	 		if($type=='File'){
	 			$file='
		    			<input lay-filter="ziduan_play" name="post[setting][up_type]" value="txt"	 title="文本" type="radio" 		'.$uptype['txt'].'>
		    			<input lay-filter="ziduan_play" name="post[setting][up_type]" value="rar" 	 title="压缩包" type="radio" 		'.$uptype['rar'].'>
		    			<input lay-filter="ziduan_play" name="post[setting][up_type]" value="all"    title="所有文件" type="radio"		'.$uptype['all'].'>';
	 		}
	 		
	 		
		 	$v='<div class="layui-form-item">
		    		<label class="layui-form-label">上传类型</label>
		    		<div class="layui-input-block">
		    			<input lay-filter="ziduan_play" name="post[setting][up_type]" value="images" title="图片" type="radio" 		'.$uptype['images'].'>
		    			<input lay-filter="ziduan_play" name="post[setting][up_type]" value="video"  title="视频" type="radio" 		'.$uptype['video'].'>
		    			<input lay-filter="ziduan_play" name="post[setting][up_type]" value="audio"  title="音频" type="radio" 		'.$uptype['audio'].'>
		    			'.$file.'
		    		</div>
		    		
		    	</div>
		    	'.$down.'
		    	<div class="layui-form-item" id="file_size">
		    		<label class="layui-form-label">单个文件大小</label>
		    		<div class="layui-input-block">
		    			<input name="post[setting][size]" id="ziduan_neirong" value="'.$arr['setting']['size'].'"  class="layui-input layui-input-my" type="text">
		    			<span>MB</span>
		    			<p>如果文件大于设置的大小，则不允许上传</p>
		    		</div>
		    	</div>
		 		<div class="layui-form-item">
		    		<label class="layui-form-label">允许上传的扩展名</label>
		    		<div class="layui-input-block">
		    			<input name="post[value]" id="ziduan_neirong" value="'.$arr['value'].'"  class="layui-input layui-input-my" type="text">
		    			<p>如：.gif .png .rar  多个用空格隔开,不填写则验证会员中心权限的设置参数，如果会员中心依旧没有填写在使用核心设置的参数</p>
		    		</div>
		    	</div>';
	 	}elseif($type=="Text"){
	 		$s[$arr['field_attr']]=' selected';
		 	$v='<div class="layui-form-item">
		    		<label class="layui-form-label">字段属性</label>
		    		<div class="layui-input-block">
		    			<select name="post[field_attr]">
		    				<option value="">-</option>
							<option value="INT" '.$s["INT"].'>INT</option>
							<option value="TINYINT" '.$s["TINYINT"].'>TINYINT</option>
							<option value="SMALLINT" '.$s["SMALLINT"].'>SMALLINT</option>
							<option value="MEDIUMINT" '.$s["MEDIUMINT"].'>MEDIUMINT</option>
							<option value="">-</option>
							<option value="DECIMAL" '.$s["DECIMAL"].'>DECIMAL</option>
							<option value="FLOAT" '.$s["FLOAT"].'>FLOAT</option>
							<option value="">-</option>
							<option value="CHAR" '.$s["CHAR"].'>CHAR</option>
							<option value="VARCHAR" '.$s["VARCHAR"].'>VARCHAR</option>
							<option value="TEXT" '.$s["TEXT"].'>TEXT</option>
							<option value="MEDIUMTEXT" '.$s["MEDIUMTEXT"].'>MEDIUMTEXT</option>
		    			</select>
		    			<p>根据你的实际情况选择字段类型，如果你不懂MySQL数据库知识就不要选择此项</p>
		    		</div>
		    	</div>
		    	<div class="layui-form-item">
		    		<label class="layui-form-label">字段长度</label>
		    		<div class="layui-input-block">
		    			<input name="post[field_length]" id="ziduan_key_changdu" value="'.$arr['field_length'].'"  class="layui-input layui-input-my" type="text">
		    			<p>如果你不懂MySQL数据库知识就不要填写此项.会自动生成</p>
		    		</div>
		    	</div>';
	 	}elseif($type=="Textarea" || $type=="Ueditor"){
	 		if($type=="Ueditor"){
	 			if($arr){
	 				$uptype[$arr['setting']['Ueditor_type']]="checked";
	 			}else{
	 				$uptype["1"]="checked";
	 			}
	 			$v.='<div class="layui-form-item">
			    		<label class="layui-form-label">编辑器模式</label>
			    		<div class="layui-input-block">
			    			<input name="post[setting][Ueditor_type]" value="1" title="完整模式" type="radio" 		'.$uptype["1"].'>
			    			<input name="post[setting][Ueditor_type]" value="0"  title="精简模式" type="radio" 		'.$uptype['0'].'>
			    			<input name="post[setting][Ueditor_type]" value="2"  title="UE设置模式" type="radio" 	'.$uptype['2'].'>
			    		</div>
			    	</div>';
	 		}
	 		
	 		
		 	$v.='
		    	<div class="layui-form-item">
		    		<label class="layui-form-label">高度</label>
		    		<div class="layui-input-block">
		    			<input name="post[height]" id="ziduan_Textarea_gaodu" value="'.$arr['height'].'"  class="layui-input layui-input-my" type="number">
		    			<span>px</span>
		    		</div>
		    	</div>';
	 	}elseif($type=="Price"){
	 		if($arr){
	 			$is_multi[$arr['choice_model']]="checked";
	 		}else{
	 			$is_multi["1"]="checked";
	 		}

		 	$v.='
		 		<div class="layui-form-item">
			    	<label class="layui-form-label">选择模式</label>
			    	<div class="layui-input-block">
			    		<input name="post[choice_model]" value="1" title="单选模式" type="radio" 		'.$is_multi['1'].'>
			    		<input name="post[choice_model]" value="2"  title="多选模式" type="radio" 	'.$is_multi['2'].'>
			    		<p>单选模式在前台为必须项，多选模式在购买时可以不进行选择</p>
			    	</div>
			    </div>
		 		<div class="layui-form-item" id="Date">
		    		<label class="layui-form-label">列表值,为空则手动填写</label>
		    		<div class="layui-input-block">
		    			<textarea style="width:50%"  class="layui-textarea" name="post[value]">'.$arr['value'].'</textarea>
		    			<p>例如，颜色的分类：白色，黑色，灰色每行一个</p>
		    		</div>
		    	</div>';
	 	}
	 	return $v;
	}
	
	public function Field_properties($type,$properties='',$leng='0'){
		$data='';
		if($type==="Checkbox" || $type==="File" || $type==="Radio" || $type==="Select"){
			$data="VARCHAR( 255 )";
			$leng='255';
			$properties='VARCHAR';
			$DEFAULT='DEFAULT NULL';
		}elseif($type==="Date"){
			$data="INT( 10 )";
			$leng='10';
			$properties='INT';
			$DEFAULT='DEFAULT 0';
		}elseif($type==="Files" || $type=="Textarea" || $type=="Ueditor" ){
			$data="TEXT";
			$properties='TEXT';
			$DEFAULT='DEFAULT NULL';
		}elseif($type==="Text" || $type==="Price"){
			if($properties==='TINYINT'){
				$leng=intval($leng);
				if($leng >"4" || !$leng) $leng=3;
				$data="{$properties}( {$leng} )";
				$DEFAULT='DEFAULT 0';
			}elseif($properties==='SMALLINT'){
				$leng=intval($leng);
				if($leng >"7" || !$leng){
					$leng=6;
				}
				$data="{$properties}( {$leng} )";
				$DEFAULT='DEFAULT 0';
			}elseif($properties==='MEDIUMINT'){
				$leng=intval($leng);
				if($leng >"10" || !$leng) $leng=9;
				$data="{$properties}( {$leng} )";
				$DEFAULT='DEFAULT 0';
			}elseif($properties==='DECIMAL' || 'FLOAT'===$properties){
				if($leng){
					$int=0;
					$float=0;
					list($int,$float)=explode(',',$leng);
					$int=intval($int);
					$float=intval($float);
					if($int > 12 || $int===0) $int=11;
					if($float > 11 ) $float=10;
					if($int && $float){
						if($int < $float){
							$int=$float;
						}
						$leng="{$int},{$float}";
						$DEFAULT=0;
					}else{
						$leng=$int;
					}
						
				}else{
					$leng=9;
				}
				$data="{$properties}( {$leng} )";
				$DEFAULT='DEFAULT 0';
			}elseif($properties==='CHAR'){
				$leng=intval($leng);
				if($leng >"255" || !$leng){
					$leng=255;
				}
				$data="{$properties}( {$leng} )";
				$DEFAULT='DEFAULT NULL';
			}elseif($properties==='VARCHAR'){
				$leng=intval($leng);
				if($leng >"255" || !$leng){
					$leng=255;
				}
				$data="{$properties}( {$leng} )";
				$DEFAULT='DEFAULT NULL';
			}elseif($properties==='INT'){
				$leng=intval($leng);
				if($leng >"12" || !$leng){
					$leng=11;
				}
				$data="{$properties}( {$leng} )";
				$DEFAULT='DEFAULT 0';
			}else{
				$properties=$data="MEDIUMTEXT";
				$DEFAULT='DEFAULT NULL';
			}
		}else{
			$leng='255';
			$data="VARCHAR( 255 )";
			$properties='VARCHAR';
			$DEFAULT='DEFAULT NULL';
		}
		$arr=['properties'=>$data,'leng'=>$leng,'DEFAULT'=>$DEFAULT,'field_attr'=>$properties];
		return $arr;
	}
	
	/*
	 * $Model_Setting 模型的一些字段
	 * $data 发布时的数据
	 * $oldata 修改时发送过来的数据
 	 */
	public function module_post_data(&$Model_Setting,&$data,&$oldata=[],$is_del=false){
	    if(!$Model_Setting){
	    	return;
	    }
	    defined('M_MODULE') or define('M_MODULE','');
		foreach($Model_Setting AS $row){
			$v='';
			$key=$row['field'];
			//进行正则验证.如果是删除就不要进行验证
			if($row['is_required'] && $is_del==false){
				//如果存在正则验证则验证
				if($row['regular']){
					preg_match($row['regular'], $data[$key], $matches);
					if(!$matches){
						(new \temmoku\controller)->err($row['msg']);
					}
				}
			}
			
			if($row['type']==="Checkbox"){
				if($data[$key]){
					$CheckboxS=[];
					foreach($data[$key] AS $Checkbox){
						$CheckboxS[]=$Checkbox;
					}
					if($CheckboxS){
						$v=implode('|||',$CheckboxS);
					}
				}
			}elseif($row['type']==="File"){
				if($data[$key]){
					if (preg_match('/(http|https):\/\/([\w\d\-_]+[\.\w\d\-_]+)[:\d+]?([\/]?[\w\/\.]+)/', $data[$key] )) {
						$v=$data[$key];
					}else{
						//如果不等于原文件，则KIll掉它
						if(($data[$key] != $oldata[$key]) && $oldata[$key]){
							$oldfile=Temmoku_PATH.C('UPFILES_CATALOG').'/'.$oldata[$key];
							//删除备份文件
							del_file($oldfile);
							@unlink($oldfile);//删除这个文件
						}
						$v=UploadFiles_MOVE($data[$key],M_MODULE);
					}
				}else{
					if($oldata[$key]){
						$oldfile=Temmoku_PATH.C('UPFILES_CATALOG').'/'.$oldata[$key];
						//删除备份文件
						del_file($oldfile);
						@unlink($oldfile);//删除这个文件
					}
				}
			}elseif($row['type']==="Files"){
				if($data[$key]){
					//修改的时候要判断老文件是否还存在，不存在则删除 star
					foreach(explode('|||',$oldata[$key]) AS $oldfils){
						list($url,$name)=explode('@@@',$oldfils);
						$in=in_array($url,$data[$key]['url']);
						if(false==$in){//删除了此文件
							$oldfile=Temmoku_PATH.C('UPFILES_CATALOG').'/'.$url;
							//删除备份文件
							del_file($oldfile);
							@unlink($oldfile);//删除这个文件
						}
					}
					//end
					//重新整理
					if(is_array($data[$key]['url'])){
						$FilesS=[];
						foreach($data[$key]['url'] AS $keys=>$Files){
							if(!$Files){
								continue;
							}
							$Files=UploadFiles_MOVE($Files,M_MODULE);
							$FilesS[]="$Files@@@{$data[$key]['name'][$keys]}";
						}
						if($FilesS){
							$v=implode('|||',$FilesS);
						}
					}
				}else{
					if($oldata[$key]){
						foreach(explode('|||',$oldata[$key]) AS $oldfils){
							list($url,$name)=explode('@@@',$oldfils);
							$oldfile=Temmoku_PATH.C('UPFILES_CATALOG').'/'.$url;
							//删除备份文件
							del_file($oldfile);
							@unlink($oldfile);//删除这个文件
						}
					}
				}
			}elseif($row['type']==="Date"){
				$v=(int)strtotime($data[$key]);
			}elseif($row['type']==="Ueditor"){
				
				$pattern="/<img.*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.jpeg]))[\'|\"].*?[\/]?>/";
				$content=htmlspecialchars_decode($data[$key]);
				if(preg_match_all($pattern,$content,$match)){
					$img=(new \temmoku\Lib\Images_Get_Down)->Get_img_url($content,$match);
					$content= htmlspecialchars($img);
				}
				//替换网址
				$v=str_replace  (WEBURL.'/'.C('upfiles_Catalog'), 'WWW_TEMMOKU_CN'   , $content);
			}elseif($row['type']==="Price"){
				$priceDB=[];
				if($data[$key]){
					foreach($data[$key]['price'] AS $keys=>$value){
						if(!$value || !is_numeric($value)){
							continue;
						}
						$stock+=$data[$key]['stock'][$keys];
						$value=number_format($value,'2','.','');
						$priceDB[$keys]['name']=addslashes($data[$key]['text'][$keys]); //价格属性名称
						$priceDB[$keys]['price']=$value;	//价格
						$priceDB[$keys]['type']=intval($data[$key]['type'][$keys]); //1为原有价格上增加价格，2为直接以新价格出售
						$priceDB[$keys]['stock']=intval($data[$key]['stock'][$keys]); //库存量
						$priceDB[$keys]['attr_id']=intval($data[$key]['attr_id'][$keys]); //属性ID
					}
				}
				if($priceDB){
					$v=serialize($priceDB);
				}
			}else{
				$v=$data[$key];
			}
			if($row['field_attr']=='INT' || $row['field_attr']=='TINYINT' || $row['field_attr']=='SMALLINT'  || $row['field_attr']=='MEDIUMINT'){
				$v=intval($v);
			}elseif($row['field_attr']=='DECIMAL' || $row['field_attr']=='FLOAT'){
				list($int,$float)=explode(',',$row['field_length']);
				$v=round($v,$float);
			}
			$input[$key]=$v;
		}
		return  $input;
	}
	
	
	
	public function show(&$Model_Setting,&$data){
		if(!$Model_Setting){
	    	return;
	   }
	   	$_data=[];
		foreach($Model_Setting AS $key=>$row){
			if($row['ziduan_leibie']==="Checkbox"){
				$_data[$row['field']]=$this->show_checkbox($row,$data[$row['field']]);
			}else if($row['ziduan_leibie']==="File"){
				$_data[$row['field']]=$this->show_file($row,$data[$row['field']]);
				
			}else if($row['ziduan_leibie']==="Files"){
				$_data[$row['field']]=$this->show_files($row,$data[$row['field']]);
			}else if($row['ziduan_leibie']==="Date"){
				$_data[$row['field']]=date($row['ziduan_neirong'],$data[$row['field']]);
			}else if($row['ziduan_leibie']==="Radio" || $row['ziduan_leibie']==="Select"){
				$_data[$row['field']]=$this->show_radio_select($row,$data[$row['field']]);
			}else{
				$_data[$row['field']]=$data[$row['field']];
			}
		}
		return $_data;
	}
	
	private function show_radio_select($row,$value){
		$array=explode(PHP_EOL,$row['ziduan_neirong']);
		$html='';
		foreach($array AS $_value){
			list($__value,$none)=explode('@@@',$_value);
			list($key,$name)=explode('|||',$__value);
			if($key==$value){
				$html = "<span>$name</span>";
				break;
			}
		}
		return $html;
	}
	
	private function show_checkbox($row,$data){
		$array=explode(PHP_EOL,$row['ziduan_neirong']);
		$_array=explode('|||',$data);
		$html='';
		foreach($array AS $value){
			list($_value,$none)=explode('@@@',$value);
			list($key,$name)=explode('|||',$_value);
			if(in_array($key,$_array)){
				$html .= "<span>$name</span>";
			}
		}
		return $html;
	}
	
	private function show_files($row,$data){
		if($row['ziduan_up_type']=='video' || $row['ziduan_up_type']=='audio'){
			//播放
			if($row['ziduan_is_play']=='1'){
				if($row['ziduan_up_type']=='audio'){
					$music=explode('|||',$data);
					$html='';
					foreach($music AS $key=>$value){
						list($url,$name)=explode('@@@',$value);
						$url=get_file_url($url);
						if($key==0){
							$html .='<audio id="music" src="'.$url.'" autoplay controls="controls">您的浏览器不支持 audio 标签。</audio>';
						}
						
						$html .='<a href="javascript:;" onclick="player(\''.$url.'\')">'.$name.'</a>';
					}
					$html.='
					<script>
					function player(dir){
						$("#music").attr(\'src\',dir);
					}</script>
					';
					$data=$html;
				}else{
					$video=explode('|||',$data);
					$html='';
					foreach($video AS $key=>$value){
						list($url,$name)=explode('@@@',$value);
						$url=get_file_url($url);
						if($key==0){
							$html.='
								<script type="text/javascript" src="'.WEBURL.'/public/player/ck/ckplayer.js"></script>
								<div id="video" style="width:600px;height:400px;"></div>
								<script type="text/javascript">
								var videoObject = {
									container: \'#video\',//“#”代表容器的ID，“.”或“”代表容器的class
									variable: \'player\',//该属性必需设置，值等于下面的new chplayer()的对象
									flashplayer:false,//如果强制使用flashplayer则设置成true
									
									video:\''.$url.'\'//视频地址
								};
								var player=new ckplayer(videoObject);
							</script>
							';
							
						}
						$html .='<a href="javascript:;" onclick="players(\''.$url.'\')">'.$name.'</a>';
					}
					$html.='
					<script>
					function players(dir){
						videoObject = {
									container: \'#video\',//“#”代表容器的ID，“.”或“”代表容器的class
									variable: \'player\',//该属性必需设置，值等于下面的new chplayer()的对象
									flashplayer:false,//如果强制使用flashplayer则设置成true
									video:dir //视频地址
								};
							var player=new ckplayer(videoObject);
					}</script>
					';
					$data=$html;
				}
			}
		}
		return $data;
	}
	//单文件
	private function show_file($row,$value){
	   	$show='';
		if($row['ziduan_up_type']=='video' || $row['ziduan_up_type']=='audio'){
			//播放
			if($row['ziduan_is_play']=='1'){
				if($row['ziduan_up_type']=='audio'){
					$url=get_file_url($value);
					$show.='<audio src="'.$url.'" autoplay controls="controls">您的浏览器不支持 audio 标签。</audio>';
				}else{
					$url=get_file_url($value);
					$show.='
						<script type="text/javascript" src="'.WEBURL.'/public/player/ck/ckplayer.js"></script>
						<div id="video" style="width:600px;height:400px;"></div>
						<script type="text/javascript">
						var videoObject = {
							container: \'#video\',//“#”代表容器的ID，“.”或“”代表容器的class
							variable: \'player\',//该属性必需设置，值等于下面的new chplayer()的对象
							flashplayer:false,//如果强制使用flashplayer则设置成true
							
							video:\''.$url.'\'//视频地址
						};
						var player=new ckplayer(videoObject);
					</script>
					';
				}
			}else{
				$show.=get_file_url($value);
			}
		}elseif($row['ziduan_up_type']=='txt' || $row['ziduan_up_type']=='rar' || $row['ziduan_up_type']=='all'){
			if($row['ziduan_is_down']=='1'){
				if(!$row['ziduan_down_url_list']){
					$fileurl=get_file_url($value);
					$show .="<a href='$fileurl' target=\"_blank\">本地下载</a>";
				}else{
					$down=explode(PHP_EOL,$row['ziduan_down_url_list']);
					$fileurl=get_file_url($value);
					foreach($down AS $text){
						list($url,$name)=explode("||",$text);
						$show .="<a href='{$url}{$value}' target=\"_blank\">$name</a>";
					}
				}
			}else{
				$show.=get_file_url($value);
			}
		}elseif($row['ziduan_up_type']=='images'){
			$show.=get_file_url($value);
		}
		return $show;
	}
	
}

?>