$timestr = time_str(time(0));
db_init();
$workunitid = get_int('workunitid');
$workunit = mysql_fetch_object(mysql_query("SELECT * FROM workunit WHERE id=" . $workunitid));
$job = mysql_fetch_object(mysql_query("SELECT * FROM q_list WHERE workunit=" . $workunit->id));
$user = mysql_fetch_object(mysql_query("SELECT * FROM user WHERE id=" . $job->user));
$title = "Job '" . workunit_name($workunit) . "' (" . $workunitid . ") of " . $user->name . " at " . $timestr;
$jobname = workunit_name($workunit);
$config = get_config();
$jobapplication = mysql_fetch_object(mysql_query("SELECT * FROM app WHERE id=" . $workunit->appid));
$jobapplicationname = $jobapplication->name;
$jobapplicationfriendlyname = $jobapplication->user_friendly_name;
$jobfops = $workunit->rsc_fpops_est;
$jobmem = $workunit->rsc_memory_bound;
$jobdisk = $workunit->rsc_disk_bound;
$jobstatusstring = workunit_status_string($workunit);
$coloredjobstatusstring = $jobstatusstring;
if ($jobstatusstring == "running") {
    $coloredjobstatusstring = "<font color='green'><b>" . $jobstatusstring . "</b></font>";
}
if ($jobstatusstring == "queued") {
    $coloredjobstatusstring = "<font color='blue'><b>" . $jobstatusstring . "</b></font>";
}
if ($jobstatusstring == "ERROR") {
    $coloredjobstatusstring = "<font color='red'><b>" . $jobstatusstring . "</b></font>";
}
$jobsubmittime = time_str($workunit->create_time);
$workunitidstring = "<a href=db_action.php?table=workunit&id=" . $job->workunit . ">" . $job->workunit . "</a>";
$jobinputurl = parse_element($workunit->xml_doc, "<file_info>");
$jobinputurl = parse_element($jobinputurl, "<url>");
$jobinput = parse_element($workunit->xml_doc, "<file_info>");
     row1("You have " . $njobs . " jobs listed !<br>");
 } else {
     row1("You have " . $njobs . " job listed !<br>");
 }
 end_table();
 start_table();
 row5("<b>Job #</b>", "<b>Job submit time</b>", "<b>Job status</b>", "<b>Job name</b>", "<b>Job ID</b>");
 for ($jobindex = 0; $jobindex < $njobs; ++$jobindex) {
     $job = mysql_fetch_object($alljobs);
     $workunitquery = mysql_query("SELECT * FROM workunit WHERE id=" . $job->workunit);
     if ($workunitquery) {
         $workunit = mysql_fetch_object($workunitquery);
         if ($workunit) {
             $prefix = '<a href="queue_show_job.php?workunitid=' . $job->workunit . '">';
             $workunitname = $prefix . workunit_name($workunit) . '</a>';
             $status = workunit_status_string($workunit);
             if ($status == "running") {
                 $status = "<font color='green'><b>" . $status . "</b></font>";
             }
             if ($status == "queued") {
                 $status = "<font color='blue'><b>" . $status . "</b></font>";
             }
             if ($status == "ERROR") {
                 $status = "<font color='red'><b>" . $status . "</b></font>";
             }
             $jobsubmittime = time_str($workunit->create_time);
         } else {
             $workunitname = "<font color='red'>WORKUNIT NOT FOUND IN DATABASE</font>";
             $status = "<font color='red'>UNKNOWN</font>";
             $jobsubmittime = "<font color='red'>UNKNOWN</font>";
         }
//  }
// }
system($command_to_submit);
unlink($temporaryinputfile);
$workunit = mysql_fetch_object(mysql_query("SELECT * FROM workunit WHERE name='" . $extendedjobname . "'"));
if (!$workunit) {
    exit_with_text("Error during submition of the workunit associated with your job !");
}
$qlistentry = mysql_query("INSERT INTO q_list VALUES('','" . $user->id . "','" . $workunit->id . "')");
if (!$qlistentry) {
    exit_with_text("Error during submition of your job !");
}
$jobidlink = '<a href="queue_show_job.php?workunitid=' . $workunit->id . '">' . $jobname . ' (' . $workunit->id . ')</a>';
start_table();
row1("Your job has been submitted !");
row2("Job status: ", workunit_status_string($workunit));
row2("Job id: ", $jobidlink);
row1("Commands");
row2("Status of this job: ", '<a href="queue_show_job.php?workunitid=' . $workunit->id . '">Show job status</a>');
$max_jobs = max_nr_of_jobs_of_user($user);
$njobs = nr_of_jobs_of_user($user);
if ($njobs < $max_jobs) {
    if ($max_jobs - $njobs > 1) {
        $line = "You can submit " . ($max_jobs - $njobs) . " more jobs: ";
    } else {
        $line = "You can submit one more job: ";
    }
    row2($line, '<a href="queue_new_job_form.php">Submit another job</a>');
}
row2("", '<a href="queue_show_queue.php">Go back to your queue</a>');
row2("", '<a href="logout.php">Log out</a>');