<?php
include "../../root.class.php";
$db = new db_safeguard();

$jc_no = isset($_GET['jc_no']) ? (int)$_GET['jc_no'] : 0;

if ($jc_no === 0) {
    exit("Invalid jobcard.");
}

$res = $db->query(
    "jobcard_timeline",
    "SELECT type, meters FROM jobcard_timeline 
     WHERE jobcard_id = $jc_no"
);

$riem = $drill = $casing = $blast = 0;

while ($row = $res->fetch_assoc()) {

    if (in_array($row['type'], ['RIEM_STOP','RIEMING_STOP','RIEMING_PAUSED'])) {
        $riem += (float)$row['meters'];
    }

    if (in_array($row['type'], ['DRILLING_STOP','DRILLING_PAUSE'])) {
        $drill += (float)$row['meters'];
    }

    if (in_array($row['type'], ['CASING_STOP','CASING_PAUSE'])) {
        $casing += (float)$row['meters'];
    }

    if (in_array($row['type'], ['BLASTING_START','BLASTING_STOP'])) {
        $blast += (float)$row['meters'];
    }
}
?>

<h2>CURRENT TOTAL METERS</h2>
<p><strong>RIEMING:</strong> <?= $riem ?> m</p>
<p><strong>DRILLING:</strong> <?= $drill ?> m</p>
<p><strong>CASING:</strong> <?= $casing ?> m</p>
<p><strong>BLASTING:</strong> <?= $blast ?> m</p>
