Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  require_once('../../../config.php');
  19  require_once ('lib.php');
  20  require_once ('grade_import_form.php');
  21  
  22  $id = required_param('id', PARAM_INT); // course id
  23  
  24  $PAGE->set_url(new moodle_url('/grade/import/xml/index.php', array('id'=>$id)));
  25  $PAGE->set_pagelayout('admin');
  26  
  27  if (!$course = $DB->get_record('course', array('id'=>$id))) {
  28      print_error('invalidcourseid');
  29  }
  30  
  31  require_login($course);
  32  $context = context_course::instance($id);
  33  require_capability('moodle/grade:import', $context);
  34  require_capability('gradeimport/xml:view', $context);
  35  
  36  // print header
  37  $strgrades = get_string('grades', 'grades');
  38  $actionstr = get_string('pluginname', 'gradeimport_xml');
  39  
  40  if (!empty($CFG->gradepublishing)) {
  41      $CFG->gradepublishing = has_capability('gradeimport/xml:publish', $context);
  42  }
  43  
  44  $mform = new grade_import_form(null, array('acceptedtypes' => array('.xml')));
  45  
  46  if ($data = $mform->get_data()) {
  47      // Large files are likely to take their time and memory. Let PHP know
  48      // that we'll take longer, and that the process should be recycled soon
  49      // to free up memory.
  50      core_php_time_limit::raise();
  51      raise_memory_limit(MEMORY_EXTRA);
  52  
  53      if ($text = $mform->get_file_content('userfile')) {
  54          print_grade_page_head($COURSE->id, 'import', 'xml',
  55                                get_string('importxml', 'grades'), false, false, true, 'importxml', 'gradeimport_xml');
  56  
  57          $error = '';
  58          $importcode = import_xml_grades($text, $course, $error);
  59          if ($importcode) {
  60              grade_import_commit($id, $importcode, $data->feedback, true);
  61              echo $OUTPUT->footer();
  62              die;
  63          } else {
  64              echo $OUTPUT->notification($error);
  65              echo $OUTPUT->continue_button($CFG->wwwroot.'/grade/index.php?id='.$course->id);
  66              echo $OUTPUT->footer();
  67              die;
  68          }
  69  
  70      } else if (empty($data->key)) {
  71          redirect('import.php?id='.$id.'&amp;feedback='.(int)($data->feedback).'&url='.urlencode($data->url));
  72  
  73      } else {
  74          if ($data->key == 1) {
  75              $data->key = create_user_key('grade/import', $USER->id, $course->id, $data->iprestriction, $data->validuntil);
  76          }
  77  
  78          print_grade_page_head($COURSE->id, 'import', 'xml',
  79                                get_string('importxml', 'grades'), false, false, true, 'importxml', 'gradeimport_xml');
  80  
  81          echo '<div class="gradeexportlink">';
  82          $link = $CFG->wwwroot.'/grade/import/xml/fetch.php?id='.$id.'&amp;feedback='.(int)($data->feedback).'&amp;url='.urlencode($data->url).'&amp;key='.$data->key;
  83          echo get_string('import', 'grades').': <a href="'.$link.'">'.$link.'</a>';
  84          echo '</div>';
  85          echo $OUTPUT->footer();
  86          die;
  87      }
  88  }
  89  
  90  print_grade_page_head($COURSE->id, 'import', 'xml',
  91                        get_string('importxml', 'grades'), false, false, true, 'importxml', 'gradeimport_xml');
  92  
  93  $mform->display();
  94  
  95  echo $OUTPUT->footer();