<?php
session_start();
if (!isset($_SESSION['username']) || $_SESSION['username'] !== 'admin') {
    header("Location: /manage/index.php");
    exit;
}

require_once '../includes/db.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $customer_id = $_POST['customer_id'];
    $name = trim($_POST['name']);
    $email = trim($_POST['email']);
    $contact_number = trim($_POST['contact_number']);
    $address = trim($_POST['address']);
    $preferred_contact_method = $_POST['preferred_contact_method'];
    $customer_type = $_POST['customer_type'];
    $loyalty_points = $_POST['loyalty_points'];

    $stmt = $pdo->prepare("
        UPDATE customers 
        SET name = ?, email = ?, contact_number = ?, address = ?, preferred_contact_method = ?, customer_type = ?, loyalty_points = ? 
        WHERE customer_id = ?
    ");
    $stmt->execute([$name, $email, $contact_number, $address, $preferred_contact_method, $customer_type, $loyalty_points, $customer_id]);

    header("Location: customer_profile.php?customer_id=$customer_id");
    exit;
}
?>
