From 5dd2973a26718506d9faf94a14ad9bb79ddde77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CVeLiTi=E2=80=9D?= <“info@veliti.nl”> Date: Sun, 23 Feb 2025 15:25:46 +0100 Subject: [PATCH] CMXX - Myaccount --- admin/dashboard.php | 129 ---------------------- admin/emailtemplates.php | 8 +- admin/index.php | 12 +- admin/language.php | 134 +++++++++++++---------- admin/settings.php | 111 +++++++++++++++++++ custom/email/email_template_register.php | 102 +++++++++++++++++ custom/email/email_template_reset.php | 99 +++++++++++++++++ custom/settings/config.php | 6 +- functions.php | 1 - home.php | 2 +- myaccount.php | 57 +++++----- products.php | 2 +- 12 files changed, 440 insertions(+), 223 deletions(-) delete mode 100644 admin/dashboard.php create mode 100644 admin/settings.php create mode 100644 custom/email/email_template_register.php create mode 100644 custom/email/email_template_reset.php diff --git a/admin/dashboard.php b/admin/dashboard.php deleted file mode 100644 index 1c0dfd9..0000000 --- a/admin/dashboard.php +++ /dev/null @@ -1,129 +0,0 @@ -prepare('SELECT t.*, COUNT(ti.id) AS total_products FROM transactions t JOIN transactions_items ti ON ti.txn_id = t.txn_id WHERE cast(t.created as DATE) = cast(now() as DATE) GROUP BY t.id, t.txn_id, t.payment_amount, t.payment_status, t.created, t.payer_email, t.first_name, t.last_name, t.address_street, t.address_city, t.address_state, t.address_zip, t.address_country, t.account_id, t.payment_method, t.discount_code, t.shipping_method, t.shipping_amount ORDER BY t.created DESC'); -$stmt->execute(); -$orders = $stmt->fetchAll(PDO::FETCH_ASSOC); -// Get the orders statistics -$stmt = $pdo->prepare('SELECT SUM(payment_amount) AS earnings FROM transactions WHERE payment_status = "Completed" AND cast(created as DATE) = cast(now() as DATE)'); -$stmt->execute(); -$order_stats = $stmt->fetch(PDO::FETCH_ASSOC); -// Get the total number of accounts -$stmt = $pdo->prepare('SELECT COUNT(*) AS total FROM accounts'); -$stmt->execute(); -$accounts = $stmt->fetch(PDO::FETCH_ASSOC); -// Get the total number of products -$stmt = $pdo->prepare('SELECT COUNT(*) AS total FROM products'); -$stmt->execute(); -$products = $stmt->fetch(PDO::FETCH_ASSOC); -?> - - -
-
- -
-

Dashboard

-

View statistics, today's transactions, and more.

-
-
-
- -
-
-
-

New Orders

-

-
- - -
- -
-
-

New Sales

-

-
- - -
- -
-
-

Total Accounts

-

-
- - -
- -
-
-

Total Products

-

-
- - -
-
- -
-
- -
-

Today's Transactions

-

List of transactions for today.

-
-
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#CustomerEmailProductsTotalMethodStatusDateActions
There are no recent orders
View Edit
-
-
- - \ No newline at end of file diff --git a/admin/emailtemplates.php b/admin/emailtemplates.php index e5f9a97..5153f43 100644 --- a/admin/emailtemplates.php +++ b/admin/emailtemplates.php @@ -3,15 +3,15 @@ defined('admin') or exit; // Capture post data if (isset($_POST['emailtemplate'], $_POST['emailtemplate2'])) { // Save templates - file_put_contents(dirname(__FILE__,-1).'/custom/mail/order-details-template.php', $_POST['emailtemplate']); - file_put_contents(dirname(__FILE__,-1).'/custom/mail/order-notification-template.php', $_POST['emailtemplate2']); + file_put_contents('../custom/email/order-details-template.php', $_POST['emailtemplate']); + file_put_contents('../custom/email/order-notification-template.php', $_POST['emailtemplate2']); header('Location: index.php?page=emailtemplates&success_msg=1'); exit; } // Read the order details template PHP file -$contents = file_get_contents(dirname(__FILE__,-1).'/custom/mail/order-details-template.php'); +$contents = file_get_contents('../custom/email/order-details-template.php'); // Read the order notification template PHP file -$contents2 = file_get_contents(dirname(__FILE__,-1).'/custom/mail/order-notification-template.php'); +$contents2 = file_get_contents('../custom/email/order-notification-template.php'); // Handle success messages if (isset($_GET['success_msg'])) { if ($_GET['success_msg'] == 1) { diff --git a/admin/index.php b/admin/index.php index fd9664d..e0eff21 100644 --- a/admin/index.php +++ b/admin/index.php @@ -15,6 +15,16 @@ include '../custom/settings/config.php'; include '../functions.php'; // Connect to MySQL database $pdo = pdo_connect_mysql(); + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++ +//LOGIN TO API +//+++++++++++++++++++++++++++++++++++++++++++++++++++++ +$data = json_encode(array("clientID" => clientID, "clientsecret" => clientsecret), JSON_UNESCAPED_UNICODE); +$responses = ioAPIv2('/v2/authorization', $data,''); +//Decode Payload +if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = '400';} +$clientsecret = $responses['token']; + // If the user is not logged-in redirect them to the login page if (!isset($_SESSION['account_loggedin'])) { header('Location: ' . url('../index.php?page=myaccount')); @@ -29,7 +39,7 @@ if (!$account || $account['role'] != 'Admin') { exit; } // Page is set to home (home.php) by default, so when the visitor visits that will be the page they see. -$page = isset($_GET['page']) && file_exists($_GET['page'] . '.php') ? $_GET['page'] : 'dashboard'; +$page = isset($_GET['page']) && file_exists($_GET['page'] . '.php') ? $_GET['page'] : 'settings'; if (isset($_GET['page']) && $_GET['page'] == 'logout') { session_destroy(); header('Location: ' . url('../index.php')); diff --git a/admin/language.php b/admin/language.php index 420587e..13e0140 100644 --- a/admin/language.php +++ b/admin/language.php @@ -1,66 +1,90 @@ +//------------------------------------------ +// Languages supported +//------------------------------------------ +$supportedLanguages = ['US', 'NL', 'DE', 'ES','FR', 'IT']; +if(isset($_POST['generatefile'])){ - + $language_key = (isset($_POST['language'])) ? $_POST['language'] : ''; -
- -
-

Translations

- -
- - -
- -

- -
- -
- US - NL -
-
-
+ function generateFile($language_key,$token){ + //GET TRANSLATION RECORDS + $api_url = '/v2/translations/generatefile='.$language_key; + $responses = ioAPIv2($api_url,'',$token); + + if (!empty($responses)){ + //define translation variable + $translation = ' - - -
-
- - -
+ //decode the API response + $responses = json_decode($responses,true); + + //loop through translation records and create variables + foreach ($responses as $response){ + $text = str_replace( + ['\\', "'", "\r", "\n", "\0", "\t"], + ['\\\\', "\\'", '\\r', '\\n', '\\0', '\\t'], + $response['translation'] + ); + + //create variable_name = translation per item + $translation .= '$'.$response['variable'].' = \''.$text.'\';'.PHP_EOL; + } + //ADD closure tag for PHP + $translation .= '?>'; + //Target dir + $target_dir = '../custom/translations/'; + //Filename + $input_file = $target_dir.'translations_'.strtoupper($language_key).'.php'; + //store translation to the file + file_put_contents($input_file, $translation); + } + } + + if ($language_key != ''){ + generateFile($language_key,$clientsecret); + } else { + + foreach ($supportedLanguages as $language){ + generateFile($language,$clientsecret); + } + } + +} + + +template_admin_header('Language', 'language'); + +$view .=' + +
+

Maintenance

+
'; + +$view .= ' + '; + +$view .= '
+
+ + +
+
'; - - +$view .= ''; - \ No newline at end of file +//Output +echo $view; + +template_admin_footer(); \ No newline at end of file diff --git a/admin/settings.php b/admin/settings.php new file mode 100644 index 0000000..47ad9db --- /dev/null +++ b/admin/settings.php @@ -0,0 +1,111 @@ +' . format_key($key) . ''; + if ($type == 'checkbox') { + $html .= ''; + } + $html .= ''; + return $html; +} +// Format tabs +function format_tabs($contents) { + $rows = explode("\n", $contents); + echo '
'; + echo 'General'; + for ($i = 0; $i < count($rows); $i++) { + preg_match('/\/\*(.*?)\*\//', $rows[$i], $match); + if ($match) { + echo '' . $match[1] . ''; + } + } + echo '
'; +} +// Format form +function format_form($contents) { + $rows = explode("\n", $contents); + echo '
'; + for ($i = 0; $i < count($rows); $i++) { + preg_match('/\/\*(.*?)\*\//', $rows[$i], $match); + if ($match) { + echo '
'; + } + preg_match('/define\(\'(.*?)\', ?(.*?)\)/', $rows[$i], $match); + if ($match) { + echo format_var_html($match[1], $match[2]); + } + } + echo '
'; +} +if (!empty($_POST)) { + // Update the configuration file with the new keys and values + foreach ($_POST as $k => $v) { + $v = in_array(strtolower($v), ['true', 'false']) ? strtolower($v) : '\'' . $v . '\''; + $contents = preg_replace('/define\(\'' . $k . '\'\, ?(.*?)\)/s', 'define(\'' . $k . '\',' . $v . ')', $contents); + } + file_put_contents('../custom/settings/config.php', $contents); + header('Location: index.php?page=settings&success_msg=1'); + exit; +} +// Handle success messages +if (isset($_GET['success_msg'])) { + if ($_GET['success_msg'] == 1) { + $success_msg = 'Settings updated successfully!'; + } +} +?> + + +
+ +
+

Settings

+ +
+ + +
+ +

+ +
+ + + +
+
+ +
+
+ +
+ + + + \ No newline at end of file diff --git a/custom/email/email_template_register.php b/custom/email/email_template_register.php new file mode 100644 index 0000000..dfb8ee1 --- /dev/null +++ b/custom/email/email_template_register.php @@ -0,0 +1,102 @@ + + + + + + ' . $subject . ' + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
+ CustomerPortal +
+ ' . $newuser_header . ', +
+
+ '.$newuser_text.' '.$newuser_credential_text_1.''.$post_content['username'].' +
+
+ '.$newuser_credential_text_2.' +
+ + + + + +
+ Reset Password +
+
+ ' . $newuser_closure . ' +
+
+ Kind regards, +
+
+ Service team +
+
+
+
+ + +'; \ No newline at end of file diff --git a/custom/email/email_template_reset.php b/custom/email/email_template_reset.php new file mode 100644 index 0000000..d727c07 --- /dev/null +++ b/custom/email/email_template_reset.php @@ -0,0 +1,99 @@ + + + + + + ' . $subject . ' + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
+ CustomerPortal +
+ ' . $changeuser_header . ', +
+
+ '.$changeuser_text.' +
+
+ '.$changeuser_credential_text_1 .' +
+ + + + + +
+ Reset Password +
+
+ ' . $changeuser_closure . ' +
+
+ Kind regards, +
+
+ Service team +
+
+
+
+ + +'; \ No newline at end of file diff --git a/custom/settings/config.php b/custom/settings/config.php index b71a4a8..cd8dcd6 100644 --- a/custom/settings/config.php +++ b/custom/settings/config.php @@ -64,6 +64,8 @@ define('default_product_sort','sort3'); define('invoice_bookkeeping',false); // Email of bookkeeping software define('email_bookkeeping',''); +// Rewrite URL? +define('rewrite_url',true); /* Images */ // Featured image URL @@ -131,8 +133,8 @@ define('mail_enabled',true); define('email','info@gewoonlekkerspaans.nl'); // Receive email notifications? define('email_notifications',false); -// Rewrite URL? -define('rewrite_url',true); +//EMAIL LOGO +define('emaillogo','custom/assets/MORVALFavicon.svg'); //Additional phpmailer-settings define('email_host_name','gewoonlekkerspaans.nl'); define('email_reply_to','info@gewoonlekkerspaans.nl'); diff --git a/functions.php b/functions.php index 1e64af5..30def2e 100644 --- a/functions.php +++ b/functions.php @@ -176,7 +176,6 @@ function template_admin_header($title, $selected = 'orders', $selected_child = ' $site_name = site_name; $icon_image = icon_image; $admin_links = ' - Dashboard Settings
Settings diff --git a/home.php b/home.php index ab02724..057bf90 100644 --- a/home.php +++ b/home.php @@ -29,7 +29,7 @@ $view = ' if(show_offer_home_page){ $view .='
-

'.show_offer_home_text.'

+

'.${show_offer_home_text} ?? show_offer_home_text .'

'; } $view .=' diff --git a/myaccount.php b/myaccount.php index 668a669..1336257 100644 --- a/myaccount.php +++ b/myaccount.php @@ -3,18 +3,22 @@ defined(security_key) or exit; // User clicked the "Login" button, proceed with the login process... check POST data and validate email if (isset($_POST['login'], $_POST['email'], $_POST['password']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { - // Check if the account exists - $stmt = $pdo->prepare('SELECT * FROM accounts WHERE email = ?'); - $stmt->execute([ $_POST['email'] ]); - $account = $stmt->fetch(PDO::FETCH_ASSOC); - // If account exists verify password - if ($account && password_verify($_POST['password'], $account['password'])) { + + //+++++++++++++++++++++++++++++++++++++++++++++++++++++ + // LOGIN CONSUMER + //+++++++++++++++++++++++++++++++++++++++++++++++++++++ + $payload = json_encode(array("login" => "consumer", "email" => $_POST['email'], "password" => $_POST['password']), JSON_UNESCAPED_UNICODE); + $account = ioAPIv2('/v2/identity/',$payload,$clientsecret); + $account= json_decode($account,true); + + if ($account && isset($account['accountID'])) { // User has logged in, create session data session_regenerate_id(); $_SESSION['account_loggedin'] = TRUE; - $_SESSION['account_id'] = $account['id']; - $_SESSION['account_role'] = $account['role']; + $_SESSION['account_id'] = $account['accountID']; + $_SESSION['account_role'] = $account['profile']; $products_in_cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : []; + if ($products_in_cart) { // user has products in cart, redirect them to the checkout page header('Location: ' . url('index.php?page=checkout')); @@ -32,9 +36,10 @@ $register_error = ''; // User clicked the "Register" button, proceed with the registration process... check POST data and validate email if (isset($_POST['register'], $_POST['email'], $_POST['password'], $_POST['cpassword']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { // Check if the account exists - $stmt = $pdo->prepare('SELECT * FROM accounts WHERE email = ?'); - $stmt->execute([ $_POST['email'] ]); - $account = $stmt->fetch(PDO::FETCH_ASSOC); + + $account = ioAPIv2('/v2/identity/email='.$_POST['email'],'',$clientsecret); + $account = json_decode($account,true); + if ($account) { // Account exists! $register_error = $error_myaccount_exists; @@ -46,25 +51,19 @@ if (isset($_POST['register'], $_POST['email'], $_POST['password'], $_POST['cpass $register_error = $error_account_password_rules; } else { // Account doesnt exist, create new account - $stmt = $pdo->prepare('INSERT INTO accounts (email, password, first_name, last_name, address_street, address_city, address_state, address_zip, address_country, address_phone) VALUES (?,?,"","","","","","","","")'); - // Hash the password - $password = password_hash($_POST['password'], PASSWORD_DEFAULT); - $stmt->execute([ $_POST['email'], $password ]); - $account_id = $pdo->lastInsertId(); - // Automatically login the user - session_regenerate_id(); - $_SESSION['account_loggedin'] = TRUE; - $_SESSION['account_id'] = $account_id; - $_SESSION['account_role'] = 'Member'; - $products_in_cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : []; - if ($products_in_cart) { - // User has products in cart, redirect them to the checkout page - header('Location: ' . url('index.php?page=checkout')); - } else { - // Redirect the user back to the same page, they can then see their order history - header('Location: ' . url('index.php?page=myaccount')); + $payload = json_encode(array("login" => "consumer", "email" => $_POST['email'], "password" => $_POST['password'], "language" => $_SESSION['country_code']), JSON_UNESCAPED_UNICODE); + $account = ioAPIv2('/v2/identity/',$payload,$clientsecret); + $account= json_decode($account,true); + + if ($account && isset($account['accountID'])) { + //SEND VERIFICATION EMAIL + ob_start(); + include dirname(__FILE__).'/custom/email/email_template_register.php'; + $register_mail= ob_get_clean(); + + send_mail_by_PHPMailer($_POST['email'], $subject, $register_mail,'', ''); + exit; } - exit; } } // Determine the current tab page diff --git a/products.php b/products.php index 4f24e3a..0a6a435 100644 --- a/products.php +++ b/products.php @@ -61,7 +61,7 @@ $view .='

'.$h1_content_top.'

if(show_offer_product_page){ $view .= '
-

'.show_offer_product_text.'

+

'.${show_offer_product_text} ?? show_offer_product_text.'

'; }