
<div class='row'>
<div class='col-md-6'>
           <div class="card">
             <div class="card-header">
					<h5 class='card-title'> Informasi</h5>
                </div>
				<div class='row'>
            <div class="card-body">
                 <form action='' method='post'>
                    <div class='right' style="margin-top:-50px">
                        <button type='submit' name='simpanpengumuman' class='btn btn-sm btn-outline-primary'><i class='fa fa-edit'></i> Simpan</button>
                    </div>
                 
                    <div class='col-sm-12'>
                        <div class='form-group'>
                            <label>Judul </label>
                            <input type='text' class='form-control' name='judul' placeholder='Judul' required>
                        </div>
                    </div><p>
                    <div class='col-sm-12'>
                        <div class='form-group'>
                            <label>Jenis Pengumuman </label><br>
                            <input type='radio' name='tipe' value='internal' checked> <span class='text-green'><b>guru</b></span> &nbsp; &nbsp;&nbsp;<input type='radio' name='tipe' value='eksternal'> <span class='text-blue'><b>siswa</b></span>
                        </div>
                    </div><p>
                    <div class='col-sm-12'>
                        <div class='form-group'>
                            <label>Informasi Pengumuman </label>
                            <textarea id='txtpengumuman' name='pengumuman' class='form-control'></textarea>
                        </div>
						 </form>
                    </div>
                </div>
            </div>
        </div>
		 </div>
   <?php
cek_session_admin();
if (isset($_POST['simpanpengumuman'])) {
    $exec = mysqli_query($koneksi, "INSERT INTO pengumuman (judul,text,user,type) VALUES ('$_POST[judul]','$_POST[pengumuman]','$pengawas[id_pengawas]','$_POST[tipe]')");
    if (!$exec) {
        $info = info("Gagal menyimpan!", "NO");
    } else {
        jump("?pg=pengumuman");
    }
}
?>
    <div class='col-md-6'>
        <div class="card">
             <div class="card-header">
                <h4 class='card-title'> Informasi</h4>
            </div>
            <div class='card-body'>
                <div class='table-responsive'>
                    <table id='example1' class='table'>
                        <thead>
                            <tr>
                                <th width='5px'></th>
                                <th>Pengumuman</th>
                                <th>Untuk</th>
                                <th width='60px'></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $pengumumanq = mysqli_query($koneksi, "SELECT * FROM pengumuman ORDER BY date DESC"); ?>
                            <?php while ($pengumuman = mysqli_fetch_array($pengumumanq)) : ?>
                                <?php $no++; ?>
                                <tr>
                                    <td><?= $no ?></td>
                                    <td><?= $pengumuman['judul'] ?></td>
                                    <td>
                                        <?php if ($pengumuman['type'] == 'eksternal') : ?>
                                           Siswa
                                            <?php else : ?>
                                               Guru
                                                <?php endif ?>
                                    </td>
                                    <td align='center'>
                                        <div class=''>
                                          <button data-id="<?= $pengumuman['id_pengumuman'] ?>" class="hapus btn-sm btn btn-outline-danger"><i class="fas fa-trash"></i></button>
                                        </div>
                                    </td>
                                </tr>
                               
                               
                                
                            <?php endwhile ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    tinymce.init({
        selector: '#txtpengumuman',
        plugins: [
            'advlist autolink lists link image charmap print preview hr anchor pagebreak',
            'searchreplace wordcount visualblocks visualchars code fullscreen',
            'insertdatetime media nonbreaking save table contextmenu directionality',
            'emoticons template paste textcolor colorpicker textpattern imagetools uploadimage paste'
        ],

        toolbar: 'bold italic fontselect fontsizeselect | alignleft aligncenter alignright bullist numlist  backcolor forecolor | emoticons code | imagetools link image paste ',
        fontsize_formats: '8pt 10pt 12pt 14pt 18pt 24pt 36pt',
        paste_data_images: true,
        paste_as_text: true,
        images_upload_handler: function(blobInfo, success, failure) {
            success('data:' + blobInfo.blob().type + ';base64,' + blobInfo.base64());
        },
        image_class_list: [{
            title: 'Responsive',
            value: 'img-responsive'
        }],
    });
	 $('#example1').on('click', '.hapus', function() {
        var id = $(this).data('id');
        console.log(id);
        Swal.fire({
				  title: 'Are you sure?',
				  text: "You won't be able to revert this!",
				  type: 'warning',
				  showCancelButton: true,
				  confirmButtonColor: '#3085d6',
				  cancelButtonColor: '#d33',
				  confirmButtonText: 'Yes, delete it!'	
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'hapus_pengumuman.php?pg=hapus_pengumuman',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                 iziToast.info(
            {
                title: 'Sukses!',
                message: 'Data berhasil dihapus',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
				 progressBarColor: '#FFFF00',
                  position: 'topRight'			  
                });
                        setTimeout(function() {
                            window.location.reload();
                        }, 2000);
                    }
                });
            }
            return false;
        })

    });

</script>