<?php
spl_autoload_register(function ($mod) {
	require('../../../../bootstrap/asset/mod/' . $mod . '.php');
});
?>
<div class="modal fade middle mt-5" id="tambahkategori" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">
	<div class="modal-dialog modal-md">
		<div class="modal-content bg-secondary">
			<form action="" method="post">
				<?php
				//require('layout/class.php');
				$csrf = new Csrf;
				$csrf->token();
				?>
				<div class="modal-header">
					<h5 class="modal-title" style="font-family:'Courier New', Courier, monospace"><span class="bi bi-people"></span> Tambah Kategori Siswa</h5>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<div class="modal-body" align="left">

					<div class="row">
						<label for="exampleEmail" class="col-sm-4 col-form-label">Nama Kategori </label>
						<div class="col-sm-8">

							<input type="text" name="kategori" style="font-family:Arial, Helvetica, sans-serif;font-size:12px" class="form-control form-control-sm fontInput small" placeholder="Nama Kategori">
						</div>
					</div>

				</div>

				<div class="modal-footer justify-content-between">
					<div class="float-right">
						<button type="submit" class="btn btn-light btn-xs " name="submitSaveKategori"><i class="bi-save"></i> SIMPAN KATEGORI</button>
					</div>
					<div class="float-left">
						<button type="button" class="badge badge-pill badge-secondary" data-dismiss="modal"><span class="badge badge-pill badge-secondary">CLOSE</span></button>
					</div>

				</div>
			</form>
		</div>
	</div>
</div>

<div class="modal fade middle mt-5" id="generateID" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">
	<div class="modal-dialog modal-md">
		<div class="modal-content bg-secondary">
			<form action="" method="post">
				<?php
				//require('layout/class.php');
				$csrf = new Csrf;
				$csrf->token();
				?>
				<div class="modal-header">
					<h5 class="modal-title" style="font-family:'Courier New', Courier, monospace"><span class="bi bi-people"></span> Generate ID Siswa</h5>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<div class="modal-body" align="left">

					<div class="row">
						<label for="exampleEmail" class="col-sm-12 col-form-label">Lanjut Generate ID Siswa? </label>

					</div>

				</div>

				<div class="modal-footer justify-content-between">
					<div class="float-right">
						<button type="submit" class="btn btn-light btn-xs " name="generateID"><i class="bi-save"></i> GENERATE ID SISWA</button>
					</div>
					<div class="float-left">
						<button type="button" class="badge badge-pill badge-secondary" data-dismiss="modal"><span class="badge badge-pill badge-secondary">CLOSE</span></button>
					</div>

				</div>
			</form>
		</div>
	</div>
</div>

<div class="modal fade middle mt-5" id="deleteAll" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">
	<div class="modal-dialog modal-md">
		<div class="modal-content bg-secondary">
			<form action="" method="post">

				<div class="modal-header">
					<h5 class="modal-title" style="font-family:'Courier New', Courier, monospace"><span class="bi bi-trash"></span> Kosongkan Data Siswa</h5>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<div class="modal-body" align="left">

					<div class="row mx-2">
						<label for="exampleEmail" class="col-sm-12 col-form-label"> <i class="bi-exclamation-triangle"></i> Yakin akan menghapus seluruh Data Siswa? </label>
					</div>

				</div>
				<div class="modal-footer justify-content-between">
					<div class="float-right">
						<button type="submit" class="btn btn-light btn-xs" name="deleteAll"><i class="bi-trash"></i> HAPUS SEMUA SISWA</button>
					</div>
					<div class="float-left">
						<button type="button" class="badge badge-pill badge-secondary" data-dismiss="modal"><span class="badge badge-pill badge-secondary">CLOSE</span></button>
					</div>

				</div>
			</form>
		</div>
	</div>
</div>

<?php
if (isset($_POST['submitSaveKategori'])) {
	$csrf = new Csrf;
	echo $csrf->Cek();

	$kategori = htmlspecialchars($_POST['kategori']);
	$dataarray = [
		'kategori' => $kategori,
	];
	$user_admin = new crudData();
	$user_admin->insertData('tb_siswa_kategori', $dataarray);
	$direct = new toast();
	echo  $direct->redirect('toast', 'save', 'seting/siswa/kategorisiswa_read');
} else {
	echo '';
};

if (isset($_POST['deleteAll'])) {
	$tahun = $_SESSION['tahun'];
	$tahun_tabel = substr($tahun, 2, 2) . substr($tahun, 7, 2);
	$tb_siswa = "tb_siswa" . $tahun_tabel;

	$siswa = new Siswa();
	$siswa->deleteAll($tb_siswa);
	$direct = new toast();
	echo  $direct->redirect('toast', 'delete', 'seting/siswa/siswa_read');
};
