<div class="breadcrumb">
    <h1>PMS Providers</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>PMS Providers list</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>

<form action="" method="post" id="searchFrm">
<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_pmsprovider_id">
                        <label for="pmsprovider_id">PMSProvider Id</label>
                        <input type="text" class="form-control" name="pmsprovider_id" id="pmsprovider_id"  />
                    </div>

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


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


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

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_sikka_id">
                        <label for="sikka_id">Sikka Id</label>
                        <input type="text" class="form-control" name="sikka_id" id="sikka_id"  />
                    </div>

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

                    <div class="col-md-2  mt-3 mt-md-0">
                        <label for="practice_name">Practice Name</label>
                        <select class="form-control" name="practice_name" id="practice_name">
                            <option value="">Select Practice</option>
                            <?php
                                $practiceObj = new practice();
                                $fields  = array('practice_id','practice_name');
                                $data    = array('fields' => $fields);
                                $practiceDetails = $practiceObj->getAllRecords($data);

                                if($practiceDetails && count($practiceDetails) > 0 )
                                {
                                    foreach ($practiceDetails as $pkey => $practicedata) 
                                    { 
                                        if(isset($practicedata->practice_name) && $practicedata->practice_name != '')
                                        {
                                        ?>

                                            <option value="<?php echo $practicedata->practice_name; ?>"><?php echo $practicedata->practice_name; ?></option>
                                        <?php } ?>    
                                        
                                   <?php }
                                }
                            ?>
                        </select>
                        <!-- <input type="text" class="form-control" name="practice_name" id="practice_name" /> -->
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0">
                        <br/>
                        <label for="provider_type">Provider Type</label>
                        <!-- <input type="text" class="form-control" name="provider_type" id="provider_type" /> -->
                        <select class="form-control" name="provider_type" id="provider_type">
                            <option value="">Select Provider</option>
                            <?php
                                $pmsproviderObj = new pmsprovider();
                                $fields  = array('pmsProvider_id','pmsProvider_type');
                                $groupBy = array("pmsProvider_type");
                                $data    = array('fields' => $fields,"groupBy"=>$groupBy);
                                $pmsproviderDetails = $pmsproviderObj->getAllRecords($data);

                                if($pmsproviderDetails && count($pmsproviderDetails) > 0 )
                                {
                                    foreach ($pmsproviderDetails as $pkey => $pmsproviderdata) 
                                    { 
                                        if(isset($pmsproviderdata->pmsProvider_type) && $pmsproviderdata->pmsProvider_type != '')
                                        {
                                        ?>

                                            <option value="<?php echo $pmsproviderdata->pmsProvider_type; ?>"><?php echo $pmsproviderdata->pmsProvider_type; ?></option>
                                        <?php } ?>    
                                        
                                   <?php }
                                }
                            ?>
                        </select>
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0">
                        <br/>
                        <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('c.clinic_id','c.clinic_name');
                                $data    = array('fields' => $fields);
                                $clinicDetails = $clinicObj->getAllRecords($data);
                            ?>
                            
                            <?php if($clinicDetails && count($clinicDetails) > 0){ 
                                  foreach($clinicDetails as $clinicdata){ ?>
                                <option value="<?php echo $clinicdata->clinic_id; ?>"><?php echo $clinicdata->clinic_name; ?></option>
                                <?php } } ?>
                        </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($_REQUEST['successMsg']) && $_REQUEST['successMsg']!='') ? "<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>".$_REQUEST['successMsg']."</div>" : '' ; ?>
    <?php echo (isset($_REQUEST['failedMsg']) && $_REQUEST['failedMsg']!='') ? "<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>".$_REQUEST['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-6">
        <select id="act" name="act" class="form-control maction">
          <option value="">Multiple action</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="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>PMSProvider Id</th>
                                <th>Practice</th>
                                <th>Name</th>
                                <th>Type</th>
                                <th>Provider OfficeId</th>
                                <th>Clinic Detail</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: 150px !important;
}
</style>

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

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

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

    
     $('#list').DataTable( { 
          "ajax": "pmsProviderlist.php?act=load",
          "processing": true,
          "serverSide": true,
          /*"lengthMenu": [ [10, 25, 50, 100, 250, 300], [10, 25, 50, 100, 250, 300] ],*/
          "pageLength": 25,
                "aaSorting": [],
                "aoColumnDefs": [
                    { 'bSortable': false, 'aTargets':  [0] },
                    { 'bSortable': true, 'aTargets':  [1] },
                    { 'bSortable': true, 'aTargets': [2] },
                    { 'bSortable': true, 'aTargets':  [3] },
                    { 'bSortable': false, 'aTargets': [4] },
                    { 'bSortable': false, 'aTargets': [5] },
                    { 'bSortable': false, 'aTargets': [6] },
                    { 'bSortable': true, 'aTargets':  [7] },
                ],
          language: {
              "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
              "sEmptyTable" :  "No records found."
          }
          
      } );

     //$( "form" ).on( "submit", function(e) {
       $( "#searchFrm" ).on( "submit", function(e) {
        e.preventDefault();
        
        var sikka_id = $("#sikka_id").val();
        var provider_officeid = $("#provider_officeid").val();
        var practice_name = $("#practice_name").val();
        var provider_type = $("#provider_type").val();
        var clinic_id = $("#clinic_id").val();
        //var provider_fullname = $("#provider_fullname").val();
        var pmsprovider_id = $("#pmsprovider_id").val();
        var provider_firstname = $("#provider_firstname").val();
        var provider_lastname = $("#provider_lastname").val();
        
        $('#list').DataTable().destroy();
          $('#list').DataTable( { 
            "ajax": "pmsProviderlist.php?act=load&sikka_id="+sikka_id+"&provider_officeid="+provider_officeid+"&practice_name="+practice_name+"&provider_type="+provider_type+"&clinic_id="+clinic_id+"&firstname="+provider_firstname+"&pmsprovider_id="+pmsprovider_id+"&lastname="+provider_lastname,
            "processing": true,
            "serverSide": true,
            "pageLength": 25,
                  "aaSorting": [],
                  "aoColumnDefs": [
                      { 'bSortable': false, 'aTargets': [0] },
                      { 'bSortable': true, 'aTargets':  [1] },
                      { 'bSortable': true, 'aTargets': [2] },
                      { 'bSortable': true, 'aTargets':  [3] },
                      { 'bSortable': false, 'aTargets': [4] },
                      { 'bSortable': false, 'aTargets': [5] },
                      { 'bSortable': false, 'aTargets': [6] },
                      { 'bSortable': false, 'aTargets':  [7] },
                  ],
            language: {
                "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                "sEmptyTable" :  "No records found."
            }
            
        } );

      });
    });

    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';
        }

        //console.log(act);return false;     
        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();
            swal("Success!", "Successfully Deleted Data!", "success");
        }, function (dismiss) {
          return false; 
        });
    }
</script>