<?php

class form
{
    static function input($name, $value = null, $option = null,$check = null)
    {
        return $input = "<input type=\"text\" name=\"$name\" id=\"$name\" value=\"$value\" class=\"form-control $check\"  $option/>";
    }

    function hidden($name, $value = null, $option = null,$check = null)
    {
        return $input = "<input type=\"hidden\" name=\"$name\" id=\"$name\" value=\"$value\"  class=\"form-control $check \" $option/>";
    }

    static function password($name, $value = null, $option = null,$check = null)
    {
        return $input = "<input type=\"password\" name=\"$name\" id=\"$name\" value=\"$value\"  class=\"form-control $check \" $option/>";
    }

    function textarea($name, $value = null, $option = null,$check = null)
    {
        return $input = "<textarea name=\"$name\" id=\"$name\" class=\"form-control textarea $check \" $option>$value</textarea>";
    }

    static function select($name, $value, $data, $option = null)
    {
        $select = "<select id=\"$name\" name=\"$name\"  class=\"form-control select $name\" $option>";

        //var_dump($data);
        if (!isset($data[0]) && !isset($data[""])) {
            $select .= "<option value=\"\">".lang("please_choose")."...</option>";
        }
        if (@$data[0] == null || (isset($data[0]) && !$data[0]))
            unset($data[0]);
        if ($_GET['table'] == 'category') {
            $category = category::getInstance();
            $subids = $category->sons($_GET['id']);
        }
        if ($_GET['table'] == 'type') {
            $category = type::getInstance();
            $subids = $category->sons($_GET['id']);
        }
        foreach ($data as $k => $d) {
            $select .= "<option value=\"$k\"";
            if ($k == $value) {
                $select .= ' selected ';
            } else if (isset($_GET['id']) && ($_GET['table'] == 'category' || $_GET['table'] == 'type') && !preg_match('/(htmlrule|isnav|ismobilenav)/is', $name)) {
                if ($_GET['id'] == $k || in_array($k, $subids)) {
                    $select .= ' disabled ';
                }
            }
            $select .= ">$d</option>";
            //$select.="<option value=\"$k\" ".($k == $value ?'selected': '').">$d</option>";
        }
        $select .= "</select>";
        return $select;
    }

    function radio($name, $value, $checked = null, $option = null)
    {
        $checked = $checked ? 'checked="checked" ' : '';
        return "<label class=\"checkbox-inline\"><input name=\"$name\" type=\"radio\" value=\"$value\" class=\"radio\" $checked $option>	</label>";
    }


    function checkbox($name, $value, $checked = null, $option = null)
    {
        $checked = $checked ? 'checked="checked" ' : '';
        return $input = "<label class=\"checkbox-inline\"><input type=\"checkbox\" name=\"$name\" id=\"$name\" class=\"checkbox\" value=\"$value\" $checked $option>	</label>&nbsp;&nbsp;&nbsp;";
    }

	    function checkbox2($name, $value, $checked = null, $option = null)
    {
        $checked = $checked ? 'checked="checked" ' : 'checked="checked" ';
        return $input = "<label class=\"checkbox-inline\"><input type=\"checkbox\" name=\"$name\" id=\"$name\" class=\"checkbox\" value=\"$value\" $checked $option>	</label>&nbsp;&nbsp;&nbsp;";
    }

    function submit($value=null)
    {
        if(!$value){
            $value=lang('submit_on');
        }
        return "<input type=\"submit\"   value=\"$value\" class=\"btn btn-primary btn-lg\" >";
    }

    function date($name, $value)
    {
        return "<script language=\"javascript\">
$(document).ready(function()
	{
	var yearFrom=1990;
	var yearTo=2030;
	$('#$name').datepicker(
		{
		dateFormat: 'yy-mm-dd',
		buttonImage: '" . front::$view->base_url . "/images/calendar.png',
		buttonText: '".lang("please_choose").lang("datetime")."',
		buttonImageOnly: true,
		showOn: 'both',
		yearRange: yearFrom+':'+yearTo,
		clearText:'".lang("clear")."',
		closeText:'".lang("close")."',
		prevText:'".lang("previous_month")."',
		nextText:'".lang("next_month")."',
		currentText:' ',
		monthNames:['".lang("january")."','".lang("february")."',
		'".lang("march")."','".lang("april")."','".lang("may")."','".lang("june")."',
		'".lang("july")."','".lang("august")."','".lang("september")."','".lang("october")."',
		'".lang("november")."','".lang("december")."']
	}
		);
}
);
</script>\r\n" . self::input($name,
                $value);
    }

    function doDef($res)
    {
        return $res[1];
    }
    function getform($name, $form, $field, $data,$check=null)
    {
		//var_dump($name);
        $newselectname='select_'.lang::getistemplate();
        if (get('table') && isset(setting::$var[get('table')][$name])){
            if($form[$name]['select']==""){
                $form[$name] = setting::$var[get('table')][$name];
            }else{
                $newselect=$form[$name]['select'];
                $form[$name] = setting::$var[get('table')][$name];
                $form[$name]['select']=$newselect;
            }
        }
		//var_dump($form[$name]);
        if (get('form') && isset(setting::$var[get('form')][$name]) && $form[$name]['select']=="" )
            $form[$name] = setting::$var[get('form')][$name];
		//var_dump($form[$name]);
        if (isset($form[$name]['default'])) {
            if ((int)PHP_VERSION >= 7) {
                $form[$name]['default'] = preg_replace_callback('/\{\?([^}]+)\}/', "self::doDef", $form[$name]['default']);
            } else {
                $form[$name]['default'] = preg_replace('/\{\?([^}]+)\}/e', "eval('return $1;')", $form[$name]['default']);
            }
        }
        if (!isset($data[$name]) && isset($form[$name]['default']))
            $data[$name] = @$form[$name]['default'];
        if (preg_match('/templat/', $name) && empty($data[$name]))
            $data[$name] = @$form[$name]['default'];
        //var_dump($field);

        if (@$form[$name]['filetype'] == 'image') {
            $return = form::upload_image($name, front::post($name) ? front::post($name) : @$data[$name]);
        } elseif (@$form[$name]['filetype'] == 'file') {
            $return = form::upload_file($name, front::post($name) ? front::post($name) : @$data[$name]);
        } elseif (@$form[$name]['filetype'] == 'image1') {
            $return = form::upload_image1($name, front::post($name) ? front::post($name) : @$data[$name]);
        } elseif (@$form[$name]['filetype'] == 'image2') {
            $return = form::upload_image2($name, front::post($name) ? front::post($name) : @$data[$name]);
        } elseif (@$form[$name]['filetype'] == 'image_mui') {
            $return = form::upload_imagemui($name, front::post($name) ? front::post($name) : @$data[$name]);
        } elseif (@$form[$name]['filetype'] == 'thumb') {
            $return = form::upload_thumb($name, front::post($name) ? front::post($name) : @$data[$name]);
        }
        elseif (@$form[$name]['selecttype'] == 'select') {
            //var_dump($form[$name]);

            if($form[$name][$newselectname]!=""){    //区分表单的多选  和  内容的多选
                preg_match_all('%\((.*?)\)(\S+)%s', $form[$name][$newselectname], $result, PREG_SET_ORDER);
            }else{
                preg_match_all('%\((.*?)\)\((.*?)\)%s', $form[$name]["select"], $result, PREG_SET_ORDER);
            }

            //var_dump($result);
			$sdata = array();
            foreach ($result as $res) $sdata[$res[1]] = $res[2];
			//var_dump($sdata)
            $return = form::select($name, front::post($name) ? front::post($name) : @$data[$name], $sdata, ' class="form-control select"');
        }
        elseif (@$form[$name]['selecttype'] == 'radio') {

            if($form[$name][$newselectname]!=""){    //区分表单的多选  和  内容的多选
                $form[$name]['select']=$form[$name][$newselectname];
            }
            preg_match_all('/\(([\d\w]+)\)\((\S+)\)/m', $form[$name]['select'], $result, PREG_SET_ORDER);
            $_res = '';
            foreach ($result as $res) $_res .= form::radio($name, $res[1], $res[1] == (front::post($name) ? front::post($name) : @$data[$name])) . $res[2];
            $return = $_res;
        }
        elseif (@$form[$name]['selecttype'] == 'checkbox') {

            if($form[$name][$newselectname]!=""){    //区分表单的多选  和  内容的多选
                $form[$name]['select']=$form[$name][$newselectname];
            }
            preg_match_all('/\(([\d\w]+)\)(\S+)/is', $form[$name]['select'], $result, PREG_SET_ORDER);
            $_res = '';
            $values = front::post($name) ? front::$post[$name] : @$data[$name];
            if (is_string($values))
                $values = explode(',', $values);
            if (!$values)
                $values = array();
            foreach ($result as $res) $_res .= $res[2] . form::checkbox($name . '[]', $res[1], in_array($res[1], $values)) . "";
            return $_res;
        }
        elseif (@$form[$name]['selecttype'] == 'checkbox2') {
            preg_match_all('/\(([\d\w]+)\)(\S+)/is', $form[$name]['select'], $result, PREG_SET_ORDER);
            $_res = '';
            $values = front::post($name) ? front::$post[$name] : @$data[$name];
            if (is_string($values))
                $values = explode(',', $values);
            if (!$values)
                $values = array();
            foreach ($result as $res) $_res .= $res[2] . form::checkbox2($name . '[]', $res[1], in_array($res[1], $values)) . "";
            return $_res;
        }
        elseif (@$field[$name]['type'] == 'text') {
            //var_dump($field);
            $return = form::textarea($name, front::post($name) ? front::post($name) : @$data[$name], '');
        }
        elseif (@$field[$name]['type'] == 'bigtext') {
            //var_dump($field);
            $return = form::textarea($name, front::post($name) ? front::post($name) : @$data[$name], '');
        }
        elseif (@$field[$name]['type'] == 'mediumtext' || $form[$name]['type'] == 'mediumtext') {
          /*  $return = form::ueditor($name, front::post($name) ? front::post($name) : @$data[$name]);*/
            $return = form::wangueditor($name, front::post($name) ? front::post($name) : @$data[$name]);
        }
        elseif (@$field[$name]['type'] == 'datetime' or @$field[$name]['type'] == 'date') {
            $return = form::date($name, front::post($name) ? front::post($name) : @$data[$name]);
        }
        else {
            $placeholder = '';
            if (isset($form[$name]['placeholder'])) {
                $placeholder = 'placeholder="' . $form[$name]['placeholder'] . '"';
            }
            $return = form::input($name, front::post($name) ? front::post($name) : @$data[$name], $placeholder,$check);
        }

        if ($field[$name]['notnull'])
            $return .= "";
        if (@$form[$name]['tips']) {
            if ((int)PHP_VERSION >= 7) {
                $tips = preg_replace_callback('/\{\?([^}]+)\}/', "self::doDef", $form[$name]['tips']);
            } else {
                $tips = preg_replace('/\{\?([^}]+)\}/e', "eval('return $1;')", $form[$name]['tips']);
            }


            $return .= "" . $tips;
        }
        return $return;
    }

    static function select_option($name, $form, $value)
    {
        $newselectname='select_'.lang::getistemplate();
        preg_match_all('/\(([\d\w]+)\)(\S+)/im', $form[$newselectname], $result, PREG_SET_ORDER);
        $values = explode(',', trim($value, ','));
        $res = array();
        foreach ($values as $key => $rs) {
            //$res[$key]=$result[$rs][2];
            foreach ($result as $a => $b) {
                if ($b[1] == $rs) {
                    $res[$key] = $b[2];
                }
            }
        }
        return implode(',', $res);
    }
    //栏目图片和内容缩略图
    static function upload_thumb($name, $value)
    {

        $cut_url = url('tool/cut_image', false);
        $img_url = './common/js/ajaxfileupload/pic.png';
        if (front::$act == 'edit' && $value) {
            /*if(strtolower(substr($value,0,7)) != 'http://'){
                $img_url = $value;
            }else{
                $img_url = $value;
            }*/
            $img_url = $value;
        }
        $res = "
        <div style=\"clear:both\"></div><div style=\"clear:both;float:left;margin-right:10px;\">
        <a title=\"".lang('select_files')."\" onclick=\"javascript:windowsdig('".lang('select_files')."','iframe:index.php?case=file&act=updialog&fileinputid={$name}&getbyid={$name}_preview&max=1&checkfrom=picshow&admin_dir=".config::getadmin('admin_dir')."','900px','480px','iframe')\" href=\"#body\"><span id=\"{$name}_preview\"><img src=\"$img_url\" class=\"img-responsive\" onerror='this.src=\"common/js/ajaxfileupload/pic.png\"' /></span></a></div><div class=\"blank10\"></div><div class=\"thumb-box\"><input name=\"$name\"  id=\"$name\" value=\"$value\"  class=\"form-control\" />" .
            '<div class="blank10"></div><input value=" '.lang('delete').' " class="btn btn-gray  thumb-del" title="'.lang('delete').'" id="' . $name . '_del" onclick="pics_delete(\'\',\'' . $name . '\');document.getElementById(\'' . $name . '_preview\').innerHTML=\'<img src=\\\'common/js/ajaxfileupload/pic.png\\\' style=\\\'max-width:90px\\\'>\';" value="'.lang('delete').'" type="button" name="delbutton" class="btn btn-gray" /></div>';

        
        return $res;
    }
    //图片上传字段
    static function upload_image($name, $value)
    {
        //////file-input版////
        $uploadUrl = url('tool/uploadimage3',false);
        $res = "";
        $base_url = front::$view->base_url;
        $res .= <<<EOT
        
        <img src="$value" style="max-width:90px;">
        <div class="blank10"></div>
        <input id="{$name}" name="{$name}" value="$value" type="text" class="form-control">
        <div class="blank10"></div>
        <input id="file_{$name}" name="file_{$name}" type="file" class="form-control">
<script>
    $( function () {
        $("#file_{$name}").fileinput( {
            uploadUrl: '$uploadUrl',
            allowedFileExtensions: [ 'jpg', 'png', 'gif' ],
            maxFileSize: 200000,
            language: 'zh',
            maxFilesNum: 1,
            maxFileCount: 1,
            showPreview: false,
            showCaption: false,
            showUploadedThumbs: false
        } ).on( 'fileerror', function ( event, data, msg ) {
            alert( msg );
        } ).on( 'fileuploaded', function ( event, data, previewId, index ) {
            response = data.response;
            if ( response.file_{$name}.code == '0' ) {
                $('#{$name}').val(response.file_{$name}.name);
                $('#{$name}').parent().find('img').attr("src",response.file_{$name}.name);
            } else {
                alert( response.file_{$name}.msg );
            }
        } );
    } );
</script>
EOT;
        //////////编辑器版 /////
        /*$res = "";
        $res .= '<input type="text" id="'.$name.'" name="'.$name.'" />';
        $res .= '<input type="button" id="btnup_'.$name.'" value="上传图片"/>';
        $res .= <<< EOT
        <script>
    var _editor;
    $(function() {
        //重新实例化一个编辑器，防止在上面的editor编辑器中显示上传的图片或者文件
        _editor = UE.getEditor('upload_ue');
        _editor.ready(function () {
            //设置编辑器不可用
            _editor.setDisabled('insertimage');
            //隐藏编辑器，因为不会用到这个编辑器实例，所以要隐藏
            _editor.hide();
            //侦听图片上传
            _editor.addListener('beforeInsertImage', function (t, arg) {
                $("#{$name}").attr("value", arg[0].src);
                //图片预览
                //$(".form-post .pic-show").show();
                //$("#preview").attr("src", arg[0].src);
            })
        });
        $('#btnup_{$name}').click(function () {
            dlg = _editor.getDialog("insertimage");
            dlg.render();
            dlg.open();
        });

    });
</script>
EOT;*/


        //////////file版//
		/*$cut_url = url('tool/cut_image', false);
        $img_url = './common/js/ajaxfileupload/pic.png';
		$img_url = $value;
        //栏目图片上传
        $res = "<a title=\"选择文件\" onclick=\"javascript:windowsdig('选择文件','iframe:index.php?case=file&act=updialog&fileinputid={$name}&getbyid={$name}_preview&max=1&checkfrom=picshow','900px','480px','iframe')\" href=\"#body\"><span id=\"{$name}_preview\" class=\"pull-left\"><img src=\"$img_url\" class=\"img-responsive\" onerror='this.src=\"common/js/ajaxfileupload/pic.png\"' /></span><div class=\"blank10\"></div></a>
           <div class=\"row\"><div class=\"col-xs-8 col-sm-8 col-md-9 col-lg-10 text-right\"><input name=\"$name\"  id=\"$name\" value=\"$value\"  class=\"form-control\" />" .
            '</div><div class="col-xs-4 col-sm-4 col-md-3 col-lg-2 text-left"><input value=" 删除 " class="btn btn-primary" title="删除" id="' . $name . '_del" onclick="pics_delete(\'\',\'' . $name . '\');document.getElementById(\'' . $name . '_preview\').innerHTML=\'<img src=\\\'./common/js/ajaxfileupload/pic.png\\\' style=\\\'max-width:90px\\\'>\';" value="删除" type="button" name="delbutton" class="btn btn-gray" /></div></div>';
        return $res;*/
		return $res;
    }

    static function upload_imagemui($name, $value)
    {

        $res = lang('address')."：<input name=\"$name\"  id=\"$name\" value=\"$value\"  class=\"form-control\" />";
        $img_url = './common/js/ajaxfileupload/pic.png';
        if (front::$act == 'edit' && $value) {
            $img_url = $value;
        }
        $res .= "
	<a title=\"".lang('select_files')."\" onclick=\"javascript:windowsdig('".lang('select_files')."','iframe:index.php?case=file&act=updialog&fileinputid={$name}&getbyid={$name}_preview&max=1&checkfrom=picshow','900px','480px','iframe')\" href=\"#body\"><img src=\"{$img_url}\" id=\"{$name}_preview\" onerror='this.src=\"common/js/ajaxfileupload/pic.png\"'/><div class=\"blank10\"></div></a>";
        $res .= '</div>';
        return $res;
    }

    static function upload_image3($name, $value)
    {
        $res = "<div class=\"blank10\"></div><span id=\"{$name}_preview\"></span>
	<br>
	".lang('address')."：<input name=\"$name\"  id=\"$name\" value=\"$value\" size=\"50\"/>";
        if (front::$act == 'edit' && $value) {
            $res .= "<script>image_preview('$name','$value');</script>
	";
        }
        $res .= "<br>
	".lang("upload")."：<input type=\"file\" name=\"{$name}_upload\" id=\"{$name}_upload\" style=\"width:400px\" onchange=\"image_preview('$name',this.value,1)\"/>
	&nbsp;&nbsp;<input type=\"button\" name=\"{$name}upload\"  id=\"{$name}upload\" onclick=\"return ajaxFileUpload('{$name}_upload','" . url('tool/upload3/site/' . front::get('site'),
                false) . "','#{$name}_loading');\" value=\"".lang("upload")."\" class=\"btn btn-gray\" />
		<img id=\"uploading\" src=\"{$base_url}/images/loading.gif\" style=\"display:none;\">";
        return $res;
    }

    static function upload_image1($name, $value)
    {
        $res = "<div class=\"blank10\"></div><span id=\"{$name}_preview\"></span>
	<br>
	".lang('address')."：<input name=\"$name\"  id=\"$name\" value=\"$value\" size=\"50\"/>";
        if (front::$act == 'edit' && $value) {
            $res .= "<script>image_preview('$name','$value');</script>
	".lang("change")."：";
        }
        $res .= "<br>
	".lang("upload")."：<input type=\"file\" name=\"{$name}_upload\" id=\"{$name}_upload\" style=\"width:400px\" onchange=\"image_preview('$name',this.value,1)\"/>
	&nbsp;&nbsp;<input type=\"button\" name=\"{$name}upload\"  id=\"{$name}upload\" onclick=\"return ajaxFileUpload('{$name}_upload','" . url('tool/upload1/site/' . front::get('site'),
                false) . "','#{$name}_loading');\" value=\"".lang("upload")."\" class=\"btn btn-gray\" />
		<img id=\"uploading\" src=\"{$base_url}/images/loading.gif\" style=\"display:none;\">";
        return $res;
    }

    static function getuploadhtml($i, $name, $purl, $value)
    {
        $cname = $name;
        $name = $name . $i;
        $res = '<div id="' . $name . '_up"><span id="' . $name . '_preview"></span><br><br>'.lang('address').'：<input name="' . $name . '" id="' . $name . '" value="' . $value . '" size="50"/> <input type="button" id="' . $name . '_del" class=\"btn btn-gray\" name="delbutton" value="'.lang('delete').'" onclick="pics_delete(' . $i . ',\'' . $cname . '\');" style="display:;"><br><br>';
        $res .= "<script>image_preview('{$name}','$value');</script>".lang("change")."：";
        $res .= '<input type="file" name="' . $name . '_upload" id="' . $name . '_upload" style="width:400px" onchange="image_preview(\'' . $name . '\',this.value,1)"/>&nbsp;&nbsp;<input type="button" name="' . $name . 'upload" id="' . $name . 'upload' . $i . '" onclick="return ajaxFileUpload2(\'' . $name . '_upload\',\'' . $purl . '\',\'#' . $cname . '_loading\');" value="'.lang("upload").'" class="btn btn-gray" /></div>';
        return $res;
    }

   
	//内页多图
    static function upload_image2($name, $value)
    {
        $res = "<div id=\"uploadarea\">";
        if (front::$act == 'edit' && $value) {
            $pics = unserialize($value);
            $i = -1;
            if (is_array($pics) && !empty($pics)) {
                foreach ($pics as $k => $v) {
                    $i++;
                    $res .= form::getuploadhtml($k, 'pics', url('tool/upload2/site/' . front::get('site'), false), $v);
                }
                $i++;
            }
            $res .= form::getuploadhtml(++$i, 'pics', url('tool/upload2/site/' . front::get('site'), false), '');
        } else {
            $res .= "<div id=\"pics0_up\"><span id=\"{$name}0_preview\"></span><div class=\"blank10\"></div><input name=\"{$name}0\"  id=\"{$name}0\" value=\"$value\"  class=\"form-control\" /> <input type=\"button\" id=\"{$name}0_del\" name=\"delbutton\" value=\"".lang('delete')."\" onclick=\"pics_delete('0','{$name}');\" class=\"btn btn-gray\" style=\"display:none;\">";
            $res .= "<input type=\"file\" name=\"{$name}0_upload\" id=\"{$name}0_upload\" style=\"width:400px\" onchange=\"image_preview('{$name}0',this.value,1)\"/><input type=\"button\" name=\"{$name}0upload\"  id=\"{$name}0upload\" onclick=\"return ajaxFileUpload2('{$name}0_upload','" . url('tool/upload2/site/' . front::get('site'), false) . "','#{$name}0_loading','{$name}');\" value=\"".lang("upload")."\" class=\"btn btn-gray  thumb-del\" /></div>";
        }
        $res .= "</div>";
        return $res;
    }

    static function upload_file($name, $value)
    {
        $res = "<span id=\"{$name}_info\"></span>
	<input name=\"$name\"  id=\"$name\" value=\"$value\" class=\"form-control\" />";
        $res .= "<div class='blank10'></div><a href=\"javascript:;\" class=\"file\">".lang('select_files')."
        <input type=\"file\" name=\"{$name}_upload\" id=\"{$name}_upload\">
    </a>
    
<input type=\"button\" name=\"{$name}upload\"  id=\"{$name}upload\" onclick=\"return ajaxFileUpload('{$name}_upload','" . url('tool/upload_file', false) . "','#{$name}_loading');\" value=\"".lang("upload")."\" class=\"btn btn-gray  thumb-del\" />
<img id=\"{$name}_loading\" src=\"{$base_url}/images/loading.gif\" style=\"display:none;\">
<input class=\"btn btn-gray thumb-del\" value=\"".lang('delete')."\" type=\"button\" name=\"delbutton\"  onclick=\"attachment_delect(get('{$name}upload').value)\" />";
        return $res;
    }

    static function editor($name, $value = '')
    {
        $fckeditor = new fckeditor($name);
        $fckeditor->Value = $value;
        /*if(preg_match('/^my_/is', $name)){
            $fckeditor->ToolbarSet = "MyForm";
        }*/
        return $fckeditor->CreateHtml() . "
		<br>
	<a href=\"javascript:;\" class=\"fckeditor_height_add_sub\" onclick=\"javascript:heightAdd('$name');\">+</a>
	<a href=\"javascript:;\" class=\"fckeditor_height_add_sub\" onclick=\"javascript:heightSub('$name');\">-</a>
                ";
    }

    static function ueditor($name, $value = '')
    {
        $root = config::getadmin('base_url') . '/ueditor';
        $str = <<< EOT
    <script id="$name" name="$name" type="text/plain">$value</script>
    <script type="text/javascript">
	window.UEDITOR_HOME_URL = "{$root}/";
	$(function(){
	    UE.delEditor('$name');
        var ue_$name = UE.getEditor('$name',{
            autoHeightEnabled : false
        });
	});
    </script>
EOT;
        return $str;
    }

    //wang编辑器
    static function wangueditor($name, $value = '')
    {
        $str = <<< EOT
    <div id="$name"  >$value</div>
    <input type="hidden" name="$name"  value="" />
    <script type="text/javascript">
        var E = window.wangEditor;
        var editor_$name = new E('#$name')
        editor_$name.customConfig.uploadImgShowBase64 = true
        // 或者 var editor = new E( document.getElementById('editor') )
         // 自定义菜单配置
        editor_$name.customConfig.menus = [
            'head',  // 标题
            'bold',  // 粗体
            'fontSize',  // 字号
            'italic',  // 斜体
            'underline',  // 下划线 
            'foreColor',  // 文字颜色
            'backColor',  // 背景颜色
            'link',  // 插入链接
            'list',  // 列表
            'justify',  // 对齐方式
            'quote',  // 引用
            'table',  // 表格
            'image',  // 插入图片   
            'undo',  // 撤销
            'redo'  // 重复
        ];
        editor_$name.create();
	    $("#$name").val('$value');
    </script>
EOT;
        return $str;
    }

    static function arraytoselect($array)
    {
        $res = '';
        if (is_array($array) && !empty($array))
            foreach ($array as $key => $value) $res .= "($key)($value) ";
        return $res;
    }

    static function yesornotoarray($str)
    {
        return array(1 => $str, 0 => '不' . $str);
    }
}