<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ပစ္စည်းလက်ကျန်စာရင်း</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha2/dist/css/bootstrap.min.css">
    <script src="https://kit.fontawesome.com/ae360af17e.js" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
    <link rel="stylesheet" href="../css/style.css">
    <link rel="icon" href="../image/logo.png" type="image/png">

    <link rel="stylesheet" href="extensions/fixed-columns/bootstrap-table-fixed-columns.css">
    <script src="extensions/fixed-columns/bootstrap-table-fixed-columns.js"></script>
</head>
<style>
        .image-container {
            width: 200px; /* Adjust this width as needed */
            height: 200px; /* Adjust this height as needed */
            overflow: hidden;
            position: relative;
            border: 1px solid #ccc; /* Add a border for the frame effect */
        }
        .image-container img {
            width: 100%;
            height: 100%;
            object-fit: contain; /* Ensure the entire image is visible */
        }
    </style>



<?php

session_start();
                                
if (isset($_SESSION['browser_id'])) {
    $browserId = $_SESSION['browser_id'];
} else {
    // Generate a new browser ID
    $browserId = generateUniqueBrowserId();

    // Store the browser ID in the session for future use
    $_SESSION['browser_id'] = $browserId;
}


include "../database/database.php";
include "../database/data.php";
include "cal_pro_remain.php";


if (isset($_POST['search'])) {
    $product_type = $_POST['product_type'];
    

    $sql = "UPDATE $catagories SET active='1' WHERE type='$product_type'";
    if (!$connection->query($sql)) {
  
    }

    $sql = "UPDATE $catagories SET active='0' WHERE type!='$product_type'";
    if (!$connection->query($sql)) {
        // Log error or handle it appropriately
       
    }
   

}
?>


<body>
    <div class="wrapper">
        <?php 
        include "sidebar.php";
        ?>

        <div class="main">
            <nav class="navbar navbar-expand px-3 border-bottom">
                <button class="btn" id="sidebar-toggle" type="button">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="navbar-collapse navbar">
                    <ul class="navbar-nav">
                    <div class="mb-3" style="margin-right:30px">
                    <h4 style="font-size:25px">ပစ္စည်းလက်ကျန်စာရင်း</h4>
                    </div>
                        <li class="nav-item dropdown">
                            <a href="#" data-bs-toggle="dropdown" class="nav-icon pe-md-0">
                                <img src="../image/logo.png" class="avatar img-fluid rounded" alt="">
                            </a>
                            <?php include "logo_profile.php";?>
                        </li>
                    </ul>
                </div>
            </nav>

            <main class="content px-3 py-2">
            <div class="container-fluid">


<div class="row">

<!-- Table Element -->
<div class="col">

<div class="card-header gx-5">

    <form class="d-flex flex-row-reverse" action="product_view.php" method="POST" >

    <div class="col-auto" style="margin-left:10px;margin-right:10px">
        <input type="text" class="form-control" id="searchInput" placeholder="Search">
    </div>

    <div class="col-auto" style="margin-left:10px">
    <!-- <select name="product_type" id="accountInput" onchange="filterTable()" class="form-control"> -->
    <select name="product_type" id="accountInput" class="form-control">
                <?php
                $sql = "SELECT * FROM ".$catagories."";
                $result = $connection->query($sql);
                if ($result && $result->num_rows > 0) {
                    while ($row = $result->fetch_assoc()){
                        $account = $row['type']; // Database
                        echo '<option value="' . $account . '">' . $account . '</option>';
                    }
                }
                ?>
            </select>

    </div>

    <div class="col-auto" style="margin-left:10px">
        <button type="submit" class="btn btn-primary mb-3"  name="search">Search</button>
    </div>

    <div class="col-auto" style="margin-left:10px">
        <button type="submit" class="btn btn-success mb-3" onclick="refreshPage()">Refresh</button>
    </div>

    <div class="col-auto" style="margin-left:10px">
    <button type="button" class="btn btn-warning mb-3" onclick="window.location.href='product_view_all.php';">All</button>
    </div>

    <div class="col-auto" style="margin-left:10px">
    <button type="button" class="btn btn-danger mb-3" onclick="window.location.href='product_view_photo.php';">Photo</button>
    </div>


    

    

    </form> 
    </div>

    <div class="row justify-content-center" style='margin:0px;'> 
                        <h1 style="margin:10px 0px 15px 10px;font-size:30px;text-align:center">ပစ္စည်းစာရင်း</h1>

                        <!-- =================cont_1================================ -->
                        
                        <?php
                        // Fetch all image data from the database
                        $sql = "SELECT * FROM ".$catagories." WHERE active='1'";
                        $result = $connection->query($sql);
                        if ($result->num_rows > 0) {
                            while ($row = $result->fetch_assoc()) {
                                $type = $row['type'];

                                $sql = "SELECT * FROM ".$cargo_1." WHERE delete_d='0' and type='$type' ORDER BY id DESC";
                                $result = $connection->query($sql);

                                if ($result->num_rows > 0) {
                                    while ($row = $result->fetch_assoc()) {
                                        $imageData = $row['image'];
                                        $id = $row['id'];
                                        echo '
                                        <div class="col-sm-4" style="border-radius:10px; width:320px; margin:10px">
                                            <div class="card mb-3">
                                                <div class="card-header bg-info text-white">
                                                    <h5 class="card-title">'.$row["product_name"].'</h5>
                                                </div>
                                                <div class="card-body">
                                                
                                                    <div class="text-center">
                                                        <div class="image-container">
                                                            <img src="data:image/jpeg;base64,' . base64_encode($imageData) . '"  alt="Sample Image" style="width:100%;">
                                                        </div>
                                                    </div>

                                                    <div style="margin-top:10px;line-height: 1;">
                                                    <p class="card-text" style="font-size:15px">ပစ္စည်းအမည်: <a style="color:white">'.$row["product_name"].'</a></p>
                                                    <p class="card-text" style="font-size:15px">code နံပါတ်: <a style="color:white">'.$row["barcode"].'</a></p>
                                                    <p class="card-text" style="font-size:15px">အမျိုးစား: <a style="color:white">'.$row["type"].'</a></p>

                                                    <p class="card-text" style="font-size:15px">လက်ကျန်ဖာ: <a style="color:white">'.$row["package_exist"].'</a></p>
                                                    <p class="card-text" style="font-size:15px">လက်ကျန်ကဒ်: <a style="color:white">'.$row["unit_exist"].'</a></p>
                                                    <p class="card-text" style="font-size:15px">လက်ကျန်ဘူး: <a style="color:white">'.$row["pieces_exist"].'</a></p>
                                                
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        ';
                                    }
                                } else {
                                    echo "No images found.";
                                }
                            }
                        }

                        
                        ?>

                    </div>
</div>


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


            <a href="#" class="theme-toggle">
                <i class="fa-regular fa-moon"></i>
                <i class="fa-regular fa-sun"></i>
            </a>
            <footer class="footer">
                <div class="container-fluid">
                    <div class="row text-muted">
                        <div class="col-6 text-start">
                            <p class="mb-0">
                                <a href="#" class="text-muted">
                                    <?php 
                                        include "../version.php";
                                    ?>
                                </a>
                            </p>
                        </div>
                        <div class="col-6 text-end">
                            <ul class="list-inline">
                                <li class="list-inline-item">
                                    <a href="#" class="text-muted">Contact</a>
                                </li>
                                <li class="list-inline-item">
                                    <a href="#" class="text-muted">About Us</a>
                                </li>
                                <li class="list-inline-item">
                                    <a href="#" class="text-muted">Terms</a>
                                </li>
                                <li class="list-inline-item">
                                    <a href="#" class="text-muted">Booking</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </footer>
        </div>
    </div>
    

    <script src="../js/script.js"></script>
    <link rel="stylesheet" href="extensions/sticky-header/bootstrap-table-sticky-header.css">
<link rel="stylesheet" href="extensions/fixed-columns/bootstrap-table-fixed-columns.css">
<script src="extensions/sticky-header/bootstrap-table-sticky-header.js"></script>
<script src="extensions/fixed-columns/bootstrap-table-fixed-columns.js"></script>

<?php 

function generateUniqueBrowserId()
{
    $randomString = bin2hex(random_bytes(16));
    $timestamp = time();

    return $randomString . $timestamp;
}

?>


</body>

</html>
