<?php
include 'includes/config.php';
session_start();

if (!isset($_SESSION['email'])) {
    header('location:login.php');
    exit();
}

// Initialize a variable to hold the success message
$successMessage = '';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Retrieve form data
    $contact_id = $_POST['contact_id'];
    $name = $_POST['name'];
    $email = $_POST['email'];
    $tax_number = $_POST['tax_number'];
    $opening_balance = $_POST['opening_balance'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $country = $_POST['country'];
    $landmark = $_POST['landmark'];
    $mobile = $_POST['mobile'];
   $created_at = $_POST['created_at'];


    // Prepare the SQL query, including the fixed value for the type column
    $sql = "INSERT INTO contacts (contact_id, name, email, tax_number, opening_balance, city, state, country, landmark, mobile, type, created_at)
            VALUES (:contact_id, :name, :email, :tax_number, :opening_balance, :city, :state, :country, :landmark, :mobile, 'supplier', :created_at)";

    // Prepare and execute the statement
    $stmt = $conn->prepare($sql);
    $stmt->execute([
        ':contact_id' => $contact_id,
        ':name' => $name,
        ':email' => $email,
        ':tax_number' => $tax_number,
        ':opening_balance' => $opening_balance,
        ':city' => $city,
        ':state' => $state,
        ':country' => $country,
        ':landmark' => $landmark,
        ':mobile' => $mobile,
         ':created_at' => $created_at,
    ]);

    // Set success message
    $successMessage = "New contact added successfully.";
}
?>


<!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">
    <title>Add Customers</title>
    <!-- Favicon -->
    <link rel="shortcut icon" href="images/favicon.ico" />
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <!-- Typography CSS -->
    <link rel="stylesheet" href="css/typography.css">
    <!-- Style CSS -->
    <link rel="stylesheet" href="css/style.css">
    <!-- Responsive CSS -->
    <link rel="stylesheet" href="css/responsive.css">
    <style>
    ion-icon {
        font-size: 20px;
        margin-bottom: -5px;
    }
    </style>
</head>

<body>
    <!-- loader Start -->
    <div id="loading">
        <div id="loading-center">
        </div>
    </div>
    <!-- loader END -->
    <!-- Wrapper Start -->
    <div class="wrapper">
        <!-- Sidebar  -->
        <?php 
            include 'includes/sidebar.php';
        ?>
        <!-- TOP Nav Bar -->
        <?php include 'includes/header.php';?>
        <!-- TOP Nav Bar END -->
        <!-- Page Content  -->
        <div id="content-page" class="content-page">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="iq-card">
                            <div class="iq-card-header d-flex justify-content-between row">
                                <div class="iq-header-title col-lg-6">
                                    <h4 class="card-title"><a href="list_supliers.php">Suppliers</a> > Add Supplier
                                    </h4>
                                </div>
                            </div>
                            <div class="iq-card-body" style="overflow:auto;">
                                <?php if ($successMessage): ?>
                                <div class="alert alert-success" role="alert">
                                    <?php echo htmlspecialchars($successMessage); ?>
                                </div>
                                <?php endif; ?>
                                <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                                    <div class="row">
                                        <!-- Contact ID -->
                                        <div class="col-lg-3"style="display:none">
                                            <div class="form-group">
                                                <label for="contact_id" class="label-control">Contact ID:</label>
                                                <input type="text" class="form-control" name="contact_id"
                                                    placeholder="Contact ID" id="contact_id">
                                            </div>
                                        </div>
 <div class="col-lg-3">
                                            <div class="form-group">
                                                <label for="name" class="label-control">Date:*</label>
                                                <input type="date" class="form-control" name="created_at"
                                                    placeholder="Enter Name" id="name" required>
                                            </div>
                                        </div>
                                        <!-- Name (Required) -->
                                        <div class="col-lg-3">
                                            <div class="form-group">
                                                <label for="name" class="label-control">Name:*</label>
                                                <input type="text" class="form-control" name="name"
                                                    placeholder="Enter Name" id="name" required>
                                            </div>
                                        </div>

                                        <!-- Mobile (Required) -->
                                        <div class="col-lg-3">
                                            <div class="form-group">
                                                <label for="mobile" class="label-control">Mobile:*</label>
                                                <input type="text" class="form-control" name="mobile"
                                                    placeholder="Mobile Number" id="mobile" required>
                                            </div>
                                        </div>

                                        <!-- Email -->
                                        <div class="col-lg-3">
                                            <div class="form-group">
                                                <label for="email" class="label-control">Email:</label>
                                                <input type="email" class="form-control" name="email"
                                                    placeholder="Email" id="email">
                                            </div>
                                        </div>

                                       
                                        <div class="col-lg-3"style="display:none">
                                            <div class="form-group">
                                                <label for="tax_number" class="label-control">Tax Number:</label>
                                                <input type="text" class="form-control" name="tax_number"
                                                    placeholder="Tax Number" id="tax_number">
                                            </div>
                                        </div>

                                        <!-- Opening Balance -->
                                        <div class="col-lg-3">
                                            <div class="form-group">
                                                <label for="opening_balance" class="label-control">Opening
                                                    Balance:</label>
                                                <input type="number" class="form-control" name="opening_balance"
                                                    placeholder="0" id="opening_balance" step="0.01">
                                            </div>
                                        </div>

                                        <!-- Address -->
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label for="landmark" class="label-control">Address:</label>
                                                <input type="text" class="form-control" name="landmark"
                                                    placeholder="Enter Address" id="landmark">
                                            </div>
                                        </div>

                                        <!-- City -->
                                        <div class="col-lg-3" style="display:none">
                                            <div class="form-group">
                                                <label for="city" class="label-control">City:</label>
                                                <input type="text" class="form-control" name="city" placeholder="City"
                                                    id="city">
                                            </div>
                                        </div>

                                        
                                        <div class="col-lg-3"style="display:none">
                                            <div class="form-group">
                                                <label for="state" class="label-control">State:</label>
                                                <input type="text" class="form-control" name="state" placeholder="State"
                                                    id="state">
                                            </div>
                                        </div>

                                      
                                        <div class="col-lg-3"style="display:none">
                                            <div class="form-group">
                                                <label for="country" class="label-control">Country:</label>
                                                <input type="text" class="form-control" name="country"
                                                    placeholder="Country" id="country">
                                            </div>
                                        </div>

                                        <!-- Submit Button -->
                                        <div class="col-lg-12">
                                            <button class="btn btn-primary">Submit</button>
                                        </div>
                                    </div>
                                </form>

                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    </div>
    <!-- Wrapper END -->
    <!-- Footer -->
    <footer class="iq-footer">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-6">
                    <ul class="list-inline mb-0">
                        <li class="list-inline-item"><a href="privacy-policy.html">Privacy Policy</a></li>
                        <li class="list-inline-item"><a href="terms-of-service.html">Terms of Use</a></li>
                    </ul>
                </div>
                <div class="col-lg-6 text-right">
                    Copyright <span id="copyright">
                        <script>
                        document.getElementById('copyright').appendChild(document.createTextNode(new Date()
                            .getFullYear()))
                        </script>
                    </span> <a href="#">Vito</a> All Rights Reserved.
                </div>
            </div>
        </div>
    </footer>
    <nav class="iq-float-menu">
        <input type="checkbox" href="#" class="iq-float-menu-open" name="menu-open" id="menu-open" />
        <label class="iq-float-menu-open-button" for="menu-open">
            <span class="lines line-1"></span>
            <span class="lines line-2"></span>
            <span class="lines line-3"></span>
        </label>
        <button class="iq-float-menu-item bg-info" data-toggle="tooltip" data-placement="top" title="Direction Mode"
            data-mode="rtl"><i class="ri-text-direction-r"></i></button>
        <button class="iq-float-menu-item bg-danger" data-toggle="tooltip" data-placement="top" title="Color Mode"
            id="dark-mode" data-active="true"><i class="ri-sun-line"></i></button>
        <button class="iq-float-menu-item bg-warning" data-toggle="tooltip" data-placement="top" title="Comming Soon"><i
                class="ri-palette-line"></i></button>
    </nav>
    <!-- Footer END -->
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="js/jquery.min.js"></script>
    <!-- Rtl and Darkmode -->
    <script src="js/rtl.js"></script>
    <script src="js/customizer.js"></script>
    <script src="js/popper.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- Appear JavaScript -->
    <script src="js/jquery.appear.js"></script>
    <!-- Countdown JavaScript -->
    <script src="js/countdown.min.js"></script>
    <!-- Counterup JavaScript -->
    <script src="js/waypoints.min.js"></script>
    <script src="js/jquery.counterup.min.js"></script>
    <!-- Wow JavaScript -->
    <script src="js/wow.min.js"></script>
    <!-- Apexcharts JavaScript -->
    <script src="js/apexcharts.js"></script>
    <!-- Slick JavaScript -->
    <script src="js/slick.min.js"></script>
    <!-- Select2 JavaScript -->
    <script src="js/select2.min.js"></script>
    <!-- Owl Carousel JavaScript -->
    <script src="js/owl.carousel.min.js"></script>
    <!-- Magnific Popup JavaScript -->
    <script src="js/jquery.magnific-popup.min.js"></script>
    <!-- Smooth Scrollbar JavaScript -->
    <script src="js/smooth-scrollbar.js"></script>
    <!-- lottie JavaScript -->
    <script src="js/lottie.js"></script>
    <!-- Chart Custom JavaScript -->
    <script src="js/chart-custom.js"></script>
    <!-- Custom JavaScript -->
    <script src="js/custom.js"></script>
</body>

</html>