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