<?php
     session_start();
      include 'database/shikanisha.kts.php';
        if(!($_SESSION['type'] == 'Cashier' || $_SESSION['type'] == 'Accountant'  || $_SESSION['type'] == 'Manager')){
            header("location:logout.php");
}


?>
<!DOCTYPE html>
<html lang="en">

<head>
    <!-- Required meta tags-->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="Colorlib Templates">
    <meta name="author" content="Colorlib">
    <meta name="keywords" content="Colorlib Templates">

    <!-- Title Page-->
    <title>THE FARM</title>

    <!-- Icons font CSS-->
    <link href="./logs/vendor/mdi-font/css/material-design-iconic-font.min.css" rel="stylesheet" media="all">
    <link href="./logs/vendor/font-awesome-4.7/css/font-awesome.min.css" rel="stylesheet" media="all">
    <!-- Font special for pages-->
    <link href="https://fonts.googleapis.com/css?family=Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">

    <!-- Vendor CSS-->
    <link href="./logs/vendor/select2/select2.min.css" rel="stylesheet" media="all">
    <link href="./logs/vendor/datepicker/daterangepicker.css" rel="stylesheet" media="all">

    <!-- Main CSS-->
    <link href="./logs/css/main.css" rel="stylesheet" media="all">
    <!-- Include SweetAlert CSS and JS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@10">

</head>

<body>
    <div class="page-wrapper bg-gra-01 p-t-180 p-b-100 font-poppins">
        <div class="wrapper wrapper--w780">
            <div class="card card-3">
                <div class="card-heading"></div>
                <div class="card-body">
                    <h2 class="title">Customer Registration Info</h2>
                    <form id="reg_customer">
                        <div class="input-group">
                            <input class="input--style-3" type="text" placeholder="Full Name" name="fullname" id="fullname">
                        </div>
                        <div class="input-group">
                            <input class="input--style-3" type="text" placeholder="Location/Shop Name" name="shop" id="shop">
                        </div>
                        <div class="input-group">
                            <input class="input--style-3" type="text" placeholder="Phone" name="phone" id="shop">
                        </div>
                        <div class="p-t-10">
                            <button class="btn btn--pill btn--green" type="submit">Submit</button>
                          <a href="index.php"><button class="btn btn--pill btn--red"  type="button" href="index.php">Close</button></a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!-- Jquery JS-->
    <script src="./logs/vendor/jquery/jquery.min.js"></script>
    <!-- Vendor JS-->
    <script src="./logs/vendor/select2/select2.min.js"></script>
    <script src="./logs/vendor/datepicker/moment.min.js"></script>
    <script src="./logs/vendor/datepicker/daterangepicker.js"></script>

    <!-- Main JS-->
    <script src="./logs/js/global.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>

    <script>
    $(document).ready(function() {
        // Add event listener to form submit button
        $('#reg_customer').on('submit', function(event) {
            event.preventDefault(); // Prevent default form submission behavior

            // Serialize form data
            var formData = $(this).serialize();

            // Send AJAX request to server
            $.ajax({
                url: './database/addclient.kts.php', // PHP script to handle the request
                type: 'POST',
                data: formData,
                success: function(response) {
                    // Parse the response as JSON
                    try {
                        response = JSON.parse(response);
                    } catch (e) {
                        console.error('Error parsing JSON response:', e);
                    }

                    // Display SweetAlert based on the response
                    if (response.success) {
                        Swal.fire({
                            icon: 'success',
                            title: 'Success',
                            text: response.message,
                        });
                        // Clear the form input fields
                        $('#reg_customer')[0].reset();
                    } else {
                        Swal.fire({
                            icon: 'error',
                            title: 'Error',
                            text: response.message,
                        });
                    }
                },
                error: function(xhr, status, error) {
                    // Handle errors
                    console.log(xhr.responseText);
                    Swal.fire({
                        icon: 'error',
                        title: 'Oops...',
                        text: 'Something went wrong!',
                    });
                }
            });
        });
    });
</script>

</body><!-- This templates was made by Colorlib (https://colorlib.com) -->

</html>
<!-- end document-->