<?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);
				$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>	
																		";
				$enableproduk="";
				$disableproduk="";
				$qoi="SELECT b.kodekategoribarang, b.namakategoribarang,
																	c.idmerek,
																	d.idmodel,
																	e.idwarna,
																	f.idthnproduksi,
																	g.ontheroad,
																	h.idwilayahotr,
																	i.*
										FROM $db_pesanandetail i
										LEFT JOIN $db_item a ON i.iditem=a.iditem
										LEFT JOIN $db_kategoribarang b ON a.idkategoribarang=b.idkategoribarang
										LEFT JOIN $db_merek c ON a.idmerek=c.idmerek
										LEFT JOIN $db_model d ON a.idmodel=d.idmodel
										LEFT JOIN $db_warna e ON a.idwarna=e.idwarna
										LEFT JOIN $db_thnproduksi f ON a.idthnproduksi=f.idthnproduksi
										LEFT JOIN $db_itemprice g ON d.idmodel=g.idmodel AND i.iditemprice=g.iditemprice
										LEFT JOIN $db_wilayahotr h ON g.idwilayahotr=h.idwilayahotr
										WHERE i.nomorpesanan='".$dord['nomorpesanan']."'
																AND i.sesipesanan='".$dord['sesipesanan']."'
										ORDER BY i.idpesanandetail ASC
										";
				$roi=mysqli_query($dbConnection, $qoi);
				// echo $qoi."<br><br>".mysqli_error($dbConnection)."<br><br>";
				// exit;
				while($doi=mysqli_fetch_array($roi))
				{ if (empty($doi['ontheroad']))
						{ $ontrharga="";
								}
						else
						{ $ontrharga=" checked";
								}
						// merek
						$qmr="SELECT * 
												FROM $db_merek
												ORDER BY namamerek ASC
												";
						$rmr=mysqli_query($dbConnection, $qmr);
						$merek="<select id='idmr".$doi['idpesanandetail']."' name='idmr[".$doi['idpesanandetail']."]' style='padding:5px' disabled>
															<option value='' selected></option>
															";
						while ($dmr=mysqli_fetch_array($rmr))
						{ if ($dmr['idmerek']==$doi['idmerek'])
								{ $selected=" selected";
										}
								else
								{ $selected="";
										}
								$merek.="<option value='".$dmr['idmerek']."'".$selected.">".strtoupper($dmr['namamerek'])."</option>";
								}
						$merek.="</select>";
						// model
						$qmd="SELECT *
												FROM $db_model
												ORDER BY idmodel ASC
												";
						$rmd=mysqli_query($dbConnection, $qmd);
						$model="<select id='idmd".$doi['idpesanandetail']."' name='idmd[".$doi['idpesanandetail']."]' style='padding:5px' disabled>
															<option value='' selected></option>
															";
						while ($dmd=mysqli_fetch_array($rmd))
						{ if ($dmd['idmodel']==$doi['idmodel'])
								{ $selected=" selected";
										}
								else
								{ $selected="";
										}
								$model.="<option value='".$dmd['idmodel']."'".$selected.">".strtoupper($dmd['namamodel'])."</option>";
								}
						$model.="</select>";
						// warna
						$qwr="SELECT *
												FROM $db_warna
												ORDER BY idwarna ASC
												";
						$rwr=mysqli_query($dbConnection, $qwr);
						$warna="<select id='idw".$doi['idpesanandetail']."' name='idw[".$doi['idpesanandetail']."]' style='padding:5px' disabled>
															<option value='' selected></option>
															";
						while ($dwr=mysqli_fetch_array($rwr))
						{ if ($dwr['idwarna']==$doi['idwarna'])
								{ $selected=" selected";
										}
								else
								{ $selected="";
										}
								$warna.="<option value='".$dwr['idwarna']."'".$selected.">".strtoupper($dwr['namawarna'])."</option>";
								}
						$warna.="</select>";
						// wilayah
						$qwl="SELECT *
												FROM $db_wilayahotr
												ORDER BY namawilayahotr ASC
												";
						$rwl=mysqli_query($dbConnection, $qwl);
						$wilayah="<select id='idwl".$doi['idpesanandetail']."' name='idwl[".$doi['idpesanandetail']."]' style='padding:5px' disabled>
																	<option value='' selected></option>
																	";
						while ($dwl=mysqli_fetch_array($rwl))
						{ if ($dwl['idwilayahotr']==$doi['idwilayahotr'])
								{ $selected=" selected";
										}
								else
								{ $selected="";
										}
								$wilayah.="<option value='".$dwl['idwilayahotr']."'".$selected.">".strtoupper($dwl['namawilayahotr'])."</option>";
								}
						$wilayah.="</select>";
						// tahun produksi
						$qtp="SELECT *
												FROM $db_thnproduksi
												ORDER BY thnproduksi ASC
												";
						$rtp=mysqli_query($dbConnection, $qtp);
						$thnproduksi="<select id='idtp".$doi['idpesanandetail']."' name='idtp[".$doi['idpesanandetail']."]' style='padding:5px' disabled>
																					<option value='' selected></option>
																					";
						while ($dtp=mysqli_fetch_array($rtp))
						{ if ($dtp['idthnproduksi']==$doi['idthnproduksi'])
								{ $selected=" selected";
										}
								else
								{ $selected="";
										}
								$thnproduksi.="<option value='".$dtp['idthnproduksi']."'".$selected.">".strtoupper($dtp['thnproduksi'])."</option>";
								}
						$thnproduksi.="</select>";
						$dataproduk.="<tr>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						<span class='material-icons-outlined' style='color:#cfcfcf'>edit_note</span>
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						<input type='text' id='jumlahpesan".$doi['idpesanandetail']."' name='jumlahpesan[".$doi['idpesanandetail']."]' value='".$doi['jumlahpesan']."' style='width:50px; padding:5px' disabled>
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						".$merek."
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						".$model."
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						".$warna."
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						".$wilayah."
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						".$thnproduksi."
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						Rp. ".number_format($doi['hargajual'], 0, ",", ".")."
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						<input type='checkbox' id='ontr".$doi['idpesanandetail']."' name='ontr[".$doi['idpesanandetail']."]' value='1'".$ontrharga." style='vertical-align:middle; margin:0; margin-bottom:1px; padding:0' disabled>&nbsp; OTR
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						Rp. &nbsp; <input type='text' id='jumlahdiskon".$doi['idpesanandetail']."' name='jumlahdiskon[".$doi['idpesanandetail']."]' value='".intval($doi['jumlahdiskon'])."' style='width:80px; padding:5px; text-align:right' onfocus=\"this.value=''\" disabled>
																					</td>
																				</tr>
																				";
						// cek apakah ada perubahan produk yang belum disetujui
						$qoc="SELECT a.*,
																			b.kodekategoribarang, b.namakategoribarang,
																			c.*,
																			d.*,
																			e.*,
																			f.*,
																			g.*,
																			h.*,
																			i.*
												FROM $db_pdetailapproval i
												LEFT JOIN $db_item a ON i.iditem=a.iditem
												LEFT JOIN $db_kategoribarang b ON a.idkategoribarang=b.idkategoribarang
												LEFT JOIN $db_merek c ON a.idmerek=c.idmerek
												LEFT JOIN $db_model d ON a.idmodel=d.idmodel
												LEFT JOIN $db_warna e ON a.idwarna=e.idwarna
												LEFT JOIN $db_thnproduksi f ON a.idthnproduksi=f.idthnproduksi
												LEFT JOIN $db_itemprice g ON d.idmodel=g.idmodel AND i.iditemprice=g.iditemprice
												LEFT JOIN $db_wilayahotr h ON g.idwilayahotr=h.idwilayahotr
												WHERE i.nomorpesanan='".$doi['nomorpesanan']."'
																		AND i.sesipesanan='".$doi['sesipesanan']."'
																		AND i.idpesanandetail='".$doi['idpesanandetail']."'
												";
						$roc=mysqli_query($dbConnection, $qoc);
						// echo $qoc."<br>".mysqli_error($dbConnection)."<br><br>";
						// exit;
						if (mysqli_num_rows($roc)>0)
						{ while ($doc=mysqli_fetch_array($roc))
								{ if (empty($doc['ontheroad']))
										{ $ontrharga="";
												}
										else
										{ $ontrharga="OTR";
												}
										// ada data yang perlu disetujui namun belum disetujui/ditolak
										if ($doc['tolaktgl']===NULL && $doc['setujutgl']===NULL)
										{ // jika yang dimintakan persetujuan bukan pernyataan "data sudah sesuai", 
												// admin sales bisa mengajukan perubahan data baru atau membatalkan perubahan data yang sedang dimintakan persetujuan
												if ($doc['datasesuai']===NULL)
												{ $tombolsesuaiproduk="<input type='button' id='tombolprodukok' value=' Data Sesuai ' style='margin-right:6px' disabled>";
														$tombolubahproduk="<input type='button' id='tombolubahproduk' value=' Ubah Data ' disabled>";
														if ($doc['iditem']!=$doi['iditem'] || $doc['iditemprice']!=$doi['iditemprice'])
														{ $labelubahproduk="<a href='produk_ubah_batal.php?ida=".$doc['idpdetailapproval']."&idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."' alt='Batalkan Perubahan' title='Batalkan Perubahan'>
																																			<span class='material-icons-outlined' style='color:#ffcc01'>backspace</span>
																																		</a>
																																		";
																}
														else
														{ $labelubahproduk="<span class='material-icons-outlined' style='color:#ffcc01'>check_box</span>";
																}
														}
												else
												{ $tombolsesuaiproduk="<input type='button' id='tombolprodukok' value=' Data Sesuai ' style='margin-right:6px' disabled>";
														$tombolubahproduk="<input type='button' id='tombolubahproduk' value=' Ubah Data ' disabled>";
														$labelubahproduk="<span class='material-icons-outlined' style='color:#ffcc01'>check_box</span>";
														}
												}
										// ada data yang perlu disetujui dan sudah ditolak, 
										// admin sales bisa menyatakan "data sudah sesuai" atau mengajukan perubahan data
										else if ($doc['tolaktgl']!==NULL && $doc['setujutgl']===NULL)
										{ $tombolsesuaiproduk="<input type='button' id='tombolprodukok' value=' Data Sesuai ' style='cursor:pointer; margin-right:6px' onclick=\"document.location='produk_ok.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'\">";
												$tombolubahproduk="<input type='button' id='tombolubahproduk' value=' Ubah Data ' style='cursor:pointer' onclick='enableProduct()'>";
												if ($doc['tolaksebab']=="BATAL UBAH")
												{ $labelubahproduk="<span class='material-icons-outlined' style='color:#ffcc01'>disabled_by_default</span>";
														}
												else
												{ $labelubahproduk="<span class='material-icons-outlined' style='color:#ff5475'>disabled_by_default</span>";
														}
												}
										// ada data yang perlu disetujui dan sudah disetujui, tidak bisa melakukan perubahan data lagi
										else if ($doc['tolaktgl']===NULL && $doc['setujutgl']!==NULL)
										{ $tombolsesuaiproduk="<input type='button' id='tombolprodukok' value=' Data Sesuai ' style='margin-right:6px' disabled>";
												$tombolubahproduk="<input type='button' id='tombolubahproduk' value=' Ubah Data ' disabled>";
												$labelubahproduk="<span class='material-icons-outlined' style='color:#33aa88'>check_box</span>";
												}
										$dataproduk.="<tr>
																									<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																										".$labelubahproduk."
																									</td>
																									<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																										".$doc['jumlahpesan']."
																									</td>
																									<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																										".$doc['namamerek']."
																									</td>
																									<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																										".$doc['namamodel']."
																									</td>
																									<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																										".$doc['namawarna']."
																									</td>
																									<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																										".$doc['namawilayahotr']."
																									</td>
																									<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																										".$doc['thnproduksi']."
																									</td>
																									<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																										Rp. ".number_format($doc['hargajual'], 0, ",", ".")."
																									</td>
																									<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																										".$ontrharga."
																									</td>
																									<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																										Rp. ".number_format($doc['jumlahdiskon'], 0, ",", ".")."
																									</td>
																								</tr>
																								";
										}
								}
						else
						{ $tombolsesuaiproduk="<input type='button' id='tombolprodukok' value=' Data Sesuai ' style='cursor:pointer; margin-right:6px' onclick=\"document.location='produk_ok.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'\">";
								$tombolubahproduk="<input type='button' id='tombolubahproduk' value=' Ubah Data ' style='cursor:pointer' onclick='enableProduct()'>";
								}
						$enableproduk.="document.getElementById('jumlahpesan".$doi['idpesanandetail']."').disabled=false;
																						document.getElementById('idmr".$doi['idpesanandetail']."').disabled=false;
																						document.getElementById('idmd".$doi['idpesanandetail']."').disabled=false;
																						document.getElementById('idw".$doi['idpesanandetail']."').disabled=false;
																						document.getElementById('idwl".$doi['idpesanandetail']."').disabled=false;
																						document.getElementById('ontr".$doi['idpesanandetail']."').disabled=false;
																						document.getElementById('idtp".$doi['idpesanandetail']."').disabled=false;
																						document.getElementById('jumlahdiskon".$doi['idpesanandetail']."').disabled=false;
																						";
						$disableproduk.="document.getElementById('jumlahpesan".$doi['idpesanandetail']."').disabled=true;
																							document.getElementById('idmr".$doi['idpesanandetail']."').disabled=true;
																							document.getElementById('idmd".$doi['idpesanandetail']."').disabled=true;
																							document.getElementById('idw".$doi['idpesanandetail']."').disabled=true;
																							document.getElementById('idwl".$doi['idpesanandetail']."').disabled=true;
																							document.getElementById('ontr".$doi['idpesanandetail']."').disabled=true;
																							document.getElementById('idtp".$doi['idpesanandetail']."').disabled=true;
																							document.getElementById('jumlahdiskon".$doi['idpesanandetail']."').disabled=true;
																							";
						}
				$dataproduk.="</table>";
				$enableproduk.="document.getElementById('tombolprodukok').style.display='none';
																				document.getElementById('tombolubahproduk').style.display='none';
																				document.getElementById('simpanubahproduk').style.display='';
																				document.getElementById('tombolbatalubahproduk').style.display='';
																				";
				$disableproduk.="document.getElementById('tombolprodukok').style.display='';
																					document.getElementById('tombolubahproduk').style.display='';
																					document.getElementById('simpanubahproduk').style.display='none';
																					document.getElementById('tombolbatalubahproduk').style.display='none';
																					";
				
				// cek apakah ada data pemesan yang berubah
				$qpa="SELECT *
										FROM $db_papproval
										WHERE sesipesanan='".$dord['sesipesanan']."'
																AND nomorpesanan='".$dord['nomorpesanan']."'
										ORDER BY idpapproval DESC
										LIMIT 1
										";
				$rpa=mysqli_query($dbConnection, $qpa);
				if (mysqli_num_rows($rpa)>0)
				{ $dpa=mysqli_fetch_array($rpa);
						if ($dpa['tolaktgl']===NULL && $dpa['setujutgl']===NULL)
						{ if ($dpa['datasesuai']===NULL)
								{ $tombolsesuaipemesan="<input type='button' id='tombolpemesanok' value=' Data Sesuai ' style='margin-right:6px' disabled>";
										$tombolubahpemesan="<input type='button' id='tombolubahpemesan' value=' Ubah Data ' style='cursor:pointer' onclick='enablePemesan()'>";
										$labelubahpemesan="<a href='pemesan_ubah_batal.php?ida=".$dpa['idpapproval']."&idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."' alt='Batalkan Perubahan' title='Batalkan Perubahan'>
																														<span class='material-icons-outlined' style='color:#ffcc01'>backspace</span>
																													</a>
																													";
										}
								else
								{ $tombolsesuaipemesan="<input type='button' id='tombolpemesanok' value=' Data Sesuai ' style='margin-right:6px' disabled>";
										$tombolubahpemesan="<input type='button' id='tombolubahpemesan' value=' Ubah Data ' disabled>";
										$labelubahpemesan="<span class='material-icons-outlined' style='color:#ffcc01'>check_box</span>";
										}
								}
						else if ($dpa['tolaktgl']!==NULL && $dpa['setujutgl']===NULL)
						{ $tombolsesuaipemesan="<input type='button' id='tombolpemesanok' value=' Data Sesuai ' style='cursor:pointer; margin-right:6px' onclick=\"document.location='pemesan_ok.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'\">";
								$tombolubahpemesan="<input type='button' id='tombolubahpemesan' value=' Ubah Data ' style='cursor:pointer' onclick='enablePemesan()'>";
								if ($dpa['tolaksebab']=="BATAL UBAH")
								{ $labelubahpemesan="<span class='material-icons-outlined' style='color:#ffcc01'>disabled_by_default</span>";
										}
								else
								{ $labelubahpemesan="<span class='material-icons-outlined' style='color:#ff5475'>disabled_by_default</span>";
										}
								}
						else if ($dpa['tolaktgl']===NULL && $dpa['setujutgl']!==NULL)
						{ $tombolsesuaipemesan="<input type='button' id='tombolpemesanok' value=' Data Sesuai ' style='margin-right:6px' disabled>";
								$tombolubahpemesan="<input type='button' id='tombolubahpemesan' value=' Ubah Data ' disabled>";
								$labelubahpemesan="<span class='material-icons-outlined' style='color:#33aa88'>check_box</span>";
								}
						$qcl="SELECT jenispembayaranlunas
												FROM $db_carabayarlunas
												WHERE idcarabayarlunas='".$dpa['idcarabayarlunas']."'
																		AND aktif='1'
												";
						$rcl=mysqli_query($dbConnection, $qcl);
						$dcl=mysqli_fetch_array($rcl);
						$pemesanedit="<tr>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						".$labelubahpemesan."
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						".$dpa['namalengkap']."
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						".str_replace("\n", " ", $dpa['alamatlengkap'])."
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						".$dpa['nohandphone']."
																					</td>
																					<td align='left' valign='middle' style='padding:8px 5px 5px 0' nowrap>
																						".$dpa['noktp']."
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0' nowrap>
																						<a href='#popupfotoktp".$dpa['idpapproval']."' rel='modal:open'><span class='material-icons-outlined' style='vertical-align:middle'>badge</span></a>
																						<div id='popupfotoktp".$dpa['idpapproval']."' class='modal'>
																							<p align='center'><img src='images/ktpfile/".$dpa['fotoktp']."' align='top' style='width:100%; border-radius:10px'></p>
																						</div>
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						".$dpa['email']."
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						".$dcl['jenispembayaranlunas']."
																					</td>
																					<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																						-
																					</td>
																					<td align='left' valign='middle' style='padding:8px 0 5px 0'>
																						-
																					</td>
																				</tr>
																				";
						}
				else
				{ $tombolsesuaipemesan="<input type='button' id='tombolpemesanok' value=' Data Sesuai ' style='cursor:pointer; margin-right:6px' onclick=\"document.location='pemesan_ok.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'\">";
						$tombolubahpemesan="<input type='button' id='tombolubahpemesan' value=' Ubah Data ' style='cursor:pointer' onclick='enablePemesan()'>";
						$pemesanedit="";
						}					
			
				$qcb="SELECT *
										FROM $db_carabayarlunas
										WHERE aktif='1'
										ORDER BY idcarabayarlunas ASC
										";
				$rcb=mysqli_query($dbConnection, $qcb);
				$carabeli="<select id='carabayar' name='carabayar' style='padding:5px' disabled>";
				while ($dcb=mysqli_fetch_array($rcb))
				{ if ($dcb['idcarabayarlunas']==$dord['idcarabayarlunas'])
						{ $selected=" selected";
								}
						else
						{ $selected="";
								}
						$carabeli.="<option value='".$dcb['idcarabayarlunas']."'".$selected.">".$dcb['jenispembayaranlunas']."</option>";
						}
				$datapemesan="<table border='0' cellspacing='0' cellpadding='0'>
																			<tr>
																				<td></td>
																				<td align='left' valign='middle' style='padding:0'>
																					<b>Nama Lengkap</b>
																				</td>
																				<td align='left' valign='middle' style='padding:0'>
																					<b>Alamat Tinggal</b>
																				</td>
																				<td align='left' valign='middle' style='padding:0'>
																					<b>No. Handphone</b>
																				</td>
																				<td align='left' valign='middle' style='padding:0' colspan='2'>
																					<b>No. &amp; Foto KTP</b>
																				</td>
																				<td align='left' valign='middle' style='padding:0'>
																					<b>E-mail</b>
																				</td>
																				<td align='left' valign='middle' style='padding:0'>
																					<b>Pembelian</b>
																				</td>
																				<td align='left' valign='middle' style='padding:0'>
																					<b>Voucher</b>
																				</td>
																				<td align='left' valign='middle' style='padding:0'>
																					<b>Catatan</b>
																				</td>
																			</tr>
																			<tr>
																				<td align='left' valign='top' style='padding:8px 13px 5px 0'>
																					<span class='material-icons-outlined' style='color:#cfcfcf'>edit_note</span>
																				</td>
																				<td align='left' valign='top' style='padding:8px 13px 5px 0'>
																					<input type='text' id='namalengkap' name='namalengkap' value='".$dord['namalengkap']."' style='width:150px; padding:5px' disabled>
																				</td>
																				<td align='left' valign='top' style='padding:8px 13px 5px 0'>
																					<input type='text' id='alamattinggal' name='alamattinggal' value='".str_replace("\n", " ", $dord['alamatlengkap'])."' style='width:265px; padding:5px' disabled>
																				</td>
																				<td align='left' valign='top' style='padding:8px 13px 5px 0'>
																					<input type='text' id='nohandphone' name='nohandphone' value='".$dord['nohandphone']."' style='width:115px; padding:5px' disabled>
																				</td>
																				<td align='left' valign='top' style='padding:8px 5px 5px 0' nowrap>
																					<input type='text' id='noktp' name='noktp' value='".$dord['noktp']."' style='width:135px; padding:5px' disabled><br>
																					<input type='file' id='fotoktp' name='fotoktp' style='padding-left:0; margin-left:0; width:135px; display:none'>
																				</td>
																				<td align='left' valign='top' style='padding:8px 13px 5px 0' nowrap>
																					<a href='#popupfotoktp' rel='modal:open'><span class='material-icons-outlined' style='vertical-align:bottom'>badge</span></a>
																					<div id='popupfotoktp' class='modal'>
																						<p align='center'><img src='https://api.digimaxoto.com/order/images/ktpfile/".$dord['fotoktp']."' style='width:100%; border-radius:10px'></p>
																					</div>
																				</td>
																				<td align='left' valign='top' style='padding:8px 13px 5px 0'>
																					<input type='text' id='email' name='email' value='".$dord['email']."' style='width:150px; padding:5px' disabled>
																				</td>
																				<td align='left' valign='top' style='padding:8px 13px 5px 0'>
																					".$carabeli."
																				</td>
																				<td align='left' valign='top' style='padding:8px 13px 5px 0'>
																					<input type='text' name='kodevoucher' value='".$dord['kodevoucher']."' style='width:100px; padding:5px' disabled>
																				</td>
																				<td align='left' valign='top' style='padding:8px 0 5px 0'>
																					<input type='text' value='".$dord['catatan']."' style='width:250px; padding:5px' disabled>
																				</td>
																			</tr>
																			".$pemesanedit."
																		</table>
																		";

				$qdf="SELECT * 
										FROM $db_pfakturapproval
										WHERE sesipesanan='".$dord['sesipesanan']."'
																AND nomorpesanan='".$dord['nomorpesanan']."'
										ORDER BY idpfakturapproval DESC
										LIMIT 1
										";
				$rdf=mysqli_query($dbConnection, $qdf);
				if (mysqli_num_rows($rdf)>0)
				{ $ddf=mysqli_fetch_array($rdf);
						if ($ddf['tolaktgl']===NULL && $ddf['setujutgl']===NULL)
						{ $tombolubahfaktur="<input type='button' id='tombolubahfaktur' value=' Ubah Data ' style='cursor:pointer' onclick='enableFaktur()'>";
								$labelubahfaktur="<a href='faktur_ubah_batal.php?ida=".$ddf['idpfakturapproval']."&idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."' alt='Batalkan Perubahan' title='Batalkan Perubahan'>
																											<span class='material-icons-outlined' style='color:#ffcc01'>backspace</span>
																										</a>
																										";
								}
						else if ($ddf['tolaktgl']!==NULL && $ddf['setujutgl']===NULL)
						{ $tombolubahfaktur="<input type='button' id='tombolubahfaktur' value=' Ubah Data ' style='cursor:pointer' onclick='enableFaktur()'>";
								if ($ddf['tolaksebab']=="BATAL UBAH")
								{ $labelubahfaktur="<span class='material-icons-outlined' style='color:#ffcc01'>disabled_by_default</span>";
										}
								else
								{ $labelubahfaktur="<span class='material-icons-outlined' style='color:#ff5475'>disabled_by_default</span>";
										}
								}
						else if ($ddf['tolaktgl']===NULL && $ddf['setujutgl']!==NULL)
						{ $tombolubahfaktur="<input type='button' id='tombolubahfaktur' value=' Ubah Data ' disabled>";
								$labelubahfaktur="<span class='material-icons-outlined' style='color:#33aa88'>check_box</span>";
								}
						$fakturedit="<tr>
																				<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																					".$labelubahfaktur."
																				</td>
																				<td align='left' valign='middle' style='padding:8px 13px 5px 0'>
																					".$ddf['namalengkap']."
																				</td>
																				<td align='left' valign='middle' style='padding:8px 5px 5px 0' nowrap>
																					".$ddf['noktp']."
																				</td>
																				<td align='left' valign='middle' style='padding:8px 13px 5px 0' nowrap>
																					<a href='#popupfotoktpf".$ddf['idpfakturapproval']."' rel='modal:open'><span class='material-icons-outlined' style='vertical-align:middle'>badge</span></a>
																					<div id='popupfotoktpf".$ddf['idpfakturapproval']."' class='modal'>
																						<p align='center'><img src='images/faktur/dokumen/".$ddf['fotoktp']."' align='top' style='width:100%; border-radius:10px'></p>
																					</div>
																				</td>
																				<td align='left' valign='middle' style='padding:8px 5px 5px 0' nowrap>
																					".$ddf['nokk']."
																				</td>
																				<td align='left' valign='middle' style='padding:8px 13px 5px 0' nowrap>
																					<a href='#popupfotokkf".$ddf['idpfakturapproval']."' rel='modal:open'><span class='material-icons-outlined' style='vertical-align:middle'>article</span></a>
																					<div id='popupfotokkf".$ddf['idpfakturapproval']."' class='modal'>
																						<p align='center'><img src='images/faktur/dokumen/".$ddf['fotokk']."' align='top' style='width:100%; border-radius:10px'></p>
																					</div>
																				</td>
																				<td align='left' valign='middle' style='padding:8px 5px 5px 0' nowrap>
																					".$ddf['nonpwp']."
																				</td>
																				<td align='left' valign='middle' style='padding:8px 13px 5px 0' nowrap>
																					<a href='#popupfotonpwpf".$ddf['idpfakturapproval']."' rel='modal:open'><span class='material-icons-outlined' style='vertical-align:middle'>credit_card</span></a>
																					<div id='popupfotonpwpf".$ddf['idpfakturapproval']."' class='modal'>
																						<p align='center'><img src='images/faktur/dokumen/".$ddf['fotonpwp']."' align='top' style='width:100%; border-radius:10px'></p>
																					</div>
																				</td>
																			</tr>
																			";
						}
				else
				{	$tombolubahfaktur="<input type='button' id='tombolubahfaktur' value=' Ubah Data ' style='cursor:pointer' onclick='enableFaktur()'>";
						$fakturedit="";
						}					
				
				$datafaktur="<table border='0' cellspacing='0' cellpadding='0'>
																		<tr>
																			<td></td>
																			<td align='left' valign='middle' style='padding:0'>
																				<b>Nama Lengkap</b>
																			</td>
																			<td align='left' valign='middle' style='padding:0' colspan='2'>
																				<b>No. &amp; Foto KTP</b>
																			</td>
																			<td align='left' valign='middle' style='padding:0' colspan='2'>
																				<b>No. &amp; Foto KK</b>
																			</td>
																			<td align='left' valign='middle' style='padding:0' colspan='2'>
																				<b>No. &amp; Foto NPWP</b>
																			</td>
																		</tr>
																		<tr>
																			<td align='left' valign='top' style='padding:8px 13px 5px 0'>
																				<span class='material-icons-outlined' style='color:#cfcfcf'>edit_note</span>
																			</td>
																			<td align='left' valign='top' style='padding:8px 13px 5px 0'>
																				<input type='text' id='namalengkapf' name='namalengkapf' style='width:150px; padding:5px' disabled>
																			</td>
																			<td align='left' valign='top' style='padding:8px 5px 5px 0' nowrap>
																				<input type='text' id='noktpf' name='noktpf' style='width:150px; padding:5px' disabled><br>
																				<input type='file' id='fotoktpf' name='fotoktpf' style='padding-left:0; margin-left:0; width:150px; display:none'>
																			</td>
																			<td align='left' valign='top' style='padding:8px 13px 5px 0' nowrap>
																				<a href='#popupfotoktpf' rel='modal:open'><span class='material-icons-outlined' style='vertical-align:bottom'>badge</span></a>
																				<div id='popupfotoktpf' class='modal'>
																					<p align='center'>Foto KTP tidak tersedia</p>
																				</div>
																			</td>
																			<td align='left' valign='top' style='padding:8px 5px 5px 0' nowrap>
																				<input type='text' id='nokkf' name='nokkf' style='width:150px; padding:5px' disabled><br>
																				<input type='file' id='fotokkf' name='fotokkf' style='padding-left:0; margin-left:0; width:150px; display:none'>
																			</td>
																			<td align='left' valign='top' style='padding:8px 13px 5px 0' nowrap>
																				<a href='#popupfotokkf' rel='modal:open'><span class='material-icons-outlined' style='vertical-align:bottom'>article</span></a>
																				<div id='popupfotokkf' class='modal'>
																					<p align='center'>Foto KK tidak tersedia</p>
																				</div>
																			</td>
																			<td align='left' valign='top' style='padding:8px 5px 5px 0' nowrap>
																				<input type='text' id='nonpwpf' name='nonpwpf' style='width:150px; padding:5px' disabled><br>
																				<input type='file' id='fotonpwpf' name='fotonpwpf' style='padding-left:0; margin-left:0; width:150px; display:none'>
																			</td>
																			<td align='left' valign='top' style='padding:8px 13px 5px 0' nowrap>
																				<a href='#popupfotonpwpf' rel='modal:open'><span class='material-icons-outlined' style='vertical-align:bottom'>credit_card</span></a>
																				<div id='popupfotonpwpf' class='modal'>
																					<p align='center'>Foto NPWP tidak tersedia</p>
																				</div>
																			</td>
																		</tr>
																		".$fakturedit."
																	</table>
																	";																	

		// catatan selama proses konfirmasi
		$qcp="SELECT * 
								FROM $db_pesanannote
								WHERE nomorpesanan='".$dord['nomorpesanan']."'
														AND sesipesanan='".$dord['sesipesanan']."'
														AND statusorder='1'
								ORDER BY catattgl DESC
								";
		$rcp=mysqli_query($dbConnection, $qcp);
		if (mysqli_num_rows($rcp)>0)
		{ $catatan="";
				while ($dcp=mysqli_fetch_array($rcp))
				{ $catatan.="<b>".date("d M Y H:i:s", strtotime($dcp['catattgl']))." - ".$dcp['catatoleh']."</b><br>".str_replace("\n", "", $dcp['catatan'])."<br><br>";
						}
				}
		else
		{ $catatan="(Belum ada catatan)";
				}
		
		$script="<script>
												function enableProduct()
												{ ".$enableproduk."
														}
												function disableProduct()
												{ ".$disableproduk."
														}
												function enablePemesan()
												{ document.getElementById('namalengkap').disabled=false;
														document.getElementById('alamattinggal').disabled=false;
														document.getElementById('nohandphone').disabled=false;
														document.getElementById('noktp').disabled=false;
														document.getElementById('fotoktp').style.display='';
														document.getElementById('email').disabled=false;
														document.getElementById('carabayar').disabled=false;
														document.getElementById('tombolpemesanok').style.display='none';
														document.getElementById('tombolubahpemesan').style.display='none';
														document.getElementById('simpanubahpemesan').style.display='';
														document.getElementById('tombolbatalubahpemesan').style.display='';
														}
												function disablePemesan()
												{ document.getElementById('namalengkap').disabled=true;
														document.getElementById('alamattinggal').disabled=true;
														document.getElementById('nohandphone').disabled=true;
														document.getElementById('noktp').disabled=true;
														document.getElementById('fotoktp').style.display='none';
														document.getElementById('email').disabled=true;
														document.getElementById('carabayar').disabled=true;
														document.getElementById('tombolpemesanok').style.display='';
														document.getElementById('tombolubahpemesan').style.display='';
														document.getElementById('simpanubahpemesan').style.display='none';
														document.getElementById('tombolbatalubahpemesan').style.display='none';
														}
												function enableFaktur()
												{ document.getElementById('namalengkapf').disabled=false;
														document.getElementById('noktpf').disabled=false;
														document.getElementById('fotoktpf').style.display='';
														document.getElementById('nokkf').disabled=false;
														document.getElementById('fotokkf').style.display='';
														document.getElementById('nonpwpf').disabled=false;
														document.getElementById('fotonpwpf').style.display='';
														document.getElementById('tombolubahfaktur').style.display='none';
														document.getElementById('simpanubahfaktur').style.display='';
														document.getElementById('tombolbatalubahfaktur').style.display='';
														}
												function disableFaktur()
												{ document.getElementById('namalengkapf').disabled=true;
														document.getElementById('noktpf').disabled=true;
														document.getElementById('fotoktpf').style.display='none';
														document.getElementById('nokkf').disabled=true;
														document.getElementById('fotokkf').style.display='none';
														document.getElementById('nonpwpf').disabled=true;
														document.getElementById('fotonpwpf').style.display='none';
														document.getElementById('tombolubahfaktur').style.display='';
														document.getElementById('simpanubahfaktur').style.display='none';
														document.getElementById('tombolbatalubahfaktur').style.display='none';
														}
											</script>
											";
		
		$msg=$script.
							"<table border='0' cellpadding='0' cellspacing='0' width='100%'>
									<tr>
										<td align='left' valign='middle' width='50%'>
											<h1>NO. PESANAN ".$nomorpesanan."</h1> 
										</td>
										<td align='right' valign='top' width='50%'>
											<input type='button' value=' Batalkan Pesanan ' style='cursor:pointer' onclick=\"document.location='pesanan_batal.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'\">
										</td>
									</tr>
								</table>
								<span class='material-icons-outlined' style='color:#ffcc01; vertical-align:middle; font-size:16pt'>check_box</span>&nbsp; Dinyatakan Sesuai, Menunggu Persetujuan
								&nbsp; &nbsp; &nbsp;
								<span class='material-icons-outlined' style='color:#ffcc01; vertical-align:middle; font-size:16pt'>backspace</span> &nbsp; Data Berubah, Menunggu Persetujuan
								&nbsp; &nbsp; &nbsp;
								<span class='material-icons-outlined' style='color:#ffcc01; vertical-align:middle; font-size:16pt'>disabled_by_default</span>&nbsp; Perubahan Data Dibatalkan
								&nbsp; &nbsp; &nbsp;
								<span class='material-icons-outlined' style='color:#33aa88; vertical-align:middle; font-size:16pt'>check_box</span>&nbsp; Sudah Disetujui
								&nbsp; &nbsp; &nbsp;
								<span class='material-icons-outlined' style='color:#ff5475; vertical-align:middle; font-size:16pt'>disabled_by_default</span>&nbsp; Tidak Disetujui
								<br><br><hr size='1'><br>
								<table border='0' cellpadding='0' cellspacing='0' width='100%'>
									<tr>
										<td align='left' valign='top' width='50%' style='padding-right:10px'>
											<h2>CATATAN ADMIN</h2>
											Masukan semua informasi yang terkait proses konfirmasi data di kotak catatan di bawah ini seperti telepon tidak diangkat / tidak aktif, 
											ada data yang ingin diubah, dan lainnya.<br><br>
											<form method='post' action='pesanan_konfirmasi_note.php?idp=".$idpesanan."&oid=".base64_encode($nomorpesanan)."'>
												<textarea name='catatan' style='resize:none; width:100%; height:65px' value=''></textarea>
												<br><br>
												<input type='submit' value=' Simpan Catatan ' style='cursor:pointer'>
											</form>
										</td>
										<td align='left' valign='top' width='50%' style='padding-left:10px; padding-top:10px'>
											<b style='font-size:9pt'>Catatan Sebelumnya:</b><br><br>
											<div style='width:95%; height:135px; padding:10px; border:1px solid #cfcfcf; line-height:17px; overflow-y:scroll'>
												".$catatan."
											</div>
										</td>
									</tr>
								</table>
								<br><hr size='1'><br>
								<div style='border:2px solid #ffaaaa; padding:10px; background-color:#ffefef; line-height:18px; font-weight:bold; font-size:10pt'>
									Berikut ini adalah data-data pesanan dan pemesan yang perlu dipastikan kembali ke pemesan.
									Jika ada data yang ingin diubah, sebelum menyimpan data baru tersebut, pastikan data baru yang dimasukan 
									tidak ada yang salah ketik.
								</div><br>
								<h2>DATA PRODUK</h2>
								<form id='formubahproduk' method='post' action='produk_ubah.php?idp=".$idpesanan."&oid=".base64_encode($nomorpesanan)."'>
									".$tombolsesuaiproduk."
									".$tombolubahproduk."
									<input type='submit' id='simpanubahproduk' value=' Simpan ' style='cursor:pointer; display:none'> &nbsp;
									<input type='button' id='tombolbatalubahproduk' value=' Batal Ubah ' style='cursor:pointer; display:none' onclick='disableProduct()'>
									<br><br>
									<div style='width:1050px; padding:15px 10px 15px 10px; border:1px solid #cfcfcf; overflow-x:scroll'>
										".$dataproduk."
									</div>	
								</form>	
								<br><hr size='1'><br><br>
								<table border='0' cellpadding='0' cellspacing='0' width='100%'>
									<tr>
										<td align='left' valign='top' width='100%'>
											<h2>DATA PEMESAN</h2>
											<form id='formubahpesanan' enctype='multipart/form-data' method='post' action='pemesan_ubah.php?idp=".$idpesanan."&oid=".base64_encode($nomorpesanan)."'>
												".$tombolsesuaipemesan."
												".$tombolubahpemesan."
												<input type='submit' id='simpanubahpemesan' value=' Simpan ' style='cursor:pointer; display:none'> &nbsp;
												<input type='button' id='tombolbatalubahpemesan' value=' Batal Ubah ' style='cursor:pointer; display:none' onclick='disablePemesan()'>
												<br><br>
												<div style='width:1050px; padding:15px 10px 15px 10px; border:1px solid #cfcfcf; overflow-x:scroll'>
													".$datapemesan."
												</div>	
											</form>
										</td>
									</tr>
									<tr>
										<td>
											<br><hr size='1'><br><br>
										</td>
									</tr>
									<tr>
										<td align='left' valign='top' width='100%'>
											<h2>DATA FAKTUR</h2>
											<form method='post' enctype='multipart/form-data' action='faktur_ubah.php?idp=".$idpesanan."&oid=".base64_encode($nomorpesanan)."'>
												".$tombolubahfaktur."
												<input type='submit' id='simpanubahfaktur' value=' Simpan ' style='cursor:pointer; display:none'> &nbsp;
												<input type='button' id='tombolbatalubahfaktur' value=' Batal Ubah ' style='cursor:pointer; display:none' onclick='disableFaktur()'>
												<br><br>
												<div style='width:1050px; padding:15px 10px 15px 10px; border:1px solid #cfcfcf; overflow-x:scroll'>
													".$datafaktur."
												</div>	
											</form>
										</td>
									</tr>
								</table>
								<br><br>
								";
				}
		else
		{ $msg="Data pesanan tidak ditemukan.<br><br>
										Biasanya terjadi karena proses konfirmasi data sudah terlewati atau pesanan sudah dibatalkan.<br><br>".$linkback;
				}

		$content="<table border='0' cellpadding='0' cellspacing='0' width='100%' height='100%'>
													<tr>
														<td align='left' valign='top' width='100%' height='100%'>
															<b class='title'>KONFIRMASI DATA</b>
															<br><hr size='1' color='#000000'><br>
															<!--
															<table border='0' cellpadding='0' cellspacing='0'>
																<tr>
																	<td align='left' valign='middle'>
																		<span class='material-icons'>arrow_circle_left</span> &nbsp;
																	</td>
																	<td align='left' valign='middle'>
																		".$linkback."
																	</td>
																</tr>
															</table>
															<br>
															-->
															".$msg."
														</td>
													</tr>
												</table>
												";
		}

include "webmenu.php";
include "common/include/template.php";
$temp=new template;
$temp->define_theme("themes/theme1.html");
$temp->define_tag("{PAGETITLE}", $namaaplikasi);
$temp->define_tag("{NAMAUSER}", strtoupper($_SESSION['SES_FULLNAME']));
$temp->define_tag("{APPMENU}", $webmenu);
$temp->define_tag("{APPCONTENT}", $content);
$temp->parse();
$temp->printproses();

closeDB();

?>