<?php

/**
 * iCMS - i Content Management System
 * Copyright (c) 2007-2017 iCMSdev.com. All rights reserved.
 *
 * @author icmsdev <master@icmsdev.com>
 * @site https://www.icmsdev.com
 * @licence https://www.icmsdev.com/LICENSE.html
 */
defined('iPHP') or exit('What are you doing?');
self::head();
?>
<script type="text/javascript">
    $(function() {
        $("#<?php echo APP_FORMID; ?>").batch();
    });
</script>
<div class="content" id="<?php echo APP_MAINID; ?>">
    <div class="block">
        <div class="block-header block-header-default">
            <h3 class="block-title">搜索</h3>
            <div class="block-options">
                <div class="block-options-item">
                    <button class="btn btn-success" type="button" id="import_rule"><i class="fa fa-fw fa-paper-plane"></i> 导入规则</button>
                </div>
            </div>
        </div>
        <div class="block-content block-content-full">
            <form action="<?php echo iPHP_SELF; ?>" method="get">
                <input type="hidden" name="app" value="<?php echo Admincp::$APP_NAME; ?>" />
                <input type="hidden" name="do" value="<?php echo Admincp::$APP_DO; ?>" />
                <div class="form-row">
                    <div class="input-group input-group-sm col-sm-6 col-lg-2 mt-1">
                        <div class="input-group-prepend">
                            <label class="input-group-text" for="pageSize">每页</label>
                        </div>
                        <input class="form-control" type="text" name="pageSize" id="pageSize" value="<?php echo Paging::$pageSize; ?>" />
                        <div class="input-group-append">
                            <label class="input-group-text" for="pageSize">条记录</label>
                        </div>
                    </div>
                    <div class="input-group input-group-sm col-sm-6 col-lg-3 mt-1">
                        <div class="input-group-prepend">
                            <label class="input-group-text" for="keywords">关键字</label>
                        </div>
                        <input type="text" name="keywords" class="form-control" id="keywords" value="<?php echo $_GET['keywords']; ?>" />
                        <div class="input-group-append">
                            <button class="btn btn-primary" type="submit"><i class="fa fa-fw fa-search"></i> 搜 索</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="block">
        <div class="block-header"> <span class="icon">
                <input type="checkbox" class="form-control" data-target="#<?php echo APP_MAINID; ?>" />
            </span>
            <h3 class="block-title">规则列表</h3>
        </div>
        <div class="block-content">
            <form action="<?php echo APP_URL; ?>&action=batch" method="POST" id="<?php echo APP_FORMID; ?>" target="iPHP_FRAME">
                <div class="table-responsive">
                    <table class="dataTable table table-hover table-striped table-vcenter font-size-sm mb-0">
                        <thead class="bg-light text-black">
                            <tr>
                                <th style="width: 36px;" class="align-middle">
                                    <div class="custom-control custom-checkbox">
                                        <input type="checkbox" class="custom-control-input" id="check-all" data-toggle="checkAll" data-target="#<?php echo APP_FORMID; ?>">
                                        <label class="custom-control-label" for="check-all"></label>
                                    </div>
                                </th>
                                <th>ID</th>
                                <th>名称</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if ($result) foreach ($result as $key => $value) { ?>
                                <tr id="id<?php echo $value['id']; ?>">
                                    <td><input type="checkbox" name="id[]" value="<?php echo $value['id']; ?>" /></td>
                                    <td><?php echo $value['id']; ?></td>
                                    <td>
                                        <h4><?php echo $value['name']; ?></h4>
                                    </td>
                                    <td class="text-right">
                                        <div class="btn-group btn-group-sm">
                                            <a href="<?php echo ADMINCP_URL; ?>=spider&do=manage&rid=<?php echo $value['id']; ?>" class="btn btn-sm btn-alt-success" target="_blank"><i class="fa fa-fw fa-list-alt"></i> 已采集</a>
                                            <a href="<?php echo APP_URL; ?>&do=error&rid=<?php echo $value['id']; ?>" class="btn btn-sm btn-alt-danger" target="_blank"><i class="fa fa-fw fa-exclamation-triangle"></i> 错误信息</a>
                                        </div>
                                        <div class="btn-group btn-group-sm">
                                            <a href="<?php echo ADMINCP_URL; ?>=spiderProject&do=manage&rid=<?php echo $value['id']; ?>" class="btn btn-sm btn-alt-info" target="_blank"><i class="fa fa-fw fa-magnet"></i> 方案</a>
                                            <a href="<?php echo ADMINCP_URL; ?>=spiderProject&action=export&rid=<?php echo $value['id']; ?>" class="btn btn-sm btn-alt-light" target="iPHP_FRAME"><i class="fa fa-fw fa-download"></i> 导出方案</a>
                                        </div>
                                        <div class="btn-group btn-group-sm">
                                            <a href="<?php echo APP_URL; ?>&action=export&rid=<?php echo $value['id']; ?>" class="btn btn-sm btn-alt-light" target="iPHP_FRAME" title="导出规则"><i class="fa fa-fw fa-download"></i></a>
                                            <a href="<?php echo APP_URL; ?>&action=copy&rid=<?php echo $value['id']; ?>" class="btn btn-sm btn-alt-light" target="iPHP_FRAME" title="复制规则"><i class="fa fa-fw fa-clipboard"></i></a>
                                            <a href="<?php echo APP_URL; ?>&do=test&rid=<?php echo $value['id']; ?>" class="btn btn-sm btn-alt-light" data-toggle="modal" title="测试规则"><i class="fa fa-fw fa-bug"></i></a>
                                            <a href="<?php echo APP_URL; ?>&do=add&rid=<?php echo $value['id']; ?>" class="btn btn-sm btn-alt-light" target="_blank" title="编辑"><i class="fa fa-fw fa-pencil-alt"></i></a>
                                            <a href="<?php echo APP_URL; ?>&action=delete&rid=<?php echo $value['id']; ?>" target="iPHP_FRAME" class="del btn btn-sm btn-alt-danger" title='永久删除' data-confirm="delete" /><i class="fa fa-fw fa-trash-alt"></i></a>
                                        </div>
                                    </td>
                                </tr>
                            <?php }  ?>
                        </tbody>
                    </table>
                    <?php self::formFoot();?>
                </div>
            </form>
        </div>
    </div>
</div>
<div id="import_rule_wrap" style="display:none;">
    <div class="alert alert-info">
        只允许导入TXT文件
    </div>
    <?php FilesWidget::uploadBtn(APP_URL . '&action=import'); ?>
</div>
<script type="text/javascript">
$(function() {
    $("#import_rule").click(function(event) {
        iCMS.ui.dialog({
            title: 'iCMS - 导入规则',
            content: document.getElementById("import_rule_wrap")
        });
    });
});
</script>
<?php self::foot(); ?>