<script type="text/javascript">

	$(document).ready(function(){
		$("#checkall").click(function(){
			if(this.checked){
				$(".check_class").attr("checked",true);					
				$(".check_class").parent().addClass("checked");					
			}else{
				$(".check_class").attr("checked",false);					
				$(".check_class").parent().removeClass("checked");					
			}
		});
		$("#status_msg").hide();
		$("#alert_msg").hide();
            
	});

function delete_entry(admin_id){
  swal({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#0CC27E',
        cancelButtonColor: '#FF586B',
        confirmButtonText: 'Yes, delete it!',
        cancelButtonText: 'No, cancel!',
        confirmButtonClass: 'btn btn-success mr-5',
        cancelButtonClass: 'btn btn-danger',
        buttonsStyling: false
    }).then(function () {
        location.href = 'adminlist.php?act=delete&admin_id='+admin_id;
    }, function (dismiss) {
      return false; 
    });
}
	
function change_status(admin_id,status){

	$(".loading_image").show();
	
	$.ajax({
	  url: "adminlist.php",
	  data: 'act=change_status&admin_id='+admin_id+'&status='+status,
	  success: function(msg){
		  	$("#status_msg").show();
		  	$("#status_msg").html("<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>Status updated successfully...</div>");
		  	$("#status_msg_td").html(msg);
        hideMessage();
		  	if(status==0){
			  	$("#td_status_"+admin_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+admin_id+"','1')\" ><span class=\"badge badge-success\">Active</span></a>");
		  	}else{
			  	$("#td_status_"+admin_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+admin_id+"','0')\" ><span class=\"badge badge-danger\">Inactive</span></a>");
		  	}
	  }
	});
}

function validate_all(act){
    var act = $("#act").val();
    if(act==''){
        $("#alert_msg").show();
        $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Please select action to apply on selected records.</div>");
        return false;
    }else if($(".check_class:checked").length == 0){
  	$("#alert_msg").show();
  	$("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Please select atleast one checkbox.</div>");
		return false;
	}else{
	  	$("#alert_msg").hide();
	}
        
  if(act == 'delete_all'){
      var msg = 'delete';
  }else if(act == 'activate_all'){
      var msg = 'activate';
  }else{
      var msg = 'inactivate';
  }
  
    swal({
        title: 'Are you sure to '+act.replace("_"," ")+' ?',
        text: "You won't be able to revert this!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#0CC27E',
        cancelButtonColor: '#FF586B',
        confirmButtonText: 'Yes, '+msg+' it!',
        cancelButtonText: 'No, cancel!',
        confirmButtonClass: 'btn btn-success mr-5',
        cancelButtonClass: 'btn btn-danger',
        buttonsStyling: false
    }).then(function () {
        $("#action").val(act);
        $("#listFrm").submit();
    }, function (dismiss) {
      return false; 
    });
}
	
</script>
<?php
$filename=basename($_SERVER['SCRIPT_FILENAME']);
$adminlogObj = new admin_log();

if($filename == 'adminlist.php')
{
    $module_id = $adminlogObj->getModuleId($filename);
}
?>
<div class="breadcrumb">
    <h1>Point</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Point list</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>

<form action="" method="post" id="searchFrm" name="searchFrm">
<div class="row">
    <div class="col-lg-12 col-md-12">
        <div class="card mb-5">
            <div class="card-body">
                <div class="row row-xs">
                    
                    <div class="col-md-2 mt-3 mt-md-0"  id="div_clinic_id">
                        <label for="clinic_id">Clinic</label>
                        <select class="form-control" id="clinic_id" name="clinic_id">
                            <option value="">Select Clinic</option>
                            <?php
                                  $clinicObj = new clinic();
                                  $fields = array('clinic_id,clinic_name');
                                  $clinicArg = array("fields"=>$fields);
                                  $clinicdata = $clinicObj->getAllRecords($clinicArg);
                                  foreach ($clinicdata as $ckey => $clinic_value) 
                                    { 
                                      ?>
                                        <option value="<?php echo $clinic_value->clinic_id; ?>"><?php echo $clinic_value->clinic_name; ?></option>
                              <?php }
                            ?>
                        </select>
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_point_category">
                        <label for="pointmaster_category_id">Category</label>
                        <select class="form-control" id="pointmaster_category_id" name="pointmaster_category_id">
                            <option value="">Select Category</option>
                            <?php
                                  $catObj = new pointcategory();
                                  $fields = array('pointcategory_id,pointcategory_title');
                                  $catArg = array("fields"=>$fields);
                                  $catdata = $catObj->getAllRecords($catArg);
                                  foreach ($catdata as $ckey => $cat_value) 
                                    { 
                                      ?>
                                        <option value="<?php echo $cat_value->pointcategory_id; ?>"><?php echo $cat_value->pointcategory_title; ?></option>
                              <?php }
                            ?>
                        </select>
                    </div>
                    
                    <div class="col-md-2  mt-3 mt-md-0">
                        <label for="xcare_wise">xcare wise</label>
                        <select class="form-control" id="xcare_wise" name="xcare_wise">
                            <option value="">Select</option>
                            <option value="1">xcare wise</option>
                        </select>
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0">
                        
                        <label for="">&nbsp;</label>
                        <button type="submit" name="submit" class="btn btn-primary btn-block">Search</button>
                    </div>
                    <div class="col-md-2 mt-3 mt-md-0">
                        
                        <label for="">&nbsp;</label>
                        <button type="reset" name="reset" class="btn btn-primary btn-block" onClick="window.location.reload()">Reset</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</form>


<div class="row mb-4">
  <div class="col-md-6">
       <!--  <select id="act" name="act" class="form-control maction">
          <option value="">Multiple action</option>              
          <option value="activate_all">Activate selected</option>
          <option value="inactivate_all">De-activate selected</option>
          
        </select>
        <button type="button" class="btn btn-primary m-1" onclick="return validate_all();">Apply</button> -->
  </div>
  <div class="col-md-6 pull-right">
        <div class="button-group">
            <a href="pointadd.php" class="btn btn-dark m-1"><i class="i-Add-User"></i> Add New</a>
      </div>    
  </div>  
</div>
<div class="widget-body">
    <div class="portlet-body">
                        
    <?php echo (isset($successMsg) && $successMsg!='') ? "<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($successMsg)."</div>" : '' ; ?>
    <?php echo (isset($failedMsg) && $failedMsg!='') ? "<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($failedMsg)."</div>" : '' ?>
   
    <div id="status_msg" style="display: none;"><div class="alert alert-success"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>
    <div id="alert_msg" style="display: none;"><div class="alert alert-danger"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>

    </div>
</div>

<div class="row mb-4">
  <div class="col-md-12 mb-4">
    <div class="card text-left">

      <div class="card-body">
          <div class="table-responsive">
            <form id="listFrm" name="listFrm" action="" method="post">       
              <input type="hidden" id="action" name="action" value="">
              <table id="list" class="display table table-striped table-bordered" style="width:100%">
                  <thead>
                    <tr>
                      <th class="center"><input type="checkbox" name="checkall" id="checkall"></th>
                      <th>Title</th>
                      <th>Clinic</th>
                      <th>Code</th>
                      <th>Sender</th>
                      <th>Receiver</th>
                      <th>Total points</th>
                      <th>Unit Point</th>
                      <th>Status</th>
                      <th>Created at</th>
                      <th>Inactive at</th>
                      <!-- <th>Action</th> -->
                    </tr>
                  </thead>
              </table>
            </form>
          </div>
      </div>
    </div>
  </div>
</div>
<script type="application/javascript">
   $(document).ready(function() {
        $('#list').DataTable( {
          "ajax": "pointlist.php?act=load",
          "processing": true,
          "serverSide": true,
          "pageLength": 25,
                "aaSorting": [],
                "aoColumnDefs": [
                    { 'bSortable': false, 'aTargets': [0] },
                    { 'bSortable': false, 'aTargets': [1] },
                    { 'bSortable': false, 'aTargets': [2] },
                    { 'bSortable': false, 'aTargets': [3] },
                    { 'bSortable': false, 'aTargets': [4] },
                    { 'bSortable': false, 'aTargets': [5] },
                    { 'bSortable': false, 'aTargets': [6] },
                    { 'bSortable': false, 'aTargets': [7] },
                    { 'bSortable': false, 'aTargets': [8] },
                    
                ],
          language: {
              "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
              "sEmptyTable" :  "No records found."
          }
          
      } );

      $("#xcare_wise").on("change", function() {
            var xcare_value = $(this).val();

            if (xcare_value === '1' || xcare_value !== '') {
                $("#clinic_id").val('').trigger('change');
                $("#pointmaster_category_id").val('').trigger('change');
            }
            
        });

      $( "#searchFrm" ).on( "submit", function(e) {
        e.preventDefault();

        var clinic_id = $("#clinic_id").val();
        var pointmaster_category_id = $("#pointmaster_category_id").val();
        var xcare_wise = $("#xcare_wise").val();
        
        $('#list').DataTable().destroy();
          $('#list').DataTable( { 
            "ajax": "pointlist.php?act=load&clinic_id="+clinic_id+"&pointmaster_category_id="+pointmaster_category_id+"&xcare_wise="+xcare_wise,
            "processing": true,
            "serverSide": true,
            "pageLength": 25,
            "aaSorting": [],
            "language": {
                "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                "sEmptyTable" :  "No records found."
            }
            
        } );
      });  
    });
</script>