<?php

header("X-Content-Type-Options: nosniff");
header("X-XSS-Protection: 1; mode=block");
header("X-Frame-Options: DENY");
header('Expires: Sun, 01 Jan 2000 00:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');

ini_set('session.cookie_httponly', 'on');
ini_set('session.cookie_secure', 'on');

session_name("SIGNADMAUTH");
session_start();

include "common/config/config.php";
include "common/config/dbconfig.php";
include "common/functions/funcconnect.php";
include "common/functions/funcvalidateinput.php";
include "common/functions/funcauthen.php";
openDB();

if (!authen())
{ header ("location: login.php");
		}
else
{ $idpesanan=isset($_GET['idp']) ? cleanval($_GET['idp']) : NULL;
		$nomorpesanan=isset($_GET['oid']) ? base64_decode(cleanval($_GET['oid'])) : NULL;
		$qord="SELECT *
									FROM $db_pesanan
									WHERE idpesanan='".$idpesanan."'
															AND nomorpesanan='".$nomorpesanan."'
															AND statusorder<4
									";
		$rord=mysqli_query($dbConnection, $qord);
		if (mysqli_num_rows($rord)>0)
		{ $dord=mysqli_fetch_array($rord);
				// ini bisa lebih dari 1 (satu) item !!
				$qoi="SELECT a.iditem,
																	b.kodekategoribarang, b.namakategoribarang,
																	c.*,
																	d.*,
																	e.*,
																	f.*,
																	g.*,
																	h.*,
																	i.*
										FROM $db_pesanandetail i
										INNER JOIN $db_item a ON i.iditem=a.iditem
										INNER JOIN $db_kategoribarang b ON a.idkategoribarang=b.idkategoribarang
										INNER JOIN $db_merek c ON a.idmerek=c.idmerek
										INNER JOIN $db_model d ON a.idmodel=d.idmodel
										INNER JOIN $db_warna e ON a.idwarna=e.idwarna
										INNER JOIN $db_thnproduksi f ON a.idthnproduksi=f.idthnproduksi
										INNER JOIN $db_itemprice g ON d.idmodel=g.idmodel AND i.iditemprice=g.iditemprice
										INNER JOIN $db_wilayahotr h ON g.idwilayahotr=h.idwilayahotr
										WHERE i.nomorpesanan='".$dord['nomorpesanan']."'
																AND i.sesipesanan='".$dord['sesipesanan']."'
										ORDER BY i.idpesanandetail DESC
										";
				$roi=mysqli_query($dbConnection, $qoi);
				// echo $qoi."<br><br>".mysqli_error($dbConnection)."<br><br>";
				// exit;
				$dataproduk="<table border='0' cellspacing='0' cellpadding='0'>
																		<tr>
																			<td></td>
																			<td align='left' valign='middle' style='padding:0'>
																				<b>Qty</b>
																			</td>
																			<td align='left' valign='middle' style='padding:0'>
																				<b>Merek</b>
																			</td>
																			<td align='left' valign='middle' style='padding:0'>
																				<b>Model</b>
																			</td>
																			<td align='left' valign='middle' style='padding:0'>
																				<b>Warna</b>
																			</td>
																			<td align='left' valign='middle' style='padding:0'>
																				<b>Wilayah</b>
																			</td>
																			<td align='left' valign='middle' style='padding:0'>
																				<b>Tahun</b>
																			</td>
																			<td align='left' valign='middle' style='padding:0' colspan='2'>
																				<b>Harga Jual</b>
																			</td>
																			<td align='left' valign='middle' style='padding:0'>
																				<b>Diskon per Unit</b>
																			</td>
																		</tr>	
																		";
				while ($doi=mysqli_fetch_array($roi))
				{ if (empty($doi['ontheroad']))
						{ $ontrharga="";
								}
						else
						{ $ontrharga=" checked";
								}
						// merek
						$qmr="SELECT * 
												FROM $db_merek
												WHERE tersedia='1'
												ORDER BY namamerek ASC
												";
						$rmr=mysqli_query($dbConnection, $qmr);
						$merek="<select id='idmr' name='idmr' style='padding:5px' disabled>
															<option value='' selected></option>
															";
						while ($dmr=mysqli_fetch_array($rmr))
						{ if ($dmr