MDL-32693 webservice: fix typo in URL
[moodle.git] / admin / webservice / service_functions.php
blob1b2fd225333657fcda492e92c044af8cd5e1c3f3
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 * Web services function UI
21 * @package webservice
22 * @copyright 2009 Moodle Pty Ltd (http://moodle.com)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once('../../config.php');
26 require_once($CFG->libdir . '/adminlib.php');
27 require_once($CFG->libdir . '/externallib.php');
28 require_once($CFG->dirroot . '/webservice/lib.php');
29 require_once('forms.php');
31 $serviceid = required_param('id', PARAM_INT);
32 $functionid = optional_param('fid', 0, PARAM_INT);
33 $action = optional_param('action', '', PARAM_ACTION);
34 $confirm = optional_param('confirm', 0, PARAM_BOOL);
36 admin_externalpage_setup('externalservicefunctions');
38 //define nav bar
39 $PAGE->set_url('/' . $CFG->admin . '/webservice/service_functions.php', array('id' => $serviceid));
40 $node = $PAGE->settingsnav->find('externalservices', navigation_node::TYPE_SETTING);
41 if ($node) {
42 $node->make_active();
44 $PAGE->navbar->add(get_string('functions', 'webservice'),
45 new moodle_url('/' . $CFG->admin . '/webservice/service_functions.php', array('id' => $serviceid)));
47 $service = $DB->get_record('external_services', array('id' => $serviceid), '*', MUST_EXIST);
48 $webservicemanager = new webservice();
49 $renderer = $PAGE->get_renderer('core', 'webservice');
50 $functionlisturl = new moodle_url('/' . $CFG->admin . '/webservice/service_functions.php',
51 array('id' => $serviceid));
53 // Add or Delete operations
54 switch ($action) {
55 case 'add':
56 $PAGE->navbar->add(get_string('addfunctions', 'webservice'));
57 /// Add function operation
58 if (confirm_sesskey() and $service and empty($service->component)) {
59 $mform = new external_service_functions_form(null,
60 array('action' => 'add', 'id' => $service->id));
62 //cancelled add operation, redirect to function list page
63 if ($mform->is_cancelled()) {
64 redirect($functionlisturl);
67 //add the function to the service then redirect to function list page
68 if ($data = $mform->get_data()) {
69 ignore_user_abort(true); // no interruption here!
70 foreach ($data->fids as $fid) {
71 $function = $webservicemanager->get_external_function_by_id(
72 $fid, MUST_EXIST);
73 // make sure the function is not there yet
74 if (!$webservicemanager->service_function_exists($function->name,
75 $service->id)) {
76 $webservicemanager->add_external_function_to_service(
77 $function->name, $service->id);
80 redirect($functionlisturl);
83 //Add function operation page output
84 echo $OUTPUT->header();
85 echo $OUTPUT->heading($service->name);
86 $mform->display();
87 echo $OUTPUT->footer();
88 die;
91 break;
93 case 'delete':
94 $PAGE->navbar->add(get_string('removefunction', 'webservice'));
95 /// Delete function operation
96 if (confirm_sesskey() and $service and empty($service->component)) {
97 //check that the function to remove exists
98 $function = $webservicemanager->get_external_function_by_id(
99 $functionid, MUST_EXIST);
101 //display confirmation page
102 if (!$confirm) {
103 echo $OUTPUT->header();
104 echo $renderer->admin_remove_service_function_confirmation($function, $service);
105 echo $OUTPUT->footer();
106 die;
109 //or remove the function from the service, then redirect to the function list
110 $webservicemanager->remove_external_function_from_service($function->name,
111 $service->id);
112 redirect($functionlisturl);
114 break;
117 /// OUTPUT function list page
118 echo $OUTPUT->header();
119 echo $OUTPUT->heading(get_string('addservicefunction', 'webservice', $service->name));
120 $functions = $webservicemanager->get_external_functions(array($service->id));
121 echo $renderer->admin_service_function_list($functions, $service);
122 echo $OUTPUT->footer();