<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>
<script src="m_proto/kelas.js" type="text/javascript"></script>
    <div class='row'>
	 <div class='col-md-12'>
             <div class='panel panel-default'>
               <div class="panel-heading" style="height:45px">
                    <div class='box-tools pull-right '>
					 
                    </div>
					<h4 class='box-title'><i class="fas fa-graduation-cap"></i> Data Proyek Penguatan Profil Pelajar Pancasila</h4>
                </div>
				<div class='box-header with-border '>
			   <div class='box-tools pull-right '>
			   <table>
			   <tr>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
              <option value=""><?= $setting['sekolah'] ?></option>
               </select>
			   </div>
				</td>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
              <option value=""><?= $setting['jenjang'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control'>
               <option value=""><?= $setting['kota'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
               <option value=""><?= $setting['kecamatan'] ?></option>
               </select>
			   </div>
				</td>
				</tr>					
			</table>
			</div>
			 <h4 class='box-title'></h4>
			  </div>
			  <div class="box-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true" >Menu E-Rapor</a></li>
                    </ul>
					<div class="tab-content">
                    <div class="tab-pane active" id="tab_1" >
				<div class="panel panel-default">
				 <div class='box-body'>
        <div class='col-md-8'>
           <div class="panel panel-default">
                <div class='box-header'>
                    <h4 class='box-title'>Proyek Penguatan Profil Pelajar Pancasila</h4>
                    <div class='box-tools pull-right'>
					
                </div>
				</div>
					
                <div class='box-body'>
                    <div class='table-responsive'>
                        <table style="font-size: 11px" id='example1' class='table table-hover'>
                            <thead >
                                <tr>
                                    <th width='3px' class="hidden-xs">No</th>
									  <th>Kelas</th>
									   <th>Fase</th>
                                    <th>Judul Proyek</th>  
									<th>Deskripsi</th>  
                               								  
									<th>Action</th>
										</tr>
									</thead>							
							<tbody>							
                                <?php
								$no = 0;
								
								 $query = mysqli_query($koneksi, "select * FROM m_proyek");
                            while ($tjn = mysqli_fetch_array($query)) {
							
                                $no++;
                            ?>
							 <tr>
                                    <td class="hidden-xs"><?= $no; ?></td>
							        <td><?= $tjn['kelas'] ?></td>
									<td ><?= $tjn['fase'] ?></td>
									<td ><?= $tjn['judul'] ?></td>
									<td><?= $tjn['deskripsi'] ?></td>
                                   <td style="text-align:center">
                                       
										 <button data-id="<?= $tjn['id'] ?>" class="hapus btn-sm btn btn-danger"><i class="fas fa-trash"></i></button>
                                   </td>
								  
							       </tr>
                            <?php } ?>
                        </tbody>
                        </table>
                    </div>
                    </div>
					</div>
                    </div>
					
                     <div class='col-md-4'>
            <div class="panel panel-default">
                <div class='box-header'>                    
					 <form id="formtujuan" action=''>
                    <div class='box-tools pull-right'>
					   <button type='submit'  class='btn btn-sm btn-success'><i class='fa fa-check'></i> Simpan</button>
								</div>
								</div>
								
									 <div class='box-body'>
									 <div class='row'>
									  <div class="col-md-12">
                                        <div class='form-group-sm'>
                                                   <label>Pilih Fase</label>
                                                    <select name='fase' class='form-control' required='true'>
                                                       
														<?php if($setting['jenjang']=='SD'){ ?>
                                                          <option value='A'> Fase A (Kelas I, II)</option>
														   <option value='B'> Fase B (Kelas III, IV)</option>
														    <option value='C'> Fase C (Kelas V, VI)</option>
														   <?php } ?>
															<?php if($setting['jenjang']=='SMP'){ ?>
															 <option value='D'> Fase D (Kelas VII, VIII, IX)</option>
															 <?php } ?>
															 <?php if($setting['jenjang']=='SMA' OR $setting['jenjang']=='SMK'){ ?>
															  <option value='E'> Fase E (Kelas X)</option>
															   <option value='F'> Fase F (Kelas XI, XII)</option>
															   <?php } ?>
                                                    </select>
                                                </div>
												</div>
									 
												
									<div class="col-md-12">
                                        <div class='form-group-sm'>
                                                   <label>Kelas</label>
                                                    <select id='kelas' name='kelas' class='form-control' required='true'>
                                                        <option value=''></option>
                                                         <?php $quem = mysqli_query($koneksi, "SELECT * FROM kelas"); ?>
                                                <?php while ($m = mysqli_fetch_array($quem)) : ?>
                                                    <option value="<?= $m['id_kelas'] ?>"><?= $m['nama'] ?></option>
                                                <?php endwhile ?>
                                                    </select>
                                                </div>
												</div>
												<div class="col-md-12">
                                          <div class='form-group-sm'>
                                                   <label>Judul Proyek</label>
                                                   
                                           <input type="text" name="judul" class="form-control" required="true" >
                                                </div>
												</div>
												
														<div class="col-md-12">
                                                             <div class="form-group-sm">
														  <label>Deskripsi Proyek</label>
														<textarea  name='deskripsi' class='form-conntrol' rows='8' cols='80' style='width:100%;' required="true" placeholder="Tuliskan secara singkat tentang deskripsi proyek yang dilakukan di sekolah anda."></textarea>
														 </div>   
														</div> 
														
												
											</div>
											    
                                            </div>
                                        </div>
										
                                    </form>
                               
                        </div>
                    </div>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div>
    </div>

	<script>
	 $('#formtujuan').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: 'm_proto/crud_proyek.php?pg=tambah',
            data: $(this).serialize(),
            beforeSend: function() {
                $('form button').on("click", function(e) {
                    e.preventDefault();
                });
            },
            success: function(data) {
                console.log(data);
                if (data == 'OK') {
                    iziToast.success({
                        title: 'Sukses!',
                        message: 'Data berhasil disimpan',
                        position: 'topRight'
                    });
                    setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                } else {
                    iziToast.error({
                        title: 'Gagal!',
                        message: 'TP pada mapel tersebut sudah ada',
                        position: 'topRight'
                    });
					setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                }

            }
        });
        return false;
    });
	
	 $('#example1').on('click', '.hapus', function() {
        var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Are you sure?',
            text: 'Akan menghapus data ini!',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'iya, hapus'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'm_proto/crud_proyek.php?pg=hapus',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                        iziToast.success({
                            title: 'Sukses!',
                            message: 'Data Berhasil dihapus',
                            position: 'topRight'
                        });
                        setTimeout(function() {
                            window.location.reload();
                        }, 2000);
                    }
                });
            }
            return false;
        })

    });
	</script>
	<script>
	tinymce.init({
		selector: '.editor1',
		
		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 formula'
		],

		toolbar: 'bold italic fontselect fontsizeselect | alignleft aligncenter alignright bullist numlist  backcolor forecolor | formula code | imagetools link image paste ',
		fontsize_formats: '8pt 10pt 12pt 14pt 18pt 24pt 36pt',
		paste_data_images: true,

		images_upload_handler: function(blobInfo, success, failure) {
			success('data:' + blobInfo.blob().type + ';base64,' + blobInfo.base64());
		},
		image_class_list: [{
			title: 'Responsive',
			value: 'img-responsive'
		}],
	});
</script>