
<div class="breadcrumb">
    <h1>Log List</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Log 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">
                        <label for="clinic_id">Select Clinic</label>
                        <select class="form-control" id="clinic_id" name="clinic_id" required="true">
                            <option value="">Select clinic</option>
                            <?php
                             if($allpractices && count($allpractices)>0){
                              foreach ($allpractices as $key => $practice) {?>
                                <option value="<?php echo $practice->clinic_id ?>"><?php echo $practice->clinic_name ?></option>
                              <?php }
                             }
                            ?>
                        </select>
                    </div>
                    <div class="col-md-2  mt-3 mt-md-0">
                        <label for="log_id">Select Log</label>
                        <select class="form-control" id="log_id" name="log_id" required="true">
                            <option value="">Select Log</option>
                            <option value="1" <?php //echo (isset($_REQUEST['log_id']) && $_REQUEST['log_id'] == '1') ? "selected='selected'" : ""; ?> >syncAppointment</option>
                            <option value="2" <?php //echo (isset($_REQUEST['log_id']) && $_REQUEST['log_id'] == '2') ? "selected='selected'" : ""; ?>>syncPatient</option>
                            <option value="3" <?php //echo (isset($_REQUEST['log_id']) && $_REQUEST['log_id'] == '3') ? "selected='selected'" : ""; ?>>syncGuarantor</option>
                        </select>
                    </div>
                    <div class="col-md-2  mt-3 mt-md-0">
                        <label for="log_file_name">Select File</label>
                        <select class="form-control" id="log_file_name" name="log_file_name" required="true">
                            <option value="">Select File</option>
                        </select>
                    </div>
                    <div class="col-md-2  mt-3 mt-md-0" id="div_log_search_data">
                        <label for="log_search_data">Search data</label>
                        <!-- <input type="text" class="form-control" name="log_search_data" id="log_search_data" required="true"> -->
                        <select id="log_search_data" name="log_search_data" class="form-control">
                            <option>Search Data</option>
                        </select>
                    </div>
                    <div class="col-md-2  mt-3 mt-md-0" id="div_search_value_data" style="display:none;">
                        <label for="search_value_data">Search Value</label>
                        <input type="text" class="form-control" name="search_value_data" id="search_value_data" >
                    </div>
                    <!-- <div class="col-md-2  mt-3 mt-md-0" id="div_search_date_data">
                        <label for="search_date_data">Search Date</label>
                        <input type="date" class="form-control" name="search_date_data" id="search_date_data">
                    </div>
                    <div class="col-md-2  mt-3 mt-md-0" id="div_search_time_data">
                        <label for="search_time_data">Search Time</label>
                        <input type="time" class="form-control" name="search_time_data" id="search_time_data">
                        <div class="invalid-tooltip" id="msg_search_time_data"></div>
                    </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" 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>Sr.No</th>
                                <th>Log Data</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() {

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

        $('#log_id').on('change', function() {
            //alert( this.value );
            var logId = this.value;
            var clinic_id = $("#clinic_id").val();
            if(logId != '' && clinic_id!="")
            {
                $('#div_search_value_data').hide();
                $.ajax({
                      url: "loglist.php",
                      data: { act:"logfileget",
                            logId:logId,clinic_id:clinic_id },
                      method: 'POST',
                      success: function(data)
                      {
                          $("#log_file_name").html(data);
                          if(logId == '1')
                          {
                            $('#log_search_data').html('');
                            $('#log_search_data').append(`<option value="Added">
                                           Added
                                      </option>
                                      <option value="Updated">
                                           Updated
                                      </option>
                                      <option value="Deleted">
                                           Deleted
                                      </option>
                                      <option value="Appointemnt">
                                           Appointemnt
                                      </option>
                                      <option value="Provider">
                                           Provider
                                      </option>
                                      <option value="other">
                                           Other
                                      </option>`);
                          }
                          if(logId == '2')
                          {
                            $('#log_search_data').html('');
                            $('#log_search_data').append(`<option value="Added">
                                           Added
                                      </option>
                                      <option value="Updated">
                                           Updated
                                      </option>
                                      <option value="Deleted">
                                           Deleted
                                      </option>
                                      <option value="Patients">
                                           Patients
                                      </option>
                                      <option value="Guarantor">
                                           Guarantor
                                      </option>
                                      <option value="other">
                                           Other
                                      </option>`);
                          }
                          if(logId == '3')
                          {
                            $('#log_search_data').html('');
                            $('#log_search_data').append(`<option value="Added">
                                           Added
                                      </option>
                                      <option value="Updated">
                                           Updated
                                      </option>
                                      <option value="Deleted">
                                           Deleted
                                      </option>
                                      <option value="Guarantors">
                                           Guarantors
                                      </option>
                                      <option value="Data Inserted">
                                           Data Inserted
                                      </option>
                                      <option value="other">
                                           Other
                                      </option>`);
                          }
                      }
                });
            }else{
                $("#log_file_name").html('');
                $('#log_search_data').html('');
            }
        });


        $('#log_search_data').on('change',function(){
            var logsearchdata = $("#log_search_data").val();
            if(logsearchdata == 'other')
            {
                $('#search_value_data').val('');
                $('#div_search_value_data').show();
            }else{
                $('#search_value_data').val('');
                $('#div_search_value_data').hide();
            }
        });
    
        /*$("#log_file_name").on('change',function()
        {
            var logfilename =  $("#log_file_name").val();
            $("#search_date_data").val(logfilename);
        })*/

        $( "form" ).on( "submit", function(e) 
        {
            e.preventDefault();
            var log_id = $("#log_id").val();
            var clinic_id = $("#clinic_id").val();
            var logfileName = $("#log_file_name").val();
            var searchvaluedata = $("#search_value_data").val();
            var searchdatedata = $("#search_date_data").val();
            var searchtimedata = $("#search_time_data").val();
            var log_search_data = $("#log_search_data").val();

            /*if(searchdatedata !== '' && searchtimedata === '')
            {
                //$("#msg_search_time_data").show();
                $("#search_time_data").addClass('error');
                $("#search_time_data").focus();
                $("#msg_search_time_data").html("Please Select Time").show();
                return false;
            }else{
                $("#search_time_data").removeClass('error');
                 $("#msg_search_time_data").hide();
            }*/

            $('#list').DataTable().destroy();
              $('#list').DataTable( { 
                "ajax": {
                "url": "loglist.php",
                "type": "POST",
                "data": {
                    "act":"load",
                    "log_id": log_id,
                    "logfilename":logfileName,
                    "searchvaluedata":searchvaluedata,
                    "searchdatedata":searchdatedata,
                    "searchtimedata":searchtimedata,
                    "log_search_data":log_search_data,
                    "clinic_id":clinic_id
                    }
                },
                "processing": true,
                "serverSide": true,
                "bFilter": false,
                //"bPaginate": false,
                "pageLength": 25,
                      "aaSorting": [],
                      "aoColumnDefs": [
                          { 'bSortable': false, 'aTargets': [] }
                      ],
                language: {
                    "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                    "sEmptyTable" :  "No records found."
                }
            });
        });
    
} ); 
</script>