<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>

  <div class="row">
     <div class="col-md-12">
		<div class="card">
             <div class="card-header">									
                  <h5 class="card-title">Tambah Bank Soal</h5>
					</div>
                      <div class="card-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[]' id='soalkelas' class='form-control form-control-sm select2' multiple='multiple' style='width:100%' required='true'>
                                                       <option value="">Pilih Kelas</option>
													   <?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>
                             
                                </div>
                                 </div>
								 
                                </form>
                            </div>
                        </div>
                    </div>
			     <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.replace('?pg=materi');
                    }, 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;
    });
	
</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>
 