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

$home = "/usr/local/e-cron";
$jobnet = param("jobnet");
$project = param("project");

@server=`sudo -u ejobmgr ${home}/bin/distributed_servers $project/$jobnet| awk '{print \$1}'`;

print "Content-type: text/html\n\n";
###############contents insert#########
system("cat ../elements/header");
print "<a href=\"./jobnet_list.cgi?${project}\">Go to Jobnet List </a>";
print "<br></br>";
print "<pre>";

unless($project){
  print "No project was selected !";
  system("cat ../elements/footer");
  exit 1
}

unless($jobnet){
  print "No jobnet was selected !";
  system("cat ../elements/footer");
  exit 1
}

foreach $server ( @server ){
  system("/usr/bin/sudo -u ejobmgr $home/bin/for_cgi/delete_jobnet $project/$jobnet $server");
}

system("sudo -u ejobmgr rm -rf ${home}/project/${project}/${jobnet}");

if ( -d "${home}/project/${project}/${jobnet}"){
  print "<p>fail to delete $jobnet</p>";
}else{
  print "<p>$jobnet successfully deleted</p>";
}
print "</pre>";
print "</div>";
system("cat ../elements/footer");

