Merge branch 'MDL-58281-file-missing-500' of https://github.com/brendanheywood/moodle
[moodle.git] / lib / ajax / getsiteadminbranch.php
blobbce7948504fc28dc7ab5bbca5b373a41e14e402d
1 <?php
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.
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/>.
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
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
28 define('AJAX_SCRIPT', true);
29 require_once(__DIR__ . '/../../config.php');
31 // This should be accessed by only valid logged in user.
32 require_login(null, false);
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');
40 // Start capturing output in case of broken plugins.
41 ajax_capture_output();
43 $PAGE->set_context(context_system::instance());
44 $PAGE->set_url('/lib/ajax/getsiteadminbranch.php', array('type'=>$branchtype));
46 $sitenavigation = new settings_navigation_ajax($PAGE);
48 // Convert and output the branch as JSON.
49 $converter = new navigation_json();
50 $branch = $sitenavigation->get('root');
52 ajax_check_captured_output();
53 echo $converter->convert($branch);