<link rel="stylesheet"
      href="<?php echo base_url(); ?>assets/at-admin/css/layouts/view.css?v=<?= rand(10000, 100000) ?>">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/at-admin/css/drag_list.css">
<style>
    .form-control {
        height: calc(1.5em + .75rem + 10px);
    }
</style>

<!-- Page Breadcrumb -->
<div class="page-breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="fa fa-home"></i>
            <a href="<?= base_url('at-admin/dashboard'); ?>" 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() ?>at-admin/pageobjects/edit"
                          enctype="multipart/form-data">
                        <input type="hidden" name="<?= $csrf['name']; ?>" value="<?= $csrf['hash']; ?>"/>
                        <input type="hidden" name="object_id" value="<?= $objects['id']; ?>"/>
                        <div class="form-group row">
                            <label class="col-sm-2 control-label">顯示行數</label>
                            <div class="col-sm-10">
                                <select name="cols" class="form-control">
                                    <?php
                                    $obj = $objects['objects'][0];
                                    $cols = $obj['cols'];
                                    for ($i = 1; $i <= 4; $i++) {
                                        echo sprintf('<option value="%s"%s>%s</option>', $i, ($i == $cols) ? ' selected="selected"' : '', $i);
                                    }
                                    ?>
                                </select>
                            </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="重設">
                                <a href="<?=$back_link;?>">返回</a>
                                <input type="hidden" name="id" value="<?= $objects['object_id']; ?>"/>
                                <input type="hidden" name="main_id" value="<?= $objects['main_id']; ?>"/>
                                <input type="hidden" name="submenu_id" value="<?= $objects['submenu_id']; ?>"/>
                                <input type="hidden" name="page_object_type"
                                       value="<?= $objects['page_object_type']; ?>"/>
                            </div>
                        </div>
                    </form>
                    <!-- end body table -->
                </div>
            </div>
        </div>
        <div class="row">
            <!-- column -->

            <div class="col">
                <!-- end dashboard -->

                <!-- body table -->
                <!-- 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="20">顯示次序</td>
                            <td width="200">圖片</td>
                            <td width="50">橫幅標題</td>
                            <td width="50">主標題</td>
                            <td width="50">副標題</td>
                            <td width="50">簡介</td>
                            <td width="50">&nbsp;</td>
                        </tr>
                        </tbody>
                    </table>
                    <ul id="content-list" class="ui-sortable">
                        <?php
                        foreach ($obj['pictures'] as $pic) {
                        ?>
                            <li id="listItem_<?php echo $pic['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 $pic['id']; ?>">
                                        <td width="30" align="center">
                                            <div class="handle"></div>
                                        </td>
                                        <td width="20">
                                            <div class="rank_no"><?php echo $pic['displayorder']; ?></div>
                                        </td>
                                        <td width="200"><img style="max-width: 200px;" src="<?=base_url($pic['path']);?>" /></td>
                                        <td width="50"><?php echo $pic['banner_title']; ?></td>
                                        <td width="50"><?php echo $pic['main_title']; ?></td>
                                        <td width="50"><?php echo $pic['sub_title']; ?></td>
                                        <td width="50"><?php echo $pic['caption']; ?></td>
                                        <td width="50" align="center">
                                            <button type="button" class="btn btn-primary edit-picture">編輯</button>
                                            <button type="submit" class="btn btn-danger remove-picture">删除</button>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </li>
                            <?php
                        }
                        ?>
                    </ul>
                </section>
            </div>
        </div>
        <div class="row pt-5">
            <div class="col">
                <h3 class="with-border">上載圖片</h3>
                <form class="form-horizontal" method="post" action="<?= base_url() ?>at-admin/pageobjects/upload_picture"
                      enctype="multipart/form-data">
                    <input type="hidden" name="<?= $csrf['name']; ?>" value="<?= $csrf['hash']; ?>"/>
                    <div class="form-group">
                        <label for="picture" class="control-label">圖片</label>
                        <?php
                        if (array_key_exists ('path', $picture_info)) {
                            if ($picture_info['path'] != '') {
                                echo sprintf('<img src="%s" class="d-block" style="max-width: 200px;" />', base_url($picture_info['path']));
                            }
                        }
                        ?>
                        <input type="file" id="picture" name="picture" class="form-control" />
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 control-label">橫幅標題</label>
                        <div class="col-sm-10">
                            <input type="text" name="banner_title" class="form-control"
                                   value="<?php
                                   if (array_key_exists ('banner_title', $picture_info)) {
                                       echo $picture_info['banner_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="main_title" class="form-control"
                                   value="<?php
                                   if (array_key_exists ('main_title', $picture_info)) {
                                       echo $picture_info['main_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="sub_title" class="form-control"
                                   value="<?php
                                   if (array_key_exists ('sub_title', $picture_info)) {
                                       echo $picture_info['sub_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="caption" class="form-control"
                                   value="<?php
                                   if (array_key_exists ('caption', $picture_info)) {
                                       echo $picture_info['caption'];
                                   }
                                   ?>">
                        </div>
                    </div>
                    <div class="form-group">
                        <input name="save" type="submit" class="btn btn-success" value="儲存">
                        <input type="submit" class="btn btn-danger" value="重設">
                        <input type="hidden" name="id" value="<?= $objects['id']; ?>"/>
                        <input type="hidden" name="main_id" value="<?= $objects['main_id']; ?>"/>
                        <input type="hidden" name="submenu_id" value="<?= $objects['submenu_id']; ?>"/>
                        <input type="hidden" name="picture_id" value="<?= $picture_info['id']; ?>"/>
                        <input type="hidden" name="object_id" value="<?= $objects['id']; ?>"/>
                        <input type="hidden" name="picture_info_id" value="<?= $obj['id']; ?>"/>
                        <input type="hidden" name="page_object_type"
                               value="<?= $objects['page_object_type']; ?>"/>
                    </div>
                </form>
            </div>
        </div>
        <!-- end dashboard -->
    </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(); ?>assets/at-admin/js/jquery-ui-min.js"></script>
<script defer="" src="<?php echo base_url(); ?>assets/at-admin/js/custom/pageobject_picture_edit.js"></script>
