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

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

@jobnet_list=();
@jobnet_list=`ls /usr/local/e-cron/project/$project`;

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

print "<pre>";

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

foreach $jobnet ( @jobnet_list ) {
  $jobnet =~ s/\n//;
  @server=();
  @server=`sudo -u ejobmgr ${home}/bin/distributed_servers $project/$jobnet| awk '{print \$1}'`;

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

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

print "</pre>";

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

