WebOrbiton
v3.0.0.2

FlatlyPage

138 lines · 4.2 KB
  1. <?php
  2. if (!file_exists('config.php')) {
  3. header('Location: newsletter-unavailable.php');
  4. exit;
  5. }
  6. require_once 'config.php';
  7. $token = $_GET['token'] ?? '';
  8. if (empty($token)) {
  9. showMessage('Error', 'Invalid confirmation link', 'error');
  10. }
  11. $pdo = getDB();
  12. if (!$pdo) {
  13. showMessage('Error', 'Server problem. Please try again later.', 'error');
  14. }
  15. try {
  16. $stmt = $pdo->prepare("
  17. UPDATE newsletter_subscribers
  18. SET confirmed = 1, confirmed_at = NOW()
  19. WHERE token = ? AND confirmed = 0
  20. ");
  21. $stmt->execute([$token]);
  22. if ($stmt->rowCount() > 0) {
  23. showMessage(
  24. 'Success!',
  25. 'Your newsletter subscription has been confirmed. Thank you!',
  26. 'success'
  27. );
  28. } else {
  29. $stmt = $pdo->prepare("SELECT confirmed FROM newsletter_subscribers WHERE token = ?");
  30. $stmt->execute([$token]);
  31. $result = $stmt->fetch();
  32. if ($result && $result['confirmed']) {
  33. showMessage(
  34. 'Info',
  35. 'This subscription has already been confirmed.',
  36. 'info'
  37. );
  38. } else {
  39. showMessage(
  40. 'Error',
  41. 'Invalid or expired confirmation link.',
  42. 'error'
  43. );
  44. }
  45. }
  46. } catch (PDOException $e) {
  47. error_log("Confirmation error: " . $e->getMessage());
  48. showMessage('Error', 'An error occurred. Please try again later.', 'error');
  49. }
  50. function showMessage($title, $message, $type) {
  51. $colors = [
  52. 'success' => ['bg' => '#d4edda', 'border' => '#c3e6cb', 'text' => '#155724'],
  53. 'error' => ['bg' => '#f8d7da', 'border' => '#f5c6cb', 'text' => '#721c24'],
  54. 'info' => ['bg' => '#d1ecf1', 'border' => '#bee5eb', 'text' => '#0c5460']
  55. ];
  56. $color = $colors[$type] ?? $colors['info'];
  57. ?>
  58. <!DOCTYPE html>
  59. <html lang="en">
  60. <head>
  61. <meta charset="UTF-8">
  62. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  63. <link rel="icon" href="nl.ico?v=<?= filemtime(__DIR__ . '/newsletter/nl.ico') ?>" type="image/x-icon">
  64. <title><?= htmlspecialchars($title) ?></title>
  65. <style>
  66. * { margin: 0; padding: 0; box-sizing: border-box; }
  67. body {
  68. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  69. background: #f5f5f5;
  70. display: flex;
  71. align-items: center;
  72. justify-content: center;
  73. min-height: 100vh;
  74. padding: 20px;
  75. }
  76. .message-box {
  77. background: white;
  78. border-radius: 8px;
  79. box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  80. max-width: 500px;
  81. width: 100%;
  82. overflow: hidden;
  83. }
  84. .message-header {
  85. background: <?= $color['bg'] ?>;
  86. border-bottom: 2px solid <?= $color['border'] ?>;
  87. color: <?= $color['text'] ?>;
  88. padding: 20px;
  89. text-align: center;
  90. }
  91. .message-content {
  92. padding: 30px;
  93. text-align: center;
  94. color: #333;
  95. line-height: 1.6;
  96. }
  97. .btn {
  98. display: inline-block;
  99. margin-top: 20px;
  100. padding: 12px 30px;
  101. background: #007bff;
  102. color: white;
  103. text-decoration: none;
  104. border-radius: 5px;
  105. transition: background 0.3s;
  106. }
  107. .btn:hover {
  108. background: #0056b3;
  109. }
  110. </style>
  111. </head>
  112. <body>
  113. <div class="message-box">
  114. <div class="message-header">
  115. <h1><?= htmlspecialchars($title) ?></h1>
  116. </div>
  117. <div class="message-content">
  118. <p><?= htmlspecialchars($message) ?></p>
  119. <a href="<?= SITE_URL ?>" class="btn">Back to homepage</a>
  120. </div>
  121. </div>
  122. </body>
  123. </html>
  124. <?php
  125. exit;
  126. }
  127. ?>