<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
include("includes/database.php");
include("functions/functions.php");
// Load Composer's autoloader
require "PHPMailer/vendor/autoload.php";
if(isset($_POST["send_guestName"])){
$send_guestName = mysqli_real_escape_string($con, $_POST["send_guestName"]);
$send_guestMobil = mysqli_real_escape_string($con, $_POST["send_guestMobile"]);
$send_guestEmail = mysqli_real_escape_string($con, $_POST["send_guestEmail"]);
$send_guestCity = mysqli_real_escape_string($con, $_POST["send_guestCity"]);
$send_guestAddress = mysqli_real_escape_string($con, $_POST["send_guestAddress"]);
$clientIPAddress = getIp();
$invoice_no = time();
$send_guestMobile = "971".$send_guestMobil;
$prod_id = mysqli_real_escape_string($con, $_POST["send_proIdef"]);
$send_prodPrice = mysqli_real_escape_string($con, $_POST["send_prodPrice"]);
$prod_qty = mysqli_real_escape_string($con, $_POST["send_singProdQty"]);
$fullAdd = $send_guestAddress.", ".$send_guestCity;
//getting the delivery rate
$delivery_rate = 0;
//getting the delivery rate
//getting product price & number of items
$total = $send_prodPrice * $prod_qty;
$status = "Pending";
$pmt_method = "cash_on_delivery";
//getting product price & number of items
//getting the product image
$_nuProImgQu = mysqli_query($con, "select product_image from product where product_id = '$prod_id'");
$_rowProImgQu = mysqli_fetch_array($_nuProImgQu);
$_fchProImg = $_rowProImgQu["product_image"];
//getting the product image
$chk_email = mysqli_query($con, "select * from customers where customer_email = '$send_guestEmail'");
$cnt_gstEmail = mysqli_num_rows($chk_email);
if($cnt_gstEmail >= 1){
//Fetching the customer id
$_rowQuery = mysqli_fetch_array($chk_email);
$customer_id = $_rowQuery["customer_id"];
//Fetching the customer id
$pen_query = "insert into pending_orders (customer_id, invoice_no, product_id, quantity, order_status) values ('$customer_id','$invoice_no','$prod_id','$prod_qty','$status')";
$run_penq = mysqli_query($con, $pen_query);
//if($total >= 100){ $delivery_rate = 0; }
//$total = $total + $delivery_rate;
if($run_penq){
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'mail.zetongifts.com';
$mail->SMTPAuth = true;
$mail->Username = 'developer@zetongifts.com';
$mail->Password = 'MbszOo^C0c$A';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom("order@zetongifts.com", "Zeton Giftshop");
$mail->addAddress($send_guestEmail, "Your Order from Zeton Giftshop");
$mail->addBCC("order@zetongifts.com", "New Quick Order");
$mail->addReplyTo("order@zetongifts.com", "Zeton Giftshop");
$mail->isHTML(true);
// Content
$mail->Subject = "Your Order from Zeton Giftshop";
$mail->Body = "
<html>
<head>
<style>
h1, h2, h3, h4, h5, h6, p{
margin-bottom: 10px;
}
hr{
border-top: 1px solid rgba(0,0,0,0.1);
}
body{
background: #f1f1f1;
padding:2%;
margin:auto;
font-family: 'Quicksand', sans-serif;
}
.center {
margin: auto;
width: 96%;
border: 3px solid #e7e7e7;
padding:2%;
background: #ffffff;
border-radius: 10px;
}
.wizBtn{
padding: 14px 20px;
background: #f0d264;
color: #333;
text-decoration: none;
border-radius: 12px;
transition: all 1s ease;
}
.wizBtn:hover {
-webkit-box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
-moz-box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
}
.btnP{
padding: 30px 0;
}
</style>
<link href='https://fonts.googleapis.com/css2?family=Quicksand:wght@600&display=swap' rel='stylesheet' />
</head>
<body>
<div class='center'>
<center>
<img src='https://www.zetongifts.com/assets/images/logo/blue-logo.jpg' width='70%' alt='zetongiftshop' title='zetongiftshop' style='margin:20px;' />
</center><hr />
<h2>Dear $send_guestName,</h2>
<h3>Thanks For Shopping With Us!</h3>
<p>Your Order Has Been Received!</p>
<hr />
<p>Product Price: $currency $send_prodPrice</p>
<p>Total Quantity: $prod_qty</p>
<p>Total Amount Due: $currency $total</p>
<!--<p>Your Order Reference Number is $invoice_no</p>-->
<p>Product Image:</p>
<p><img src='https://www.zetongifts.com/images/product_images/$_fchProImg' width='100' /></p>
<hr />
<h4>Important Points:</h4>
<p>Please note that your product delivery will be scheduled shortly.</p>
<p>Thanks Again For Shopping With Us!</p><hr />
<p>Phone: <a href='tel:+971 555 566 581'>+971 555 566 581</a></p>
<p>Email: <a href='mailto:info@zetongifts.com'>info@zetongifts.com</a></p>
<p>Website: <a href='https://www.zetongifts.com/'>www.zetongifts.com</a></p>
<img src='https://www.zetongifts.com/assets/images/logo/logo.jpg' width='50%' alt='zetongiftshop' title='zetongiftshop' style='margin:20px;' />
</div>
</body>
</html>
";
//send mail ends
if(!$mail->send()){
echo $mail->ErrorInfo;
}else{
$insert_order = "insert into customer_orders (customer_id, due_amount, invoice_no, total_products, order_date, order_status, payment_method, customer_address, customer_phone, customer_location, order_discount, total_amount, approval_status) values ('$customer_id','$total','$invoice_no','$prod_qty',NOW() + INTERVAL 10 HOUR,'$status','$pmt_method','$fullAdd','$send_guestMobile','$send_guestCity','','','')";
$run_order = mysqli_query($con, $insert_order);
if($run_order){
echo "success";
}else{ echo "customer-order-problem"; }
}
}else{
echo "Pending Order Problem";
}
}else{
$custInfo_query = "insert into customers(customer_ip, customer_user_agent, customer_name, customer_email, customer_pass, customer_address, customer_gender, customer_phone, customer_image, customer_location, actual_location, register_date,pescription_status) values('$clientIPAddress','$customa_user_agent_id','$send_guestName','$send_guestEmail','$send_guestMobile','$fullAdd','Male','$send_guestMobile','default.jpg','inside_region','$send_guestCity',NOW(),'')";
$insert_custInfo = mysqli_query($con, $custInfo_query);
if($insert_custInfo){
//Creating the customer id
$_runIDQu = mysqli_query($con, "select * from customers ORDER BY customer_id DESC LIMIT 1");
$_rowQuery = mysqli_fetch_array($_runIDQu);
$customer_id = $_rowQuery["customer_id"];
//Creating the customer id
$pen_query = "insert into pending_orders (customer_id, invoice_no, product_id, quantity, order_status) values ('$customer_id','$invoice_no','$prod_id','$prod_qty','$status')";
$run_penq = mysqli_query($con, $pen_query);
//if($total >= 100){ $delivery_rate = 0; }
//$total = $total + $delivery_rate;
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'mail.zetongifts.com';
$mail->SMTPAuth = true;
$mail->Username = 'developer@zetongifts.com';
$mail->Password = 'MbszOo^C0c$A';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom("order@zetongifts.com", "Zeton Giftshop");
$mail->addAddress($send_guestEmail, "Your Order from Zeton Giftshop");
$mail->addBCC("order@zetongifts.com", "New Quick Order");
$mail->addReplyTo("order@zetongifts.com", "Zeton Giftshop");
$mail->isHTML(true);
// Content
$mail->Subject = "Your Order from Zeton Giftshop";
$mail->Body = "
<html>
<head>
<style>
h1, h2, h3, h4, h5, h6, p{
margin-bottom: 10px;
}
hr{
border-top: 1px solid rgba(0,0,0,0.1);
}
body{
background: #f1f1f1;
padding:2%;
margin:auto;
font-family: 'Quicksand', sans-serif;
}
.center {
margin: auto;
width: 96%;
border: 3px solid #e7e7e7;
padding:2%;
background: #ffffff;
border-radius: 10px;
}
.wizBtn{
padding: 14px 20px;
background: #f0d264;
color: #333;
text-decoration: none;
border-radius: 12px;
transition: all 1s ease;
}
.wizBtn:hover {
-webkit-box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
-moz-box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
}
.btnP{
padding: 30px 0;
}
</style>
<link href='https://fonts.googleapis.com/css2?family=Quicksand:wght@600&display=swap' rel='stylesheet' />
</head>
<body>
<div class='center'>
<center>
<img src='https://www.zetongifts.com/assets/images/logo/blue-logo.jpg' width='70%' alt='zetongiftshop' title='zetongiftshop' style='margin:20px;' />
</center><hr />
<h2>Dear $send_guestName,</h2>
<h3>Thanks For Shopping With Us!</h3>
<p>An account has been created for you.</p>
<p>To Log into Your Account, please use the following details:</p>
<hr />
<p>Email Address: $send_guestEmail</p>
<p>Password: $send_guestMobile</p>
<hr />
<p>Product Price: $currency $send_prodPrice</p>
<p>Total Quantity: $prod_qty</p>
<p>Total Amount Due: $currency $total</p>
<p>Product Image:</p>
<p><img src='https://www.zetongifts.com/images/product_images/$_fchProImg' width='100' /></p>
<hr />
<h4>Important Points:</h4>
<p>Please note that your product delivery will be scheduled shortly.</p>
<p>Thanks Again For Shopping With Us!</p><hr />
<p>Phone: <a href='tel:+971 555 566 581'>+971 555 566 581</a></p>
<p>Email: <a href='mailto:info@zetongifts.com'>info@zetongifts.com</a></p>
<p>Website: <a href='https://www.zetongifts.com/'>www.zetongifts.com</a></p>
<img src='https://www.zetongifts.com/assets/images/logo/logo.jpg' width='50%' alt='zetongiftshop' title='zetongiftshop' style='margin:20px;' />
</div>
</body>
</html>
";
//send mail ends
if(!$mail->send()){
echo $mail->ErrorInfo;
}else{
$insert_order = "insert into customer_orders (customer_id, due_amount, invoice_no, total_products, order_date, order_status, payment_method, customer_address, customer_phone, customer_location, order_discount, total_amount, approval_status) values ('$customer_id','$total','$invoice_no','$prod_qty',NOW() + INTERVAL 10 HOUR,'$status','$pmt_method','$fullAdd','$send_guestMobile','$send_guestCity','','','')";
$run_order = mysqli_query($con, $insert_order);
if($run_order){
echo "success";
}else{ echo "customer-order-problem"; }
}
}else{echo "customer-create-problem";}
}
}
?>