<?php
 $type =  $_REQUEST['type'];
  if($type == 'dependantdata')
  {
    $dependantId = $_REQUEST['dependants_id'];
  }else{
    $dependantId = '0';
  }
  
?>
<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>Clinic Patient</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Clinic Patient list</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></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_patient_id">
                        <label for="patient_id">Xcare Patient Id</label>
                        <?php if($dependantId != '' && $dependantId != '0'){ ?>
                        <input type="text" class="form-control" name="patient_id" id="patient_id" value="<?php echo $dependantId; ?>" disabled  />
                    <?php }else{ ?>
                        <input type="text" class="form-control" name="patient_id" id="patient_id"  />
                    <?php } ?>
                    </div>

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

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

                    <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_dependant_name">
                        <label for="dependant_name">Patient name</label>
                        <input type="text" class="form-control" name="dependant_name" id="dependant_name"  />
                    </div> -->

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


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

                    <div class="col-md-2  mt-3 mt-md-0" id="div_dependant_email">
                        <br/>
                        <label for="dependant_email">Patient 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">
                        <br/>
                        <label for="dependant_phone">Patient 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_campaign_status">
                        <br/>
                        <label for="campaign_status">Marketing</label>
                        <select id="campaign_status" name="campaign_status" class="form-control">
                            <option value="">Select Status</option>
                            <option value="1">On</option>
                            <option value="0">Off</option>
                        </select>
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0" id="div_notification_status">
                        <br/>
                        <label for="notification_status">Reminders</label>
                        <select id="notification_status" name="notification_status" class="form-control">
                            <option value="">Select Status</option>
                            <option value="1">On</option>
                            <option value="0">Off</option>
                        </select>
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0" id="div_admin_notification_status">
                        <br/>
                        <label for="admin_notification_status">Admin Notification</label>
                        <select id="admin_notification_status" name="admin_notification_status" class="form-control">
                            <option value="">Select Status</option>
                            <option value="1">On</option>
                            <option value="0">Off</option>
                        </select>
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0" id="div_chat_pin_status">
                        <br/>
                        <label for="chat_pin_status">Chat Pin</label>
                        <select id="chat_pin_status" name="chat_pin_status" class="form-control">
                            <option value="">Select Status</option>
                            <option value="1">On</option>
                            <option value="0">Off</option>
                        </select>
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0" id="div_chat_status">
                        <br/>
                        <label for="chat_status">Chat</label>
                        <select id="chat_status" name="chat_status" class="form-control">
                            <option value="">Select Status</option>
                            <option value="1">On</option>
                            <option value="0">Off</option>
                        </select>
                    </div>

                    <!-- <div class="col-md-2  mt-3 mt-md-0" id="div_chat_status">
                        <br/>
                    </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>
          
        </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="">
                    <input type="hidden" id="action_type" name="action_type" value="<?php echo $_REQUEST['type']; ?>">
                    <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>Clinic</th>
                                <!-- <th>Dependant</th> -->
                                <th>Patient</th>
                                <th>Status</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>

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

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

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

     var type_action = $("#action_type").val();
     
    if(type_action == 'dependantdata')
    {
      $('#list').DataTable( { 
          "ajax": "clinicpatientlist.php?act=load&app_type="+type_action+"&dependants_id="+<?php echo $dependantId; ?>,
          "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."
          }
          
      } );  
    }else{ 
     $('#list').DataTable( { 
          "ajax": "clinicpatientlist.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 patient_id = $("#patient_id").val();
        var patient_external_id = $("#patient_external_id").val();
        var clinic_id = $("#clinic_id").val();
        //var dependant_name = $("#dependant_name").val();
        var dependant_email = $("#dependant_email").val();
        var dependant_phone = $("#dependant_phone").val();
        var campaign_status = $("#campaign_status").val();
        var notification_status = $("#notification_status").val();
        var admin_notification_status = $("#admin_notification_status").val();
        var chat_pin_status = $("#chat_pin_status").val();
        var chat_status = $("#chat_status").val();
        var dependant_fname = $("#dependant_fname").val();
        var dependant_lname = $("#dependant_lname").val();
        var clinic_external_id = $("#clinic_external_id").val();

        $('#list').DataTable().destroy();
          $('#list').DataTable( { 
            "ajax": "clinicpatientlist.php?act=load&patient_id="+patient_id+"&clinic_id="+clinic_id+"&firstname="+dependant_fname+"&dependant_email="+dependant_email+"&dependant_phone="+dependant_phone+"&campaign_status="+campaign_status+"&notification_status="+notification_status+"&admin_notification_status="+admin_notification_status+"&chat_pin_status="+chat_pin_status+"&chat_status="+chat_status+"&patient_external_id="+patient_external_id+"&lastname="+dependant_lname+"&clinic_external_id="+clinic_external_id,
            "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>

