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

$home = "/usr/local/e-cron";
$jobnet = param("jobnet");
$project = param("project");
$job_order = param("job_order");
$mail_addr = param("mail_addr");
$schedule = param("schedule");
$input_message = param("input_message");
$output_message = param("output_message");
$execution_servers = param("execution_servers");
$spare_server = param("spare_server");
$ssh_port = param("ssh_port");
$job_exec_user = param("job_exec_user");
$tmp_file = "/tmp/${project}${jobnet}jobnetprof.tmp";

$schedule = quotemeta($schedule);

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 setting</a>";
print "<br></br>";
print "&nbsp;&nbsp;&nbsp;<a href=\"./set_status_form.cgi?${project},${jobnet}\">Enable/Disable operation</a>";


# update jobnet
open(JOBPROF,">$tmp_file");
print JOBPROF "JOB_ORDER\=\"$job_order\"" ;
print JOBPROF "\n" ;
print JOBPROF "MAIL_ADDR\=\"$mail_addr\"" ;
print JOBPROF "\n" ;
print JOBPROF "INPUT_MESSAGE\=\"$input_message\"" ;
print JOBPROF "\n" ;
print JOBPROF "OUTPUT_MESSAGE\=\"$output_message\"" ;
print JOBPROF "\n" ;
print JOBPROF "EXECUTION_SERVERS\=\"$execution_servers\"" ;
print JOBPROF "\n" ;
print JOBPROF "SPARE_SERVER\=\"$spare_server\"" ;
print JOBPROF "\n" ;
print JOBPROF "JOB_EXEC_USER\=\"$job_exec_user\"" ;
print JOBPROF "\n" ;
#print JOBPROF "SCHEDULE:$schedule" ;
close(JOBPROF);

system("echo SCHEDULE:$schedule >> $tmp_file");
system("sudo -u ejobmgr cp $tmp_file $home/project/$project/$jobnet/jobnet.prof");
system("sudo -u ejobmgr chmod 755 $home/project/$project/$jobnet/jobnet.prof");

# distribute jobnet
print "<br></br>";
print "<div style=\"padding-left:12px;\">";
print "<pre>";
system("echo \"#$home/bin/for_cgi/distribute_jobnet $project/$jobnet $ssh_port\"");
system("sudo -u ejobmgr $home/bin/for_cgi/distribute_jobnet $project/$jobnet $ssh_port");
print "</pre>";
print "</div>";
system("cat ../elements/footer");
system("rm $tmp_file");

