3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * Web services function UI
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_ALPHANUMEXT
);
34 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
36 admin_externalpage_setup('externalservicefunctions');
39 $PAGE->set_url('/' . $CFG->admin
. '/webservice/service_functions.php', array('id' => $serviceid));
40 $node = $PAGE->settingsnav
->find('externalservices', navigation_node
::TYPE_SETTING
);
44 $PAGE->set_primary_active_tab('siteadminnode');
45 $PAGE->navbar
->add(get_string('externalservices', 'webservice'),
46 new moodle_url('/admin/settings.php', ['section' => 'externalservices']));
47 $PAGE->navbar
->add(get_string('functions', 'webservice'),
48 new moodle_url('/' . $CFG->admin
. '/webservice/service_functions.php', array('id' => $serviceid)));
50 $service = $DB->get_record('external_services', array('id' => $serviceid), '*', MUST_EXIST
);
51 $webservicemanager = new webservice();
52 $renderer = $PAGE->get_renderer('core', 'webservice');
53 $functionlisturl = new moodle_url('/' . $CFG->admin
. '/webservice/service_functions.php',
54 array('id' => $serviceid));
56 // Add or Delete operations
59 $PAGE->navbar
->add(get_string('addfunctions', 'webservice'));
60 /// Add function operation
61 if (confirm_sesskey() and $service and empty($service->component
)) {
62 $mform = new external_service_functions_form(null,
63 array('action' => 'add', 'id' => $service->id
));
65 //cancelled add operation, redirect to function list page
66 if ($mform->is_cancelled()) {
67 redirect($functionlisturl);
70 //add the function to the service then redirect to function list page
71 if ($data = $mform->get_data()) {
72 ignore_user_abort(true); // no interruption here!
73 foreach ($data->fids
as $fid) {
74 $function = $webservicemanager->get_external_function_by_id(
76 // make sure the function is not there yet
77 if (!$webservicemanager->service_function_exists($function->name
,
79 $webservicemanager->add_external_function_to_service(
80 $function->name
, $service->id
);
83 redirect($functionlisturl);
86 //Add function operation page output
87 echo $OUTPUT->header();
88 echo $OUTPUT->heading($service->name
);
90 echo $OUTPUT->footer();
97 $PAGE->navbar
->add(get_string('removefunction', 'webservice'));
98 /// Delete function operation
99 if (confirm_sesskey() and $service and empty($service->component
)) {
100 //check that the function to remove exists
101 $function = $webservicemanager->get_external_function_by_id(
102 $functionid, MUST_EXIST
);
104 //display confirmation page
106 echo $OUTPUT->header();
107 echo $renderer->admin_remove_service_function_confirmation($function, $service);
108 echo $OUTPUT->footer();
112 //or remove the function from the service, then redirect to the function list
113 $webservicemanager->remove_external_function_from_service($function->name
,
115 redirect($functionlisturl);
120 /// OUTPUT function list page
121 echo $OUTPUT->header();
122 echo $OUTPUT->heading(get_string('addservicefunction', 'webservice', $service->name
));
123 $functions = $webservicemanager->get_external_functions(array($service->id
));
124 echo $renderer->admin_service_function_list($functions, $service);
125 echo $OUTPUT->footer();