<?php
include('../include/auth.php');
include('../include/lskfjwfe.php'); // Database connectivity file

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
   $category_id = intval($_POST['category_id']);
$category_name = mysqli_real_escape_string($db2, $_POST['category_name']);
$category_alias = mysqli_real_escape_string($db2, $_POST['category_alias']);
$category_description = mysqli_real_escape_string($db2, $_POST['category_description']);
$category_type = mysqli_real_escape_string($db2, $_POST['category_type']);

$sql = "UPDATE jostj_vikrentcar_categories 
        SET name = '$category_name',
            alias = '$category_alias',
            descr = '$category_description',
            type = '$category_type'
        WHERE id = $category_id";


    if (mysqli_query($db2, $sql)) {
        // Log the action
        $action = "Edit Category";
        $details = "Edited category $category_id, $category_name";
        $log_query = "INSERT INTO action_logs (action, details, user) VALUES ('$action', '$details', '$user')";
        mysqli_query($db2, $log_query);

        echo "<script>
            alert('Category updated successfully.');
            window.location.href = '../categories.php';
        </script>";
    } else {
        echo "<script>
            alert('Error updating category: " . mysqli_error($db2) . "');
            window.location.href = '../categories.php';
        </script>";
    }
}
?>
