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

$home="/usr/local/e-cron";
$string = $ENV{'QUERY_STRING'};
$string =~s/\///g ;
$project =`echo $string | awk -F\",\" '{print \$1}'`;
$project =~s/\s//g ;
$jobnet =`echo $string | awk -F\",\" '{print \$2}'`;
$jobnet =~s/\s//g ;

@server_list=();
@server_list=`sudo -u ejobmgr ${home}/bin/distributed_servers $project/$jobnet| sed -e \"s/        version:/ /g\" | sed -e \"s/ /,/g\"`;

print "Content-type: text/html\n\n";
###############contents insert#########
system("cat ../elements/header");
print "<h3>${project}::${jobnet} server list</h3>";

unless(@server_list){
  print "<h6>This jobnet did not distributed to any server</h6>";
  print "<h6>Please distribute jobnet from project menue</h6>";
  print "</div>";
  system("cat ../elements/footer");
  exit 1
}  
print "<div class=\"large-8 columns\">";
print "<form method=\"post\" action=\"./execute_jobnet.cgi\" class=\"custom\">";
print "  <input type=\"hidden\" name=\"project\" value=\"$project\">";
print "  <input type=\"hidden\" name=\"jobnet\" value=\"$jobnet\">";
print "<table>";
print "  <thead>";
print "    <tr>";
print "      <th>Server_Name</th>";
print "      <th>Status</th>";
print "      <th>Job and Batch file version</th>";
print "      <th>Check</th>";
print "    </tr>";
print "  </thead>";
print "  <tbody>";

while (<@server_list>){
 @distributed_server=();
 @distributed_server=split(/,/, $_);
  print "    <tr>";
 
  if ( $distributed_server[3] eq spare ){ 
    print "       <td>$distributed_server[0] *spare</td>";
  }else{
    print "       <td>$distributed_server[0]</td>";
  }
  print "       <td>$distributed_server[1]</td>";
  print "       <td>$distributed_server[2]</td>";
  print "       <td><input type=\"checkbox\" name=\"server\" id=\"checkbox\" value=\"$distributed_server[0]\" style=\"display: none;\"><span class=\"custom checkbox\"></span></td>";
  print "    </tr>"; 
}

print "  </tbody>";
print "</table>";
print "<input type=\"submit\" class=\"button\" value=\"Execute Now\">";
print "</form>";
print "</div>";
print "<div class=\"large-4 columns\">";
print "<a href=\"./set_jobnet_form.cgi?${project},${jobnet}\">Back to Jobnet Setting</a></p>";
print "</div>";
system("cat ../elements/footer");
