
<div class="breadcrumb">
    <h1>Manual Reminder</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Manual Reminder</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></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">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-body">
                <form action="" id='frm-reminder' method="post" enctype="multipart/form-data">
                    <div class="row">
                      <div class="col-md-6 form-group mb-3">
                            <label for="clinic_data">Select Clinic <span class="asterisk">*</span></label>
                            <br/>
                           <select class="form-control" id="clinic_id" name="clinic_id" required="true">
                            <option value="">Select Client</option>
                            <?php if($allClinic && count($allClinic) > 0){ foreach($allClinic as $clinic){ ?>
                            <option value="<?php echo $clinic->clinic_id; ?>" ><?php echo $clinic->clinic_name; ?></option>
                            <?php } } ?>
                           </select>
                            <div class="invalid-tooltip" id="msg_clinic_data"></div>
                      </div>

                      <div class="col-md-6 form-group mb-3">
                            <label for="reminder_template_id">Select Template <span class="asterisk">*</span></label>
                            <br/>
                           <select class="form-control" id="reminder_template_id" name="reminder_template_id" >
                            <option value="">Select Template</option>
                            
                           </select>
                            <div class="invalid-tooltip" id="msg_reminder_template_id"></div>
                      </div>
                      
                      <div class="col-md-3 form-group mb-3" id="div_manual_remider_date">
                          <label for="manual_remider_date">Date <span class="asterisk">*</span></label>
                          <input type="date" class="form-control" id="manual_remider_date" name="manual_remider_date" >
                          <div class="invalid-tooltip" id="msg_manual_remider_date"></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>
 <div class='loader-bubble loader-bubble-secondary m-5' align="center" style="display: none;"></div>
 <div id="loader" class="loader" style="display: none;"></div>
<div id="btnid"></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: 400px !important;  
}

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

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

     futureDateDisable();

      $("#clinic_id").on('change',function(){
          var ClinicId = $("#clinic_id").val();
          $(".loader").show();
          $.ajax({
                    url: "manual_reminder_send.php?act=getremindertemplate&ClinicId="+ClinicId, 
                    type: "POST",
                    data: ({act:"getremindertemplate",clinic_id: ClinicId}),
                    success: function(data)
                    {  
                      $(".loader").hide();
                      $("#reminder_template_id").html(data);
                    }
               });
      });

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

          var clinic_id = $("#clinic_id").val();
          var reminder_template_id = $("#reminder_template_id").val();
          var manual_remider_date = $("#manual_remider_date").val();
        
          if(reminder_template_id == ''){
              $("#reminder_template_id").addClass('error');
              $("#reminder_template_id").focus();
              $("#msg_reminder_template_id").html('Please select template').show();
            return false;
          }
          else if(manual_remider_date == ''){

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

              $("#manual_remider_date").addClass('error');
              $("#manual_remider_date").focus();
              $("#msg_manual_remider_date").html('Please input date').show();
            return false;
          }else{

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

            $(".loader").show();
              
             $.ajax({
                url: "manual_reminder_send.php",
                type:'POST',
                data: ({act:"chkreminder",clinic_id: clinic_id,reminder_template_id:reminder_template_id,manual_remider_date:manual_remider_date}),
                success: function(data){
                  if(data == 'already'){
                      alredyreminderpopup(clinic_id,reminder_template_id,manual_remider_date);
                  }else if(data == 'firsttime'){
                      reminderdata(clinic_id,reminder_template_id,manual_remider_date);
                  }
                }
             });
          }
      });
   });


function futureDateDisable()
{
      var today = new Date().toISOString().split('T')[0];
      document.getElementsByName("manual_remider_date")[0].setAttribute('max', today);
}

function alredyreminderpopup(clinic_id,reminder_template_id,manual_remider_date)
{

  swal({
        title: 'Are you sure ?',
        text: "already send reminder notifiction!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#0CC27E',
        cancelButtonColor: '#FF586B',
        confirmButtonText: 'Yes, Send!',
        cancelButtonText: 'No, cancel!',
        confirmButtonClass: 'btn btn-success mr-5',
        cancelButtonClass: 'btn btn-danger',
        buttonsStyling: false
    }).then(function () {
        $.ajax({
          url: "manual_reminder_send.php",
          type:'POST',
          data: ({act:"load",clinic_id: clinic_id,reminder_template_id:reminder_template_id,manual_remider_date:manual_remider_date}),
          success: function(data)
          {    

              $("#status_msg").show();
              $("#status_msg").html("<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>"+data+"</div>");
              $("#status_msg_td").html(data.msg);
              hideMessage();
              $("#frm-reminder")[0].reset();
              $("#clinic_id").val("").trigger("change.select2");

              //window.location='manual_reminder_send.php';
          }
        });
    }, function (dismiss) {
      return false; 
    });
}
function reminderdata(clinic_id,reminder_template_id,manual_remider_date)
{
  $.ajax({
          url: "manual_reminder_send.php",
          type:'POST',
          data: ({act:"load",clinic_id: clinic_id,reminder_template_id:reminder_template_id,manual_remider_date:manual_remider_date}),
          success: function(data)
          {    

              $("#status_msg").show();
              $("#status_msg").html("<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>"+data+"</div>");
              $("#status_msg_td").html(data.msg);
              hideMessage();
              /*$("#clinic_id").val("");
              $("#reminder_template_id").val("");
              $("#manual_remider_date").val("");*/
              $("#frm-reminder")[0].reset();
              $("#clinic_id").val("").trigger("change.select2");
              //window.location='manual_reminder_send.php';
          }
        });
}


</script>
<?php //} ?>