<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>
    <div class='row'>
        <div class='col-md-12'>
             <div class="card">
             <div class="card-header">
                  <h5 class='card-title'><i class="fas fa-envelope"></i> WA Gateway</h5></div>    
			    
			  <div class="card-body">
 <div class='row'>
      <div class='col-md-3'></div>      
    <div class='col-md-6'>
            <form id="formwa">
               
                        
                        <div class='form-group'>
                            <label>Pilih Kontak</label>
							<div class="input-group">
                            <select class="form-select" name="nomor" required="true">
                                <option value="">Pilih Kontak</option>
                                <?php $q = mysqli_query($koneksi, "select * from kontakme WHERE iduser='$user[id_user]' ");
                                while ($data = mysqli_fetch_array($q)) { ?>
                                    <option value="<?= $data['nomor'] ?>"><?= $data['nama_kontak'] ?></option>
                                <?php } ?>
                            </select>
							 <span class="input-group-btn">
					         <button type='submit' name='submit' class='btn btn-success'><i class='fa fa-check-circle'></i> Kirim</button>
                        </span>
					</div>        
                        </div>
                        <div class='form-group-sm'>
                            <label>Pesan</label>
                            <textarea name='pesan' class='form-control' rows="5" required='true'  /></textarea>
					   
                       <input type='hidden' name='layanan' value="Dikirim melalui Server WA <?= $setting['sekolah'] ?> pada <?= date('d-m-Y H:i:s') ?>, Sender BY <?= $user['nama'] ?>" class='form-control' required='true' autocomplete="off" />
                       <input type='hidden' name='balas' value="Jika ingin membalas pesan, silahkan kirim ke <?= $user['nama'] ?> dengan nomor <?= $user['nowa'] ?>" class='form-control' required='true' autocomplete="off" />
                       
					   </div>
                        
                            </div>
                        </div>
                    </div>
                </div>
            </form>
       
        
     
    </div>
</div>
<script>
$('#formwa').submit(function(e)
{
    e.preventDefault();
    var data = new FormData(this);
    
    $.ajax(
    {
        type: 'POST',
        url: 'gateway/pesan.php',
        enctype: 'multipart/form-data',
        data: data,
        cache: false,
        contentType: false,
        processData: false,
        success: function(data){
           
            iziToast.info(
            {
                title: 'Sukses!',
                message: 'Pesan dikirim',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
				 progressBarColor: '#FFFF00',
                  position: 'topRight'
            });
            setTimeout(function()
            {
                window.location.reload();
            }, 2000);
            
        }
    });
    return false;
});
</script>

