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

if(!isset($_SESSION['id'])){
 echo "<script> window.location.href = 'index.php' </script>";
  }
?>

<?php  include 'include/head.php'; ?>
                    
                      <!-- Start Content-->
                      <div class="container-fluid">
                        
                        <!-- start page title -->
                        <div class="row">
                            <div class="col-12">
                                <div class="page-title-box">
                                    <div class="page-title-right">
                                        <ol class="breadcrumb m-0">
                                            <li class="breadcrumb-item"><a href="dashboard.php">Home</a></li>
                                            <li class="breadcrumb-item active">Amanagal Shop</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title">Amangal Shop</h4>
                                </div>
                            </div>
                        </div>
                        <!-- end page title --> 


                        <div class="row">
                            <div class="col-12">
                                <div class="card">
                                    <div class="card-body">
                                        
                                        <?php
                                        if(isset($_GET['user'])){
                                            $id = $_GET['user'];
                                        
                                            $sql = "DELETE FROM `registration` WHERE id='$id'";
                                           // print_r($sql);
                                            if(mysqli_query($conn,$sql)){

                                            echo "<script>document.location('shop.php');</script>";
                                            }
                                           
                                        }
                                        ?>
                                        <div class="table-responsive">
                                            <div class="tab-pane show active" id="basic-datatable-preview">
                                                <table id="datatable" class="table table-striped dt-responsive nowrap w-100">
                                                    <thead>
                                                        <tr>
                                                            <th>Sr. No.</th>
                                                            <th>Unique Id</th>
                                                            <th>Name</th>
                                                            <th>Shop Name</th>
                                                            <th>Number</th>
                                                            <th>Address</th>
                                                            <th>Gst Number</th>
                                                            <th>About Shop</th>
                                                            <th>Image One</th>
                                                            <th>Image Two</th>
                                                            <th>Image Three</th>
                                                            <th>Image Four</th>
                                                            <th>Image Five</th>
                                                            <th>Map Address</th>
                                                            <th>Rating</th>
                                                            <th>Status</th>
                                                            <th>Action</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                    <?php
                                                    $sql = "SELECT * FROM `registration` WHERE `status` = 'amangal'";
                                                    $res = mysqli_query($conn, $sql);
                                                    $i = 1;
                                                    while ($row = mysqli_fetch_assoc($res)) {
                                                    ?>
                                                        <tr>
                                                            <td><?= $i; ?></td>
                                                            <td><?= $row['unique_id'] ?></td>
                                                            <td><?= $row['name'] ?></td>
                                                            <td><?= $row['shop_name'] ?></td>
                                                            <td><?= $row['phone_number'] ?></td>
                                                            <td><?= $row['address'] ?></td>
                                                            <td><?= $row['gst_number'] ?></td>
                                                            <td><?= $row['about_shop'] ?></td>
                                                             <?php  
                                                             $fullImagePath = $row['img_1'];

                                                             $prefixToRemove = 'upload/image/';

                                                             $imageFilename = str_replace($prefixToRemove, '', $fullImagePath);
                                                             ?>
                                                             <td><img src="<?= '../upload/image/' . $imageFilename; ?>" style="width:100px; height:60px;"></td>
                                                             <?php  
                                                             $fullImagePath2 = $row['img_2'];

                                                             $prefixToRemove2 = 'upload/image/';

                                                             $imageFilename2 = str_replace($prefixToRemove2, '', $fullImagePath2);
                                                             ?>
                                                             <td><img src="<?= '../upload/image/' . $imageFilename2; ?>" style="width:100px; height:60px;"></td>
                                                             <?php  
                                                             $fullImagePathh3 = $row['img_3'];

                                                             $prefixToRemovee3 = 'upload/image/';

                                                             $imageFilenamee3 = str_replace($prefixToRemovee3, '', $fullImagePathh3);
                                                             ?>
                                                             <td><img src="<?= '../upload/image/' . $imageFilenamee3; ?>" style="width:100px; height:60px;"></td>
                                                             <?php  
                                                             $fullImagePath4 = $row['img_4'];

                                                             $prefixToRemove4 = 'upload/image/';

                                                             $imageFilename4 = str_replace($prefixToRemove4, '', $fullImagePath4);
                                                             ?>
                                                             <td><img src="<?= '../upload/image/' . $imageFilename4; ?>" style="width:100px; height:60px;"></td>
                                                                <?php  
                                                             $fullImagePath = $row['img_5'];

                                                             $prefixToRemove = 'upload/image/';

                                                             $imageFilename = str_replace($prefixToRemove, '', $fullImagePath);
                                                             ?>
                                                             <td><img src="<?= '../upload/image/' . $imageFilename; ?>" style="width:100px; height:60px;"></td>
                                                            <td><?= $row['map_address'] ?></td>
                                                            <td><?= $row['rating'] ?></td>
                                                            <td><?= $row['status'] ?></td>
                                                            <td>
                                                                <a href="shop_edit.php?id=<?=$row['id']?>" class="action-icon"> <i class="mdi mdi-square-edit-outline"></i></a>
                                                                <a href="shop.php?user=<?=$row['id']?>" class="action-icon"> <i class="mdi mdi-delete"></i></a>
                                                            </td>
                                                         </tr>
                                                        <?php
                                                       $i++;  } 
                                                        ?>
                                                    </tbody>
                                                </table>                                           
                                            </div> <!-- end preview-->
                                        
                                            
                                        </div> <!-- end tab-content-->

                                    </div> <!-- end card body-->
                                </div> <!-- end card -->
                            </div><!-- end col-->
                        </div> <!-- end row-->

                    
                    </div> <!-- container -->


<?php  
include 'include/footer.php'; 
?>