Example #1
0
 /**
  * Compressing and downloading test data and descriptions of an assignment to the browser
  */
 public function downloadtestsdesc($assignment_id = FALSE)
 {
     if ($assignment_id === FALSE) {
         show_404();
     }
     if ($this->user->level <= 1) {
         // permission denied
         show_404();
     }
     $this->load->library('zip');
     $assignment = $this->assignment_model->assignment_info($assignment_id);
     $number_of_problems = $assignment['problems'];
     $root_path = rtrim($this->settings_model->get_setting('assignments_root'), '/') . "/assignment_{$assignment_id}";
     for ($i = 1; $i <= $number_of_problems; $i++) {
         $path = "{$root_path}/p{$i}/in";
         $this->zip->read_dir($path, FALSE, $root_path);
         $path = "{$root_path}/p{$i}/out";
         $this->zip->read_dir($path, FALSE, $root_path);
         $path = "{$root_path}/p{$i}/tester.cpp";
         if (file_exists($path)) {
             $this->zip->add_data("p{$i}/tester.cpp", file_get_contents($path));
         }
         $pdf_files = glob("{$root_path}/p{$i}/*.pdf");
         if ($pdf_files) {
             $path = $pdf_files[0];
             $this->zip->add_data("p{$i}/" . shj_basename($path), file_get_contents($path));
         }
         $path = "{$root_path}/p{$i}/desc.html";
         if (file_exists($path)) {
             $this->zip->add_data("p{$i}/desc.html", file_get_contents($path));
         }
         $path = "{$root_path}/p{$i}/desc.md";
         if (file_exists($path)) {
             $this->zip->add_data("p{$i}/desc.md", file_get_contents($path));
         }
     }
     $pdf_files = glob("{$root_path}/*.pdf");
     if ($pdf_files) {
         $path = $pdf_files[0];
         $this->zip->add_data(shj_basename($path), file_get_contents($path));
     }
     $this->zip->download("assignment{$assignment_id}_tests_desc_" . date('Y-m-d_H-i', shj_now()) . '.zip');
 }
Example #2
0
 /**
  * Download pdf file of an assignment (or problem) to browser
  */
 public function pdf($problem_id)
 {
     // Find pdf file
     $pdf_dir = "/var/www/html/pdf/p{$problem_id}/*.pdf";
     $pdf_files = glob($pdf_dir);
     if (!$pdf_files) {
         show_error("File not found");
     }
     // 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);
 }