<?php session_start();

if ($_POST["item_name_1"] != "") {
	if (!isset($_POST['submit'])) {
		exit('Fail!');
	} else {
		include '../../conf/conn.php';
	}
	$sql = NULL;
	$sql1 = NULL;
	if (@$_POST["discount_rate"] != "") {
		$discount_rate = $_POST["discount_rate"];
		$query = "select * from coupon where code = '" . $_POST["code"] . "'";
		$result = mysqli_query($conn, $query);
		$row = mysqli_fetch_assoc($result);
		$coupon = $row["coupon_name"];
		$coupon_code = $row["code"];
		$usage_count = $row["usage_count"];
		$sql = ",`coupon_name`,`coupon_code`";
		$sql1 = ",'" . $row["coupon_name"] . "','" . $row["code"] . "'";
	} else {
		$discount_rate = 1;
	}

	$customer_name = $_POST["customer_Fname"] . ' ' . $_POST["customer_Lname"];
	$recipient_name = $_POST["recipient_Fname"] . ' ' . $_POST["recipient_Lname"];

	$y = $_POST["y"] - 1;
	$x = 1;
	while ($x <= $y) {
		$item_name = str_replace('D.', '<div class="Dark">', $_POST["item_name_" . $x]);
		$item_name = str_replace('W.', '<div class="White">', $item_name);
		$item_name = str_replace('P.', '<div class="Pink">', $item_name);
		$item_name = str_replace('_', '</div>', $item_name);

		if ($x == 1) {
			$bought_items = $item_name;
			$amount = $_POST["amount_" . $x] * $_POST["quantity_" . $x];
			$x++;
		} else {
			$bought_items = $bought_items . '<br>' . $item_name;
			$amount = $amount + $_POST["amount_" . $x] * $_POST["quantity_" . $x];
			$x++;
		}}

	if ($_GET["Payment_Type"] == 'Bank_Transfer') {
		$paypal = $_SESSION["id"] . date("dHis");

		$sql = 'INSERT INTO `orders`(`record`, `paypal id`, `bought_items`, `amount`, `username`, `customer Fname`,`customer Lname`, `customer phone`, `customer email`, `customer address`, `company name`, `recipient Fname`,`recipient Lname`, `phone`, `email`, `address`, `delivery date`, `delivery time`, `remarks`, `time`, `status`' . $sql . ') VALUES (null,"' . $paypal . '",' . "'" . $bought_items . "'" . ',"' . $amount . '","' . $_POST["username"] . '","' . $_POST["customer_Fname"] . '","' . $_POST["customer_Lname"] . '","' . $_POST["customer_phone"] . '","' . $_POST["customer_email"] . '","' . $_POST["customer_address"] . '","' . $_POST["company_name"] . '","' . $_POST["recipient_Fname"] . '","' . $_POST["recipient_Lname"] . '","' . $_POST["phone"] . '","' . $_POST["email"] . '","' . preg_replace("/\r\n/", '<br>', htmlspecialchars($_POST["address"])) . '","' . $_POST["delivery_date"] . '","' . $_POST["delivery_time"] . '","' . preg_replace("/\r\n/", '<br>', htmlspecialchars($_POST["remarks"])) . '","' . date("Y-m-d H:i:s") . '","bank"' . $sql1 . ')';
		error_log(print_r($sql, true) . "\r\n", 3, "../../order_insert.log");

		$remarks = preg_replace("/\r\n/", '<br>', htmlspecialchars($_POST["remarks"]));
		$query = mysqli_query($conn, $sql);

		$sql = "SELECT * FROM `orders` WHERE `paypal id` ='" . $paypal . "'";
		$query = mysqli_query($conn, $sql);
		$row = mysqli_fetch_assoc($query);
		$paypal1 = "SRI" . date("y") . "-" . sprintf("%'05d", $row["record"]);

		$sql = "UPDATE `orders` SET `paypal id` = '" . $paypal1 . "' WHERE `paypal id` = '" . $paypal . "'";
		$query = mysqli_query($conn, $sql);
		$paypal = $paypal1;

		$_SESSION["page"] = 11;
		$url = "../e-shop.php";
		echo "<script language='javascript'
type='text/javascript'>";
		echo "window.location.href='$url'";
		echo "</script>";
		$customer_email = $_POST["customer_email"];
		$email = $_POST["email"];
		$phone = $_POST["phone"];
		$address = $_POST["address"];
		$username = $_POST["username"];

		$maillist = '';
		$amount1 = 0;
		$amount3 = 0;
		$query = "select * from cart where username='$username'";
		$result = mysqli_query($conn, $query);
		if (mysqli_num_rows($result) > 0) {
			while ($row = mysqli_fetch_assoc($result)) {
				$product_name = str_replace('<div class="Dark">', "<img src ='www.sayvour.com.hk/img/letter/d_", $row["product_name"]);
				$product_name = str_replace('<div class="White">', "<img src ='www.sayvour.com.hk/img/letter/w_", $product_name);
				$product_name = str_replace('<div class="Pink">', "<img src ='www.sayvour.com.hk/img/letter/p_", $product_name);
				$product_name = str_replace('</div>', ".png' align ='left'>", $product_name);
				$product_name = str_replace('_?.', "_s1.", $product_name);
				$product_name = str_replace('_/.', "_s2.", $product_name);
				$product_name = str_replace('_:.', "_s3.", $product_name);
				$product_name = str_replace('><br><', "><br><br><br><", $product_name);

				$maillist = $maillist . "<div style='Margin-left:20px;Margin-right:20px; width:100%;'>

											<table style='WIDTH:100%;BORDER-COLLAPSE:collapse;BORDER-SPACING:0; margin:10px 0px' cellspacing='0' cellpadding='0' width='100%' border='0'>
											<tbody>
											<tr>

											  <td style='WIDTH:45%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='50%'>
												<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>" . $product_name . "<u></u><u></u></span></p></td>
											  <td style='WIDTH:15%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='25%'>
												<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>
												HK$" . round($row["price"] * $discount_rate, 1)
					. "<u></u><u></u></span></p></td>

												<td style='WIDTH:10%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='25%'>
												<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>
												" . $row["amount"]
					. "<u></u><u></u></span></p></td>
											  <td style='WIDTH:20%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='25%'>
												<p class='MsoNormal' style='TEXT-ALIGN:right;LINE-HEIGHT:12.75pt' align='right'><strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>HK$";

				$price = round($row["price"] * $discount_rate, 1) * $row["amount"];

				$maillist = $maillist . $price . "</span></strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>
											  <td style='WIDTH:0.3pt;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='1'></td></tr>

											  </tbody>
											  </table>
														</div>

										<div style='Margin-left:20px;Margin-right:20px'>
															<div style='display:block;font-size:2px;line-height:2px;Margin-left:auto;Margin-right:auto;width:100%;background-color:#7cc3c3'>&nbsp;</div>
														</div>";
				$amount3 = $amount3 + ($row["price"] * $row["amount"]);
				$amount1 = $amount1 + round($row["price"] * $discount_rate, 1) * $row["amount"];
			}
			$amount2 = round($amount1, 1) * 1;

			if ($amount / $discount_rate < 500) {
				$deliveryfee = $maillist . "<div style='Margin-left:20px;Margin-right:20px; width:100%;'>

											<table style='WIDTH:100%;BORDER-COLLAPSE:collapse;BORDER-SPACING:0; margin:10px 0px' cellspacing='0' cellpadding='0' width='100%' border='0'>
											<tbody>
											<tr>

											  <td style='WIDTH:45%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='50%'>
												<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>Delivery Fee<u></u><u></u></span></p></td>
											 <td style='WIDTH:15%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='25%'>
												<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>
												HK$38<u></u><u></u></span></p></td>
											  <td style='WIDTH:10%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='25%'>
												<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>
												1<u></u><u></u></span></p></td>
											  <td style='WIDTH:20%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='25%'>
												<p class='MsoNormal' style='TEXT-ALIGN:right;LINE-HEIGHT:12.75pt' align='right'><strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>HK$38</span></strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>
											  <td style='WIDTH:0.3pt;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='1'></td></tr>

											  </tbody>
											  </table>
														</div>

										<div style='Margin-left:20px;Margin-right:20px'>
															<div style='display:block;font-size:2px;line-height:2px;Margin-left:auto;Margin-right:auto;width:100%;background-color:#7cc3c3'>&nbsp;</div>
														</div>";
			} else {
				$deliveryfee = "											  <tr>

											  <td style='WIDTH:45%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='45%'>
												<strong><p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>Delivery Fee<u></u><u></u></span></p></strong></td>

											  <td style='WIDTH:20%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='20%'>
												<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>

											  <td style='WIDTH:25%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='22%'>
												<p class='MsoNormal' style='TEXT-ALIGN:right;LINE-HEIGHT:12.75pt' align='right'><strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>HK$0</span></strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>

											  <td style='WIDTH:0.3pt;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='1'></td>

											  </tr>
";
			}
			if ($discount_rate != 1) {

				$discount_rate2 = (1 - $discount_rate) * 100;
				$discount_rate1 = "<tr>

											  <td style='WIDTH:45%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='45%'>
												<strong><p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>Discount(%)<u></u><u></u></span></p></strong></td>

											  <td style='WIDTH:20%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='20%'>
												<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>

											  <td style='WIDTH:25%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='22%'>
												<p class='MsoNormal' style='TEXT-ALIGN:right;LINE-HEIGHT:12.75pt' align='right'><strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>" . $discount_rate2 . "%</span></strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>

											  <td style='WIDTH:0.3pt;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='1'></td>

											  </tr>
											  <tr>
<td style='WIDTH:45%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='45%'>
<strong><p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>Sub-Total After Discount<u></u><u></u></span></p></strong></td>
<td style='WIDTH:20%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='20%'>
<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>
<td style='WIDTH:25%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='22%'>
<p class='MsoNormal' style='TEXT-ALIGN:right;LINE-HEIGHT:12.75pt' align='right'><strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>HK$" . $amount2 . "</span></strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>
<td style='WIDTH:0.3pt;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='1'></td>
</tr>
";} else { $discount_rate1 = "";}

			if ($amount / $discount_rate < 500) {
				$deliveryfee = "											  <tr>

											  <td style='WIDTH:45%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='45%'>
												<strong><p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>Delivery Fee<u></u><u></u></span></p></strong></td>

											  <td style='WIDTH:20%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='20%'>
												<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>

											  <td style='WIDTH:25%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='22%'>
												<p class='MsoNormal' style='TEXT-ALIGN:right;LINE-HEIGHT:12.75pt' align='right'><strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>HK$38</span></strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>

											  <td style='WIDTH:0.3pt;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='1'></td>

											  </tr>
";
			} else {
				$deliveryfee = "											  <tr>

											  <td style='WIDTH:45%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='45%'>
												<strong><p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>Delivery Fee<u></u><u></u></span></p></strong></td>

											  <td style='WIDTH:20%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='20%'>
												<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>

											  <td style='WIDTH:25%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='22%'>
												<p class='MsoNormal' style='TEXT-ALIGN:right;LINE-HEIGHT:12.75pt' align='right'><strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>HK$0</span></strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>

											  <td style='WIDTH:0.3pt;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='1'></td>

											  </tr>
";}

			$maillist = $maillist . "
<div style='Margin-left:20px;Margin-right:20px; width:100%;'>
<table style='WIDTH:100%;BORDER-COLLAPSE:collapse;BORDER-SPACING:0; margin:10px 0px' cellspacing='0' cellpadding='0' width='100%' border='0'>
<tbody>
<tr>
<td style='WIDTH:45%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='45%'>
<strong><p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>Sub-Total<u></u><u></u></span></p></strong></td>
<td style='WIDTH:20%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='20%'>
<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>
<td style='WIDTH:25%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='22%'>
<p class='MsoNormal' style='TEXT-ALIGN:right;LINE-HEIGHT:12.75pt' align='right'><strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>HK$" . $amount3 . "</span></strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>
<td style='WIDTH:0.3pt;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='1'></td>
</tr>
" . $discount_rate1 . $deliveryfee . "</tbody>
</table>
</div>
<div style='Margin-left:20px;Margin-right:20px'>
<div style='display:block;font-size:2px;line-height:2px;Margin-left:auto;Margin-right:auto;width:100%;background-color:#7cc3c3'>&nbsp;</div></div>
";
		}

		$query = "select * from cart where username='$username'";
		$result = mysqli_query($conn, $query);
		if (mysqli_num_rows($result) > 0) {
			$maillist1 = "INSERT INTO `artechwebs_sayvour`.`email` (`id`, `paypal id`, `username`, `maillist`) VALUES (NULL,'$paypal','$username'," . '"';
			while ($row = mysqli_fetch_assoc($result)) {
				$product_name = str_replace('<div class="Dark">', "<img src ='www.sayvour.com.hk/img/letter/d_", $row["product_name"]);
				$product_name = str_replace('<div class="White">', "<img src ='www.sayvour.com.hk/img/letter/w_", $product_name);
				$product_name = str_replace('<div class="Pink">', "<img src ='www.sayvour.com.hk/img/letter/p_", $product_name);
				$product_name = str_replace('</div>', ".png' align ='left'>", $product_name);
				$product_name = str_replace('_?.', "_s1.", $product_name);
				$product_name = str_replace('_/.', "_s2.", $product_name);
				$product_name = str_replace('_:.', "_s3.", $product_name);
				$product_name = str_replace('><br><', "><br><br><br><", $product_name);

				$maillist1 = $maillist1 . "<div style='Margin-left:20px;Margin-right:20px; width:100%;'>

											<table style='WIDTH:100%;BORDER-COLLAPSE:collapse;BORDER-SPACING:0; margin:10px 0px' cellspacing='0' cellpadding='0' width='100%' border='0'>
											<tbody>
											<tr>

											  <td style='WIDTH:45%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='50%'>
												<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>" . $product_name . "<u></u><u></u></span></p></td>
											  <td style='WIDTH:15%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='25%'>
												<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>
												HK$" . round($row["price"] * $discount_rate, 1)
					. "<u></u><u></u></span></p></td>

												<td style='WIDTH:10%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='25%'>
												<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>
												" . $row["amount"]
					. "<u></u><u></u></span></p></td>
											  <td style='WIDTH:20%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='25%'>
												<p class='MsoNormal' style='TEXT-ALIGN:right;LINE-HEIGHT:12.75pt' align='right'><strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>HK$";

				$price = round($row["price"] * $discount_rate, 1) * $row["amount"];

				$maillist1 = $maillist1 . $price . "</span></strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>
											  <td style='WIDTH:0.3pt;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='1'></td></tr>

											  </tbody>
											  </table>
														</div>

										<div style='Margin-left:20px;Margin-right:20px'>
															<div style='display:block;font-size:2px;line-height:2px;Margin-left:auto;Margin-right:auto;width:100%;background-color:#7cc3c3'>&nbsp;</div>
														</div>";}

			$maillist1 = $maillist1 . "
<div style='Margin-left:20px;Margin-right:20px; width:100%;'>
<table style='WIDTH:100%;BORDER-COLLAPSE:collapse;BORDER-SPACING:0; margin:10px 0px' cellspacing='0' cellpadding='0' width='100%' border='0'>
<tbody>
<tr>
<td style='WIDTH:45%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='45%'>
<strong><p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>Sub-Total<u></u><u></u></span></p></strong></td>
<td style='WIDTH:20%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='20%'>
<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>
<td style='WIDTH:25%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='22%'>
<p class='MsoNormal' style='TEXT-ALIGN:right;LINE-HEIGHT:12.75pt' align='right'><strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>HK$" . $amount3 . "</span></strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>
<td style='WIDTH:0.3pt;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='1'></td>
</tr>
" . $discount_rate1 . $deliveryfee . "</tbody>
</table>
</div>
<div style='Margin-left:20px;Margin-right:20px'>
<div style='display:block;font-size:2px;line-height:2px;Margin-left:auto;Margin-right:auto;width:100%;background-color:#7cc3c3'>&nbsp;</div></div>
";

			$maillist1 = $maillist1 . '")';
			$query = mysqli_query($conn, $maillist1);
		}

		require_once '../../phpmailer/class.phpmailer.php';
		$mail = new PHPMailer(); // create a new object
		//$mail->IsSMTP(); // enable SMTP
		//$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
		//$mail->SMTPAuth = true; // authentication enabled
		//$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
		//$mail->Host = "localhost";
		//$mail->Host = "mail.station191.com";
		//$mail->Port = 587; // or 587

		$mail->addReplyTo("info@sayvour.com.hk", "Sayvour");
		$mail->AddBCC("daniel@at-creative.com");
		$mail->AddBCC("info@sayvour.com.hk");
		$mail->AddBCC("catherine@sayvour.com.hk");
		$mail->AddBCC("sayvourhongkong@gmail.com");
		$mail->IsHTML(true);
		//$mail->Username = "kk@at-creative.com";
		//$mail->Password = "artech0088";
		$mail->setFrom("info@sayvour.com.hk", "Sayvour");
		$mail->Subject = "Thank you for your order from Sayvour";
		$mail->Body = "                                <!-- top bar -->

										<div id=':lt' class='ii gt adP adO'>
											<div id=':ls' class='a3s aXjCH m156312919a8bb8e9'><u></u>
												<div style='margin:0;padding:0'>
													<div style='min-width:320px;background-color:#c2e3e3' lang='x-wrapper'>
														<div style='Margin:0 auto;max-width:560px;min-width:280px;'>
															<div style='border-collapse:collapse;display:table;width:100%'>
																<div style='Float:left;font-size:12px;line-height:19px;max-width:280px;min-width:140px;padding:10px 0 5px 0;color:#9dc4c4;font-family:Cabin,Avenir,sans-serif'></div>
																<div style='Float:left;font-size:12px;line-height:19px;max-width:280px;min-width:139px;padding:10px 0 5px 0;text-align:right;color:#9dc4c4;font-family:Cabin,Avenir,sans-serif'></div>
															</div>
														</div>
														<div style='Margin:0 auto;max-width:600px;min-width:320px;'>
															<div style='font-size:26px;line-height:32px;Margin-top:6px;Margin-bottom:20px;color:#ffffff;font-family:&quot;PT Serif&quot;,Georgia,serif;Margin-left:20px;Margin-right:20px' align='center'>
																<div style='font-size:0px!important;line-height:0!important' align='center'><img style='min-height:auto;width:100%;border:0;max-width:217px' src='https://ci4.googleusercontent.com/proxy/vUMxJkR_Kw9qDMrAUmEEtS4_hy8v4TztsG8zNDbLJxG0zizdPUmHdqEAaVAuRWqrT0fA9zde7TizwG9QGRXUNgPmnlhNJWJ_gzMCbqpsW3bSMaNbueUnoTh1=s0-d-e1-ft#http://i1.cmail2.com/ei/d/F9/F24/F62/203623/csfinal/sayvour-logo.png' alt='' width='217' class='CToWUd'></div>
															</div>
														</div>

										<!-- end top bar -->

										<!-- Dear -->
										<div style='background-color:#FFFFFF'>
											<div style='Margin:0 auto;max-width:600px;min-width:320px;word-wrap:break-word;word-break:break-word'>
												<div style='border-collapse:collapse;display:table;width:100%'>
													<div style='max-width:600px;min-width:320px;text-align:left;FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>
														<div style='Margin-left:20px;Margin-right:20px'>
															<div style='line-height:40px;font-size:1px'>&nbsp;</div>
														</div>
														<div style='Margin-left:20px;Margin-right:20px'>
															<h1 style='Margin-top:0;Margin-bottom:20px;font-style:normal;font-weight:normal;color:#499f9e;font-size:24px;line-height:32px;font-family:&quot;PT Serif&quot;,Georgia,serif;text-align:center' lang='x-size-28'>Thank you for your order from Sayvour</h1>
														</div>
														<div style='Margin-left:20px;Margin-right:20px'>
															<p style='Margin-top:0;Margin-bottom:0;text-transform: capitalize'>Dear&nbsp;" . $_POST["customer_Fname"] . ",</p><p style='Margin-top:20px;Margin-bottom:20px'>Thank you for your recent order on " . date('Y-m-d') . ". We would like to confirm the details as follows:</p>
														</div>
														<div style='Margin-left:20px;Margin-right:20px'>
															<div style='line-height:20px;font-size:1px'>&nbsp;</div>
										</div>

										<!-- End Dear -->


										<!-- Order Summary -->

										<div style='Margin-left:20px;Margin-right:20px'>
									<p style='Margin-top:0;Margin-bottom:20px;font-size:16px;line-height:24px' lang='x-size-16'><span style='color:#575757'><strong>Order Summary</strong></span></p>
								</div>

                <div style='Margin-left:20px;Margin-right:20px; width:100%;'>

					<table style='WIDTH:100%;BORDER-COLLAPSE:collapse;BORDER-SPACING:0; margin:10px 0px' cellspacing='0' cellpadding='0' width='100%' border='0'>
                    <tbody>
                    <tr>

                      <td style='WIDTH:45%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='50%'>
                        <strong><p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>Product Name<u></u><u></u></span></p></strong></td>
                      <td style='WIDTH:15%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='25%'>
                        <strong><p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>Unit Price<u></u><u></u></span></p></strong></td>
					  <td style='WIDTH:20%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='25%'>
                        <strong><p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>Quantity<u></u><u></u></span></p></strong></td>
                      <td style='WIDTH:10%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='25%'>
                        <p class='MsoNormal' style='TEXT-ALIGN:right;LINE-HEIGHT:12.75pt' align='right'><strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>Amount</span></strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>
                      <td style='WIDTH:0.3pt;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='1'></td></tr>

                      </tbody>
                      </table>
								</div>

										<div style='Margin-left:20px;Margin-right:20px'>
															<div style='display:block;font-size:2px;line-height:2px;Margin-left:auto;Margin-right:auto;width:100%;background-color:#7cc3c3'>&nbsp;</div>
														</div>"
			. $maillist .
			"
<div style='Margin-left:20px;Margin-right:20px; width:100%;'>
<table style='WIDTH:100%;BORDER-COLLAPSE:collapse;BORDER-SPACING:0; margin:10px 0px' cellspacing='0' cellpadding='0' width='100%' border='0'>
<tbody>
<tr>
<td style='WIDTH:45%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='45%'>
<strong><p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>Total<u></u><u></u></span></p></strong></td>
<td style='WIDTH:20%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='20%'>
<p class='MsoNormal' style='LINE-HEIGHT:12.75pt'><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>
<td style='WIDTH:25%;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='22%'>
<p class='MsoNormal' style='TEXT-ALIGN:right;LINE-HEIGHT:12.75pt' align='right'><strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'>HK$" . $amount . "</span></strong><span style='FONT-SIZE:9pt;FONT-FAMILY:&quot;Helvetica&quot;,sans-serif;COLOR:#333333'><u></u><u></u></span></p></td>
<td style='WIDTH:0.3pt;PADDING-BOTTOM:0in;PADDING-TOP:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in' valign='top' width='1'></td></tr>
</tbody>
</table>
</div>

										<!-- End Order Summary -->


										<div style='Margin-left:20px;Margin-right:20px'>
											<div style='line-height:20px;font-size:1px'>&nbsp;</div>
										</div>
										<div style='Margin-left:20px;Margin-right:20px'>
											<div style='line-height:5px;font-size:1px'>&nbsp;</div>
										</div>

										<!-- Best regards -->
										 <div style='Margin-left:20px;Margin-right:20px'>
										<strong>Order Details:</strong>
										<table style='Margin-top:0;Margin-bottom:20px;font-size:14px;line-height:21px;text-align:left' lang='x-size-14'>
										<tr><td>Name:</td><td> " . $customer_name . "</td></tr>
										<tr><td>Email:</td><td> " . $_POST["customer_email"] . "</td></tr>
										<tr><td>Phone:</td><td> " . $_POST["customer_phone"] . "</td></tr>
										<tr><td valign='top'>Company Name:</td><td> " . $_POST["company_name"] . "</td></tr>
										</table>


									   </div>

										<div style='Margin-left:20px;Margin-right:20px'>
											<div style='line-height:10px;font-size:1px'>&nbsp;</div>
										</div>

										<div style='Margin-left:20px;Margin-right:20px'>
										<strong>Delivery Details:</strong>
										<table style='Margin-top:0;Margin-bottom:20px;font-size:14px;line-height:21px;text-align:left' lang='x-size-14'>
										<tr><td>Name:</td><td> " . $recipient_name . "</td></tr>
										<tr><td>Email:</td><td> " . $email . "</td></tr>
										<tr><td>Phone:</td><td> " . $phone . "</td></tr>
										<tr><td valign='top'>Address:</td><td> " . $address . "</td></tr>
										<tr><td valign='top'>Delivery Time:</td><td> " . $_POST["delivery_date"] . " " . $_POST["delivery_time"] . "</td></tr>
										<tr><td valign='top'>Remarks:</td><td> " . $remarks . "</td></tr>
										</table>


									   </div>

<div style='Margin-left:20px;Margin-right:20px'><p style='Margin-top:0;font-size:14px;line-height:21px;text-align:left' lang='x-size-14'>Payment Method: Bank Transfer</p>
											<p style='Margin-top:0;font-size:14px;line-height:21px;text-align:left' lang='x-size-14'>
											 Please note that the order will only be confirmed once the payment is settled. The date of delivery may be affected if the transfer is delayed. We will prepare the chocolates freshly by hand and deliver to your designated address accordingly.
Once you have deposited the payment, please send us an email with your payment slip to info@artech-system.com and specify your order number as follows: <p style='color:red;display:inline;'>" . $paypal . "  (Please put it on the subject for easy reference)</p> <p
											</p>
										</div>


<div style='Margin-left:20px;Margin-right:20px;color:#58ACFA'>
											<p style='Margin-top:0;font-size:14px;line-height:21px;text-align:left' lang='x-size-14'>
											<strong>Company Account Details:</strong><br>
											Company Name:  Patisserie Sayvour Limited<br>
											Beneficiary's Bank Name: HSBC       <br>
											Beneficiary's Account no.  : 023-462187-838<br>
											SWIFT address: HSBCHKHHHKH<br>
											Bank address: 1 Queen's Road Central, Hong Kong<br>
											<br>
										</div>


										<div style='Margin-left:20px;Margin-right:20px'>
											<p style='Margin-top:0;Margin-bottom:20px;font-size:14px;line-height:21px;text-align:left;' lang='x-size-14'>Refrigerated Delivery: All our chocolates are made to order and will be delivered to your designated address according to your schedule.<bt>

Should you have further enquiry, please feel free to contact us at +852 2951 0005.<br><br>
Thank you once again for supporting Sayvour. We hope that you and your loved ones will savour every mouthful of our delicacies and every moment of receiving the personalised gifts made by us.</p>
										</div>


										<div style='Margin-left:20px;Margin-right:20px'>
											<div style='line-height:20px;font-size:1px'>&nbsp;</div>
										</div>

										<div style='Margin-left:20px;Margin-right:25px'>
															<p style='Margin-top:0;Margin-bottom:20px;font-size:14px;line-height:21px;text-align:left' lang='x-size-14'>
															Best regards,</p>
														</div>
														<div style='font-size:12px;font-style:normal;font-weight:normal' align='left'>
															<a href='http://www.sayvour.com.hk'><img style='border:0;display:block;min-height:auto;width:100%;max-width:150px; padding-left:20px' alt='' width='249' src='https://ci4.googleusercontent.com/proxy/WhjL_vvSpLarh-zQTnIIub3yktIgmMYyzgWhl_XTAMbJQ9LIpv2A32hCNW_U3MQg3wHDHewv_AnV0ysjc7_dtTBbxdltT6OvngagFLBQ44sF8Vmw8QWrq9G8jgY=s0-d-e1-ft#http://i1.cmail2.com/ei/d/F9/F24/F62/203624/csfinal/Sayvour-logo-b.png' class='CToWUd'></a>
														</div>
														<div style='Margin-left:20px;Margin-right:20px;Margin-top:20px'>
															<p style='Margin-top:0;Margin-bottom:20px'>Sayvour | Say Your Flavour</p>
														</div>
														<div style='Margin-left:20px;Margin-right:20px'>
															<div style='line-height:5px;font-size:1px'>&nbsp;</div>
														</div>
														<div style='Margin-left:20px;Margin-right:20px'>
															<div style='line-height:5px;font-size:1px'>&nbsp;</div>
														</div>
														<div style='Margin-left:20px;Margin-right:20px'>
															<div style='line-height:5px;font-size:1px'>&nbsp;</div>
														</div>
													</div>
												</div>
											</div>
										</div>

										<!-- End Best regards -->


										<!-- footer  -->

										<div style='Margin:0 auto;max-width:600px;min-width:320px;word-wrap:break-word;word-break:break-word'>
											<div style='border-collapse:collapse;display:table;width:100%'>
												<div style='text-align:left;font-size:12px;line-height:19px;color:#7A7A7A;font-family:Cabin,Avenir,sans-serif;Float:left;max-width:400px;min-width:320px;'>
													<div style='Margin-left:20px;Margin-right:20px;Margin-top:10px;Margin-bottom:10px'>
														<table style='border-collapse:collapse;table-layout:fixed'>
															<tbody>
																<tr>
																	<td style='padding:0;width:26px'><a style='text-decoration:underline;color:#9dc4c4' href='http://kk.cmail2.com/t/d-i-ijlhttd-l-r/' target='_blank'><img style='border:0' src='https://ci4.googleusercontent.com/proxy/cdaOVwx01pydUCeWanZ5I0WsxDjvph7JzEiKY3zimkrOp-LjXcGnE1GadRLWYfIKzlmiYSOtzr-WjjHJdYebPiyRLHmWcDY2Zz_HAol546DebSYvB0BcePndD26qkP8w-AE=s0-d-e1-ft#http://i8.cmail2.com/static/eb/master/13-the-blueprint-3/images/facebook.png' width='26' height='26' class='CToWUd'></a></td>
																	<td style='padding:0 0 0 3px;width:26px'><a style='text-decoration:underline;color:#9dc4c4' href='http://kk.cmail2.com/t/d-i-ijlhttd-l-y/' target='_blank'><img style='border:0' src='https://ci5.googleusercontent.com/proxy/H7Yt85uks7gPb4DmaC8HgjAqYMQhhSna9kYBtoUZr5D3lFKE-IJtZdN1MqyIopBh8YJYDX-igm7ScYklACfkd0Y1wvJ0BbBd3m1bcejcougYGa1dWg76ozQ-vG28HEqFDCbI=s0-d-e1-ft#http://i1.cmail2.com/static/eb/master/13-the-blueprint-3/images/instagram.png' width='26' height='26' class='CToWUd'></a></td>
																</tr>
															</tbody>
														</table>
														<div style='Margin-top:20px'>
															<div>Patisserie Sayvour Limited</div>
														</div>
														<div style='Margin-top:18px'>
															<div>Sayvour is an artisan confectionery specialising in handmade chocolates and pastries by using high quality ingredients from around the world.</div>
														</div>
													</div>
												</div>
												<div style='text-align:left;font-size:12px;line-height:19px;color:#9dc4c4;font-family:Cabin,Avenir,sans-serif;Float:left;max-width:320px;min-width:200px;'>
													<div style='Margin-left:20px;Margin-right:20px;Margin-top:10px;Margin-bottom:10px'></div>
												</div>
											</div>
										</div>
										<div style='Margin:0 auto;max-width:600px;min-width:320px;word-wrap:break-word;word-break:break-word'>
											<div style='border-collapse:collapse;display:table;width:100%'>
												<div style='text-align:left;font-size:12px;line-height:19px;color:#9dc4c4;font-family:Cabin,Avenir,sans-serif;max-width:600px;min-width:320px;'>
												</div>
											</div>
										</div>
										<div style='line-height:40px;font-size:40px'>&nbsp;</div>
									</div>
									<img style='overflow:hidden;display:block!important;min-height:1px!important;width:1px!important;border:0!important;margin:0!important;padding:0!important' src='https://ci4.googleusercontent.com/proxy/-HQ08vlGM2ltqJyXUtWXZlorkMV10CQ0pH8IJ2TQo0JNoLOLepN2GqRqjNvhCsxelytv0dohcw2kweEKYfPeyqw=s0-d-e1-ft#https://kk.cmail2.com/t/d-o-ijlhttd-l/o.gif' width='1' height='1' border='0' alt='' class='CToWUd'>
									<div class='yj6qo'></div>
									<div class='adL'></div>
								</div>
								<div class='adL'></div>
							</div>
						</div>

										<!--End  footer  -->


								";
		$mail->AddAddress($_POST["customer_email"]);
		if (!$mail->Send()) {
			error_log("n");
		} else {
			error_log("OK");
		}

		$y = $_POST["y"] - 1;
		$x = 1;
		while ($x <= $y) {
			$bought_items = str_replace('D.', '<div class="Dark">', $_POST["item_name_" . $x]);
			$bought_items = str_replace('W.', '<div class="White">', $bought_items);
			$bought_items = str_replace('P.', '<div class="Pink">', $bought_items);
			$bought_items = str_replace('_', '</div>', $bought_items);
			if ($_POST["item_name_" . $x] == 'Delivery Fee') {
				$x++;
				continue;
			} else {
				$query = "INSERT INTO `bought_item` (`record`, `paypal_id`, `username`, `product_name`, `price`, `amount`) VALUES (NULL, '" . $paypal . "', '" . $username . "', '" . $bought_items . "', '" . $_POST["amount_" . $x] . "', '" . $_POST["quantity_" . $x] . "')";
				$result1 = mysqli_query($conn, $query);
			}
			$x++;
		}

		$query = "DELETE FROM `cart` WHERE `cart`.`username` = '$username'";
		$result = mysqli_query($conn, $query);

		if (@$_POST["discount_rate"] != "") {
			$query = "INSERT INTO `used_coupon` (`record`, `date`, `username`, `receipt_no`, `code`) VALUES (NULL, '" . date("Y-m-d H:i:s") . "', '" . $username . "', '" . $paypal . "', '" . $_POST["code"] . "')";
			$result = mysqli_query($conn, $query);
			$usage_count--;
			$query = "UPDATE `coupon` SET `usage_count` = '" . $usage_count . "' WHERE `coupon`.`code` = '" . $_POST["code"] . "';";
			$result = mysqli_query($conn, $query);
		}

	}

	if ($_GET["Payment_Type"] == 'paypal') {

		$paypal = $_POST["custom"] . date("Y-m-d H:i:s");

		$sql = 'INSERT INTO `orders`(`record`, `paypal id`, `bought_items`, `amount`, `username`, `customer Fname`, `customer Lname`, `customer phone`, `customer email`, `customer address`, `company name`, `recipient Fname`,`recipient Lname`, `phone`, `email`, `address`, `delivery date`, `delivery time`, `remarks`, `time`, `status`' . $sql . ') VALUES (null,"' . $paypal . '",' . "'" . $bought_items . "'" . ',"' . $amount . '","' . $_POST["username"] . '","' . $_POST["customer_Fname"] . '","' . $_POST["customer_Lname"] . '","' . $_POST["customer_phone"] . '","' . $_POST["customer_email"] . '","' . $_POST["customer_address"] . '","' . $_POST["company_name"] . '","' . $_POST["recipient_Fname"] . '","' . $_POST["recipient_Lname"] . '","' . $_POST["phone"] . '","' . $_POST["email"] . '","' . preg_replace("/\r\n/", '<br>', htmlspecialchars($_POST["address"])) . '","' . $_POST["delivery_date"] . '","' . $_POST["delivery_time"] . '","' . preg_replace("/\r\n/", '<br>', htmlspecialchars($_POST["remarks"])) . '","' . date("Y-m-d H:i:s") . '","perpare"' . $sql1 . ')';
		error_log(print_r($sql, true) . "\r\n", 3, "../../order_insert.log");
		$query = mysqli_query($conn, $sql);

		$sql = "SELECT * FROM `orders` WHERE `paypal id` ='" . $paypal . "'";
		$query = mysqli_query($conn, $sql);
		$row = mysqli_fetch_assoc($query);
		$paypal1 = "SRI" . date("y") . "-" . sprintf("%'05d", $row["record"]);

		$query = "select * from cart where username='" . $_POST["username"] . "'";
		$result = mysqli_query($conn, $query);
		if (mysqli_num_rows($result) > 0) {
			while ($row = mysqli_fetch_assoc($result)) {
				$query = "INSERT INTO `bought_item` (`record`, `paypal_id`, `username`, `product_name`, `price`, `amount`) VALUES (NULL, '" . $paypal1 . "', '" . $row["username"] . "', '" . $row["product_name"] . "', '" . round($row["price"] * $discount_rate, 1) . "', '" . $row["amount"] . "')";
				$result1 = mysqli_query($conn, $query);
			}}

		$sql = "UPDATE `orders` SET `paypal id` = '" . $paypal1 . "' WHERE `paypal id` = '" . $paypal . "'";
		$query = mysqli_query($conn, $sql);
		$paypal = $paypal1;

		echo '
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.hidden {
    display: none !important;
}
</style>
</head>

<body>

<form method="post" name="paypal_form" id="paypal_form" action="https://www.paypal.com/cgi-bin/webscr">
<input class="hidden" name="rm" value="2"/>
<input class="hidden" name="cmd" value="_cart"/>
<input class="hidden" name="custom" value="' . $paypal . '"/>
<input class="hidden" name="business" value="info@sayvour.com.hk"/>
<!-- Where people will be sent after a successful order -->
<input class="hidden" name="return" value="http://' . $_SERVER['SERVER_NAME'] . '/en/Complete_purchase.php?url=' . $_SERVER['SERVER_NAME'] . '"/>
<!-- Where people will be sent after a cancelled order -->
<input class="hidden" name="cancel_return" value="http://' . $_SERVER['SERVER_NAME'] . '/en/e-shop.php?page=12"/>
<!-- The location of your IPN. PayPal needs to know this so it knows where to send the infomation about the order -->
<input class="hidden" name="notify_url" value="http://' . $_SERVER['SERVER_NAME'] . '/paypal.php"/>
<input class="hidden" name="quantity" value="2"/>
<input class="hidden" name="charset" value="utf-8"/> ';

		$y = $_POST["y"] - 1;
		$x = 1;
		while ($x <= $y) {
			$amount = $_POST["amount_" . $x];
			echo "<input class='hidden' name='item_name_" . $x . "' value='" . $_POST["item_name_" . $x] . "'/>";
			echo '<input class="hidden" name="amount_' . $x . '" value="' . $amount . '"/>';
			echo '<input class="hidden" name="quantity_' . $x . '" value="' . $_POST["quantity_" . $x] . '"/>';
			$x++;
		}

		echo '<input class="hidden" name="upload" value="1"/>
<input class="hidden" name="txn_type" value="cart"/>
<input class="hidden" name="currency_code" value="HKD"/>
<input  class="hidden" type="submit" name="place-order" value="Place Order">
</form>
<script>document.getElementById("paypal_form").submit();</script>
</body>
</html>
';}
} else {
	$url = "../e-shop.php";
	echo "<script>";
	echo "alert('Transaction failed. Please try again.');window.location.href='$url';";
	echo "</script>";
}
?>
<html>
<head>
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', '1705821553071403', {
em: 'insert_email_variable,'
});
fbq('track', 'PageView');

fbq('track', 'InitiateCheckout');


</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=1705821553071403&ev=PageView&noscript=1"
/></noscript>
<!-- DO NOT MODIFY -->
<!-- End Facebook Pixel Code -->

</head>
<body>
</body>
</html>