<?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;
		$catatan=isset($_POST['catatan']) ? $_POST['catatan'] : NULL;
		$script="";
		
		if (!empty(trim($catatan)) && strlen(trim($catatan))>15)
		{ $qord="SELECT *
											FROM $db_pesanan
											WHERE idpesanan='".$idpesanan."'
																	AND nomorpesanan='".$nomorpesanan."'
																	AND statusorder<2
											";
				$rord=mysqli_query($dbConnection, $qord);
				if (mysqli_num_rows($rord)>0)
				{ $dord=mysqli_fetch_array($rord);
						$qic="INSERT INTO $db_pesanannote (nomorpesanan,
																																									sesipesanan,
																																									idrekanan,
																																									idtoko,
																																									statusorder,
																																									catatan,
																																									catattgl,
																																									catatoleh)
												VALUES ('".$nomorpesanan."',
																				'".$dord['sesipesanan']."',
																				'".$dord['idrekanan']."',
																				'".$dord['idtoko']."',
																				'".$dord['statusorder']."',
																				'".$catatan."',
																				'".$wktsekarangdb."',
																				'".$_SESSION['SES_USERNAME']."')
												";
						$ric=mysqli_query($dbConnection, $qic);
						if ($ric)
						{ $msg="Sukses menyimpan catatan.";
								$script.="<script>
																			var goBack = function ()
																																{ setTimeout(function()
																																													{ window.location='konfirmasidata.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."';
																																															}, 
																																													1000);
																																		};
																			window.onload = goBack();
																		</script>
																		";
								}
						else
						{ $msg="Gagal menyimpan catatan.<br><br>".$linkback;
								}
						}
				else
				{ $msg="Data pesanan tidak ditemukan.<br><br>
												Status pesanan ini mungkin sudah berubah sehingga data pesanan sudah tidak dapat dikonfirmasi lagi.<br><br>".$linkhome;
						}
				}
		else
		{ $msg="Gagal menyimpan catatan.<br><br>
										Catatan yang ingin dimasukan kosong atau terlalu singkat.<br><br>".$linkback;
				}
		
		$content=$script.
											"<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>
															<h1>NO. PESANAN ".$nomorpesanan."</h1>
															<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();

?>