{template "header.html"}

<link href="{THEME_PATH}assets/global/plugins/bootstrap-select/css/bootstrap-select.min.css" rel="stylesheet" type="text/css" />
<script src="{THEME_PATH}assets/global/plugins/bootstrap-select/js/bootstrap-select.min.js" type="text/javascript"></script>
<script>
    if (App.isAngularJsApp() === false) {
        jQuery(document).ready(function() {
            $('.bs-select').selectpicker({
                iconBase: 'fa',
                tickIcon: 'fa-check'
            });
        });
    }
    {if $is_verify}
    $(function () {
        $('#dr_row_hits').hide();
    });
    {else}
    {$auto_form_data_ajax}
    {/if}
    function dr_syncat() {
        var title = '<i class="fa fa-refresh"></i> {dr_lang('同步到其他栏目')}';
        var url = '{dr_url(MOD_DIR.'/home/syncat_edit')}&catid='+$('#dr_syncatid').val();
        layer.open({
            type: 2,
            title: title,
            shadeClose: true,
            shade: 0,
            area: [{php echo !IS_MOBILE_USER ? '"40%", "70%"' : '"95%", "90%"'}],
            btn: [lang['ok']],
            yes: function(index, layero){
                var body = layer.getChildFrame('body', index);
                $(body).find('.form-group').removeClass('has-error');
                // 延迟加载
                var loading = layer.load(2, {
                    shade: [0.3,'#fff'], //0.1透明度的白色背景
                    time: 10000
                });
                $.ajax({type: "POST",dataType:"json", url: url, data: $(body).find('#myform').serialize(),
                    success: function(json) {
                        layer.close(loading);
                        if (json.code == 1) {
                            layer.close(index);
                            $('#dr_syncatid').val(json.data);
                            $('#dr_syncat_text').show();
                            $('#dr_syncat_num').html(json.msg);
                        } else {
                            dr_tips(json.code, json.msg);
                        }
                        return false;
                    },
                    error: function(HttpRequest, ajaxOptions, thrownError) {
                        dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError);
                    }
                });
                return false;
            },
            content: url+'&is_ajax=1'
        });
    }

    // 定时发布
    function dr_ajax_time_submit() {

        layer.open({
            type: 2,
            title: '<i class="fa fa-clock-o"></i> {dr_lang('定时发布')}',
            fix:true,
            scrollbar: false,
            shadeClose: true,
            shade: 0,
            area: [{php echo !IS_MOBILE_USER ? '"500px", "450px"' : '"95%", "90%"'}],
            btn: [lang['ok']],
            success: function (json) {
                if (json.code == 0) {
                    layer.close();
                    dr_tips(json.code, json.msg);
                }
            },
            yes: function(index, layero){
                var body = layer.getChildFrame('body', index);
                var loading = layer.load(2, {
                    time: 10000
                });
                var url = '{dr_url(APP_DIR.'/time/add')}';
                var posttime = $(body).find('#posttime').val();
                if (posttime.length < 5) {
                    layer.closeAll('loading');
                    dr_tips(0, "{dr_lang('发布时间必须填写')}");
                    return false;
                }
                $('#myform .form-group').removeClass('has-error');
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: url+"&posttime="+posttime,
                    data: $("#myform").serialize(),
                    success: function(json) {
                        layer.close(loading);
                        if (json.code > 0) {
                            dr_tips(1, json.msg);
                            setTimeout("window.location.href = '{dr_url(APP_DIR.'/time/index')}'", 2000);
                        } else {
                            dr_tips(0, json.msg);
                            if (json.data.field) {
                                $('#dr_row_'+json.data.field).addClass('has-error');
                                $('#dr_'+json.data.field).focus();
                            }
                        }
                    },
                    error: function(HttpRequest, ajaxOptions, thrownError) {
                        dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError);
                    }
                });

                return false;
            },
            content: "{dr_url(APP_DIR.'/time/add')}&is_ajax=1"
        });
    }
	// 退稿
	function dr_ajax_tui_submit() {

        layer.open({
            type: 2,
            title: '<i class="fa fa-sign-out"></i> {dr_lang('退稿')}',
            fix:true,
            scrollbar: false,
            shadeClose: true,
            shade: 0,
            area: [{php echo !IS_MOBILE_USER ? '"40%", "70%"' : '"95%", "90%"'}],
            btn: [lang['ok']],
            success: function (json) {
                if (json.code == 0) {
                    layer.close();
                    dr_tips(json.code, json.msg);
                }
            },
            yes: function(index, layero){
                var body = layer.getChildFrame('body', index);
                var loading = layer.load(2, {
                    time: 10000
                });
                var url = '{dr_url(APP_DIR.'/home/tuigao_edit')}&id={$id}';
                var note = $(body).find('#dr_note').val();
                var clear = $(body).find("input[name='clear']:checked").val();
		
                if (note.length == 0) {
                    layer.closeAll('loading');
                    dr_tips(0, "{dr_lang('退稿理由必须填写')}");
                    return false;
                }
                $('#myform .form-group').removeClass('has-error');
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: url+"&note="+note+"&clear="+clear,
                    data: $("#myform").serialize(),
                    success: function(json) {
                        layer.close(loading);
                        if (json.code == 1) {
                            dr_tips(1, json.msg);
                            setTimeout("window.location.href = '{$reply_url}'", 2000);
                        } else {
                            dr_tips(0, json.msg);
                            if (json.data.field) {
                                $('#dr_row_'+json.data.field).addClass('has-error');
                                $('#dr_'+json.data.field).focus();
                            }
                        }
                    },
                    error: function(HttpRequest, ajaxOptions, thrownError) {
                        dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError);
                    }
                });

                return false;
            },
            content: "{dr_url(APP_DIR.'/home/tui_edit')}&page=5&is_ajax=1"
        });
    }
    function dr_ajax_verify_submit() {
        $('#dr_is_draft').val(0);
        dr_ajax_submit('{dr_now_url()}', 'myform', '2000', '{$reply_url}');
    }
    $(function () {
        {if isset($_GET['is_verify_iframe']) && $_GET['is_verify_iframe']}
        $('#dr_is_draft').val(0);
        $.ajax({
            type: "POST",
            dataType: "json",
            url: '{dr_now_url()}',
            data: $("#myform").serialize(),
            success: function(json) {
                if (json.code) {
                    if (json.data.htmlfile) {
                        // 执行生成htmljs
                        $.ajax({
                            type: "GET",
                            url: json.data.htmlfile,
                            dataType: "jsonp",
                            success: function(json){ },
                            error: function(){ }
                        });
                    }
                    if (json.data.htmllist) {
                        // 执行生成htmljs
                        $.ajax({
                            type: "GET",
                            url: json.data.htmllist,
                            dataType: "jsonp",
                            success: function(json){ },
                            error: function(){ }
                        });
                    }
                    parent.$('#content_{$id}').addClass("badge badge-success");
                    parent.$('#content_{$id}').html('{dr_lang("成功")}');
                } else {
                    parent.$('#content_{$id}').addClass("badge badge-danger");
                    parent.$('#content_{$id}').html(json.msg);
                }
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                parent.$('#content_{$id}').addClass("badge badge-danger");
                parent.$('#content_{$id}').html('{dr_lang("执行失败")}');
            }
        });

        {/if}
    });
</script>
{if $post_notice_msg}
<div class="note note-danger">
    <p>{$post_notice_msg}</p>
</div>
{/if}
<form action="" class="form-horizontal" method="post" name="myform" id="myform">
    {$form}
    <div class="myfbody">
        <div class="row ">
            <div class="{if $is_mobile}col-md-12{else}col-md-9{/if}">

                <div class="portlet light bordered">
                    <div class="portlet-title">
                        <div class="caption">
                            <span class="caption-subject font-green sbold ">{dr_lang('基本内容')}</span>
                        </div>

                        <div class="actions">
                            {if $draft_list}
                            <div class="btn-group">
                                <a class="btn btn-default dropdown-toggle" data-toggle="dropdown" href="javascript:;" aria-expanded="false">
                                    {dr_lang('草稿')}
                                    <i class="fa fa-angle-down"></i>
                                </a>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a href="{$draft_url}"> {dr_lang('查看原文')} </a>
                                    </li>
                                    {loop $draft_list $t}
                                    <li>
                                        <a href="{$draft_url}&did={$t.id}" {if $t.id==$did}style="color:red"{/if}> {dr_date($t.inputtime)} - {$t.title} </a>
                                    </li>
                                    {/loop}
                                </ul>
                            </div>
                            {/if}
                            <div class="btn-group">
                                <a class="btn" href="{$reply_url}"> <i class="fa fa-mail-reply"></i> {dr_lang('返回列表')}</a>
                            </div>
                        </div>
                    </div>
                    <div class="portlet-body">
                        <div class="form-body">
                            <div class="form-group {if !$is_category_show}hide{/if}">
                                <label class="col-md-2 control-label">{dr_lang('栏目')}</label>
                                <div class="col-md-9">
                                    {if $module['category'][$catid]['setting']['notedit']}
                                    <label style="margin-top: 7px;">
                                        <span class="label label-sm label-success circle">{$module['category'][$catid]['name']}</span>
                                    </label>
                                    <input type="hidden" id="dr_catid" name="catid" value="{$catid}">
                                    {else}
                                        <label style="margin-right:10px">{$select}</label>
                                        {if $module['setting']['sync_category']}
                                        {if !$id || $is_sync_cat}
                                        <label style="margin-right:10px"><a href="javascript:;" onclick="dr_syncat()">[{dr_lang('同步发布到其他栏目')}]</a></label>
                                        <label>
                                            <input id="dr_syncatid" name="sync_cat" type="hidden" value="{$is_sync_cat}" />
                                            <span id="dr_syncat_text" class="label label-success" style="display: {if $is_sync_cat}blank{else}none{/if};"><b id="dr_syncat_num">{php echo substr_count($is_sync_cat, ',') + 1;}</b></span>
                                        </label>
                                        {else if $link_id != 0}
                                        <label>{dr_lang('修改内容时会同步更新其他外联文档')}</label>
                                        {/if}
                                        {/if}
										{if !$module['category']}
										<label style="margin-right:10px"><a href="{dr_url($module['dirname'].'/category/index')}">[{dr_lang('栏目管理')}]</a></label>
										{/if}
                                    {/if}
                                </div>
                            </div>
                            {$myfield}
                        </div>
                    </div>
                </div>

                {if $diyfield}
                <div class="portlet light bordered">
                    <div class="portlet-title">
                        <div class="caption">
                            <span class="caption-subject font-green sbold ">{dr_lang('其他内容')}</span>
                        </div>
                    </div>
                    <div class="portlet-body">
                        <div class="form-body">
                            {$diyfield}
                        </div>
                    </div>
                </div>
                {/if}

            </div>
            <div class="{if $is_mobile}col-md-12{else}col-md-3{/if} my-sysfield">
                <div class="portlet light bordered">
                    <div class="portlet-body">
                        <div class="form-body">
                            {$sysfield}

                            {if !$is_verify && $is_post_time}
                            <div class="form-group">
                                <label class="col-md-2 control-label">{dr_lang('定时发布时间')}</label>
                                <div class="col-md-9">
                                    <span class="form-date input-group">
                                        <div class="input-group date field_date_post_inputtime">
                                            <input id="posttime" name="posttime" type="text" style="width:160px;" value="{dr_date($posttime, 'Y-m-d H:i:s')}"  required="required" class="form-control ">
                                            <span class="input-group-btn">
                                                <button class="btn default date-set" type="button">
                                                    <i class="fa fa-calendar"></i>
                                                </button>
                                            </span>
                                        </div>
                                        <script>
                                        $(function(){
                                            $(".field_date_post_inputtime").datetimepicker({
                                                isRTL: App.isRTL(),
                                                format: "yyyy-mm-dd hh:ii:ss",
                                                showMeridian: true,
                                                autoclose: true,
                                                pickerPosition: (App.isRTL() ? "bottom-right" : "bottom-left"),
                                                todayBtn: true
                                            });
                                        });
                                        </script>
                                    </span>
                                </div>
                            </div>
                            {/if}
                        </div>
                    </div>
                </div>
            </div>
        </div>


        {if $is_verify}
        <div class="row ">
            <div class="col-md-12 ">
                <div class="portlet light bordered">
                    <div class="portlet-title">
                        <div class="caption">
                            <span class="caption-subject font-green sbold ">{dr_lang('内容审核')}</span>
                        </div>
                    </div>
                    <div class="portlet-body">
                        <div class="form-body">

                            {if $status}
                            <div class="form-group">
                                <label class="col-md-2 control-label">{dr_lang('当前状态')}</label>
                                <div class="col-md-9">
                                    <p class="form-control-static">
                                        <span class="label label-warning"> {dr_lang('%s审中', $status)} </span>
                                    </p>
                                </div>
                            </div>
                            {else}
                            <div class="form-group">
                                <label class="col-md-2 control-label">{dr_lang('当前状态')}</label>
                                <div class="col-md-9">
                                    <p class="form-control-static">
                                        <span class="label label-danger"> {dr_lang('被拒绝')} </span>
                                    </p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-2 control-label">{dr_lang('处理账号')}</label>
                                <div class="col-md-9">
                                    <p class="form-control-static">
                                        {Function_list::author($verify.backinfo.author, [], $verify.backinfo)}
                                    </p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-2 control-label">{dr_lang('处理时间')}</label>
                                <div class="col-md-9">
                                    <p class="form-control-static">
                                        {dr_date($verify.backinfo.optiontime)}
                                    </p>
                                </div>
                            </div>
                            {if $verify.backinfo.backcontent}
                            <div class="form-group">
                                <label class="col-md-2 control-label">{dr_lang('拒绝理由')}</label>
                                <div class="col-md-9">
                                    <p class="form-control-static">
                                        {$verify.backinfo.backcontent}
                                    </p>
                                </div>
                            </div>
                            {/if}
                            {/if}
                            {if $verify_step[$status]['name']}
                            <div class="form-group">
                                <label class="col-md-2 control-label">{dr_lang('当前审核')}</label>
                                <div class="col-md-9">
                                    <p class="form-control-static"> {$verify_step[$status]['name']} </p>
                                </div>
                            </div>
                            {/if}
                            <div class="form-group">
                                <label class="col-md-2 control-label">{dr_lang('下级审核')}</label>
                                <div class="col-md-9">
                                    <p class="form-control-static"> {$verify_step[$verify_next]['name']} </p>
                                </div>
                            </div>
                            {if $is_post_user}
                            <div class="form-group">
                                <label class="col-md-2 control-label">审核人</label>
                                <div class="col-md-9">
                                    <p class="form-control-static">
                                        {Function_list::author($verify.backinfo.author, [], $verify.backinfo)}
                                    </p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-2 control-label">审核时间</label>
                                <div class="col-md-9">
                                    <p class="form-control-static">
                                        {dr_date($verify.backinfo.optiontime)}
                                    </p>
                                </div>
                            </div>
                            {if $verify.backinfo.backcontent}
                            <div class="form-group">
                                <label class="col-md-2 control-label">拒绝理由</label>
                                <div class="col-md-9">
                                    <p class="form-control-static">
                                        {$verify.backinfo.backcontent}
                                    </p>
                                </div>
                            </div>
                            {/if}
                            {else}
                            <div class="form-group">
                                <label class="col-md-2 control-label">{dr_lang('操作状态')}</label>
                                <div class="col-md-9">
                                    <div class="mt-radio-inline">
                                        <label class="mt-radio mt-radio-outline"><input type="radio" onclick="$('.dr_close_msg').hide()" name="verify[status]" value="1" {if !$back_note} checked{/if} /> {dr_lang('通过')} <span></span></label>
                                        <label class="mt-radio mt-radio-outline"><input type="radio" onclick="$('.dr_close_msg').show()" name="verify[status]" value="0" {if $back_note} checked{/if} /> {dr_lang('拒绝')} <span></span></label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group dr_close_msg" style="{if !$back_note} display:none{/if}">
                                <label class="col-md-2 control-label">{dr_lang('拒绝理由')}</label>
                                <div class="col-md-9">
                                    <textarea id="dr_verify_msg" class="form-control" style="height:100px" name="verify[msg]">{$back_note}</textarea>
                                </div>
                            </div>
                            <div class="form-group dr_close_msg" style="{if !$back_note} display:none{/if}">
                                <label class="col-md-2 control-label">{dr_lang('常用理由')}</label>
                                <div class="col-md-9">
                                    <label>
                                        <select class="form-control" onchange="javascript:$('#dr_verify_msg').val(this.value)">
                                            <option value=""> -- </option>
                                            {loop $verify_msg $t}
                                            <option value="{$t}">{$t}</option>
                                            {/loop}
                                        </select>
                                    </label>
                                </div>
                            </div>
                            {/if}



                        </div>
                    </div>
                </div>
            </div>
        </div>
        {/if}

    </div>


    <div class="portlet-body form myfooter">
        <div class="form-actions text-center">
            {if !defined('IS_MODULE_RECYCLE')}
                {if $is_verify}
                    <label><button type="button" onclick="dr_ajax_verify_submit()" class="btn green"> <i class="fa fa-save"></i> {dr_lang('提交审核')}</button></label>
                {else if $is_post_time}
                    <label><button type="button" onclick="$('#dr_is_draft').val(0);dr_ajax_submit('{dr_now_url()}&posttime={dr_date($posttime, 'Y-m-d H:i:s')}', 'myform', '2000')" class="btn green"> <i class="fa fa-save"></i> {dr_lang('保存内容')}</button></label>
                {else}
                    <label><button type="button" onclick="$('#dr_is_draft').val(0);dr_ajax_submit('{dr_now_url()}', 'myform', '2000')" class="btn green"> <i class="fa fa-save"></i> {dr_lang('保存内容')}</button></label>
                    <label><button type="button" onclick="$('#dr_is_draft').val(0);dr_ajax_submit('{dr_now_url()}', 'myform', '2000', '{$post_url}&catid='+$('#dr_catid').val())" class="btn blue"> <i class="fa fa-plus"></i> {dr_lang('保存再添加')}</button></label>
                    <label><button type="button" onclick="$('#dr_is_draft').val(0);dr_ajax_submit('{dr_now_url()}', 'myform', '2000', '{$reply_url}')" class="btn yellow"> <i class="fa fa-mail-reply-all"></i> {dr_lang('保存并返回')}</button></label>
                    {if $ci->_is_admin_auth(MOD_DIR.'/draft/add')}
                    <label><button type="button" onclick="$('#dr_is_draft').val(1);dr_ajax_submit('{dr_now_url()}', 'myform', '2000')" class="btn red"> <i class="fa fa-pencil"></i> {dr_lang('保存草稿')}</button></label>
                    {/if}
                    {if !$id && !$is_post_user && $ci->_is_admin_auth(MOD_DIR.'/time/add')}
                    <label><button type="button" onclick="dr_ajax_time_submit()" class="btn dark"> <i class="fa fa-clock-o"></i> {dr_lang('定时发布')}</button></label>
                    {/if}
                    {if $is_form_cache}
                    <label><button type="button" onclick="auto_form_data_delete()" class="btn red"> <i class="fa fa-trash"></i> {dr_lang('删除历史缓存')}</button></label>
                    {/if}
                {/if}
                {if $id && !$is_verify && !$is_post_user}
                <label><button type="button" onclick="dr_ajax_tui_submit()" class="btn green"> <i class="fa fa-sign-out"></i> {dr_lang('退稿')}</button></label>
                {/if}
            {else}
            <label><a href="{$reply_url}" class="btn yellow"> <i class="fa fa-mail-reply-all"></i> {dr_lang('返回列表')}</a></label>
            <label><button type="button" onclick="$('#dr_is_draft').val(0);dr_ajax_submit('{dr_now_url()}', 'myform', '2000', '{$reply_url}')" class="btn green"> <i class="fa fa-save"></i> {dr_lang('恢复此内容')}</button></label>
            {/if}
        </div>
    </div>
</form>

{template "footer.html"}