<?php session_start();
	include_once ("../../functions/init.php"); 
	include_once ($thisUrl."adm1n/functions/access.php");
	include_once ($thisUrl."adm1n/functions/koneksi.php");
	include_once ($thisUrl."functions/indonesian_date.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<?php
		include_once ($thisUrl."adm1n/functions/head_section.php");
		?>
    </head>	
	<body>
    	<div class="se-pre-con"></div>
		<center>
			<table width="1024">
				<tr valign="top">
					<td width="207" class="bg">
						<?php 
						$tmp = $thisUrl."adm1n/functions/kiri.php";
						include ($tmp);
						?>
					</td>
					<td width="10"></td>
					<td width="807">
						<?php 
						$tmp = $thisUrl."adm1n/functions/logo.php";
						include ($tmp);
						
						$tmp = $thisUrl."adm1n/functions/getUrl.php";
						include ($tmp);
						
						$tmp = $thisUrl."adm1n/functions/php_functions.php";
						include ($tmp);

						echo '<div>'.$txt_legend.'</div>';

						$tmp = $thisUrl."adm1n/functions/request_data.php";
						include ($tmp);
						
						$export = 0;
						$action = (isset($_POST["action"])? $_POST["action"] : null);
						$laporan = (isset($_POST["laporan"]) ? $_POST["laporan"] : null);
						if ($action == "GenerateReport") {							
							$remark = (isset($_POST["remark"]) ? $_POST["remark"] : null); 
							$pic = (isset($_POST["pic"]) ? $_POST["pic"] : null); 
							
							//echo "<br>date_start".$date_start;
							//echo "<br>date_end".$date_end;	

							$jenis_transaksi = (isset($_POST["jenis_transaksi"]) ? $_POST["jenis_transaksi"] : null);
							if ($jenis_transaksi) {
								$_transaksi = '';
								foreach ($jenis_transaksi as $arr) {
									if ($_transaksi) $_transaksi .= ',';
									$_transaksi .= $arr;
								}
								//$jenis_transaksi = $_transaksi;
							} else {
								$_transaksi = (isset($_POST["_transaksi"]) ? $_POST["_transaksi"] : null);
								if ($_transaksi) {
									$jenis_transaksi = explode(',',$_transaksi);
								}
							}
							//echo "<br>jenis_transaksi: ".$jenis_transaksi;

							$row1 = '';
							$sql7 =
							" SELECT laporanNama FROM kd_laporan ".
							" WHERE laporanTarget = '$laporan' ";
							if ($hasil7 = mysqli_query($conn, $sql7)) {
								while ($data7 = mysqli_fetch_array($hasil7)) {
									$row1 = $data7["laporanNama"];
								}
							}
							$row2 = 'Periode: '.indonesian_date($date_start).' sampai dengan '.indonesian_date($date_end);
							if (isset($jenis_transaksi) != null)
								$row3 = 'Filter by Jenis Transaksi';
							else 
								$row3 = null;

							$type_hidden = '
							<input type="hidden" name="action" id="action" value="'.$action.'" />
							<input type="hidden" name="laporan" id="laporan" value="'.$laporan.'" />
							<input type="hidden" name="data_start" id="date_start" value="'.$date_start.'" />
							<input type="hidden" name="data_end" id="date_end" value="'.$date_end.'" />
							<input type="hidden" name="remark" id="remark" value="'.$remark.'" />
							<input type="hidden" name="pic" id="pic" value="'.$pic.'" />
							<input type="hidden" name="_transaksi" value="'.$_transaksi.'" />
							<input type="hidden" name="row1" value="'.$row1.'" />
							<input type="hidden" name="row2" value="'.$row2.'" />
							<input type="hidden" name="row3" value="'.$row3.'" />';
							
							echo '
							<div style="display:block; margin-top:10px">	
								<div style="display:inline-block; text-align:left; margin-top:10px">	
									<form name="formExport" id="formExport" class="form" action="export_.php" method="post">
										'.$type_hidden.'
										<input type="submit" name="ExportReport" id="ExportReport" class="menu-box" value="Export to Excell" style="width:160px; font-size:14px; line-height:24px">
									</form>
								</div>
								<div style="display:inline-block; text-align:left; margin-top:10px">	
									<form name="formExport2" id="formExport2" class="form" action="export_save.php" method="post">
										'.$type_hidden.'
										<input type="submit" name="ExportReport2" id="ExportReport2" class="menu-box" value="Export to Excell Alt 2" style="width:180px; font-size:14px; line-height:24px">
									</form>
								</div>
							</div>';
							echo '
							<div style="display:block;  margin:10px 0px; clear:all;">';
								//echo '<p>Laporan: '.$laporan.'</p>';
								include_once (__DIR__ . "/component.php");
								include ($laporan);
								//echo $laporan;	
								echo '
							</div>';
						} else {
							echo '						
							<form name="formLaporan" id="formLaporan" class="form" action="'.$thisPage.'adm1n/'.$curPage1.'" method="post">
								<div style="margin-top:20px; padding-bottom:5px">
									<strong>Pilih Laporan</strong>
								</div>';
								$sql = 
								"SELECT * FROM kd_laporan ";
								if ($hasil = mysqli_query($conn, $sql)) {
									if (mysqli_num_rows($hasil) > 0) {
										echo '
										<select name="laporan" id="laporan">
											<option value=""> - Select Report - </option>';
											while ($data = mysqli_fetch_array($hasil)) {
												echo '
												<option value="'.$data["laporanTarget"].'">'.$data["laporanNama"].'</option>';
											}
											echo '
										</select>';
									}
								}
								echo '
								<div style="margin-top:20px; padding-bottom:5px">
									<strong>Pilih Tanggal</strong>
								</div>';
								echo '
								<table width="100&" cellpadding=0; cellspacing=0>
									<tr>
										<td style="padding-right:10px"><strong>Dari</strong></td>
										<td>
											<select name="fromMonth">
												<option value=""> - Pilih - </option>';													
												foreach ($bulan as $key => $value) {
													$fromSelected = "";
													if($fromMonth) {
														if ($fromMonth == $value)
															$fromSelected = " selected ";
													} else {
														if ($month == $value)
															$fromSelected = " selected ";
													}
													echo '
													<option class="cssForm" "'.$fromSelected.'" value="'.$value.'">'.$key.'</option>';
												}
												echo '
											</select>
										</td>
										<td>
											<select name="fromDay">
												<option value=""> - Pilih - </option>';
												for($i=1; $i<=31; $i++) {
													$fromSelected = "";
													if($fromDay) {
														if ($fromDay == $i)
															$fromSelected = " selected ";
													} else{
														if ($day == $i)
															$fromSelected = " selected ";
													}
													echo '
													<option "'.$fromSelected.'" value="'.$i.'">'.sprintf('%02d', $i).'</option>';
												}
											echo '
											</select>									
										</td>
										<td style="padding-left:10px; padding-right:10px"><strong>Sampai</strong></td><td>
											<select name="toMonth">
												<option value=""> - Pilih - </option>';													
												foreach ($bulan as $key => $value) {
													$fromSelected = "";
													if($fromMonth) {
														if ($fromMonth == $value)
															$fromSelected = " selected ";
													} else {
														if ($month == $value)
															$fromSelected = " selected ";
													}
													echo '
													<option class="cssForm" "'.$fromSelected.'" value="'.$value.'">'.$key.'</option>';
												}
												echo '
											</select>
										</td>
										<td>
											<select name="toDay">
												<option value=""> - Pilih - </option>';
												for($i=1; $i<=31; $i++) {
													$fromSelected = "";
													if($fromDay) {
														if ($fromDay == $i)
															$fromSelected = " selected ";
													} else{
														if ($day == $i)
															$fromSelected = " selected ";
													}
													echo '
													<option "'.$fromSelected.'" value="'.$i.'">'.sprintf('%02d', $i).'</option>';
												}
												echo '
											</select>									
										</td>											
									</tr>
								</table>';
								
								echo '
								<div style="margin-top:20px; padding-bottom:5px">
									<strong>Jenis Transaksi</strong>
								</div>
								<div class="display:block;">
									<table><tr>';
									$sql7 = 
									' SELECT * FROM form_element_value '.
									' WHERE elementSubParentID = 92 '.
									' AND valueID not in (1220, 1214, 1219) '.
									' ORDER BY valueName';
									$Others = ''; $ctr=0;
									if ($hasil7 = mysqli_query($conn, $sql7)) {
										while ($data7 = mysqli_fetch_array($hasil7)) {
											$ctr++;
											if ($ctr%4==0) echo '</tr><tr style="height:5px"><td></td></tr><tr>';
											$cek_button = '
											<td style="padding-right:20px">
												<input type="checkbox" name="jenis_transaksi[]" value="'.$data7["valueID"].'"> '.$data7["valueName"].'</input>
											</td>';
											if (strtolower($data7["valueName"]) == strtolower('Others')) {
												$Others = $cek_button;
											} else {
												echo $cek_button;
											}
										}
									}
									echo $Others.'</tr></table>';
									echo '
								</div>';
								echo '
								<div style="margin-top:20px; padding-bottom:5px">
									<strong>Including</strong>
								</div>
								<div class="display:block;">
									<table cellpadding="0" cellspacing="0">
										<tr>
											<td style="padding-right:20px">
												<input type="checkbox" name="remark" value="on"> Remark</input>
											</td>
											<td style="padding-right:20px">
												<input type="checkbox" name="pic" value="on"> PIC</input>
											</td>
										</tr>
									</table>
								</div>';
								echo '
								<div style="display:block; margin-top:35px; border-top:1px solid #999999"></div>
								<div style="display:block; margin-top:15px; margin-bottom:15px">
									<div id="submitformLaporan" class="hvr-sweep-to-right" style="padding:10px 30px; cursor:pointer;">
										<font style="color:#ffffff; text-align:center"	>
											Generate Report >>
										</font>
									</div>
									<input type="hidden" name="action" id="action" value="GenerateReport" />
								</div>
							</form>';
						}
						?>
					</td>
				</tr>
			</table>
		</center>
	</body>
</html>	