Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/import/xml/import.php
Go to the documentation of this file.
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 $CFG->libdir.'/filelib.php';
00021 
00022 $url       = required_param('url', PARAM_URL); // only real urls here
00023 $id        = required_param('id', PARAM_INT); // course id
00024 $feedback  = optional_param('feedback', 0, PARAM_BOOL);
00025 
00026 $url = new moodle_url('/grade/import/xml/import.php', array('id'=>$id,'url'=>$url));
00027 if ($feedback !== 0) {
00028     $url->param('feedback', $feedback);
00029 }
00030 $PAGE->set_url($url);
00031 
00032 if (!$course = $DB->get_record('course', array('id'=>$id))) {
00033     print_error('nocourseid');
00034 }
00035 
00036 require_login($course);
00037 $context = get_context_instance(CONTEXT_COURSE, $id);
00038 
00039 require_capability('moodle/grade:import', $context);
00040 require_capability('gradeimport/xml:view', $context);
00041 
00042 
00043 // Large files are likely to take their time and memory. Let PHP know
00044 // that we'll take longer, and that the process should be recycled soon
00045 // to free up memory.
00046 @set_time_limit(0);
00047 raise_memory_limit(MEMORY_EXTRA);
00048 
00049 $text = download_file_content($url);
00050 if ($text === false) {
00051     print_error('cannotreadfile');
00052 }
00053 
00054 $error = '';
00055 $importcode = import_xml_grades($text, $course, $error);
00056 
00057 if ($importcode !== false) {
00059 
00060     if (defined('USER_KEY_LOGIN')) {
00061         if (grade_import_commit($id, $importcode, $feedback, false)) {
00062             echo 'ok';
00063             die;
00064         } else {
00065             print_error('cannotimportgrade'); //TODO: localize
00066         }
00067 
00068     } else {
00069         print_grade_page_head($course->id, 'import', 'xml', get_string('importxml', 'grades'));
00070 
00071         grade_import_commit($id, $importcode, $feedback, true);
00072 
00073         echo $OUTPUT->footer();
00074         die;
00075     }
00076 
00077 } else {
00078     print_error('error', 'gradeimport_xml');
00079 }
00080 
00081 
 All Data Structures Namespaces Files Functions Variables Enumerations