users.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <?php
  2. // Αρχείο: /var/www/html/hockey-cms/admin/users.php
  3. require_once 'admin_auth.php';
  4. require_once '../config/database.php';
  5. session_start();
  6. // Αυστηρός έλεγχος: Μόνο ο Administrator (role_id = 1) έχει πρόσβαση
  7. if (!isset($_SESSION['user_id']) || $_SESSION['role_id'] != 1) {
  8. header("Location: index.php");
  9. exit;
  10. }
  11. // --- Μηχανισμός Αλλαγής Γλώσσας ---
  12. if (isset($_GET['lang']) && in_array($_GET['lang'], ['el', 'en'])) {
  13. $_SESSION['lang'] = $_GET['lang'];
  14. }
  15. $current_lang = $_SESSION['lang'] ?? 'el';
  16. $translations = [
  17. 'el' => [
  18. 'page_title' => 'Διαχείριση Χρηστών',
  19. 'header_title' => 'Διαχείριση Χρηστών & Sellers',
  20. 'allow_sellers_q' => 'Επιτρέπεται οι χρήστες (Πελάτες) να γίνονται από μόνοι τους Πωλητές (Sellers) μέσα από το προφίλ τους;',
  21. 'yes_allow' => 'ΝΑΙ, ΕΠΙΤΡΕΠΕΤΑΙ',
  22. 'new_account' => 'Δημιουργία Νέου Λογαριασμού',
  23. 'username' => 'Όνομα Χρήστη (Username) *',
  24. 'password' => 'Κωδικός Πρόσβασης (Password) *',
  25. 'first_name' => 'Όνομα',
  26. 'last_name' => 'Επώνυμο',
  27. 'email' => 'Email',
  28. 'phone' => 'Τηλέφωνο',
  29. 'role' => 'Ρόλος (Δικαιώματα) *',
  30. 'select_role' => '-- Επίλεξε Ρόλο --',
  31. 'btn_create' => 'Δημιουργία Χρήστη',
  32. 'user_list' => 'Λίστα Εγγεγραμμένων Χρηστών',
  33. 'th_id' => 'ID',
  34. 'th_user' => 'Χρήστης',
  35. 'th_name' => 'Ονοματεπώνυμο',
  36. 'th_contact' => 'Επικοινωνία',
  37. 'th_role' => 'Ρόλος',
  38. 'th_actions' => 'Ενέργειες',
  39. 'btn_pass' => 'Κωδικός',
  40. 'btn_del' => 'Διαγραφή',
  41. 'your_account' => 'Ο λογαριασμός σας',
  42. 'change_pass_title' => 'Αλλαγή Κωδικού',
  43. 'for_user' => 'Για τον χρήστη:',
  44. 'new_pass_label' => 'Νέος Κωδικός Πρόσβασης',
  45. 'btn_save_pass' => 'Αποθήκευση νέου κωδικού',
  46. 'msg_setting_ok' => 'Η ρύθμιση για τους πωλητές ενημερώθηκε!',
  47. 'msg_user_added' => 'Ο χρήστης δημιουργήθηκε επιτυχώς!',
  48. 'msg_err_empty' => 'Παρακαλώ συμπληρώστε τα υποχρεωτικά πεδία.',
  49. 'msg_err_role_self' => 'Δεν μπορείτε να αλλάξετε τον δικό σας ρόλο!',
  50. 'msg_role_upd' => 'Ο ρόλος του χρήστη ενημερώθηκε επιτυχώς!',
  51. 'msg_err_del_self' => 'Απαγορεύεται η διαγραφή του δικού σας λογαριασμού!',
  52. 'msg_del_ok' => 'Ο χρήστης διαγράφηκε επιτυχώς!',
  53. 'msg_err_del' => 'Δεν μπορεί να διαγραφεί αυτός ο χρήστης γιατί έχει καταχωρημένα προϊόντα ή ιστορικό παραγγελιών.',
  54. 'msg_pass_self_ok' => 'Ο προσωπικός σας κωδικός άλλαξε επιτυχώς! Στην επόμενη σύνδεση θα χρησιμοποιήσετε τον νέο.',
  55. 'msg_pass_ok' => 'Ο κωδικός του χρήστη άλλαξε επιτυχώς!',
  56. 'confirm_del' => 'ΠΡΟΣΟΧΗ: Θέλετε σίγουρα να διαγράψετε τον χρήστη: '
  57. ],
  58. 'en' => [
  59. 'page_title' => 'User Management',
  60. 'header_title' => 'Users & Sellers Management',
  61. 'allow_sellers_q' => 'Are users (Customers) allowed to become Sellers on their own through their profile?',
  62. 'yes_allow' => 'YES, ALLOWED',
  63. 'new_account' => 'Create New Account',
  64. 'username' => 'Username *',
  65. 'password' => 'Password *',
  66. 'first_name' => 'First Name',
  67. 'last_name' => 'Last Name',
  68. 'email' => 'Email',
  69. 'phone' => 'Phone',
  70. 'role' => 'Role (Permissions) *',
  71. 'select_role' => '-- Select Role --',
  72. 'btn_create' => 'Create User',
  73. 'user_list' => 'Registered Users List',
  74. 'th_id' => 'ID',
  75. 'th_user' => 'User',
  76. 'th_name' => 'Full Name',
  77. 'th_contact' => 'Contact',
  78. 'th_role' => 'Role',
  79. 'th_actions' => 'Actions',
  80. 'btn_pass' => 'Password',
  81. 'btn_del' => 'Delete',
  82. 'your_account' => 'Your account',
  83. 'change_pass_title' => 'Change Password',
  84. 'for_user' => 'For user:',
  85. 'new_pass_label' => 'New Password',
  86. 'btn_save_pass' => 'Save new password',
  87. 'msg_setting_ok' => 'Seller setting updated!',
  88. 'msg_user_added' => 'User created successfully!',
  89. 'msg_err_empty' => 'Please fill in the required fields.',
  90. 'msg_err_role_self' => 'You cannot change your own role!',
  91. 'msg_role_upd' => 'User role updated successfully!',
  92. 'msg_err_del_self' => 'Deleting your own account is forbidden!',
  93. 'msg_del_ok' => 'User deleted successfully!',
  94. 'msg_err_del' => 'Cannot delete this user because they have registered products or order history.',
  95. 'msg_pass_self_ok' => 'Your personal password changed successfully! Use the new one on next login.',
  96. 'msg_pass_ok' => 'User password changed successfully!',
  97. 'confirm_del' => 'WARNING: Are you sure you want to delete user: '
  98. ]
  99. ];
  100. $t = $translations[$current_lang];
  101. header('Content-Type: text/html; charset=utf-8');
  102. $message = '';
  103. try {
  104. $pdo->exec("CREATE TABLE IF NOT EXISTS settings (`key` VARCHAR(50) PRIMARY KEY, `value` TEXT NOT NULL)");
  105. $stmt = $pdo->query("SELECT value FROM settings WHERE `key` = 'allow_user_to_seller'");
  106. if ($stmt->rowCount() == 0) {
  107. $pdo->exec("INSERT INTO settings (`key`, `value`) VALUES ('allow_user_to_seller', '0')");
  108. }
  109. } catch (Exception $e) {}
  110. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] == 'update_seller_setting') {
  111. $allow_seller = isset($_POST['allow_seller']) ? '1' : '0';
  112. $stmt = $pdo->prepare("REPLACE INTO settings (`key`, `value`) VALUES ('allow_user_to_seller', ?)");
  113. $stmt->execute([$allow_seller]);
  114. $message = "<div class='alert success'>{$t['msg_setting_ok']}</div>";
  115. }
  116. $stmt = $pdo->query("SELECT value FROM settings WHERE `key` = 'allow_user_to_seller'");
  117. $allow_user_to_seller = (int)$stmt->fetchColumn();
  118. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] == 'add_user') {
  119. $username = trim($_POST['username']);
  120. $password = $_POST['password'];
  121. $first_name = trim($_POST['first_name']);
  122. $last_name = trim($_POST['last_name']);
  123. $email = trim($_POST['email']);
  124. $phone = trim($_POST['phone']);
  125. $role_id = (int)$_POST['role_id'];
  126. if (!empty($username) && !empty($password) && !empty($role_id)) {
  127. try {
  128. $hashed_password = password_hash($password, PASSWORD_DEFAULT);
  129. $stmt = $pdo->prepare("INSERT INTO users (role_id, username, password, first_name, last_name, email, phone) VALUES (?, ?, ?, ?, ?, ?, ?)");
  130. $stmt->execute([$role_id, $username, $hashed_password, $first_name, $last_name, $email, $phone]);
  131. $message = "<div class='alert success'>{$t['msg_user_added']}</div>";
  132. } catch (PDOException $e) {
  133. $message = "<div class='alert error'>Σφάλμα: " . $e->getMessage() . "</div>";
  134. }
  135. } else {
  136. $message = "<div class='alert error'>{$t['msg_err_empty']}</div>";
  137. }
  138. }
  139. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] == 'change_role') {
  140. $target_user_id = (int)$_POST['user_id'];
  141. $new_role_id = (int)$_POST['new_role_id'];
  142. if ($target_user_id === (int)$_SESSION['user_id']) {
  143. $message = "<div class='alert error'>{$t['msg_err_role_self']}</div>";
  144. } else {
  145. try {
  146. $stmt = $pdo->prepare("UPDATE users SET role_id = ? WHERE id = ?");
  147. $stmt->execute([$new_role_id, $target_user_id]);
  148. $message = "<div class='alert success'>{$t['msg_role_upd']}</div>";
  149. } catch (Exception $e) {
  150. $message = "<div class='alert error'>Σφάλμα: " . $e->getMessage() . "</div>";
  151. }
  152. }
  153. }
  154. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] == 'delete_user') {
  155. $del_user_id = (int)$_POST['user_id'];
  156. if ($del_user_id === (int)$_SESSION['user_id']) {
  157. $message = "<div class='alert error'>{$t['msg_err_del_self']}</div>";
  158. } else {
  159. try {
  160. $stmt = $pdo->prepare("DELETE FROM users WHERE id = ?");
  161. $stmt->execute([$del_user_id]);
  162. $message = "<div class='alert success'>{$t['msg_del_ok']}</div>";
  163. } catch (PDOException $e) {
  164. $message = "<div class='alert error'>{$t['msg_err_del']}</div>";
  165. }
  166. }
  167. }
  168. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] == 'change_password') {
  169. $cp_user_id = (int)$_POST['user_id'];
  170. $new_password = $_POST['new_password'];
  171. if (!empty($new_password)) {
  172. try {
  173. $hashed = password_hash($new_password, PASSWORD_DEFAULT);
  174. $stmt = $pdo->prepare("UPDATE users SET password = ? WHERE id = ?");
  175. $stmt->execute([$hashed, $cp_user_id]);
  176. if ($cp_user_id === (int)$_SESSION['user_id']) {
  177. $message = "<div class='alert success'>{$t['msg_pass_self_ok']}</div>";
  178. } else {
  179. $message = "<div class='alert success'>{$t['msg_pass_ok']}</div>";
  180. }
  181. } catch (Exception $e) {
  182. $message = "<div class='alert error'>Σφάλμα: " . $e->getMessage() . "</div>";
  183. }
  184. }
  185. }
  186. $roles = $pdo->query("SELECT id, name FROM roles ORDER BY id")->fetchAll();
  187. $users = $pdo->query("
  188. SELECT u.id, u.username, u.first_name, u.last_name, u.email, u.phone, u.created_at, u.role_id, r.name as role_name
  189. FROM users u
  190. JOIN roles r ON u.role_id = r.id
  191. ORDER BY u.id DESC
  192. ")->fetchAll();
  193. ?>
  194. <!DOCTYPE html>
  195. <html lang="<?php echo $current_lang; ?>">
  196. <head>
  197. <meta charset="UTF-8">
  198. <title><?php echo $t['page_title']; ?> - Hockey CMS</title>
  199. <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
  200. <style>
  201. :root {
  202. --primary: #f97316;
  203. --primary-hover: #ea580c;
  204. --bg-color: #0b1120;
  205. --panel-bg: #1e293b;
  206. --border-color: #334155;
  207. --text-main: #f8fafc;
  208. --text-muted: #94a3b8;
  209. }
  210. body { font-family: 'Inter', sans-serif; background-color: var(--bg-color); color: var(--text-main); margin: 0; }
  211. .content { margin-left: 250px; padding: 30px; }
  212. .content h2 { margin-top: 0; color: var(--primary); font-size: 26px; text-transform: uppercase; letter-spacing: 0.5px; }
  213. .card { background: var(--panel-bg); padding: 25px; border-radius: 8px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3); border: 1px solid var(--border-color); margin-bottom: 25px; }
  214. .card h3 { margin-top: 0; color: var(--text-main); border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 15px; font-size: 18px; text-transform: uppercase; letter-spacing: 0.5px; }
  215. .form-group { margin-bottom: 20px; }
  216. .form-group label { display: block; margin-bottom: 8px; font-weight: 700; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;}
  217. .form-group input, .form-group select { width: 100%; padding: 12px; background: #0f172a; border: 1px solid var(--border-color); color: var(--text-main); border-radius: 6px; box-sizing: border-box; font-family: 'Inter', sans-serif; outline: none; transition: 0.2s; }
  218. .form-group input:focus, .form-group select:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.2); }
  219. .btn { padding: 12px 20px; background: var(--primary); color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: 800; font-size: 14px; text-transform: uppercase; transition: 0.2s; }
  220. .btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
  221. table { width: 100%; border-collapse: collapse; margin-top: 10px; }
  222. table th, table td { padding: 15px; border-bottom: 1px solid rgba(255,255,255,0.05); text-align: left; vertical-align: middle; }
  223. table th { background: rgba(0,0,0,0.2); color: var(--text-muted); text-transform: uppercase; font-size: 13px; font-weight: 700; }
  224. table td { color: var(--text-main); font-size: 14px; }
  225. .badge { padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 800; color: #fff; text-transform: uppercase; }
  226. .badge-admin { background: #ef4444; }
  227. .badge-seller { background: #10b981; }
  228. .badge-user { background: var(--text-muted); color: #0b1120; }
  229. .alert { padding: 15px; border-radius: 6px; margin-bottom: 20px; font-weight: 600; font-size: 14px;}
  230. .success { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.2); }
  231. .error { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2); }
  232. .btn-small { padding: 6px 12px; border: none; border-radius: 4px; cursor: pointer; font-size: 12px; font-weight: 700; color: #fff; margin-right: 5px; text-transform: uppercase; transition: 0.2s;}
  233. .btn-pass { background: rgba(59, 130, 246, 0.1); color: #3b82f6; border: 1px solid rgba(59, 130, 246, 0.2); }
  234. .btn-pass:hover { background: #3b82f6; color: white;}
  235. .btn-del { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2); }
  236. .btn-del:hover { background: #ef4444; color: white;}
  237. .modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.8); }
  238. .modal-content { background-color: var(--panel-bg); margin: 10% auto; padding: 30px; border-radius: 8px; width: 400px; position: relative; box-shadow: 0 10px 25px rgba(0,0,0,0.5); border: 1px solid var(--border-color); }
  239. .close-btn { position: absolute; right: 20px; top: 15px; font-size: 24px; font-weight: bold; cursor: pointer; color: var(--text-muted); }
  240. .close-btn:hover { color: var(--text-main); }
  241. .switch-container { background: rgba(249, 115, 22, 0.1); border: 1px solid rgba(249, 115, 22, 0.2); padding: 15px 25px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px;}
  242. .switch-container p { margin: 0; color: var(--primary); font-weight: 600; font-size: 14px;}
  243. </style>
  244. </head>
  245. <body>
  246. <?php include 'sidebar.php'; ?>
  247. <div class="content">
  248. <h2><?php echo $t['header_title']; ?></h2>
  249. <?php echo $message; ?>
  250. <!-- Ρύθμιση: Να γίνονται μόνοι τους Sellers; -->
  251. <div class="switch-container">
  252. <p><?php echo $t['allow_sellers_q']; ?></p>
  253. <form method="POST" action="users.php" style="margin: 0; display: flex; align-items: center; gap: 10px;">
  254. <input type="hidden" name="action" value="update_seller_setting">
  255. <label style="cursor: pointer; display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--text-main); font-size: 13px;">
  256. <input type="checkbox" name="allow_seller" value="1" <?php echo $allow_user_to_seller ? 'checked' : ''; ?> style="width: 18px; height: 18px; accent-color: var(--primary);" onchange="this.form.submit()">
  257. <?php echo $t['yes_allow']; ?>
  258. </label>
  259. </form>
  260. </div>
  261. <!-- Φόρμα Δημιουργίας Χρήστη -->
  262. <div class="card">
  263. <h3><?php echo $t['new_account']; ?></h3>
  264. <form method="POST" action="users.php">
  265. <input type="hidden" name="action" value="add_user">
  266. <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
  267. <div class="form-group">
  268. <label><?php echo $t['username']; ?></label>
  269. <input type="text" name="username" required>
  270. </div>
  271. <div class="form-group">
  272. <label><?php echo $t['password']; ?></label>
  273. <input type="password" name="password" required>
  274. </div>
  275. <div class="form-group">
  276. <label><?php echo $t['first_name']; ?></label>
  277. <input type="text" name="first_name">
  278. </div>
  279. <div class="form-group">
  280. <label><?php echo $t['last_name']; ?></label>
  281. <input type="text" name="last_name">
  282. </div>
  283. <div class="form-group">
  284. <label><?php echo $t['email']; ?></label>
  285. <input type="email" name="email">
  286. </div>
  287. <div class="form-group">
  288. <label><?php echo $t['phone']; ?></label>
  289. <input type="text" name="phone">
  290. </div>
  291. <div class="form-group">
  292. <label><?php echo $t['role']; ?></label>
  293. <select name="role_id" required>
  294. <option value=""><?php echo $t['select_role']; ?></option>
  295. <?php foreach($roles as $role): ?>
  296. <option value="<?php echo $role['id']; ?>"><?php echo strtoupper($role['name']); ?></option>
  297. <?php endforeach; ?>
  298. </select>
  299. </div>
  300. </div>
  301. <button type="submit" class="btn"><?php echo $t['btn_create']; ?></button>
  302. </form>
  303. </div>
  304. <!-- Λίστα Χρηστών -->
  305. <div class="card">
  306. <h3><?php echo $t['user_list']; ?></h3>
  307. <table>
  308. <thead>
  309. <tr>
  310. <th><?php echo $t['th_id']; ?></th>
  311. <th><?php echo $t['th_user']; ?></th>
  312. <th><?php echo $t['th_name']; ?></th>
  313. <th><?php echo $t['th_contact']; ?></th>
  314. <th><?php echo $t['th_role']; ?></th>
  315. <th><?php echo $t['th_actions']; ?></th>
  316. </tr>
  317. </thead>
  318. <tbody>
  319. <?php foreach($users as $user): ?>
  320. <tr>
  321. <td><strong>#<?php echo $user['id']; ?></strong></td>
  322. <td><?php echo htmlspecialchars($user['username']); ?></td>
  323. <td><?php echo htmlspecialchars($user['first_name'] . ' ' . $user['last_name']); ?></td>
  324. <td>
  325. <small style="color: var(--text-muted);">
  326. ✉️ <?php echo htmlspecialchars($user['email']); ?><br>
  327. 📞 <?php echo htmlspecialchars($user['phone']); ?>
  328. </small>
  329. </td>
  330. <td>
  331. <?php
  332. $badge_class = 'badge-user';
  333. if ($user['role_id'] == 1) $badge_class = 'badge-admin';
  334. if ($user['role_id'] == 2) $badge_class = 'badge-seller';
  335. ?>
  336. <span class="badge <?php echo $badge_class; ?>">
  337. <?php echo htmlspecialchars($user['role_name']); ?>
  338. </span>
  339. </td>
  340. <td>
  341. <?php if ($user['id'] != $_SESSION['user_id']): ?>
  342. <form method="POST" action="users.php" style="display: inline-block; margin-right: 5px;">
  343. <input type="hidden" name="action" value="change_role">
  344. <input type="hidden" name="user_id" value="<?php echo $user['id']; ?>">
  345. <select name="new_role_id" style="padding: 6px; border-radius: 4px; font-size: 12px; width: 100px;" onchange="this.form.submit()">
  346. <?php foreach($roles as $role): ?>
  347. <option value="<?php echo $role['id']; ?>" <?php echo ($role['id'] == $user['role_id']) ? 'selected' : ''; ?>>
  348. <?php echo ucfirst($role['name']); ?>
  349. </option>
  350. <?php endforeach; ?>
  351. </select>
  352. </form>
  353. <button type="button" class="btn-small btn-pass"
  354. onclick="openPasswordModal(<?php echo $user['id']; ?>, '<?php echo addslashes(htmlspecialchars($user['username'])); ?>')">
  355. <?php echo $t['btn_pass']; ?>
  356. </button>
  357. <form method="POST" action="users.php" style="display: inline-block;" onsubmit="return confirm('<?php echo $t['confirm_del'] . addslashes(htmlspecialchars($user['username'])); ?>;');">
  358. <input type="hidden" name="action" value="delete_user">
  359. <input type="hidden" name="user_id" value="<?php echo $user['id']; ?>">
  360. <button type="submit" class="btn-small btn-del"><?php echo $t['btn_del']; ?></button>
  361. </form>
  362. <?php else: ?>
  363. <span style="color: var(--text-muted); font-size: 12px; margin-right: 15px; font-style: italic;"><?php echo $t['your_account']; ?></span>
  364. <button type="button" class="btn-small btn-pass"
  365. onclick="openPasswordModal(<?php echo $user['id']; ?>, '<?php echo addslashes(htmlspecialchars($user['username'])); ?>')">
  366. <?php echo $t['btn_pass']; ?>
  367. </button>
  368. <?php endif; ?>
  369. </td>
  370. </tr>
  371. <?php endforeach; ?>
  372. </tbody>
  373. </table>
  374. </div>
  375. </div>
  376. <!-- Το Αναδυόμενο Παράθυρο (Modal) για την αλλαγή κωδικού -->
  377. <div id="passwordModal" class="modal">
  378. <div class="modal-content">
  379. <span class="close-btn" onclick="closePasswordModal()">&times;</span>
  380. <h3 style="margin-top: 0; color: var(--text-main); font-size: 18px; text-transform: uppercase;"><?php echo $t['change_pass_title']; ?></h3>
  381. <p style="color: var(--text-muted); font-size: 14px;"><?php echo $t['for_user']; ?> <strong id="modal-username-display" style="color: var(--primary);"></strong></p>
  382. <form method="POST" action="users.php">
  383. <input type="hidden" name="action" value="change_password">
  384. <input type="hidden" name="user_id" id="modal-user-id" value="">
  385. <div class="form-group" style="margin-top: 25px;">
  386. <label><?php echo $t['new_pass_label']; ?></label>
  387. <input type="password" name="new_password" required placeholder="••••••••">
  388. </div>
  389. <button type="submit" class="btn" style="width: 100%; margin-top: 10px;"><?php echo $t['btn_save_pass']; ?></button>
  390. </form>
  391. </div>
  392. </div>
  393. <script>
  394. function openPasswordModal(userId, username) {
  395. document.getElementById('modal-user-id').value = userId;
  396. document.getElementById('modal-username-display').innerText = username;
  397. document.getElementById('passwordModal').style.display = 'block';
  398. }
  399. function closePasswordModal() {
  400. document.getElementById('passwordModal').style.display = 'none';
  401. }
  402. window.onclick = function(event) {
  403. const modal = document.getElementById('passwordModal');
  404. if (event.target == modal) {
  405. closePasswordModal();
  406. }
  407. }
  408. </script>
  409. </body>
  410. </html>