<?php
include "../../root.class.php";
$db = new db_safeguard();

$team_id = isset($_GET['team_id']) ? (int)$_GET['team_id'] : 0;

if ($team_id === 0) {
    exit;
}

$res = $db->query(
    "jobcards",
    "SELECT jc_no, address, action_date 
     FROM jobcards 
     WHERE status = 0 AND team_assigned_id = $team_id
     ORDER BY jc_no DESC"
);

if ($res->num_rows === 0) {
    echo "<em>No active jobcards</em>";
    exit;
}

while ($jc = $res->fetch_assoc()) {
    ?>
    <div class="jobcard_item">
        <strong>Jobcard #<?= (int)$jc['jc_no']; ?></strong><br>
        <?= htmlspecialchars($jc['address']); ?><br>
        <small><?= $jc['action_date']; ?></small>

        <button onclick="openDetails(<?= (int)$jc['jc_no']; ?>)">
            VIEW DETAILS
        </button>
    </div>
<?php } ?>
