#!/usr/bin/perl
use CGI qw(param);

$word = param("word");

print "Content-type: text/html\n\n";
###############contents insert#########
system("cat ../elements/header");

@STATUS_LIST = ();
@STATUS_LIST=`/usr/local/e-cron/bin/server_stat | grep -v "No server connection" | egrep "$word"`;

unless(@STATUS_LIST){

 unless($word){
    print "<h4>Job has not distributed to any server</h4><h4>Please distribute job from Projects menu</h4>";
    print "</div>";
    system("cat ../elements/footer");
  exit 0
  }else{
    print "<h4>No search result</h4>";
    print "<a href=\"./server_stat.cgi\">back to server status</a><h6>";
    print "</div>";
    system("cat ../elements/footer");
    exit 0
  }
}

print "<h6>status will be updated 1-5min, please refresh this page</h6>";
system("cat ../elements/search_server_stat");
print "<table  style=\"border-style:none\">";
print "  <thead>";
print "    <tr>";
print "      <th>Date</th>";
print "      <th>Time</th>";
print "      <th>Status</th>";
print "      <th>Detail</th>";
print "      <th>Server</th>";
print "    </tr>";
print "  </thead>";
print "  <tbody>";

foreach $status (@STATUS_LIST){
 $status =~ s/  / /g;
 @status = split(/ /, $status);
 print "    <tr>";
 print "<td>$status[0]</td>";
 print "<td>$status[1]</td>";
 
 if ( $status[3] eq SUCCESS ){
   print "<td><span class=\"success label\">$status[3]</span></td>";
 }elsif ( $status[3] eq ERROR ){
   print "<td><span class=\"alert label\">$status[3]</span></td>";
 }elsif ( $status[3] eq INFO ){
   print "<td><span class=\"label\">$status[3]</span></td>";
 }else{
   print "<td>$status[3]</td>";
 }
 print "<td>$status[4]</td>";
 print "<td><a href=\"./server_info.cgi?$status[2]\">$status[2]</a></td>";
 print "    </tr>";
} 
print "</tbody>";
print "</table>";
print "</div>";
system("cat ../elements/footer");
