<?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("functions/functions.php");
// Load Composer's autoloader
require "PHPMailer/vendor/autoload.php";
function sendEmail($to, $from, $fromName, $body){
$mail = new PHPMailer(true);
$mail->setFrom($from, $fromName);
$mail->addAddress($to);
$mail->isHTML(true);
$mail->Subject = $comp_title;
$mail->Body = $body;
return $mail->send();
}
if(isset($_POST["post_response"])){
global $con;
$customer_id = $_POST["customer_id"];
$ticket_id = $_POST["ticket_id"];
$ticket_number = mysqli_real_escape_string($con, $_POST["ticket_number"]);
$ticket_response = mysqli_real_escape_string($con, $_POST["ticket_response"]);
if($ticket_response == ""){
echo "Please Type Something!";
exit();
}else{
$response_query = "insert into ticket_reply (ticket_id, ticket_no, customer_id, reply, reply_date) values ('$ticket_id','$ticket_number','$customer_id','$ticket_response',NOW())";
$run_response = mysqli_query($con, $response_query);
if($run_response){
echo "Response Sent!";
}
}
}
if(isset($_POST["view_responses"])){
global $con;
$ticket_id = $_POST["ticket_id"];
$ticket_num = $_POST["ticket_number"];
$cust_id = $_POST["customer_id"];
$get_reply = "select * from ticket_reply where ticket_id = '$ticket_id' AND ticket_no = '$ticket_num' AND customer_id = '$cust_id' ORDER BY 1 DESC";
$run_reply = mysqli_query($con, $get_reply);
$reply_count = mysqli_num_rows($run_reply);
if($reply_count == 0){
}else{
while($row_reply = mysqli_fetch_array($run_reply)){
$reply_body = $row_reply["reply"];
$reply_date = $row_reply["reply_date"];
echo "
<div style='padding: 15px; border: 1px solid #ccc;'>
<p style='text-align: justify;'>$reply_body</p><hr />
<p style='color: #9900cc; text-align: right;'>Date: $reply_date</p>
</div><br />
";
}
}
}
if(isset($_POST["add_to_cart"])){
global $con;
$user_ip = getIp();
$qty = 1;
$user_ip = mysqli_real_escape_string($con, $user_ip);
$customa_user_agent_id = mysqli_real_escape_string($con, $customa_user_agent_id);
$produ_id = mysqli_real_escape_string($con, $_POST["pro_id"]);
$check_pro = "select * from cart where ip_address = '$user_ip' AND product_id = '$produ_id' AND customer_user_agent = '$customa_user_agent_id'";
$run_check = mysqli_query($con, $check_pro);
$check_cart = mysqli_num_rows($run_check);
if($check_cart == 1){
echo "already_in_cart";
}else{
$_query = "select * from product where product_id = '$produ_id'";
$_run = mysqli_query($con, $_query);
$_row = mysqli_fetch_array($_run);
$prod_title = $_row["product_name"];
$prod_image = $_row["product_image"];
$prod_price = $_row["product_price"];
$prod_title = mysqli_real_escape_string($con, $prod_title);
$insert_pro = "insert into cart (product_id, customer_user_agent, ip_address, product_title, product_image, quantity, product_price, total) values ('$produ_id', '$customa_user_agent_id', '$user_ip', '$prod_title', '$prod_image', '$qty', '$prod_price', '$prod_price')";
$run_pro = mysqli_query($con, $insert_pro);
if($run_pro){
echo "Product Added!";
}
}
}
if(isset($_POST["add_to_cart_qty"])){
global $con;
$user_ip = getIp();
$qty = $_POST["pro_qty"];
$user_ip = mysqli_real_escape_string($con, $user_ip);
$customa_user_agent_id = mysqli_real_escape_string($con, $customa_user_agent_id);
$produ_id = mysqli_real_escape_string($con, $_POST["pro_id"]);
$check_pro = "select * from cart where ip_address = '$user_ip' AND product_id = '$produ_id' AND customer_user_agent = '$customa_user_agent_id'";
$run_check = mysqli_query($con, $check_pro);
$check_cart = mysqli_num_rows($run_check);
if($check_cart > 0){
echo "already_in_cart";
exit();
}else{
$query = "select * from product where product_id = '$produ_id'";
$run = mysqli_query($con, $query);
$row = mysqli_fetch_array($run);
$prod_title = $row["product_name"];
$prod_image = $row["product_image"];
$prod_price = $row["product_price"];
$prod_title = mysqli_real_escape_string($con, $prod_title);
$_cartTot = $qty * $prod_price;
$insert_pro = "insert into cart (product_id, customer_user_agent, ip_address, product_title, product_image, quantity, product_price, total) values ('$produ_id', '$customa_user_agent_id', '$user_ip', '$prod_title', '$prod_image', '$qty', '$prod_price', '$_cartTot')";
$run_pro = mysqli_query($con, $insert_pro);
if($run_pro){
echo "Product Added!";
}
}
}
if(isset($_POST["total_cartPage_products"])){
global $con;
$ip = getIp();
$run_items = mysqli_query($con, "select * from cart where ip_address = '$ip' AND customer_user_agent = '$customa_user_agent_id'");
$count_items = mysqli_num_rows($run_items);
if($count_items <= 0){}else{
while($row_sidebarQuer = mysqli_fetch_array($run_items)){
$neuDB_proID = $row_sidebarQuer["product_id"];
$neuDB_proTitle = $row_sidebarQuer["product_title"];
$neuDB_proImg = $row_sidebarQuer["product_image"];
$neuDB_proQty = $row_sidebarQuer["quantity"];
$neuDB_proPrice = $row_sidebarQuer["product_price"];
$neuDB_proTotal = $row_sidebarQuer["total"];
$neu_slugQuer = mysqli_query($con, "select product_urlslug from product where product_id = '$neuDB_proID' LIMIT 1");
$row_neu_slugQuer = mysqli_fetch_array($neu_slugQuer);
$neuDB_proUrlSlug = $row_neu_slugQuer["product_urlslug"];
echo "
<tr>
<td class='product-thumbnail'>
<figure>
<a href='bk-$neuDB_proUrlSlug'>
<img src='images/product_images/$neuDB_proImg' width='100' height='100' alt='$neuDB_proTitle' />
</a>
</figure>
</td>
<td class='product-name'>
<div class='product-name-section'>
<a href='bk-$neuDB_proUrlSlug'>$neuDB_proTitle</a>
</div>
</td>
<td class='product-subtotal'>
<span class='amount'>$wiscoy_currency $neuDB_proPrice</span>
</td>
<td class='product-quantity'>
<div class='input-group'>
<select class='form-control qty' id='qty-$neuDB_proID' pid='$neuDB_proID' actPrice='$neuDB_proPrice'>
<option value='$neuDB_proQty'>$neuDB_proQty</option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
</select>
</div>
</td>
<td class='product-price'>
<span class='amount'>$wiscoy_currency $neuDB_proTotal</span>
</td>
<td class='product-close' id='shopping_cart_trash' pid='$neuDB_proID'>
<a href='#' class='product-remove' title='Remove this product'>
<i class='fas fa-times'></i>
</a>
</td>
</tr>
";
}
}
}
if(isset($_POST["update_item"])){
global $con;
$ip = getIp();
$prod_id = $_POST["pro_id"];
$qty = $_POST["quantity"];
$price = $_POST["prod_price"];
$total = $_POST["total_amt"];
$ip = mysqli_real_escape_string($con, $ip);
$customa_user_agent_id = mysqli_real_escape_string($con, $customa_user_agent_id);
$get_query = "update cart set quantity = '$qty', product_price = '$price', total = '$total' where ip_address = '$ip' AND product_id = '$prod_id' AND customer_user_agent = '$customa_user_agent_id'";
$run_query = mysqli_query($con, $get_query);
}
if(isset($_POST["total_sidebar_products"])){
global $con;
$ip = getIp();
$run_items = mysqli_query($con, "select * from cart where ip_address = '$ip' AND customer_user_agent = '$customa_user_agent_id'");
$count_items = mysqli_num_rows($run_items);
if($count_items <= 0){}else{
while($row_sidebarQuer = mysqli_fetch_array($run_items)){
$neuDB_proID = $row_sidebarQuer["product_id"];
$neuDB_proTitle = $row_sidebarQuer["product_title"];
$neuDB_proImg = $row_sidebarQuer["product_image"];
$neuDB_proQty = $row_sidebarQuer["quantity"];
$neuDB_proPrice = $row_sidebarQuer["product_price"];
$neu_slugQuer = mysqli_query($con, "select product_urlslug from product where product_id = '$neuDB_proID' LIMIT 1");
$row_neu_slugQuer = mysqli_fetch_array($neu_slugQuer);
$neuDB_proUrlSlug = $row_neu_slugQuer["product_urlslug"];
echo "
<div class='product product-cart'>
<figure class='product-media'>
<a href='bk-$neuDB_proUrlSlug'>
<img src='images/product_images/$neuDB_proImg' alt='$neuDB_proTitle' width='80' height='88' />
</a>
<button class='btn btn-link btn-close' id='cart_trash' pid='$neuDB_proID'>
<i class='fas fa-times'></i><span class='sr-only'>Close</span>
</button>
</figure>
<div class='product-detail'>
<a href='bk-$neuDB_proUrlSlug' class='product-name'>$neuDB_proTitle</a>
<div class='price-box'>
<span class='product-quantity'>$neuDB_proQty</span>
<span class='product-price'>$wiscoy_currency $neuDB_proPrice</span>
</div>
</div>
</div>
";
}
}
}
if(isset($_POST["total_price"])){
global $con;
$total = 0;
$delRate = 0;
$user_ip = getIp();
$newTotal = 0;
$sel_price = "select * from cart where ip_address = '$user_ip' AND customer_user_agent = '$customa_user_agent_id'";
$run_price = mysqli_query($con, $sel_price);
while($row_p = mysqli_fetch_array($run_price)){
$prod_id = $row_p["product_id"];
$prod_qty = $row_p["quantity"];
$prod_price = "select * from product where product_id = '$prod_id'";
$run_pro_price = mysqli_query($con, $prod_price);
while($row_price = mysqli_fetch_array($run_pro_price)){
$product_price = array($row_price["product_price"]);
$values = array_sum($product_price);
$total = $total + ($values * $prod_qty);
if($total >= 100){$delRate = 0;}else{$delRate = $wiz_rate_ins;}
$newTotal = $total + $delRate;
}
}
$total_val = number_format($newTotal,2);
echo "$currency $total_val";
}
if(isset($_POST["total_items"])){
global $con;
$ip = getIp();
$get_items = "select * from cart where ip_address = '$ip' AND customer_user_agent = '$customa_user_agent_id'";
$run_items = mysqli_query($con, $get_items);
$count_items = mysqli_num_rows($run_items);
echo $count_items;
}
if(isset($_POST["delete_item"])){
global $con;
$ip = getIp();
$prod_id = $_POST["pro_id"];
$get_query = "delete from cart where ip_address = '$ip' AND product_id = '$prod_id' AND customer_user_agent = '$customa_user_agent_id'";
$run_query = mysqli_query($con, $get_query);
}
?>