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

$code=`cat ${home}/project/${project}/${jobnet}/bat/${batch_name}`;

unless($code){
  $code=`cat ../elements/sample_code`;
}

print "Content-type: text/html\n\n";
###############contents insert#########
system("cat ../elements/header");
print "<h3>${project}::${jobnet}</h3>";
print "<form method=\"post\" action=\"./set_batch.cgi\">";
print "  <input type=\"hidden\" name=\"project\" value=\"$project\">";
print "  <input type=\"hidden\" name=\"jobnet\" value=\"$jobnet\">";
print "  <div class=\"large-8 columns\">";
if ( $batch_name eq new ){
  print "  <label>Batch Name</label>";
  print "  <input type=\"text\" name=\"batch_name\" value=\"\" placeholder=\"XXX.sh\" required>";
}else{
  print "  <input type=\"hidden\" name=\"batch_name\" value=\"$batch_name\">";
  print "<h4>$batch_name</h4>";
}
print "  <label>#Code</label>";
print "  <textarea placeholder=\"\" name=\"code\" value=\"`cat ${home}/project/${project}/${jobnet}/bat/${batch_name}`\" rows=\"20\" style=\"height:auto;\">";
system("cat ${home}/project/${project}/${jobnet}/bat/${batch_name}");
print "</textarea>";
print "  <input type=\"submit\" class=\"small button\" value=\"Set Batch\">";
print "  </div>";
print "</form>";
print "<div class=\"large-4 columns\">";
print " &nbsp;&nbsp;&nbsp;<a href=\"./batch_upload_form.cgi?${project},${jobnet}\">Add Batch by Upload</a>";
print "<br></br>";
print " &nbsp;&nbsp;&nbsp;<a href=\"./set_jobnet_form.cgi?${project},${jobnet}\">Back to jobnet</a>";
print "<br></br>";
print " &nbsp;&nbsp;&nbsp;<a href=\"./delete_batch.cgi?${project},${jobnet},${batch_name}\">Delete This batch</a>";
print "  </div>";

system("cat ../elements/footer");
