| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- // Αρχείο: /var/www/html/hockey-cms/profile.php
- session_start();
- require_once __DIR__ . '/config/database.php';
- // Πρέπει να είναι συνδεδεμένος
- if (!isset($_SESSION['user_id'])) { header("Location: login.php"); exit; }
- $user_id = $_SESSION['user_id'];$message = '';
- // Διαβάζουμε αν επιτρέπεται στους χρήστες να γίνονται sellers (από το admin)
- $stmt =$pdo->query("SELECT value FROM settings WHERE `key` = 'allow_user_to_seller'");
- $allow_user_to_seller = (int)$stmt->fetchColumn();
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $email = trim($_POST['email']);
- $phone = trim($_POST['phone']);
-
- // Αν επιτρέπεται η αλλαγή σε seller, διαβάζουμε το checkbox. Αλλιώς, κρατάμε την τρέχουσα κατάσταση (ή 0)
- if ($allow_user_to_seller) {
- $is_seller = isset($_POST['is_seller']) ? 1 : 0;
- } else {
- // Αν δεν επιτρέπεται, δεν αφήνουμε την αλλαγή μέσω της φόρμας
- $is_seller =$_SESSION['is_seller'] ?? 0;
- }
-
- // Ενημέρωση βάσης
- $stmt =$pdo->prepare("UPDATE users SET email = ?, phone = ?, is_seller = ? WHERE id = ?");
- $stmt->execute([$email,$phone, $is_seller,$user_id]);
-
- // Ενημέρωση του session αμέσως!
- $_SESSION['is_seller'] =$is_seller;
-
- $message = "<div style='background:#d1e7dd; color:#0f5132; padding:10px; border-radius:6px; margin-bottom:20px;'>Το προφίλ σου ενημερώθηκε επιτυχώς!</div>";
- }
- // Φέρνουμε τα τρέχοντα στοιχεία
- $stmt =$pdo->prepare("SELECT * FROM users WHERE id = ?");
- $stmt->execute([$user_id]);
- $user =$stmt->fetch(PDO::FETCH_ASSOC);
- ?>
- <!DOCTYPE html>
- <html lang="el">
- <head>
- <meta charset="UTF-8">
- <title>Το Προφίλ μου</title>
- <style>
- body { font-family: 'Segoe UI', sans-serif; background: #0f172a; padding: 40px; color: #f8fafc;}
- .profile-container { background: #1e293b; padding: 30px; border-radius: 12px; box-shadow: 0 4px 10px rgba(0,0,0,0.5); max-width: 500px; margin: 0 auto; border: 1px solid #334155; }
- input[type="text"], input[type="email"] { width: 100%; padding: 12px; margin: 8px 0 20px; border: 1px solid #334155; border-radius: 6px; box-sizing: border-box; background: #0f172a; color: #fff; }
- input[type="text"]:focus, input[type="email"]:focus { outline: none; border-color: #f97316; }
- button { padding: 12px 20px; background: #f97316; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; width: 100%; text-transform: uppercase; font-size: 15px;}
- button:hover { background: #ea580c; }
- .seller-box { background: rgba(249, 115, 22, 0.1); border: 1px solid rgba(249, 115, 22, 0.2); padding: 15px; border-radius: 6px; margin-bottom: 20px; }
- label { font-weight: 600; color: #cbd5e1; font-size: 14px;}
- </style>
- </head>
- <body>
- <div class="profile-container">
- <h2 style="color: #f8fafc; margin-top: 0;">👤 Το Προφίλ μου</h2>
- <?php echo $message; ?>
-
- <form method="POST">
- <label>Όνομα Χρήστη (Δεν αλλάζει)</label>
- <input type="text" value="<?php echo htmlspecialchars($user['username']); ?>" disabled style="background: rgba(255,255,255,0.05); color: #94a3b8;">
- <label>Email</label>
- <input type="email" name="email" value="<?php echo htmlspecialchars($user['email'] ?? ''); ?>" required>
-
- <label>Τηλέφωνο</label>
- <input type="text" name="phone" value="<?php echo htmlspecialchars($user['phone'] ?? ''); ?>">
- <?php if ($allow_user_to_seller): ?>
- <div class="seller-box">
- <label style="display:flex; align-items:center; gap:10px; font-weight:bold; cursor:pointer; color: #f97316;">
- <input type="checkbox" name="is_seller" value="1" <?php echo $user['is_seller'] ? 'checked' : ''; ?> style="width:20px; height:20px; accent-color: #f97316;">
- Θέλω να γίνω Πωλητής (Ανέβασμα Αγγελιών)
- </label>
- <p style="font-size:12px; color:#94a3b8; margin:8px 0 0 30px;">Ενεργοποίησέ το για να εμφανιστεί το εικονίδιο 'Seller' στο μενού και να μπορείς να πουλάς τον δικό σου εξοπλισμό!</p>
- </div>
- <?php else: ?>
- <!-- Αν είναι ήδη πωλητής από παλιά, ή του το έδωσε ο admin, τον ενημερώνουμε απλά -->
- <?php if ($user['is_seller']): ?>
- <div style="background: rgba(16, 185, 129, 0.1); border: 1px solid rgba(16, 185, 129, 0.2); padding: 15px; border-radius: 6px; margin-bottom: 20px;">
- <p style="margin:0; color: #10b981; font-weight: bold;">✔️ Ο λογαριασμός σου έχει δικαιώματα Πωλητή.</p>
- </div>
- <?php endif; ?>
- <?php endif; ?>
- <button type="submit">Αποθήκευση Αλλαγών</button>
- </form>
-
- <div style="text-align:center; margin-top:20px;">
- <a href="index.php" style="color: #94a3b8; text-decoration:none;">Επιστροφή στο E-shop</a>
- </div>
- </div>
- </body>
- </html>
|