<?php
namespace Manage\Src\Lib;

use Dever;

class Input
{
    /**
     * desc
     *
     * @return string
     */
    public static function modal($modal, $desc)
    {
        return '<a href="#dever_modal" data-toggle="modal" onclick="$(\'#dever_modal_body\').html($(this).next().html())">' . $modal . '</a><div style="display:none;">' . $desc . '</div>';
    }

    /**
     * desc
     *
     * @return string
     */
    public static function desc($desc)
    {
        return '';
        return $desc;
    }

    /**
     * hr 分割线
     *
     * @return string
     */
    public static function hr($param)
    {
        return '<div class="dever_form_hr ' . (isset($param['class']) ? $param['class'] : '') . '" ' . (isset($param['attr']) ? $param['attr'] : '') . '>' . $param['name'] . '</div>';
    }

    /**
     * cue
     *
     * @return string
     */
    public static function cue($param)
    {
        $param['cue'] = isset($param['cue']) ? $param['cue'] : '';
        if (strpos($param['name'], '-') !== false) {
            $temp = explode('-', $param['name']);
            $param['name'] = $temp[0];
            $param['cue'] = $temp[1];
        } elseif (strpos($param['name'], '(') !== false) {
            $temp = explode('(', $param['name']);
            $param['name'] = $temp[0];
            $param['cue'] = str_replace(')', '', $temp[1]);
        } elseif (strpos($param['name'], '（') !== false) {
            $temp = explode('（', $param['name']);
            $param['name'] = $temp[0];
            $param['cue'] = str_replace('）', '', $temp[1]);
        }

        return $param;
    }

    /**
     * pageLeft
     *
     * @return string
     */
    public static function pageLeft($param)
    {
        $param = self::cue($param);

        if ($param['cue']) {
            $param['cue'] = '<span style="font-size:12px;font-weight:normal;font-color:#bababa;margin-left:5px;">[' . $param['cue'] . ']</span>';
        }

        $html = '<label style="font-size:14px;font-weight:bold;">' . $param['name'] . $param['cue'] . '</label>';

        return $html;
    }

    /**
     * textarea
     *
     * @return string
     */
    public static function textarea($param)
    {
        return '<textarea style="height:100px;" update_type="value" class="update_value form-control ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" >' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '</textarea>';

        return '<textarea style="height:100px;" update_type="value" class="update_value form-control ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '">' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '</textarea>';
    }

    /**
     * image
     *
     * @return string
     */
    public static function image($param)
    {
        if (isset($param['value']) && $param['value']) {
            $pic = 'src="' . $param['value'] . '"';
        } elseif (isset($param['places'])) {
            $pic = 'src="http://placehold.it/' . $param['place'] . '"';
        } else {
            $pic = 'src="" style=display:none;';
        }
        return '<input type="button" style="width:10%;" class="form-control image_upload" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="选择文件"/>
        <div style="margin:10px;">
        <img ' . $pic . ' onclick="picDel($(this), \'' . $param['name'] . '_' . $param['index'] . '\', 1);" class="update_value" update_type="src" id="show_' . $param['name'] . '_' . $param['index'] . '" width="150" /></div>
        <input type="text" class="update_value form-control ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" id="' . $param['name'] . '_' . $param['index'] . '" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '">';
    }

    /**
     * images
     *
     * @return string
     */
    public static function images($param)
    {
        $pic = '';
        if (isset($param['value'])) {
            $temp = explode(',', $param['value']);
            foreach ($temp as $k => $v) {
                $pic .= '<a href="javascript:;" title="点此删除" onclick="picDel($(this), \'' . $param['name'] . '_' . $param['index'] . '\')"><img src="' . $v . '" id="show_' . $param['name'] . '_' . $param['index'] . '_' . $k . '" width="150"  style="margin-left:5px;" alt="点此删除"/></a>';
            }
        }
        return '<input type="button" style="width:10%;" class="form-control image_upload" mul="yes" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="选择文件"/>
        <div style="margin:10px;" update_type="html"  class="update_value ' . $param['name'] . '_' . $param['index'] . '_mul">' . $pic . '</div>

        <input type="text" class="update_value form-control ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" id="' . $param['name'] . '_' . $param['index'] . '" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '">';
    }

    /**
     * upload
     *
     * @return string
     */
    public static function upload($param)
    {
        return '<input type="file" style="width:10%;" class="form-control image_upload" t="file" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '"/>
        <div><input type="text" class="update_value form-control ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" id="' . $param['name'] . '_' . $param['index'] . '" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '">
        </div>';
        //return '<input type="file" class="form-control" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '" name="' . $param['name'] . '"/>';
    }

    /**
     * upload
     *
     * @return string
     */
    public static function uploads($param)
    {
        $file = '';
        if (isset($param['value']) && $param['value']) {
            $temp = explode(',', $param['value']);
            foreach ($temp as $k => $v) {
                $upload = Dever::load('upload/file-check', array('option_key' => md5($v)));
                $file .= '<li><a href="' . $v . '" rel="box" title="点此下载" >' . $upload['source_name'] . '</a>&nbsp;&nbsp;<a href="javascript:;" style="color:red;" title="点此删除" onclick="fileDel($(this), \'' . $param['name'] . '_' . $param['index'] . '\')">[删除]</a></li>';
            }
        }

        return '<input type="file" style="width:10%;" class="form-control image_upload" t="file" mul="yes" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '"/>

        <ul style="margin:10px;" update_type="html"  class="update_value ' . $param['name'] . '_' . $param['index'] . '_mul">' . $file . '</ul>

        <input type="hidden" class="update_value form-control ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" id="' . $param['name'] . '_' . $param['index'] . '" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '">';
        //return '<input type="file" class="form-control" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '" name="' . $param['name'] . '"/>';
    }

    /**
     * editor
     *
     * @return string
     */
    public static function editor($param)
    {
        return '<textarea style="width:100%;display: inline"  update_type="value" class=" update_value editor" id="' . $param['name'] . '_editor" key="' . (isset($param['key']) ? $param['key'] : 1) . '" name="' . $param['name'] . '" rows="18" cols="100" >' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '</textarea>';
    }

    /**
     * markdown
     *
     * @return string
     */
    public static function markdown($param)
    {
        return '<textarea style="height:300px;" update_type="value" key="' . (isset($param['key']) ? $param['key'] : 1) . '" class="maze-note update_value form-control ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" >' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '</textarea>';
    }

    /**
     * selector
     *
     * @return string
     */
    public static function selector($param, $type = '')
    {
        $html = '';

        if (isset($param['key']) && strpos($param['key'], '.css') !== false) {
            $param['key'] = '<link rel="stylesheet" href="' . $param['key'] . '"/>';
        }

        if (isset($param['option'])) {
            foreach ($param['option'] as $k => $v) {
                $check = '';

                if ((isset($param['value']) && $param['value'] == $k) || (empty($param['value']) && isset($param['default']) && $param['default'] == $k)) {
                    $check = 'checked';
                }

                if (is_array($v)) {
                    $value = $v['name'];
                } else {
                    $value = $v;
                }

                $html .= '<a href="javascript:;" onclick="selector($(this))" class="' . $param['name'] . '_selector selector" data-check="' . $check . '" data-name="' . $param['name'] . '" data-value="' . $k . '">' . $value . '</a>&nbsp;&nbsp;';
            }

            $html .= self::hidden($param);
        }
        return '<div class="am-btn-group" >' . $html . '</div>';
    }

    /**
     * radio
     *
     * @return string
     */
    public static function radio($param, $type = '')
    {
        $html = '';

        if (isset($param['option'])) {
            if (isset($param['option']['state']) && $param['option']['state'] == 1) {
                if (isset($param['value'])) {
                    $param['value'] = explode(',', $param['value']);
                } else {
                    $param['value'] = array();
                }
                # 处理比较复杂的多维数组
                unset($param['option']['state']);

                foreach ($param['option'] as $k => $v) {
                    $check = '';
                    if (isset($param['update_parent'])) {
                        $input_type = $param['update_parent'];
                    } else {
                        $input_type = $param['update'];
                    }

                    //{check}
                    $html .= '<input update_type="checked" class="update_value checkbox-checkall ' . (isset($param['valid']) ? $param['valid'] : '') . '" type="' . $input_type . '" name="temp[]" value="'.$param['name'] . '-' . $k . '"/> 【' . $v['name'] . '】&nbsp;&nbsp;<br />';

                    $span = array('', '');

                    if (isset($v['child']) && $v['child']) {
                        //$i = 1;
                        $j = -1;
                        $html .= '<ul style="list-style:none;margin:0px;display:;" class="">';
                        foreach ($v['child'] as $ki => $vi) {
                            if (!is_array($vi)) {
                                $temp = $vi;
                                $vi = array();
                                $vi['name'] = $temp;
                                $vi['id'] = $ki;
                            }
                            if (isset($v['url'])) {
                                $span = array('<span class="edit" data-url="' . Dever::url($v['url'] . '?id=' . $vi['id']) . '">', '</span>');
                            }
                            $check = '';
                            $disabled = 'disabled="true"';
                            if (isset($param['value']) && in_array($ki, $param['value'])) {
                                $check = 'checked';
                                $disabled = '';
                                $j++;
                            } elseif (isset($param['default']) && is_array($param['default']) && (in_array($k . '_' . $ki, $param['default']))) {
                                $check = 'checked';
                                $disabled = '';
                                $j++;
                            }

                            $input = '';

                            if (isset($param['update_input'])) {
                                if (isset($param['update_input_data']) && isset($param['update_input_data'][$j])) {
                                    $input_value = $param['update_input_data'][$j];
                                } else {
                                    $input_value = 1;
                                }

                                $input = '[' . $param['update_input'] . ']：<input class="form-control" name="' . $param['name'] . '_input[]" type="text" value="' . $input_value . '" style="width:5%;margin:5px;display:inline" placeholder="' . $param['update_input'] . '" ' . $disabled . '/>';
                            }

                            $html .= '<li><input update_type="checked" class="update_value checkbox-checkall-' . $param['name'] . '-'. $k . ' ' . (isset($param['valid']) ? $param['valid'] : '') . '" type="' . $param['update'] . '" name="' . $param['name'] . '[]" value="' . $ki . '" ' . $check . '/> ' . $span[0] . $vi['name'] . $span[1] . '&nbsp;&nbsp;' . $input . '</li>';

                            //++$i;
                        }
                        $html .= '</ul>';
                    }

                    $html .= '<br />';
                }
            } else {
                $js = '';
                if (isset($param['control']) && is_string($param['control'])) {
                    //print_r($param);die;
                    $js = ' show_id="' . $param['control'] . '" onclick="inputShow($(this), \'' . $param['control'] . '\')"';
                } elseif (isset($param['bind'])) {
                    $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
                    $js = $param['bind'][0] . '="' . $param['bind'][1] . '(\'' . $param['name'] . '\', $(this), ' . $param['bind'][2] . ')" ';

                    $js .= ' onload="' . $param['bind'][1] . '(\'' . $param['name'] . '\', $(this), ' . $param['bind'][2] . ')" ';
                }

                $param['parent'] = isset($param['parent']) ? $param['parent'] : '0';
                $param['parent'] .= '_' . $param['name'];

                if ($param['update'] == 'checkbox' && empty($param['checkall'])) {
                    //$html .= '<input update_type="checked" class="checkbox-checkall ' . $param['name'] . ' update_value" type="' . $param['update'] . '" name="temp_' . $param['name'] . '[]" value="' . $param['parent'] . '"/> 全选 &nbsp;&nbsp;';
                }

                foreach ($param['option'] as $k => $v) {
                    $check = '';
                    if (is_array($v)) {
                        $value = $v['name'];
                        isset($v['id']) && $k = $v['id'];
                    } else {
                        $value = $v;
                    }

                    if (isset($param['bit'][$k])) {
                        if (isset($param['value']) && ($param['value'] & $k) > 0) {
                            $check = 'checked';
                        }
                    } elseif (isset($param['value'])) {
                        if (is_string($param['value']) && strpos(',' . $param['value'] . ',', ',' . $k . ',') !== false) {
                            $check = 'checked';
                        } elseif (is_array($param['value']) && in_array($k, $param['value'])) {
                            $check = 'checked';
                        }
                    } elseif (isset($param['default'])) {
                        if (is_string($param['default']) && strpos(',' . $param['default'], ',' . $k) !== false) {
                            $check = 'checked';
                        } elseif (is_array($param['default']) && in_array($k, $param['default'])) {
                            $check = 'checked';
                        }
                    }

                    $cjs = $js;
                    if (isset($param['control']) && is_string($param['control']) && $param['control'] != $param['name']) {
                        $cjs = str_replace('update_', '', str_replace($param['control'], $param['name'], $js));
                    }
                    $html .= '<input update_type="checked" class="autoload checkbox-checkall-' . $param['parent'] . ' ' . $param['name'] . ' update_value ' . (isset($param['valid']) ? $param['valid'] : '') . '" type="' . $param['update'] . '" name="' . $param['name'] . '[]" value="' . $k . '" ' . $check . ' ' . $cjs . '/> ' . $value . ' &nbsp;&nbsp;';

                    if (isset($param['bind'])) {
                        //$html .= '<script>$(document).ready(function(){$(".checkbox-checkall-'.$param['parent'].'").click();})</script>';
                    }
                }
            }
        }
        return '<div class="am-btn-group" >' . $html . '</div>';
    }

    /**
     * group
     *
     * @return string
     */
    public static function group($param, $class = '', $hidden = '', $change = '')
    {
        $html = $class ? '<div class="' . $class . '">' : '';

        $html .= $hidden . '<select class="update_value form-control ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '"  ' . $change . '>';

        if (isset($param['option'])) {
            foreach ($param['option'] as $k => $v) {
                if ($v['id'] <= 0) {
                    $html .= '<option value="0" selected>' . $v['name'] . '</option>';
                } else {
                    $html .= '<optgroup label="' . $v['name'] . '">';

                    if (isset($v['child'])) {
                        foreach ($v['child'] as $k1 => $v1) {
                            $selected = '';

                            if ((isset($param['value']) && $param['value'] == $v1['id']) || (empty($param['value']) && isset($param['default']) && $param['default'] == $v1['id'])) {
                                $selected = 'selected';
                            }
                            $html .= '<option value="' . $v1['id'] . '" ' . $selected . '>' . $v1['name'] . '</option>';
                        }
                    }

                    $html .= '</optgroup>';
                }
            }
        }

        $html .= '</select>';

        $html .= $class ? '</div>' : '';

        return $html;
    }

    /**
     * mul select
     *
     * @return string
     */
    public static function mul($param, $class = '', $hidden = '', $change = '')
    {
        $div = 'div';
        $w = 'width:20%;';
        if ($class == 'span') {
            $div = 'span';
            $w = '';
        }

        $num = 0;
        $level = -1;
        if (is_array($param['option'])) {
            $num = $param['option'][1];
            $level = isset($param['option'][2]) ? $param['option'][2] : $level;
            $param['option'] = $param['option'][0];
        }
        $html = '<' . $div . ' class="' . $class . ' dever-mul-' . $param['name'] . '">';
        if (isset($param['value']) && is_array($param['value'])) {
            $param['value'] = implode(',', $param['value']);
            /*
        $count = count($param['value']) - 1;
        if($param['value'][$count] <= 0)
        {
        $param['value'] = $param['value'][$count-1];
        }
        else
        {
        $param['value'] = $param['value'][$count];
        }
         */
        }

        $html .= '<script>function mul_' . $param['name'] . '(level,state){if(state == 1){select_mul(0, ".dever-mul-' . $param['name'] . '")}select_mul(level, ".dever-mul-' . $param['name'] . '","' . $param['option'] . '", "' . $param['name'] . '", "' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '", "' . (isset($param['valid']) ? $param['valid'] : '') . '", "' . $w . '", ' . $num . ')};';

        $html .= '$(document).ready(function(){mul_' . $param['name'] . '(' . $level . ',0)});</script>';

        $html .= '</' . $div . '>';

        return $html;
    }

    /**
     * select
     *
     * @return string
     */
    public static function select($param, $class = '', $hidden = '', $change = '')
    {
        $html = $class ? '<div class="' . $class . '">' : '';

        $child_class = '';
        if (isset($param['child'])) {
            $child_param['name'] = 'update_' . $param['child_name'];
            isset($param['value']) && $param['value'] = $param['value'];
            isset($param['child_value']) && $child_param['value'] = $param['child_value'];

            $change = 'style="width:45%" id="' . $param['name'] . '" data-child="' . $child_param['name'] . '_child" ';
            $child_class = ' change';
            //$param['name'] .= '_parent';
        }

        if (isset($param['bind'])) {
            $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
            $change = $param['bind'][0] . '="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';

            $child_class .= ' change';
        }
        $html .= $hidden . '<select class="update_value form-control ' . $child_class . '  ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '"  ' . $change . '>';

        if (isset($param['option'])) {
            if (isset($param['lang']) && $param['lang']) {
                $html .= '<option value="0" selected>' . $param['lang'] . '</option>';
            }
            foreach ($param['option'] as $k => $v) {
                if (is_array($v)) {
                    $value = $v['name'];
                    isset($v['id']) && $k = $v['id'];
                } else {
                    $value = $v;
                }
                $check = '';

                if ((isset($param['value']) && $param['value'] == $k) || (isset($param['bit'][$k]) && isset($param['value']) && ($param['value'] & $k) > 0) || (empty($param['value']) && isset($param['default']) && $param['default'] == $k)) {
                    $check = 'selected';
                }

                $parent = '';
                if (isset($param['parent']) && $param['parent'] && isset($v[$param['parent']])) {
                    $parent = $v[$param['parent']];
                }

                if (is_array($v)) {
                    $value = isset($v['name']) ? $v['name'] : $v['lang'];
                } else {
                    $value = $v;
                }

                $html .= '<option parent="'.$parent.'" value="' . $k . '" ' . $check . '>' . $value . '</option>';
            }
        }

        $html .= '</select>';

        if (isset($param['child'])) {
            $child = $child_param['name'];
            $hidden = self::hidden(array('name' => $child, 'class' => $child . '_child_value'));
            foreach ($param['child'] as $k => $v) {
                $child_param['name'] = 'child-' . $k;
                $child_param['option'] = $v;

                $html .= self::select($child_param, $child . '_child ' . $child . '_child_' . $k . '" parent="' . $k . '" style="display:none;margin-top: -35px;margin-left: 47%;"', $hidden);
            }
        }

        $html .= $class ? '</div>' : '';
        return $html;
    }

    /**
     * radio
     *
     * @return string
     */
    public static function checkbox($param)
    {
        return self::radio($param);
    }

    /**
     * text
     *
     * @return string
     */
    public static function text($param, $class = '')
    {
        if ($class) {
            return '<div class="">' . self::text($param, false) . '</div>';
        } else {
            $auto = $input = '';
            $value = (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : ''));
            if (isset($param['autocomplete'])) {
                if (empty($param['autocomplete'][1])) {
                    $param['autocomplete'][1] = 'value';
                }
                if ($param['autocomplete'][1] == 'id') {
                    $input = self::hidden(array('name' => $param['name'], 'value' => $value));
                    if (isset($param['autocomplete'][2]) && $value) {
                        # 重新定义value
                        $value = Dever::load($param['autocomplete'][2], $value);
                    }

                    $param['name'] = $param['name'] . '_temp';
                }
                $auto = 'complete="' . Dever::url($param['autocomplete'][0]) . '" complete_callback="' . $param['autocomplete'][1] . '" ';
            }
            if (isset($param['bind'])) {
                $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
                $auto .= $param['bind'][0] . '="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';

                $auto .= ' onload="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';
            }
            return '<input ' . $auto . ' type="' . (isset($param['update']) ? $param['update'] : 'text') . '" class="autoload_text update_value ' . (isset($param['class']) ? $param['class'] : 'form-control') . ' ' . (isset($param['valid']) ? $param['valid'] : '') . '" value="' . $value . '" name="' . $param['name'] . '" id="' . $param['name'] . '_value" autocomplete="new'.time().'" placeholder="' . (isset($param['placeholder']) ? $param['placeholder'] : '') . '"/>' . $input;
        }
    }

    /**
     * password
     *
     * @return string
     */
    public static function password($param)
    {
        $param['value'] = '';
        return self::text($param);
    }

    /**
     * hidden
     *
     * @return string
     */
    public static function hidden($param)
    {
        $param['update'] = 'hidden';
        return self::text($param, '');
    }

    /**
     * time
     *
     * @return string
     */
    public static function time($param)
    {
        return '<input type="text" value="' . ((isset($param['value']) && $param['value'] > 0) ? date('Y-m-d', $param['value']) : ((isset($param['default']) && $param['default'] > 0) ? date('Y-m-d', $param['default']) : '')) . '" placeholder="' . (isset($param['lang']) ? $param['lang'] : '') . '" name="' . $param['name'] . '" class="manage_time update_value form-control ' . (isset($param['valid']) ? $param['valid'] : '') . '" autocomplete="off"/>';
    }

    /**
     * date
     *
     * @return string
     */
    public static function date($param)
    {
        return '<input type="text" value="' . ((isset($param['value']) && $param['value'] > 0) ? date('Y-m-d H:i:s', $param['value']) : ((isset($param['default']) && $param['default'] > 0) ? date('Y-m-d H:i:s', $param['default']) : '')) . '" placeholder="' . (isset($param['lang']) ? $param['lang'] : '') . '" name="' . $param['name'] . '" class="manage_date update_value form-control ' . (isset($param['valid']) ? $param['valid'] : '') . '" autocomplete="off"/>';
    }

    /**
     * div
     *
     * @return string
     */
    public static function node($param, $type = 'div')
    {
        $result = array('', '');
        foreach ($param as $k => $v) {
            $result[0] .= '<' . $type . ' ' . $v . '>';
            $result[1] .= '</' . $type . '>';
        }
        return $result;
    }
}
