
<!----------------------------------Login------------------------------------>
<?php
session_start();
include 'php/db_connection.php';

// শুধুমাত্র লগইন করা ইউজার পেজ দেখতে পারবে
if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}

$userName = $_SESSION['user_name'];
$role = $_SESSION['role']; // ✅ এখানে role সেভ করা হচ্ছে
$userId = $_SESSION['user_id'];


$isAdmin = ($_SESSION['role'] == 'admin');

?>



<?php include 'heade.php';?>
<?php include 'sidebar.php';?>
<?php include "php/db_connection.php";?>
<body>

<h2 style="text-align: center;">Customer List</h2>

<!-----------------------------------Add Product Cat From---------------------------------->
<div class="add-product-container">
        <button class="add-product-button" onclick="showForm()">Add Customer</button>
    </div>
    


    <div class="container" id="productFormContainer">
        <h2>Add Customer</h2>
        <form  method="post">
        <?php
                            if(isset($_POST['send'])){
                                $productName = $_POST['productName'];
                                $productId = $_POST['productId'];
                                $price = $_POST['price'];
                                $insert = "INSERT INTO customer (Customer_name, Customer_phone, Customer_address	) VALUES ( '$productName', $productId,  '$price')";
                                $query = mysqli_query($con  , $insert );
                                if ($query){
                                    echo "<script>alert('Add successfully')</script>";
                                    
                                }
                                else "<script>alert('Add Not successfully') </script>";
                            }
                            ?>

            
            <input type="text" id="productName" name="productName" placeholder=" Name" required>

           
            <input type="text" id="productId" name="productId" placeholder="Phone" required>
           
            <input type="text" id="price" name="price" placeholder=" Address" required>

            <div class="button-group">
                <input type="submit" name="send" class="submit-button" value="Submit">
                <button type="button" name="send"  class="close-button" onclick="hideForm()">Close</button>
            </div>
        </form>
    </div>

<!-----------------------------------Add Product Cat Tabele---------------------------------->
<!-----------------------------------Scerch Hideen
<div class="col-md-12 form-group form-inline">
            <label class="font-weight-bold" for="">Search :&emsp;</label>
            <input type="text"  class="form-control" id=""  placeholder="Product Name" onkeyup="searchSupplier(this.value);">
          </div>---------------------------------->
<table>
    <thead>
        <tr>
            <th colspan='6' style='text-align: left;'>
            <form action="history.php" method="get">
            <input type="text" name="customer_phone" placeholder="Enter Customer Phone" required>
            <input class="btn btn-success" type="submit" value="View History">
         </form>
            </th>
        </tr>
        <tr>
            <th>Sl No</th>
            
            <th>Customer Name</th>
            <th>Customer Phone</th>
            <th>Customer Address</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
    <?php
                    require 'php/Customer.php';
                   
                    

function showSupplierRow($seq_no, $row) {
    ?>
    <tr>
        <td><?php echo $seq_no; ?></td>
       
        <td><?php echo htmlspecialchars($row['Customer_name']); ?></td>
        <td><?php echo htmlspecialchars($row['Customer_phone']); ?></td>
        <td><?php echo htmlspecialchars($row['Customer_address']); ?></td>
        <td>
<!--------------Login Admin & User---------------->
        <?php 
        $isAdmin = ($_SESSION['role'] == 'admin');
        if ($isAdmin): ?>

            <button class="btn btn-info btn-sm" onclick="editSupplier(<?php echo $row['id']; ?>);">
                <i class="fa fa-pencil"></i> 
            </button>
            <button class="btn btn-danger btn-sm" onclick="deleteSupplier(<?php echo $row['id']; ?>);">
                <i class="fa fa-trash"></i>
            <?php else: ?>
    <span class="text-muted">No Permission</span>
 <?php endif; ?>
            </button>
            <a href="php/customar_due/receive_due.php?customer_id=<?= $row['id'] ?>" class="btn btn-success btn-sm"><i class="fas fa-money-bill-wave"></i></a>
            </button>
             <a href="export_pdf.php?customer_id=<?= $row['id'] ?>" class="btn btn-success btn-sm"><i class="fa fa-eye"></i></a>
           
        </td>
    </tr>
    <?php
    }
    ?>
    </tbody>
</table>
<script>
        function showForm() {
            document.getElementById('productFormContainer').style.display = 'flex';
        }

        function hideForm() {
            document.getElementById('productFormContainer').style.display = 'none';
        }
    </script>
</body>
</html>
 