<!doctype html>
<html class="no-js">
<head>
<include file="Common/head" />
    <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>
<include file="Common/header" />
<div class="am-cf admin">

    <!-- sidebar start -->
    <include file="Common/sidebar" nav="$nav"/>
    <!-- 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">Distribution Management</strong> / <small>Distributor Apply List</small>
                    </div>
                </div>
                
                <hr style="margin-top:0px;">

                <div class="am-g">
                  <form class="am-form-group am-u-sm-12 am-u-md-8">
                    <div class="am-input-group am-input-group-sm search-div">
                      <input type="text" class="am-form-field" name="title" placeholder="Name or Phone" value="{$_GET['title']}" style="width: 300px;">
                      <select name="type" class="am-form-field" style="width:100px;display: inline-block;">
                        <option value="">All</option>
                        <option value="0">Pending Review</option>
                        <option value="1">Approved</option>
                        <option value="2">Reject</option>
                      </select>
                      <span class="am-input-group-btn" style="display: inline-block;" >
                        <button class="am-btn am-btn-default" type="submit">Search</button>
                      </span>
                      <script type="text/javascript">
                        $(function(){
                          <?php if($_GET[type]) echo '$("select[name=type]").val("'.$_GET[type].'");';?>
                        });
                      </script>
                    </div>
                  </form>
                </div>

                <div class="am-g">
                  <div class="am-u-sm-12">
                    <form class="am-form am-scrollable-horizontal">
                      <table class="am-table table-main am-text-nowrap">
                        <thead>
                          <tr>
                            <th width="5%">ID</th>
                            <th width="5%">User ID</th>
                            <th width="5%">Username</th>
                            <th width="5%">Phone</th>
                            <th width="5%">Applied Date</th>
                            <th width="5%">Reviewed Date</th>
                            <th width="5%">Review Status</th>
                            <th width="5%">Action</th>
                          </tr>
                        </thead>
                        <tbody>
                        
                          <if condition="!$list">
                            <tr><td colspan="16" style="text-align:center;">There's nothing here</td></tr>
                          </if>
                          <volist name="list" id="vo" key="k">
                            <tr>
                              <td>{$vo.id}</td>
                              <td>{$vo.user_id}</td>
                              <td>{$vo.name}</td>
                              <td>{$vo.phone}</td>
                              <td><?php echo date('Y-m-d H:i',$vo['addtime']) ?></td>
                              <td><?php if($vo['endtime']){ echo date('Y-m-d H:i',$vo['endtime']); }else{ ?> Not audit <?php } ?></td>
                              <td>
                                <?php if($vo['status']==0){?> Pending Review  <?php } ?>
                                <?php if($vo['status']==1){?> Approved  <?php } ?>
                                <?php if($vo['status']==2){?> Reject  <?php } ?>
                              </td>
                              <td>
                              <?php if($vo['status']==0){?>
                                <a  class="am-btn am-btn-default am-btn-xs" onclick="pass_apply(<?php echo $vo['user_id'] ?>,<?php echo $vo['id'] ?>,1)">Approve</a>
                                <a  class="am-btn am-btn-default am-btn-xs" onclick="pass_apply(<?php echo $vo['user_id'] ?>,<?php echo $vo['id'] ?>,2)">Reject</a>
                              <?php } ?>
                              <a onclick="share_apply_del(<?php echo $vo['id'] ?>)" class="am-btn am-btn-danger am-btn-xs" onclick="return confirm('Are you sure about deleting')">Delete</a>
                              </td>
                            </tr>
                          </volist>
                        </tbody>
                      </table>
                    </form>
                    <div class="am-cf">
                      <div class="am-fr">
                        {$page}
                      </div>
                    </div>
                  </div>
                </div>

            </div>
        </div>
    <!-- end right Content here -->
</div>
<include file="Common/footer" />
<script>
  function pass_apply(userid,id,status){
    $.ajax({
      type:"post",
      url:"<?php echo U('/Smi/Distribution/pass_apply') ?>",
      async:false,
      data: {
        id:id,
        status:status,
        userid:userid,
      },
      datatype:'json',
      success:function(data){
         
         if(data==10000){
            alert('Successfully Reviewed');
            location.href="";
         };
         if(data==20000){
            alert('Audit failure!');
            location.href="";
         };
      }
    });
  }

  function share_apply_del(id){
    $.ajax({
      type:"post",
      url:"<?php echo U('Smi/Distribution/share_apply_del') ?>",
      async:false,
      data: {
        id:id,
      },
      datatype:'json',
      success:function(data){
         if(data==10000){
            alert('Successfully Deleted');
            location.href="";
         };
         if(data==20000){
            alert('Delete failed!');
            location.href="";
         };
      }
    });
  }
</script>
</body>
</html>