MDL-26198 make user_has_role_assignment() check parent contexts too
[moodle.git] / webservice / wsdoc.php
CommitLineData
fbe52a39 1<?php
9ef728d6 2
fbe52a39 3///////////////////////////////////////////////////////////////////////////
4// //
5// This file is part of Moodle - http://moodle.org/ //
6// Moodle - Modular Object-Oriented Dynamic Learning Environment //
7// //
8// Moodle is free software: you can redistribute it and/or modify //
9// it under the terms of the GNU General Public License as published by //
10// the Free Software Foundation, either version 3 of the License, or //
11// (at your option) any later version. //
12// //
13// Moodle is distributed in the hope that it will be useful, //
14// but WITHOUT ANY WARRANTY; without even the implied warranty of //
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
16// GNU General Public License for more details. //
17// //
18// You should have received a copy of the GNU General Public License //
19// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
20// //
21///////////////////////////////////////////////////////////////////////////
22
fbe52a39 23require_once('../config.php');
9ef728d6 24require($CFG->dirroot . '/webservice/lib.php');
25
26require_login();
27require_sesskey();
28
29$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
30$tokenid = required_param('id', PARAM_INT);
31
32//PAGE settings
33$PAGE->set_context($usercontext);
34$PAGE->set_url('/user/wsdoc.php');
35$PAGE->set_title(get_string('documentation', 'webservice'));
36$PAGE->set_heading(get_string('documentation', 'webservice'));
37$PAGE->set_pagelayout('standard');
38
39//nav bar
40$PAGE->navbar->ignore_active(true);
41$PAGE->navbar->add(get_string('usercurrentsettings'));
42$PAGE->navbar->add(get_string('securitykeys', 'webservice'),
43 new moodle_url('/user/managetoken.php',
44 array('id' => $tokenid, 'sesskey' => sesskey())));
45$PAGE->navbar->add(get_string('documentation', 'webservice'));
46
47//check web service are enabled
48if (empty($CFG->enablewsdocumentation)) {
49 echo get_string('wsdocumentationdisable', 'webservice');
50 die;
51}
d4c6ef70 52
9ef728d6 53//check that the current user is the token user
54$webservice = new webservice();
55$token = $webservice->get_token_by_id($tokenid);
56if (empty($token) or empty($token->userid) or empty($USER->id)
57 or ($token->userid != $USER->id)) {
58 throw new moodle_exception('docaccessrefused', 'webservice');
59}
7886efc4 60
9ef728d6 61// get the list of all functions related to the token
62$functions = $webservice->get_external_functions(array($token->externalserviceid));
8725605d 63
9ef728d6 64// get all the function descriptions
65$functiondescs = array();
66foreach ($functions as $function) {
67 $functiondescs[$function->name] = external_function_info($function);
68}
fbe52a39 69
9ef728d6 70//get activated protocol
71$activatedprotocol = array();
72$activatedprotocol['rest'] = webservice_protocol_is_enabled('rest');
73$activatedprotocol['xmlrpc'] = webservice_protocol_is_enabled('xmlrpc');
d4c6ef70 74
9ef728d6 75/// Check if we are in printable mode
76$printableformat = false;
77if (isset($_REQUEST['print'])) {
78 $printableformat = $_REQUEST['print'];
fbe52a39 79}
d4c6ef70 80
9ef728d6 81/// OUTPUT
82echo $OUTPUT->header();
d4c6ef70 83
9ef728d6 84$renderer = $PAGE->get_renderer('core', 'webservice');
85echo $renderer->documentation_html($functiondescs,
86 $printableformat, $activatedprotocol, array('id' => $tokenid));
d4c6ef70 87
9ef728d6 88/// trigger browser print operation
89if (!empty($printableformat)) {
90 $PAGE->requires->js_function_call('window.print', array());
7886efc4 91}
92
9ef728d6 93echo $OUTPUT->footer();