<?php defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!'); ?>
<?php if ($ac == '') { ?>
    <div class='row'>
        <div class='col-md-12'>
		 <div class="card">
             <div class="card-header">	
                    <div class='right'>
					
					 <a href="?pg=inputmateri" class='btn btn-outline-primary'><i class="fa fa-plus-circle"></i>Materi</a>
							<a href="?" class='btn btn-outline-danger' ><i class="fas fa-times-circle"></i>Back</a>	
                    </div>
					<h5 class='card-title'><i class="fas fa-rss"></i> Daftar materi Daring</h5>
                </div>
				
                   <div class="modal fade" id="modalmateri" tabindex="-1" aria-labelledby="modalmateri" aria-hidden="true">
			   <div class="modal-dialog modal-lg">
				   <div class="modal-content">
					  <div class="modal-header">
						<h5 class="modal-title" id="tambahjadwal">Tambah Materi</h5>
						   <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
								</div>
                            <div class="modal-body">
                                <form id="formmateri" >
                               
                                        <input type="hidden" class="form-control" name="id_mapel" value="<?= $id_mapel ?>">
                                         <div class="row mb-1">
													<label  class="col-md-3 col-form-label bold">Mata Pelajaran</label>
							                <div class="col-sm-7">
                                            <select name='mapel' class='form-select' style='width:100%' required>
                                                <option value=''>Pilih Mata Pelajaran</option>
                                                <?php $que = mysqli_query($koneksi, "SELECT * FROM mata_pelajaran"); ?>
                                                <?php while ($mapel = mysqli_fetch_array($que)) : ?>

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

                                                <?php endwhile ?>
                                            </select>
                                        </div>
										</div>
										 <div class="row mb-1">
										<label  class="col-md-3 col-form-label bold">Judul Materi</label>
							                <div class="col-sm-9">
                                            <input type="text" class="form-control" name="judul" aria-describedby="helpId" placeholder="Judul materi" required>
                                       </div>
                                        </div>
										 
											 <div class="row mb-1">
										<label  class="col-md-3 col-form-label bold">Jenis Kompetensi</label>
								   <div class="col-sm-3">
						<select id="kategori" name="kategori" onchange="tampilkan()" class="form-select" style="width: 100%" required>
                          <option value="">--Pilih Kompetensi--</option>
						 <option value="KI3">Pengetahuan</option>
                        <option value="KI4">Keterampilan</option>
                              </select>
                       </div>
                       
						<div class="col-sm-3">
						<select id="tampil" name="tampil" class="form-select" style="width: 100%">
                           </select>
						         </div>
						            
											<label  class="col-md-1 col-form-label bold">Quiz </label> 
						                  <div class="col-sm-2">
                                            <select name='quiz' class='form-select' style='width:100%' required>
                                                <option value=''>Quiz</option>
												 <option value="Ya">Ya</option>
                                                 <option value="Tidak">Tidak</option>
                                            </select>
                                        </div>
									 </div>
									  
									
									<div class="row mb-1">
										<label  class="col-md-3 col-form-label bold">Materi Belajar</label> 
						                  <div class="col-sm-9">
                                       <textarea name='isimateri' class='editor1' rows='10' cols='80' style='width:100%;'></textarea>
                                        </div>
									 </div>
									
                                        <div class="row mb-1">
										<label  class="col-md-3 col-form-label bold">Kelas</label> 
						                  <div class="col-md-4">
                                                <select name='kelas' class='form-select'  style='width:100%' required='true'>
                                                        <?php $lev = mysqli_query($koneksi, "SELECT * FROM kelas"); ?>
                                                        <?php while ($kelas = mysqli_fetch_array($lev)) : ?>
                                                            <option value="<?= $kelas['id_kelas'] ?>"><?= $kelas['id_kelas'] ?></option>
                                                        <?php endwhile ?>
                                                    </select>
                                                </div>
												 <label  class="col-md-2 col-form-label bold">Tanggal</label>
						                             <div class="col-sm-3">
                                                    <input type='text' name='tgl_mulai' class='tgl form-control' autocomplete='off' required='true' />
                                                </div>
												 </div>
												  <div class="row mb-1">
										             <label  class="col-md-3 col-form-label bold">Link Youtube</label> 
						                             <div class="col-sm-9">
                                                    <input type='text' name='youtube' class='form-control' autocomplete='off' />
                                                </div>
												  
												<label  class="col-md-3 col-form-label bold"></label>
												   <div class="col-sm-10">
												   <label>Cara memasukan Link Youtube  Contoh Link : <b>https://youtu.be/42cqGZY9VTc</b> maka yang dimasukan adalah :<b>42cqGZY9VTc</b></label>
												    <label class="col-xs-12 control-label"></label>
												  </div>
												  </div>
												   
                                         <label  class="col-md-3 col-form-label bold">File Pendukung</label> 
						                             <div class="col-sm-9">
                                            <input type="file" class="form-control-file" name="file" placeholder="" aria-describedby="fileHelpId">
                                            <small id="fileHelpId" class="form-text text-muted">format file (doc/docx/xls/xlsx/pdf)</small>
                                        </div>
                                    </div>
												
									<hr>
                                    <div class='modal-footer'>
                       <div class='box-tools pull-right btn-group'>
                          <button type='submit'  class='btn btn-outline-primary'><i class='fa fa-check-circle'></i>Simpan</button>
                              <button type='button' class='btn btn-outline-default' data-bs-dismiss='modal'><i class='fa fa-times-circle'></i>Close</button>
                                </div>
                                 </div>
								 
                                </form>
                            </div>
                        </div>
                    </div>
			
				 <div class="card-body">	
                    <div id='tablemateri' class='table-responsive'>
                        <table id="example1" class='table'>
                            <thead>
                                <tr>
                                    <th width='5px'>#</th>
                                    <th>Mata Pelajaran</th>
                                    <th width="5%">KD</th>
                                    <th>Judul materi</th>
                                    <th>Tgl Publish</th>
                                    <th>Kelas</th>
                                    <th width="5%">File</th>
                                    <th style="text-align:center" width="5%">Quiz</th>
									<th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                if ($user['level'] == 'guru') {
                                    $materiQ = mysqli_query($koneksi, "SELECT * FROM materi where id_guru='$_SESSION[id_user]'");
                                } else {
                                    $materiQ = mysqli_query($koneksi, "SELECT * FROM materi ");
                                }
                                ?>
                                <?php while ($materi = mysqli_fetch_array($materiQ)) : ?>
                                    <?php
                                    $guru = mysqli_fetch_array(mysqli_query($koneksi, "select * FROM users where id_user='$materi[id_guru]'"));
                                    $no++
                                    ?>
                                    <tr>
                                        <td><?= $no ?></td>
                                        <td>
                                            <?= $materi['mapel'] ?>
                                        </td>
                                        <td>
                                            <?= $materi['kd'] ?>
                                        </td>
                                        <td>
                                            <?= $materi['judul'] ?>
                                        </td>

                                        <td style="text-align:center">
                                            <?= $materi['tgl_mulai'] ?>
                                        </td>
                                        <td style="text-align:center">
                                            <?php $kelas = unserialize($materi['kelas']);
                                            foreach ($kelas as $kelas) {
                                                echo $kelas . " ";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if ($materi['file'] <> null) { ?>
                                                <a href="../berkas/<?= $materi['file'] ?>" target="_blank">Lihat</a>
                                            <?php } ?>
                                        </td>
										
										<td style="text-align:center">
										<?php if($materi['quiz']=='Ya'){ ?>
										<a href="?pg=quizbank&id=<?= $materi[id_materi] ?>" class='btn btn-sm btn-outline-success' data-bs-placement="top" data-bs-toggle="tooltip" title="Soal Quiz"><i class='fas fa-plus-circle'></i></a>
										<?php } ?>
                                        </td>
										
                                        <td style="text-align:center">
                                            <div class=''>
											<a href='?pg=materi&ac=absen&id=<?= $materi['id_materi'] ?>' class='btn btn-sm btn-outline-warning'  data-bs-toggle="tooltip" data-bs-placement="top" title="Absen"><i class='fas fa-camera'></i></a>
											<a href='?pg=materi&ac=nilai&id=<?= $materi['id_materi'] ?>' class='btn btn-sm btn-outline-info '  data-bs-toggle="tooltip" data-bs-placement="top" title="Nilai Quiz"><i class='fas fa-book'></i></a>
                                                <a href='?pg=materi&ac=lihat&id=<?= $materi['id_materi'] ?>' class='btn btn-sm btn-outline-success'  data-bs-toggle="tooltip" data-bs-placement="top" title="Komentar"><i class='fas fa-comment'></i></a>
                                               
                                                <button type="button" class="btn btn-outline-primary btn-sm" data-bs-toggle="modal" data-bs-target="#modaledit<?= $materi['id_materi'] ?>">
                                                    <i class="fas fa-edit" data-bs-toggle="tooltip" data-bs-placement="top" title="Edit"></i>
                                                </button>
                                                <button data-id='<?= $materi['id_materi'] ?>' class="hapus btn btn-outline-danger btn-sm"  data-bs-toggle="tooltip" data-bs-placement="top" title="Hapus"><i class="fas fa-trash-alt"></i></button>
                                            </div>
                                        </td>
                                    </tr>
                                    
                                    <div class="modal fade" id="modaledit<?= $materi['id_materi'] ?>" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
                                        <div class="modal-dialog modal-lg" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">

                                                   <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                                </div>
                                                <form id="formeditmateri<?= $materi['id_materi'] ?>">
                                                    <div class="modal-body">
                                                        <input type="hidden" value="<?= $materi['id_materi'] ?>" name='id'>
                                                        <div class="form-group-sm">
														<label>Mata Pelajaran</label><br>
                                                            <select name='mapel' class='form-select' style='width:100%' required>
                                                                <option value='<?= $materi['mapel'] ?>' selected><?= $materi['mapel'] ?></option>
                                                                 <?php $que = mysqli_query($koneksi, "SELECT * FROM mata_pelajaran"); ?>
                                                                <?php while ($mapel = mysqli_fetch_array($que)) : ?>

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

                                                                <?php endwhile ?>
                                                            </select>
                                                        </div>
														
                                                        <div class="form-group-sm">
                                                         <label>Judul Materi</label><br>
                                                            <input type="text" class="form-control" name="judul" aria-describedby="helpId" placeholder="Judul materi" value="<?= $materi['judul'] ?>" required>

                                                        </div>
														
														<div class="form-group-sm">
														<label>Quiz</label><br>
                                            <select name='quiz' class='form-select' style='width:100%' required>
											 <option value='<?= $materi['quiz'] ?>' selected><?= $materi['quiz'] ?></option>
                                                <option value=''>Quiz</option>
												 <option value="Ya">Ya</option>
                                                 <option value="Tidak">Tidak</option>
                                            </select>
                                        </div>
										<label>Materi Belajar</label><br>
                                                        <div class="form-group-sm">
                                                            <textarea name='isimateri' class='editor1' rows='10' cols='80' style='width:100%;'><?= $materi['materi'] ?></textarea>
                                                        </div><p>
                                                        <div class='form-group'>
                                                            <div class='row'>
                                                                <div class='col-md-4'>
                                                                    <label>Pilih Kelas</label><br>
                                                                    <select name='kelas[]' id='soalkelas' class='form-control form-control-sm select2' multiple='multiple' style='width:100%' readonly>
                                                                       <?php $lev = mysqli_query($koneksi, "SELECT * FROM kelas"); ?>
                                                                        <?php while ($kelas = mysqli_fetch_array($lev)) : ?>
                                                                            <?php if (in_array($kelas['id_kelas'], unserialize($materi['kelas']))) : ?>
                                                                                <option value="<?= $kelas['id_kelas'] ?>" selected><?= $kelas['id_kelas'] ?></option>
                                                                            <?php else : ?>
                                                                                <option value="<?= $kelas['id_kelas'] ?>"><?= $kelas['id_kelas'] ?></option>
                                                                            <?php endif; ?>
                                                                        <?php endwhile ?>
                                                                    </select>
                                                                </div>
                                                                <div class='col-md-4'>
                                                                    <label>Tanggal Publish</label>
                                                                    <input type='text' name='tgl_mulai' class='tgl form-control' autocomplete='off' required='true' value="<?= $materi['tgl_mulai'] ?>" />
                                                                </div>
                                                                <div class='col-md-4'>
                                                                    <label>Video Youtube</label>
                                                                    <input type='text' name='youtube' class='form-control' autocomplete='off'  value="<?= $materi['youtube'] ?>" />
                                                                </div>

                                                            </div>
                                                        </div><p>
                                                        <div class="form-group-sm">
                                                            <label for="file">File Pendukung</label>
                                                            <input type="file" class="form-control-file" name="file" id="file" placeholder="" aria-describedby="fileHelpId">
                                                            <small id="fileHelpId" class="form-text text-muted">format file (doc/docx/xls/xlsx/pdf)</small>
                                                        </div>
                                                    </div>
                                                     <div class='modal-footer'>
                       <div class='box-tools pull-right btn-group'>
                          <button type='submit'  class='btn btn-primary'><i class='fa fa-check'></i> Simpan</button>
                              <button type='button' class='btn btn-default' data-bs-dismiss='modal'>Close</button>
                                </div>
                                 </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                    <script>
                                        $('#formeditmateri<?= $materi['id_materi'] ?>').submit(function(e) {
                                            e.preventDefault();
                                           var data = new FormData(this);
      
                                            $.ajax({
                                                type: 'POST',
                                                url: 'sandik_learn/materi/edit_materi.php',
                                                enctype: 'multipart/form-data',
												data: data,
												cache: false,
												contentType: false,
												processData: false,
												success: function(data) {
												  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);

												}
											});
											return false;
										});
 
                                    </script>
                                <?php endwhile ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
		
<?php } elseif ($ac == 'lihat') { ?>
    <?php $id = $_GET['id']; ?>
    <div class='row'>
        <div class='col-md-12'>
            <div class="card">
             <div class="card-header">	
			  <div class='right'>
			 		<a href="?pg=materi" class='btn btn-outline-danger' ><i class="fas fa-times-circle"></i>Back</a>	
                    </div>
					 <h5 class='card-title'><i class="fas fa-envelope"></i> Daftar Komentar</h5>
                </div>
            
					<div class="card-body">
						<?php $m=fetch($koneksi,'materi',['id_materi'=>$_GET['id']]); ?>
						<center><h4 class='box-title'><?= $m['mapel'] ?></h4>
						<p>Tanggal <?= date('d-m-Y',strtotime($m['tgl'])); ?></p></center>	
				<div class="panel panel-default"> 
			
                      <div id='tablekomentar' class='table-responsive'>
                        <table id="example1" class='table table-bordered table-hover'>
                            <thead>
                                <tr>
                                    <th width='5px'>#</th>
                                    
                                    <th>Nama Siswa</th>
                                    <th>Komentar</th>
									 <th width="15%">Dikirim</th>
                                    <th width='5px'>Hapus</th>
                                </tr>
                            </thead>
                            <tbody>
							       <?php     
								$no=0;
								 if ($pengawas['level'] == 'guru') :
                              $materiQ = mysqli_query($koneksi, "SELECT * FROM komentar WHERE guru='$_SESSION[id_user]' ");
                            elseif ($pengawas['level'] == 'guru') :
							 $materiQ = mysqli_query($koneksi, "SELECT * FROM komentar WHERE guru='$pengawas[id_user]' ");
							  endif;
						   while ($komentar = mysqli_fetch_array($materiQ)){
								$siswa=fetch($koneksi,'siswa',['id_siswa' => $komentar['id_user']]);
								$materi=fetch($koneksi,'materi',['id_materi' => $komentar['id_materi']]);
                              $no++;
                                ?>
								<tr>
                                        <td><?= $no ?></td>
                                        
									   <td><?= $siswa['nama'] ?> </td>
									   <td><?= $komentar['komentar'] ?> </td>
									   <td><?= $komentar['tgl'] ?> </td>
									   <td>
									   <button data-id='<?= $komentar['id'] ?>' class="hapus btn btn-danger btn-sm"><i class="fas fa-trash-alt    "></i></button>
								        </td>
								</tr>
							<?php } ?>
					</tbody>
                        </table>		
                </div>
            </div>
        </div>
    </div>
<script>
 $('#example1').on('click', '.hapus', function() {
        var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Apa anda yakin?',
            text: "akan menghapus materi ini!",
            type:'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes!'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'sandik_learn/materi/hapus_komen.php',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                       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);
                    }
                });
            }
            return false;
        })

    });
	 
</script>


<?php } elseif ($ac == 'nilai') { ?>
    <?php $id = $_GET['id']; ?>
    <div class='row'>
        <div class='col-md-12'>
             <div class="card">
             <div class="card-header">
			  <div class='right'>
			 		<a href="?pg=materi" class='btn btn-outline-danger' ><i class="fas fa-times-circle"></i>Back</a>	
                    </div>
					 <h5 class='card-title'><i class="fas fa-school"></i> Daftar Nilai Quiz</h5>
                </div>
             
						<div class="card-body">
						<?php $m=fetch($koneksi,'materi',['id_materi'=>$_GET['id']]); ?>
						<center><h5 class='box-title'><?= $m['mapel'] ?></h5>
						<p>Tanggal <?= date('d-m-Y',strtotime($m['tgl'])); ?></p></center>	
				<div class="panel panel-default"> 
				
                      <div id='tabelnile' class='table-responsive'>
                        <table id="example1" class='table table-bordered table-hover'>
                            <thead>
                                <tr>
                                    <th width='5px'>#</th>
                                   
                                    <th>Nama Siswa</th>
                                    <th width="5%">Nilai</th>
									 <th width="10%">Dikerjakan</th>
                                    
                                </tr>
                            </thead>
                            <tbody>
							       <?php     
								$no=0;
                              $nilaiQ = mysqli_query($koneksi, "SELECT * FROM nilaiquiz WHERE idmateri='$_GET[id]'");
                            while ($nilai = mysqli_fetch_array($nilaiQ)){
								$siswa=fetch($koneksi,'siswa',['id_siswa' => $nilai['idsiswa']]);
								$materi=fetch($koneksi,'materi',['id_materi' => $nilai['idmateri']]);
                              $no++;
                                ?>
								<tr>
                                        <td><?= $no ?></td>
                                        
									   <td><?= $siswa['nama'] ?> </td>
									   <td><?= $nilai['nilai'] ?> </td>
									   <td><?= $nilai['tgl'] ?> </td>
									   
								</tr>
							<?php } ?>
					</tbody>
                        </table>		
                </div>
            </div>
        </div>
    </div>
		<iframe id='loadframe' name='frameresult' src='sandik_learn/cetaknilaiquiz.php?id=<?= $_GET['id'] ?>' style='display:none'></iframe>
	<script>
	$('#example1').on('click', '.hapus', function() {
        var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Apa anda yakin?',
            text: "akan menghapus materi ini!",
            type:'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes!'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'sandik_learn/materi/hapus_nilaiquiz.php',
                    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>
	<?php } elseif ($ac == 'absen') { ?>
    <?php $id = $_GET['id']; ?>
    <div class='row'>
        <div class='col-md-12'>
            <div class="card">
             <div class="card-header">
			  <div class='right'>
			 		<a href="?pg=materi" class='btn btn-outline-danger' ><i class="fas fa-times-circle"></i>Back</a>	
                    </div>
					<h5 class='card-title'><i class="fas fa-download"></i> Daftar Download / Menonton Video Materi</h5>
                </div>
             
						<div class="card-body">
						<?php $m=fetch($koneksi,'materi',['id_materi'=>$_GET['id']]); ?>
						<center><h5 class='box-title'><?= $m['mapel'] ?></h5>
						<p>Tanggal <?= date('d-m-Y',strtotime($m['tgl'])); ?></p></center>
				<div class="panel panel-default">
								
                      <div id='tablekomentar' class='table-responsive'>
                        <table id="example1" class='table table-bordered table-hover'>
                            <thead>
                                <tr>
                                    <th width='5px'>#</th>              
                                    <th>Nama Siswa</th>
                                    <th width="5%">Absen</th>
									 <th width="15%">Tgl Absen</th>
                                    <th width="15%" class="text-center">Buka Materi</th>
                                </tr>
                            </thead>
                            <tbody>
							       <?php     
								$no=0;
                              $nilaiQ = mysqli_query($koneksi, "SELECT * FROM absen_daringmapel WHERE idmateri='$_GET[id]'");
                            while ($nilai = mysqli_fetch_array($nilaiQ)){
								$siswa=fetch($koneksi,'siswa',['id_siswa' => $nilai['idsiswa']]);
								$materi=fetch($koneksi,'materi',['id_materi' => $nilai['idmateri']]);
                              $no++;
                                ?>
								<tr>
                                        <td><?= $no ?></td>
                                       
									   <td><?= $siswa['nama'] ?> </td>
									   <td class="text-center"><?= $nilai['ket'] ?> </td>
									   <td><?= $nilai['tanggal'] ?></td>
									    <td class="text-center"><?= $nilai['jam'] ?></td>
									  
								</tr>
							<?php } ?>
					</tbody>
                        </table>		
                </div>
            </div>
        </div>
    </div>

<?php } ?>
<script>
function tampilkan(){
  var nama_kota=document.getElementById("formmateri").kategori.value;
  if (nama_kota=="KI3")
    {
        document.getElementById("tampil").innerHTML=
		"<option value='3.1'>3.1</option><option value='3.2'>3.2</option><option value='3.3'>3.3</option><option value='3.4'>3.4</option><option value='3.5'>3.5</option><option value='3.6'>3.6</option><option value='3.7'>3.7</option><option value='3.8'>3.8</option><option value='3.9'>3.9</option><option value='3.10'>3.10</option><option value='3.11'>3.11</option><option value='3.12'>3.12</option>";
    }
  else if (nama_kota=="KI4")
    {
        document.getElementById("tampil").innerHTML="<option value='4.1'>4.1</option><option value='4.2'>4.2</option><option value='4.3'>4.3</option><option value='4.4'>4.4</option><option value='4.5'>4.5</option><option value='4.6'>4.6</option><option value='4.7'>4.7</option><option value='4.8'>4.8</option><option value='4.9'>4.9</option><option value='4.10'>4.10</option><option value='4.11'>4.11</option><option value='4.12'>4.12</option>";
    }
}
</script>
<script>
    $('#formmateri').submit(function(e) {
        e.preventDefault();
        var data = new FormData(this);
        //console.log(data);
        $.ajax({
            type: 'POST',
            url: 'sandik_learn/materi/buat_materi.php',
            enctype: 'multipart/form-data',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(data) {
                $('#modalmateri').modal('hide');
                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.info(
            {
                title: 'GAGAL!',
                message: 'Data 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;
    });
	
    $('#tablemateri').on('click', '.hapus', function() {
        var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Apa anda yakin?',
            text: "Akan menghapus semu data materi ini !",
            type:'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes!'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'sandik_learn/materi/hapus_materi.php',
                    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;
        })

    });
	
    $('#tablejawaban').on('click', '.hapus', function() {
        var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Apa anda yakin?',
            text: "akan menghapus nilai ini!",

            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes!'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'sandik_learn/materi/hapus_nilai.php',
                    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>
<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'
        }],
        setup: function(editor) {
            editor.on('change', function() {
                tinymce.triggerSave();
            });
        }
    });
</script>
 <script>
			$('.select2').select2();
			</script>