<?php
require("../../config/koneksi.php");
require("../../config/function.php");
require("../../config/crud.php");
cek_session_admin();
(isset($_GET['pg'])) ? $pg = $_GET['pg'] : $pg = '';

if ($pg == 'setting_kurikulum') {
  $level = $_POST['level'];
  $data = [  
		'kurikulum' => $_POST['kurikulum']
		  ];
		   $exec = update($koneksi, 'kelas', $data, ['level' => $level]);
		  
}
if ($pg == 'settingptm') {
  
  $data = [  
		'absen_siswa' => $_POST['absis'],
		'absen_guru' => $_POST['abgur'],
		'ptm'=>$_POST['ptm']
		  ];
		$datax = [ 
		'kirimabsen'=>$_POST['pesan']
		];
		   $exec = update($koneksi, 'menu', $data, ['id_menu' => 1]);
		   $exec = update($koneksi, 'aplikasi', $datax, ['id_aplikasi' => 1]);
}
if ($pg == 'setting_clear') {
    $pengawas = fetch($koneksi, 'pengawas', ['id_pengawas' => $_SESSION['id_pengawas']]);
    $password = $_POST['password'];
    if (!password_verify($password, $pengawas['password'])) {
        echo "password salah";
    } else {
        if (!empty($_POST['data'])) {
            $data = $_POST['data'];
            if ($data <> '') {
                foreach ($data as $table) {
                    if ($table <> 'pengawas') {
                        mysqli_query($koneksi, "TRUNCATE $table");
                    } else {
                        mysqli_query($koneksi, "DELETE FROM $table WHERE level!='admin'");
                    }
                }
                echo "ok";
            }
        }
    }
}

if ($pg == 'setting_server') {
 $data = [
        'server' => $_POST['server']
		  ];
		   $exec = update($koneksi, 'setting', $data, ['id_setting' => '1']);
}
if ($pg == 'reset') {
$exec = mysqli_query($koneksi, "truncate absensi");
$exec = mysqli_query($koneksi, "truncate absen_mapel");
$exec = mysqli_query($koneksi, "truncate agenda");
$exec = mysqli_query($koneksi, "truncate agenda_proto");
$exec = mysqli_query($koneksi, "truncate  arsip");
$exec = mysqli_query($koneksi, "truncate berita");
$exec = mysqli_query($koneksi, "truncate banksoal");
$exec = mysqli_query($koneksi, "truncate datafid");
$exec = mysqli_query($koneksi, "truncate deskripsi");
$exec = mysqli_query($koneksi, "truncate  file_pendukung");	
 $exec = mysqli_query($koneksi, "truncate hasil_jawaban");
 $exec = mysqli_query($koneksi, "truncate jadwal_mapel");
 $exec = mysqli_query($koneksi, "truncate jadwal_proto");
 $exec = mysqli_query($koneksi, "truncate jawaban");
 $exec = mysqli_query($koneksi, "truncate jodoh");
 $exec = mysqli_query($koneksi, "truncate kelas");
 $exec = mysqli_query($koneksi, "truncate lemari");
 $exec = mysqli_query($koneksi, "truncate level");
 $exec = mysqli_query($koneksi, "truncate lingkup");
 $exec = mysqli_query($koneksi, "truncate log");
 $exec = mysqli_query($koneksi, "truncate log_guru");
 $exec = mysqli_query($koneksi, "truncate log_face");
 $exec = mysqli_query($koneksi, "truncate map");
 $exec = mysqli_query($koneksi, "truncate mapel_proto");
 $exec = mysqli_query($koneksi, "truncate mata_pelajaran");
 $exec = mysqli_query($koneksi, "truncate m_bayar");
 $exec = mysqli_query($koneksi, "truncate m_eskul");
 $exec = mysqli_query($koneksi, "truncate m_proyek");
 $exec = mysqli_query($koneksi, "truncate nilai");
 $exec = mysqli_query($koneksi, "truncate nilai_formatif");
 $exec = mysqli_query($koneksi, "truncate nilai_harian");
 $exec = mysqli_query($koneksi, "truncate nilai_proses");
 $exec = mysqli_query($koneksi, "truncate nilai_proyek");
 $exec = mysqli_query($koneksi, "truncate nilai_rapor");
 $exec = mysqli_query($koneksi, "truncate nilai_sumatif");
 $exec = mysqli_query($koneksi, "truncate pengumuman");
 $exec = mysqli_query($koneksi, "truncate pk");
 $exec = mysqli_query($koneksi, "truncate proyek");
 $exec = mysqli_query($koneksi, "truncate ruang");
 $exec = mysqli_query($koneksi, "truncate server");
 $exec = mysqli_query($koneksi, "truncate sesi");
 $exec = mysqli_query($koneksi, "truncate siswa");
  $exec = mysqli_query($koneksi, "truncate siswa_eskul");
   $exec = mysqli_query($koneksi, "truncate siswa_mutasi");
    $exec = mysqli_query($koneksi, "truncate siswa_ptm");
	 $exec = mysqli_query($koneksi, "truncate soal");
	  $exec = mysqli_query($koneksi, "truncate sosial");
	   $exec = mysqli_query($koneksi, "truncate spiritual");
	    $exec = mysqli_query($koneksi, "truncate surat_keluar");
		 $exec = mysqli_query($koneksi, "truncate surat_masuk");
		  $exec = mysqli_query($koneksi, "truncate trx");
		   $exec = mysqli_query($koneksi, "truncate tujuan");
		    $exec = mysqli_query($koneksi, "truncate ujian");
			$exec = mysqli_query($koneksi, "truncate daftar");
			$exec = mysqli_query($koneksi, "truncate bayar");
			$exec = mysqli_query($koneksi, "truncate jenjang");
			$exec = mysqli_query($koneksi, "truncate jurusan");
			$exec = mysqli_query($koneksi, "truncate materi");
			$exec = mysqli_query($koneksi, "truncate tugas");
			$exec = mysqli_query($koneksi, "truncate barusikap");
			$exec = mysqli_query($koneksi, "truncate soal_quiz");
			$exec = mysqli_query($koneksi, "truncate prasarana");
			$exec = mysqli_query($koneksi, "truncate pra_kondisi");
			$exec = mysqli_query($koneksi, "truncate pra_gambar");
			$exec = mysqli_query($koneksi, "truncate binduk_absen");
			$exec = mysqli_query($koneksi, "truncate binduk_nilai");
			$exec = mysqli_query($koneksi, "truncate binduk_ortu");
			$exec = mysqli_query($koneksi, "truncate binduk_siswa");
 $files = glob('../../files/*'); 
foreach ($files as $file) {
    if (is_file($file))
        unlink($file); 
}
}