Skip to content

Commit

Permalink
Merge pull request #16 from athlonneo/Version-1
Browse files Browse the repository at this point in the history
Integrated Development Environment
  • Loading branch information
pascalalfadian authored Jan 3, 2023
2 parents 263df79 + eff318e commit 6a76fac
Show file tree
Hide file tree
Showing 1,247 changed files with 151,910 additions and 13,889 deletions.
7 changes: 7 additions & 0 deletions application/config/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,12 @@
define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code

/*Code editor related constants*/
define('EDITOR_FILE_NAME', "editor");
define('EDITOR_FILE_EXT', "txt");
define('EDITOR_IN_NAME', "exec_in");
define('EDITOR_OUT_NAME', "exec_out");
define('EDITOR_SUBMIT_ID', 0);

/* End of file constants.php */
/* Location: ./application/config/constants.php */
55 changes: 50 additions & 5 deletions application/controllers/Assignments.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ public function select()
/**
* Download pdf file of an assignment (or problem) to browser
*/
public function pdf($assignment_id, $problem_id = NULL)
public function pdf($assignment_id, $problem_id = NULL, $no_download = FALSE)
{
$finishtime = strtotime($this->assignment_model->assignment_info($assignment_id)['finish_time']);
$starttime = strtotime($this->assignment_model->assignment_info($assignment_id)['start_time']);
$extratime = $this->assignment_model->assignment_info($assignment_id)['extra_time'];

// Find pdf file
if ($problem_id === NULL)
if ($problem_id === NULL || $problem_id === "null")
$pattern = rtrim($this->settings_model->get_setting('assignments_root'),'/')."/assignment_{$assignment_id}/*.pdf";
else
$pattern = rtrim($this->settings_model->get_setting('assignments_root'),'/')."/assignment_{$assignment_id}/p{$problem_id}/*.pdf";
Expand All @@ -120,10 +120,19 @@ public function pdf($assignment_id, $problem_id = NULL)
elseif ( shj_now() < $starttime)
show_error('Selected assignment has not started.');

// Download the file to browser
$this->load->helper('download')->helper('file');


$filename = shj_basename($pdf_files[0]);
force_download($filename, file_get_contents($pdf_files[0]), TRUE);
// Download the file to browser
if($no_download === FALSE){
$this->load->helper('download')->helper('file');
force_download($filename, file_get_contents($pdf_files[0]), TRUE);
}
else{
$content = file_get_contents($pdf_files[0]);
header('Content-Type: application/pdf');
die($content);
}
}


Expand Down Expand Up @@ -574,7 +583,43 @@ public function edit($assignment_id)
// redirect to add function
$this->add();
}



// ------------------------------------------------------------------------



/**
* Check PDF File Availability
*/
public function pdfCheck($assignment_id, $problem_id = NULL)
{
$finishtime = strtotime($this->assignment_model->assignment_info($assignment_id)['finish_time']);
$starttime = strtotime($this->assignment_model->assignment_info($assignment_id)['start_time']);
$extratime = $this->assignment_model->assignment_info($assignment_id)['extra_time'];

// Find pdf file
if ($problem_id === NULL || $problem_id === "null")
$pattern = rtrim($this->settings_model->get_setting('assignments_root'),'/')."/assignment_{$assignment_id}/*.pdf";
else
$pattern = rtrim($this->settings_model->get_setting('assignments_root'),'/')."/assignment_{$assignment_id}/p{$problem_id}/*.pdf";
$pdf_files = glob($pattern);

if ( ! $pdf_files )
$response = json_encode(array(status=>FALSE));
elseif (!$this->assignment_model->assignment_info($assignment_id)['open'])
$response = json_encode(array(status=>FALSE));
elseif ( ! $this->assignment_model->is_participant($this->assignment_model->assignment_info($assignment_id)['participants'],$this->user->username) )
$response = json_encode(array(status=>FALSE));
elseif ( shj_now() > $finishtime + $extratime)
$response = json_encode(array(status=>FALSE));
elseif ( shj_now() < $starttime)
$response = json_encode(array(status=>FALSE));
else
$response = json_encode(array(status=>TRUE));

echo $response;
}

}
16 changes: 11 additions & 5 deletions application/controllers/Queueprocess.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function run()
$assignment = $queue_item['assignment'];
$assignment_info = $this->assignment_model->assignment_info($assignment);
$problem = $this->assignment_model->problem_info($assignment, $queue_item['problem']);
$type = $queue_item['type']; // $type can be 'judge' or 'rejudge'
$type = $queue_item['type']; // $type can be 'judge', 'rejudge', or 'exec'

$submission = $this->submit_model->get_submission($username, $assignment, $problem['id'], $submit_id);

Expand Down Expand Up @@ -86,7 +86,14 @@ public function run()
$op4 = $this->settings_model->get_setting('enable_py3_shield');
$op5 = $this->settings_model->get_setting('enable_java_policy');
$op6 = $assignment_info['javaexceptions'];

if($type === 'exec') {
$exec_only = TRUE;
$op7 = 1;
}
else {
$op7 = 0;
}

if ($file_type === 'c' OR $file_type === 'cpp')
$time_limit = $problem['c_time_limit']/1000;
elseif ($file_type === 'java')
Expand All @@ -101,7 +108,7 @@ public function run()
$diff_arg = $problem['diff_arg'];
$output_size_limit = $this->settings_model->get_setting('output_size_limit') * 1024;

$cmd = "cd $tester_path;\n./tester.sh $problemdir ".escapeshellarg($username).' '.escapeshellarg($main_filename).' '.escapeshellarg($raw_filename)." $file_type $time_limit $time_limit_int $memory_limit $output_size_limit $diff_cmd $diff_arg $op1 $op2 $op3 $op4 $op5 $op6";
$cmd = "cd $tester_path;\n./tester.sh $problemdir ".escapeshellarg($username).' '.escapeshellarg($main_filename).' '.escapeshellarg($raw_filename)." $file_type $time_limit $time_limit_int $memory_limit $output_size_limit $diff_cmd $diff_arg $op1 $op2 $op3 $op4 $op5 $op6 $op7";

file_put_contents($userdir.'/log', $cmd);

Expand Down Expand Up @@ -132,8 +139,7 @@ public function run()
}

//reconnect to database incase we have run test for a long time.
$this->db->reconnect();

$this->db->reconnect();
// Save the result
$this->queue_model->save_judge_result_in_db($submission, $type);

Expand Down
Loading

0 comments on commit 6a76fac

Please sign in to comment.