public function download_solution($task_set_id, $file) { if ($this->usermanager->is_student_session_valid() && !Restriction::check_restriction_for_ip_address() || $this->usermanager->is_teacher_session_valid()) { $task_set = new Task_set(); $task_set->get_by_id(intval($task_set_id)); if ($task_set->exists()) { $filename = decode_from_url($file); $file_info = $task_set->get_specific_file_info($filename); if ($file_info !== FALSE) { $allow_download = TRUE; if (!$this->usermanager->is_teacher_session_valid()) { $solution_version = new Solution_version(); $solution_version->where('version', $file_info['version']); $solution_version->where_related('solution/task_set', 'id', $task_set_id); $solution_version->get(); if ($solution_version->exists()) { if ((bool) $solution_version->download_lock) { $allow_download = FALSE; } } } if ($allow_download) { $log = new Log(); if (!$this->usermanager->is_teacher_session_valid()) { $log->add_student_solution_download_log($this->lang->line('tasks_log_message_student_solution_download'), $this->usermanager->get_student_id(), $filename, $task_set->id); } $filename = $file_info['file_name'] . '_' . $file_info['version'] . '.zip'; $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime_type = finfo_file($finfo, $file_info['filepath']); finfo_close($finfo); header('Content-Description: File Transfer'); header('Content-Type: ' . $mime_type); header('Content-Disposition: attachment; filename=' . $filename); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file_info['filepath'])); ob_clean(); flush(); $f = fopen($file_info['filepath'], 'r'); while (!feof($f)) { echo fread($f, 1024); } fclose($f); exit; } else { $this->parser->parse('frontend/tasks/download_solution.tpl', array('version_download_disabled' => TRUE)); } } else { $this->output->set_status_header(404, 'Not found'); } } else { $this->output->set_status_header(404, 'Not found'); } } else { $this->parser->parse('frontend/tasks/download_solution.tpl'); } }
public function get_solution_version_metadata($task_set_id, $solution_id, $solution_file) { $task_set = new Task_set(); $task_set->where_related('solution', 'id', $solution_id); $task_set->include_related('solution/student', 'id'); $task_set->get_by_id($task_set_id); if ($task_set->exists()) { $file_name = decode_from_url($solution_file); $file_info = $task_set->get_specific_file_info($file_name); $this->parser->assign('file_last_modified', $file_info['last_modified']); $solution_version = new Solution_version(); $solution_version->where('version', $file_info['version']); $solution_version->where_related('solution', 'id', $solution_id); $solution_version->get(); if (!$solution_version->exists()) { $solution_version = new Solution_version(); $solution_version->version = (int) $file_info['version']; $solution_version->solution_id = (int) $solution_id; $solution_version->save(); } //$solution_version->check_last_query(); $this->parser->assign('solution_version', $solution_version); $this->parser->assign('task_set', $task_set); } $this->parser->parse('backend/solutions/version_metadata.tpl'); }
public function task($task_set_id_url = NULL, $task_id_url = NULL) { $this->_add_mathjax(); $task_set_id = url_get_id($task_set_id_url); $task_id = url_get_id($task_id_url); $this->_initialize_student_menu(); $this->_select_student_menu_pagetag('projects'); $this->parser->add_css_file('frontend_projects.css'); $this->parser->add_js_file('projects/task.js'); $this->_add_prettify(); $this->_add_jquery_countdown(); $this->parser->assign('max_filesize', compute_size_with_unit(intval($this->config->item('maximum_solition_filesize') * 1024))); $cache_id = $this->usermanager->get_student_cache_id('task_set_' . $task_set_id . '|task_' . $task_id); if (!$this->_is_cache_enabled() || !$this->parser->isCached($this->parser->find_view('frontend/projects/task.tpl'), $cache_id)) { $project_all = $this->get_task_set($task_set_id, $course, $student); $project = $this->filter_valid_task_sets($project_all); if ($course->exists()) { $this->lang->init_overlays('task_sets', $project, array('name')); $project = count($project) == 1 ? $project[0] : new Task_set(); $this->parser->assign('project', $project); $task = $project->task; $task->include_join_fields()->order_by('`task_task_set_rel`.`sorting`', 'asc'); $task->get_by_id($task_id); $project_selection = new Project_selection(); $project_selection->where('task_set_id', $project->id); $project_selection->where('student_id', $this->usermanager->get_student_id()); $project_selection->where('task_id', $task->id); $project_selection->get(); $students = new Student(); $students->where_related('project_selection', 'task_set_id', $project->id); $students->where_related('project_selection', 'task_id', $task->id); $students->get_iterated(); $solution_versions = new Solution_version(); $solution_versions->where_related('solution/task_set', 'id', $task_set_id); $solution_versions->where_related('solution', 'student_id', $this->usermanager->get_student_id()); $query = $solution_versions->get_raw(); $versions_metadata = array(); if ($query->num_rows()) { foreach ($query->result() as $row) { $versions_metadata[$row->version] = clone $row; } } $query->free_result(); $this->parser->assign('task', $task); $this->parser->assign('students', $students); $this->parser->assign('project_selection', $project_selection); $this->parser->assign('solution_files', $project->get_student_files($student->id)); $this->parser->assign('versions_metadata', $versions_metadata); } $this->parser->assign(array('course' => $course)); } $this->parser->parse('frontend/projects/task.tpl', array(), FALSE, $this->_is_cache_enabled(), $cache_id); }