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.
   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  /**
  19   * This file is used to deliver a branch from the site administration
  20   * in XML format back to a page from an AJAX call
  21   *
  22   * @since Moodle 2.6
  23   * @package core
  24   * @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
  25   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  
  28  define('AJAX_SCRIPT', true);
  29  require_once(__DIR__ . '/../../config.php');
  30  
  31  // This should be accessed by only valid logged in user.
  32  require_login(null, false);
  33  
  34  // This identifies the type of the branch we want to get. Make sure it's SITE_ADMIN.
  35  $branchtype = required_param('type', PARAM_INT);
  36  if ($branchtype !== navigation_node::TYPE_SITE_ADMIN) {
  37      throw new coding_exception('Incorrect node type passed');
  38  }
  39  
  40  // Start capturing output in case of broken plugins.
  41  ajax_capture_output();
  42  
  43  $PAGE->set_context(context_system::instance());
  44  $PAGE->set_url('/lib/ajax/getsiteadminbranch.php', array('type'=>$branchtype));
  45  
  46  $sitenavigation = new settings_navigation_ajax($PAGE);
  47  
  48  // Convert and output the branch as JSON.
  49  $converter = new navigation_json();
  50  $branch = $sitenavigation->get('root');
  51  
  52  ajax_check_captured_output();
  53  echo $converter->convert($branch);