<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

// session_start();

include "../../../root.class.php";
$db = new db_safeguard();

if (empty($_POST['jobcard_no'])) {
    echo '<p style="color:white;">NO IMAGES FOUND</p>';
    exit;
}

$jobcard_no = $_POST['jobcard_no'];

$res = $db->query("notes", "SELECT * FROM notes WHERE jobcard_id = '{$jobcard_no}' AND reason = 'INSTALL IMAGE' ORDER BY record_id DESC");

if ($res->num_rows === 0) {
    echo '<p style="color:white;">NO IMAGES FOUND</p>';
    exit;
}

while ($row = $res->fetch_assoc()) {
    $image = htmlspecialchars($row['image']);
    $note = htmlspecialchars($row['note']);
    $date_time = htmlspecialchars($row['date_time']);

    echo "
        <div style='display:flex; flex-direction:column; align-items:center; background:rgba(0, 0, 0, 0.1); border-radius:8px; padding:2vw;'>
            <img 
                src='/app/jobcards/pump/install_images/{$image}' 
                style='width:100%; border-radius:8px; border:2px solid white; cursor:pointer;'
                onclick=\"openLightbox('/app/jobcards/pump/install_images/{$image}')\"
            /><br>
            <label style='color:black; font-size:2em;'>DESCRIPTION</label>
            <textarea style='color:black; margin-top:8px; font-size:3em; text-align:center; width:100%;' class='inputs' cols='70' rows='3' readonly>{$note}</textarea>
            <p style='color:black; font-size:3em; margin-top:8px;'>{$date_time}</p>
        </div><br>
    ";
}