query("SELECT * FROM settings"); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { if (isset($row['key']) && $row['key'] === 'active_theme' && !empty($row['value'])) { $active_theme = trim($row['value']); } } } catch (Exception $e) {} $theme_dir = __DIR__ . '/themes/' . $active_theme; if (!is_dir($theme_dir)) { $active_theme = 'default'; $theme_dir = __DIR__ . '/themes/default'; } // --- Αρχικοποίηση Twig --- $loader = new \Twig\Loader\FilesystemLoader($theme_dir); $twig = new \Twig\Environment($loader, ['cache' => false]); $twig->addGlobal('session', $_SESSION); $twig->addGlobal('current_lang', $current_lang); // --- Φόρτωση Δυναμικών Κειμένων Site --- $siteTexts = []; try { $text_column = ($current_lang === 'en') ? 'text_value_en' : 'text_value_el'; $textsStmt = $pdo->query("SELECT text_key, {$text_column} as text_value FROM site_texts"); while ($row = $textsStmt->fetch(PDO::FETCH_ASSOC)) { $siteTexts[$row['text_key']] = $row['text_value']; } } catch (Exception $e) {} $twig->addGlobal('text', $siteTexts); // --- Φόρτωση Logo Site --- $site_logo = ''; try { $stmtSettings = $pdo->query("SELECT * FROM settings"); while ($row = $stmtSettings->fetch(PDO::FETCH_ASSOC)) { if (isset($row['key']) && $row['key'] === 'site_logo') { $site_logo = $row['value']; } } } catch (Exception $e) {} $twig->addGlobal('site_logo', $site_logo); // --- Μεταφράσεις --- $translations = [ 'el' => [ 'title' => 'Νέα Εγγραφή', 'fname' => 'Όνομα *', 'lname' => 'Επίθετο *', 'username' => 'Διάλεξε Username *', 'email' => 'Το Email σου *', 'phone' => 'Τηλέφωνο (Προαιρετικό)', 'password' => 'Κωδικός *', 'btn_register' => 'Δημιουργία Λογαριασμού', 'btn_google' => 'Εγγραφή με Google', 'already_have' => 'Έχετε ήδη λογαριασμό;', 'login' => 'Σύνδεση', 'err_exists' => 'Το Όνομα Χρήστη ή το Email υπάρχει ήδη!', 'err_general' => 'Σφάλμα κατά την εγγραφή. Δοκιμάστε ξανά.', 'err_req_fields' => 'Παρακαλώ συμπληρώστε όλα τα υποχρεωτικά πεδία!', 'err_captcha' => 'Λάθος αποτέλεσμα στην επαλήθευση (CAPTCHA)!', 'success' => 'Η εγγραφή ολοκληρώθηκε! Μπορείτε να συνδεθείτε.', 'captcha_label' => 'Επαλήθευση: Πόσο κάνει ', 'captcha_ph' => 'Αποτέλεσμα...' ], 'en' => [ 'title' => 'Create Account', 'fname' => 'First Name *', 'lname' => 'Last Name *', 'username' => 'Choose Username *', 'email' => 'Email Address *', 'phone' => 'Phone (Optional)', 'password' => 'Password *', 'btn_register' => 'Register', 'btn_google' => 'Sign up with Google', 'already_have' => 'Already have an account?', 'login' => 'Login', 'err_exists' => 'Username or Email already exists!', 'err_general' => 'Registration error. Please try again.', 'err_req_fields' => 'Please fill in all required fields!', 'err_captcha' => 'Incorrect verification result (CAPTCHA)!', 'success' => 'Registration complete! You can now login.', 'captcha_label' => 'Verification: How much is ', 'captcha_ph' => 'Result...' ] ]; $t = $translations[$current_lang]; $message = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $first_name = trim($_POST['reg_first_name'] ?? ''); $last_name = trim($_POST['reg_last_name'] ?? ''); $username = trim($_POST['reg_username'] ?? ''); $email = trim($_POST['reg_email'] ?? ''); $phone = trim($_POST['reg_phone'] ?? ''); $password = $_POST['reg_password'] ?? ''; $captcha_answer = isset($_POST['reg_captcha']) ? (int)$_POST['reg_captcha'] : -1; $expected_captcha = $_SESSION['captcha_result'] ?? -2; if (empty($first_name) || empty($last_name) || empty($username) || empty($email) || empty($password)) { $message = "
" . $t['err_req_fields'] . "
"; } elseif ($captcha_answer !== $expected_captcha) { $message = "
" . $t['err_captcha'] . "
"; } else { $check = $pdo->prepare("SELECT id FROM users WHERE username = ? OR email = ?"); $check->execute([$username, $email]); if ($check->fetch()) { $message = "
" . $t['err_exists'] . "
"; } else { $hashed = password_hash($password, PASSWORD_DEFAULT); $stmt = $pdo->prepare("INSERT INTO users (first_name, last_name, username, email, phone, password, role_id, is_seller) VALUES (?, ?, ?, ?, ?, ?, 3, 0)"); if ($stmt->execute([$first_name, $last_name, $username, $email, $phone, $hashed])) { $message = "
" . $t['success'] . "
"; } else { $message = "
" . $t['err_general'] . "
"; } } } } // CAPTCHA $num1 = rand(1, 10); $num2 = rand(1, 10); $_SESSION['captcha_result'] = $num1 + $num2; $captcha_text = $num1 . " + " . $num2; echo $twig->render('register.html.twig', [ 't' => $t, 'current_lang' => $current_lang, 'message' => $message, 'captcha_text' => $captcha_text ]);