<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(doctor_id,clinic_id){
    console.log(clinic_id);
    var doctor_clinic = clinic_id;
    //var doctor_clinic = $('#doctor_clinic').val();
    /*if(doctor_clinic==''){
        $("#alert_msg").show();
        $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Please select atleast one clinic.</div>");
        return false;
    }else{
        $("#alert_msg").hide();*/

        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 = 'doctorlist.php?act=delete&doctor_id='+doctor_id;
            $.ajax({
              url: "doctorlist.php",
              type:'POST',
              data: 'act=delete&doctor_id='+doctor_id+'&doctor_clinic='+doctor_clinic,  
              success: function(data){
                        $.toast({
                            //heading: 'Positioning',
                            heading: '</em>',
                            text: data,
                            position: 'top-right',
                            stack: false,
                            showHideTransition: 'slide',
                            icon: 'success'
                        });
                        setTimeout(function(){
                          location.reload();
                        }, 1000);
              }
            });
        }, function (dismiss) {
          return false; 
        });
    //}
  
}
	
function change_status(doctor_id,status){
	$(".loading_image").show();
	$.ajax({
	  url: "doctorlist.php",
	  data: 'act=change_status&doctor_id='+doctor_id+'&status='+status,
    dataType: 'json',
    cache: false,
	  success: function(data){
                $("#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(data.msg);
                hideMessage();
                if(data.dstatus=='1')
                {
                  $("#td_status_"+data.doctor_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+data.doctor_id+"','0')\" ><span class=\"badge badge-success\">Active</span></a>");
                }else
                {
                    $("#td_status_"+data.doctor_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+data.doctor_id+"','1')\" ><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 == 'doctorlist.php')
{
    $module_id = $adminlogObj->getModuleId($filename);
}
?>

<div class="breadcrumb">
    <h1>Provider</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Provider list</li>
        <li><a href="<?php echo SITE_URL."x-admin/adminloglist.php?module_id=$module_id" ?>" target="_blank">Log</a></li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>

<form action="" method="post" id="frmsearch">
<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_doctor_id">
                        <label for="doctor_id">Xcare Provider Id</label>
                        <input type="text" class="form-control" name="doctor_id" id="doctor_id"  />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_doctor_unique_id">
                        <label for="doctor_unique_id">Provider External Id(Global/Clinic)</label>
                        <input type="text" class="form-control" name="doctor_unique_id" id="doctor_unique_id"  />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_doctor_fullname">
                        <label for="doctor_fullname">Provider Full Name</label>
                        <input type="text" class="form-control" name="doctor_fullname" id="doctor_fullname"  />
                    </div>

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

                    <div class="col-md-2 mt-3 mt-md-0" id="div_doctor_phone" >
                      <label for="doctor_phone">Provider Phone</label>
                      <input type="text" class="form-control" name="doctor_phone" id="doctor_phone" />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0" id="div_doctor_Licence_no" >
                      <label for="doctor_licence_no">Provider Licence No</label>
                      <input type="text" class="form-control" name="doctor_licence_no" id="doctor_licence_no" />
                    </div>

                    <!-- <div class="col-md-2 mt-3 mt-md-0" id="div_doctor_website">
                      <br/>
                      <label for="doctor_website">Website</label>
                      <input type="text" class="form-control" name="doctor_website" id="doctor_website" />
                    </div> -->

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_doctor_gender">
                        <br/>
                        <label for="doctor_gender">Gender</label>
                        <select class="form-control" id="doctor_gender" name="doctor_gender">
                            <option value="">Select Gender</option>
                            <option value="Male">Male</option>
                            <option value="Female">Female</option>
                        </select>
                        
                    </div>

                    <!-- <div class="col-md-2 mt-3 mt-md-0" id="div_doctor_sikka_code" >
                      <br/>
                      <label for="doctor_sikka_code">Sikka Code</label>
                      <input type="text" class="form-control" name="doctor_sikka_code" id="doctor_sikka_code" />
                    </div> -->

                    <div class="col-md-2  mt-3 mt-md-0" id="div_doctor_specality">
                      <br/>
                        <label for="doctor_specality">Specality</label>
                        <select class="form-control" id="doctor_specality" name="doctor_specality">
                            <option value="">Select Specality</option>
                            <?php
                                  $specality_obj = new speciality;
                                  $fields = array('speciality_id,speciality_name');
                                  $specalityArg = array("fields"=>$fields);
                                  $specialitydata = $specality_obj->getAllRecords($specalityArg);
                                  foreach ($specialitydata as $skey => $specality_value) 
                                    { ?>
                                        <option value="<?php echo $specality_value->speciality_id; ?>"><?php echo $specality_value->speciality_name; ?></option>
                              <?php }
                            ?>

                        </select>
                    </div> 

                    <!-- <div class="col-md-2  mt-3 mt-md-0" id="div_doctor_language">
                      <br/>
                        <label for="doctor_language">Language</label>
                        <select class="form-control" id="doctor_language" name="doctor_language">
                            <option value="">Select Language</option>
                            <?php
                                  $languageobj = new language;
                                  $fields = array('language_id,language_name');
                                  $languageArg = array("fields"=>$fields);
                                  $languagedata = $languageobj->getAllRecords($languageArg);
                                  foreach ($languagedata as $skey => $language_value) 
                                    { ?>
                                        <option value="<?php echo $language_value->language_id; ?>"><?php echo $language_value->language_name; ?></option>
                              <?php }
                            ?>

                        </select>
                    </div> -->

                    <div class="col-md-2  mt-3 mt-md-0" id="div_doctor_clinic">
                      <br/>
                        <label for="doctor_clinic">Clinic</label>
                        <select class="form-control" id="doctor_clinic" name="doctor_clinic">
                            <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_doctor_date">
                      <br/>
                      <label for="doctor_date">Provider Created Date</label>
                      <input type="date" class="form-control" name="doctor_date" id="doctor_date" />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0" id="div_doctor_status">
                      <br/>
                      <label for="doctor_status">Status</label>
                      <select id="doctor_status" name="doctor_status" class="form-control">
                          <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">
                       <br/>
                        <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">
                       <br/>
                        <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>
          <!-- <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="doctoradd.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>ID/Provider External Id(s)</th>
                                <!-- <th>Provider External Id(s)</th> -->
                                <th>Associated Clinic detail</th>
                                <th>Provider Detail</th>
                                <!-- <th>Detail</th> -->
                                <th>App Sign-In Detail</th>
                                <th>Status</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                    </table>
                  </form>
                </div>
            </div>
        </div>
    </div>
</div>

<link href="./assets/styles/css/select2.min.css" rel="stylesheet" />
<script src="./assets/js/select2.min.js"></script>

<link rel="stylesheet" href="./assets/styles/css/jquery.toast.css">
<script src="./assets/js/jquery.toast.js"></script>

<style type="text/css">
.select2 {
  width: 160px !important;
}
</style>

<script type="application/javascript">
   $(document).ready(function() {

    $("#doctor_clinic").select2({
        tags: true
     });

     $('#list').DataTable( { 
          "ajax": "doctorlist.php?act=load",
          "processing": true,
          "serverSide": true,
          "pageLength": 25,
                "aaSorting": [],
                "aoColumnDefs": [
                    { 'bSortable': false, 'aTargets': [0,5] }
                ],
          language: {
              "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                    "sEmptyTable" :  "No records found."
          }
          
      } );

      $( "#frmsearch" ).on( "submit", function(e) {
        e.preventDefault();
        
        var doctor_fullname = $("#doctor_fullname").val();
        var doctor_unique_id = $("#doctor_unique_id").val();
        var docotr_email = $("#docotr_email").val();
        var doctor_phone = $("#doctor_phone").val();
        var doctor_specality = $("#doctor_specality").val();
        var doctor_licenceno = $("#doctor_licence_no").val();
        //var doctor_language = $("#doctor_language").val();
        var doctor_gender = $("#doctor_gender").val();
        var doctor_clinic = $('#doctor_clinic').val();
        //var doctor_website = $('#doctor_website').val();
        var doctor_id = $("#doctor_id").val();
        var doctor_date = $("#doctor_date").val();
        var doctor_status = $("#doctor_status").val();
        //"&doctor_website="+doctor_website
        //"&doctor_language="+doctor_language+
        $('#list').DataTable().destroy();
          $('#list').DataTable( { 
            "ajax": "doctorlist.php?act=load&fullname="+doctor_fullname+"&doctor_unique_id="+doctor_unique_id+"&doctor_gender="+doctor_gender+"&docotr_email="+docotr_email+"&doctor_phone="+doctor_phone+"&doctor_specality="+doctor_specality+"&doctor_licenceno="+doctor_licenceno+"&doctor_clinic="+doctor_clinic+"&doctor_id="+doctor_id+"&doctor_date="+doctor_date+"&doctor_status="+doctor_status,
            "processing": true,
            "serverSide": true,
            "pageLength": 25,
                  "aaSorting": [],
                  "aoColumnDefs": [
                      { 'bSortable': false, 'aTargets': [0,5] }
                  ],
            language: {
                "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                "sEmptyTable" :  "No records found."
            }
            
        } );

      });
    });
</script>

