<?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">INPUT MATERI PEMBELAJARAN</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-2">
											<label  class="col-md-2 col-form-label bold">Mata Pelajaran</label>
							                <div class="col-sm-10">
                                            <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['nama_mapel'] ?></option>"

                                                <?php endwhile ?>
                                            </select>
                                        </div>
										</div>
										 <div class="row mb-2">
										<label  class="col-md-2 col-form-label bold">Judul Materi</label>
							                <div class="col-sm-10">
                                            <input type="text" class="form-control" name="judul" aria-describedby="helpId" placeholder="Judul materi" required>
                                       </div>
                                        </div>
										
									<div class="row mb-2">
										<label  class="col-md-2 col-form-label bold">Materi Belajar</label> 
						                  <div class="col-sm-10">
                                       <textarea name='isimateri' class='editor1' rows='10' cols='80' style='width:100%;'></textarea>
                                        </div>
									 </div>
									
                                        <div class="row mb-2">
										<label  class="col-md-2 col-form-label bold">Kelas</label> 
						                  <div class="col-md-4">
                                                <select name='kelas[]' id='soalkelas' class='form-control 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['kelas'] ?>"><?= $kelas['kelas'] ?></option>
                                                        <?php endwhile ?>
                                                    </select>
                                                </div>
												 <label  class="col-md-1 col-form-label bold">Tanggal</label>
						                             <div class="col-sm-5">
                                                    <input type='text' name='tgl_mulai' class='tgl form-control' autocomplete='off' required='true' />
                                                </div>
												
											 </div>
												  <div class="row mb-2">
										             <label  class="col-md-2 col-form-label bold">Link Youtube</label> 
						                             <div class="col-sm-10">
                                                    <input type='text' name='youtube' class='form-control' autocomplete='off' />
                                                  
												  <h5><small>Cara memasukan Link Youtube  Contoh Link :</small> <span class="badge badge-secondary">https://youtu.be/42cqGZY9VTc</b> maka yang dimasukan adalah :<b>42cqGZY9VTc</b></span></h5>
												</div>
											 </div>
												   <div class="row mb-2"> 
                                                  <label  class="col-md-2 col-form-label bold">File Pendukung</label> 
						                             <div class="col-sm-10">
                                            <input type="file" class="form-control" name="file" placeholder="" aria-describedby="fileHelpId">
                                             <p>
											<h5><span class="badge badge-secondary">format file (doc/docx/xls/xlsx/pdf)</span></h5>
                                        </div>
                                    </div>
												
									<p>
                            <div class="kanan">
                          <button type='submit' id="blockui-3" class='btn btn-primary'>SIMPAN</button>
                             
                                </div>
                                
                                </form>
                            </div>
                        </div>
                    </div>
			     </div>
				</div>
<script>
    $('#formmateri').submit(function(e) {
        e.preventDefault();
        var data = new FormData(this);
        //console.log(data);
        $.ajax({
            type: 'POST',
            url: 'cbtserver_learn/buat_materi.php',
            enctype: 'multipart/form-data',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(data) {
                if (data = 'ok') {
               
                    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>
 