|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00018 require_once('../../../config.php'); 00019 require_once('lib.php'); 00020 require_once('grade_import_form.php'); 00021 00022 $id = required_param('id', PARAM_INT); // course id 00023 00024 $PAGE->set_url(new moodle_url('/grade/import/xml/index.php', array('id'=>$id))); 00025 $PAGE->set_pagelayout('admin'); 00026 00027 if (!$course = $DB->get_record('course', array('id'=>$id))) { 00028 print_error('nocourseid'); 00029 } 00030 00031 require_login($course); 00032 $context = get_context_instance(CONTEXT_COURSE, $id); 00033 require_capability('moodle/grade:import', $context); 00034 require_capability('gradeimport/xml:view', $context); 00035 00036 // print header 00037 $strgrades = get_string('grades', 'grades'); 00038 $actionstr = get_string('pluginname', 'gradeimport_xml'); 00039 00040 if (!empty($CFG->gradepublishing)) { 00041 $CFG->gradepublishing = has_capability('gradeimport/xml:publish', $context); 00042 } 00043 00044 $mform = new grade_import_form(); 00045 00046 if ($data = $mform->get_data()) { 00047 // Large files are likely to take their time and memory. Let PHP know 00048 // that we'll take longer, and that the process should be recycled soon 00049 // to free up memory. 00050 @set_time_limit(0); 00051 raise_memory_limit(MEMORY_EXTRA); 00052 00053 if ($text = $mform->get_file_content('userfile')) { 00054 print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades')); 00055 00056 $error = ''; 00057 $importcode = import_xml_grades($text, $course, $error); 00058 if ($importcode) { 00059 grade_import_commit($id, $importcode, $data->feedback, true); 00060 echo $OUTPUT->footer(); 00061 die; 00062 } else { 00063 echo $OUTPUT->notification($error); 00064 echo $OUTPUT->continue_button($CFG->wwwroot.'/grade/index.php?id='.$course->id); 00065 echo $OUTPUT->footer(); 00066 die; 00067 } 00068 00069 } else if (empty($data->key)) { 00070 redirect('import.php?id='.$id.'&feedback='.(int)($data->feedback).'&url='.urlencode($data->url)); 00071 00072 } else { 00073 if ($data->key == 1) { 00074 $data->key = create_user_key('grade/import', $USER->id, $course->id, $data->iprestriction, $data->validuntil); 00075 } 00076 00077 print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades')); 00078 00079 echo '<div class="gradeexportlink">'; 00080 $link = $CFG->wwwroot.'/grade/import/xml/fetch.php?id='.$id.'&feedback='.(int)($data->feedback).'&url='.urlencode($data->url).'&key='.$data->key; 00081 echo get_string('import', 'grades').': <a href="'.$link.'">'.$link.'</a>'; 00082 echo '</div>'; 00083 echo $OUTPUT->footer(); 00084 die; 00085 } 00086 } 00087 00088 print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades')); 00089 00090 $mform->display(); 00091 00092 echo $OUTPUT->footer(); 00093 00094