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

$id_mapel = $_POST['mapel'];
$id_guru = $_SESSION['id_user'];
$tugas = addslashes($_POST['isitugas']);
$judul = addslashes($_POST['judul']);
$tgl_mulai = $_POST['tgl_mulai'];
$tgl_selesai = $_POST['tgl_selesai'];
$kelas = serialize($_POST['kelas']);
$ki = $_POST['kategori'];
$kd = $_POST['tampil'];
$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 = end($ext);
   if (in_array($ext, $ektensi)) {
      $dest = '../../datafile/';
      $path = $dest . $file;
      $upload = move_uploaded_file($temp, $path);
      if ($upload) {
         $data =[
            'mapel' => $id_mapel,
            'kelas' => $kelas,
            'id_guru' => $id_guru,
            'judul' => $judul,
            'tugas' => $tugas,
            'tgl_mulai' => $tgl_mulai,
            'tgl_selesai' => $tgl_selesai,
             'file' => $file
			
         ];
         insert($koneksi, 'tugas', $data);
         echo "ok";
      } else {
         echo "gagal";
      }
   }
} else {
   $datax = [
      'mapel' => $id_mapel,
      'kelas' => $kelas,
      'id_guru' => $id_guru,
      'judul' => $judul,
      'tugas' => $tugas,
      'tgl_mulai' => $tgl_mulai,
      'tgl_selesai' => $tgl_selesai
	
   ];
   insert($koneksi, 'tugas', $datax);
   echo "ok";
}
