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

$home="/usr/local/e-cron";
$server = $ENV{'QUERY_STRING'};
$server =~s/\s//g ;

@jobnet_list=`sudo -u ejobmgr $home/bin/for_cgi/distributed_jobnets $server`;

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


print "<h3>${server} jobnet list</h3>";
unless(@jobnet_list){
  print "<h6>No jobnet distributed yet</h6>";
  print "<h6>Please distribute jobnet from project menue</h6>";
  print "</div>";
  system("cat ../elements/footer");
  exit 1
}
print "<div class=\"large-6 columns\">";
print "<form method=\"post\" action=\"./set_server_status.cgi\" class=\"custom\">";
print "  <input type=\"hidden\" name=\"server\" value=\"$server\">";
print "<table>";
print "  <thead>";
print "    <tr>";
print "      <th>Project</th>";
print "      <th>Jobnet</th>";
print "      <th>Status</th>";
print "      <th>Exec Status</th>";
print "      <th>Check</th>";
print "    </tr>";
print "  </thead>";
print "  <tbody>";

while (<@jobnet_list>){
 @jobnet_info=split(/,/, $_);
  print "    <tr>";
  print "       <td>$jobnet_info[0]</td>";

  if ( $jobnet_info[4] eq spare ){
    print "       <td><a href=\"./set_jobnet_form.cgi?$jobnet_info[0],$jobnet_info[1]\">$jobnet_info[1] *spare</a></td>";
  }else{
    print "       <td><a href=\"./set_jobnet_form.cgi?$jobnet_info[0],$jobnet_info[1]\">$jobnet_info[1]</a></td>";
  }
  print "       <td>$jobnet_info[2]</td>";
  print "       <td><a href=\"./ls_log.cgi?$jobnet_info[0],$jobnet_info[1],$server\">$jobnet_info[3]</a></td>";
  print "       <td><input type=\"checkbox\" name=\"project_jobnet\" id=\"checkbox\" value=\"$jobnet_info[0],$jobnet_info[1]\" style=\"display: none;\"><span class=\"custom checkbox\"></span></td>";
  print "    </tr>"; 
}

print "  </tbody>";
print "</table>";
print "<label for=\"radio1\"><input name=\"change_status\" type=\"radio\" id=\"radio\" value=\"change_to_enable\" style=\"display:none;\"  CHECKED><span class=\"custom radio checked\"></span> Change to Enable</label>";
print  "<label for=\"radio1\"><input name=\"change_status\" type=\"radio\" id=\"radio\" value=\"change_to_disable\" style=\"display:none;\"><span class=\"custom radio\"></span> Change to Disable </label>";
print  "<label for=\"radio1\"><input name=\"change_status\" type=\"radio\" id=\"radio\" value=\"delete_jobnet\" style=\"display:none;\"><span class=\"custom radio\"></span> Delete </label>";
print "<br>";
print "<input type=\"submit\" class=\"button\" value=\"Execute Operation\">";
print "</form>";
print "</div>";
print "<div class=\"large-6 columns\">";
print "<a href=\"./delete_server_form.cgi?${server}\">Delete This Server</a></p>";
print "</div>";
system("cat ../elements/footer");
