<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(cconsultation_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 = 'clinic_schedulelist.php?act=delete&cconsultation_id='+cconsultation_id;
    }, function (dismiss) {
      return false; 
    });
}
	
function change_status(cconsultation_id,status){

  $(".loading_image").show();
  
  $.ajax({
    url: "clinic_schedulelist.php",
    data: 'act=change_status&cconsultation_id='+cconsultation_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_"+cconsultation_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+cconsultation_id+"','1')\" ><span class=\"badge badge-danger\">Inactive</span></a>");
        }else{
          $("#td_status_"+cconsultation_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+cconsultation_id+"','0')\" ><span class=\"badge badge-success\">Active</span></a>");
        }
    }
  });
}

function validate_all(act){
    var act = $("#act").val();
	if($(".check_class:checked").length == 0){

		$("#msg_select_action").html('Please select atleast one checkbox');
		  	$("#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?',
        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 == 'clinic_schedulelist.php')
// {
//     $module_id = $adminlogObj->getModuleId($filename);
// }
?>

<div class="breadcrumb">
    <h1><?php echo $clinicDetails->clinic_name ?> | Clinic Schedule</h1>
</div>
<div class="separator-breadcrumb border-top"></div>
<form action="" method="post" name="searchFrm" id="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">
                        <label for="cconsultation_speciality_id">Select Speciality</label>
                        <select class="form-control" id="cconsultation_speciality_id" name="cconsultation_speciality_id" required="true"  >
                            <option value="">Select Speciality</option>
                            <?php if($allspecialities && count($allspecialities) > 0){ foreach($allspecialities as $speciality){ ?>
                            <option value="<?php echo $speciality->speciality_id; ?>"><?php echo $speciality->speciality_name; ?></option>
                            <?php } } ?>
                        </select>
                    </div>
                    <div class="col-md-2 mt-3 mt-md-0">
                        <label for="cconsultation_speciality_name">Name</label>
                        <input type="text" class="form-control" name="cconsultation_speciality_name" id="cconsultation_speciality_name">
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0">
                        <label for="cconsultation_duration">Duration</label>
                        <input type="text" name="cconsultation_duration" id="cconsultation_duration" class="form-control">
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0">
                        <label for="cconsultation_status">Status</label>
                        <select class="form-control" name="cconsultation_status" id="cconsultation_status">
                            <option value="">Select Status</option>
                            <option value="1">Active</option>
                            <option value="0">Inactive</option>
                        </select>
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0">
                        <label for="">&nbsp;</label>
                        <button type="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" onclick="window.location.reload();" class="btn btn-primary btn-block">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>
          <!--<option value="delete_all">Delete 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="clinic_scheduleadd.php?clinic_id=<?php echo $_REQUEST['clinic_id'] ?>" class="btn btn-dark m-1"><i class="i-Add-User"></i> Add New</a>
            <a href="<?php echo SITE_URL ?><?php echo str_replace(" ", "-", strtolower($clinicDetails->clinic_name)) ?>/<?php echo $clinicDetails->clinic_unique_id ?>/c" target="_blank" class="btn btn-dark m-1">Preview</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>Provider/Day</th>
                                <th>Open Hours</th>
                                <th>Open/Block Slot</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                    </table>
                  </form>
                </div>
            </div>
        </div>
    </div>
</div>

<?php //if(isset($_REQUEST['cconsultation_speciality_id']) && $_REQUEST['cconsultation_speciality_id']!=""){ ?>
<script type="application/javascript">
   $(document).ready(function() {
     $('#list').DataTable({ 
          "ajax": "clinic_schedulelist.php?act=load&clinic_id="+<?php echo $_REQUEST['clinic_id'] ?>,
          "processing": true,
          "serverSide": true,
          "pageLength": 25,
                "aaSorting": [],
                "aoColumnDefs": [
                    { 'bSortable': false, 'aTargets': [0,2] }
                ],
          language: {
              "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
              "sEmptyTable" :  "No records found."
          }
          
      });

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

      //     var cconsultation_speciality_id = $("#cconsultation_speciality_id").val();
      //     var cconsultation_speciality_name = $("#cconsultation_speciality_name").val();
      //     var cconsultation_duration = $("#cconsultation_duration").val();
      //     var cconsultation_status = $("#cconsultation_status").val();
          
      //     $("#list").DataTable().destroy();
      //       $("#list").DataTable({

      //           "ajax":"clinic_schedulelist.php?act=load&cconsultation_speciality_id="+cconsultation_speciality_id+"&cconsultation_speciality_name="+cconsultation_speciality_name+"&cconsultation_duration="+cconsultation_duration+"&cconsultation_status="+cconsultation_status,
      //           "processing":true,
      //           "serverSide":true,
      //           "pageLength":25,
      //               "aaSorting":[],
      //               "aoColumnDefs":[
      //                   { 'bSortable':false, 'aTargets': [0] }
      //               ],
      //           language:{
      //               "processing":"<div class='loader-bubble loader-bubble-primary m-5'></div>",
      //               "sEmptyTable":"No records found",
      //           }
      //       });
      // });
    });
</script>
<?php //} ?>