<?php
require("header.php");
?>
<style>
    .btn-group>.btn:not(:last-child):not(.dropdown-toggle) {
        background: black;
    }

    .btn-group>.btn-group:not(:first-child)>.btn {
        background: black;
    }

    .page-item.active .page-link {
        background: black;
    }

    .dt-button-collection .dropdown-menu .buttons-columnVisibility {
        background-color: black;
    }
</style>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <!-- <h1>Add Product</h1> -->
                </div>
                <div class="col-sm-6">

                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="row">

                <div class="col-md-12">
                    <!-- general form elements -->
                    <div class="card card-secondary">
                        <div class="card-header" style="background-color: black;">
                            <h3 class="card-title">Add Product</h3>
                            <ol class="breadcrumb float-sm-right" style="background-color: black;">
                                <li class="breadcrumb-item"><a href="#">Home</a></li>
                                <li class="breadcrumb-item active">Add Product</li>
                            </ol>
                        </div>
                        <!-- /.card-header -->
                        <!-- form start -->

                        <div class="card-body">
                            <form action="add_product_code.php" method="post" enctype="multipart/form-data">

                                <div class="row">


                                    <div class="col-sm-6">
                                        <!-- text input -->
                                        <div class="form-group">
                                            <label>Product Name<span style="color:red; font-size:25px;">*</span></label>
                                            <select class="form-control" name="product_name" required>
                                                <?php
                                                include('connection.php');
                                                $sql0 = "SELECT * FROM add_catalouge ";
                                                $res1 = mysqli_query($conn, $sql0);
                                                while ($row = mysqli_fetch_assoc($res1)) {
                                                ?>
                                                    <option><?php echo $row['title']; ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-sm-6">
                                        <!-- select -->
                                        <div class="form-group">
                                            <label>Select Salt <span style="color:red; font-size:25px;">*</span></label>
                                            <select class="form-control" name="salt" required>
                                                <?php
                                                include('connection.php');
                                                $sql1 = "SELECT * FROM salt WHERE status='1' ORDER BY salt_name";
                                                $res1 = mysqli_query($conn, $sql1);
                                                while ($row = mysqli_fetch_assoc($res1)) {
                                                ?>
                                                    <option><?php echo $row['salt_name']; ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <!-- input states -->
                                <div class="row">
                                    <div class="col-sm-6">
                                        <div class="form-group">
                                            <label>Select Origin <span style="color:red; font-size:25px;">*</span></label>
                                            <select class="form-control" name="origin" required>
                                                <?php
                                                $sql1 = "SELECT * FROM origin WHERE status='1' ORDER BY origin_name";
                                                $res1 = mysqli_query($conn, $sql1);
                                                while ($row = mysqli_fetch_assoc($res1)) {
                                                ?>
                                                    <option><?php echo $row['origin_name']; ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="form-group">
                                            <label>Quantity <span style="color:red; font-size:25px;">*</span></label>
                                            <select class="form-control" name="quantity" required>
                                                <?php
                                                $sql1 = "SELECT * FROM quantity WHERE status='1' ORDER BY quantity";
                                                $res1 = mysqli_query($conn, $sql1);
                                                while ($row = mysqli_fetch_assoc($res1)) {
                                                ?>
                                                    <option><?php echo $row['quantity']; ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-sm-6">
                                        <label>Product price <span style="color:red; font-size:25px;">*</span></label>
                                        <div class="input-group">
                                            <div class="input-group-prepend"></div>
                                            <input type="text" class="form-control" name="price" required>
                                        </div>
                                    </div>
                                </div>
                                <BR>

                                <div class="row">
                                    <div class="col-sm-12">
                                        <button type="submit" class="btn btn-dark btn-lg btn-block" style="font-size: 15px;height: 35px; background:black" name="submit">Add</button>
                                    </div>
                                </div>

                            </form>
                        </div>

                    </div>

                    <div class="card  card-secondary">

                        <!-- /.card-header -->
                        <div class="card-body">
                            <table id="example1" class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>Sr.no</th>
                                        <th>Date Time</th>
                                        <th>Salt</th>
                                        <th>Product Name</th>
                                        <th>Origin</th>
                                        <th>Quantity</th>
                                        <th>Product price</th>
                                        <th>Status</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    include('connection.php');
                                    $i = 0;
                                    $sql = "SELECT * FROM product ORDER BY date_time";
                                    $res = mysqli_query($conn, $sql);
                                    while ($row = mysqli_fetch_assoc($res)) {
                                        $i++;
                                    ?>

                                        <tr>
                                            <td><?php echo $i; ?></td>
                                            <td><?php echo $row['date_time']; ?></td>
                                            <td> <?php echo $row['salt']; ?></td>
                                            <td>
                                                <?php echo $row['product_name']; ?>
                                            </td>
                                            <td><?php echo $row['origin'] ?></td>
                                            <td><?php echo $row['quantity']; ?></td>
                                            <td><?php echo $row['price']; ?></td>
                                            <td>
                                                <form method="POST" action="add_product_code.php">
                                                    <input type="hidden" name="item_id" value="<?php echo $row['id']; ?>">
                                                    <?php if ($row['status'] == 1) { ?>
                                                        <input type="submit" name="block" value="Block" class="btn btn-danger" style="font-weight: 600;font-size: 12px;height: 30px;">
                                                    <?php } else { ?>
                                                        <input type="submit" name="activate" value="Activate" class="btn btn-success" style="font-weight: 600;font-size: 12px;height: 30px;">
                                                    <?php } ?>
                                                    <!-- <?php echo ($row['status'] == 1) ? "<div class='test rounded-circle'></div>" : "<div class='test2 rounded-circle'></div>"; ?> -->
                                                </form>
                                            </td>
                                            <td> <a class="btn btn-danger btn-sm" href="delete_product.php?id=<?php echo $row['id']; ?>"> <i class="fas fa-trash"> </i> Delete </a></td>
                                        </tr>
                                    <?php
                                    }
                                    ?>
                                </tbody>
                            </table>
                        </div>


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

<!-- /.row -->
</section>
<!-- /.content -->
</div>
<!-- for searching -->
<?php
require("footer.php");
?>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
<script>
    <?php if (isset($_GET['error'])) { ?>
        Swal.fire({
            icon: 'error',
            title: 'Error',
            text: '<?php echo $_GET['error']; ?>',
        });
    <?php } ?>

    <?php if (isset($_GET['success'])) { ?>
        Swal.fire({
            icon: 'success',
            title: 'Success',
            text: '<?php echo $_GET['success']; ?>',
        });
    <?php } ?>
</script>
</body>

</html>