<?php
require("../../config/koneksi.php");
require("../../config/function.php");
require("../../config/crud.php");

$mapel = addslashes($_POST['mapel']);
$id_guru = $_SESSION['id_user'];
$materi = addslashes($_POST['isimateri']);
$quiz = $_POST['quiz'];
$judul = addslashes($_POST['judul']);
$tgl_mulai = $_POST['tgl_mulai'];
$youtube = $_POST['youtube'];
$kelas = serialize($_POST['kelas']);
$ektensi = ['jpg', 'png', 'docx', 'pdf', 'xlsx', 'pptx', 'ppt', 'doc','mp4','3gp'];
if ($_FILES['file']['name'] <> '') {
   $file = $_FILES['file']['name'];
   $temp = $_FILES['file']['tmp_name'];
   $ext = explode('.', $file);
   $ext = strtolower(end($ext));
   if (in_array($ext, $ektensi)) {
      $dest = '../../datafile/';
      $path = $dest . $file;
      $upload = move_uploaded_file($temp, $path);
      if ($upload) {
         $data = array(
            'mapel' => $mapel,
            'kelas' => $kelas,
            'id_guru' => $id_guru,
            'judul' => $judul,
			'tgl'=>$tanggal,
            'materi' => $materi,
            'tgl_mulai' => $tgl_mulai,
            'youtube' => $youtube,
            'file' => $file
         );
         insert($koneksi, 'materi', $data);
         echo "ok";
      } else {
         echo "gagal";
      }
   }
} else {
   $data = array(
      'mapel' => $mapel,
      'kelas' => $kelas,
      'id_guru' => $id_guru,
      'judul' => $judul,
      'materi' => $materi,
	  'tgl'=>$tanggal,
      'tgl_mulai' => $tgl_mulai,
      'youtube' => $youtube
	 
   );
   insert($koneksi, 'materi', $data);
   echo mysqli_error($koneksi);
}
