when no gradebook roles is set, there are lots of sql breakages so we should check...
[moodle-pu.git] / grade / import / xml / index.php
blob912eedfd8eb2c8836eef7d9d6ca8ebe22eb92d0f
1 <?php //$Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
9 // //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
11 // //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
16 // //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
21 // //
22 // http://www.gnu.org/copyleft/gpl.html //
23 // //
24 ///////////////////////////////////////////////////////////////////////////
26 require_once '../../../config.php';
27 require_once 'lib.php';
28 require_once 'grade_import_form.php';
30 $id = required_param('id', PARAM_INT); // course id
32 if (!$course = get_record('course', 'id', $id)) {
33 print_error('nocourseid');
36 require_login($course);
37 $context = get_context_instance(CONTEXT_COURSE, $id);
38 require_capability('moodle/grade:import', $context);
39 require_capability('gradeimport/xml:view', $context);
41 // print header
42 $strgrades = get_string('grades', 'grades');
43 $actionstr = get_string('modulename', 'gradeimport_xml');
44 $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course->id));
46 $mform = new grade_import_form();
48 if ($data = $mform->get_data()) {
49 // Large files are likely to take their time and memory. Let PHP know
50 // that we'll take longer, and that the process should be recycled soon
51 // to free up memory.
52 @set_time_limit(0);
53 @raise_memory_limit("256M");
54 if (function_exists('apache_child_terminate')) {
55 @apache_child_terminate();
58 if ($text = $mform->get_file_content('userfile')) {
59 print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
60 print_grade_plugin_selector($id, 'import', 'xml');
62 $error = '';
63 $importcode = import_xml_grades($text, $course, $error);
64 if ($importcode) {
65 grade_import_commit($id, $importcode);
66 print_footer();
67 die;
68 } else {
69 notify($error);
70 print_continue($CFG->wwwroot.'/grade/index.php?id='.$course->id);
71 print_footer();
72 die;
75 } else if (empty($data->key)) {
76 redirect('import.php?id='.$id.'&url='.urlencode($data->url));
78 } else {
79 if ($data->key == 1) {
80 $data->key = create_user_key('grade/import', $USER->id, $course->id, $data->iprestriction, $data->validuntil);
83 print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
84 print_grade_plugin_selector($id, 'import', 'xml');
86 echo '<div class="gradeexportlink">';
87 $link = $CFG->wwwroot.'/grade/import/xml/fetch.php?id='.$id.'&amp;url='.urlencode($data->url).'&amp;key='.$data->key;
88 echo get_string('import', 'grades').': <a href="'.$link.'">'.$link.'</a>';
89 echo '</div>';
90 print_footer();
91 die;
95 print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
96 print_grade_plugin_selector($id, 'import', 'xml');
98 $mform->display();
100 print_footer();