<?php //print_r($usertype);exit; ?>
    <section class="content-header">
      <h1>
        <?php if($this->uri->segment(3)=='expiredusers'){ echo 'Expired';} ?> Members
      </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>
              <?php if(chkWritePermission('All_Members',$this->session->userdata('admin_id'))!=0 || $this->session->userdata('admin_id')=='19624' ){ ?>
              <?php if($this->uri->segment(3)!='expiredusers'){ ?>
                <a class="btn btn-primary margin-right pull-right" href="<?php echo base_url()?>admin/users/add">Add</a>
			        <?php } ?>
              <?php } ?>
              </div>
               
              <div></div>
            <!-- /.box-header -->
            <div class="box-body">
            <form action="" id="search_frm" method="post" style="margin-bottom: 5%;">
              <input type="text" name="search" class="form-control" placeholder="Search by email" value="<?php if($this->input->post('search')) { echo $this->input->post('search'); }?>" style="width: 25%; float: right;">
              <input type="text" name="search_name" class="form-control" placeholder="Search by pseudonym" value="<?php if($this->input->post('search_name')) { echo $this->input->post('search_name'); }?>" style="width: 25%; float: right;">
              <input type="submit" class="btn btn-primary" value="Search" style="float: right;">
            </form>
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Email</th>
                  <th>Pseudonym</th>
                  <th>Registered</th>
                  <th>Last Login</th>
                  <th>Account Type</th>
                  <th>User Status</th>
                  <th>Email Status</th>
                  <th>Other Status</th>
                  <th>Came from</th>
                  <th>Campaign ID</th>
                  <th>IP Address</th>
                  <!--<th>Reject Reason</th>-->
                  <?php if(chkWritePermission('All_Members',$this->session->userdata('admin_id'))!=0 || $this->session->userdata('admin_id')=='19624' ){ ?>
                  <th>Action</th>
                  <?php } ?>
                </tr>
                </thead>
                 <?php if(count($users)>0)
                {?>
                <tbody>
               <?php
                $i=1;
                foreach ($users as $data) 
                {
                ?>
                <tr>
                    <td><?php echo $data['email']; ?></td>
                    <td><?php echo $data['username']; ?></td>
                    <td><?php echo date('d-m-Y h:i:s',$data['created']);?></td>
                    <td><?php if($data['last_login'] > 0) { echo date('d-m-Y h:i:s',$data['last_login']);} ?></td>
                    <td><?php echo $data['accounttype'];?></td>
                    <td><?php if($data['email_confirmed'] == 1) { echo 'Active'; } elseif($data['email_confirmed'] ==0 ) { echo 'Email not confirmed'; } else { echo 'Inactive'; }?></td>
                    <td><?php echo $data['email_status']; ?></td>
                    <td><?php echo $data['membership']; ?></td>
                    <td><?php if($data['came_from'] == 1) { echo 'Google Adwords'; } elseif($data['came_from'] ==2 ) { echo 'Facebook Adwords'; } else { echo 'Normal'; }?></td>
                    <td><?php echo $data['campaign_id']; ?></td>
                    <td><?php echo $data['ip_address']; ?></td>
                    <!--<td><?php echo $data['reject_reason']; ?></td>-->
                    <?php if(chkWritePermission('All_Members',$this->session->userdata('admin_id'))!=0 || $this->session->userdata('admin_id')=='19624' ){ ?>
                    <td>
                    <?php if($data['email_confirmed'] == 0) { ?>
                      <a href="<?php echo base_url();?>admin/users/email_confirm/<?php echo base64_encode($data['id']);?>" title="Confirm Email" onclick="return confirm('Are you sure ?');"><span class="fa fa-envelope"></span></a>
                    <?php } ?> 
                      <a href="<?php echo base_url();?>admin/users/edit/<?php echo base64_encode($data['id']);?>" title="Edit"><span class="fa fa-pencil-square"></span></a>
                      <a href="<?php echo base_url();?>admin/users/delete/<?php echo base64_encode($data['id']);?>" title="Delete" onclick="return confirm('Are you sure to delete ?');"><span class="fa fa-ban"></span></a>
                      <a href="<?php echo base_url();?>admin/users/add_membership/<?php echo base64_encode($data['id']);?>" title="Add membership"><span class="fa fa-plus"></span></a>
          					  <?php if($data['status'] == 1) { ?>
          					  <a href="<?php echo base_url();?>admin/users/block/<?php echo base64_encode($data['id']);?>/2" title="Block" onclick="return confirm('Are you sure to block ?');"><span class="fa fa-check"></span></a>
          					  <?php } else { ?>
          					  <a href="<?php echo base_url();?>admin/users/block/<?php echo base64_encode($data['id']);?>/1" title="Unblock" onclick="return confirm('Are you sure to unblock ?');"><span class="fa fa-times"></span></a>
          					  <?php } ?>
                      <?php if(($data['mobile_number'] != '' || $data['mobile_number'] != 0) && $data['verified'] == 0) { ?>
                      <a href="<?php echo base_url();?>admin/users/verify/<?php echo base64_encode($data['id']);?>/<?php echo str_replace('/','-',uri_string()); ?>" title="Verify" onclick="return confirm('Are you sure to verify ?');"><span class="fa fa-check-circle"></span></a>
                      <?php } ?>
                      <?php if($data['mobile_number'] == '' || $data['mobile_number'] == 0) { ?>
                      <a href="javascript: void(0)" class="update_number" data-toggle="modal" data-target="#myModal" data-id="<?php echo $data['id'];?>" title="Update Number" ><span class="fa fa-phone"></span></a>
                      <?php } ?>
          					</td> 
                    <?php } ?>
                </tr>

               <?php $i++; } ?>

                </tbody>
                <?php } ?>
                <tfoot>
               
                </tfoot>
              </table>
              <?php if($this->uri->segment(3)!='expiredusers'){ ?>
                <div class="custom_pagination"><?php echo $link; ?></div>
              <?php } ?>  
            </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">Update Number</h4>
      </div>
      <div class="modal-body">
        <form action="<?php echo base_url().'admin/users/update_number'; ?>" method="post">
            <div class="box-body">
              <div class="form-group">
                <label class="col-sm-2 control-label">Mobile Number</label>
                <div class="col-sm-6">
                <input name="mobile_number" class="form-control" placeholder="Enter Mobile" value="" type="text">
                <input name="user_id" id="user_id" class="form-control" placeholder="Enter Mobile" value="" style="" type="hidden">
                </div>
              </div>
          </div>
          <div class="box-footer">
            <input type="submit" class="btn btn-info " value="Update" id="add">
          </div>
            
        </form>
      </div>
      
    </div>

  </div>
</div>

    <style type="text/css">
      .dataTables_info, .dataTables_paginate {   
      display: none;
      }
    </style>

    
<script>
  $(function () {
    $("#example1").DataTable();

    $('.custom_pagination a').click(function(e){
      e.preventDefault();
      $('#search_frm').attr('action',$(this).attr('href'));
      $('#search_frm').submit();
    })

    $('.update_number').click(function(){
      $('#user_id').val($(this).data('id'));
    })
  });
</script>
<style type="text/css">
  .dataTables_length, .dataTables_filter{ display: none; }
</style>