Skip to content

Commit

Permalink
Merge pull request #12 from athlonneo/br3
Browse files Browse the repository at this point in the history
issue #10, #11
  • Loading branch information
pascalalfadian authored Nov 24, 2021
2 parents 9f8d240 + 4b40ede commit eff318e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 14 deletions.
41 changes: 36 additions & 5 deletions application/controllers/Assignments.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ public function pdf($assignment_id, $problem_id = NULL, $no_download = FALSE)
else{
$content = file_get_contents($pdf_files[0]);
header('Content-Type: application/pdf');
header('Content-Length: ' . strlen($content));
header('Content-Disposition: inline; filename="'.$filename.'"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression','0');
die($content);
}
}
Expand Down Expand Up @@ -588,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;
}

}
4 changes: 0 additions & 4 deletions application/controllers/Submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class Submit extends CI_Controller
private $ext; //uploaded file extension
private $file_name; //uploaded file name without extension
private $coefficient;
private $editor_file_name;
private $editor_file_ext;
private $editor_in_name;
private $editor_out_name;

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

Expand Down
24 changes: 19 additions & 5 deletions application/views/pages/submit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,21 @@
<link rel="stylesheet" type='text/css' href="{{ base_url('assets/styles/submit.css') }}"/>
<script>
shj.p={};
{{ problems_js|raw }}
{{ problems_js|raw }};
$.ajax({
url: "{{ site_url('assignments/pdfCheck/' ~ user.selected_assignment.id) }}",
cache: false,
success: function(data){
data = JSON.parse(data);
if(data.status){
$("#pdf_viewer").attr('src', "{{ base_url('assets/pdfjs/web/viewer.html?file=') ~ site_url('assignments/pdf/' ~ user.selected_assignment.id ~ '/null/true') }}");
$("#pdf_viewer").show();
}
},
error: function (error){
console.error(error);
},
});
</script>
<script src={{ base_url('assets/ace/ace.js') }}></script>
<script type='text/javascript' src="{{ base_url("assets/js/shj_submit.js") }}"></script>
Expand Down Expand Up @@ -68,7 +82,7 @@
<br>
<details>
<summary>Code, Test, and Submit using built-in editor</summary>
<iframe id="pdf_viewer" src={{ base_url('assets/pdfjs/web/viewer.html?file=') ~ site_url('assignments/pdf/' ~ user.selected_assignment.id ~ '/null/true')}} ></iframe>
<iframe id="pdf_viewer" src="" style="display: none"></iframe>
<div id="ide_wrap">
<fieldset id="editor_wrap">
<legend>Code</legend>
Expand All @@ -84,9 +98,9 @@
</fieldset>
</div>
<br>
<button type="button" id="editor_save" disabled>Save</button>
<button type="button" id="editor_execute" disabled>Save & Execute</button>
<button type="button" id="editor_submit" disabled>Save & Submit</button>
<button type="button" class="sharif_input" id="editor_save" disabled>Save</button>
<button type="button" class="sharif_input" id="editor_execute" disabled>Save &amp; Execute</button>
<button type="button" class="sharif_input" id="editor_submit" disabled>Save &amp; Submit</button>
<span id="ajax_status"></span>
</details>
{% endif %}
Expand Down
6 changes: 6 additions & 0 deletions assets/js/shj_submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ $(document).ready(function(){
editor.session.setMode("ace/mode/c_cpp");
disableEditor(false);
}
else if(this.value.toLowerCase().includes("txt")){
editor.session.setMode("ace/mode/plain_text");
disableEditor(false);
$("#editor_execute").prop("disabled", true);
$("#editor_input").prop("disabled", true);
}
else{
editor.session.setMode("ace/mode/plain_text");
disableEditor(true);
Expand Down

0 comments on commit eff318e

Please sign in to comment.