<?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(false);
?>
<div class="block" id="spider-list">
    <div class="block-header block-header-default">
        <h3 class="block-title">采集列表</h3>
    </div>
    <div class="block-content p-0">
        <form action="<?php echo APP_URL; ?>&action=mpublish" method="POST" id="<?php echo APP_FORMID; ?>" target="iPHP_FRAME">
            <table class="dataTable table table-sm  table-hover table-striped table-vcenter 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>标题</th>
                        <th>网址</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <?php if ($result) foreach ($result as $furl => $lists) { ?>
                    <thead class="bg-light text-black font-size-base">
                        <tr>
                            <th>
                                <div class="custom-control custom-checkbox">
                                    <input type="checkbox" class="custom-control-input" id="check-all-<?php echo md5($furl); ?>" data-toggle="checkAll" data-target="#spider-list-<?php echo md5($furl); ?>">
                                    <label class="custom-control-label" for="check-all-<?php echo md5($furl); ?>"></label>
                                </div>
                            </th>
                            <th colspan="3" style="text-transform:none;"><?php echo $furl; ?></th>
                        </tr>
                    </thead>
                    <tbody class="spider-list" id="spider-list-<?php echo md5($furl); ?>">
                        <?php
                        if ($lists) foreach ($lists as $lkey => $value) {
                            $_title = $value['title'];
                            $_url   = $value['url'];
                            if (empty($value)) {
                                continue;
                            }
                            $hash = md5($_url);
                            $uri = sprintf(
                                'cid=%s&pid=%s&rid=%s&hash=%s&url=%s&title=%s',
                                $cid,
                                $pid,
                                $rid,
                                $hash,
                                urlencode($_url),
                                urlencode($_title)
                            );
                        ?>
                            <tr id="<?php echo $hash; ?>">
                                <td><input type="checkbox" name="pub[]" value="<?php echo $uri; ?>" /></td>
                                <td><?php echo $_title; ?></td>
                                <td><?php echo $_url; ?></td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <a href="<?php echo APP_URL; ?>&do=publish&<?php echo $uri; ?>" class="btn btn-light" target="iPHP_FRAME" title="发布"><i class="fa fa-fw fa-check"></i></a>
                                        <a href="<?php echo ADMINCP_URL; ?>=spiderProject&do=test&<?php echo $uri; ?>" class="btn btn-light" target="_blank" title="测试"><i class="fa fa-fw fa-bug"></i></a>
                                        <a href="<?php echo ADMINCP_URL; ?>=spiderUrl&do=mark&<?php echo $uri; ?>" class="btn btn-light" target="iPHP_FRAME" title="移除"><i class="fa fa-fw fa-trash-alt"></i></a>
                                    </div>
                                </td>
                            </tr>
                        <?php } ?>
                    <?php } ?>
                    </tbody>
            </table>
            <div class="form-group py-4 mt-4 bg-body-light">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <label class="input-group-text" for="checkAll">全选</label>
                        <div class="input-group-text">
                            <div class="custom-control custom-checkbox">
                                <input type="checkbox" class="custom-control-input" id="checkAll" data-toggle="checkAll" data-target="#<?php echo APP_FORMID; ?>" />
                                <label class="custom-control-label" for="checkAll"></label>
                            </div>
                        </div>
                    </div>
                    <button class="btn btn-primary" type="submit"><i class="fa fa-fw fa-check"></i> 开始采集</button>
                </div>
            </div>

        </form>
    </div>
</div>
<?php self::foot(); ?>