<?php
error_reporting(0);
session_start();
include("login_check_admin.php");


include('header.php');
include("db_con.php");
$equipment_id = $_GET["equipment_id"];

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>View Log</title>
    

</head>
<body>
<table class="table table-hover">


    <?php
    
    $Qry3="SELECT * FROM `log`  WHERE equipment_id = '$equipment_id'";


    $Run3=mysqli_query($con,$Qry3);
    if(mysqli_num_rows($Run3)<1)
    {
        echo"<tr class='alert alert-danger text-center'><td colspan='3'>No Logs found</td></tr>";
    }
    else
    {
      ?>
      <br>
      <div class="container">
      <div class="row row-cols-1 row-cols-md-4">
      <?php
        while($Data3=mysqli_fetch_assoc($Run3))
        {
            $date=date_create($Data3["date"]);
            $date = date_format($date,"d/m/yy");
            
            $next_service=date_create($Data3["$next_service"]);
            $next_service = date_format($next_service,"d/m/yy");
            
           
            
            //echo $date."=".$next_service;
            ?>

                
  

  
<div class="col mb-4">
    <div class="card">
    <div class="card-header">
    <?php echo $Data3["type"]; ?>
        
    </div>
      <img src="images\log\<?php echo $Data3['log_id'].'/'.$Data3['image']; ?>" onerror="if (this.src != 'images/default/log_image_not_found.jpg') this.src = 'images/default/log_image_not_found.jpg';" class="card-img-top" alt="...">
      <div class="card-body">
        <!-- <h5 class="card-title py-0 my-0">Type: <?php echo $Data3["type"]; ?></h5> -->

        <p class="card-text"><small class="text-muted"><br>Date: <?php echo $date; ?><br><?php if($Data3["type"]!="report"){echo "Notes: ".$Data3["notes"];} ?><?php if($Data3["type"]=="service"){ echo "<br>Next Service: ".$next_service;} ?><br><?php if($Data3["type"]!="report"){echo "Completed by: ".$Data3["completed_by"];} ?></small></p>
        <?php 
        if($Data3["type"]=="report")
        { 
        ?> 
       <p class="card-text">Message: <?php echo $Data3["message"]; ?></p> 
        <?php 
        }
        else
        {
            ?>
             <p class="card-text">Description: <?php echo $Data3["description"]; ?></p> 
             <?php
        }
        ?>
       
        <!-- <p class="card-text"><small class="text-muted">Notes: <?php echo $Data3["notes"]; ?></small></p> -->
      </div>
      <!-- <div class="card-footer">

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


            <!-- <tr>
                
                <td rowspan=""><a class="text-decoration-none text-dark" href="images\<?php echo $Data3['equipment_id'].'/'.$Data3['image']; ?>"><img width="200px" height="150px" src="images\<?php echo $Data3['equipment_id'].'/'.$Data3['image']; ?>" alt="NOT_FOUND" style="max-width:50px"></a></td>
                <td><?php echo "Title: ".$Data3["title"]."<br>Location: ".$Data3["location"]."<br>Equipment Type: ".$Data3["equipment_type"]."<br>Equipment Description: ".$Data3["equipment_description"]."<br>Notes: ".$Data3["notes"]."<br>Service Interval: ".$Data3["service_interval"]; ?></td>
              
               
              
               
                <td rowspan="" class="text-center align-middle"><a href="DeleteOrder.php?OrderNumber=<?php echo $Data3["OrderNumber"]?>&OrderID=<?php echo $Data3["OrderID"]?>&Image=<?php echo $Data3["Image"]?>" class="btn btn-danger"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
  <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
  <path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
</svg></a></td>    
            </tr>   -->
            
           
        <?php
        }
        ?>
        </div>
        </div>
        </table>
        <?php
    }
    ?>
</body>
</html>