<& /htmlheader &>
<& modelheader &>

<h2>Submitted Tracklets</h2>
<h3>TJD <% $nn + 1 - 50000 %> (MOPS Night Number <% $nn %>)<br>
<% $utdate_str %>
</h3>

<!-- <% $sql %> -->

<table border=1 cellspacing=0 cellpadding=2 width="100%">
<tr>
    <th class="darkheader"> Database/Tracklet ID </th>
    <th class="darkheader"> Observation<br>Date </th>
    <th class="darkheader"> Source Chunk </th> </th>
    <th class="darkheader"> Internal<br>Designation </th>
    <th class="darkheader"> MPC<br>Designation </th>
    <th class="darkheader"> Digest2 </th>
    <th class="darkheader"> Disposition </th>
</tr>
% foreach $href (@rows) {
% my $trk_dbname = $href->{dbname};
% my $trkId = $href->{tracklet_id};
<tr>

<td valign="center" align="left">
    <a href="<% qq{/model/$href->{dbname}/search?T$href->{tracklet_id}} %>"><% "$href->{dbname}/T$href->{tracklet_id}" %></a>
</td>
<td valign="center" align="left">
    <% mopslib_mjd2utcdatestr($href->{epoch_mjd}) %>
</td>
<td valign="center" align="center">
    <% defined($href->{digest}) ? $href->{survey_mode} : 'NA' %>
</td>
<td valign="center" align="center">
    <% $href->{desig} %>
</td>
<td valign="center" align="center">
    <% $href->{mpc_desig} || 'NA' %>
</td>
<td valign="center" align="center">
    <% defined($href->{digest}) ? $href->{digest} : 'NA' %>
</td>
<td valign="center" align="center">
    <% $dispmap{$href->{disposition}} || 'NA' %>
</td>

</tr>
% }
</table>


<& /htmlfooter &>

<%args>
$tjd
</%args>

<%init>
use Astro::Time;
use PS::MOPS::Lib qw(:all);
use PS::MOPS::Constants qw(:all);

my $utdate_str = mopslib_mjd2utctimestr($tjd + 50000);
$utdate_str =~ s/T.*//; # trim everything after date
$utdate_str .= 'UT';

my $inst = $m->notes('INST');
my $model = $m->notes('MODEL');
my $dbh = $inst->dbh();
my $epoch1 = $tjd + 50000 - 1;
my $epoch2 = $epoch1 + 1;
my $sql = <<"SQL";
select 
    epoch_mjd,
    ra_deg,
    dec_deg,
    filter_id,
    mag,
    desig,
    mpc_desig,
    digest,
    dbname,
    tracklet_id,
    disposition
from mpc_sub 
where epoch_mjd between $epoch1 and $epoch2
group by desig
SQL

my $sth = $dbh->prepare($sql) or die $dbh->errstr;
$sth->execute() or die $sth->errstr;

my @rows;
my $href;
while ($href = $sth->fetchrow_hashref()) {
    push @rows, $href;
}
$sth->finish();

</%init>
