#!/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 ;
$job =`echo $string | awk -F\",\" '{print \$3}'`;
$job =~s/\s//g ;

print "Content-type: text/html\n\n";
###############contents insert#########
system("cat ../elements/header");
print " &nbsp;&nbsp;&nbsp;<a href=\"./set_jobnet_form.cgi?${project},${jobnet}\">Back to jobnet</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
}

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

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

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

