edit_order.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. // Αρχείο: /var/www/html/hockey-cms/admin/edit_order.php
  3. require_once 'admin_auth.php';
  4. require_once '../config/database.php';
  5. session_start();
  6. if (!isset($_SESSION['user_id'])) {
  7. header("Location: login.php");
  8. exit;
  9. }
  10. // --- Μηχανισμός Αλλαγής Γλώσσας ---
  11. if (isset($_GET['lang']) && in_array($_GET['lang'], ['el', 'en'])) {
  12. $_SESSION['lang'] = $_GET['lang'];
  13. }
  14. $current_lang = $_SESSION['lang'] ?? 'el';
  15. $translations = [
  16. 'el' => [
  17. 'page_title' => 'Επεξεργασία Παραγγελίας',
  18. 'customer_name' => 'Ονοματεπώνυμο Πελάτη *',
  19. 'email' => 'Email *',
  20. 'phone' => 'Τηλέφωνο *',
  21. 'status' => 'Κατάσταση Παραγγελίας',
  22. 'status_pending' => 'Εκκρεμεί',
  23. 'status_completed' => 'Ολοκληρώθηκε',
  24. 'status_cancelled' => 'Απορρίφθηκε',
  25. 'address' => 'Διεύθυνση / Πόλη',
  26. 'products_title' => 'Προϊόντα Παραγγελίας',
  27. 'prod_col' => 'Προϊόν',
  28. 'price_col' => 'Τιμή Μονάδας',
  29. 'qty_col' => 'Ποσότητα',
  30. 'total_col' => 'Σύνολο',
  31. 'grand_total' => 'Συνολικό Ποσό:',
  32. 'btn_save' => 'Αποθήκευση Αλλαγών',
  33. 'btn_back' => 'Επιστροφή στη Λίστα',
  34. 'msg_ok' => 'Η παραγγελία ενημερώθηκε επιτυχώς!',
  35. 'msg_err' => 'Παρακαλώ συμπληρώστε τα υποχρεωτικά πεδία.'
  36. ],
  37. 'en' => [
  38. 'page_title' => 'Edit Order',
  39. 'customer_name' => 'Customer Name *',
  40. 'email' => 'Email *',
  41. 'phone' => 'Phone *',
  42. 'status' => 'Order Status',
  43. 'status_pending' => 'Pending',
  44. 'status_completed' => 'Completed',
  45. 'status_cancelled' => 'Cancelled',
  46. 'address' => 'Address / City',
  47. 'products_title' => 'Order Products',
  48. 'prod_col' => 'Product',
  49. 'price_col' => 'Unit Price',
  50. 'qty_col' => 'Quantity',
  51. 'total_col' => 'Total',
  52. 'grand_total' => 'Grand Total:',
  53. 'btn_save' => 'Save Changes',
  54. 'btn_back' => 'Back to List',
  55. 'msg_ok' => 'Order updated successfully!',
  56. 'msg_err' => 'Please fill in required fields.'
  57. ]
  58. ];
  59. $t = $translations[$current_lang];
  60. header('Content-Type: text/html; charset=utf-8');
  61. $message = '';
  62. $order_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
  63. if ($order_id === 0) {
  64. header("Location: orders.php");
  65. exit;
  66. }
  67. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  68. $customer_name = trim($_POST['customer_name']);
  69. $customer_email = trim($_POST['customer_email']);
  70. $customer_phone = trim($_POST['customer_phone']);
  71. $shipping_address = trim($_POST['shipping_address']);
  72. $status = $_POST['status'];
  73. if (!empty($customer_name) && !empty($customer_email) && !empty($customer_phone)) {
  74. try {
  75. $stmt = $pdo->prepare("UPDATE orders SET customer_name = ?, customer_email = ?, customer_phone = ?, shipping_address = ?, status = ? WHERE id = ?");
  76. $stmt->execute([$customer_name, $customer_email, $customer_phone, $shipping_address, $status, $order_id]);
  77. $message = "<div class='alert success'>{$t['msg_ok']}</div>";
  78. } catch (Exception $e) {
  79. $message = "<div class='alert error'>Σφάλμα: " . $e->getMessage() . "</div>";
  80. }
  81. } else {
  82. $message = "<div class='alert error'>{$t['msg_err']}</div>";
  83. }
  84. }
  85. $stmt = $pdo->prepare("SELECT * FROM orders WHERE id = ?");
  86. $stmt->execute([$order_id]);
  87. $order = $stmt->fetch(PDO::FETCH_ASSOC);
  88. if (!$order) {
  89. die("Order not found.");
  90. }
  91. $itemsStmt = $pdo->prepare("
  92. SELECT oi.*, p.title
  93. FROM order_items oi
  94. JOIN products p ON oi.product_id = p.id
  95. WHERE oi.order_id = ?
  96. ");
  97. $itemsStmt->execute([$order_id]);
  98. $items = $itemsStmt->fetchAll(PDO::FETCH_ASSOC);
  99. ?>
  100. <!DOCTYPE html>
  101. <html lang="<?php echo $current_lang; ?>">
  102. <head>
  103. <meta charset="UTF-8">
  104. <title><?php echo $t['page_title']; ?> #<?php echo $order['id']; ?> - Hockey CMS</title>
  105. <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
  106. <style>
  107. :root {
  108. --primary: #f97316;
  109. --primary-hover: #ea580c;
  110. --bg-color: #0b1120;
  111. --panel-bg: #1e293b;
  112. --border-color: #334155;
  113. --text-main: #f8fafc;
  114. --text-muted: #94a3b8;
  115. }
  116. body { font-family: 'Inter', sans-serif; background-color: var(--bg-color); color: var(--text-main); margin: 0; }
  117. .content { margin-left: 250px; padding: 30px; }
  118. .content h2 { margin-top: 0; color: var(--primary); font-size: 26px; text-transform: uppercase; letter-spacing: 0.5px; }
  119. .card { background: var(--panel-bg); padding: 30px; border-radius: 8px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3); border: 1px solid var(--border-color); margin-bottom: 20px; }
  120. .form-group { margin-bottom: 20px; }
  121. .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;}
  122. .form-group input, .form-group select, .form-group textarea { 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; }
  123. .form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.2); }
  124. .btn { padding: 12px 25px; background: var(--primary); color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 800; text-transform: uppercase; transition: 0.2s;}
  125. .btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
  126. .btn-secondary { background: rgba(255,255,255,0.05); text-decoration: none; display: inline-block; padding: 12px 25px; color: var(--text-main); border-radius: 6px; font-weight: 700; border: 1px solid var(--border-color); text-transform: uppercase; transition: 0.2s;}
  127. .btn-secondary:hover { background: rgba(255,255,255,0.1); }
  128. .alert { padding: 15px; border-radius: 6px; margin-bottom: 20px; font-weight: 600; font-size: 14px;}
  129. .success { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.2); }
  130. .error { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2); }
  131. table { width: 100%; border-collapse: collapse; margin-top: 10px; }
  132. table th, table td { padding: 15px; border-bottom: 1px solid rgba(255,255,255,0.05); text-align: left; }
  133. table th { background: rgba(0,0,0,0.2); color: var(--text-muted); text-transform: uppercase; font-size: 13px; font-weight: 700; }
  134. table td { color: var(--text-main); font-size: 14px; }
  135. </style>
  136. </head>
  137. <body>
  138. <?php include 'sidebar.php'; ?>
  139. <div class="content">
  140. <h2><?php echo $t['page_title']; ?> #<?php echo $order['id']; ?></h2>
  141. <?php echo $message; ?>
  142. <div class="card">
  143. <form method="POST">
  144. <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
  145. <div class="form-group">
  146. <label><?php echo $t['customer_name']; ?></label>
  147. <input type="text" name="customer_name" value="<?php echo htmlspecialchars($order['customer_name']); ?>" required>
  148. </div>
  149. <div class="form-group">
  150. <label><?php echo $t['email']; ?></label>
  151. <input type="email" name="customer_email" value="<?php echo htmlspecialchars($order['customer_email']); ?>" required>
  152. </div>
  153. </div>
  154. <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
  155. <div class="form-group">
  156. <label><?php echo $t['phone']; ?></label>
  157. <input type="text" name="customer_phone" value="<?php echo htmlspecialchars($order['customer_phone']); ?>" required>
  158. </div>
  159. <div class="form-group">
  160. <label><?php echo $t['status']; ?></label>
  161. <select name="status">
  162. <option value="pending" <?php echo $order['status'] == 'pending' ? 'selected' : ''; ?>><?php echo $t['status_pending']; ?></option>
  163. <option value="completed" <?php echo $order['status'] == 'completed' ? 'selected' : ''; ?>><?php echo $t['status_completed']; ?></option>
  164. <option value="cancelled" <?php echo $order['status'] == 'cancelled' ? 'selected' : ''; ?>><?php echo $t['status_cancelled']; ?></option>
  165. </select>
  166. </div>
  167. </div>
  168. <div class="form-group">
  169. <label><?php echo $t['address']; ?></label>
  170. <textarea name="shipping_address" rows="3"><?php echo htmlspecialchars($order['shipping_address']); ?></textarea>
  171. </div>
  172. <h3 style="margin-top: 30px; color: var(--text-main); font-size: 18px; text-transform: uppercase;"><?php echo $t['products_title']; ?></h3>
  173. <table>
  174. <thead>
  175. <tr>
  176. <th><?php echo $t['prod_col']; ?></th>
  177. <th><?php echo $t['price_col']; ?></th>
  178. <th><?php echo $t['qty_col']; ?></th>
  179. <th><?php echo $t['total_col']; ?></th>
  180. </tr>
  181. </thead>
  182. <tbody>
  183. <?php foreach ($items as $item): ?>
  184. <tr>
  185. <td><strong><?php echo htmlspecialchars($item['title']); ?></strong></td>
  186. <td><?php echo number_format($item['price'], 2, ',', '.'); ?> €</td>
  187. <td><?php echo $item['quantity']; ?></td>
  188. <td><strong><?php echo number_format($item['price'] * $item['quantity'], 2, ',', '.'); ?> €</strong></td>
  189. </tr>
  190. <?php endforeach; ?>
  191. </tbody>
  192. </table>
  193. <p style="text-align: right; font-size: 1.2em; margin-top: 20px; color: var(--text-muted);">
  194. <?php echo $t['grand_total']; ?> <strong style="color: #10b981;"><?php echo number_format($order['total_amount'], 2, ',', '.'); ?> €</strong>
  195. </p>
  196. <div style="margin-top: 25px; display: flex; gap: 10px;">
  197. <button type="submit" class="btn"><?php echo $t['btn_save']; ?></button>
  198. <a href="orders.php" class="btn-secondary"><?php echo $t['btn_back']; ?></a>
  199. </div>
  200. </form>
  201. </div>
  202. </div>
  203. </body>
  204. </html>