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

$file_mimes = array('application/vnd.ms-excel', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
if (isset($_FILES['file']['name'])) {
    $ext = ['xls', 'xlsx'];
    $arr_file = explode('.', $_FILES['file']['name']);
    $extension = end($arr_file);
    if (in_array($extension, $ext)) {
        if ('xls' == $extension) {
            $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
        } else {
            $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
        }

        $spreadsheet = $reader->load($_FILES['file']['tmp_name']);
        $sheetData = $spreadsheet->getActiveSheet()->toArray();
		
		
$idmapel=$_POST['idmapel'];

  for ($i = 8; $i < count($sheetData); $i++) {
            $nomor = $sheetData[$i]['0'];
            $jenis = $sheetData[$i]['1'];
            $soal = $sheetData[$i]['2'];
            $soal = addslashes($soal);
			 $pilA = $sheetData[$i]['3'];
            $pilA = addslashes($pilA);
			 $pilB = $sheetData[$i]['4'];
            $pilB = addslashes($pilB);
			 $pilC = $sheetData[$i]['5'];
            $pilC = addslashes($pilC);
			 $pilD = $sheetData[$i]['6'];
            $pilD = addslashes($pilD);
			$pilE = $sheetData[$i]['7'];
            $pilE = addslashes($pilE);
			
			  $perA = $sheetData[$i]['8'];
            $perA = addslashes($perA);
			 $perB = $sheetData[$i]['9'];
            $perB = addslashes($perB);
			 $perC = $sheetData[$i]['10'];
            $perC = addslashes($perC);
			 $perD = $sheetData[$i]['11'];
            $perD = addslashes($perD);
			$perE = $sheetData[$i]['12'];
            $perE = addslashes($perE);
			
			 $jawaban = $sheetData[$i]['13'];
			 $skor = $sheetData[$i]['14'];

	        $exec = mysqli_query($koneksi, "INSERT INTO soal (id_bank,nomor,soal,jenis,pilA,pilB,pilC,pilD,pilE,perA,perB,perC,perD,perE,jawaban,max_skor)VALUES('$idmapel','$nomor','$soal','$jenis','$pilA','$pilB','$pilC','$pilD','$pilE','$perA','$perB','$perC','$perD','$perE','$jawaban','$skor')");
		}
	}
	
}
?>		
		
	
			