WebOrbiton
v1.1.0.0

StocketBase

440 lines · 29.4 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. require_once __DIR__ . '/includes/config.php';
  6. require_once __DIR__ . '/includes/database.php';
  7. require_once __DIR__ . '/includes/user-auth.php';
  8. require_once __DIR__ . '/includes/csrf.php';
  9. require_once __DIR__ . '/includes/language.php';
  10. require_once __DIR__ . '/includes/site-front.php';
  11. require_once __DIR__ . '/includes/currency.php';
  12. require_once __DIR__ . '/includes/countries.php';
  13. require_once __DIR__ . '/includes/orders.php';
  14. require_once __DIR__ . '/includes/order-view.php';
  15. require_once __DIR__ . '/includes/digital-files.php';
  16. require_once __DIR__ . '/includes/licenses.php';
  17. ​
  18. UserAuth::boot();
  19. UserAuth::requireLogin();
  20. ​
  21. $reader = UserAuth::user();
  22. $settings = SiteFront::settings();
  23. $usersDb = Database::users();
  24. $tabs = [
  25. 'overview' => Language::get('account_tab_overview', 'Overview'),
  26. 'orders' => Language::get('account_tab_orders', 'Orders'),
  27. 'downloads' => Language::get('account_tab_downloads', 'Downloads'),
  28. 'licenses' => Language::get('account_tab_licenses', 'License keys'),
  29. 'addresses' => Language::get('account_tab_addresses', 'Addresses'),
  30. 'profile' => Language::get('account_tab_profile', 'Profile'),
  31. 'privacy' => Language::get('account_tab_privacy', 'Privacy'),
  32. ];
  33. $activeTab = (string) ($_GET['tab'] ?? 'overview');
  34. if (!isset($tabs[$activeTab])) {
  35. $activeTab = 'overview';
  36. }
  37. ​
  38. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  39. $postedTab = (string) ($_POST['tab'] ?? $activeTab);
  40. if (!Csrf::verify($_POST['csrf_token'] ?? null)) {
  41. $_SESSION['account_flash'] = ['error', Language::get('form_security_failed', 'Security check failed, please try again.')];
  42. header('Location: account.php?tab=' . urlencode(isset($tabs[$postedTab]) ? $postedTab : 'overview'));
  43. exit;
  44. }
  45. ​
  46. if (($_POST['action'] ?? '') === 'export_data') {
  47. $export = ['exported_at' => gmdate('c'), 'account' => array_diff_key($reader, array_flip(['password_hash']))];
  48. $queries = [
  49. 'addresses' => 'SELECT * FROM user_addresses WHERE user_account_id = :id',
  50. 'orders' => 'SELECT * FROM orders WHERE user_account_id = :id',
  51. 'subscriptions' => 'SELECT * FROM subscriptions WHERE user_account_id = :id',
  52. 'consents' => 'SELECT consent_type, is_granted, granted_at, revoked_at FROM user_consents WHERE user_account_id = :id',
  53. 'reviews' => 'SELECT product_id, rating, body, created_at FROM product_reviews WHERE user_account_id = :id',
  54. ];
  55. foreach ($queries as $key => $sql) {
  56. try {
  57. $statement = $usersDb->prepare($sql);
  58. $statement->execute(['id' => $reader['id']]);
  59. $export[$key] = $statement->fetchAll();
  60. } catch (PDOException $exception) {
  61. $export[$key] = [];
  62. }
  63. }
  64. foreach ($export['orders'] as $index => $exportedOrder) {
  65. unset($export['orders'][$index]['access_token']);
  66. $export['orders'][$index]['items'] = Orders::items((int) $exportedOrder['id']);
  67. }
  68. $export['license_keys'] = array_map(static fn(array $key): array => [
  69. 'product' => $key['product_title_snapshot'], 'key' => $key['license_key'], 'order' => $key['order_number'], 'assigned_at' => $key['assigned_at'],
  70. ], Licenses::forUser((int) $reader['id']));
  71. ​
  72. header('Content-Type: application/json; charset=utf-8');
  73. header('Content-Disposition: attachment; filename="my-data-' . date('Y-m-d') . '.json"');
  74. header('Cache-Control: no-store');
  75. echo json_encode($export, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  76. exit;
  77. }
  78. ​
  79. $result = require __DIR__ . '/dashboard-actions/save-account.php';
  80. if (is_array($result)) {
  81. [$flashType, $flashText, $flashTab] = $result;
  82. if ($flashType === 'deleted') {
  83. header('Location: index.php');
  84. exit;
  85. }
  86. $_SESSION['account_flash'] = [$flashType, $flashText];
  87. header('Location: account.php?tab=' . urlencode((string) $flashTab));
  88. exit;
  89. }
  90. header('Location: account.php?tab=' . urlencode($activeTab));
  91. exit;
  92. }
  93. ​
  94. $flash = null;
  95. if (isset($_SESSION['account_flash']) && is_array($_SESSION['account_flash'])) {
  96. $flash = $_SESSION['account_flash'];
  97. unset($_SESSION['account_flash']);
  98. }
  99. ​
  100. $ordersStatement = $usersDb->prepare("SELECT * FROM orders WHERE user_account_id = :id AND status <> 'failed' ORDER BY created_at DESC LIMIT 200");
  101. $ordersStatement->execute(['id' => $reader['id']]);
  102. $orders = $ordersStatement->fetchAll();
  103. ​
  104. $accountDownloads = [];
  105. $ownedProductIds = DigitalFiles::ownedProductIds((int) $reader['id']);
  106. if (!empty($ownedProductIds)) {
  107. $placeholders = implode(',', array_fill(0, count($ownedProductIds), '?'));
  108. $ownedProductsStatement = Database::site()->prepare("SELECT id, title, slug, cover_image_path FROM products WHERE id IN ({$placeholders})");
  109. $ownedProductsStatement->execute($ownedProductIds);
  110. $ownedProducts = [];
  111. foreach ($ownedProductsStatement->fetchAll() as $ownedProduct) {
  112. $ownedProducts[(int) $ownedProduct['id']] = $ownedProduct;
  113. }
  114. ​
  115. foreach ($ownedProductIds as $ownedProductId) {
  116. $ownedFiles = DigitalFiles::filesForProduct($ownedProductId);
  117. if (empty($ownedFiles)) {
  118. continue;
  119. }
  120. $ownedProduct = $ownedProducts[$ownedProductId] ?? null;
  121. $ownedTitle = (string) ($ownedProduct['title'] ?? ($ownedFiles[0]['product_title'] ?? ''));
  122. $accountDownloads[] = [
  123. 'title' => $ownedTitle !== '' ? $ownedTitle : $ownedFiles[0]['original_name'],
  124. 'cover' => $ownedProduct['cover_image_path'] ?? null,
  125. 'files' => $ownedFiles,
  126. ];
  127. }
  128. usort($accountDownloads, static fn(array $a, array $b): int => strcasecmp($a['title'], $b['title']));
  129. }
  130. ​
  131. $licenseKeys = Licenses::forUser((int) $reader['id']);
  132. ​
  133. $addressesStatement = $usersDb->prepare('SELECT * FROM user_addresses WHERE user_account_id = :id ORDER BY is_default_shipping DESC, id ASC');
  134. $addressesStatement->execute(['id' => $reader['id']]);
  135. $addresses = $addressesStatement->fetchAll();
  136. ​
  137. $subscriptionsStatement = $usersDb->prepare('SELECT * FROM subscriptions WHERE user_account_id = :id ORDER BY created_at DESC');
  138. $subscriptionsStatement->execute(['id' => $reader['id']]);
  139. $subscriptions = $subscriptionsStatement->fetchAll();
  140. ​
  141. $consentsStatement = $usersDb->prepare('SELECT consent_type, is_granted FROM user_consents WHERE user_account_id = :id ORDER BY id ASC');
  142. $consentsStatement->execute(['id' => $reader['id']]);
  143. $consents = [];
  144. foreach ($consentsStatement->fetchAll() as $row) {
  145. $consents[$row['consent_type']] = (bool) $row['is_granted'];
  146. }
  147. ​
  148. $viewOrder = null;
  149. $viewOrderId = (int) ($_GET['order'] ?? 0);
  150. if ($viewOrderId > 0) {
  151. foreach ($orders as $candidateOrder) {
  152. if ((int) $candidateOrder['id'] === $viewOrderId) {
  153. $viewOrder = Orders::ensureAccessToken($candidateOrder);
  154. $activeTab = 'orders';
  155. }
  156. }
  157. }
  158. ​
  159. $editAddress = null;
  160. $editAddressId = (int) ($_GET['edit'] ?? 0);
  161. foreach ($addresses as $address) {
  162. if ((int) $address['id'] === $editAddressId) {
  163. $editAddress = $address;
  164. }
  165. }
  166. ​
  167. $e = static fn($value): string => htmlspecialchars((string) $value, ENT_QUOTES);
  168. $pageTitle = Language::get('account_title', 'My account') . ' - ' . $settings['site_name'];
  169. $pageNoindex = true;
  170. ​
  171. require __DIR__ . '/includes/front-header.php';
  172. ​
  173. ?>
  174. <div class="account-page">
  175. <div class="account-head">
  176. <div>
  177. <h1 class="article-title"><?= $e(Language::get('account_title', 'My account')) ?></h1>
  178. <p class="account-hello"><?= $e(str_replace('{name}', (string) ($reader['display_name'] ?: $reader['email']), Language::get('account_hello', 'Hi, {name}'))) ?></p>
  179. </div>
  180. <a class="account-logout" href="user-login.php?logout=1"><?= $e(Language::get('nav_logout', 'Log out')) ?></a>
  181. </div>
  182. ​
  183. <nav class="account-tabs" aria-label="<?= $e(Language::get('account_title', 'My account')) ?>">
  184. <?php foreach ($tabs as $tabKey => $tabLabel): ?>
  185. <?php
  186. $tabCount = match ($tabKey) {
  187. 'orders' => count($orders),
  188. 'downloads' => count($accountDownloads),
  189. 'licenses' => count($licenseKeys),
  190. 'addresses' => count($addresses),
  191. default => null,
  192. };
  193. ?>
  194. <a href="account.php?tab=<?= $e($tabKey) ?>" class="<?= $activeTab === $tabKey ? 'active' : '' ?>" <?= $activeTab === $tabKey ? 'aria-current="page"' : '' ?>>
  195. <?= $e($tabLabel) ?><?php if ($tabCount): ?><span class="account-tab-count"><?= (int) $tabCount ?></span><?php endif; ?>
  196. </a>
  197. <?php endforeach; ?>
  198. </nav>
  199. ​
  200. <?php if ($flash !== null): ?>
  201. <div class="account-flash account-flash-<?= $e($flash[0]) ?>" role="status"><?= $e($flash[1]) ?></div>
  202. <?php endif; ?>
  203. ​
  204. <?php if (empty($reader['email_verified_at'])): ?>
  205. <div class="account-verify">
  206. <p><?= $e(str_replace('{email}', (string) $reader['email'], Language::get('account_verify_notice', 'Please confirm your email address ({email}). After that, orders you placed as a guest with this email will show up here.'))) ?></p>
  207. <form method="post">
  208. <?= Csrf::field() ?>
  209. <input type="hidden" name="action" value="resend_verification">
  210. <input type="hidden" name="tab" value="<?= $e($activeTab) ?>">
  211. <button type="submit" class="account-button-secondary"><?= $e(Language::get('account_verify_resend', 'Send the link again')) ?></button>
  212. </form>
  213. </div>
  214. <?php endif; ?>
  215. ​
  216. <?php if ($activeTab === 'overview'): ?>
  217. <div class="account-cards">
  218. <a class="account-card" href="account.php?tab=orders"><strong><?= count($orders) ?></strong><span><?= $e(Language::get('account_tab_orders', 'Orders')) ?></span></a>
  219. <a class="account-card" href="account.php?tab=downloads"><strong><?= count($accountDownloads) ?></strong><span><?= $e(Language::get('account_tab_downloads', 'Downloads')) ?></span></a>
  220. <a class="account-card" href="account.php?tab=licenses"><strong><?= count($licenseKeys) ?></strong><span><?= $e(Language::get('account_tab_licenses', 'License keys')) ?></span></a>
  221. <a class="account-card" href="account.php?tab=addresses"><strong><?= count($addresses) ?></strong><span><?= $e(Language::get('account_tab_addresses', 'Addresses')) ?></span></a>
  222. </div>
  223. ​
  224. <h2 class="account-section-title"><?= $e(Language::get('account_recent_orders', 'Recent orders')) ?></h2>
  225. <?php if (empty($orders)): ?>
  226. <p class="account-empty"><?= $e(Language::get('account_no_orders', 'You have not placed any orders yet.')) ?> <a href="index.php"><?= $e(Language::get('order_confirmation_continue_shopping', 'Continue shopping')) ?></a></p>
  227. <?php else: ?>
  228. <?php $recentOrders = array_slice($orders, 0, 3); ?>
  229. <?php require __DIR__ . '/includes/account-order-list.php'; ?>
  230. <?php endif; ?>
  231. ​
  232. <?php if (($settings['pricing_model'] ?? 'per_product') === 'subscription' || !empty($subscriptions)): ?>
  233. <h2 class="account-section-title"><?= $e(Language::get('account_subscriptions', 'Subscriptions')) ?></h2>
  234. <?php if (empty($subscriptions)): ?>
  235. <p class="account-empty"><?= $e(Language::get('account_no_subscriptions', 'No active subscriptions.')) ?></p>
  236. <?php else: ?>
  237. <ul class="account-subscriptions">
  238. <?php foreach ($subscriptions as $subscription): ?>
  239. <li>
  240. <span><?= $e(ucfirst((string) $subscription['provider'])) ?><?= !empty($subscription['plan_code']) ? ' · ' . $e($subscription['plan_code']) : '' ?></span>
  241. <span class="status-pill status-<?= $e($subscription['status']) ?>"><?= $e(Language::get('subscription_status_' . $subscription['status'], (string) $subscription['status'])) ?></span>
  242. <?php if (!empty($subscription['current_period_end'])): ?><small><?= $e(str_replace('{date}', OrderView::date((string) $subscription['current_period_end']), Language::get('account_subscription_until', 'until {date}'))) ?></small><?php endif; ?>
  243. </li>
  244. <?php endforeach; ?>
  245. </ul>
  246. <?php endif; ?>
  247. <?php endif; ?>
  248. <?php endif; ?>
  249. ​
  250. <?php if ($activeTab === 'orders'): ?>
  251. <?php if ($viewOrder !== null): ?>
  252. <p><a href="account.php?tab=orders">&larr; <?= $e(Language::get('account_back_to_orders', 'Back to order history')) ?></a></p>
  253. <?= OrderView::render($viewOrder, Orders::items((int) $viewOrder['id']), true) ?>
  254. <?= OrderView::copyScript() ?>
  255. <?php elseif (empty($orders)): ?>
  256. <p class="account-empty"><?= $e(Language::get('account_no_orders', 'You have not placed any orders yet.')) ?></p>
  257. <?php else: ?>
  258. <?php $recentOrders = $orders; ?>
  259. <?php require __DIR__ . '/includes/account-order-list.php'; ?>
  260. <?php endif; ?>
  261. <?php endif; ?>
  262. ​
  263. <?php if ($activeTab === 'downloads'): ?>
  264. <?php if (empty($accountDownloads)): ?>
  265. <p class="account-empty"><?= $e(Language::get('account_no_downloads', 'Files you buy will show up here.')) ?></p>
  266. <?php else: ?>
  267. <p class="account-hint"><?= $e(Language::get('order_downloads_unlimited', 'No limit while you are logged in.')) ?></p>
  268. <div class="account-downloads">
  269. <?php foreach ($accountDownloads as $accountDownload): ?>
  270. <div class="download-group">
  271. <h3><?= $e($accountDownload['title']) ?></h3>
  272. <ul class="download-list">
  273. <?php foreach ($accountDownload['files'] as $accountFile): ?>
  274. <li>
  275. <a href="<?= $e(DigitalFiles::downloadUrl((int) $accountFile['id'])) ?>" rel="nofollow"><?= Icons::icon('download', 'icon icon-sm') ?><?= $e(DigitalFiles::displayName($accountFile)) ?></a>
  276. <small><?= $e(DigitalFiles::formatSize((int) $accountFile['size_bytes'])) ?><?= !empty($accountFile['created_at']) ? ' · ' . $e(str_replace('{date}', OrderView::date((string) $accountFile['created_at']), Language::get('account_file_updated', 'updated {date}'))) : '' ?></small>
  277. </li>
  278. <?php endforeach; ?>
  279. </ul>
  280. </div>
  281. <?php endforeach; ?>
  282. </div>
  283. <?php endif; ?>
  284. <?php endif; ?>
  285. ​
  286. <?php if ($activeTab === 'licenses'): ?>
  287. <?php if (empty($licenseKeys)): ?>
  288. <p class="account-empty"><?= $e(Language::get('account_no_licenses', 'License keys for software you buy will show up here.')) ?></p>
  289. <?php else: ?>
  290. <ul class="license-list">
  291. <?php foreach ($licenseKeys as $licenseKey): ?>
  292. <li>
  293. <span><?= $e($licenseKey['product_title_snapshot']) ?><small><a href="account.php?tab=orders&amp;order=<?= (int) $licenseKey['order_ref'] ?>"><?= $e($licenseKey['order_number']) ?></a></small></span>
  294. <code class="license-key"><?= $e($licenseKey['license_key']) ?></code>
  295. <button type="button" class="license-copy" data-copy="<?= $e($licenseKey['license_key']) ?>" data-copied="<?= $e(Language::get('code_copied', 'Copied')) ?>"><?= $e(Language::get('code_copy', 'Copy')) ?></button>
  296. </li>
  297. <?php endforeach; ?>
  298. </ul>
  299. <?= OrderView::copyScript() ?>
  300. <?php endif; ?>
  301. <?php endif; ?>
  302. ​
  303. <?php if ($activeTab === 'addresses'): ?>
  304. <?php if (!empty($addresses)): ?>
  305. <div class="account-addresses">
  306. <?php foreach ($addresses as $address): ?>
  307. <div class="account-address">
  308. <?php if (!empty($address['label'])): ?><strong class="account-address-label"><?= $e($address['label']) ?></strong><?php endif; ?>
  309. <p>
  310. <?= $e($address['full_name']) ?><br>
  311. <?php if (!empty($address['company'])): ?><?= $e($address['company']) ?><br><?php endif; ?>
  312. <?= $e($address['address_line1']) ?><br>
  313. <?php if (!empty($address['address_line2'])): ?><?= $e($address['address_line2']) ?><br><?php endif; ?>
  314. <?= $e(trim($address['postal_code'] . ' ' . $address['city'])) ?><br>
  315. <?= $e(Countries::name((string) $address['country'])) ?>
  316. <?php if (!empty($address['phone'])): ?><br><?= $e($address['phone']) ?><?php endif; ?>
  317. <?php if (!empty($address['tax_id'])): ?><br><?= $e(Language::get('receipt_tax_id', 'Tax ID')) ?>: <?= $e($address['tax_id']) ?><?php endif; ?>
  318. </p>
  319. <div class="account-address-badges">
  320. <?php if ((int) $address['is_default_shipping'] === 1): ?><span class="account-badge"><?= $e(Language::get('account_default_shipping', 'Default for delivery')) ?></span><?php endif; ?>
  321. <?php if ((int) $address['is_default_billing'] === 1): ?><span class="account-badge"><?= $e(Language::get('account_default_billing', 'Default for billing')) ?></span><?php endif; ?>
  322. </div>
  323. <div class="account-address-actions">
  324. <a href="account.php?tab=addresses&amp;edit=<?= (int) $address['id'] ?>#address-form"><?= $e(Language::get('account_edit', 'Edit')) ?></a>
  325. <?php if ((int) $address['is_default_shipping'] !== 1): ?>
  326. <form method="post"><?= Csrf::field() ?><input type="hidden" name="action" value="default_address"><input type="hidden" name="kind" value="shipping"><input type="hidden" name="address_id" value="<?= (int) $address['id'] ?>"><button type="submit"><?= $e(Language::get('account_make_default_shipping', 'Use for delivery')) ?></button></form>
  327. <?php endif; ?>
  328. <?php if ((int) $address['is_default_billing'] !== 1): ?>
  329. <form method="post"><?= Csrf::field() ?><input type="hidden" name="action" value="default_address"><input type="hidden" name="kind" value="billing"><input type="hidden" name="address_id" value="<?= (int) $address['id'] ?>"><button type="submit"><?= $e(Language::get('account_make_default_billing', 'Use for billing')) ?></button></form>
  330. <?php endif; ?>
  331. <form method="post" onsubmit="return confirm(<?= $e(json_encode(Language::get('account_address_delete_confirm', 'Delete this address?'))) ?>);"><?= Csrf::field() ?><input type="hidden" name="action" value="delete_address"><input type="hidden" name="address_id" value="<?= (int) $address['id'] ?>"><button type="submit" class="account-danger-link"><?= $e(Language::get('account_delete', 'Delete')) ?></button></form>
  332. </div>
  333. </div>
  334. <?php endforeach; ?>
  335. </div>
  336. <?php endif; ?>
  337. ​
  338. <form method="post" class="account-form" id="address-form">
  339. <h2 class="account-section-title"><?= $e($editAddress !== null ? Language::get('account_edit_address', 'Edit address') : Language::get('account_add_address', 'Add an address')) ?></h2>
  340. <?= Csrf::field() ?>
  341. <input type="hidden" name="action" value="save_address">
  342. <input type="hidden" name="address_id" value="<?= (int) ($editAddress['id'] ?? 0) ?>">
  343. <label><?= $e(Language::get('account_address_label', 'Name for this address (optional, e.g. Home or Office)')) ?><input type="text" name="label" maxlength="60" value="<?= $e($editAddress['label'] ?? '') ?>"></label>
  344. <label><?= $e(Language::get('checkout_full_name', 'Full name')) ?><input type="text" name="full_name" required maxlength="190" autocomplete="name" value="<?= $e($editAddress['full_name'] ?? ($reader['display_name'] ?? '')) ?>"></label>
  345. <div class="checkout-grid">
  346. <label><?= $e(Language::get('checkout_company', 'Company name')) ?><input type="text" name="company" maxlength="190" autocomplete="organization" value="<?= $e($editAddress['company'] ?? '') ?>"></label>
  347. <label><?= $e(Language::get('checkout_tax_id', 'Tax ID (VAT number)')) ?><input type="text" name="tax_id" maxlength="60" value="<?= $e($editAddress['tax_id'] ?? '') ?>"></label>
  348. </div>
  349. <label><?= $e(Language::get('checkout_country_label', 'Country')) ?>
  350. <select name="country" required autocomplete="country">
  351. <option value=""><?= $e(Language::get('checkout_choose_country', 'Choose a country')) ?></option>
  352. <?php foreach (Countries::all() as $countryCode => $countryName): ?>
  353. <option value="<?= $e($countryCode) ?>" <?= ($editAddress['country'] ?? Shop::setting('shop_default_country', '')) === $countryCode ? 'selected' : '' ?>><?= $e($countryName) ?></option>
  354. <?php endforeach; ?>
  355. </select>
  356. </label>
  357. <label><?= $e(Language::get('checkout_address_line1', 'Address')) ?><input type="text" name="address_line1" required maxlength="255" autocomplete="address-line1" value="<?= $e($editAddress['address_line1'] ?? '') ?>"></label>
  358. <label><?= $e(Language::get('checkout_address_line2', 'Address line 2 (optional)')) ?><input type="text" name="address_line2" maxlength="255" autocomplete="address-line2" value="<?= $e($editAddress['address_line2'] ?? '') ?>"></label>
  359. <div class="checkout-grid">
  360. <label><?= $e(Language::get('checkout_postal_code', 'Postal code')) ?><input type="text" name="postal_code" required maxlength="30" autocomplete="postal-code" value="<?= $e($editAddress['postal_code'] ?? '') ?>"></label>
  361. <label><?= $e(Language::get('checkout_city', 'City')) ?><input type="text" name="city" required maxlength="120" autocomplete="address-level2" value="<?= $e($editAddress['city'] ?? '') ?>"></label>
  362. </div>
  363. <div class="checkout-grid">
  364. <label><?= $e(Language::get('checkout_region', 'State / Region')) ?><input type="text" name="region" maxlength="120" autocomplete="address-level1" value="<?= $e($editAddress['region'] ?? '') ?>"></label>
  365. <label><?= $e(Language::get('checkout_phone', 'Phone number')) ?><input type="tel" name="phone" maxlength="40" autocomplete="tel" value="<?= $e($editAddress['phone'] ?? ($reader['phone'] ?? '')) ?>"></label>
  366. </div>
  367. <div class="account-form-actions">
  368. <button type="submit" class="unlock-btn"><?= $e(Language::get('account_save', 'Save changes')) ?></button>
  369. <?php if ($editAddress !== null): ?><a href="account.php?tab=addresses"><?= $e(Language::get('account_cancel', 'Cancel')) ?></a><?php endif; ?>
  370. </div>
  371. </form>
  372. <?php endif; ?>
  373. ​
  374. <?php if ($activeTab === 'profile'): ?>
  375. <form method="post" class="account-form">
  376. <h2 class="account-section-title"><?= $e(Language::get('account_details', 'Your details')) ?></h2>
  377. <?= Csrf::field() ?>
  378. <input type="hidden" name="action" value="update_profile">
  379. <label><?= $e(Language::get('auth_display_name', 'Display name')) ?><input type="text" name="display_name" maxlength="100" value="<?= $e($reader['display_name'] ?? '') ?>"></label>
  380. <label><?= $e(Language::get('checkout_phone', 'Phone number')) ?><input type="tel" name="phone" maxlength="40" autocomplete="tel" value="<?= $e($reader['phone'] ?? '') ?>"></label>
  381. <label class="checkout-check"><input type="checkbox" name="marketing_opt_in" value="1" <?= (int) ($reader['marketing_opt_in'] ?? 0) === 1 ? 'checked' : '' ?>> <?= $e(Language::get('account_marketing', 'Send me news and offers by email')) ?></label>
  382. <div class="account-form-actions"><button type="submit" class="unlock-btn"><?= $e(Language::get('account_save', 'Save changes')) ?></button></div>
  383. </form>
  384. ​
  385. <form method="post" class="account-form">
  386. <h2 class="account-section-title"><?= $e(Language::get('account_email_title', 'Email address')) ?></h2>
  387. <p class="account-hint"><?= $e(Language::get('account_email_current', 'Current email:')) ?> <strong><?= $e($reader['email']) ?></strong>
  388. <?= !empty($reader['email_verified_at']) ? '<span class="account-badge">' . $e(Language::get('account_email_verified', 'confirmed')) . '</span>' : '' ?></p>
  389. <?= Csrf::field() ?>
  390. <input type="hidden" name="action" value="change_email">
  391. <label><?= $e(Language::get('account_new_email', 'New email address')) ?><input type="email" name="new_email" required maxlength="190" autocomplete="email"></label>
  392. <label><?= $e(Language::get('account_current_password_short', 'Current password')) ?><input type="password" name="current_password" required autocomplete="current-password"></label>
  393. <div class="account-form-actions"><button type="submit" class="account-button-secondary"><?= $e(Language::get('account_change_email', 'Change email')) ?></button></div>
  394. </form>
  395. ​
  396. <form method="post" class="account-form">
  397. <h2 class="account-section-title"><?= $e(Language::get('account_password_title', 'Password')) ?></h2>
  398. <?= Csrf::field() ?>
  399. <input type="hidden" name="action" value="change_password">
  400. <label><?= $e(Language::get('account_current_password_short', 'Current password')) ?><input type="password" name="current_password" required autocomplete="current-password"></label>
  401. <div class="checkout-grid">
  402. <label><?= $e(Language::get('account_new_password_short', 'New password')) ?><input type="password" name="new_password" required minlength="8" autocomplete="new-password"></label>
  403. <label><?= $e(Language::get('auth_confirm_password', 'Confirm password')) ?><input type="password" name="new_password_confirm" required minlength="8" autocomplete="new-password"></label>
  404. </div>
  405. <div class="account-form-actions"><button type="submit" class="account-button-secondary"><?= $e(Language::get('account_change_password', 'Change password')) ?></button></div>
  406. </form>
  407. <?php endif; ?>
  408. ​
  409. <?php if ($activeTab === 'privacy'): ?>
  410. <form method="post" class="account-form">
  411. <h2 class="account-section-title"><?= $e(Language::get('account_consents', 'Privacy consents')) ?></h2>
  412. <?= Csrf::field() ?>
  413. <input type="hidden" name="action" value="update_consents">
  414. <label class="checkout-check"><input type="checkbox" name="consent_analytics" <?= !empty($consents['analytics']) ? 'checked' : '' ?>> <?= $e(Language::get('account_consent_analytics', 'Allow analytics tracking')) ?></label>
  415. <label class="checkout-check"><input type="checkbox" name="consent_ads_personalization" <?= !empty($consents['ads_personalization']) ? 'checked' : '' ?>> <?= $e(Language::get('account_consent_ads', 'Allow personalized ads')) ?></label>
  416. <div class="account-form-actions"><button type="submit" class="unlock-btn"><?= $e(Language::get('account_save', 'Save changes')) ?></button></div>
  417. </form>
  418. ​
  419. <form method="post" class="account-form">
  420. <h2 class="account-section-title"><?= $e(Language::get('account_export_title', 'Download your data')) ?></h2>
  421. <p class="account-hint"><?= $e(Language::get('account_export_hint', 'Get a file with your account details, addresses, orders and license keys.')) ?></p>
  422. <?= Csrf::field() ?>
  423. <input type="hidden" name="action" value="export_data">
  424. <div class="account-form-actions"><button type="submit" class="account-button-secondary"><?= Icons::icon('download', 'icon icon-sm') ?><?= $e(Language::get('account_export_button', 'Download my data')) ?></button></div>
  425. </form>
  426. ​
  427. <form method="post" class="account-form account-danger-zone" onsubmit="return confirm(<?= $e(json_encode(Language::get('account_delete_confirm', 'Delete your account for good? This cannot be undone.'))) ?>);">
  428. <h2 class="account-section-title"><?= $e(Language::get('account_delete_title', 'Delete account')) ?></h2>
  429. <p class="account-hint"><?= $e(Language::get('account_delete_hint', 'We remove your personal details and log you out. Orders stay in our records because the law requires it, but they are no longer linked to a login.')) ?></p>
  430. <?= Csrf::field() ?>
  431. <input type="hidden" name="action" value="delete_account">
  432. <label><?= $e(Language::get('account_current_password_short', 'Current password')) ?><input type="password" name="current_password" required autocomplete="current-password"></label>
  433. <label class="checkout-check"><input type="checkbox" name="confirm_delete" value="1" required> <?= $e(Language::get('account_delete_check', 'I understand that this cannot be undone')) ?></label>
  434. <div class="account-form-actions"><button type="submit" class="account-button-danger"><?= $e(Language::get('account_delete_button', 'Delete my account')) ?></button></div>
  435. </form>
  436. <?php endif; ?>
  437. </div>
  438. ​
  439. <?php require __DIR__ . '/includes/front-footer.php'; ?>
  440. ​