<link rel="stylesheet"
      href="<?php echo base_url(); ?>public/static/backend/css/layouts/view.css?v=<?= rand(10000, 100000) ?>">
<link rel="stylesheet" href="<?php echo base_url(); ?>public/static/backend/css/drag_list.css">
<!-- Page Breadcrumb -->
<div class="page-breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="fa fa-home"></i>
            <a href="<?= base_url('backend/dashboard'); ?>" style="color: #797979">主頁</a>
        </li>
        <li>
            <i class="fa fa-home"></i>
            <a href="<?= base_url('backend/landingmain'); ?>" style="color: #797979">網站主網頁</a>
        </li>
        <li class="active" style="color: #ef4130">新增網站主網頁</li>
    </ul>
</div>
<!-- /Page Breadcrumb -->
<!-- Page Header -->
<div class="page-header position-relative">
    <div class="header-title">
        <h1>
            網站主網頁
        </h1>
    </div>
    <!--Header Buttons-->
    <div class="header-buttons">
        <a class="sidebar-toggler" href="#">
            <i class="glyphicon glyphicon-resize-horizontal"></i>
        </a>
        <a class="refresh" id="refresh-toggler" href="#">
            <i class="glyphicon glyphicon-refresh"></i>
        </a>
        <a class="fullscreen" id="fullscreen-toggler" href="#">
            <i class="glyphicon glyphicon-fullscreen"></i>
        </a>
    </div>
    <!--Header Buttons End-->
</div>
<!-- /Page Header -->
<!-- Page Body -->
<div class="page-body">
    <div class="container-fluid py-2" style="min-height:80vh;">
        <!-- <h2 style="color:#7d4495;">正在架設中...敬請期待!</h2> -->

        <!-- dashboard -->
        <div class="row">
            <!-- column -->

            <div class="col">
                <!-- body table -->
                <div class="box-typical box-typical-padding">
                    <h5 class="with-border">Information</h5>
                    <form class="form-horizontal" method="post" action="<?= base_url() ?>backend/landingmain/edit"
                          enctype="multipart/form-data">
                        <input type="hidden" name="<?= $csrf['name']; ?>" value="<?= $csrf['hash']; ?>"/>
                        <input type="hidden" name="displayorder"
                               value="<?= isset($landingmain[0]->displayorder) ? $landingmain[0]->displayorder : ''; ?>"/>
                        <?php if ($save) { ?>
                            <div class="alert alert-success alert-dismissable ">
                                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                                Landing Main 主目錄成功儲存.
                            </div>
                        <?php } ?>
                        <div class="form-group row">
                            <label class="col-sm-2 control-label">標題（中文）</label>
                            <div class="col-sm-10">
                                <input type="text" name="title" class="form-control" required
                                       value="<?php if (isset($landingmain[0]->title)) {
                                           echo $landingmain[0]->title;
                                       } ?>">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 control-label">標題（英文）</label>
                            <div class="col-sm-10">
                                <input type="text" name="title_en" class="form-control"
                                       value="<?php if (isset($landingmain[0]->title_en)) {
                                           echo $landingmain[0]->title_en;
                                       } ?>">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 control-label">路徑</label>
                            <div class="col-sm-10">
                                <input type="text" name="uri" class="form-control"
                                       value="<?php if (isset($landingmain[0]->uri)) {
                                           echo $landingmain[0]->uri;
                                       } ?>">
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="col-sm-2"></div>
                            <div class="col-sm-10">
                                <input name="save" type="submit" class="btn btn-success" value="儲存">
                                <input type="submit" class="btn btn-danger" value="重設">
                                <input type="hidden" name="id" value="<?php if (isset($landingmain[0]->id)) {
                                    echo $landingmain[0]->id;
                                } ?>">
                            </div>
                        </div>
                    </form>
                </div>
                <!--.box-typical-->

                <!-- end body table -->
            </div>
        </div>
        <!-- end dashboard -->
        <?php
            if (isset($landingmain[0]->id)) {
        ?>
        <div class="row">
            <!-- column -->

            <div class="col">
                <!-- body table -->
                <!-- add button -->
                <div class="dropdown">
                    <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        新增
                    </button>
                    <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                        <a class="dropdown-item add-title">標題</a>
                        <a class="dropdown-item add-picture">圖片</a>
                    </div>
                </div>
                <!-- end add button -->

                <!-- drag table test -->
                <section class="box-typical">

                    <div class="fixed-table-toolbar">
                        <div class="bars pull-left">
                            <div id="toolbar"><strong>物件</strong></div>
                        </div>
                        <div class="pull-right search"></div>
                    </div>

                    <div id="info" class="content">(Drag the <span style="color:red">red square</span> to re-arrange the
                        order.)
                    </div>
                    <!-- test drag table -->
                    <table width="100%" border="1" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC" class="content">
                        <tbody>
                        <tr bgcolor="#EEEEEE">
                            <td width="30" align="center"></td>
                            <td width="100">顯示次序</td>
                            <td width="200">物件種類</td>
                            <td width="50"></td>
                            <td width="50"></td>
                        </tr>
                        </tbody>
                    </table>
                    <ul id="content-list" class="ui-sortable">
                        <?php
                        foreach ($landingmain_objects as $object) {
                            ?>
                            <li id="listItem_<?php echo $object['id']; ?>" class="border border-secondary my-2">
                                <table width="100%" border="1" cellpadding="2" cellspacing="1" bgcolor="#cccccc"
                                       class="content" style="background: rgb(255, 182, 182);">
                                    <tbody>
                                    <tr bgcolor="#FFFFFF" id="<?php echo $object['id']; ?>">
                                        <td width="30" align="center">
                                            <div class="handle"></div>
                                        </td>
                                        <td width="100">
                                            <div class="rank_no"><?php echo $object['displayorder']; ?></div>
                                        </td>
                                        <?php
                                        $type = $object['page_object_type'];
                                        if ($type == 'TITLE') {
                                            if ($object['objects'][0]['title_type'] == 'M') {
                                                $type = 'MAIN' . $type;
                                            }
                                            else {
                                                $type = 'SUB' . $type;
                                            }
                                        }
                                        ?>
                                        <td width="200"><?php echo $object_type[$type]; ?></td>

                                        <td width="50" align="center"><a
                                                    href="<?php echo base_url(); ?>backend/pageobjects/edit?main_id=<?php echo $landingmain[0]->id; ?>&id=<?php echo $object['id']; ?>"
                                                    class="btn btn-primary">更改</a></td>
                                        <td width="50" align="center">
                                            <button type="submit" class="btn btn-danger remove">删除</button>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </li>
                            <?php
                        }
                        ?>
                    </ul>
                </section>

                <!-- end body table -->
            </div>
        </div>
        <?php
            }
        ?>
    </div>
</div>

<!-- /Page Body -->
<script>
    var base_url = '<?=base_url();?>';
    var csrf_name = '<?=$csrf['name'];?>';
    var csrf_hash = '<?=$csrf['hash'];?>';
</script>
<script defer="" src="<?php echo base_url(); ?>public/static/backend/js/jquery-ui-min.js"></script>
<script defer="" src="<?php echo base_url(); ?>public/static/backend/js/custom/landingmain_edit.js"></script>
