<?php
include "config/conn.php";
if($_POST['btncari']=="Search") {
	$tglf=$_POST['tglf'];
	$tgls=$_POST['tgls'];
} else { 
	$tglf= date('Y-m-d');
	$tgls = date('Y-m-d',strtotime('-1 day',strtotime($tglf))) ;
}
$sql="SELECT * from t_pemohon_ka WHERE pemohon_asal_bbws=".$_SESSION['id_bbws']." ORDER BY pemohon_tgl_input DESC";
$query=mysql_query($sql);

if($_POST['simpan']=="Simpan"){
		$id_debit=strip_tags($_POST['id_debit']);
		$tahun_debit=$_POST['tahun_debit'];
		$ibbws=trim($_POST['ibbws']);
		$id_lokasi=strip_tags($_POST['id_lokasi']);
		$nilai_a=strip_tags($_POST['nilai_a']);
		$nilai_b=strip_tags($_POST['nilai_b']);
		$nilai_c=strip_tags($_POST['nilai_c']);

		if ($id_debit=="") {
			$sqlinsertmdebit="INSERT INTO m_debit values('','$ibbws','$id_lokasi','$tahun_debit','$nilai_a','$nilai_b','$nilai_c')";
		    $query=mysql_query($sqlinsertmdebit);
			if($query){
				echo "<script>alert('Input hasil debit berhasil disimpan!');history.go(-1);</script>";
			}
		} else {
		$sql="UPDATE m_debit SET id_bbws='$ibbws', id_lokasi='$id_lokasi',tahun_debit='$tahun_debit',nilai_a='$nilai_a',nilai_b='$nilai_b',nilai_c='$nilai_c' WHERE id_debit='$id_debit'";			
		$query=mysql_query($sql);
			if($query){
				echo"<script>alert('Update data debit berhasil !');history.go(-1);</script>";
			}
		}
}
?>
					<link rel="stylesheet" href="https://cdn.datatables.net/1.11.0/css/dataTables.bootstrap5.min.css">
					<!--//Page Toolbar//-->
                    <div class="toolbar pt-4 px-4 px-lg-8">
                        <div class="position-relative container-fluid px-0">
                            <div class="row align-items-center position-relative">
                                <div class="col-md-7">
                                    <h3 class="mb-2">Permohonan Data </h3>

                                    <!--nav aria-label="breadcrumb">
                                        <ol class="breadcrumb mb-0">
                                            <li class="breadcrumb-item"><a href="index.html">Home</a></li>
                                            <li class="breadcrumb-item active">UI Components</li>
                                            <li class="breadcrumb-item active">Feather Icons</li>
                                        </ol>
                                    </nav-->
                                </div>
                                <div class="col-md-5 text-md-end">
                                  <div class="d-flex justify-content-sm-end align-items-center">
                                    <div class="d-flex align-items-center">
                                      <button type="button" class="btn btn-info mb-2 me-2" data-bs-toggle="modal" data-bs-target="#newform"><i data-feather="plus"></i>&nbsp; Tambah Permohonan</button>
                                    </div>
                                  </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--//Page Toolbar End//-->

                    <!--//Page content//-->
                    <div class="content pt-4 px-4 px-lg-8 d-flex flex-column-fluid">
                        <div class="container-fluid px-0">
                            <div class="row">
                                <div class="col-12 mb-4">
                                    <div class="row">
                                        <div class="col-12 mb-4">
                                            <div class="card">
                                                <div class="table-responsive">
					                                <table id="datatable" class="table mt-0 table-striped table-card table-nowrap"><?php //var_dump($_SESSION['id_bbws']); ?>
					                                    <thead class="text-uppercase small text-muted">
					                                        <tr>
					                                            <th class="mc">No</th>
					                                            <th class="mc">Nama</th>
					                                            <th class="mc">Status</th>
					                                            <th class="mc">Instansi</th>
					                                            <th class="mc">Alamat</th>
					                                            <th class="mc">No.Telp</th>
					                                            <th class="mc">Email</th>
					                                            <th class="mc">Tanggal Permohonan</th>
					                                            <th class="mc">Status</th>
					                                            <th class="mc">File</th>
					                                            <th class="mc">Aksi</th>
					                                        </tr>
					                                    </thead>
					                                    <tbody>
				                                    	<?php
				                                    	$i = 1;
					                                    while($row=mysql_fetch_array($query)){
					                                    	if(strlen($row['pemohon_instansi_alamat']) > 20){
					                                    		$pemohon_instansi_alamat = substr($row['pemohon_instansi_alamat'], 0, 20).'...';
					                                    	}else{
					                                    		$pemohon_instansi_alamat = $row['pemohon_instansi_alamat'];
					                                    	}

					                                    	if($_SESSION['id_bbws'] == '8'){
					                                    		$file = '<a href="http://bbwscitanduy.sdatelemetry.com/upload/filepemohon/'.$row['pemohon_surat_file'].'" target="_blank"><i data-feather="file-text"></i></a>';
					                                    	}else{
					                                    		$file = '&nbsp;';
					                                    	}
					                                    ?>
					                                        <tr>
					                                            <td class="tc"><?php echo $i; ?></td>
					                                            <td class="tl"><?php echo $row['pemohon_nama']; ?></td>
					                                            <td class="tl"><?php echo $row['pemohon_jabatan']; ?></td>
					                                            <td class="tl"><?php echo $row['pemohon_instansi']; ?></td>
					                                            <td class="tl"><?php echo $pemohon_instansi_alamat; ?></td>
					                                            <td class="tc"><?php echo $row['pemohon_hp']; ?></td>
					                                            <td class="tl"><?php echo $row['pemohon_email']; ?></td>
					                                            <td class="tc"><?php echo substr($row['pemohon_tgl_input'], 0, 10).'<br/>'.substr($row['pemohon_tgl_input'], 11, 5); ?></td>
					                                            <td class="tc">&nbsp;</td>
					                                            <td class="tc"><?php echo $file; ?></td>
					                                            <td class="tc">
					                                            	<i class="text-warning" data-feather="edit" data-bs-toggle="modal" data-bs-target="#editform" style="cursor: pointer;"></i>
					                                            </td>
					                                        </tr>
					                                    <?php 
					                                    	$i++; 
					                                	}
					                                    ?>
					                                    </tbody>
					                                </table>
					                            </div>
					                            <!-- New Modal -->
					                            <div class="modal fade" id="newform" data-bs-backdrop="static"
	                                                data-bs-keyboard="false" tabindex="-1"
	                                                aria-labelledby="newformLabel" aria-hidden="true">
	                                                <div class="modal-dialog modal-lg">
	                                                    <div class="modal-content">
	                                                        <div class="modal-header">
	                                                            <h5 class="modal-title" id="editformLabel">Tambah Data Daerah Aliran Sungai</h5>
	                                                            <button type="button" class="btn-close"
	                                                                data-bs-dismiss="modal" aria-label="Close"></button>
	                                                        </div>
	                                                        <div class="modal-body">
	                                                            <div class="row">
	                                                            	<div class="col-6">
	                                                            		<div class="row">
	                                                            			<div class="col-12 mb-3">
	                                                            				<label for="new-namadas" class="form-label">Nama DAS</label>
                                                  								<input type="text" class="form-control" id="new-namadas" name="new-namadas">
	                                                            			</div>
	                                                            			<div class="col-12 mb-3">
	                                                            				<label for="new-namasungai" class="form-label">Nama Sungai</label>
                                                  								<input type="text" class="form-control" id="new-namasungai" name="new-namasungai">
	                                                            			</div>
	                                                            		</div>
	                                                            	</div>
	                                                            	<div class="col-6">
	                                                            		<div class="row">
	                                                            			<div class="col-6 mb-3">
	                                                            				<label for="new-kodedas" class="form-label">Kode DAS</label>
                                                  								<input type="text" class="form-control" id="new-kodedas" name="new-kodedas">
	                                                            			</div>
	                                                            			<div class="col-6 mb-3">
	                                                            				<label for="new-luasdas" class="form-label">Luas Darah Aliran</label>
                                                  								<input type="text" class="form-control" id="new-luasdas" name="new-luasdas" style="text-align: right;">
	                                                            			</div>
	                                                            		</div>
	                                                            	</div>
	                                                            </div>
	                                                        </div>
	                                                        <div class="modal-footer">
	                                                            <button type="button" class="btn btn-secondary"
	                                                                data-bs-dismiss="modal">Close</button>
	                                                            <button type="button"
	                                                                class="btn btn-info">Save</button>
	                                                        </div>
	                                                    </div>
	                                                </div>
	                                            </div>
					                            <!-- Edit Modal -->
	                                            <div class="modal fade" id="editform" data-bs-backdrop="static"
	                                                data-bs-keyboard="false" tabindex="-1"
	                                                aria-labelledby="editformLabel" aria-hidden="true">
	                                                <div class="modal-dialog modal-lg">
	                                                    <div class="modal-content">
	                                                        <div class="modal-header">
	                                                            <h5 class="modal-title" id="editformLabel">Ubah Data Daerah Aliran Sungai</h5>
	                                                            <button type="button" class="btn-close"
	                                                                data-bs-dismiss="modal" aria-label="Close"></button>
	                                                        </div>
	                                                        <div class="modal-body">
	                                                            <div class="row">
	                                                            	<div class="col-6">
	                                                            		<div class="row">
	                                                            			<div class="col-12 mb-3">
	                                                            				<label for="edit-namadas" class="form-label">Nama DAS</label>
                                                  								<input type="text" class="form-control" id="edit-namadas" name="edit-namadas">
	                                                            			</div>
	                                                            			<div class="col-12 mb-3">
	                                                            				<label for="edit-namasungai" class="form-label">Nama Sungai</label>
                                                  								<input type="text" class="form-control" id="edit-namasungai" name="edit-namasungai">
	                                                            			</div>
	                                                            		</div>
	                                                            	</div>
	                                                            	<div class="col-6">
	                                                            		<div class="row">
	                                                            			<div class="col-6 mb-3">
	                                                            				<label for="edit-kodedas" class="form-label">Kode DAS</label>
                                                  								<input type="text" class="form-control" id="edit-kodedas" name="edit-kodedas">
	                                                            			</div>
	                                                            			<div class="col-6 mb-3">
	                                                            				<label for="edit-luasdas" class="form-label">Luas Darah Aliran</label>
                                                  								<input type="text" class="form-control" id="edit-luasdas" name="edit-luasdas" style="text-align: right;">
	                                                            			</div>
	                                                            		</div>
	                                                            	</div>
	                                                            </div>
	                                                        </div>
	                                                        <div class="modal-footer">
	                                                            <button type="button" class="btn btn-secondary"
	                                                                data-bs-dismiss="modal">Close</button>
	                                                            <button type="button"
	                                                                class="btn btn-info">Save</button>
	                                                        </div>
	                                                    </div>
	                                                </div>
	                                            </div>
                                            </div>
                                        </div>
                                    </div>
                                    

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