<?php self::head(); ?>
<script type="text/javascript">
    iCMS.set("Vue.data", {
        type: "<?php echo $_GET['type']; ?>",
    });
</script>
<script type="text/javascript">
    $(function () {
        $("#local_app").click(function (event) {
            var local_app_wrap = document.getElementById("local_app_wrap");
            iCMS.ui.dialog({
                title: "iCMS - 安装本地应用",
                content: local_app_wrap,
            });
        });
    });
</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">
                <button class="btn btn-primary btn-sm" type="button" id="local_app">
                    <i class="si fa-fw si-puzzle"></i>
                    安装本地应用
                </button>
                <a class="btn btn-success btn-sm" href="<?php echo APP_URL; ?>&action=cache" target="iPHP_FRAME">
                    <i class="si fa-fw si-refresh"></i>
                    更新缓存
                </a>
            </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; ?>" />
                <div class="form-row">
                    <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="type">类型</label>
                        </div>
                        <select v-model="type" id="type" name="type" class="form-control" data-placeholder="请选择应用类型...">
                            <option value="">所有类型</option>
                            <?php echo Apps::getTypeSelect(); ?>
                        </select>
                    </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="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-content p-0">
            <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 text-nowrap table-hover table-striped table-vcenter font-size-sm mb-0">
                        <thead class="bg-light text-black">
                            <tr>
                                <th style="width: 40px">APPID</th>
                                <th>
                                    名称
                                    <span class="badge badge-success">标识</span>
                                    <span class="badge badge-info">版本</span>
                                </th>
                                <th>类型</th>
                                <th class="text-center">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            if ($result) foreach ($result as $key =>$value) { 
                                $table = AppsTable::items($value['table']); 
                                $config = $value['config']; 
                            ?>
                            <tr id="id<?php echo $value['id']; ?>">
                                <td class="text-center"><?php echo $value['id']; ?></td>
                                <td class="font-size-sm">
                                    <p class="font-w600 mb-1">
                                        <a href="javascript:void(0)"><?php echo $value['name']; ?></a>
                                        <span class="badge badge-success"><?php echo $value['app']; ?></span>
                                        <span class="badge badge-info"><?php echo $config['version']; ?></span>
                                    </p>
                                    <?php if ($value['apptype'] == Apps::CONTENT_TYPE) { ?>
                                    <div class="btn-group btn-group-sm">
                                        <a href="<?php echo ADMINCP_URL; ?>=<?php echo $value['app']; ?>&do=manage&appid=<?php echo $value['id']; ?>" class="btn btn-alt-primary" target="_blank" title="内容管理">
                                            <i class="fa fa-fw fa-list-alt"></i>
                                            内容管理
                                        </a>
                                        <a href="<?php echo ADMINCP_URL; ?>=<?php echo $value['app']; ?>&do=add&appid=<?php echo $value['id']; ?>" class="btn btn-alt-primary" target="_blank" title="添加内容">
                                            <i class="fa fa-fw fa-plus-circle"></i>
                                            添加内容
                                        </a>
                                    </div>
                                    <?php } ?>
                                    <p class="d-none d-sm-block text-muted text-wrap">
                                        <?php echo $config['info']; ?>
                                    </p>
                                </td>
                                <td>
                                    <p class="mb-0"><?php echo Apps::$typeMap[$value['type']]; ?></p>
                                    <div class="btn-group btn-group-sm">
                                        <?php if (is_array($table) && !empty($table)) { ?>
                                        <a class="btn btn-sm btn-alt-info" href="https://www.icmsdev.com/docs/v8/<?php echo $value['app']; ?>/table.html" target="_blank" title="点击查看应用数据结构说明"><i class="fa fa-fw fa-cubes"></i></a>
                                        <?php } ?>
                                        <?php if ($config['template']) { ?>
                                        <a class="btn btn-sm btn-alt-info" href="https://www.icmsdev.com/docs/v8/<?php echo $value['app']; ?>/template.html" target="_blank" title="点击查看模板标签说明">
                                            <i class="fa fa-fw fa-layer-group"></i>
                                        </a>
                                        <?php } ?>
                                    </div>
                                </td>
                                <td class="text-right">
                                    <?php if ($value['type']) { ?>
                                    <div class="btn-group btn-group-sm">
                                        <a href="<?php echo APP_URL; ?>&do=add&id=<?php echo $value['id']; ?>" class="btn btn-alt-primary" title="编辑"><i class="fa fa-fw fa-pencil-alt"></i></a>
                                        <?php if ($value['apptype']) { ?>
                                        <a href="<?php echo APP_URL; ?>&do=clone&id=<?php echo $value['id']; ?>" class="btn btn-alt-primary" title="复制"><i class="fa fa-fw fa-copy"></i></a>
                                        <a href="<?php echo APP_URL; ?>&do=add&rootid=<?php echo $value['id']; ?>" class="btn btn-alt-primary" title="子应用"><i class="fa fa-fw fa-bezier-curve"></i></a>
                                        <a href="<?php echo APP_URL; ?>&do=pack&id=<?php echo $value['id']; ?>" class="btn btn-alt-primary" title="打包"><i class="fa fa-fw fa-suitcase-rolling"></i></a>
                                        <?php } ?>
                                    </div>
                                    <?php if ($value['apptype']) { ?>
                                    <div class="clearfix mt-1"></div>
                                    <div class="btn-group btn-group-sm">
                                        <?php if ($value['status']) { ?>
                                        <a href="<?php echo APP_URL; ?>&action=update&_args=status;0&id=<?php echo $value['id']; ?>" target="iPHP_FRAME" class="btn btn-alt-primary" data-confirm="delete" title="关闭">
                                            <i class="fa fa-fw fa-times"></i>
                                        </a>
                                        <?php } else { ?>
                                        <a href="<?php echo APP_URL; ?>&action=update&_args=status;1&id=<?php echo $value['id']; ?>" target="iPHP_FRAME" class="btn btn-alt-primary" title="启用"><i class="fa fa-fw fa-check"></i></a>
                                        <?php } ?>
                                        <a
                                            href="<?php echo APP_URL; ?>&action=uninstall&id=<?php echo $value['id']; ?>"
                                            target="iPHP_FRAME"
                                            class="btn btn-alt-danger"
                                            title="卸载应用？\n卸载应用会清除应用所有数据！\n卸载应用会清除应用所有数据！\n卸载应用会清除应用所有数据！\n确定要卸载?\n确定要卸载?\n确定要卸载?"
                                            data-confirm="delete"
                                        >
                                            <i class="fa fa-fw fa-trash-alt"></i>
                                        </a>
                                    </div>
                                    <?php } ?>
                                    <?php } ?>
                                </td>
                            </tr>
                            <?php }  ?>
                        </tbody>
                    </table>
                </div>
                <?php self::formFoot(); ?>
            </form>
        </div>
    </div>
</div>
<div id="local_app_wrap" style="display: none">
    <form action="<?php echo APP_URL; ?>&action=install" method="POST" id="<?php echo APP_FORMID; ?>" target="iPHP_FRAME">
        <div class="alert alert-info">
            由于安全限制
            <br />
            请先把iCMS应用安装包文件(.
            <?php echo Apps::PKG_EXT; ?>
            )
            <br />
            上传到网站根目录下
        </div>
        <div class="form-group">
            <div class="input-group">
                <div class="input-group-prepend">
                    <span class="input-group-text">可用安装包</span>
                </div>
                <select name="zipfile" class="form-control" data-placeholder="请选择iCMS应用安装包文件(.<?php echo Apps::PKG_EXT; ?>)...">
                    <?php
                $pkgArray = AppsHelper::getLocalPkg();
                if ($pkgArray) foreach ($pkgArray as $value) {
                    $name = str_replace(iPHP_PATH, '', $value);
                ?>
                    <option value="<?php echo $name; ?>">
                        <?php echo $name; ?>
                    </option>
                    <?php } ?>
                </select>
            </div>
        </div>
        <button class="btn btn-primary btn-lg btn-block" type="submit">
            <i class="fa fa-fw fa-check"></i>
            安装
        </button>
    </form>
</div>
<?php self::foot(); ?>
