<div id="page-wrapper">
<div class="container-fluid">
<div class="table widget">
    <div class="row">
                    <div class="col-lg-12">
                        <h3 class="page-header">
                            Agent List
                        </h3>
                         
                    </div>
                   <!--  <div class="col-lg-3 pull-left">  
                    <div class="form-group ">
                                  <select class="form-control " id="user_type" name="user_type" onchange="search_faq()" >
                                        <option value="" class="select">Select User Type</option>
                                        <option value="<?php echo ACTIVE ?>"  <?php if(ACTIVE == $user_type){?> selected <?php } ?>>Active Admins</option>
                                        <option value="<?php echo INACTIVE?>" <?php if(INACTIVE == $user_type){?> selected <?php } ?> >InActive Admins</option>
                                        
                                    </select>
                    </div>
                    </div>-->
                    <div class="col-lg-4 pull-left">   
                             <div class="input-group"> 
                             <input type="text" name="search" id="search" placeholder="Enter Name or Username" class="form-control" style="width:70%;" onchange="search_faq();">      
                                <button onclick="search_faq();" class="input-group-addon btn btn-primary" style="width:30%; height:34px; border:0;">Search</button>
                             </div>
                    </div>
                    <div class="col-lg-3 pull-right">
                      <a href="<?php echo site_url('user_form')?>" class="btn btn-primary pull-right" ><i class="fa fa-plus"></i> Add</a>
                    </div>
                    
    </div><br>

<!--<div class="col-lg-9"> -->
	<div class="widget">
    <div id="filters" style="margin-bottom:20px;">

 
		<div class="users" id="update-div">
			<table id="partner_details" class="display table table-striped table-bordered" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th></th>
                <th>Sl.No.</th>
                <th>Name</th>
            	  <th>Username</th> 
                 <th>Taluk</th>  	 
                  <th>Panchayath</th> 
                <th>Action</th>

      <!--          <th> <label>
   <input type="checkbox" id="selectall"/>
    <span class="custom-check"></span>
   Select All
  </label>  <button onclick="select_all_approve_partner();" class="input-group-addon btn btn-primary" style="width:35%; height:26px; border:0;">Approve</button></th>

               <!-- <th><input type="checkbox" id="selectall" value=""> &nbsp  <button onclick="select_all_approve_partner();" class="input-group-addon btn btn-primary" style="width:35%; height:26px; border:0;padding: 0px;">Approve</button></th>-->

            </tr>
        </thead>
    </table>
   
   		</div>
      
    </div>
</div>
</div>
</div>
</div>

<script>
	//call_datatable();
</script>
 <!-- Modal -->
  <!--<div id="pwdModal1" 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>
                                          <h3 class="text-center">PARTNER PROFILE</h3>
                                        </div>
                                        <div class="modal-body"> 
                                          
                                           <div id="test5" class="col-md-12" ></div>     



                                            
                                            <div class="clearfix"></div>
                                            <div id="sucess_verification1" role="alert">
                                            <p id="fail1"></p>
                                        </div>
                                </div>
                                    </div>
    </div>                                
  </div>-->
                            <div id="pwdModal" 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>
                                          <h3 class="modal-title text-center">Change Password</h3>
                                        </div>
                                        <div class="modal-body"> 
                                          <?php if ($this->session->flashdata('error')) { ?>
                                            <div class="alert alert-danger" role="alert"> <?php echo $this->session->flashdata('error'); ?></div>
                                          <?php } ?>
                                          <?php $attributes = array('id' => 'chng_pwd', 'name' => 'chng_pwd');
                                                echo form_open_multipart('', $attributes);
                                            ?>
                                                <div class="form-group">
                                                    <input type="password" class="form-control" name="password" maxlength="50"  id="password" required class="left"  placeholder="New Password" pattern=".{3,}" required title="Must have atleast 3 characters" onchange="this.setCustomValidity(this.validity.patternMismatch ? this.title : ''); if(this.checkValidity()) form.confirm_password.pattern = this.value;">
                                                </div>
                                                <div class="form-group">
                                                    <input type="password" class="form-control" name="confirm_pass"  maxlength="50" id="confirm_pass" class="left" required placeholder="Confirm New Password" required title="Both Passwords must be same" onchange="this.setCustomValidity(this.validity.patternMismatch ? this.title : '');">
                                                </div>
                                                <input type="hidden" name="uid" id="uid" value="" >
                                                  
                                                <div class="form-group text-center">
                                                    <input type="submit" name="submit" id="submit" value="SUBMIT" class="btn btn-primary">
                                                </div>
                                            </form>
                                            <div class="clearfix"></div>
                                            
                                            <p id="fail"></p>
                                        
                                </div>
                              </div>
                            </div>
</div>
<script src="<?php echo base_url()?>js/jquery.js"></script>
 <!-- Bootstrap Core JavaScript -->
<script src="<?php echo base_url()?>js/bootstrap.min.js"></script><link rel="stylesheet" href="<?php echo base_url();?>css/dataTables.bootstrap.min.css">
<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery-ui.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.dataTables.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>js/dataTables.bootstrap.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>js/pipeline.js"></script>
<script type="text/javascript">
$(document).ready(function(){

  search_faq();
  });

$(document).ready(function(){

  $("#chng_pwd").on('submit',(function(e){ 

         e.preventDefault();
         var response = $.ajax({
              url: "<?php echo site_url('user/change_password_admin')?>",
              type: "POST",
              data:  new FormData(this),
              contentType: false,
              cache: false,
              processData:false,
              async:false,
              success: function(data){           
               },
              error: function(){}             
           }).responseText;
        
     if(response == 'NO_UPDATION' ){
       //$("#sucess_verification").addClass('alert alert-danger');
       $("#fail").addClass('text-danger');
       $("#fail").html('Sorry, No updation.');
     }else if(response ==  'FAIL'){
     // $("#sucess_verification").addClass('alert alert-danger');
      $("#fail").addClass('text-danger');
       $("#fail").html('Sorry, Please try Again.');
     }else if(response == 'MIS_MATCH'){
      //$("#sucess_verification").addClass('alert alert-danger');
      $("#fail").addClass('text-danger');
       $("#fail").html('Sorry, Please specify your New Password Again.');
     }
        else{
    $("#password").val('');
    $("#confirm_pass").val('');
  //  $("#sucess_verification").removeClass('alert-danger');
 // $("#sucess_verification").addClass('alert-success');
  $("#fail").removeClass('text-danger');
  $("#fail").addClass('success');
  $("#fail").html('Password changed');
 }

        }));
  });
  
  function search_faq(){ 

    var user_type     =  $('#user_type').val();
    var search_value =  $('#search').val();
    $("#partner_details").dataTable().fnDestroy();
    call_datatable();
   
}
function call_datatable(){ 

    $('#partner_details').dataTable( {
        dom: 'T<"clear">lfrtip',
        bFilter: false,
        "processing": true,
        "serverSide": true,
        "stateSave": true,
        "oTableTools": {
          "aButtons": [
              {
                  "sExtends":    "collection",
                  "sButtonText": "Export"
              }
          ]
      },
        "ajax": $.fn.dataTable.pipeline( {
            url: "<?php echo site_url('user/get_users_list') ?>",// get the parameters of your datatables using $_GET in your controller. Needed in order to implement filter (Search) in datatable. 
            method: 'POST',
            pages: 5, // number of pages to cache
            data: function ( d ) { 
                //d.user_type = $('#user_type').val();
                d.search_text = $('#search').val();
              //  d.districts = $('#districts').val();
              //  d.searchQuery = $('#searchQuery').val();
             //   d.searchQuery1 = $('#searchQuery1').val();
               // d.skills = $('#skills').val();
               d.<?php echo $this->security->get_csrf_token_name(); ?> = '<?php echo $this->security->get_csrf_hash(); ?>';
                
            }
        } ),
        
        "aoColumnDefs": [  
        { "bVisible": false, "aTargets":[0]}, 
        { "aTargets":[1] ,"mData": null,
         "bSortable": false, "mRender": function (data) { return data[6];}},
         { "aTargets":[2] ,"mData": null,
         "bSortable": false, "mRender": function (data) { return data[2];}},
         { "aTargets":[3] ,"mData": null,
         "bSortable": false, "mRender": function (data) { return data[3];}},
          { "aTargets":[4] ,"mData": null,
         "bSortable": false, "mRender": function (data) { return data[4];}},
          { "aTargets":[5] ,"mData": null,
         "bSortable": false, "mRender": function (data) { return data[5];}},
        /* { "aTargets":[4] ,"mData": null,
         "bSortable": false, "mRender": function (data) { return data[3];}},
         { "aTargets":[5] ,"mData": null,
         "bSortable": false, "mRender": function (data) { return data[6];}},*/
      {
        "sWidth": "18%",
         "aTargets": [6],
         "mData": null,
         "bSortable": false,
         "mRender": function (data) { 
    
      return '<a class="btn btn-primary fa fa-pencil"  href="<?php echo site_url()?>edit_user/'+data[1]+'" Title="Edit" ></a>  <a class="btn btn-danger fa fa-trash-o" href="#" onClick="delete_user('+data[1]+');"  Title="Delete" ></i></a>  <a class="btn btn-default gear_ic" onclick="get_popup('+data[1]+')"   Title="Change Password" data-toggle="modal" data-target="#pwdModal"><i class="fa fa-gear"></i></a>';
           //return '<?php  /*$perm1 = ADD_PLANTING_METRIALS; if(in_array($perm1, $permiss)){ ?><a class="btn" href="<?php echo site_url("Farms/add_palanting_meterials/'+data[5]+'"); ?>"  Title="Add"><i class="fa fa-pencil"></i></a><?php } $perm1 = DELETEFARM; if(in_array($perm1, $permiss)){ ?><a class="btn" onclick="delete_farm('+data[5]+');" Title="Delete"><i class="fa fa-trash-o"></i></a><?php }*/ ?>';
        /*  if(data[7] == 1)
           {
           return '<a class="btn btn-primary fa fa-pencil"  href="<?php echo site_url()?>user/edit_user/'+data[5]+'"   onClick="user_edit('+data[5]+');"  Title="Edit" ></a>  <a class="btn btn-danger fa fa-trash-o" href="#" onClick="delete_user('+data[5]+');"  Title="Delete" return confirm("Are you sure you want to delete this user?");></i></a>  <a class="btn btn-default gear_ic" onclick="get_popup('+data[5]+')"   Title="Change Password" data-toggle="modal" data-target="#pwdModal"><i class="fa fa-gear"></i></a>';//<a class="btn btn-default gear_ic"   onclick="get_popup11('+data[5]+','+data[6]+')"   Title="User Profile" data-toggle="modal" data-target="#pwdModal11"  ><i class="fa fa-user" aria-hidden="true"></i></a>';//<a class="btn btn-success" href="<?php //echo site_url("Farms/farm_edit_profile_admin/'+data[6]+'");?>" Title="Edit" ><i class="fa fa-pencil"></i></a>
            }else
            {
             return '<a class="btn btn-primary fa fa-pencil"  href="<?php echo site_url()?>user/edit_user/'+data[5]+'"   onClick="user_edit('+data[5]+');"  Title="Edit" ></a>  <a class="btn btn-success fa fa-check" href="#" onClick="activate_user('+data[5]+');"  Title="Activate" return confirm("Are you sure you want to Activate this user?");></i></a>  <a class="btn btn-default gear_ic" onclick="get_popup('+data[5]+')"   Title="Change Password" data-toggle="modal" data-target="#pwdModal"><i class="fa fa-gear"></i></a>'; 
            }*/
     }
       }
    //   {
     //   "sWidth": "18%",
     //    "aTargets": [7],
    //     "mData": null,
    //     "bSortable": false,
     //    "mRender": function (data) { 
      // onClick="select_all_approve_partner('+data[5]+','+data[6]+');"
           //return '<?php  /*$perm1 = ADD_PLANTING_METRIALS; if(in_array($perm1, $permiss)){ ?><a class="btn" href="<?php echo site_url("Farms/add_palanting_meterials/'+data[5]+'"); ?>"  Title="Add"><i class="fa fa-pencil"></i></a><?php } $perm1 = DELETEFARM; if(in_array($perm1, $permiss)){ ?><a class="btn" onclick="delete_farm('+data[5]+');" Title="Delete"><i class="fa fa-trash-o"></i></a><?php }*/ ?>';
    //       return '<label ><input type="checkbox" class="case" name="customer_id[]"  onclick="clearvalue("'+data[5]+'")"  value="'+data[5]+'" > <span class="custom-check"></span></label>';//<a class="btn btn-success" href="<?php //echo site_url("Farms/farm_edit_profile_admin/'+data[6]+'");?>" Title="Edit" ><i class="fa fa-pencil"></i></a>
    // }
    //   }
     ],
    } ); 
}

/* 
function get_popup1(uid,rid){ 
         $.ajax({
            type: "POST",
            url: "<?php echo site_url('partner/view_partner_profile'); ?>",
            data: "user_id=" + uid +"&role_id=" + rid ,
            success: function (d)
            {
             // data=$.parseJSON(d)
              //$.each(data,function(i,e){
             //     alert(e.id);
             // });
       
              $('#test5').html(d);
            }
          });
}*/
function delete_user(id)
{
  var response = confirm("Press 'Ok' to delete the User");
  if (response == true) {
  $.ajax({
              type: "POST",
              url: "<?php echo site_url('user/delete_user'); ?>",
              data: "user_id="+id+"&<?php echo $this->security->get_csrf_token_name(); ?>=<?php echo $this->security->get_csrf_hash(); ?>",
              success: function (msg)
              {
                $("#partner_details").dataTable().fnDestroy();
                call_datatable();
              }
          });
  }
}
function activate_user(id)
{
  var response = confirm("Press 'Ok' to activate the User");
  if (response == true) {
  $.ajax({
              type: "POST",
              url: "<?php echo site_url('user/activate_user'); ?>",
              data: "user_id="+id+"&<?php echo $this->security->get_csrf_token_name(); ?>=<?php echo $this->security->get_csrf_hash(); ?>",
              success: function (msg)
              {
                $("#partner_details").dataTable().fnDestroy();
                call_datatable();
              }
          });
  }
}
function user_edit(id)
{
  
  $.ajax({
              type: "POST",
              url: "<?php echo site_url('user/edit_user'); ?>",
              data: "user_id="+id+"&<?php echo $this->security->get_csrf_token_name(); ?>=<?php echo $this->security->get_csrf_hash(); ?>",
              success: function (msg)
              { 
                // $("#partner_details").dataTable().fnDestroy();
                //call_datatable();
              }
          });
  
  
}
function get_popup(id){ 
        $("#fail").html('');
        $('#uid').val(id);
}




 </script>
