<!-- Page Heading -->
          <div class="d-sm-flex align-items-center justify-content-between mb-4">
            <h1 class="h3 mb-0 text-gray-800">Blast WhatsApp</h1>
          </div>
          <div class="row">
            <div class="card col-md-6">
              <div class="card-body">
                <form id="send_um">
                  <div class="row">
                    <div class="col-md-6">
                      <div class="form-group">
                        <label for="um">Pilih Unit Misioner</label>
                        <select class="form-control" id="um" name="um">
                        </select>
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-md-12">
                      <div class="form-group">
                        <label for="msg">Pesan</label>
                        <textarea class="form-control" id="msg" name="msg" rows="3"></textarea>
                      </div>
                    </div>
                  </div>
                  <button type="button" id="btn-send_um" class="btn btn-success btn-lg btn-block">Kirim Whatsapp</button>
                </form>
              </div>
            </div>
            <div class="card col-md-6">
              <div class="card-body">
                <form id="send_user">
                  <div class="row">
                    <div class="col-md-6">
                      <div class="form-group">
                        <label for="exampleFormControlSelect1">Pilih User</label>
                        <select class="form-control" id="users" name="user">
                        </select>
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-md-12">
                      <div class="form-group">
                        <label for="msg2">Pesan</label>
                        <textarea class="form-control" id="msg2" name="msg" rows="3"></textarea>
                      </div>
                    </div>
                  </div>
                  <button type="button" id="btn-send_user" class="btn btn-primary btn-lg btn-block">Kirim Whatsapp</button>
                </form>
              </div>
            </div>
          </div>

              
          <script type="text/javascript">
            $(document).ready(function(){
              var base_url = "<?=base_url()?>";
              $('#btn-send_um').click(function() {
                var formData = new FormData($('#send_um')[0]);// yourForm: form selector        
                $.ajax({
                    type: "POST",
                    url: base_url+"Whatsapp/send_um",// where you wanna post
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType:'json',
                    error: function(jqXHR, textStatus, errorMessage) {
                        console.log(jqXHR); // Optional
                        alert(errorMessage)
                    },
                    success: function(data) {
                        if(data == true){
                            Command: toastr["success"]("Anda berhasil mengirim pesan", "Berhasil");
                            // getcontens('page/file_pka');
                        }else{
                            Command: toastr["error"]("Simpan error, data tidak berhasil mengirim pesan", "Error");
                        }
                      }
                });


              });
              $('#btn-send_user').click(function() {
                var formData = new FormData($('#send_user')[0]);// yourForm: form selector        
                $.ajax({
                    type: "POST",
                    url: base_url+"Whatsapp/send_user",// where you wanna post
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType:'json',
                    error: function(jqXHR, textStatus, errorMessage) {
                        console.log(jqXHR); // Optional
                        alert(errorMessage)
                    },
                    success: function(data) {
                      if(data == true){
                            Command: toastr["success"]("Anda berhasil mengirim pesan", "Berhasil");
                            // getcontens('page/file_pka');
                        }else{
                            Command: toastr["error"]("Simpan error, data tidak berhasil mengirim pesan", "Error");
                        }
                    } 
                });


              });


                jQuery.ajax({
                  url: base_url+"Whatsapp/data_unit_misioner",
                  dataType:'json',
                  success:function(response){
                    var data = response;
                    var $id = $('#um');
                    $id.empty();
                    $id.append('<option value="all">- All -</option>');
                    for (var i = 0; i < data.length; i++) {
                      $id.append('<option value="'+data[i].id_unit_misioner+','+data[i].kode+'">' + data[i].nama + '</option>');
                    }        
                  } ,
                  error: function(jqXHR, textStatus, errorMessage) {
                        console.log(errorMessage); // Optional
                        alert(jqXHR)
                    },           
                });
                jQuery.ajax({
                  url: base_url+"Whatsapp/data_users",
                  dataType:'json',
                  success:function(response){
                    var data = response;
                    var $id = $('#users');
                    $id.empty();
                    $id.append('<option value="all">- Pilih User -</option>');
                    for (var i = 0; i < data.length; i++) {
                      $id.append('<option value="'+data[i].tlp+'">' + data[i].username + '</option>');
                    }        
                  } ,
                  error: function(jqXHR, textStatus, errorMessage) {
                        console.log(errorMessage); // Optional
                        alert(jqXHR)
                    },           
                });
            
          });
          </script>