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 solution_version_switch_download_lock($solution_version_id) { $this->_transaction_isolation(); $this->db->trans_begin(); $output = new stdClass(); $output->status = FALSE; $output->value = FALSE; $output->message = $this->lang->line('admin_solutions_valuation_version_metadata_download_lock_error_cant_found'); $solution_version = new Solution_version(); $solution_version->include_related('solution'); $solution_version->get_by_id((int) $solution_version_id); if ($solution_version->exists()) { $output->value = $solution_version->download_lock == 0 ? FALSE : TRUE; $solution_version->download_lock = $solution_version->download_lock == 0 ? 1 : 0; if ($solution_version->save()) { $output->value = $solution_version->download_lock == 0 ? FALSE : TRUE; $output->status = TRUE; if ($output->value) { $output->message = $this->lang->line('admin_solutions_valuation_version_metadata_download_lock_enabled'); } else { $output->message = $this->lang->line('admin_solutions_valuation_version_metadata_download_lock_disabled'); } $this->db->trans_commit(); $this->_action_success(); $this->output->set_internal_value('student_id', (int) $solution_version->solution_student_id); } else { $output->message = $this->lang->line('admin_solutions_valuation_version_metadata_download_lock_error_cant_save'); $this->db->trans_rollback(); } } $this->output->set_content_type('application/json'); $this->output->set_output(json_encode($output)); }
public function upload_solution($task_set_id_url, $task_id_url) { $task_set_id = url_get_id($task_set_id_url); $task_id = url_get_id($task_id_url); $this->_transaction_isolation(); $this->db->trans_begin(); $date = date('Y-m-d H:i:s'); $student = new Student(); $student->get_by_id($this->usermanager->get_student_id()); $course = new Course(); $course->where_related('active_for_student', 'id', $student->id); $course->where_related('participant', 'student_id', $student->id); $course->where_related('participant', 'allowed', 1); $course->include_related('period', 'name'); $course->get(); $task_set = new Task_set(); $task_set->where_related($course); $task_set->where('published', 1); $task_set->group_start(); $task_set->where('publish_start_time <=', $date); $task_set->or_where('publish_start_time', NULL); $task_set->group_end(); $task_set->get_by_id($task_set_id); $task = $task_set->task->include_join_fields()->get_by_id($task_id); $project_selection = new Project_selection(); $project_selection->where_related($student); $project_selection->where_related($task_set); $project_selection->where_related($task); $project_selection->get(); if ($student->exists() && $course->exists() && $task_set->exists() && $task->exists() && $project_selection->exists()) { if ($date <= $task_set->upload_end_time) { $config['upload_path'] = 'private/uploads/solutions/task_set_' . intval($task_set_id) . '/'; $config['allowed_types'] = 'zip'; $config['max_size'] = intval($this->config->item('maximum_solition_filesize')); $current_version = $task_set->get_student_file_next_version($student->id); $config['file_name'] = $student->id . '_' . $this->normalize_student_name($student) . '_' . substr(md5(time() . rand(-500000, 500000)), 0, 4) . '_' . $current_version . '.zip'; @mkdir($config['upload_path'], DIR_READ_MODE); $this->load->library('upload', $config); if ($this->upload->do_upload('file')) { $solution = new Solution(); $solution->where('task_set_id', $task_set->id); $solution->where('student_id', $student->id); $solution->get(); $revalidate = 1; if ($solution->exists()) { $solution->ip_address = $_SERVER["REMOTE_ADDR"]; $solution->revalidate = $revalidate; $solution->save(); } else { $solution = new Solution(); $solution->ip_address = $_SERVER["REMOTE_ADDR"]; $solution->revalidate = $revalidate; $solution->save(array('student' => $student, 'task_set' => $task_set)); } $solution_version = new Solution_version(); $solution_version->ip_address = $_SERVER["REMOTE_ADDR"]; $solution_version->version = $current_version; $solution_version->save($solution); if ($this->db->trans_status()) { $log = new Log(); $log->add_student_solution_upload_log(sprintf($this->lang->line('projects_task_solution_upload_log_message'), $config['file_name']), $student, $solution->id); $this->db->trans_commit(); $this->messages->add_message('lang:projects_task_solution_uploaded', Messages::MESSAGE_TYPE_SUCCESS); $this->_action_success(); $this->output->set_internal_value('task_set_id', $solution->task_set_id); $this->output->set_internal_value('task_id', $task->id); } else { $this->db->trans_rollback(); @unlink($config['upload_path'] . $config['file_name']); $this->messages->add_message('lang:projects_task_solution_canceled_due_db_error', Messages::MESSAGE_TYPE_ERROR); } redirect(create_internal_url('projects/task/' . $task_set_id_url . '/' . $task_id_url)); } else { $this->db->trans_rollback(); $this->parser->assign('file_error_message', $this->upload->display_errors('', '')); $this->task($task_set_id_url, $task_id_url); } } else { $this->db->trans_rollback(); $this->messages->add_message('lang:projects_task_solution_upload_time_error', Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('projects/task/' . $task_set_id_url . '/' . $task_id_url)); } } else { $this->db->trans_rollback(); $this->messages->add_message('lang:projects_task_solution_database_data_wrong_error', Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('projects/task/' . $task_set_id_url . '/' . $task_id_url)); } }