<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>
    <div class='row'>
        <div class='col-md-12'>
            <div class='panel panel-default'>
               <div class="panel-heading">
                  <h5 class='box-title'><i class="fas fa-envelope"></i> WA Gateway</h5></div>    
			  
			  <div class="box-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true" >Wa Broadcast</a></li>                        
                    </ul>					
					<div class="tab-content">
                        <div class="tab-pane active" id="tab_1" >
						<br>
						
    <div class='row'>    
    <div class='col-md-6'>
         <?php $w = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM wabot  WHERE id='1'")); ?>
           
                <div class='panel panel-default'>
                    <div class='box-header with-border'>
                        <h4 class='box-title'>Template Pesan</h4>
                        <div class='box-tools pull-right '>
                          
                        </div>
                    </div>
                    <div class='box-body'>
					 <form id="formwa" action=''>
                        <div class='form-group-sm'>
                            <label>Isi Pesan</label>
                            <textarea name='pesan' class='form-control' rows="5" required='true'  /><?= $w['pesan'] ?></textarea>
					   </div>
					    <div class='form-group'>
                           <label>Pilih Kelas</label><br>
                           <select name='kelas' class='form-control' style='width:100%'  required='true'>
                              <option value='<?= $w[untuk] ?>'><?= $w['untuk'] ?></option>
                                 <?php $lev = mysqli_query($koneksi, "SELECT * FROM siswa GROUP BY id_kelas"); ?>
                                    <?php while ($kelas = mysqli_fetch_array($lev)) : ?>

                                       <option value="<?= $kelas['id_kelas'] ?>"><?= $kelas['id_kelas'] ?></option>

                                              <?php endwhile ?>
                                               </select>
                                                </div>
                        <br>
                        <div class='form-group-sm'>
					   <button type='submit' name='submit' class='btn btn-sm btn-success pull-right'><i class='fa fa-check'></i>Simpan</button>
					</div> 
                            </div>
                      
            </form>
      </div>
	    </div>
		
 <div class='col-md-6'>
                <div class='panel panel-default'>
                    <div class='box-header with-border'>
                        <h4 class='box-title'>Data Kontak</h4>
                        <div class='box-tools pull-right '>
						 <form id="formkirimmasal">
                           <input type="hidden" name="untuk" value="<?= $w['untuk'] ?>" >
						   <input type="hidden" name="pesan" value="<?= $w['pesan'] ?>" >
						    <button type='submit' class='btn btn-sm btn-success pull-right'><i class='fa fa-check'></i> Kirim</button>
						   </form>
                        </div>
                    </div>
                    <div class='box-body'>
					<div class='table-responsive'>
                    <table id='example1' style="font-size: 12px" class='table'>
                        <thead>
                            <tr>
                                <th width='5px'>#</th>
                                <th>Nama</th>
                                <th>No Whatsapp</th>
                              
                            </tr>
                        </thead>
                        <tbody>
                            <?php $kontakme = mysqli_query($koneksi, "SELECT * FROM siswa where id_kelas='$w[untuk]' "); ?>
                            <?php while ($kontak = mysqli_fetch_array($kontakme)) : ?>
                                <?php $no++; ?>
                                <tr>
                                    <td><?= $no ?></td>
									 <td><?= $kontak['nama'] ?></td>
                                    <td><?= $kontak['hp'] ?></td>
                           
                                   
                                </tr>
                            <?php endwhile ?>
                        </tbody>
                    </table>
					 </div>
                        </div>
                    </div>
					<script>
$('#formkirimmasal').submit(function(e)
{
    e.preventDefault();
    var data = new FormData(this);
    
    $.ajax(
    {
        type: 'POST',
        url: 'gateway/wabot.php',
        enctype: 'multipart/form-data',
        data: data,
        cache: false,
        contentType: false,
        processData: false,
        success: function(data){
           
            iziToast.info(
            {
                title: 'Sukses!',
                message: 'Pesan Terkirim',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
				 progressBarColor: '#FFFF00',
                  position: 'topRight'
            });
            setTimeout(function()
            {
                window.location.reload();
            }, 2000);
            
        }
    });
    return false;
});
</script>
<script>
$('#formwa').submit(function(e)
{
    e.preventDefault();
    var data = new FormData(this);
    
    $.ajax(
    {
        type: 'POST',
        url: 'gateway/crudmasal.php',
        enctype: 'multipart/form-data',
        data: data,
        cache: false,
        contentType: false,
        processData: false,
        success: function(data){
           
            iziToast.info(
            {
                title: 'Sukses!',
                message: 'Pesan Tersimpan',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
				 progressBarColor: '#FFFF00',
                  position: 'topRight'
            });
            setTimeout(function()
            {
                window.location.reload();
            }, 2000);
            
        }
    });
    return false;
});
</script>