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

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
   $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 = "INSERT INTO jostj_vikrentcar_categories (name, alias, descr, type) 
        VALUES ('$category_name', '$category_alias', '$category_description', '$category_type')";


    if (mysqli_query($db2, $sql)) {
        // Log the action
        $action = "Add New Category";
        $details = "Added new category: $category_name ($category_type)";
        $log_query = "INSERT INTO action_logs (action, details, user) VALUES ('$action', '$details', '$user')";
        mysqli_query($db2, $log_query);

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