MDL-26198 make user_has_role_assignment() check parent contexts too
[moodle.git] / webservice / wsdoc.php
1 <?php
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 ///////////////////////////////////////////////////////////////////////////
23 require_once('../config.php');
24 require($CFG->dirroot . '/webservice/lib.php');
26 require_login();
27 require_sesskey();
29 $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
30 $tokenid = required_param('id', PARAM_INT);
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');
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'));
47 //check web service are enabled
48 if (empty($CFG->enablewsdocumentation)) {
49     echo get_string('wsdocumentationdisable', 'webservice');
50     die;
51 }
53 //check that the current user is the token user
54 $webservice = new webservice();
55 $token = $webservice->get_token_by_id($tokenid);
56 if (empty($token) or empty($token->userid) or empty($USER->id)
57         or ($token->userid != $USER->id)) {
58     throw new moodle_exception('docaccessrefused', 'webservice');
59 }
61 // get the list of all functions related to the token
62 $functions = $webservice->get_external_functions(array($token->externalserviceid));
64 // get all the function descriptions
65 $functiondescs = array();
66 foreach ($functions as $function) {
67     $functiondescs[$function->name] = external_function_info($function);
68 }
70 //get activated protocol
71 $activatedprotocol = array();
72 $activatedprotocol['rest'] = webservice_protocol_is_enabled('rest');
73 $activatedprotocol['xmlrpc'] = webservice_protocol_is_enabled('xmlrpc');
75 /// Check if we are in printable mode
76 $printableformat = false;
77 if (isset($_REQUEST['print'])) {
78     $printableformat = $_REQUEST['print'];
79 }
81 /// OUTPUT
82 echo $OUTPUT->header();
84 $renderer = $PAGE->get_renderer('core', 'webservice');
85 echo $renderer->documentation_html($functiondescs,
86         $printableformat, $activatedprotocol, array('id' => $tokenid));
88 /// trigger browser print operation
89 if (!empty($printableformat)) {
90     $PAGE->requires->js_function_call('window.print', array());
91 }
93 echo $OUTPUT->footer();