2009-07-07 02:26:36 +00:00
|
|
|
<?php
|
2007-05-24 02:16:31 +00:00
|
|
|
|
2009-07-07 02:26:36 +00:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2007-07-24 09:30:46 +00:00
|
|
|
|
2010-06-04 08:37:17 +00:00
|
|
|
require_once('../../../config.php');
|
|
|
|
require_once('lib.php');
|
|
|
|
require_once('grade_import_form.php');
|
2007-05-24 02:16:31 +00:00
|
|
|
|
|
|
|
$id = required_param('id', PARAM_INT); // course id
|
|
|
|
|
2010-05-05 03:27:22 +00:00
|
|
|
$PAGE->set_url(new moodle_url('/grade/import/xml/index.php', array('id'=>$id)));
|
|
|
|
$PAGE->set_pagelayout('admin');
|
2009-10-15 06:58:21 +00:00
|
|
|
|
2008-06-01 17:59:13 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$id))) {
|
2017-06-23 10:22:24 +08:00
|
|
|
print_error('invalidcourseid');
|
2007-07-24 09:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require_login($course);
|
2012-07-24 14:04:40 +08:00
|
|
|
$context = context_course::instance($id);
|
2007-07-24 09:30:46 +00:00
|
|
|
require_capability('moodle/grade:import', $context);
|
|
|
|
require_capability('gradeimport/xml:view', $context);
|
2007-05-24 02:16:31 +00:00
|
|
|
|
2007-07-17 08:40:35 +00:00
|
|
|
// print header
|
2007-07-17 03:32:10 +00:00
|
|
|
$strgrades = get_string('grades', 'grades');
|
MDL-23071 standardising gradebook plugin names
AMOS BEGIN
MOV [modulename,gradeimport_csv],[pluginname,gradeimport_csv]
MOV [modulename,gradeimport_xml],[pluginname,gradeimport_xml]
MOV [modulename,gradeexport_ods],[pluginname,gradeexport_ods]
MOV [modulename,gradeexport_txt],[pluginname,gradeexport_txt]
MOV [modulename,gradeexport_xls],[pluginname,gradeexport_xls]
MOV [modulename,gradeexport_xml],[pluginname,gradeexport_xml]
MOV [modulename,gradereport_grader],[pluginname,gradereport_grader]
MOV [modulename,gradereport_outcomes],[pluginname,gradereport_outcomes]
MOV [modulename,gradereport_overview],[pluginname,gradereport_overview]
MOV [modulename,gradereport_user],[pluginname,gradereport_user]
AMOS END
2010-07-04 13:08:11 +00:00
|
|
|
$actionstr = get_string('pluginname', 'gradeimport_xml');
|
2007-08-01 06:47:35 +00:00
|
|
|
|
2007-09-27 06:51:54 +00:00
|
|
|
if (!empty($CFG->gradepublishing)) {
|
|
|
|
$CFG->gradepublishing = has_capability('gradeimport/xml:publish', $context);
|
|
|
|
}
|
|
|
|
|
2014-03-13 09:35:43 -04:00
|
|
|
$mform = new grade_import_form(null, array('acceptedtypes' => array('.xml')));
|
2007-05-24 02:16:31 +00:00
|
|
|
|
2008-06-09 16:53:30 +00:00
|
|
|
if ($data = $mform->get_data()) {
|
2007-05-24 02:16:31 +00:00
|
|
|
// Large files are likely to take their time and memory. Let PHP know
|
|
|
|
// that we'll take longer, and that the process should be recycled soon
|
|
|
|
// to free up memory.
|
2013-10-15 13:22:19 +01:00
|
|
|
core_php_time_limit::raise();
|
2010-10-19 10:13:15 +00:00
|
|
|
raise_memory_limit(MEMORY_EXTRA);
|
2007-05-24 02:16:31 +00:00
|
|
|
|
2007-09-26 18:11:48 +00:00
|
|
|
if ($text = $mform->get_file_content('userfile')) {
|
2015-07-14 18:28:40 -03:00
|
|
|
print_grade_page_head($COURSE->id, 'import', 'xml',
|
|
|
|
get_string('importxml', 'grades'), false, false, true, 'importxml', 'gradeimport_xml');
|
2007-06-11 09:00:17 +00:00
|
|
|
|
2007-09-26 18:11:48 +00:00
|
|
|
$error = '';
|
|
|
|
$importcode = import_xml_grades($text, $course, $error);
|
|
|
|
if ($importcode) {
|
2007-10-07 10:22:21 +00:00
|
|
|
grade_import_commit($id, $importcode, $data->feedback, true);
|
2009-08-06 14:12:17 +00:00
|
|
|
echo $OUTPUT->footer();
|
2007-09-26 18:11:48 +00:00
|
|
|
die;
|
|
|
|
} else {
|
2009-08-18 04:59:57 +00:00
|
|
|
echo $OUTPUT->notification($error);
|
|
|
|
echo $OUTPUT->continue_button($CFG->wwwroot.'/grade/index.php?id='.$course->id);
|
2009-08-06 14:12:17 +00:00
|
|
|
echo $OUTPUT->footer();
|
2007-09-26 18:11:48 +00:00
|
|
|
die;
|
2007-07-18 19:56:07 +00:00
|
|
|
}
|
2007-09-26 18:11:48 +00:00
|
|
|
|
|
|
|
} else if (empty($data->key)) {
|
2007-10-07 10:22:21 +00:00
|
|
|
redirect('import.php?id='.$id.'&feedback='.(int)($data->feedback).'&url='.urlencode($data->url));
|
2007-09-26 18:11:48 +00:00
|
|
|
|
2007-06-11 09:00:17 +00:00
|
|
|
} else {
|
2007-09-26 18:11:48 +00:00
|
|
|
if ($data->key == 1) {
|
|
|
|
$data->key = create_user_key('grade/import', $USER->id, $course->id, $data->iprestriction, $data->validuntil);
|
|
|
|
}
|
|
|
|
|
2015-07-14 18:28:40 -03:00
|
|
|
print_grade_page_head($COURSE->id, 'import', 'xml',
|
|
|
|
get_string('importxml', 'grades'), false, false, true, 'importxml', 'gradeimport_xml');
|
2007-09-26 18:11:48 +00:00
|
|
|
|
|
|
|
echo '<div class="gradeexportlink">';
|
2007-10-07 10:22:21 +00:00
|
|
|
$link = $CFG->wwwroot.'/grade/import/xml/fetch.php?id='.$id.'&feedback='.(int)($data->feedback).'&url='.urlencode($data->url).'&key='.$data->key;
|
2007-09-26 18:11:48 +00:00
|
|
|
echo get_string('import', 'grades').': <a href="'.$link.'">'.$link.'</a>';
|
|
|
|
echo '</div>';
|
2009-08-06 14:12:17 +00:00
|
|
|
echo $OUTPUT->footer();
|
2007-09-26 18:11:48 +00:00
|
|
|
die;
|
2007-05-24 02:16:31 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-11 09:00:17 +00:00
|
|
|
|
2015-07-14 18:28:40 -03:00
|
|
|
print_grade_page_head($COURSE->id, 'import', 'xml',
|
|
|
|
get_string('importxml', 'grades'), false, false, true, 'importxml', 'gradeimport_xml');
|
2007-09-26 18:11:48 +00:00
|
|
|
|
|
|
|
$mform->display();
|
|
|
|
|
2009-08-06 14:12:17 +00:00
|
|
|
echo $OUTPUT->footer();
|