<?php
require_once "../../config/settings.inc.php";
define("IEM_APPID", 100);
require_once "../../include/myview.php";
require_once "../../include/database.inc.php";
$t = new MyView();
$t->title = "Quality Control, Active Trouble Tickets";

$conn = iemdb("portfolio");
$rs = pg_query($conn, "SELECT *, getSiteName(s_mid) as s_name from tt_base " .
    "WHERE status != 'CLOSED' ORDER by id ASC");

$ars = array("isusm" => "", "iaawos" => "", "iarwis" => "");

while ($row = pg_fetch_assoc($rs)) {
    if (!array_key_exists($row["portfolio"], $ars)) {
        continue;
    }
    $entered = new DateTime(substr($row["entered"], 0, 16));
    $last = new DateTime(substr($row["last"], 0, 16));
    $s = "<tr>
        <th>" . $row["id"] . "</th>
        <td>" . $row["status"] . "</td>
        <td>" . $entered->format("Y-m-d") . "</td>
        <td>" . $last->format("Y-m-d") . "</td>
        <td>[" . $row["s_mid"] . "] " . $row["s_name"] . "</td>
        <td>" . $row["subject"] . "</td>
     </tr>";
    if (array_key_exists($row["portfolio"], $ars)) {
        $ars[$row["portfolio"]] .= $s;
    } else {
        $ars[$row["portfolio"]] = $s;
    }
}

foreach ($ars as $key => $val) {
    if ($val == '')
        $ars[$key] = "<tr><td colspan=\"6\">No Open/Active Tickets Found</td></tr>";
}

$t->content = <<<EOM
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
 <li class="breadcrumb-item"><a href="/QC/">Quality Control</a></li>
 <li class="breadcrumb-item active" aria-current="page">Active Trouble Tickets</li>
</ol>
</nav>

<p>The IEM developed a system called "IEM Tracker" to track meta-data
of sites in our component networks.  This page presents a listing of
'Trouble Tickets' that are currently active.  Currently, only the ticket
header is presented, but in the future more info will be made publicly
available.  If you have any questions or comments about a ticket listed,
please feel free to <a href="/info/contacts.php">Contact Us</a>.</p>

<h3 class="mt-4">Iowa State Soil Moisture Network</h3>
<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead class="table-light">
<tr>
 <th>ID</th><th>Status:</th><th>Opened:</th><th>Updated:</th><th>Site:</th>
 <th>Ticket Topic:</th>
</tr>
</thead>
<tbody>
{$ars["isusm"]}
</tbody>
</table>
</div>

<h3 class="mt-4">Iowa AWOS network</h3>
<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead class="table-light">
<tr>
 <th>ID</th><th>Status:</th><th>Opened:</th><th>Updated:</th><th>Site:</th>
 <th>Ticket Topic:</th>
</tr>
</thead>
<tbody>
{$ars["iaawos"]}
</tbody>
</table>
</div>

<h3 class="mt-4">Iowa RWIS network</h3>
<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead class="table-light">
<tr>
 <th>ID</th><th>Status:</th><th>Opened:</th><th>Updated:</th><th>Site:</th>
 <th>Ticket Topic:</th>
</tr>
</thead>
<tbody>
{$ars["iarwis"]}
</tbody>
</table>
</div>
EOM;
$t->render('single.phtml');
