| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- <?php
- // Αρχείο: /var/www/html/hockey-cms/admin/edit_order.php
- require_once 'admin_auth.php';
- require_once '../config/database.php';
- session_start();
- if (!isset($_SESSION['user_id'])) {
- header("Location: login.php");
- exit;
- }
- // --- Μηχανισμός Αλλαγής Γλώσσας ---
- if (isset($_GET['lang']) && in_array($_GET['lang'], ['el', 'en'])) {
- $_SESSION['lang'] = $_GET['lang'];
- }
- $current_lang = $_SESSION['lang'] ?? 'el';
- $translations = [
- 'el' => [
- 'page_title' => 'Επεξεργασία Παραγγελίας',
- 'customer_name' => 'Ονοματεπώνυμο Πελάτη *',
- 'email' => 'Email *',
- 'phone' => 'Τηλέφωνο *',
- 'status' => 'Κατάσταση Παραγγελίας',
- 'status_pending' => 'Εκκρεμεί',
- 'status_completed' => 'Ολοκληρώθηκε',
- 'status_cancelled' => 'Απορρίφθηκε',
- 'address' => 'Διεύθυνση / Πόλη',
- 'products_title' => 'Προϊόντα Παραγγελίας',
- 'prod_col' => 'Προϊόν',
- 'price_col' => 'Τιμή Μονάδας',
- 'qty_col' => 'Ποσότητα',
- 'total_col' => 'Σύνολο',
- 'grand_total' => 'Συνολικό Ποσό:',
- 'btn_save' => 'Αποθήκευση Αλλαγών',
- 'btn_back' => 'Επιστροφή στη Λίστα',
- 'msg_ok' => 'Η παραγγελία ενημερώθηκε επιτυχώς!',
- 'msg_err' => 'Παρακαλώ συμπληρώστε τα υποχρεωτικά πεδία.'
- ],
- 'en' => [
- 'page_title' => 'Edit Order',
- 'customer_name' => 'Customer Name *',
- 'email' => 'Email *',
- 'phone' => 'Phone *',
- 'status' => 'Order Status',
- 'status_pending' => 'Pending',
- 'status_completed' => 'Completed',
- 'status_cancelled' => 'Cancelled',
- 'address' => 'Address / City',
- 'products_title' => 'Order Products',
- 'prod_col' => 'Product',
- 'price_col' => 'Unit Price',
- 'qty_col' => 'Quantity',
- 'total_col' => 'Total',
- 'grand_total' => 'Grand Total:',
- 'btn_save' => 'Save Changes',
- 'btn_back' => 'Back to List',
- 'msg_ok' => 'Order updated successfully!',
- 'msg_err' => 'Please fill in required fields.'
- ]
- ];
- $t = $translations[$current_lang];
- header('Content-Type: text/html; charset=utf-8');
- $message = '';
- $order_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
- if ($order_id === 0) {
- header("Location: orders.php");
- exit;
- }
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- $customer_name = trim($_POST['customer_name']);
- $customer_email = trim($_POST['customer_email']);
- $customer_phone = trim($_POST['customer_phone']);
- $shipping_address = trim($_POST['shipping_address']);
- $status = $_POST['status'];
- if (!empty($customer_name) && !empty($customer_email) && !empty($customer_phone)) {
- try {
- $stmt = $pdo->prepare("UPDATE orders SET customer_name = ?, customer_email = ?, customer_phone = ?, shipping_address = ?, status = ? WHERE id = ?");
- $stmt->execute([$customer_name, $customer_email, $customer_phone, $shipping_address, $status, $order_id]);
- $message = "<div class='alert success'>{$t['msg_ok']}</div>";
- } catch (Exception $e) {
- $message = "<div class='alert error'>Σφάλμα: " . $e->getMessage() . "</div>";
- }
- } else {
- $message = "<div class='alert error'>{$t['msg_err']}</div>";
- }
- }
- $stmt = $pdo->prepare("SELECT * FROM orders WHERE id = ?");
- $stmt->execute([$order_id]);
- $order = $stmt->fetch(PDO::FETCH_ASSOC);
- if (!$order) {
- die("Order not found.");
- }
- $itemsStmt = $pdo->prepare("
- SELECT oi.*, p.title
- FROM order_items oi
- JOIN products p ON oi.product_id = p.id
- WHERE oi.order_id = ?
- ");
- $itemsStmt->execute([$order_id]);
- $items = $itemsStmt->fetchAll(PDO::FETCH_ASSOC);
- ?>
- <!DOCTYPE html>
- <html lang="<?php echo $current_lang; ?>">
- <head>
- <meta charset="UTF-8">
- <title><?php echo $t['page_title']; ?> #<?php echo $order['id']; ?> - Hockey CMS</title>
- <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
- <style>
- :root {
- --primary: #f97316;
- --primary-hover: #ea580c;
- --bg-color: #0b1120;
- --panel-bg: #1e293b;
- --border-color: #334155;
- --text-main: #f8fafc;
- --text-muted: #94a3b8;
- }
- body { font-family: 'Inter', sans-serif; background-color: var(--bg-color); color: var(--text-main); margin: 0; }
- .content { margin-left: 250px; padding: 30px; }
- .content h2 { margin-top: 0; color: var(--primary); font-size: 26px; text-transform: uppercase; letter-spacing: 0.5px; }
-
- .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; }
- .form-group { margin-bottom: 20px; }
- .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;}
- .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; }
- .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); }
-
- .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;}
- .btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
- .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;}
- .btn-secondary:hover { background: rgba(255,255,255,0.1); }
-
- .alert { padding: 15px; border-radius: 6px; margin-bottom: 20px; font-weight: 600; font-size: 14px;}
- .success { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.2); }
- .error { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2); }
-
- table { width: 100%; border-collapse: collapse; margin-top: 10px; }
- table th, table td { padding: 15px; border-bottom: 1px solid rgba(255,255,255,0.05); text-align: left; }
- table th { background: rgba(0,0,0,0.2); color: var(--text-muted); text-transform: uppercase; font-size: 13px; font-weight: 700; }
- table td { color: var(--text-main); font-size: 14px; }
- </style>
- </head>
- <body>
- <?php include 'sidebar.php'; ?>
- <div class="content">
- <h2><?php echo $t['page_title']; ?> #<?php echo $order['id']; ?></h2>
- <?php echo $message; ?>
- <div class="card">
- <form method="POST">
- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
- <div class="form-group">
- <label><?php echo $t['customer_name']; ?></label>
- <input type="text" name="customer_name" value="<?php echo htmlspecialchars($order['customer_name']); ?>" required>
- </div>
- <div class="form-group">
- <label><?php echo $t['email']; ?></label>
- <input type="email" name="customer_email" value="<?php echo htmlspecialchars($order['customer_email']); ?>" required>
- </div>
- </div>
- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
- <div class="form-group">
- <label><?php echo $t['phone']; ?></label>
- <input type="text" name="customer_phone" value="<?php echo htmlspecialchars($order['customer_phone']); ?>" required>
- </div>
- <div class="form-group">
- <label><?php echo $t['status']; ?></label>
- <select name="status">
- <option value="pending" <?php echo $order['status'] == 'pending' ? 'selected' : ''; ?>><?php echo $t['status_pending']; ?></option>
- <option value="completed" <?php echo $order['status'] == 'completed' ? 'selected' : ''; ?>><?php echo $t['status_completed']; ?></option>
- <option value="cancelled" <?php echo $order['status'] == 'cancelled' ? 'selected' : ''; ?>><?php echo $t['status_cancelled']; ?></option>
- </select>
- </div>
- </div>
- <div class="form-group">
- <label><?php echo $t['address']; ?></label>
- <textarea name="shipping_address" rows="3"><?php echo htmlspecialchars($order['shipping_address']); ?></textarea>
- </div>
- <h3 style="margin-top: 30px; color: var(--text-main); font-size: 18px; text-transform: uppercase;"><?php echo $t['products_title']; ?></h3>
- <table>
- <thead>
- <tr>
- <th><?php echo $t['prod_col']; ?></th>
- <th><?php echo $t['price_col']; ?></th>
- <th><?php echo $t['qty_col']; ?></th>
- <th><?php echo $t['total_col']; ?></th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ($items as $item): ?>
- <tr>
- <td><strong><?php echo htmlspecialchars($item['title']); ?></strong></td>
- <td><?php echo number_format($item['price'], 2, ',', '.'); ?> €</td>
- <td><?php echo $item['quantity']; ?></td>
- <td><strong><?php echo number_format($item['price'] * $item['quantity'], 2, ',', '.'); ?> €</strong></td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <p style="text-align: right; font-size: 1.2em; margin-top: 20px; color: var(--text-muted);">
- <?php echo $t['grand_total']; ?> <strong style="color: #10b981;"><?php echo number_format($order['total_amount'], 2, ',', '.'); ?> €</strong>
- </p>
- <div style="margin-top: 25px; display: flex; gap: 10px;">
- <button type="submit" class="btn"><?php echo $t['btn_save']; ?></button>
- <a href="orders.php" class="btn-secondary"><?php echo $t['btn_back']; ?></a>
- </div>
- </form>
- </div>
- </div>
- </body>
- </html>
|