
<div class="breadcrumb">
    <h1>Appointment Status :  </h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
    </ul>
</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="separator-breadcrumb border-top"></div>
<div class='loader-bubble loader-bubble-secondary m-5' align="center" style="display: none;"></div>
<div class="row">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-body">
                <div class="card-title mb-3">Appointment Status</div>
                <form action="" id='frm-appoinmentstatus' method="post" enctype="multipart/form-data">
                    <div class="row">
                      <div class="col-md-6 form-group mb-3">
                            <label for="clinic_id">Clinic <span class="asterisk">*</span></label>
                            <br/>
                           <select class="form-control" id="clinic_id" name="clinic_id" required="true">
                            <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 class="invalid-tooltip" id="msg_clinic_id"></div>
                      </div>
                      <!-- multiple name="msgtemplate_id[]" -->
                      <div class="col-md-6 form-group mb-3">
                            <label for="pmsstatus_id">Select PMS Status <span class="asterisk">*</span></label>
                            <br/>
                           <select class="form-control" id="pmsstatus_id" name="pmsstatus_id[]" multiple >
                          
                           </select>
                            <div class="invalid-tooltip" id="msg_pmsstatus_id"></div>
                      </div>
                      
                      <div class="col-md-6 form-group mb-3">
                            <label for="xcare_status_id">Select Xcare Status <span class="asterisk">*</span></label>
                            <br/>
                           <select class="form-control" id="xcare_status_id" name="xcare_status_id" >
                            <option value="">Select Xcare Status</option>
                            <option value="schedule">Schedule</option>
                            <option value="completed">Completed</option>
                            <option value="cancelled">Cancelled</option>
                            <option value="confirmed">Schedule(confirmed)</option>
                            <option value="floating">Schedule(floating)</option>
                            

                        </select>
                            <div class="invalid-tooltip" id="msg_xcare_status_id"></div>
                      </div>

                      <div class="col-md-12" id="div_app_submit">
                        <br/>
                          <input type="submit" class="btn btn-primary" id="submit" name="submit" value="Submit">
                      </div>
                      
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<script src="./assets/js/jquery.multiselect.js"></script>
<link rel="stylesheet" href="./assets/styles/css/jquery.multiselect.css">

<link rel="stylesheet" href="./assets/styles/css/jquery.toast.css">
<script src="./assets/js/jquery.toast.js"></script>

<link href="./assets/styles/css/select2.min.css" rel="stylesheet" />
<script src="./assets/js/select2.min.js"></script>

<script type="text/javascript">              

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

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

     $("#clinic_id").on('change',function(){
          
          var clinic_id = $("#clinic_id").val();
          $(".loader-bubble").show();
         
          $.ajax({
                    url: "appointment_statusupdate.php",
                    type: "POST",
                    data: ({act:"getpmsstatus",clinic_id: clinic_id}),
                    success: function(data)
                    {  
                      $(".loader-bubble").hide();
                      $("#pmsstatus_id").html(data);
                    }
               });
    });


    $( "#frm-appoinmentstatus" ).on( "submit", function(e) {
          
          e.preventDefault();

          var clinic_id = $("#clinic_id").val();
          var pmsstatus_id = $("#pmsstatus_id").val();
          var xcare_status_id = $("#xcare_status_id").val();
          

          if(pmsstatus_id == ''){
              $("#pmsstatus_id").addClass('error');
              $("#pmsstatus_id").focus();
              $("#msg_pmsstatus_id").html('Please select pms status').show();
            return false;
          }
          else if(xcare_status_id == ''){

              if(pmsstatus_id != '')
              {
                  $("#pmsstatus_id").removeClass('error');
                  $("#msg_pmsstatus_id").hide();
              }

              $("#xcare_status_id").addClass('error');
              $("#xcare_status_id").focus();
              $("#msg_xcare_status_id").html('Please select xcare status').show();
            return false;
          }else{

            if(pmsstatus_id != '')
            {
                $("#pmsstatus_id").removeClass('error');
                $("#msg_pmsstatus_id").hide();
            }

            $(".loader-bubble").show();
              
             $.ajax({
                url: "appointment_statusupdate.php",
                type:'POST',
                data: ({act:"updatestatus",clinic_id: clinic_id,pmsstatus_id:pmsstatus_id,xcare_status_id:xcare_status_id}),
                success: function(data){
                  if(data == 'Success')
                  { 
                    $(".loader-bubble").hide();
                    $.toast({
                              //heading: 'Positioning',
                              heading: '</em>',
                              text: "Successfully update status",
                              position: 'top-right',
                              stack: false,
                              showHideTransition: 'slide',
                              icon: 'success'
                          });
                    
                    
                    $("#clinic_id").val("").trigger("change.select2");
                    $("#pmsstatus_id").val("").trigger("change.select2");
                    $("#xcare_status_id").val('');
                    /*setTimeout(function(){
                        location.reload();
                      }, 3000); */
                    //window.location='clinic_setting.php?clinic_id='+fclinic_id; 
                  }
                }
             });
          }
    });

    
</script>