<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
$ac = dekripsi($ac);

$materi = mysqli_fetch_array(mysqli_query($koneksi, "select * from materi where id_materi='$ac'"));
$nilai = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM nilaiquiz WHERE idmateri='$materi[id_materi]' AND idsiswa='$_SESSION[id_siswa]' "));
function youtube($url)
{
    $link = str_replace('http://www.youtube.com/watch?v=', '', $url);
    $link = str_replace('https://www.youtube.com/watch?v=', '', $link);
    $data = '<iframe width="100%" height="315" src="https://www.youtube.com/embed/' . $link . '" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
    return $data;
}
$jam=date('H:i:s');
$tanggal=date('Y-m-d');
$cekdata = "SELECT * FROM absen_daringmapel WHERE idsiswa='$_SESSION[id_siswa]'  AND idmateri='$ac'";
$jikaada = mysqli_query($koneksi,$cekdata);
if(mysqli_num_rows($jikaada)==0){
$exec = mysqli_query($koneksi,"INSERT INTO absen_daringmapel(idmateri,idsiswa,tanggal,jam,ket) VALUES('$ac','$_SESSION[id_siswa]','$tanggal','$jam','H')");

}else{
	
}
$cek = "SELECT * FROM absen_daring WHERE idsiswa='$_SESSION[id_siswa]'  AND tanggal='$tanggal'";
$jika = mysqli_query($koneksi,$cek);
if(mysqli_num_rows($jika)==0){
$exec = mysqli_query($koneksi,"INSERT INTO absen_daring(idsiswa,tanggal,ket) VALUES('$_SESSION[id_siswa]','$tanggal','H')");

}else{
	
}
?>

<div class='row'>
    <div class='col-md-6'>
       <div class="card">
             <div class="card-header">
                <h5 class='card-title'><i class="fas fa-file-signature"></i> Detail materi</h5>
            </div>
            <div class='card-body'>
			
                <table class='table table-striped'>
                    <tr>
                        <th width='150'>Mata Pelajaran</th>
                        <td width='10'>:</td>
                        <td><?= $materi['mapel'] ?></td>

                    </tr>

                    <tr>
                        <th>Tgl Pembelajaran</th>
                        <td width='10'>:</td>
                        <td><?= $materi['tgl_mulai'] ?></td>
                    </tr>
                    <?php if($materi['quiz']=='Ya' AND $nilai==0){ ?>
					 <tr>
                        <th>Quiz</th>
                        <td width='10'>:</td>
                        <td> <a href="<?= $homeurl . '/soalquiz/' . $materi['id_materi'] ?>" class="btn btn-sm btn-outline-primary">
						<i class="fas fa-edit"></i> Quiz</a>
						</td>
                    </tr>
					<?php } ?>
					<?php if($materi['file']<>''){ ?>
					 <tr>
                        <th>Download</th>
                        <td width='10'>:</td>
                        <td> <a href="<?= $homeurl . '/berkas/' . $materi['file'] ?>" class="btn btn-sm btn-outline-danger"><i class="fas fa-download"></i>Download</a></td>
                    </tr>
					<?php } ?>
                </table>
				
					<?php 
                    if(!empty($materi['file'])){
						$pecah=explode('.',$materi['file']);
						$ekstensi=$pecah[1];
					?>
					<?php if($ekstensi=='mp4'){ ?>
					<video src="<?= $homeurl ?>/berkas/<?= $materi['file'] ?>" controls autoplay width="100%" height="315"></video>
					 <?php } ?>
					 <?php if($ekstensi=='jpg' OR $ekstensi=='png'){ ?>
					<img src="<?= $homeurl ?>/berkas/<?= $materi['file'] ?>" controls autoplay width="100%" height="315">
					 <?php } ?>
					 <?php if($ekstensi=='pdf'){ ?>
					<iframe  src="<?= $homeurl ?>/berkas/<?= $materi['file'] ?>" controls autoplay width="100%" height="315"></iframe>
					<?php } ?>
					 <?php if($ekstensi=='docx'){ ?>
					<iframe src="http://docs.google.com/viewer?url=berkas/<?= $materi['file'] ?> 
					&embedded=true"  width="100%" height="315" controls autoplay style="border: none;"></iframe>

					<?php } ?>
					  <?php } ?>
                    <center>
                        <div class="callout">
                            <strong>
                                <h5><?= $materi['judul'] ?></h5>
                            </strong>
                        </div>
                    </center>
                    <?php if ($materi['youtube'] <> null) {  ?>
                        <div class="col-md-3"></div>
                        <div class="callout col-md-6">
                            <?= youtube($materi['youtube']) ?>
                        </div>
                        <div class="col-md-3"></div>
                    <?php } ?>
                    <div class="col-md-12">
                        <?= $materi['materi'] ?>
                    </div>
            </div>
</div>
        </div>
   
  <div class='col-md-6'>
       <div class="card">
             <div class="card-header">
                <h5 class='card-title'><i class="fas fa-file-signature"></i> Komentar</h5>
            </div>
            <div class='card-body'>
                <table class='table  table-striped'>
                    <tr>
                        <th width='150'>Mata Pelajaran</th>
                        <td width='10'>:</td>
                        <td><?= $materi['mapel'] ?></td>

                    </tr>

                    <tr>
                        <th>Tgl Pembelajaran</th>
                        <td width='10'>:</td>
                        <td><?= $materi['tgl_mulai'] ?></td>
                    </tr>

                </table>
                <form method="post" action="" enctype="multipart/form-data">
										
				<input type='hidden' name='id_materi' value="<?= $materi['id_materi'] ?>" >
				<input type='hidden' name='guru' value="<?= $materi['id_guru'] ?>" >
				<font> Silahkan kirim pesan jika materi pembelajaran kurang dimengerti </font>
				<textarea id='editor2' name='komentar' class='editor1' rows='5' cols='80' style='width:100%;'></textarea>
				<div class="modal-footer">
                  <button type="submit" name="submit" class="btn btn-danger">Kirim Pesan</button>
                </div>
					</form>
                
                    </div>
            </div>
        </div>
    </div>
</div>
<?php            
            if (isset($_POST['submit'])) {
           $id_siswa=$_SESSION['id_siswa'];
		   $guru=$_POST['guru'];
		   $tgl=date('Y-m-d H:i:s');
		   $id_materi=$_POST['id_materi'];
		   $komentar=$_POST['komentar'];
			mysqli_query($koneksi,"INSERT INTO komentar(id_user,id_materi,komentar,jenis,tgl,guru) VALUES('$id_siswa','$id_materi','$komentar','1','$tgl','$guru')");
	echo "
	  <script type='text/javascript'>
		setTimeout(function () { 	
			swal({
				title: 'Sukses !!!',
				text:  'Komentar Berhasil dikirim',
				type: 'success',
				timer: 2000,
				showConfirmButton: true
			});		
		},10);	
		window.setTimeout(function(){ 
			window.location.replace();
		} ,2000);	
	  </script>";
	
			}
            ?>