<?php echo $this->extend('/template'); ?>
<?php echo $this->section('content') ?>

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<title>Impor Pemudik Excell</title>
</head>

<body>
	<?php
	$s = 0; //nomor sheet
	$dt['head']['wilayah_id'] = 0;
	?>

	<div class="container">
		<h3>
			<img src="<?php echo base_url(); ?>/assets/images/pemprovsmr/header_icon.png" width="35px">&nbsp;<b>IMPOR EXCELL DATA PEMUDIK</b>
		</h3>

		<div class="row">
			<div class="col-sm-6">
				<form id="fm" method="post" enctype="multipart/form-data" action="/impxls2025/<?php echo $data['balik']; ?>">
					<input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>" />
					<input type="hidden" name="ok" value="1">
					<div class="form-group">
						<input type="file" name="fileexcel" class="form-control" id="file" required accept=".xls, .xlsx" /></p>
					</div>
					<button class="btn btn-primary" type="submit">IMPOR</button>
					<!--
					<div class="fitem">
						<input class="easyui-textbox" id="nobus" name="nobus" style="width:50%" label="Nomor Bus" value='<?php //echo $data[$s]['head']['nobus']; ?>'><br />
						<input class="easyui-textbox" id="tujuan" name="tujuan" style="width:50%" label="Tujuan" value='<?php echo $data[$s]['head']['wilayah_nama']; ?>'>
						<input type="hidden" name="wilayah_id" id="wilayah_id">

					</div>
				-->
				</form>

			</div>
			<div class="col-sm-6">
				<i>Sila unduh format standar excel isian data pemudik :</i><BR />
				<a href="assets/FORMAT_STANDAR_PEDAMATENG_SAMPLE.xls" target="_blank">FORMAT STANDAR EXCEL DATA PEMUDIK</a>

			</div>

			<?php

			for ($s = 0; $s <= $data['jmlsheet'] - 1; $s++) {
				$i = 1;

				if (sizeof($data[$s]['isi']) > 0) {
					echo '<div class="row"><div class="col-sm-9">';
					echo '<i><h4><b>Catatan Hasil Pembacaan dan Pemeriksaan:</b></h4>';

					if ($data[$s]['head']['wilayah_id'] == 0) {
						echo "<div style='color:red;font-size:20px'>DATA TUJUAN TIDAK TERDETEKSI, Sila Periksa kolom TUJUAN di Excell agar bisa meneruskan proses impor</div>";
					} else {
						echo '<h2>';
						echo 'SHEET : ' . ($s + 1);
						echo '<br/>TUJUAN : ' . $data[$s]['head']['wilayah_nama'];
						// echo '<br/>NO BUS :' . $data[$s]['head']['nobus'];
						echo '</h2>';
						//echo '<pre>';print_r($data[$s]['head']); echo '</pre>';
					}
					echo 'Periksa tabel berikut sebelum menekan tombol "YA, IMPOR", terutama baris yang bewarna abu atau merah<br/>';
					echo 'Update Excell untuk pembetulan<br/>';
					echo 'Jika tombol "YA, IMPOR" ditekan, maka baris2 data bewarna tidak akan tersimpan<br/><br/></i>';

					echo '</div><div class="col-sm-3"><br/>';
					echo '<a href="#" onclick="simpanxls22025('.$s.','.$data[$s]['head']['wilayah_id'].')"><button class="btn-primary" style="width:100px;height:50px">YA IMPOR</button></a>';
					echo '</div></div>';
					echo '<table class="table">';
					echo '<tr><th>NO</th><th>GRUP</th><th>NIK</th><th>NAMA</th><th>TEMPAT LAHIR</th><th>USIA</th><th>NO TELP</th><th>TUJUAN</th><th>TUJUAN<BR/>TERBACA</th><th>KETERANGAN</th></tr>';

					foreach ($data[$s]['isi'] as $k => $v) {
						if (strpos($v[11], 'NIK') !== false) echo '<tr style="background-color:#f79b9b;font-weight:bold">';
						else if ($v[10] == '') echo '<tr style="background-color:#ddd">';

						else echo '<tr>';
						echo '<td>' . $i . '</td>';
						echo '<td>' . $v[1] . '</td>';
						echo '<td>' . $v[2] . '</td>';
						echo '<td>' . $v[3] . '</td>';
						echo '<td align="center">' . $v[4] . '</td>';
						echo '<td>' . $v[5] . '</td>';
						echo '<td>' . $v[6] . '</td>';
						echo '<td>' . $v[7] . '</td>';
						echo '<td>' . $v[10] . '</td>';
						echo '<td>' . $v[11] . '</td>';
						echo '</tr>';
						$i++;
					}
					echo '</table>';
				}
			} //for $s sejumlah sheet
			?>



		</div>



	</div>
</body>
<script>
	function prosessheet() {
		$('#fm').submit();

	}

	function simpanxls22025(s,wid) {
		if (wid == 0) {
			alert('Tujuan Invalid');
			return;
		}
		$.ajax({
			type: 'post',
			url: "/simpanxls22025",
			data: {
				"<?= csrf_token() ?>": "<?= csrf_hash() ?>",
				data: '<?php echo json_encode($data); ?>',
				s : s,
				balik : '<?php echo ISMUDIKORBALIK; ?>'
			},
			success: function(data) {
				var respon = $.parseJSON(data);
				//console.log(respon);
				alert('DATA BERHASIL DI IMPOR DAN TERSIMPAN DI DATABASE. SILA CEK DI MENU CALON PEMUDIK');
			}

		});

	}
</script>
<style>
	table.table th {
		background-color: #444;
		color: #fff;
	}
</style>



</html>
<?php echo $this->endSection() ?>