<div class="container-fluid">
    <div class="row">
        <div class="col-sm-5 col-md-4">

            <form action="<?php echo site_url('thirdparty/form/index/create_form'); ?>" method="post" >
                <p class="btn-lg col-xs-24"></p>
                <p>
                <div class="input-group">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button">类型</button>
                    </span>
                    <select class="form-control" name="file_type" id="file_type">
                        <option value="contactus">ContactUs</option>
                        <option value="tailormade">TailorMade</option>
                        <option value="question">Question</option>
                    </select>
                </div>
                </p>
                <p class="btn-sm col-xs-24"></p>
                <p><button type="button" class="btn btn-primary btn-block" onclick="location.href = '<?php echo site_url("thirdparty/form/index/create_form/0"); ?>/' + $('#file_type').val();">新建表单→</button></p>
            </form>

            <p class="btn-lg col-xs-24"></p>
            <h4><a href="<?php echo site_url('thirdparty/form'); ?>"><strong>表单列表</strong></a></h4>
            <div class="center-col" style="background:#fff;border-right: 1px solid #ddd;">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>表单名</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($form_list as $key => $v) { ?>
                            <tr>
                                <td><?php echo $key + 1; ?></td>
                                <td><a href="<?php echo site_url('thirdparty/form/index/create_form/' . $v->form_sn); ?>"><?php echo $v->form_name; ?></a></td>

                                <td>


                                </td>
                            </tr> 
                        <?php } ?>
                    </tbody>
                </table>
            </div>    

        </div>


        <div class="col-sm-19 col-md-20">
            <!-- 表单编辑器 -->



            <div class="row">
                <!-- Building Form. -->
                <div class="col-md-12">
                    <div class="clearfix">
                        <h4>Building Form: <small><?php echo isset($form_detail) ? $form_detail->form_type : $form_type; ?></small></h4>
                        <div id="build">
                            <form id="target" class="form-horizontal">  </form>

                        </div>
                    </div> 
                    <hr/>


                    <button type="button" id="get_form_code_btn" class="btn btn-success" onclick="call_form(<?php echo isset($form_detail) ? $form_detail->form_sn : false; ?>);"  >获取调用代码</button>
                    <a class="btn btn-info" target="_blank" href="<?php echo isset($form_detail) ? site_url('/thirdparty/form/index/test/' . $form_detail->form_sn) : '#'; ?>"   >预览</a>

                    <?php
                    $session_admin = $this->session->userdata('session_admin');
                    $login_user = $session_admin['OPI_SN'];
                    if (!isset($form_detail) || (isset($form_detail) && $login_user == $form_detail->form_user)) {
                        ?>
                        <a class="btn btn-danger" href="<?php echo isset($form_detail) ? site_url('/thirdparty/form/index/delete/' . $form_detail->form_sn) : '#'; ?>" onclick="if (confirm('是否删除？删除后找不回咯！')) {
                                        return true;
                                    } else {
                                        return false;
                                    }"  >删除</a>

                        <button type="button" id="form_builder_btn"  onclick="
                                    $('#form_web_structure').val($('#render').val());
                                    $('#form_name').val($('#target legend').text());
                                    $('#form_builder').submit();"
                                class="btn btn-primary pull-right">保存表单</button>

                    <?php } ?>  


                    <form name="form_builder" id="form_builder" method="post" action="<?php echo site_url('thirdparty/form/index/do_create_form'); ?>">
                        <input type="hidden" id='form_name' name="form_name" value="<?php echo isset($form_detail) ? $form_detail->form_name : false; ?>"/>
                        <input type="hidden" id="form_type" name="form_type" value="<?php echo isset($form_detail) ? $form_detail->form_type : $form_type; ?>"/>
                        <input type="hidden" name="form_sn" value="<?php echo isset($form_detail) ? $form_detail->form_sn : false; ?>"/>
                        <input type="hidden" id="form_structure" name="form_structure" value='<?php echo isset($form_detail) ?  str_ireplace('\'', '&#39', $form_detail->form_structure)  : false; ?>' />       
                        <input type="hidden" id="form_web_structure" name="form_web_structure" value="" />       
                    </form>
                </div>
                <!-- / Building Form. -->

                <!-- Components -->
                <div class="col-md-12">
                    <h4>Drag & Drop components</h4>
                    <div class="tabbable">
                        <ul class="nav nav-tabs" id="formtabs">
                            <!-- Tab nav -->
                        </ul>
                        <form class="form-horizontal" id="components">
                            <fieldset>
                                <div class="tab-content">
                                    <!-- Tabs of snippets go here -->
                                </div>
                            </fieldset>
                        </form>
                    </div>
                </div>
                <!-- / Components -->
            </div>


            <link href="/js/bootstrap-form-builder/css/custom.css" rel="stylesheet">
            <script data-main="/js/bootstrap-form-builder/js/main.js" src="/js/require.js"></script>
            <!-- 表单编辑器 end -->
        </div>


    </div>
</div>




<div class="modal fade form_call_dialog" id="form_call_dialog" tabindex="-1" role="dialog" aria-labelledby="form_call_dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header" style="padding:10px 15px;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myLargeModalLabel">表单调用代码</h4>
            </div>
            <div class="modal-body form_html_body">

            </div>

        </div>
    </div>
</div>
<style type="text/css">
    .required{
        background-image: url("data:image/gif;base64,R0lGODlhCgAWANUmAP//+u/0/P/++qlER7tEQv///7tVQvj9/bNVQv/78f/+/qtOe8WanqtEU/fz7ebf5c+FScF4Webk9diQVvX7/6lEQs6kx7ZEQq5JQv/+9P38/evv/f7+/vLau/T6/8CQnalbd+jo+KtOb6tnZalEX8lyQv///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4zLWMwMTEgNjYuMTQ1NjYxLCAyMDEyLzAyLzA2LTE0OjU2OjI3ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M2IChXaW5kb3dzKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDoxNUI2MTAyMUY2MkQxMUU1OTIwNUQyNjg4MjI4QkE3QyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDoxNUI2MTAyMkY2MkQxMUU1OTIwNUQyNjg4MjI4QkE3QyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjE1QjYxMDFGRjYyRDExRTU5MjA1RDI2ODgyMjhCQTdDIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjE1QjYxMDIwRjYyRDExRTU5MjA1RDI2ODgyMjhCQTdDIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+Af/+/fz7+vn49/b19PPy8fDv7u3s6+rp6Ofm5eTj4uHg397d3Nva2djX1tXU09LR0M/OzczLysnIx8bFxMPCwcC/vr28u7q5uLe2tbSzsrGwr66trKuqqainpqWko6KhoJ+enZybmpmYl5aVlJOSkZCPjo2Mi4qJiIeGhYSDgoGAf359fHt6eXh3dnV0c3JxcG9ubWxramloZ2ZlZGNiYWBfXl1cW1pZWFdWVVRTUlFQT05NTEtKSUhHRkVEQ0JBQD8+PTw7Ojk4NzY1NDMyMTAvLi0sKyopKCcmJSQjIiEgHx4dHBsaGRgXFhUUExIREA8ODQwLCgkIBwYFBAMCAQAAIfkEAQAAJgAsAAAAAAoAFgAABjtAk3BILBqPyKRyyWwKM5dQUWECEDYmzbA0+CAYGJJn6IhUQA8OUWAYNQLFyeIAEVGIHYkpYSk4/4CBQQA7");
        background-repeat:no-repeat;
        background-position: right;
    }
</style>
<script type="text/javascript">
                            function call_form(form_sn) {
                                $(".form_html_body").html('<textarea class="form-control" id="form_html_box" rows="20"><div id="form_container"></div>' + "\r\n" + '<script type="text/javascript">' + "\r\n" + '$(function () { $.post(\'https://info.chinahighlights.com/info.php/thirdparty/form/call/call_form\',{"form_sn":"' + form_sn + '"},function(htmls) {$("#form_container").html(htmls);});});' + "\r\n" + '<\/script><\/textarea>');
                                $('#form_call_dialog').modal('show');
                            }
</script>




