<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();
});

</script>



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

<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_referral_patientname">
                        <label for="patient_id_uniqueid">Xcare Patient Id</label>
                        <input type="text" class="form-control" name="patient_id_uniqueid" id="patient_id_uniqueid"  />
                    </div>

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

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

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


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

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_referral_type">
                        <label for="referral_type">Type</label>
                        <!-- <input type="text" class="form-control" name="referral_type" id="referral_type"  /> -->
                        <select id="referral_type" name="referral_type" class="form-control">
                                <option value="">Select Type</option>
                            <?php
                                $referralObj = new referral();
                                $fields = array('referral_id','referral_type');
                                $groupBy = array('referral_type');
                                $referralArg = array('fields'=>$fields,'groupBy'=>$groupBy);
                                $referraldata = $referralObj->getAllRecords($referralArg);
                                foreach($referraldata as $rkey => $referalvalue)
                                { ?>
                                    <option value="<?php echo $referalvalue->referral_type; ?>"><?php echo $referalvalue->referral_type; ?></option>

                               <?php }
                            ?>
                        </select>
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_referral_on">
                        <label for="referral_on">Referral On</label>
                        <input type="text" class="form-control" name="referral_on" id="referral_on"  />
                    </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-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</th>
                                <th>Patient Detail</th>
                                <th>Type</th>
                                <th>Referral On</th>
                                <th>Detail</th>
                            </tr>
                        </thead>
                    </table>
                  </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="application/javascript">
   $(document).ready(function() {
     $('#list').DataTable( { 
          "ajax": "referrallist.php?act=load",
          "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."
          }
          
      } );

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

        var referral_type = $("#referral_type").val();
        var referral_on = $("#referral_on").val();
        var patient_name = $("#patient_name").val();
        var patient_id_uniqueid = $("#patient_id_uniqueid").val();
        var patient_external_uniqueid = $("#patient_external_uniqueid").val();
        var patient_firstname = $("#patient_firstname").val();
        var patient_lastname = $("#patient_lastname").val();

        
        $('#list').DataTable().destroy();
          $('#list').DataTable( { 
            "ajax": "referrallist.php?act=load&referral_type="+referral_type+"&referral_on="+referral_on+"&firstname="+patient_firstname+"&patient_id_uniqueid="+patient_id_uniqueid+"&patient_external_uniqueid="+patient_external_uniqueid+"&lastname="+patient_lastname,
            "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>