<?php //print_r($usertype);exit; ?>
    <section class="content-header">
      <h1>
        Members Having Discount
      </h1>
      <ol class="breadcrumb">
        <li><a href="<?php echo base_url().'admin';?>"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">List</li>
      </ol>
    </section>

    <section class="content">
      <div class="row">
        <?php echo $this->utility->showMsg();?>
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">Management</h3>
              
              </div>
               
              <div></div>
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <?php if($this->session->userdata('admin_id') =='11330' || $this->session->userdata('admin_id') =='25267' ) { ?>
                  <th>Email</th>
                  <?php } ?>
                  <th>Psedonym</th>
                  <th>Registered</th>
                  <th>Discounted percent</th>
                  <th>Action</th>
                </tr>
                </thead>
                 <?php if(count($discounted_users)>0)
                {?>
                <tbody>
               <?php
                $i=1;
                foreach ($discounted_users as $data) 
                {
                ?>
                <tr>
                  <?php if($this->session->userdata('admin_id') =='11330' || $this->session->userdata('admin_id') =='25267' ) { ?>
                    <td><?php echo $data['email']; ?></td>
                    <?php } ?>
                    <td><?php echo $data['username']; ?></td>
                    <td><?php echo date('d-m-Y h:i:s',$data['created']);?></td>
                    <td><?php echo $data['discount']; ?></td>
                    <td><a href="javascript:void(0)" title="Edit Discount" class="discount" data-toggle="modal" data-target="#myModal" data-id="<?php echo $data['user_id'];?>" data-percent="<?php echo $data['discount']; ?>"><span class="fa fa-pencil"></span></a></td>
                </tr>

               <?php $i++; } ?>

                </tbody>
                <?php } ?>
                <tfoot>
               
                </tfoot>
              </table>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    
 <div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Enter Discount Percent</h4>
      </div>
      <div class="modal-body">
        <form action="<?php echo base_url().'admin/users/add_delete_date'; ?>" method="post">
            <div class="box-body">
              <div class="form-group">
                  <label class="col-sm-2 control-label">Discount</label>
                  <div class="col-sm-6">
                    <select name="discount" id="discount" class="form-control">
                        <option value="0">0</option>
                    <?php for($i=1; $i<101; $i++){ ?>
                        <option value="<?php echo $i; ?>" <?php if(!empty($memberDiscount) && $memberDiscount['discount']==$i){ echo 'selected'; }?>><?php echo $i; ?></option>
                    <?php }?>
                    </select>
                    <input name="user_id" id="user_id" class="form-control" type="hidden" value="">
                  </div>

                </div>
          </div>
          <div class="text-center">
            <input type="button" class="btn btn-info " value="Update" id="add">
          </div>
            
        </form>

      </div>
      
    </div>

  </div>
</div>   
<script>
  $(function () {
    var datatable = $("#example1").DataTable();
    $('body').on('click','.discount', function(){
        $('#user_id').val($(this).data('id'));
        $('#discount"]').val($(this).data('percent'));
    })
    $('#add').click(function(){
      if($('#user_id').val() > 0){
        $.ajax({
          url: '<?php echo base_url('admin/discount_users/update');?>',
          type:'POST',
          data:{
            user_id: $('#user_id').val(),
            discount: $('#discount').val()
          },
          success: function(){
            window.location.reload();
          }
        })
      } else {
        alert('Some error occured');
      }
    })
  });
</script>