{template "header.html"}

<div class="note note-danger"  id="table-search-tool">

    {template "api_list_date_search.html"}

    <div class="row table-search-tool">
        <form action="{SELF}" method="get">
            {dr_form_search_hidden(['field' => 'type'])}
            {if $remote}
            <div class="col-md-12 col-sm-12">
                <label>
                    <select name="remote" class="form-control">
                        <option value=""> - </option>
                        {loop $remote $t}
                        <option value="{$t.id}" {if $param.remote==$t.id}selected{/if}>{$t.name}</option>
                        {/loop}
                    </select>
                </label>
            </div>
            {/if}
            <div class="col-md-12 col-sm-12">
                <label>
                    <select name="field" class="form-control">
                        <option value="id"> Id </option>
                        {loop $field $t}
                        {if dr_is_admin_search_field($t)}
                        <option value="{$t.fieldname}" {if $param.field==$t.fieldname}selected{/if}>{$t.name}</option>
                        {/if}
                        {/loop}
                    </select>
                </label>
                <label><i class="fa fa-caret-right"></i></label>
                <label><input type="text" class="form-control" placeholder="" value="{$param['keyword']}" name="keyword" /></label>
            </div>
            <div class="col-md-12 col-sm-12">
                <label>
                    <div class="input-group input-medium date-picker input-daterange" data-date="" data-date-format="yyyy-mm-dd">
                        <input type="text" class="form-control" value="{$param.date_form}" name="date_form">
                        <span class="input-group-addon"> {dr_lang('到')} </span>
                        <input type="text" class="form-control" value="{$param.date_to}" name="date_to">
                    </div>
                </label>
            </div>


            <div class="col-md-12 col-sm-12">
                <label><button type="submit" class="btn blue btn-sm " name="submit" > <i class="fa fa-search"></i> {dr_lang('搜索')}</button></label>
               </div>
        </form>
    </div>
</div>

<div class="right-card-box">


    <form class="form-horizontal" role="form" id="myform">
        {dr_form_hidden(['table' => $table])}
        <div class="bootstrap-table bootstrap-table2">
            <div id="toolbar" class="toolbar">
                {if $ci->_is_admin_auth('del')}
                <label><button type="button" onclick="dr_ajax_option('{dr_url($uriprefix.'/del')}', '{dr_lang('你确定要删除它们吗？')}', 1)" class="btn red btn-sm"> <i class="fa fa-trash"></i> {dr_lang('删除')}</button>
                </label>
                {/if}
                {if $ci->_is_admin_auth('edit')}
                {if $remote}
                <label style="margin-right: 5px">
                    <select name="remote" class="form-control">
                        <option value="-1"> -- </option>
                        <option value="0"> {dr_lang('默认')} </option>
                        {loop $remote $t}
                        <option value="{$t.id}" {if $param.remote==$t.id}selected{/if}>{$t.name}</option>
                        {/loop}
                    </select>
                </label>
                <label><button type="button" onclick="dr_ajax_option('{dr_url($uriprefix.'/type_edit', ['table'=>$table])}', '{dr_lang('需要手动将这些附件复制到储存策略的目录中，你确定要变更吗？')}', 1)" class="btn green btn-sm "> <i class="fa fa-cloud"></i> {dr_lang('变更储存策略')}</button>
                </label>
                {/if}
                {if $table == 'data'}
                <link href="{ROOT_THEME_PATH}assets/global/plugins/jquery-fileupload/css/jquery.fileupload.css" rel="stylesheet" type="text/css" />
                <script src="{ROOT_THEME_PATH}assets/global/plugins/jquery-fileupload/js/jquery.fileupload.js" type="text/javascript"></script>
                <label class="dev" id="fileupload">
                    <a href="JavaScript:;" class="fileinput-button  btn blue"> <i class="fa fa-upload"></i> {dr_lang('上传')}<input type="file" multiple name="file_data"> </a>
                </label>
                <label class="dev">
                    <input id="dr_file_count" value="0" type="hidden">
                    <a class="fileupload-progress"></a>
                </label>
                <script type="text/javascript">
                    $(function() {
                        $("#fileupload").fileupload({
                            disableImageResize: false,
                            autoUpload: true,
                            maxFileSize: "{$upload.param.size}",
                            url: "{$upload.url}",
                            dataType: "json",
                            acceptFileTypes: "{$upload.param.exts}",
                            maxChunkSize: '{$upload.param.chunk}',
                            progressall: function (e, data) {
                                // 上传进度条 all
                                var progress = parseInt(data.loaded / data.total * 100, 10);
                                $(".fileupload-progress").show();
                                $(".fileupload-progress").html(""+progress+"%");
                            },
                            add: function (e, data) {
                                $(".fileupload-progress").hide();
                                data.submit();

                            },
                            done: function (e, data) {
                                var count = parseInt($('#dr_file_count').val()) + 1;
                                $('#dr_file_count').val(count);
                                $(".fileupload-progress").hide();
                                if (data.result.code > 0) {
                                    dr_tips(data.result.code, data.result.msg);
                                    if (count == data.originalFiles.length) {
                                        setTimeout("window.location.href = '{$upload.back}'", 2000);
                                    }
                                    //setTimeout("window.location.href = '{$field.back}'", 2000);
                                } else {
                                    dr_tips(data.result.code, data.result.msg, -1);
                                }
                            },
                            fail: function (e, data) {
                                //console.log(data.errorThrown);
                                dr_tips(0, "系统故障："+data.errorThrown, -1);
                                layer.closeAll('tips');
                                $(".fileupload-progress").hide();

                            },
                        });
                    });
                </script>

                {else}
                <label><button type="button" onclick="dr_ajax_option('{dr_url($uriprefix.'/edit')}', '{dr_lang('你确定要强制归档它们吗？')}', 1)" class="btn blue btn-sm "> <i class="fa fa-database"></i> {dr_lang('归档')}</button>
                </label>
                {/if}
                {/if}
            </div>

        </div>
        <div class="clearfix hrb10"></div>
        <div class="table-scrollable deltable-clearfix">
            <table class="table table-striped table-bordered table-bordered2 table-hover table-checkable dataTable">
                
                <thead>
                <tr class="heading">
                    <th class="myselect">
                        <label class="mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
                            <input type="checkbox" class="group-checkable" data-set=".checkboxes" />
                            <span></span>
                        </label>
                    </th>
                    <th style="text-align:center"  width="90" class="{dr_sorting('id')}" name="id">Id</th>
                    <th style="text-align:center"  width="120" class="{dr_sorting('remote')}" name="remote">{dr_lang('储存策略')}</th>
                    <th width="150" class="{dr_sorting('uid')}" name="uid">{dr_lang('账号')}</th>
                    <th class="{dr_sorting('filename')}" name="filename">{dr_lang('名称')}</th>
                    <th style="text-align:center" width="90" class="{dr_sorting('fileext')}" name="fileext">{dr_lang('扩展名')}</th>
                    <th width="100" class="{dr_sorting('filesize')}" name="filesize">{dr_lang('大小')}</th>
                    <th width="160" class="{dr_sorting('inputtime')}" name="inputtime">{dr_lang('上传时间')}</th>
                    <th width="200">{dr_lang('附件归属')}</th>
                </tr>
                </thead>
                <tbody>
                {loop $list $t}
                <?php
                if (!$t.filename) {
                    $t.filename = '未命名';
                }
                if (dr_is_image($t.fileext)) {
                    $hs = 'dr_preview_image';
                } elseif ($t.fileext == 'mp4') {
                    $hs = 'dr_preview_video';
                } else {
                    $hs = 'dr_preview_url';
                }
                $t.url = 'javascript:'.$hs.'(\''.dr_get_file_url($t).'\');';
                ?>
                <tr class="odd gradeX" id="dr_row_{$t.id}">
                    <td class="myselect">
                        <label class="mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
                            <input type="checkbox" class="checkboxes" name="ids[]" value="{$t.id}" />
                            <span></span>
                        </label>
                    </td>
                    <td style="text-align:center">
                        {$t.id}
                    </td>
                    <td style="text-align:center">
                        <label>{if !$t.remote}<span class="label label-sm label-info">{dr_lang('默认')}</span>
                            {elseif !isset($remote[$t.remote])}<span class="label label-sm label-danger">{dr_lang('已失效')}</span>
                            {else}<span class="label label-sm label-warning">{dr_lang($remote[$t.remote]['name'])}</span>{/if}</label>
                    </td>
                    <td>{Function_list::uid($t.uid)}</td>
                    <td>
                        <a href="{$t.url}">{Function_list::title($t.filename, $param)}</a>
                        <a class="btn blue btn-xs" href="javascript:dr_iframe('{dr_lang('改名')}', '{dr_url('api/name_edit', ['id'=>$t.id])}', '350px', '220px');">{dr_lang('改名')}</a>
                        <a class="btn green btn-xs" href="javascript:dr_iframe_show('{dr_lang('重新上传')}', '{dr_url('attachments/file_edit', ['id'=>$t.id])}', '350px', '220px');">{dr_lang('重传')}</a>
                        {if $ci->_is_admin_auth() && in_array($t.fileext, ['jpg', 'gif', 'png', 'jpeg'])}<a class="btn red btn-xs" href="javascript:dr_iframe('{dr_lang('改图')}', '{dr_url('api/image_edit', ['id'=>$t.id])}', '80%');">{dr_lang('改图')}</a>{/if}
                    </td>
                    <td style="text-align:center">{$t.fileext}</td>
                    <td>{dr_format_file_size($t.filesize)}</td>
                    <td>{dr_date($t.inputtime, null, 'red')}</td>
                    <td>{if $table == 'data'}{$t.related}{else}<a href="javascript:dr_layer_tips('{$t.attachinfo}');">{$t.attachinfo}</a>{/if}</td>
                </tr>
                {/loop}
                </tbody>
            </table>
        </div>

        <div class="row fc-list-footer table-checkable ">

            <div class="col-md-12 fc-list-page">
                {$mypages}
            </div>
        </div>
    </form>
</div>

{template "footer.html"}