<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html class="no-js">
<head>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Catering - background management</title>
    <link rel="stylesheet" href="/canyin2/Public/assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="/canyin2/Public/assets/css/core.css" />
    <link rel="stylesheet" href="/canyin2/Public/assets/css/menu.css" />
    <link rel="stylesheet" href="/canyin2/Public/assets/css/index.css" />
    <link rel="stylesheet" href="/canyin2/Public/assets/css/admin.css" />
    <link rel="stylesheet" href="/canyin2/Public/assets/css/page/typography.css" />
    <link rel="stylesheet" href="/canyin2/Public/assets/css/page/form.css" />
    <link rel="stylesheet" href="/canyin2/Public/assets/css/component.css" />
    <link rel="stylesheet" href="/canyin2/Public/layui2/css/layui.css" />
    <script type="text/javascript" src="/canyin2/Public/assets/js/jquery.min.js" ></script>
    <script type="text/javascript" src="/canyin2/Public/assets/js/app.js" ></script>
    <script type="text/javascript" src="/canyin2/Public/assets/js/jquery-2.1.0.js" ></script>
    <script src="/canyin2/Public/layer/layer.js"></script>
    <script src="/canyin2/Public/layui2/layui.all.js"></script>
    <style type="text/css">
        .am-padding-0 {
            padding: 0!important;
            overflow-y: hidden;
        }
        .content-page {
            flex: 1;
            -webkit-flex: 1;
            background: white;
        }
    </style>

    <style type="text/css">
        a.am-text-secondary:visited{color:#3bb4f2;}
        a.am-text-danger:visited{color:#dd514c;}
        .am-btn-default {background-color: #fff;}
        th {text-align:center;}
        tr td{text-align:center;}
        select{padding: 4px;border: 1px solid #ccc;}
        .am-popup-bd {background:#fff;}
        .am-popup-bd img {max-width: 100%}
        .am-u-sm-2 {border-top: 1px solid #ddd;margin-top: 10px;}
        .am-u-sm-10 {border-left: 1px solid #ddd;margin-top: 10px;}
    </style>
</head>
<body>

<!-- Begin page -->
        <header class="am-topbar am-topbar-fixed-top" style="    border-top: 3px solid #ebeff2;">
            <div class="am-topbar-left am-hide-sm-only">
                <a href="#" class="logo"><span>Admin<span></span></span><i class="zmdi zmdi-layers"></i></a>
            </div>
    
            <div class="contain">
                <ul class="am-nav am-navbar-nav am-navbar-left">

                    <li><h4 class="page-title">Admin Backend Management</h4></li>
                </ul>
                
                <ul class="am-nav am-navbar-nav am-navbar-right">
                    <!-- <li class="hidden-xs am-hide-sm-only" style=" margin-top: 8px;">
                        <form role="search" class="app-search">
                            <input type="text" placeholder="Search..." class="form-control">
                            <a href=""><img src="/canyin2/Public/assets/img/search.png"></a>
                        </form>
                    </li> -->
                    <li class="inform" style="margin: 0px">
                        <section data-am-widget="accordion" style="margin-left:10px; margin-top:0px" class="am-accordion am-accordion-basic" data-am-accordion='{  }'>
                            <dl class="am-accordion-item " style="width: 80px">
                                <dt class="am-accordion-title" style="padding: 0">
                                    <span class="am-icon-home "></span>
                                </dt>
                                <dd class="am-accordion-bd am-collapse">
                                    <!-- 规避 Collapase 处理有 padding 的折叠内容计算计算有误问题， 加一个容器 -->
                                    <div class="am-accordion-content" style=" background: #f3f3f3;">
                                        <a href="javascript: ;" id="change_pw">Change the password</a><br/>
                                        <a href="<?php echo U('login/logout');?>">exit</a><br/>
                                    </div>
                                </dd>
                            </dl>
                        </section>
                    </li>
                </ul>
            </div>

        </header>
<div class="am-modal am-modal-prompt am-modal-active" tabindex="-1" id="my-prompt-pw" style="">
    <div class="am-modal-dialog" style="color: #000;">
        <div class="am-modal-hd">Change the password</div>
        <div class="am-modal-bd">

            <input type="password" class="am-modal-prompt-input input-pw" id="old_pw" placeholder="The original password">
            <input type="password" class="am-modal-prompt-input input-pw" id="new_pw" placeholder="The new password">
            <input type="password" class="am-modal-prompt-input input-pw" id="mew_pw" placeholder="Repeat the password">
        </div>
        <div class="am-modal-footer">
            <span class="am-modal-btn" data-am-modal-cancel="">cancel</span>
            <span class="am-modal-btn" id="confirm_pw" data-am-modal-confirm="">confirm</span>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        $("#confirm_pw").on('click',function(){
            var old_pw = $("#old_pw").val();
            var new_pw = $("#new_pw").val();
            var mew_pw = $("#mew_pw").val();
            if(!old_pw){
                layer.msg("Please enter the original password");
                return false;
            }
            if(!new_pw){
                layer.msg("Please enter a new password");
                return false;
            }
            if(!mew_pw){
                layer.msg("Please enter a duplicate password");
                return false;
            }
            if(new_pw != mew_pw){
                layer.msg("The passwords entered do not match");
                return false;
            }
        });
    });
    $(function(){
        $("#change_pw").on('click',function(){
            $('#my-prompt-pw').modal({
                relatedTarget: this,
                closeOnConfirm: false,
                onConfirm: function(e) {
                    var old_pw = $("#old_pw").val();
                    var new_pw = $("#new_pw").val();
                    var mew_pw = $("#mew_pw").val();
                    if(!old_pw || !new_pw || !mew_pw || new_pw!= mew_pw){return false;}

                    $.ajax({type:'post',url:'<?php echo U("Smi/Login/change_pw");?>',
                        data:{old_pw:old_pw,new_pw:new_pw},
                        success:function(result){
//                        alert(result);
                            if(result == 1){
                                alert("Modified successfully, please login again");
                                window.location.href = "<?php echo U('Login/logout');?>";
                            }else{
                                alert('The original password is wrong, please input again');
                            // $(".input-pw").val('');
                            // return false;
                        }
                        }
                    });
                },
                onCancel: function(e) {
                    $(".input-pw").val('');
                }
            });
        });
    });
</script>

<!-- end page -->

<div class="am-cf admin">

    <!-- sidebar start -->
    ﻿                  <div class="admin-sidebar am-offcanvas  am-padding-0" id="admin-offcanvas" style=" overflow-y: scroll;">
                    <div class="am-offcanvas-bar admin-offcanvas-bar">
                        <!-- User -->
                        <div class="user-box am-hide-sm-only">
                            <div class="user-img">
                                <img src="/canyin2/Uploads/<?php echo session('picture');?>"  alt="user-img" title="Mat Helme" class="img-circle img-thumbnail img-responsive">
                                <!--<?php echo ($_SESSION['admin_picture']); ?>-->
                                <div class="user-status offline"><i class="am-icon-dot-circle-o" aria-hidden="true"></i></div>
                            </div>
                            <h5><a href="#"><?php echo ($_SESSION['admin']); ?></a> </h5>
                            <ul class="list-inline">
                                <li>
                                    <a href="#">
                                        <i class="fa fa-cog" aria-hidden="true"></i>
                                    </a>
                                </li>
    
                                <li>
                                    <a href="#" class="text-custom">
                                        <i class="fa fa-cog" aria-hidden="true"></i>
                                    </a>
                                </li>
                            </ul>
                        </div>
                        <!-- End User -->
                        
                 <ul class="am-list admin-sidebar-list" style="margin-bottom: 2rem;">
                  <?php foreach ($menu_list as $vo) : ?>
                    <li class="admin-parent">
                        <a class="am-cf" data-am-collapse="{target: '#<?php echo ($vo['nav']); ?>-nav'}">
                            <span class="am-icon-file"></span>
                            <?php echo ($vo["title"]); ?>
                            <span class="am-icon-angle-right am-fr am-margin-right"></span>
                        </a>
                          <ul class="am-list am-collapse admin-sidebar-sub <?php if($nav == $vo['nav']): ?>am-in<?php endif; ?>" id="<?php echo ($vo["nav"]); ?>-nav">
                          <?php foreach ($vo['menu_list'] as $vv) : ?>
                          <li>
                              <a href="<?php echo U($vv['url']);?>" class="am-cf">
                                  <span class="am-icon-calendar"></span>
                                  <?php echo ($vv['title']); ?>
                              </a>
                          </li>
                          <?php endforeach;?>
                        </ul>
                    </li>
                  <?php endforeach;?>
              </ul>
              <br><br>
              <br>
              <br><br><br><br>
          </div>
      </div>
        <!-- sidebar end -->
    <!-- sidebar end -->

    <!-- Start right Content here -->
        <div class="content-page" style="background: white;">
            <!-- Start content -->
            <div class="content">
                <div class="am-cf am-padding am-padding-bottom-0">
                    <div class="am-fl am-cf">
                        <strong class="am-text-primary am-text-lg">E-voucher</strong> / <small>List<span style="color: red;">(Note: You can only set one E-voucher as red packet)</span></small>
                    </div>
                </div>
                <!-- <hr style="margin-top:0px;"> -->
                <div class="am-g">
                    <form class="am-form-inline" action="" method="get">
                        <div class="am-u-sm-12 am-u-md-6">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <a class="am-btn am-btn-secondary" href="<?php echo U('add');?>">Add E-voucher</a>
                                </div>
                            </div>
                        </div>
                        <div class="am-u-sm-12 am-u-md-3">&nbsp;</div>
                    </form>
                </div>
                <div class="am-g">
                    <div class="am-u-sm-12">
                        <table class="am-table am-table-hover table-main am-text-nowrap">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Discount Amount(RM)</th>
                                    <th>Amount Entitled to Use Voucher</th>
                                    <th>E-voucher Total QTY</th>
                                    <th>E-voucher Remaining QTY</th>
                                    <th>QTY Per Person</th>
                                    <th>Valid Period</th>
                                    <th>Set As Red Packet</th>
                                    <th>Created Date</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if(is_array($list)): foreach($list as $key=>$vo): ?><tr>
                                        <td><?php echo ($vo["id"]); ?></td>
                                        <td><?php echo ($vo["pre_money"]); ?></td>
                                        <td><?php echo ($vo["full_money"]); ?></td>
                                        <td><?php echo ($vo["nums"]); ?></td>
                                        <td><?php echo($vo['nums']-$vo['re_nums']);?></td>
                                        <td><?php echo ($vo["num"]); ?></td>
                                        <td><?php echo ($vo["validity_day"]); ?></td>
                                        <td><?php if($vo['is_red'] == 0) : ?>No<?php else : ?><span style="color: red;">Yes</span><?php endif;?></td>
                                        <td><?php echo (date("Y-m-d H:i:s",$vo["create_time"])); ?></td>
                                        <td>
                                            <div class="am-dropdown" data-am-dropdown>
                                                <button class="am-btn am-btn-default am-btn-xs am-dropdown-toggle" data-am-dropdown-toggle>
                                                    <span class="am-icon-cog"></span>
                                                    <span class="am-icon-caret-down"></span>
                                                </button>
                                                <ul class="am-dropdown-content">
                                                     <li><a href="javascript:;" data-id="<?php echo ($vo["id"]); ?>" class="set_red">Set As Red Packet</a></li>
                                                    <li><a href="<?php echo U('edit',array('id' => $vo['id']));?>">Edit</a></li>
                                                    <li>
                                                        <a class="del_link" data-name="" data-url="<?php echo U('delete', array('id' => $vo[id]));?>" href="javascript:;">
                                                            Delete
                                                        </a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr><?php endforeach; endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
    <!-- end right Content here -->
        </div>

        <!-- navbar -->
        <a href="admin-offcanvas" class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}"><!--<i class="fa fa-bars" aria-hidden="true"></i>--></a>
        
        <script type="text/javascript" src="/canyin2/Public/assets/js/amazeui.min.js"></script>
        <script type="text/javascript" src="/canyin2/Public/assets/js/blockUI.js" ></script>
        <script type="text/javascript" src="/canyin2/Public/assets/js/charts/echarts.min.js" ></script>
        <script type="text/javascript" src="/canyin2/Public/assets/js/charts/indexChart.js" ></script>




        <style>
    .gai_title{
        display: flex;
        justify-content: space-around;
        height: 45px;
        line-height: 45px;
        font-size: 16px;
    }
    .all_div{
        display: flex;

    }
    .first_di{
        width: 100px;
        text-align: right;
        margin-right: 30px;
    }
    .jj_gai{
        display: flex;
        background: #F37B1D;
    }
    .gai_span{
        width: 105px;
        line-height: 50px;
        margin-left: 5px;
        color: #fff;
    }
    .gai_input{
        width: 280px;
        height: 30px;
        border-radius: 10px;
        margin-top: 11px;
    }
/*  .am-btn{
        width: 60%;
        margin-left: 20%;
        color: #fff;
        margin-top: 20px;
    } */
</style>

<audio id="remind" src="/canyin2/Public/remind.mp3"></audio>
<script type="text/javascript">
var remind = document.getElementById("remind");
	self.setInterval(getOrder,10000);   //10秒
   	

    //预定订单
    function getOrder() {
        var url = "<?php echo U('Order/CheckNewOrder');?>"//路径
        $.get(url, function(data){
            console.log(data)
            if(data.status == 1){
                remind.currentTime = 0;
                remind.play();
                layer.closeAll('page'); //关闭所有页面层
                layer.open({
                title:['新的订单','background:#0e90d2;color:white;text-align:center;padding-left:76px;font-size:17px;'],
                type: 1,
                skin: 'layui-layer-rim', //加上边框
                area: ['420px', '330px'], //宽高
                content: data.content
            });
            }
        },'json')
     //  

    }
    //layui-layer-ico layui-layer-close layui-layer-close1
    $('body').on('click', '.close_box', function() {

      layer.closeAll();
    });
</script>

<script type="text/javascript">
    $(function(){
        // 删除
        $(".del_link").on("click",function(){
            var name=$(this).attr("data-name");
            var the_link=$(this).attr("data-url");
            var bool = confirm("Confirm Delete?");
            if (bool) {
                location.href = the_link;
            };
        });

        // 设为红包
        $('.set_red').click(function(){
            $.ajax({
                url: "<?php echo U('/Smi/Pre/set_red');?>", 
                type: 'POST', 
                data: {id: $(this).attr('data-id')},
                success: function (res) {
                    if (res.status == 1) {
                        alert(res.msg);
                        location.reload();
                    } else {
                        alert(res.msg);
                    }
                }
            });
        });
    });
</script>
</body>
</html>