123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- require_once('../../../../config.php');
- require_once('../../locallib.php');
- require_once('../../lib.php');
- require_once('submission_form.php');
- require_once('submission_form_functions.php');
- $cmid = required_param('cmid', PARAM_INT);
- $id = optional_param('id', 0, PARAM_INT);
- $subid = optional_param('subid', -1, PARAM_INT);
- $cm = get_coursemodule_from_id('gradeimporter', $cmid, 0, false, MUST_EXIST);
- $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
- $gradeimporter = $DB->get_record('gradeimporter', array('id' => $cm->instance), '*', MUST_EXIST);
- $context = context_module::instance($cm->id);
- $url = new moodle_url('/mod/gradeimporter/forms/submission/submission.php', array('cmid' => $cm->id));
- if (!empty($id)) {
- $url->param('id', $id);
- }
- $PAGE->set_url($url);
- require_login($course, false, $cm);
- require_capability('mod/gradeimporter:edit', $context);
- if (!isset($entry)) {
-
- $entry = new stdClass();
- $entry->id = null;
- }
- $entry->cmid = $cm->id;
- $maxbytes = $course->maxbytes;
- $filemanageroptions = array('subdirs' => 0,
- 'maxbytes' => $maxbytes,
- 'areamaxbytes' => 10485760,
- 'maxfiles' => 1,
- 'accepted_types' => array('.csv', '.zip')
- );
- $entry = file_prepare_standard_filemanager($entry, 'submissionfiles', $filemanageroptions, $context,
- 'mod_gradeimporter', 'submissionfiles', $entry->id);
- $mform = new mod_gradeimporter_submission_form(null, array('submission' => $entry,
- 'filemanageroptions' => $filemanageroptions,
- 'gradeimporterid' => $gradeimporter->id,
- 'cmid' => $cm->id
- )
- );
- if ($mform->is_cancelled()) {
-
- $viewurl = new moodle_url('/mod/gradeimporter/view.php', ['id' => $cm->id, 'edit' => 1]);
- redirect($viewurl);
- } else if ($formdata = $mform->get_data()) {
- validate_formdata($formdata);
-
- $entry = create_submission($formdata, $gradeimporter->id, $USER->id);
-
- $entry = file_postupdate_standard_filemanager($entry, 'submissionfiles',
- $filemanageroptions, $context, 'mod_gradeimporter',
- 'submissionfiles', $entry->id);
- store_files($context, $cm, $entry);
-
- $viewurl = new moodle_url('/mod/gradeimporter/view.php', ['id' => $cm->id, 'edit' => 1]);
- redirect($viewurl);
- } else {
-
-
- if ($subid != -1) {
-
-
- $subdata = $DB->get_record('gradeimporter_submission', array('id' => $subid));
- $subdata->description = array('text' => $subdata->description,
- 'format' => $subdata->descriptionformat
- );
- $mform->set_data($subdata);
- }
- $PAGE->set_title($gradeimporter->name);
- $PAGE->set_heading($course->fullname);
- echo $OUTPUT->header();
- echo $OUTPUT->heading(format_string($gradeimporter->name), 2);
- $mform->display();
- echo $OUTPUT->footer();
- }
|