profile.php 5.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. // Αρχείο: /var/www/html/hockey-cms/profile.php
  3. session_start();
  4. require_once __DIR__ . '/config/database.php';
  5. // Πρέπει να είναι συνδεδεμένος
  6. if (!isset($_SESSION['user_id'])) { header("Location: login.php"); exit; }
  7. $user_id = $_SESSION['user_id'];$message = '';
  8. // Διαβάζουμε αν επιτρέπεται στους χρήστες να γίνονται sellers (από το admin)
  9. $stmt =$pdo->query("SELECT value FROM settings WHERE `key` = 'allow_user_to_seller'");
  10. $allow_user_to_seller = (int)$stmt->fetchColumn();
  11. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  12. $email = trim($_POST['email']);
  13. $phone = trim($_POST['phone']);
  14. // Αν επιτρέπεται η αλλαγή σε seller, διαβάζουμε το checkbox. Αλλιώς, κρατάμε την τρέχουσα κατάσταση (ή 0)
  15. if ($allow_user_to_seller) {
  16. $is_seller = isset($_POST['is_seller']) ? 1 : 0;
  17. } else {
  18. // Αν δεν επιτρέπεται, δεν αφήνουμε την αλλαγή μέσω της φόρμας
  19. $is_seller =$_SESSION['is_seller'] ?? 0;
  20. }
  21. // Ενημέρωση βάσης
  22. $stmt =$pdo->prepare("UPDATE users SET email = ?, phone = ?, is_seller = ? WHERE id = ?");
  23. $stmt->execute([$email,$phone, $is_seller,$user_id]);
  24. // Ενημέρωση του session αμέσως!
  25. $_SESSION['is_seller'] =$is_seller;
  26. $message = "<div style='background:#d1e7dd; color:#0f5132; padding:10px; border-radius:6px; margin-bottom:20px;'>Το προφίλ σου ενημερώθηκε επιτυχώς!</div>";
  27. }
  28. // Φέρνουμε τα τρέχοντα στοιχεία
  29. $stmt =$pdo->prepare("SELECT * FROM users WHERE id = ?");
  30. $stmt->execute([$user_id]);
  31. $user =$stmt->fetch(PDO::FETCH_ASSOC);
  32. ?>
  33. <!DOCTYPE html>
  34. <html lang="el">
  35. <head>
  36. <meta charset="UTF-8">
  37. <title>Το Προφίλ μου</title>
  38. <style>
  39. body { font-family: 'Segoe UI', sans-serif; background: #0f172a; padding: 40px; color: #f8fafc;}
  40. .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; }
  41. 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; }
  42. input[type="text"]:focus, input[type="email"]:focus { outline: none; border-color: #f97316; }
  43. 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;}
  44. button:hover { background: #ea580c; }
  45. .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; }
  46. label { font-weight: 600; color: #cbd5e1; font-size: 14px;}
  47. </style>
  48. </head>
  49. <body>
  50. <div class="profile-container">
  51. <h2 style="color: #f8fafc; margin-top: 0;">👤 Το Προφίλ μου</h2>
  52. <?php echo $message; ?>
  53. <form method="POST">
  54. <label>Όνομα Χρήστη (Δεν αλλάζει)</label>
  55. <input type="text" value="<?php echo htmlspecialchars($user['username']); ?>" disabled style="background: rgba(255,255,255,0.05); color: #94a3b8;">
  56. <label>Email</label>
  57. <input type="email" name="email" value="<?php echo htmlspecialchars($user['email'] ?? ''); ?>" required>
  58. <label>Τηλέφωνο</label>
  59. <input type="text" name="phone" value="<?php echo htmlspecialchars($user['phone'] ?? ''); ?>">
  60. <?php if ($allow_user_to_seller): ?>
  61. <div class="seller-box">
  62. <label style="display:flex; align-items:center; gap:10px; font-weight:bold; cursor:pointer; color: #f97316;">
  63. <input type="checkbox" name="is_seller" value="1" <?php echo $user['is_seller'] ? 'checked' : ''; ?> style="width:20px; height:20px; accent-color: #f97316;">
  64. Θέλω να γίνω Πωλητής (Ανέβασμα Αγγελιών)
  65. </label>
  66. <p style="font-size:12px; color:#94a3b8; margin:8px 0 0 30px;">Ενεργοποίησέ το για να εμφανιστεί το εικονίδιο 'Seller' στο μενού και να μπορείς να πουλάς τον δικό σου εξοπλισμό!</p>
  67. </div>
  68. <?php else: ?>
  69. <!-- Αν είναι ήδη πωλητής από παλιά, ή του το έδωσε ο admin, τον ενημερώνουμε απλά -->
  70. <?php if ($user['is_seller']): ?>
  71. <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;">
  72. <p style="margin:0; color: #10b981; font-weight: bold;">✔️ Ο λογαριασμός σου έχει δικαιώματα Πωλητή.</p>
  73. </div>
  74. <?php endif; ?>
  75. <?php endif; ?>
  76. <button type="submit">Αποθήκευση Αλλαγών</button>
  77. </form>
  78. <div style="text-align:center; margin-top:20px;">
  79. <a href="index.php" style="color: #94a3b8; text-decoration:none;">Επιστροφή στο E-shop</a>
  80. </div>
  81. </div>
  82. </body>
  83. </html>