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'])) { // User has logged in, create session data session_regenerate_id(); $_SESSION['account_loggedin'] = TRUE; $_SESSION['account_id'] = $account['id']; $_SESSION['account_role'] = $account['role']; $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')); } exit; } else { $error = $error_myaccount; } } // Variable that will output registration errors $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); if ($account) { // Account exists! $register_error = $error_myaccount_exists; ; } else if ($_POST['cpassword'] != $_POST['password']) { $register_error = 'Passwords do not match!'; } else if (strlen($_POST['password']) > 20 || strlen($_POST['password']) < 5) { // Password must be between 5 and 20 characters long. $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')); } exit; } } // Determine the current tab page $tab = isset($_GET['tab']) ? $_GET['tab'] : 'orders'; // If user is logged in if (isset($_SESSION['account_loggedin'])) { // Select all the users transations, which will appear under "My Orders" $stmt = $pdo->prepare('SELECT * FROM transactions WHERE account_id = ? ORDER BY created DESC'); $stmt->execute([ $_SESSION['account_id'] ]); $transactions = $stmt->fetchAll(PDO::FETCH_ASSOC); // Select all the users transations, which will appear under "My Orders" $stmt = $pdo->prepare('SELECT p.name, p.id AS product_id, t.txn_id, t.payment_status, t.created AS transaction_date, ti.item_price AS price, ti.item_quantity AS quantity, ti.item_id, (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 transactions t JOIN transactions_items ti ON ti.txn_id = t.txn_id JOIN accounts a ON a.id = t.account_id JOIN products p ON p.id = ti.item_id WHERE t.account_id = ? ORDER BY t.created DESC'); $stmt->execute([ $_SESSION['account_id'] ]); $transactions_items = $stmt->fetchAll(PDO::FETCH_ASSOC); // Retrieve the digital downloads $transactions_ids = array_column($transactions_items, 'product_id'); if ($transactions_ids) { $stmt = $pdo->prepare('SELECT product_id, file_path, id FROM products_downloads WHERE product_id IN (' . trim(str_repeat('?,',count($transactions_ids)),',') . ') ORDER BY position ASC'); $stmt->execute($transactions_ids); $downloads = $stmt->fetchAll(PDO::FETCH_GROUP); } else { $downloads = []; } // Retrieve account details $stmt = $pdo->prepare('SELECT * FROM accounts WHERE id = ?'); $stmt->execute([ $_SESSION['account_id'] ]); $account = $stmt->fetch(PDO::FETCH_ASSOC); // Update settings if (isset($_POST['save_details'], $_POST['email'], $_POST['password'])) { // Assign and validate input data $first_name = isset($_POST['first_name']) ? $_POST['first_name'] : ''; $last_name = isset($_POST['last_name']) ? $_POST['last_name'] : ''; $address_street = isset($_POST['address_street']) ? $_POST['address_street'] : ''; $address_city = isset($_POST['address_city']) ? $_POST['address_city'] : ''; $address_state = isset($_POST['address_state']) ? $_POST['address_state'] : ''; $address_zip = isset($_POST['address_zip']) ? $_POST['address_zip'] : ''; $address_country = isset($_POST['address_country']) ? $_POST['address_country'] : ''; $address_phone = isset($_POST['address_phone']) ? $_POST['address_phone'] : ''; // Check if account exists with captured email $stmt = $pdo->prepare('SELECT * FROM accounts WHERE email = ?'); $stmt->execute([ $_POST['email'] ]); // Validation if ($_POST['email'] != $account['email'] && $stmt->fetch(PDO::FETCH_ASSOC)) { $error = 'Account already exists with that email!'; } else if ($_POST['password'] && (strlen($_POST['password']) > 20 || strlen($_POST['password']) < 5)) { $error = 'Password must be between 5 and 20 characters long!'; } else { // Update account details in database $password = $_POST['password'] ? password_hash($_POST['password'], PASSWORD_DEFAULT) : $account['password']; $stmt = $pdo->prepare('UPDATE accounts SET email = ?, password = ?, first_name = ?, last_name = ?, address_street = ?, address_city = ?, address_state = ?, address_zip = ?, address_country = ?, address_phone = ? WHERE id = ?'); $stmt->execute([ $_POST['email'], $password, $first_name, $last_name, $address_street, $address_city, $address_state, $address_zip, $address_country, $address_phone, $_SESSION['account_id'] ]); // Redirect to settings page header('Location: ' . url('index.php?page=myaccount&tab=settings')); exit; } } } ?> =template_header($myaccount_text)?>
=$error?>
=$register_error?>
=$myorders_message?>
|
|
=$transaction_item['quantity']?> x =$transaction_item['name']?> | =currency_code?>=number_format($transaction_item['price'] * $transaction_item['quantity'],2)?> |
=$mydownloads_message?>
| =$mydownloads_product?> | ||
|
|
=$item['name']?> | =basename($download['file_path'])?> |