<?php
require "../../config/koneksi.php";
require "../../vendor/autoload.php";
require("../../config/function.php");
require("../../config/crud.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();
         for ($a = 6; $a < 12; $a++) {
                        $kode = $sheetData['4'][$a];
                        
                            for ($i = 5; $i < count($sheetData); $i++) {
                                $nis = $sheetData[$i]['1'];
								$kelas = $sheetData[$i]['3'];
								$mapel = $sheetData[$i]['5'];
                               $kode = str_replace(['SMT-'],"", $kode);
                                $nilai_p = $sheetData[$i][$a];
								
                                $datax = [
                                    'nis' => $nis,
                                    'semester' => $kode,
									'kelas' =>$kelas,
									'mapel' => $mapel,
                                    'nilai_p' => $nilai_p
                                    
                                ];
                               
                                    $exec = insert($koneksi, 'nilai_skl', $datax);
                               
                            }
                          
                        }
						 for ($e = 12; $e < 18; $e++) {
                        $kode = $sheetData['4'][$e];
                        
                            for ($i = 5; $i < count($sheetData); $i++) {
                                $nis = $sheetData[$i]['1'];
								$kelas = $sheetData[$i]['3'];
								$mapel = $sheetData[$i]['5'];
                                 $kode = str_replace(['SMT-'],"", $kode);
                                $nilai_k = $sheetData[$i][$e];
								$where =[
								 'nis' => $nis,
								 'mapel' => $mapel,
                                  'semester' => $kode
								];
                                $datax = [
                              
                                  'nilai_k' => $nilai_k
                                ];
                               
                                    $exec = update($koneksi, 'nilai_skl', $datax, $where);
                               
                            }
                          
                        }
						
						
                    }
                  
                }
           
