#!/usr/local/bin/perl  
use DBI;

require "$ENV{'FSW'}/web/rebuild_db.pl";

my (@data, $i, $j, $max_loop, $not_depend);


@data = ();
@data = sql_execute ( "select", "select a1.rebuild_start_time, a1.rebuild_end_time, a1.FSW_build_instance, a1.rebuild_os_type,  a2.status, a1.official_release, a1.comment  from build_release_log as a1, rebuild_status as a2 where a1.rebuild_status = a2.id and a2.status = 'completed' and a1.FSW_build_instance like \"B%\" and official_release = 'yes' order by a1.rebuild_start_time desc ", @data );


print "<p><p><b>Successful FSW Release Build:</b>\n";
print "<table>\n";
print "<tr>\n";
print "<td width=160><b>Build Start Time</b></td>\n";
print "<td width=160><b>Build End Time</b></td>\n";
print "<td width=70><b>CMX Instance</b></td>\n";
print "<td width=50><b>OS</b></td>\n";
print "<td width=80><b>Build Status</b></td>\n";
print "<td width=80><b>Official Release</b></td>\n";
print "<td width=80><b>Comment</b></td>\n";
print "</tr>\n";

for $i ( 0 .. $#data )
{
    print "<tr>\n";
    for $j ( 0 .. $#{ $data[$i] } )
    {
       print "<td>$data[$i][$j]</td>\n";
    }
    print "</tr>\n";
}

print "</table>\n";


@data = ();
@data = sql_execute ( "select", "select a1.rebuild_start_time, a1.rebuild_end_time, a1.FSW_build_instance, a1.rebuild_os_type, a2.status  from build_release_log as a1, rebuild_status as a2 where a1.rebuild_status = a2.id and a2.status = 'completed' and a1.FSW_build_instance not like \"B%\" and ( DATEDIFF(NOW(),(a1.rebuild_start_time)) < 30 ) order by a1.id desc ", @data );


print "<p><p><b>Successful FSW Nightly Build:</b>\n";
print "<table>\n";
print "<tr>\n";
print "<td width=160><b>Build Start Time</b></td>\n";
print "<td width=160><b>Build End Time</b></td>\n";
print "<td width=70><b>CMX Instance</b></td>\n";
print "<td width=50><b>OS</b></td>\n";
print "<td width=80><b>Build Status</b></td>\n";
print "</tr>\n";

for $i ( 0 .. $#data )
{
    print "<tr>\n";
    for $j ( 0 .. $#{ $data[$i] } )
    {
       print "<td>$data[$i][$j]</td>\n";
    }
    print "</tr>\n";
}

print "</table>\n";


print "<p><p><b>Failed FSW Build:</b>\n";
print "<table>\n";
print "<tr>\n";
print "<td width=160><b>Build Start Time</b></td>\n";
print "<td width=70><b>CMX Instance</b></td>\n";
print "<td width=60><b>OS</b></td>\n";
print "<td><b>Where the build failed</b></td>\n";
print "</tr>\n";

@data = ();
@data = sql_execute ( "select", "select a1.rebuild_start_time, a1.FSW_build_instance, a1.rebuild_os_type, a1.comment  from build_release_log as a1 where a1.rebuild_status = 4 and comment != '' and ( DATEDIFF(NOW(),(a1.rebuild_start_time)) < 10 )  order by a1.id desc ", @data );


for $i ( 0 .. $#data )
{
    print "<tr>\n";
    for $j ( 0 .. $#{ $data[$i] } )
    {
       print "<td>$data[$i][$j]</td>\n";
    }
    print "</tr>\n";
}

print "</table>\n";

