<?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" style="height:45px">
                    <div class='box-tools pull-right '>
					 
                    </div>
					<h4 class='box-title'><i class="fas fa-graduation-cap"></i> Lingkup Materi</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'>
			<?php if($pengawas['level']=='guru'){ ?>	 
        <div class='col-md-8'>
			<?php }else{ ?>
		 <div class='col-md-12'>
			<?php } ?>
            <div class="panel panel-default">
                <div class='box-header'> 
                    <h4 class='box-title'>Lingkup Materi</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>Tingkat</th>
                                    <th>Mapel</th>
									<th>Kode</th>
                                        <th>Lingkup Materi</th>	
                            <?php if($pengawas['level']=='guru'){ ?>										
									<th>Action</th>
							<?php } ?>
										</tr>
									</thead>							
							<tbody>							
                                <?php
								$no = 0;
								
								 $query = mysqli_query($koneksi, "select * from lingkup  
								 JOIN jadwal_proto ON jadwal_proto.kode=lingkup.kodemap
								 WHERE jadwal_proto.idguru='$_SESSION[id_pengawas]'");
                            while ($tjn = mysqli_fetch_array($query)) {
							
                                $no++;
                            ?>
							 <tr>
                                    <td class="hidden-xs"><?= $no; ?></td>
							        <td><?= $tjn['tingkat'] ?></td>
									<td ><?= $tjn['kodemap'] ?></td>
									<td ><?= $tjn['lm'] ?></td>
									<td><?= $tjn['materi'] ?></td>
										 <?php if($pengawas['level']=='guru'){ ?>
                                   <td style="text-align:center">
								  
                                       <button type="button" class="btn btn-info btn-xs" data-toggle="modal" data-target="#modaledit<?= $no ?>" >
                                                    <i class="fas fa-edit    "></i>
                                                </button>
										 <button data-id="<?= $tjn['id'] ?>" class="hapus btn-xs btn btn-danger"><i class="fas fa-trash"></i></button>
                                 
                                     </td>
								   <?php } ?>
								  
								   <div class="modal fade" id="modaledit<?= $no ?>" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                  <div class='modal-header'>
                                    <button class='close' data-dismiss='modal'><span aria-hidden='true'><i class='glyphicon glyphicon-remove'></i></span></button>
                                    <h4 class='modal-title'></h4>
                                         </div>
                                                <form id="formedit<?= $no ?>">
												<input type="hidden" name="id" value="<?= $tjn['id'] ?>" >
                                       <div class='modal-body'>
									    <div class='row'>
									
												
														<div class="col-md-12">
                                                             <div class="form-group-sm">
														  <label>Lingkup Materi</label>
														<textarea  name="materi" class="form-control" rows="5" required><?= $tjn['materi'] ?></textarea>
														 </div>   
														</div> 
														
											</div>
												
                                                <div class='modal-footer' >
                                            <div class='box-tools pull-right btn-group' >
                                                <button type='submit' class='btn btn-sm btn-success'><i class='fa fa-check'></i> Simpan</button>
                                               
                                            </div>
                                        </div>
										
                                    </form>
                                            </div>
                                        </div>
                                    </div>
                                    <script>
                        $("#formedit<?= $no ?>").submit(function(e) {
                          e.preventDefault();
						$.ajax({
							type: 'POST',
							url: 'sandik_ikm/crud_tujuan.php?pg=editmateri',
							data: $(this).serialize(),
							beforeSend: function() {
								$('form button').on("click", function(e) {
									e.preventDefault();
								});
							},
							success: function(data) {
								console.log(data);
								if (data == 'OK') {
									iziToast.info(
									{
									title: 'Sukses!',
									message: 'Data berhasil disimpan',
									titleColor: '#FFFF00',
									messageColor: '#fff',
									backgroundColor: 'rgba(0, 0, 0, 0.5)',
								   progressBarColor: '#FFFF00',
									position: 'topRight'			  
									});
									setTimeout(function() {
										window.location.reload();
									}, 2000);
								} else {
									iziToast.error({
										title: 'Gagal!',
										message: 'Materi tersebut sudah ada',
										titleColor: '#FFFF00',
									messageColor: '#fff',
									backgroundColor: 'rgba(0, 0, 0, 0.5)',
								   progressBarColor: '#FFFF00',
									position: 'topRight'	
									});
									setTimeout(function() {
									window.location.reload();
								}, 2000);
								}

							}
						});
						return false;
					});
                    </script>
   			
							       </tr>
                            <?php } ?>
                        </tbody>
                        </table>
                    </div>
                    </div>
					</div>
                    </div>
					<?php if($pengawas['level']=='guru'){ ?>	
                     <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='modal-body'>
									 <div class='row'>
									 <div class="col-md-4">
                                        <div class='form-group-sm'>
                                                   <label>Kode</label>
                                                    <select name='lm' class='form-control' required='true'>
                                                        <option value=''></option>
                                                         <?php 
														 for($i=1;$i<=14;$i++){
														?>
                                                    <option value="LM<?= $i ?>">LM<?= $i ?></option>
                                                <?php } ?>
                                                    </select>
                                                </div>
												</div>
									<div class="col-md-8">
                                        <div class='form-group-sm'>
                                                   <label>Tingkat</label>
                                                   <select id='tingkat' name='tingkat' class='form-control' required='true'>
                                                        <option value=''></option>
                                                         <?php $quem = mysqli_query($koneksi, "SELECT * FROM siswa  GROUP BY level"); ?>
                                                <?php while ($m = mysqli_fetch_array($quem)) : ?>
                                                    <option value="<?= $m['level'] ?>"><?= $m['level'] ?></option>
                                                <?php endwhile ?>
                                                    </select>
                                                </div>
												</div>
												<div class="col-md-12">
                                          <div class='form-group-sm'>
                                                   <label>Mapel</label>
                                                   <select id="mapel" name='mapel' class='form-control' style='width:100%' required>
                                                   <?php if($pengawas['level']=='guru'){ ?>
                                                <?php $que = mysqli_query($koneksi, "SELECT * FROM jadwal_proto WHERE idguru='$_SESSION[id_pengawas]' GROUP BY kode"); ?>
												<?php }else{ ?>
												<?php $que = mysqli_query($koneksi, "SELECT * FROM jadwal_proto  GROUP BY kode"); ?>
												<?php } ?>
											   <?php while ($mapel = mysqli_fetch_array($que)) : ?>

                                                    <option value="<?= $mapel['kode'] ?>"><?= $mapel['mapel'] ?></option>

                                                <?php endwhile ?>
                                            </select>
                                                </div>
												</div>
												
														<div class="col-md-12">
                                                             <div class="form-group-sm">
														  <label>Lingkup Materi</label>
														<textarea  name="materi" class="form-control" rows="5" required placeholder="isikan sesuai BAB dalam satu semester"></textarea>
														 </div>   
														</div> 
														
														
												<div class="col-md-12">
											   <div class='form-group-sm'>
                                                   <label>Guru Mapel</label>
                                                   <select id='guru' name='guru' class='form-control' style='width:100%' required>
													
													 <?php
													 if($pengawas['level']=='admin'){ 
                                                        $kelasQ = mysqli_query($koneksi, "SELECT * FROM pengawas WHERE level<>'admin' ");
													 }else{
														$kelasQ = mysqli_query($koneksi, "SELECT * FROM pengawas WHERE id_pengawas='$_SESSION[id_pengawas]' ");
													 }
                                                        while ($ekstra = mysqli_fetch_array($kelasQ)) {
                                                            echo "<option value='$ekstra[id_pengawas]'>$ekstra[nama]</option>";
                                                        }
                                                        ?>
													
                                                    </select>
                                                </div>
												</div>
											</div>
											
                                                <div class='modal-footer' >
                                            <div class='box-tools pull-right btn-group' >
                                             
                                            </div>
                                        </div>
										
                                    </form>
                               
                        </div>
                    </div>
                </div>
            </div>
					<?php } ?>
        </div>
    </div>

	<script>
	 $('#formtujuan').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: 'sandik_ikm/crud_tujuan.php?pg=materi',
            data: $(this).serialize(),
            beforeSend: function() {
                $('form button').on("click", function(e) {
                    e.preventDefault();
                });
            },
            success: function(data) {
                console.log(data);
                if (data == 'OK') {
                 iziToast.info(
					{
					title: 'Sukses!',
					message: 'Data berhasil disimpan',
					titleColor: '#FFFF00',
					messageColor: '#fff',
					backgroundColor: 'rgba(0, 0, 0, 0.5)',
				   progressBarColor: '#FFFF00',
					position: 'topRight'			  
					});
                    setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                } else {
                    iziToast.error({
                        title: 'Gagal!',
                        message: 'Materi sudah ada',
                       titleColor: '#FFFF00',
					messageColor: '#fff',
					backgroundColor: 'rgba(0, 0, 0, 0.5)',
				   progressBarColor: '#FFFF00',
					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,
			type:'warning',
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'iya, hapus'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'sandik_ikm/crud_tujuan.php?pg=hapusmateri',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                        iziToast.success({
                            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>
     
	