<?php
// Include your database connection
include('../config/db.php');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $pharmacy_name = $_POST['pharmacy_name'];
    $pharmacy_address = $_POST['pharmacy_address'];
    $pharmacy_phone = $_POST['pharmacy_phone'];
    $pharmacy_email = $_POST['pharmacy_email'];
    $pharmacy_logo = $_FILES['pharmacy_logo']['name'];
    $pharmacy_description = $_POST['pharmacy_description'];
    
    // Handle the logo upload
    if ($pharmacy_logo) {
        $target_dir = "uploads/";
        $target_file = $target_dir . basename($pharmacy_logo);
        move_uploaded_file($_FILES['pharmacy_logo']['tmp_name'], $target_file);
    }

    $stmt = $pdo->prepare("UPDATE settings SET pharmacy_name = ?, pharmacy_address = ?, pharmacy_phone = ?, pharmacy_email = ?, pharmacy_logo = ?, pharmacy_description = ?, updated_at = NOW() WHERE id = 1");
    $stmt->execute([$pharmacy_name, $pharmacy_address, $pharmacy_phone, $pharmacy_email, $pharmacy_logo, $pharmacy_description]);

    // Redirect or show success message
    header("Location: settings.php?updated=1");
}
?>
