<!-- Main Content -->

<div class="page-wrapper">

    <div class="container-fluid pt-25">

        <div class="row">

            <div class="col-md-12">

                <div class="alert alert-success alert-dismissible" role="alert" <?php if($this->session->flashdata('message')==''){ ?> style="display:none" <?php } ?> >

                    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>

                    <?php echo $this->session->flashdata('message'); ?>

                </div>

            </div>

        </div>

        <!-- Row -->

        <div class="row">

            <div class="col-sm-12">

                <div class="panel panel-default card-view">

                    <div class="panel-heading">

                        <div class="pull-left">

                            <h6 class="panel-title txt-dark">User List</h6>

                        </div>

                        <div class="pull-right">
                            <a href="javascript:void(0);" class="btn btn-info" data-toggle="modal" data-target="#searchModal">Search</a>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <?php if($this->admin_type=='superadmin' || (in_array('9.1', $this->authority))){ ?>
                                <a href="<?php echo base_url(A.'/downloadUserCsv'); ?>" class="btn btn-primary">Export</a>
                            <?php } ?>

                        </div>

                        <div class="clearfix"></div>

                    </div>

                    <div class="panel-wrapper collapse in">

                        <div class="panel-body">

                            <div class="table-wrap">

                                <div class="table-responsive">

                                    <table id="datable_1" class="table table-hover">

                                        <thead>

                                            <tr>

                                                <th>Sr. No.</th>

                                                <th>Name</th>

                                                <th>Email</th>

                                                <th>Mobile No.</th>

                                                <!-- <th>Total Point</th>
                                                <th>Level</th> -->

                                                <!-- <th>Newsletter Consent</th> -->
                                                <!-- <th>Terms & Conditions</th> -->

                                                <th>Action</th>

                                            </tr>

                                        </thead>

                                        <tbody>

                                            <?php //echo "<pre>"; print_r($users);

                                            $order_status = $this->config->item("order_status");

                                             if($users){ foreach ($users as $key => $value) : ?>

                                                <tr id="<?php echo "user_".$value['profileid']; ?>">

                                                    <td><?php echo ($key+1); ?></td>

                                                    <td><?php echo $value['name']; ?></td>

                                                    <td><?php echo $value['email']; ?></td>

                                                    <td><?php echo $value['mobile_no']; ?></td>

                                                    <!-- <td><a href="<?php //echo base_url(A.'/user-point-history/'.$value['profileid']); ?>" target="_blank"><?php //echo $value['remain_point']; ?></a></td> -->
                                                    <!-- <td>
                                                        <?php //if($value['package']==2){ ?>
                                                           <span class="badge badge-gold"><i class="fa fa-certificate"></i> Gold</span>
                                                        <?php //}else if($value['package']==1){ ?>
                                                            <span class="badge badge-silver"><i class="fa fa-certificate"></i> Silver</span>
                                                        <?php //}else{ ?>
                                                            <span class="badge badge-bronge"><i class="fa fa-certificate"></i> Bronze</span>
                                                        <?php //} ?>
                                                    </td> -->

                                                    <!-- <td><?php //echo (($value['newsletter']==1)?"Yes":"No"); ?></td> -->
                                                    <!-- <td><?php //echo (($value['terms']==1)?"Accept":"Not Accept"); ?></td> -->

                                                    <th>
                                                        <?php if($this->admin_type=='superadmin' || (in_array('9.2', $this->authority))){ ?>
                                                            <a href="<?php echo base_url(A.'/userdetail?userid='.$value['profileid']); ?>" class="text-inverse pr-10" target="_blank"> 
                                                                <button class="btn btn-primary btn-icon-anim btn-square mb-5">
                                                                    <i class="fa fa-eye fa-lg"></i>                                 
                                                                </button>
                                                            </a>
                                                        <?php } ?>
                                                        <?php if($this->admin_type=='superadmin' || (in_array('9.3', $this->authority))){ ?>
                                                            <a href="javascript:void(0)" class="text-inverse ajax_delete" data-table="user" data-value="<?php echo "profileid_".$value['profileid']; ?>"> 
                                                                <button class="btn btn-danger btn-icon-anim btn-square">
                                                                    <i class="fa fa-trash-o fa-lg"></i>
                                                                </button>
                                                            </a>
                                                        <?php } ?>
                                                    </th>

                                                </tr>

                                            <?php endforeach; } ?>

                                        </tbody>

                                    </table>

                                </div>

                            </div>

                        </div>

                    </div>

                </div>  

            </div>

        </div>

        <!-- /Row -->

    </div>
    <div class="modal fade" id="searchModal" tabindex="-1" role="dialog" aria-labelledby="searchModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="searchModalLabel">Search</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <form action="<?php echo base_url(A.'/user-list'); ?>" method="get">
              <div class="modal-body">
                    <div class="form-group">
                        <label>Name</label>
                        <input type="text" name="name" class="form-control" placeholder="Name">
                    </div>
                    <div class="form-group">
                        <label>Email</label>
                        <input type="text" name="email" class="form-control" placeholder="Email">
                    </div>
                    <div class="form-group">
                        <label>Mobile No.</label>
                        <input type="text" name="mobile_no" class="form-control" placeholder="Mobile No.">
                    </div>
                    <!-- <div class="form-group">
                        <label>Level</label>
                        <select class="form-control" name="level">
                            <option value="">Select</option>
                            <option value="1">Bronge</option>
                            <option value="2">Silver</option>
                            <option value="3">Gold</option>
                        </select>
                    </div> -->
              </div>
              <div class="modal-footer">
                <button type="submit" class="btn btn-primary">Submit</button>
              </div>
          </form>
        </div>
      </div>
    </div>
        
<style>
    .badge-gold{background:#F6BD2A;color:#fff;}
    .badge-silver{background:#99979A;color:#fff;}
    .badge-bronge{background:#A35F2E;color:#fff;}
</style>
<script type="text/javascript">

    var site_url = "<?php echo base_url(); ?>";
    var urlLink = "<?php echo A; ?>";

    $(".ajax_delete").on("click",function(){

        var id = $(this).attr("data-value");

        var split = id.split("_");

        //alert(split[0]);

        var table = $(this).attr("data-table");

        var image = ($(this).attr("data-image")=="undefined")?"":$(this).attr("data-image");

        var result = confirm("Are you sure you want to delete?");

        if(result) {

            $.ajax({

                url: site_url+urlLink+"/ajaxDelete",

                type: "POST",

                data: split[0]+"="+split[1]+"&table="+table+"&image="+image,

                success: function(result){

                    if(result==1)

                    {

                        $("#"+table+"_"+split[1]).remove();

                    }

                }

            });

        }

    });
</script>
