784 lines
37 KiB
PHP
784 lines
37 KiB
PHP
<?php
|
|
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// PDF creator +++++++++++++++++++++++++++++++++++++++
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
include dirname(__FILE__).'/custom/customfunctions.php';
|
|
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// PDF creator +++++++++++++++++++++++++++++++++++++++
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// include autoloader
|
|
require dirname(__FILE__).'/lib/dompdf/autoload.inc.php';
|
|
|
|
// reference the Dompdf namespace
|
|
use Dompdf\Dompdf;
|
|
|
|
// instantiate and use the dompdf class
|
|
use Dompdf\Options;
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++
|
|
//dompdf libary +++++++++++++++++++++++++++
|
|
//+++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
$options = new Options();
|
|
$options->set('isRemoteEnabled', true);
|
|
$dompdf = new Dompdf($options);
|
|
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// include PHP Mailer+++++++++++++++++++++++++++++++++++++
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use PHPMailer\PHPMailer\Exception;
|
|
require dirname(__FILE__).'/lib/mail/PHPMailer.php';
|
|
require dirname(__FILE__).'/lib/mail/SMTP.php';
|
|
require dirname(__FILE__).'/lib/mail/Exception.php';
|
|
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// Send Mail via PHPMailer++++++++++++++++++++++++++++++++
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
function send_mail_by_PHPMailer($to, $subject, $message, $attachment, $attachment_name){
|
|
|
|
// SEND MAIL by PHP MAILER
|
|
$mail = new PHPMailer();
|
|
$mail->CharSet = 'UTF-8';
|
|
//$mail->isSMTP(); // Use SMTP protocol
|
|
$mail->Host = email_host_name; // Specify SMTP server
|
|
$mail->SMTPAuth = true; // Auth. SMTP
|
|
$mail->Username = email; // Mail who send by PHPMailer
|
|
$mail->Password = email_outgoing_pw; // your pass mail box
|
|
$mail->SMTPSecure = email_outgoing_security; // Accept SSL
|
|
$mail->Port = email_outgoing_port; // port of your out server
|
|
$mail->setFrom(email, mail_from); // Mail to send at
|
|
$mail->addAddress($to); // Add sender
|
|
$mail->addReplyTo(email_reply_to); // Adress to reply
|
|
$mail->isHTML(true); // use HTML message
|
|
$mail->Subject = $subject;
|
|
$mail->Body = $message;
|
|
if (!empty($attachment) || $attachment != ''){
|
|
$mail->AddStringAttachment($attachment, $attachment_name, 'base64', 'application/pdf');
|
|
}
|
|
|
|
// SEND
|
|
if( !$mail->send() ){
|
|
|
|
// render error if it is
|
|
$tab = array('error' => 'Mailer Error: '.$mail->ErrorInfo );
|
|
echo json_encode($tab);
|
|
exit;
|
|
}
|
|
else{
|
|
// return true if message is send
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// Generated PDF ++++++++++++++++++++++++++++++++
|
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
function generatedPDF($input,$filename){
|
|
$options = new Options();
|
|
$options->set('isRemoteEnabled', true);
|
|
$dompdf = new Dompdf($options);
|
|
$dompdf->loadHtml($input);
|
|
|
|
// (Optional) Setup the paper size and orientation
|
|
$dompdf->setPaper('A4', 'portrait');
|
|
// Render the HTML as PDF
|
|
$dompdf->render();
|
|
ob_end_clean();
|
|
$dompdf->stream($filename.'.pdf', array("Attachment" => false));
|
|
}
|
|
|
|
|
|
// Function that will connect to the MySQL database
|
|
function pdo_connect_mysql() {
|
|
try {
|
|
// Connect to the MySQL database using the PDO interface
|
|
$pdo = new PDO('mysql:host=' . db_host . ';dbname=' . db_name . ';charset=utf8', db_user, db_pass);
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
return $pdo;
|
|
} catch (PDOException $exception) {
|
|
// Could not connect to the MySQL database! If you encounter this error, ensure your db settings are correct in the config file!
|
|
exit('Failed to connect to database!');
|
|
}
|
|
}
|
|
// Function to retrieve a product from cart by the ID and options string
|
|
function &get_cart_product($id, $options) {
|
|
$p = null;
|
|
if (isset($_SESSION['cart'])) {
|
|
foreach ($_SESSION['cart'] as &$product) {
|
|
if ($product['id'] == $id && $product['options'] == $options) {
|
|
$p = &$product;
|
|
return $p;
|
|
}
|
|
}
|
|
}
|
|
return $p;
|
|
}
|
|
|
|
// Populate categories function
|
|
function populate_categories($categories, $selected = 0, $parent_id = 0, $n = 0) {
|
|
$html = '';
|
|
foreach ($categories as $category) {
|
|
if ($parent_id == $category['parent_id'] && $category['status'] == 1) {
|
|
$html .= '<option value="' . $category['id'] . '"' . ($selected == $category['id'] ? ' selected' : '') . '>' . str_repeat('--', $n) . ' ' . $category['name'] . '</option>';
|
|
$html .= populate_categories($categories, $selected, $category['id'], $n+1);
|
|
}
|
|
}
|
|
return $html;
|
|
}
|
|
|
|
// Send order details email function
|
|
function send_order_details_email($email, $products, $first_name, $last_name, $address_street, $address_city, $address_state, $address_zip, $address_country, $subtotal, $discounttotal,$shippingtotal,$taxtotal,$total, $order_id) {
|
|
include './custom/translations/translations_'.strtoupper(language_code).'.php';
|
|
// Send payment notification to webmaster
|
|
$address_name = htmlspecialchars($first_name ?? '', ENT_QUOTES).' '.htmlspecialchars($last_name ?? '', ENT_QUOTES);
|
|
if (email_notifications) {
|
|
|
|
$subject = $subject_order_notification;
|
|
$headers = 'From: ' . mail_from . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'Return-Path: ' . mail_from . "\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-Type: text/html; charset=UTF-8' . "\r\n";
|
|
ob_start();
|
|
include './custom/order-notification-template.php';
|
|
$order_notification_template = ob_get_clean();
|
|
send_mail_by_PHPMailer(email, $subject, $order_notification_template, '', '');
|
|
}
|
|
if (!mail_enabled) {
|
|
return;
|
|
}
|
|
$subject = $subject_new_order;
|
|
$headers = 'From: ' . mail_from . "\r\n" . 'Reply-To: ' . mail_from . "\r\n" . 'Return-Path: ' . mail_from . "\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-Type: text/html; charset=UTF-8' . "\r\n";
|
|
ob_start();
|
|
include './custom/order-details-template.php';
|
|
$order_details_template = ob_get_clean();
|
|
send_mail_by_PHPMailer($email, $subject, $order_details_template, '', '');
|
|
}
|
|
|
|
//Send email to administrator for out of stock notification // only for registered users
|
|
function send_product_notification_email($email,$product_details){
|
|
include './custom/translations/translations_'.strtoupper(language_code).'.php';
|
|
|
|
$subject = $subject_out_of_stock.' - '.$product_details;
|
|
$headers = 'From: ' . mail_from . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'Return-Path: ' . mail_from . "\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-Type: text/html; charset=UTF-8' . "\r\n";
|
|
|
|
$message = $product_details.' are out of stock. Please notify '.$email.' when available';
|
|
//mail(email, $subject, $message, $headers);
|
|
send_mail_by_PHPMailer(email, $subject, $message, '', '');
|
|
}
|
|
|
|
// Template admin header
|
|
function template_admin_header($title, $selected = 'orders', $selected_child = 'view') {
|
|
$base_url = 'https://'.$_SERVER['SERVER_NAME'].'/';
|
|
$site_name = site_name;
|
|
$icon_image = icon_image;
|
|
$admin_links = '
|
|
<a href="index.php?page=dashboard"' . ($selected == 'dashboard' ? ' class="selected"' : '') . '><i class="fas fa-tachometer-alt"></i>Dashboard</a>
|
|
<a href="index.php?page=orders"' . ($selected == 'orders' ? ' class="selected"' : '') . '><i class="fas fa-shopping-cart"></i>Orders</a>
|
|
<div class="sub">
|
|
<a href="index.php?page=orders"' . ($selected == 'orders' && $selected_child == 'view' ? ' class="selected"' : '') . '><span>◼</span>View Orders</a>
|
|
<a href="index.php?page=order_manage"' . ($selected == 'orders' && $selected_child == 'manage' ? ' class="selected"' : '') . '><span>◼</span>Create Order</a>
|
|
</div>
|
|
<a href="index.php?page=products"' . ($selected == 'products' ? ' class="selected"' : '') . '><i class="fas fa-box-open"></i>Products</a>
|
|
<div class="sub">
|
|
<a href="index.php?page=products"' . ($selected == 'products' && $selected_child == 'view' ? ' class="selected"' : '') . '><span>◼</span>View Products</a>
|
|
<a href="index.php?page=product"' . ($selected == 'products' && $selected_child == 'manage' ? ' class="selected"' : '') . '><span>◼</span>Create Product</a>
|
|
</div>
|
|
<a href="index.php?page=categories"' . ($selected == 'categories' ? ' class="selected"' : '') . '><i class="fas fa-list"></i>Categories</a>
|
|
<div class="sub">
|
|
<a href="index.php?page=categories"' . ($selected == 'categories' && $selected_child == 'view' ? ' class="selected"' : '') . '><span>◼</span>View Categories</a>
|
|
<a href="index.php?page=category"' . ($selected == 'categories' && $selected_child == 'manage' ? ' class="selected"' : '') . '><span>◼</span>Create Category</a>
|
|
</div>
|
|
<a href="index.php?page=accounts"' . ($selected == 'accounts' ? ' class="selected"' : '') . '><i class="fas fa-users"></i>Accounts</a>
|
|
<div class="sub">
|
|
<a href="index.php?page=accounts"' . ($selected == 'accounts' && $selected_child == 'view' ? ' class="selected"' : '') . '><span>◼</span>View Accounts</a>
|
|
<a href="index.php?page=account"' . ($selected == 'accounts' && $selected_child == 'manage' ? ' class="selected"' : '') . '><span>◼</span>Create Account</a>
|
|
</div>
|
|
<a href="index.php?page=shipping"' . ($selected == 'shipping' ? ' class="selected"' : '') . '><i class="fas fa-shipping-fast"></i>Shipping</a>
|
|
<div class="sub">
|
|
<a href="index.php?page=shipping"' . ($selected == 'shipping' && $selected_child == 'view' ? ' class="selected"' : '') . '><span>◼</span>View Shipping Methods</a>
|
|
<a href="index.php?page=shipping_process"' . ($selected == 'shipping' && $selected_child == 'manage' ? ' class="selected"' : '') . '><span>◼</span>Create Shipping Method</a>
|
|
</div>
|
|
<a href="index.php?page=discounts"' . ($selected == 'discounts' ? ' class="selected"' : '') . '><i class="fas fa-tag"></i>Giftcards / Discounts</a>
|
|
<div class="sub">
|
|
<a href="index.php?page=discounts"' . ($selected == 'discounts' && $selected_child == 'view' ? ' class="selected"' : '') . '><span>◼</span>View Giftcard / Discounts</a>
|
|
<a href="index.php?page=discount"' . ($selected == 'discounts' && $selected_child == 'manage' ? ' class="selected"' : '') . '><span>◼</span>Create Giftcard / Discount</a>
|
|
</div>
|
|
<a href="index.php?page=taxes"' . ($selected == 'taxes' ? ' class="selected"' : '') . '><i class="fa-solid fa-percent"></i>Taxes</a>
|
|
<div class="sub">
|
|
<a href="index.php?page=taxes"' . ($selected == 'taxes' && $selected_child == 'view' ? ' class="selected"' : '') . '><span>◼</span>View Taxes</a>
|
|
<a href="index.php?page=tax"' . ($selected == 'taxes' && $selected_child == 'manage' ? ' class="selected"' : '') . '><span>◼</span>Create Tax</a>
|
|
</div>
|
|
<a href="index.php?page=media"' . ($selected == 'media' ? ' class="selected"' : '') . '><i class="fas fa-images"></i>Media</a>
|
|
<a href="index.php?page=emailtemplates"' . ($selected == 'emailtemplates' ? ' class="selected"' : '') . '><i class="fas fa-envelope"></i>Email Templates</a>
|
|
<a href="index.php?page=settings"' . ($selected == 'settings' ? ' class="selected"' : '') . '><i class="fas fa-tools"></i>Settings</a>
|
|
<div class="sub">
|
|
<a href="index.php?page=settings"' . ($selected == 'settings' && $selected_child == '' ? ' class="selected"' : '') . '><span>◼</span>Settings</a>
|
|
<a href="index.php?page=language"' . ($selected == 'language' && $selected_child == '' ? ' class="selected"' : '') . '><span>◼</span>Language</a>
|
|
</div>
|
|
';
|
|
// DO NOT INDENT THE BELOW CODE
|
|
echo <<<EOT
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,minimum-scale=1">
|
|
<title>$title</title>
|
|
<link rel="icon" type="image/png" href="{$base_url}$icon_image">
|
|
<link href="admin.css" rel="stylesheet" type="text/css">
|
|
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.0.0/css/all.css">
|
|
</head>
|
|
<body class="admin">
|
|
<aside class="responsive-width-100 responsive-hidden">
|
|
<h1>$site_name</h1>
|
|
$admin_links
|
|
<div class="footer">
|
|
</div>
|
|
</aside>
|
|
<main class="responsive-width-100">
|
|
<header>
|
|
<a class="responsive-toggle" href="#">
|
|
<i class="fas fa-bars"></i>
|
|
</a>
|
|
<div class="space-between"></div>
|
|
<div class="dropdown right">
|
|
<i class="fas fa-user-circle"></i>
|
|
<div class="list">
|
|
<a href="index.php?page=account&id={$_SESSION['account_id']}">Edit Profile</a>
|
|
<a href="index.php?page=logout">Logout</a>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
EOT;
|
|
}
|
|
// Template admin footer
|
|
function template_admin_footer($js_script = '') {
|
|
$js_script = $js_script ? '<script>' . $js_script . '</script>' : '';
|
|
// DO NOT INDENT THE BELOW CODE
|
|
echo <<<EOT
|
|
</main>
|
|
<script src="admin.js"></script>
|
|
{$js_script}
|
|
</body>
|
|
</html>
|
|
EOT;
|
|
}
|
|
// Determine URL function
|
|
function url($url) {
|
|
if (rewrite_url) {
|
|
$url = preg_replace('/\&(.*?)\=/', '/', str_replace(['index.php?page=', 'index.php'], '', $url));
|
|
}
|
|
return base_url . $url;
|
|
}
|
|
// Routeing function
|
|
function routes($urls) {
|
|
foreach ($urls as $url => $file_path) {
|
|
$url = '/' . ltrim($url, '/');
|
|
$prefix = dirname($_SERVER['PHP_SELF']);
|
|
$uri = $_SERVER['REQUEST_URI'];
|
|
if (substr($uri, 0, strlen($prefix)) == $prefix) {
|
|
$uri = substr($uri, strlen($prefix));
|
|
}
|
|
$uri = '/' . ltrim($uri, '/');
|
|
$path = explode('/', parse_url($uri)['path']);
|
|
$routes = explode('/', $url);
|
|
$values = [];
|
|
foreach ($path as $pk => $pv) {
|
|
if (isset($routes[$pk]) && preg_match('/{(.*?)}/', $routes[$pk])) {
|
|
$var = str_replace(['{','}'], '', $routes[$pk]);
|
|
$routes[$pk] = preg_replace('/{(.*?)}/', $pv, $routes[$pk]);
|
|
$values[$var] = $pv;
|
|
}
|
|
}
|
|
if ($routes === $path && rewrite_url) {
|
|
foreach ($values as $k => $v) {
|
|
$_GET[$k] = $v;
|
|
}
|
|
return file_exists($file_path) ? $file_path : 'home.php';
|
|
}
|
|
}
|
|
if (rewrite_url) {
|
|
header('Location: ' . url('index.php'));
|
|
exit;
|
|
}
|
|
return null;
|
|
}
|
|
// Format bytes to human-readable format
|
|
function format_bytes($bytes) {
|
|
$i = floor(log($bytes, 1024));
|
|
return round($bytes / pow(1024, $i), [0,0,2,2,3][$i]).['B','KB','MB','GB','TB'][$i];
|
|
}
|
|
|
|
|
|
function getAccessoiries($pdo, $categoryID){
|
|
|
|
include './custom/translations/translations_'.strtoupper(language_code).'.php';
|
|
|
|
$stmt = $pdo->prepare('SELECT p.*, (SELECT m.full_path FROM products_media pm JOIN media m ON m.id = pm.media_id WHERE pm.product_id = p.id ORDER BY pm.position ASC LIMIT 1) AS img FROM products p JOIN products_categories pc ON pc.category_id = :category_id AND pc.product_id = p.id JOIN categories c ON c.id = pc.category_id WHERE p.status = 1');
|
|
$stmt->bindValue(':category_id', $categoryID, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
|
|
$additional_products = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
echo '<div class="content-wrapper">
|
|
<div class="add_products">
|
|
<h2>'.$h2_cart_suggestions.'</h2>
|
|
';
|
|
|
|
foreach ($additional_products as $additional_product){
|
|
if (!empty($additional_product['img']) && file_exists($additional_product['img'])){
|
|
|
|
$url_contents = 'index.php?page=product&id=';
|
|
$url_contents .= $additional_product['url_slug'] ? $additional_product['url_slug'] : $additional_product['id'];
|
|
$additional_product_url = url($url_contents);
|
|
echo'
|
|
<div class="add_product">
|
|
<a href="'.$additional_product_url.'" id="'.$additional_product['id'].'A" class="product">
|
|
<img src="'.base_url.$additional_product['img'].'" id="'.$additional_product['id'].'" width="15%" height="" alt="'.$additional_product['name'].'">
|
|
</a>
|
|
<form id="product-form" action="" method="post">
|
|
<input type="hidden" name="add_product_id" value="'.$additional_product['id'].'">
|
|
<input type="hidden" name="add_product_price" value="'.$additional_product['price'].'">
|
|
<input type="hidden" name="add_product_weight" value="'.$additional_product['weight'].'">
|
|
<input type="submit" name="accessoiries" value="+">
|
|
</form>
|
|
<a href="'.$additional_product_url.'" id="'.$additional_product['id'].'A" class="product">
|
|
<span class="add_name">'.$additional_product['name'].'</span>
|
|
<span class="add_price"> '.currency_code.'.'.number_format($additional_product['price'],2).'
|
|
';
|
|
if ($additional_product['rrp'] > 0){
|
|
echo '
|
|
<span class="add_rrp">'.currency_code.''.number_format($additional_product['rrp'],2).'</span>
|
|
';
|
|
}
|
|
echo'
|
|
</a>
|
|
</div>
|
|
';
|
|
}
|
|
}
|
|
echo '</div></div>';
|
|
}
|
|
|
|
function getSamples($pdo, $categoryID){
|
|
|
|
include './custom/translations/translations_'.strtoupper(language_code).'.php';
|
|
|
|
$stmt = $pdo->prepare('SELECT p.*, (SELECT m.full_path FROM products_media pm JOIN media m ON m.id = pm.media_id WHERE pm.product_id = p.id ORDER BY pm.position ASC LIMIT 1) AS img FROM products p JOIN products_categories pc ON pc.category_id = :category_id AND pc.product_id = p.id JOIN categories c ON c.id = pc.category_id WHERE p.status = 1');
|
|
$stmt->bindValue(':category_id', $categoryID, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
|
|
$additional_products = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
echo '<div class="content-wrapper">
|
|
<h2 style="font-weight:normal;">'.$h2_cart_samples.'</h2>
|
|
<div class="add_sample_button"><button id="slideLeft" class="scrollButton" type="button"><</button></div>
|
|
<div id="add_samples_container" class="add_samples">
|
|
|
|
';
|
|
|
|
foreach ($additional_products as $additional_product){
|
|
if (!empty($additional_product['img']) && file_exists($additional_product['img'])){
|
|
|
|
//Pricing override for samples
|
|
if (sample_pricing_override){
|
|
$additional_product['price'] = sample_pricing_override_price; // Price override for free sample! Remove for standard price
|
|
}
|
|
|
|
$url_contents = 'index.php?page=product&id=';
|
|
$url_contents .= $additional_product['url_slug'] ? $additional_product['url_slug'] : $additional_product['id'];
|
|
$additional_product_url = url($url_contents);
|
|
echo'
|
|
<div class="add_sample">
|
|
<img src="'.base_url.$additional_product['img'].'" id="'.$additional_product['id'].'" width="50" height="50" alt="'.$additional_product['name'].'">
|
|
<form id="product-form" action="" method="post">
|
|
<input type="hidden" name="add_product_id" value="'.$additional_product['id'].'">
|
|
<input type="hidden" name="add_product_price" value="'.$additional_product['price'].'">
|
|
<input type="hidden" name="add_product_weight" value="'.$additional_product['weight'].'">
|
|
<input type="submit" name="samples" value="+">
|
|
</form>
|
|
<a href="'.$additional_product_url.'" id="'.$additional_product['id'].'A" class="product">
|
|
<span class="add_name">'.$additional_product['name'].'</span>';
|
|
if ($additional_product['price'] > 0){
|
|
echo '
|
|
<span class="add_price"> '.currency_code.'.'.number_format($additional_product['price'],2).'
|
|
';
|
|
}
|
|
if ($additional_product['rrp'] > 0){
|
|
echo '
|
|
<span class="add_rrp">'.currency_code.''.number_format($additional_product['rrp'],2).'</span>
|
|
';
|
|
}
|
|
echo'
|
|
</a>
|
|
</div>
|
|
';
|
|
}
|
|
}
|
|
echo '
|
|
|
|
</div>
|
|
<div class="add_sample_button"><button id="slideRight" class="scrollButton" type="button">></button></div>
|
|
</div>';
|
|
|
|
}
|
|
|
|
function createGiftCart($pdo, $orderID){
|
|
|
|
$giftcard_ID = giftcard_id;
|
|
|
|
//Check if Giftcard is ordered
|
|
$stmt = $pdo->prepare('SELECT t.payer_email as email, ti.id as id, ti.txn_id as txn, ti.item_price as item_price, ti.item_quantity as item_quantity FROM transactions t INNER JOIN transactions_items ti ON t.txn_id = ti.txn_id INNER JOIN products_categories p ON ti.item_id = p.product_id WHERE p.category_id = ? AND ti.txn_id = ?');
|
|
$stmt->execute([$giftcard_ID,$orderID]);
|
|
$giftcards = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if ($giftcards) {
|
|
foreach ($giftcards as $giftcard) {
|
|
|
|
//For each quantity
|
|
$x = 0;
|
|
|
|
while ($x < $giftcard['item_quantity']){
|
|
|
|
//Generate discount code = TXN/ID/X
|
|
$discount_code = $giftcard['txn'].'#'.$giftcard['id'].'#'.$x;
|
|
$value = $giftcard['item_price'];
|
|
|
|
// Get the current date
|
|
$start_date = date("Y-m-d H:i:s");
|
|
$end_date = date("Y-m-d H:i:s", strtotime("+5 years"));;
|
|
|
|
//Check if Giftcard already exists
|
|
$stmt = $pdo->prepare('SELECT * from discounts WHERE discount_code = ?');
|
|
$stmt->execute([$discount_code]);
|
|
$discount_exist = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if (empty($discount_exist) || $discount_exist == '') {
|
|
//Insert Giftcard
|
|
//SQL Insert
|
|
$stmt = $pdo->prepare('INSERT INTO discounts (discount_code,discount_type,discount_value,start_date,end_date) VALUES (?,?,?,?,?)');
|
|
$stmt->execute([$discount_code, 'Fixed', $value, $start_date, $end_date]);
|
|
}
|
|
$x++;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
function useGiftCart($pdo, $giftcard){
|
|
|
|
$discount_code = $giftcard;
|
|
|
|
// Get the current date
|
|
$end_date = date("Y-m-d H:i:s");
|
|
|
|
//Check if Giftcard already exists
|
|
$stmt = $pdo->prepare('SELECT * from discounts WHERE discount_code = ?');
|
|
$stmt->execute([$discount_code]);
|
|
$discount_exist = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
//Dump parameters
|
|
//$stmt->debugDumpParams();
|
|
|
|
if (!empty($discount_exist) || $discount_exist != '') {
|
|
//Update Giftcard end data
|
|
$stmt = $pdo->prepare('UPDATE discounts SET end_date = ? WHERE discount_code = ?');
|
|
$stmt->execute([$end_date,$discount_code]);
|
|
}
|
|
}
|
|
|
|
function removeGiftCart($pdo, $orderID){
|
|
|
|
$discount_code = $orderID.'#%#%';
|
|
|
|
//Check if Giftcard already exists
|
|
$stmt = $pdo->prepare('SELECT * from discounts WHERE discount_code like ?');
|
|
$stmt->execute([$discount_code]);
|
|
$discount_exist = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if (!empty($discount_exist) || $discount_exist != '') {
|
|
//Remove all Giftcards related to order
|
|
$stmt = $pdo->prepare('DELETE FROM discounts WHERE discount_code like ?');
|
|
$stmt->execute([$discount_code]);
|
|
|
|
}
|
|
}
|
|
|
|
function generateInvoice($pdo, $orderID){
|
|
|
|
// Retrieve order items
|
|
$stmt = $pdo->prepare('SELECT ti.*, p.productcode, p.name FROM transactions t JOIN transactions_items ti ON ti.txn_id = t.txn_id LEFT JOIN products p ON p.id = ti.item_id WHERE t.txn_id = ?');
|
|
$stmt->execute([ $orderID ]);
|
|
$order_items = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Retrieve order details
|
|
$stmt = $pdo->prepare('SELECT a.email, a.id AS a_id, a.first_name AS a_first_name, a.last_name AS a_last_name, a.address_street AS a_address_street, a.address_city AS a_address_city, a.address_state AS a_address_state, a.address_zip AS a_address_zip, a.address_country AS a_address_country, t.* FROM transactions t LEFT JOIN transactions_items ti ON ti.txn_id = t.txn_id LEFT JOIN accounts a ON a.id = t.account_id WHERE t.txn_id = ?');
|
|
$stmt->execute([ $orderID]);
|
|
$order = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
// Get tax
|
|
$stmt = $pdo->prepare('SELECT * FROM taxes WHERE country = ?');
|
|
$stmt->execute([$order['a_address_country']]);
|
|
$tax = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
$tax_rate = $tax ? $tax['rate'] : 0.00;
|
|
//$stmt->debugDumpParams();
|
|
//Variables
|
|
$customer_email = htmlspecialchars($order['payer_email'] ?? '', ENT_QUOTES);
|
|
$address_name = htmlspecialchars($order['first_name'] ?? '', ENT_QUOTES).' '.htmlspecialchars($order['last_name'] ?? '', ENT_QUOTES);
|
|
$address_street = htmlspecialchars($order['address_street'] ?? '', ENT_QUOTES);
|
|
$address_city = htmlspecialchars($order['address_city'] ?? '', ENT_QUOTES);
|
|
$address_state = htmlspecialchars($order['address_state'] ?? '', ENT_QUOTES);
|
|
$address_zip = htmlspecialchars($order['address_zip'] ?? '', ENT_QUOTES);
|
|
$address_country = htmlspecialchars($order['address_country'] ?? '', ENT_QUOTES);
|
|
|
|
$order_id = $order['id'];
|
|
$products = $order_items;
|
|
$shippingtotal = $order['shipping_amount'];
|
|
$total = $order['payment_amount'];
|
|
$taxtotal = $order['tax_amount'];
|
|
$order_created = $order['created'];
|
|
|
|
//Generate invoice
|
|
ob_start();
|
|
include dirname(__FILE__).'/custom/order-invoice-template.php';
|
|
$order_invoice_template = ob_get_clean();
|
|
|
|
return array($order_invoice_template,$customer_email,$order_id);
|
|
}
|
|
|
|
function freeShipment($price, $type){
|
|
|
|
include './custom/translations/translations_'.strtoupper(language_code).'.php';
|
|
|
|
//Free delivery indicator
|
|
$delivery_status = ($price >= free_shipment_price) ? $free_delivery : $non_free_delivery.currency_code.free_shipment_price.',-';
|
|
$style = ($delivery_status == $free_delivery) ? 'style="color:green;font-weight: bold;"' : 'style="color:gray;font-weight: lighter;"';
|
|
|
|
echo '
|
|
<'.$type.' class="delivery">
|
|
<p '.$style.'> '.$delivery_status.'</p>
|
|
</'.$type.'>';
|
|
}
|
|
|
|
function consent()
|
|
{
|
|
include './custom/translations/translations_'.strtoupper(language_code).'.php';
|
|
|
|
$age_consent = '
|
|
<div id="simple-cookie-consent">
|
|
<div class="cookie-consent-container">
|
|
<div class="cookie-consent-notice">
|
|
<h4>'.$age_consent_h4.'</h4>
|
|
<hr>
|
|
<p>'.$age_consent_text.'</p>
|
|
</div>
|
|
<div class="cookie-consent-selection">
|
|
<form action="'.htmlspecialchars($_SERVER["PHP_SELF"]).'" method="POST">
|
|
<input type="submit" name="age_consent_allow" value="'.$age_consent_btn_allow.'" class="cookie-consent-allow">
|
|
<input type="submit" name="age_consent_deny" value="'.$age_consent_btn_deny.'" class="cookie-consent-deny">
|
|
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
';
|
|
|
|
return $age_consent;
|
|
}
|
|
|
|
function banner()
|
|
{
|
|
include './custom/translations/translations_'.strtoupper(language_code).'.php';
|
|
|
|
$banner = '
|
|
<div id="banner">
|
|
<div class="banner_container" style="background-image:url('.banner_background.');background-position: center center;">
|
|
<div class="banner_notice">
|
|
<h4>'.banner_wow.'</h4>
|
|
<hr>
|
|
<p>'.banner_text.'</p>
|
|
</div>
|
|
<div class="banner_selection">
|
|
<form action="'.htmlspecialchars($_SERVER["PHP_SELF"]).'" method="POST">
|
|
<input type="submit" name="banner_move" value="'.banner_btn_1.'" class="banner_allow">
|
|
<input type="submit" name="banner_stay" value="'.banner_btn_2.'" class="banner_deny">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
';
|
|
|
|
return $banner;
|
|
}
|
|
|
|
function maintenanceMode()
|
|
{
|
|
include './custom/translations/translations_'.strtoupper(language_code).'.php';
|
|
|
|
$maintenanceMode = '
|
|
<div id="simple-cookie-consent">
|
|
<div class="cookie-consent-container">
|
|
<div class="cookie-consent-notice">
|
|
<h4>'.$maintenanceMode_h4.'</h4>
|
|
<hr>
|
|
<p>'.$maintenanceMode_text.'</p>
|
|
</div>
|
|
<div class="cookie-consent-selection">
|
|
<form action="'.htmlspecialchars($_SERVER["PHP_SELF"]).'" method="POST">
|
|
<input type="submit" name="maintenanceMode" value="'.$maintenanceMode_btn.'" class="cookie-consent-allow">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
';
|
|
|
|
return $maintenanceMode;
|
|
}
|
|
//++++++++++++++++++++++++++++++++++++++++
|
|
//HomePage Products
|
|
//++++++++++++++++++++++++++++++++++++++++
|
|
function getPictureID($pdo,$id,$config){
|
|
$stmt = $pdo->prepare('SELECT * FROM products_media where product_id = :product_id ORDER BY position ASC');
|
|
$stmt->bindValue(':product_id', $id, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$product_media = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
//Search for option_id
|
|
$option_profile = json_decode($config,true) ?? '';
|
|
if (!empty($option_profile) && $option_profile !=''){
|
|
foreach ($option_profile as $option){
|
|
if ($option['IMG_large_id'] == $product_media[0]['media_id']){
|
|
return $option['option_id'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//++++++++++++++++++++++++++++++++++++++++
|
|
//HomePage Products
|
|
//++++++++++++++++++++++++++++++++++++++++
|
|
function highlightedProducts($pdo,$categoryID,$range){
|
|
|
|
include './custom/translations/translations_'.strtoupper(language_code).'.php';
|
|
|
|
$stmt = $pdo->prepare('SELECT p.*, (SELECT m.full_path FROM products_media pm JOIN media m ON m.id = pm.media_id WHERE pm.product_id = p.id ORDER BY pm.position ASC LIMIT 1) AS img FROM products p JOIN products_categories pc ON pc.category_id = :category_id AND pc.product_id = p.id JOIN categories c ON c.id = pc.category_id WHERE p.status = 1');
|
|
$stmt->bindValue(':category_id', $categoryID, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$view = '
|
|
<h2>'.$range.'<span class="limited">Limited edition</span></h2>
|
|
<div class="products">';
|
|
foreach($products as $product){
|
|
|
|
$view .= '
|
|
<div class="product">';
|
|
if (empty($product['product_config'])){
|
|
$view .= '<a href="'.url('index.php?page=product&id=' . ($product['url_slug'] ? ($product['url_slug'] ) : $product['id'])).'" id="'.$product['id'].'A" class="product">';
|
|
}
|
|
else{//ADD related optionID when configuration is found
|
|
$option_id = getPictureID($pdo,$product['id'],$product['product_config']);
|
|
|
|
$view .= '<a href="'.url('index.php?page=product&id=' . ($product['url_slug'] ? ($product['url_slug'].'/'.$option_id ) : $product['id'])).'" id="'.$product['id'].'A" class="product">';
|
|
}
|
|
|
|
if (!empty($product['img']) && file_exists($product['img'])){
|
|
if (empty($product['product_config'])){
|
|
$view .= '
|
|
<img src="'.$product['img'].'" width="" height="250" alt="'.$product['name'].'">';
|
|
$view .= '
|
|
</a>
|
|
<!-- Show small image below main image in case of not configured -->
|
|
<div class="" style="display:flex;justify-content: center">
|
|
<div>
|
|
<img class="img_config" src="'.base_url.$product['img'].'"/>
|
|
</div>
|
|
</div>';
|
|
} else {
|
|
|
|
$view .= '<img src="'.base_url.$product['img'].'" id="'.$product['id'].'" width="" height="250" alt="'.$product['name'].'">
|
|
</a>';
|
|
if (show_options_carrousel){
|
|
$view .= '<div class="" style="display:flex;justify-content: center">';
|
|
$option_profile = json_decode($product['product_config']);
|
|
|
|
foreach ($option_profile as $option){
|
|
//get all media
|
|
$stmt = $pdo->query('SELECT id, full_path FROM media');
|
|
$stmt->execute();
|
|
$media = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
foreach ($media as $media_item){
|
|
if ($media_item['id'] == $option->IMG_small_id){
|
|
$IMG_small_id = $media_item['full_path'];
|
|
}
|
|
if ($media_item['id'] == $option->IMG_large_id){
|
|
$IMG_large_id = $media_item['full_path'];
|
|
}
|
|
}
|
|
$option_id = ($option->option_id != '') ? $option->option_id : '';
|
|
|
|
$view .= '
|
|
<div>
|
|
<img class="img_config" src="'.url($IMG_small_id).'" id="'.$option->IMG_small_id.'" onclick="update(\''.$product['id'].'\',\''.url($IMG_large_id).'\',\''.url('index.php?page=product&id=' . ($product['url_slug'] ? $product['url_slug'].'/'.$option_id : $product['id'].'/'.$option_id )).'\')" />
|
|
</div>
|
|
|
|
';
|
|
|
|
}
|
|
$view .= '</div>';
|
|
}
|
|
}
|
|
|
|
}
|
|
//Stock status
|
|
$stock_status = ($product['quantity'] != 0) ? $product_on_stock : $out_of_stock;
|
|
$style = ($stock_status == $product_on_stock) ? 'style="background-color: green;"' : 'style="background-color:gray;font-weight: lighter;"';
|
|
$view .=' <span class="stock">
|
|
<p '.$style.'> '.$stock_status.' </p>
|
|
</span>';
|
|
|
|
|
|
//Remove first characters from Productname
|
|
if (product_truncate_text != ''){
|
|
$productname = str_replace(product_truncate_text,'',$product['name']);
|
|
$productname = (product_truncate !=0)? substr($productname,product_truncate):$productname;
|
|
} else {
|
|
$productname = $product['name'];
|
|
}
|
|
|
|
//ADD related optionID when configuration is found
|
|
if (empty($product['product_config'])){
|
|
$option_id = '';
|
|
}else {
|
|
$option_id = '/'.getPictureID($pdo,$product['id'],$product['product_config']);
|
|
}
|
|
$view .= '
|
|
<a href="'.url('index.php?page=product&id=' . ($product['url_slug'] ? $product['url_slug'].$option_id : $product['id'])).'" id="'.$product['id'].'B" class="product">
|
|
<span class="productname">'.$productname.'</span>
|
|
<span class="productprice">'.currency_code.number_format($product['price'],2);
|
|
if ($product['rrp'] > 0) {
|
|
$view .= '<span class="productrrp">'.currency_code.number_format($product['rrp'],2).'</span>';
|
|
}
|
|
$view .= '
|
|
</span>
|
|
</a>
|
|
</div>';
|
|
}
|
|
|
|
$view .= '</div>';
|
|
return $view;
|
|
}
|
|
|
|
//---------------------------
|
|
//debuglog
|
|
//---------------------------
|
|
|
|
function debuglog($error){
|
|
$test = $error.PHP_EOL;
|
|
$filelocation = './log/log_'.date('m').'.txt';
|
|
error_log($test, 3, $filelocation);
|
|
}
|
|
?>
|