<?php
require("../../../config/koneksi.php");
require("../../../config/function.php");
require("../../../config/crud.php");
require_once("../../PHPExcel/PHPExcel.php");
session_start();
$kelas=$_POST['kelas'];
$kode=$_POST['mapel'];
$guru=$_POST['guru'];
$jml = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM lingkup WHERE kelas='$kelas' AND kodemap='$kode' AND  idguru='$guru' "));
 $nama_file_baru = 'data.xlsx';
	
				if(is_file('../../temp/'.$nama_file_baru)) 
					unlink('../../temp/'.$nama_file_baru); 

				$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); 
				$tmp_file = $_FILES['file']['tmp_name'];
				if($ext == "xlsx"){
					move_uploaded_file($tmp_file, '../../temp/'.$nama_file_baru);
     
	$excelreader = new PHPExcel_Reader_Excel2007();
	$loadexcel = $excelreader->load('../../temp/'.$nama_file_baru); 
	$sheet = $loadexcel->getActiveSheet()->toArray();
			
	
	 $nama_file_baru = 'data.xlsx';
        $sukses = $gagal = 0;
       
        for ($a = 5; $a < (5+$jml); $a++) {
            $kode = $sheet['0'][$a];
            
            for ($i = 1; $i < count($sheet); $i++) {
				

                $idsiswa = $sheet[$i]['1'];
				$mapel = $sheet[$i]['3'];
				$kelas = $sheet[$i]['2'];
                $kode = $kode;
                $nilai = $sheet[$i][$a];
				$khp = $sheet[$i]['19'];
              
				
	
$query = "INSERT INTO nilai_sumatif(idsiswa,kelas,mapel,nilai,ket,khp) VALUES('".$idsiswa."','".$kelas."','".$mapel."','".$nilai."','".$kode."','".$khp."')";

		
			mysqli_query($koneksi, $query);
			
            }
        }
}

