<?php
include 'config/rupiah.php';
if ($_GET[act] == '') {
	if (isset($_GET['kelas']) && $_GET['kelas'] != "") {
		if (isset($_GET['status']) && $_GET['status'] != "") {
			$tampil = mysqli_query($conn, "SELECT * FROM view_detil_siswa WHERE idKelas='$_GET[kelas]' AND statusSiswa='$_GET[status]' ORDER BY idKelas ASC");
		} else {
			$tampil = mysqli_query($conn, "SELECT * FROM view_detil_siswa WHERE idKelas='$_GET[kelas]' ORDER BY idKelas ASC");
		}
		$kelas = $_GET['kelas'];
	} else {
		$tampil = mysqli_query($conn, "SELECT * FROM view_detil_siswa ORDER BY idKelas ASC");
	}


	$ta = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM tahun_ajaran where idTahunAjaran='$_GET[tahun]'"));
	$idTahun = $ta['idTahunAjaran'];
	$tahun = $ta['nmTahunAjaran'];

	$idt = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM identitas where npsn='10700295'"));
	$pos = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM pos_bayar where idPosBayar='$_GET[pos]'"));

	$idsiswa = $_GET['siswa'];
	$dtsiswa = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM view_detil_siswa where idSiswa='$_GET[siswa]'"));
	$nissiswa = $dtsiswa['nisSiswa'];
	$namasiswa = $dtsiswa['nmSiswa'];
	$namakelas = $dtsiswa['nmKelas'];
?>
	<div class="col-xs-12">
		<div class="box box-warning">
			<div class="box-header with-border">
				<h3 class="box-title"> Data Siswa </h3>
			</div><!-- /.box-header -->
			<div class="box-body">
				<?php
				if (isset($_GET['sukses'])) {
					echo "<div class='alert alert-success alert-dismissible fade in' role='alert'> 
					<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
					<span aria-hidden='true'>×</span></button> <strong>Sukses!</strong> - Data telah Berhasil Di Proses,..
					</div>";
				} elseif (isset($_GET['gagal'])) {
					echo "<div class='alert alert-danger alert-dismissible fade in' role='alert'> 
					<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
					<span aria-hidden='true'>×</span></button> <strong>Gagal!</strong> - Data tidak Di Proses, terjadi kesalahan dengan data..
					</div>";
				}
				?>
				<form method="GET" action="" class="form-horizontal">
					<input type="hidden" name="view" value="siswa" />
					<table class="table table-striped">
						<tbody>
							<tr>
								<td>
									<select id="kelas" name="kelas" class="form-control">
										<option value="" selected> - Pilih Kelas - </option>
										<?php
										$sqk = mysqli_query($conn, "SELECT * FROM kelas_siswa ORDER BY idKelas ASC");
										while ($k = mysqli_fetch_array($sqk)) {
											$selected = ($k['idKelas'] == $kelas) ? ' selected="selected"' : "";
											echo "<option value=" . $k['idKelas'] . " " . $selected . ">" . $k['nmKelas'] . "</option>";
										}
										?>
									</select>
								</td>
								<td>
									<select class="form-control" name="status">
										<option value="">- Semua Status -</option>
										<option value="Aktif">Aktif</option>
										<option value="Non Aktif">Non Aktif</option>
										<option value="Drop Out">Drop Out</option>
										<option value="Pindah">Pindah</option>
										<option value="Lulus">Lulus</option>
									</select>
								</td>
								<td width="100">
									<input type="submit" name="tampil" value="Tampilkan" class="btn btn-success  btn-sm pull-right">
								</td>
								<td>

									<span class="pull-right">
										<a class="btn btn-danger  btn-sm" href="index.php?view=siswa&act=import">
											<i class="fa fa-file-excel-o"></i> Import Data Siswa
										</a>
										<a class='btn btn-primary btn-sm' href='index.php?view=siswa&act=tambah'>Tambahkan Data</a>
									</span>
								</td>
							</tr>
						</tbody>
					</table>
				</form>

				<div class="box-body">

				</div><!-- /.box-body -->

				<div class="table-responsive">
					<table id="example1" class="table table-bordered table-striped table-condensed">
						<thead>
							<tr>
								<th>No</th>
								<th>NISN</th>
								<th>Nama Siswa</th>
								<th>Jenis Kelamin</th>
								<th>Kelas</th>
								<th>Wa Ortu</th>
								<th>Saldo Tabungan</th>
								<th>Aksi</th>

							</tr>
						</thead>

						<tbody>
							<?php
							$no = 1;
							while ($r = mysqli_fetch_array($tampil)) {
								echo "<tr><td>$no</td>
							
								<td>" . $r['nisnSiswa'] . "</td>
								<td>" . $r['nmSiswa'] . "</td>
								<td>" . $r['jkSiswa'] . "</td>
								<td>" . $r['nmKelas'] . "</td>
								<td>" . $r['noHpOrtu'] . "</td>
								<td>Rp." . rupiah($r['saldo']) . "</td>
								<td>
								<a class='btn btn-info btn-xs' title='Edit Data' target='_blank' href='cetak_data_siswa.php?id=$r[idSiswa]'><span class='glyphicon glyphicon-print'> </span> Cetak Buku Induk</a>
								<a class='btn btn-success btn-xs ' title='Edit Data' href='?view=siswa&act=edit&id=$r[idSiswa]'><span class='glyphicon glyphicon-edit'></span></a>
								<a class='btn btn-danger btn-xs ' title='Delete Data' href='?view=siswa&hapus&id=$r[idSiswa]' onclick=\"return confirm('Apa anda yakin untuk hapus Data ini? (Menghapus siswa berarti juga akan menghapus tagihan dan pembayaran!)')\"><span class='glyphicon glyphicon-remove'></span></a>
								</td>
								";
								echo "</tr>";
								$no++;
							}
							if (isset($_GET[hapus])) {
								mysqli_query($conn, "DELETE FROM siswa where idSiswa='$_GET[id]'");
								echo "<script>document.location='index.php?view=siswa';</script>";
							}

							?>
						</tbody>
					</table>
				</div>
			</div><!-- /.box-body -->
		</div><!-- /.box -->
	</div>
<?php
} elseif ($_GET[act] == 'edit') {
	if (isset($_POST[update])) {
		$nama_file = $_FILES['fotoSiswa']['name'];
		$ukuran_file = $_FILES['fotoSiswa']['size'];
		$tipe_file = $_FILES['fotoSiswa']['type'];
		$tmp_file = $_FILES['fotoSiswa']['tmp_name'];
		$ekstensi =  array('png', 'jpg', 'jpeg', 'gif');
		$ext = pathinfo($nama_file, PATHINFO_EXTENSION);
		// Set path folder tempat menyimpan gambarnya
		$path = "foto_siswa/" . $nama_file;


		if ($ukuran_file <= 1000000) { // Cek apakah ukuran file yang diupload kurang dari sama dengan 1MB
			// Jika ukuran file kurang dari sama dengan 1MB, lakukan :
			// Proses upload
			if (move_uploaded_file($tmp_file, $path)) {
				if (!in_array($ext, $ekstensi)) {
					header("location:index.php?view=siswa&gagal"); // Cek apakah gambar berhasil diupload atau tidak
					// Jika gambar berhasil diupload, Lakukan :  
					// Proses simpan ke Database
				} else {
					$query = mysqli_query($conn, "UPDATE siswa SET nisSiswa='$_POST[nisSiswa]',nisnSiswa='$_POST[nisnSiswa]',nmSiswa='$_POST[nmSiswa]',jkSiswa='$_POST[jkSiswa]',agamaSiswa='$_POST[agamaSiswa]',tmptLahir='$_POST[tmptLahir]',tglLahirSiswa='$_POST[tglLahir]',level='siswa',statusKeluarga='$_POST[statusKeluarga]',anakKe='$_POST[anakKe]',sekolah='$_POST[sekolah]',
				nmOrtuIbu='$_POST[nmIbu]',idKelas='$_POST[kelasSiswa]',statusSiswa='$_POST[statusSiswa]',nmOrtu='$_POST[nmAyah]',username='$_POST[username]',password='$_POST[password]',alamatOrtu='$_POST[alamat]',noHpOrtu='$_POST[noHp]',noHpSis='$_POST[noHpSis]', foto='$nama_file'
					WHERE idSiswa='$_POST[id]'");
				}
			} else {
				$query = mysqli_query($conn, "UPDATE siswa SET nisSiswa='$_POST[nisSiswa]',nisnSiswa='$_POST[nisnSiswa]',nmSiswa='$_POST[nmSiswa]',jkSiswa='$_POST[jkSiswa]',agamaSiswa='$_POST[agamaSiswa]',tmptLahir='$_POST[tmptLahir]',tglLahirSiswa='$_POST[tglLahir]',level='siswa',statusKeluarga='$_POST[statusKeluarga]',anakKe='$_POST[anakKe]',sekolah='$_POST[sekolah]',
				nmOrtuIbu='$_POST[nmIbu]',idKelas='$_POST[kelasSiswa]',statusSiswa='$_POST[statusSiswa]',nmOrtu='$_POST[nmAyah]',username='$_POST[username]',password='$_POST[password]',alamatOrtu='$_POST[alamat]',noHpOrtu='$_POST[noHp]',noHpSis='$_POST[noHpSis]'
					WHERE idSiswa='$_POST[id]'");
			}
		}



		if ($query) {
			echo "<script>document.location='index.php?view=siswa&sukses';</script>";
		} else {
			echo "<script>document.location='index.php?view=siswa&gagal';</script>";
		}
	}
	$edit = mysqli_query($conn, "SELECT * FROM view_detil_siswa where idSiswa='$_GET[id]'");
	$record = mysqli_fetch_array($edit);
?>
	<form method="POST" action="" class="form-horizontal" enctype="multipart/form-data">
		<div class="col-md-9">
			<div class="box box-success">
				<div class="box-body">
					<div class="nav-tabs-custom">
						<ul class="nav nav-tabs">
							<li class="active"><a href="#tab_1" data-toggle="tab">Data Pribadi</a></li>
							<li><a href="#tab_2" data-toggle="tab">Data Sekolah</a></li>
							<li><a href="#tab_3" data-toggle="tab">Data Keluarga</a></li>
						</ul>
						<div class="tab-content">
							<div class="tab-pane active" id="tab_1">
								<div class="col-md-6">
									<input name="id" type="hidden" class="form-control" placeholder="Nama lengkap" value="<?= $record['idSiswa'] ?>">
									<label>Nama lengkap <small data-toggle="tooltip" title="" data-original-title="Wajib diisi">*</small></label>
									<input name="nmSiswa" type="text" class="form-control" placeholder="Nama lengkap" value="<?= $record['nmSiswa'] ?>">
								</div>
								<br>
								<div class="col-md-6">
									<label>Jenis Kelamin</label>
									<div class="radio">
										<label>
											<?php
											if ($record['jkSiswa'] == 'L') {
												echo '<input type="radio" name="jkSiswa" value="L" checked> Laki-laki';
											} else {
												echo '<input type="radio" name="jkSiswa" value="L"> Laki-laki';
											}
											?>
										</label>&nbsp;&nbsp;
										<label>
											<?php
											if ($record['jkSiswa'] == 'P') {
												echo '<input type="radio" name="jkSiswa" value="P" checked> Perempuan';
											} else {
												echo '<input type="radio" name="jkSiswa" value="P"> Perempuan';
											}
											?>
										</label>
									</div>
								</div>
								<br>
								<div class="col-md-6">
									<label>Tempat Lahir</label>
									<input name="tmptLahir" type="text" class="form-control" placeholder="Tempat Lahir" value="<?= $record['tmptLahir'] ?>">
								</div>
								<br>
								<div class="col-md-6">
									<label>Tanggal Lahir </label>
									<div class="input-group date date-picker" data-date="" data-date-format="yyyy-mm-dd">
										<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
										<input class="form-control" type="text" name="tglLahir" readonly="readonly" placeholder="Tanggal" value="<?php if ($record[tglLahirSiswa] == '0000-00-00') {
																																						echo '';
																																					} else {
																																						echo $record[tglLahirSiswa];
																																					} ?>">
									</div>
								</div>
								<div class="col-md-6">
									<label>Agama</label>

									<select class="form-control" name="agamaSiswa">
										<option value="<?php echo $record['agamaSiswa']; ?>"><?php echo $record['agamaSiswa']; ?></option>
										<option value="Islam">Islam</option>
										<option value="Katolik">Katolik</option>
										<option value="Protestan">Protestan</option>
										<option value="Hindu">Hindu</option>
										<option value="Budha">Budha</option>
									</select>

								</div>
								<br>
								<div class="col-md-6">
									<label>Alamat</label>
									<textarea class="form-control" name="alamat" placeholder="Alamat Tempat Tinggal"><?= $record['alamatOrtu'] ?></textarea>
								</div>
								<br><br><br><br><br><br><br>
							</div>

							<div class="tab-pane" id="tab_2">
								<div class="col-sm-6">
									<label>NIS <small data-toggle="tooltip" title="" data-original-title="Wajib diisi">*</small></label>
									<input name="nisSiswa" type="text" class="form-control" placeholder="NIS Siswa" value="<?= $record['nisSiswa'] ?>">
								</div>
								<div class="col-sm-6">
									<label>NISN <small data-toggle="tooltip" title="" data-original-title="Wajib diisi"></small></label>
									<input name="nisnSiswa" type="text" class="form-control" placeholder="NISN Siswa" value="<?= $record['nisnSiswa'] ?>">
								</div>
								<div class="col-sm-6">
									<input type="hidden" id="idKelas" value="<?= $record['idKelas'] ?>">
									<label>Kelas <small data-toggle="tooltip" title="" data-original-title="Wajib diisi">*</small></label>
									<select name="kelasSiswa" id="Ckelas" class="form-control">
										<option disabled selected> - Pilih Kelas - </option>
									</select>
								</div>
								<div class="col-md-6">
									<label>Sekolah Asal</label>
									<input type="text" name="sekolah" class="form-control" value="<?php echo $record['sekolah']; ?>" placeholder="">
								</div>
								<div class="col-md-6">
									<label>Username</label>
									<input type="text" name="username" class="form-control" value="<?php echo $record['username']; ?>" placeholder="">
								</div>
								<div class="col-md-6">
									<label>Password</label>
									<input type="text" name="password" class="form-control" value="<?php echo $record['password']; ?>" placeholder="">
								</div>
								<br><br><br><br><br><br><br><br><br>
							</div>

							<div class="tab-pane" id="tab_3">

								<div class="col-sm-6">
									<label>Nama Ibu Kandung</label>
									<input name="nmIbu" type="text" class="form-control" placeholder="Nama Ibu" value="<?= $record['nmOrtuIbu'] ?>">
								</div>

								<div class="col-sm-6">
									<label>Nama Ayah Kandung</label>
									<input name="nmAyah" type="text" class="form-control" placeholder="Nama Ayah" value="<?= $record['nmOrtu'] ?>">
								</div>

								<div class="col-sm-6">
									<label>No. Handphone Orang Tua <small data-toggle="tooltip" title="" data-original-title="Wajib diisi"></small></label>
									<input name="noHp" type="text" class="form-control" placeholder="No Handphone Orang Tua" value="<?= $record['noHpOrtu'] ?>">
								</div>

								<div class="col-sm-6">
									<label>No. Handphone Siswa <small data-toggle="tooltip" title="" data-original-title="Wajib diisi"></small></label>
									<input name="noHpSis" type="text" class="form-control" placeholder="No Handphone Siswa" value="<?= $record['noHpSis'] ?>">
								</div>

								<div class="col-sm-6">
									<label>Anak Ke</label>
									<input type="text" name="anakKe" class="form-control" value="<?php echo $record['anakKe']; ?>" placeholder="">
								</div>


								<div class="col-sm-6">
									<label>Status Dalam Keluarga</label>
									<input type="text" name="statusKeluarga" class="form-control" value="<?php echo $record['statusKeluarga']; ?>" placeholder="">
								</div>
								<br><br><br><br><br><br><br><br><br><br>
							</div>
						</div>
					</div>
					<p style="color:#9C9C9C;margin-top: 5px"><i>*) Field Wajib Diisi</i></p>
				</div>
			</div>
		</div>

		<div class="col-md-3">
			<div class="box box-success">
				<div class="box-body">
					<label>Status</label>
					<div class="radio">
						<label>
							<?php
							if ($record['statusSiswa'] == 'Non Aktif') {
								echo '<input type="radio" name="statusSiswa" value="Non Aktif" checked> Tidak Aktif';
							} else {
								echo '<input type="radio" name="statusSiswa" value="Non Aktif" checked> Tidak Aktif';
							}
							?>
						</label>
					</div>
					<div class="radio">
						<label>
							<?php
							if ($record['statusSiswa'] == 'Aktif') {
								echo '<input type="radio" name="statusSiswa" value="Aktif" checked> Aktif';
							} else {
								echo '<input type="radio" name="statusSiswa" value="Aktif"> Aktif';
							}
							?>
						</label>
					</div>
					<div class="radio">
						<label>
							<?php
							if ($record['statusSiswa'] == 'Lulus') {
								echo '<input type="radio" name="statusSiswa" value="Lulus" checked> Lulus';
							} else {
								echo '<input type="radio" name="statusSiswa" value="Lulus"> Lulus';
							}
							?>
						</label>
					</div>
					<div class="radio">
						<label>
							<?php
							if ($record['statusSiswa'] == 'Pindah') {
								echo '<input type="radio" name="statusSiswa" value="Pindah" checked> Pindah';
							} else {
								echo '<input type="radio" name="statusSiswa" value="Pindah"> Pindah';
							}
							?>
						</label>
					</div>
					<div class="radio">
						<label>
							<?php
							if ($record['statusSiswa'] == 'Drop Out') {
								echo '<input type="radio" name="statusSiswa" value="Drop Out" checked> Drop Out';
							} else {
								echo '<input type="radio" name="statusSiswa" value="Drop Out"> Drop Out';
							}
							?>
						</label>
					</div>
					<br>

					<label>Foto</label>

					<a href="#" class="thumbnail">
						<img src="<?= 'foto_siswa/' . $record[foto] ?>" id="target" alt="Choose image to upload" class="img-thumbnail img-responsive">
					</a>
					<input type="file" class="form-control form-control-sm" name="fotoSiswa" id="foto" accept=".png, .jpg, .jpeg">



					<br>
					<button name="update" type="submit" value="Simpan" class="btn btn-block btn-success">Simpan</button>
					<a href="index.php?view=<?= $_GET[view] ?>" class="btn btn-block btn-danger">Batal</a>
				</div>
			</div>
		</div>

	</form>

<?php
} elseif ($_GET[act] == 'tambah') {
	if (isset($_POST[tambah])) {
		$nama_file = $_FILES['fotoSiswa']['name'];
		$ukuran_file = $_FILES['fotoSiswa']['size'];
		$tipe_file = $_FILES['fotoSiswa']['type'];
		$tmp_file = $_FILES['fotoSiswa']['tmp_name'];
		$ekstensi =  array('png', 'jpg', 'jpeg', 'gif');
		$ext = pathinfo($nama_file, PATHINFO_EXTENSION);
		// Set path folder tempat menyimpan gambarnya
		$path = "foto_siswa/" . $nama_file;


		if ($ukuran_file <= 1000000) { // Cek apakah ukuran file yang diupload kurang dari sama dengan 1MB
			// Jika ukuran file kurang dari sama dengan 1MB, lakukan :
			// Proses upload
			if (move_uploaded_file($tmp_file, $path)) {
				if (!in_array($ext, $ekstensi)) {
					header("location:index.php?view=siswa&gagal"); // Cek apakah gambar berhasil diupload atau tidak
					// Jika gambar berhasil diupload, Lakukan :  
					// Proses simpan ke Database
				} else {
					$query = mysqli_query($conn, "INSERT INTO siswa(nisSiswa,nisnSiswa,nmSiswa,jkSiswa,agamaSiswa,tglLahirSiswa,tmptLahir,idKelas,statusSiswa,username,password,level,statusKeluarga,anakKe,sekolah,nmOrtuIbu,nmOrtu,alamatOrtu,noHpOrtu,noHpSis, foto) 
				VALUES('$_POST[nisSiswa]','$_POST[nisnSiswa]','$_POST[nmSiswa]','$_POST[jkSiswa]','$_POST[agamaSiswa]','$_POST[tglLahir]','$_POST[tmptLahir]','$_POST[idKelas]','$_POST[statusSiswa]','$_POST[username]','$_POST[password]','$_POST[level]','$_POST[statusKeluarga]','$_POST[anakKe]','$_POST[sekolah]','$_POST[nmOrtuIbu]','$_POST[nmOrtu]','$_POST[alamat]','$_POST[noHp]','$_POST[noHpSis]','$nama_file')");
				}
			} else {
				$query = mysqli_query($conn, "INSERT INTO siswa(nisSiswa,nisnSiswa,nmSiswa,jkSiswa,agamaSiswa,tglLahirSiswa,tmptLahir,idKelas,statusSiswa,username,password,level,statusKeluarga,anakKe,sekolah,nmOrtuIbu,nmOrtu,alamatOrtu,noHpOrtu,noHpSis) 
									  VALUES('$_POST[nisSiswa]','$_POST[nisnSiswa]','$_POST[nmSiswa]','$_POST[jkSiswa]','$_POST[agamaSiswa]','$_POST[tglLahir]','$_POST[tmptLahir]','$_POST[idKelas]','$_POST[statusSiswa]','$_POST[username]','$_POST[password]','$_POST[level]','$_POST[statusKeluarga]','$_POST[anakKe]','$_POST[sekolah]','$_POST[nmOrtuIbu]','$_POST[nmOrtu]','$_POST[alamat]','$_POST[noHp]','$_POST[noHpSis]')");
			}
		}

		if ($query) {
			echo "<script>document.location='index.php?view=siswa&sukses';</script>";
		} else {
			echo "<script>document.location='index.php?view=siswa&gagal';</script>";
		}
	}

?>
	<div class="col-md-9">
		<div class="box box-success">
			<div class="box-body">
				<div class="nav-tabs-custom">
					<ul class="nav nav-tabs">
						<li class="active"><a href="#tab_1" data-toggle="tab">Data Pribadi</a></li>
						<li><a href="#tab_2" data-toggle="tab">Data Sekolah</a></li>
						<li><a href="#tab_3" data-toggle="tab">Data Keluarga</a></li>
					</ul>
					<div class="tab-content">
						<div class="tab-pane active" id="tab_1">
							<form method="POST" action="" class="form-horizontal" enctype="multipart/form-data">
								<div class="col-md-6">
								
									<label>Nama lengkap <small data-toggle="tooltip" title="" data-original-title="Wajib diisi">*</small></label>
									<input name="nmSiswa" type="text" class="form-control" placeholder="Nama lengkap" >
								</div>
								<br>
								<div class="col-md-6">
									<label>Jenis Kelamin</label>
									<div class="radio">
										<label>
											<?php
											if ($record['jkSiswa'] == 'L') {
												echo '<input type="radio" name="jkSiswa" value="L" checked> Laki-laki';
											} else {
												echo '<input type="radio" name="jkSiswa" value="L"> Laki-laki';
											}
											?>
										</label>&nbsp;&nbsp;
										<label>
											<?php
											if ($record['jkSiswa'] == 'P') {
												echo '<input type="radio" name="jkSiswa" value="P" checked> Perempuan';
											} else {
												echo '<input type="radio" name="jkSiswa" value="P"> Perempuan';
											}
											?>
										</label>
									</div>
								</div>
								<br>
								<div class="col-md-6">
									<label>Tempat Lahir</label>
									<input name="tmptLahir" type="text" class="form-control" placeholder="Tempat Lahir" ">
								</div>
								<br>
								<div class="col-md-6">
									<label>Tanggal Lahir </label>
									<div class="input-group date date-picker" data-date="" data-date-format="yyyy-mm-dd">
										<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
										<input class="form-control" type="text" name="tglLahir" readonly="readonly" placeholder="Tanggal" value="<?php if ($record[tglLahirSiswa] == '0000-00-00') {
																																						echo '';
																																					} else {
																																						echo $record[tglLahirSiswa];
																																					} ?>">
									</div>
								</div>
								<div class="col-md-6">
									<label>Agama</label>

									<select class="form-control" name="agamaSiswa">
										
										<option value="Islam">Islam</option>
										<option value="Katolik">Katolik</option>
										<option value="Protestan">Protestan</option>
										<option value="Hindu">Hindu</option>
										<option value="Budha">Budha</option>
									</select>

								</div>
								<br>

								<br><br><br><br><br><br><br>
						</div>
						<div class="tab-pane " id="tab_2">
							<div class="col-sm-6">
								<label>NIS <small data-toggle="tooltip" title="" data-original-title="Wajib diisi">*</small></label>
								<input name="nisSiswa" type="text" class="form-control" placeholder="NIS Siswa" >
							</div>
							<div class="col-sm-6">
								<label>NISN <small data-toggle="tooltip" title="" data-original-title="Wajib diisi"></small></label>
								<input name="nisnSiswa" type="text" class="form-control" placeholder="NISN Siswa" >
							</div>
							<div class="col-md-6">
								<label>Level</label>

								<select class="form-control" name="level">

									<option value="siswa">Siswa</option>
									<option value="ketuakelas">Ketua Kelas</option>

								</select>

							</div>
							<div class="col-md-6">
								<label>Kelas</label>

								<select name="idKelas" class="form-control">
									<?php
									$sqk = mysqli_query($conn, "SELECT * FROM kelas_siswa ORDER BY idKelas ASC");
									while ($k = mysqli_fetch_array($sqk)) {
										$selected = ($k['idKelas'] == $record['idKelas']) ? ' selected="selected"' : "";

										echo '<option value="' . $k['idKelas'] . '" ' . $selected . '>' . $k['nmKelas'] . '</option>';
									}
									?>
								</select>

							</div>
							<div class="col-md-6">
								<label>Sekolah Asal</label>

								<input type="text" name="sekolah" class="form-control" placeholder="">

							</div>

							<div class="col-md-6">
								<label>Status</label>

								<select class="form-control" name="statusSiswa">
									<option value="Aktif"> Aktif</option>
									<option value="Non Aktif">Non Aktif</option>
									<option value="Drop Out">Drop Out</option>
									<option value="Pindah">Pindah</option>
									<option value="Lulus">Lulus</option>
								</select>
							</div>
							<div class="col-md-6">
								<label>Username</label>

								<input type="text" name="username" class="form-control" placeholder="">

							</div>
							<div class="col-md-6">
								<label>Password</label>

								<input type="text" name="password" class="form-control" placeholder="">
							</div>
							<br><br><br><br><br><br><br><br><br><br><br><br>
						</div>
						<div class="tab-pane " id="tab_3">

							<div class="col-sm-6">
								<label>Status Dalam Keluarga</label>

								<input type="text" name="statusKeluarga" class="form-control" placeholder="">

							</div>
							<div class="col-sm-6">
								<label>Anak Ke</label>

								<input type="text" name="anakKe" class="form-control" placeholder="">

							</div>

							<div class="col-md-6">
								<label>Alamat</label>

								<input type="text" name="alamat" class="form-control" placeholder="" required>

							</div>
							<div class="col-md-3">
								<label>No.Hp Ortu</label>

								<input type="text" name="noHp" class="form-control" placeholder="" required>

							</div>
							<div class="col-md-3">
								<label>No.Hp Siswa</label>

								<input type="text" name="noHpSis" class="form-control" placeholder="" required>

							</div>
							<div class="col-md-6">
								<label>Nama Ayah</label>

								<input type="text" name="nmOrtu" class="form-control" placeholder="">

							</div>
							<div class="col-md-6">
								<label>Nama Ibu</label>

								<input type="text" name="nmOrtuIbu" class="form-control" placeholder="">

							</div>


							<br><br><br><br><br><br><br><br><br>
						</div>

					</div>

				</div>
				<p style="color:#9C9C9C;margin-top: 5px"><i>*) Field Wajib Diisi</i></p>
			</div>
		</div>
	</div>
	<div class="col-md-3">
		<div class="box box-success">
			<div class="box-body">
				<label>Status</label>
				<div class="radio">
					<label>
						<?php
						if ($record['statusSiswa'] == 'Non Aktif') {
							echo '<input type="radio" name="statusSiswa" value="Non Aktif" checked> Tidak Aktif';
						} else {
							echo '<input type="radio" name="statusSiswa" value="Non Aktif" checked> Tidak Aktif';
						}
						?>
					</label>
				</div>
				<div class="radio">
					<label>
						<?php
						if ($record['statusSiswa'] == 'Aktif') {
							echo '<input type="radio" name="statusSiswa" value="Aktif" checked> Aktif';
						} else {
							echo '<input type="radio" name="statusSiswa" value="Aktif"> Aktif';
						}
						?>
					</label>
				</div>
				<div class="radio">
					<label>
						<?php
						if ($record['statusSiswa'] == 'Lulus') {
							echo '<input type="radio" name="statusSiswa" value="Lulus" checked> Lulus';
						} else {
							echo '<input type="radio" name="statusSiswa" value="Lulus"> Lulus';
						}
						?>
					</label>
				</div>
				<div class="radio">
					<label>
						<?php
						if ($record['statusSiswa'] == 'Pindah') {
							echo '<input type="radio" name="statusSiswa" value="Pindah" checked> Pindah';
						} else {
							echo '<input type="radio" name="statusSiswa" value="Pindah"> Pindah';
						}
						?>
					</label>
				</div>
				<div class="radio">
					<label>
						<?php
						if ($record['statusSiswa'] == 'Drop Out') {
							echo '<input type="radio" name="statusSiswa" value="Drop Out" checked> Drop Out';
						} else {
							echo '<input type="radio" name="statusSiswa" value="Drop Out"> Drop Out';
						}
						?>
					</label>
				</div>
				<br>

				<label>Foto</label>

				<a href="#" class="thumbnail">
					<img src="<?= 'foto_siswa/' . $record[foto] ?>" id="target" alt="Choose image to upload" class="img-thumbnail img-responsive">
				</a>
				<input type="file" class="form-control form-control-sm" name="fotoSiswa" id="foto" accept=".png, .jpg, .jpeg">



				<br>
				<button name="tambah" type="submit" value="Simpan" class="btn btn-block btn-success">Simpan</button>
				<a href="index.php?view=<?= $_GET[view] ?>" class="btn btn-block btn-danger">Batal</a>
			</div>
		</div>


		</form>


	<?php
} elseif ($_GET[act] == 'import') {
	?>
		<div class="col-md-12">
			<div class="box box-warning">
				<div class="box-header with-border">
					<h3 class="box-title"> Import Data Siswa</h3>
				</div><!-- /.box-header -->
				<div class="box-body">
					<?php
					//jika tombol import ditekan
					if (isset($_POST['prosesimport'])) {

						$target = "temp/" . basename($_FILES['fileSiswa']['name']);
						move_uploaded_file($_FILES['fileSiswa']['tmp_name'], $target);

						$data = new Spreadsheet_Excel_Reader("temp/" . $_FILES['fileSiswa']['name'], false);

						//  menghitung jumlah baris file xls
						$baris = $data->rowcount($sheet_index = 0);

						//    import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
						for ($i = 2; $i <= $baris; $i++) {
							// membaca data (kolom ke-1 sd terakhir)
							$nis 		= $data->val($i, 1);
							$nisn   	= $data->val($i, 2);
							$nama  	= $data->val($i, 3);
							$jk  		= $data->val($i, 4);
							$agama  	= $data->val($i, 5);
							$idkelas 	= $data->val($i, 6);
							$alamat = $data->val($i, 7);
							$noHp 	= $data->val($i, 8);
							$nmOrtu 	= $data->val($i, 9);
							$username	= $data->val($i, 10);
							$password	= $data->val($i, 11);
							$noHpSis 	= $data->val($i, 12);
							$level		=	'siswa';
							// setelah data dibaca, masukkan ke tabel pegawai sql
							$hasil = mysqli_query($conn, "INSERT INTO siswa(nisSiswa,nisnSiswa,nmSiswa,jkSiswa,level,agamaSiswa,idKelas,alamatOrtu,noHpOrtu,noHpSis,nmOrtu,username,password) 
							VALUES('$nis','$nisn','$nama','$jk','$level','$agama','$idkelas','$alamat','$noHp','$noHpSis','$nmOrtu','$username','$password')");
						}

						if (!$hasil) {
							//          jika import gagal

							echo "<div class='alert alert-danger' role='alert'>
						Data Gagal Diimport....!<br>" . die(mysql_error()) . "
						</div>";
						} else {
							//          jika impor berhasil
							echo "<div class='alert alert-success' role='alert'>
						Data Berhasil Diimport....!
						</div>";
						}

						//    hapus file xls yang udah dibaca
						unlink("temp/" . $_FILES['fileSiswa']['name']);
					}
					?>

					<form method="POST" action="" class="form-horizontal" onSubmit="return validateForm()" enctype="multipart/form-data">
						<div class="form-group">
							<label for="" class="col-sm-4 control-label">Download Format Data Siswa</label>
							<div class="col-sm-8">
								<a href="./files/formatdatasiswa.xls" class="btn btn-info">formatdatasiswa.xls</a>
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-4 control-label">Pilih File Excel (.xls / Format Excel 2003)</label>
							<div class="col-sm-8">
								<input type="file" name="fileSiswa" class="form-control" id="fileSiswa" placeholder="" required>
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-4 control-label"></label>
							<div class="col-sm-8">
								<input type="submit" name="prosesimport" value="Proses Import" class="btn btn-success">
								<a href="index.php?view=siswa" class="btn btn-default">Cancel</a>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			//    validasi form (hanya file .xls yang diijinkan)
			function validateForm() {
				function hasExtension(inputID, exts) {
					var fileName = document.getElementById(inputID).value;
					return (new RegExp(' (' + exts.join('|').replace(/\./g, '\\.') + ')$')).test(fileName);
				}

			}
		</script>
	<?php
}
	?>

	<script type="text/javascript">
		function readURL(input) {
			if (input.files && input.files[0]) {
				var reader = new FileReader();
				reader.onload = function(e) {
					$('#target').attr('src', e.target.result);
				};

				reader.readAsDataURL(input.files[0]);
			}
		}

		$("#foto").change(function() {
			readURL(this);
		});
	</script>