<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){
  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;
    }, 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,
	  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_"+doctor_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+doctor_id+"','1')\" ><span class=\"badge badge-success\">Active</span></a>");
                }else{
                    $("#td_status_"+doctor_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+doctor_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 == 'dependantlist.php')
{
    $module_id = $adminlogObj->getModuleId($filename);
}
?>

<div class="breadcrumb">
    <!-- <h1>Dependant</h1> -->
    <h1>Patients</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <!-- <li>Dependant list</li> -->
        <li>Patient 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>

<!-- <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>  -->

<form action="" method="post">
<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_dependant_id">
                        <label for="dependant_id">Xcare Patient Id</label>
                        <input type="text" class="form-control" name="dependant_id" id="dependant_id"  />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_dependant_unique_id">
                        <label for="dependant_unique_id">Patient External Id</label>
                        <input type="text" class="form-control" name="dependant_unique_id" id="dependant_unique_id"  />
                    </div>

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

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_dependant_firstname">
                        <label for="dependant_firstname">First Name</label>
                        <input type="text" class="form-control" name="dependant_firstname" id="dependant_firstname"  />
                    </div>


                    <div class="col-md-2 mt-3 mt-md-0"  id="div_dependant_lastname">
                        <label for="dependant_lastname">Last Name</label>
                        <input type="text" class="form-control" name="dependant_lastname" id="dependant_lastname"  />
                    </div>

                    <!-- <div class="col-md-2 mt-3 mt-md-0"  id="div_dependant_fullname">
                        <label for="dependant_patientname">Patient Name</label>
                        <input type="text" class="form-control" name="dependant_patientname" id="dependant_patientname"  />
                    </div> -->

                    

                    <!-- <div class="col-md-2 mt-3 mt-md-0"  id="div_dependant_gender">
                        <label for="dependant_gender">Gender</label>
                        <select class="form-control" id="dependant_gender" name="dependant_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">
                        <label for="dependant_email">Email</label>
                        <input type="text" class="form-control" name="dependant_email" id="dependant_email" />
                    </div>

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


                    <div class="col-md-2  mt-3 mt-md-0" id="div_dependant_dob">
                        <br/>
                        <label for="dependant_dob">DOB</label>
                        <input type="date" class="form-control" name="dependant_dob" id="dependant_dob" />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0" id="div_guarantor_id">
                    <br/>
                      <label for="guarantor_id">Guarantor External Id</label>
                      <input type="text" class="form-control" name="guarantor_id" id="guarantor_id" />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0" id="div_login_id">
                    <br/>
                      <label for="login_id">Xcare SignIn External Id</label>
                      <input type="text" class="form-control" name="login_id" id="login_id" />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0" id="div_loyalty_member">
                    <br/>
                      <label for="loyalty_member">Loyalty Member</label>
                      <select name="loyalty_member" id="loyalty_member" class="form-control">
                            <option value="">Select</option>
                            <option value="Yes">Yes</option>
                      </select>
                    </div>

                    <!-- <div class="col-md-2  mt-3 mt-md-0" id="div_dependant_contact_method">
                        <br/>
                        <label for="dependant_contact_method">Contact Method</label>
                        <select class="form-control" id="dependant_contact_method" name="dependant_contact_method">
                            <option value="">Select Contact Method</option>
                            <option value="email">Email</option>
                            <option value="text">Text</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="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>Patient Info</th>
                                <th>DOB/Gender/Relation</th>
                                <th>Contact Perference</th>
                                <th>Sign In Info</th>
                                <th>Guarantor Info</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                    </table>
                  </form>
                </div>
            </div>
        </div>
    </div>
</div>
 
<script type="application/javascript">
   $(document).ready(function() {
     $('#list').DataTable( { 
          "ajax": "dependantlist.php?act=load",
          "processing": true,
          "serverSide": true,
          "pageLength": 25,
                "aaSorting": [],
                "aoColumnDefs": [
                    { 'bSortable': false, 'aTargets': [2,4] }
                ],
          language: {
              "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                    "sEmptyTable" :  "No records found."
          }
          
      } );

      $( "form" ).on( "submit", function(e) {
        e.preventDefault();
        
        //var dependant_fullname = $("#dependant_fullname").val();

        var dependant_firstname = $("#dependant_firstname").val();
        var dependant_lastname = $("#dependant_lastname").val();
        var dependant_unique_id = $("#dependant_unique_id").val();
        //var dependant_gender = $("#dependant_gender").val();
        var dependant_email = $("#dependant_email").val();
        var dependant_phone = $("#dependant_phone").val();
        var dependant_dob = $("#dependant_dob").val();
        //var contact_method = $("#dependant_contact_method").val();
        //var dependant_patientname = $("#dependant_patientname").val();
        var dependant_id = $("#dependant_id").val();
        var guarantor_id = $("#guarantor_id").val();
        var login_id = $("#login_id").val();
        var loyalty_member = $("#loyalty_member").val();

        $('#list').DataTable().destroy();
          $('#list').DataTable( { 
            "ajax": "dependantlist.php?act=load&firstname="+dependant_firstname+"&lastname="+dependant_lastname+"&dependant_unique_id="+dependant_unique_id+"&dependant_email="+dependant_email+"&dependant_phone="+dependant_phone+"&dependant_dob="+dependant_dob+"&dependant_id="+dependant_id+"&guarantor_id="+guarantor_id+"&login_id="+login_id+"&loyalty_member="+loyalty_member,
            "processing": true,
            "serverSide": true,
            "pageLength": 25,
                  "aaSorting": [],
                  "aoColumnDefs": [
                      { 'bSortable': false, 'aTargets': [2,4] }
                  ],
            language: {
                "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                "sEmptyTable" :  "No records found."
            }
            
        } );

      });
    });
</script>