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->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
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(
73 // make sure the function is not there yet
74 if (!$webservicemanager->service_function_exists($function->name
,
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
);
87 echo $OUTPUT->footer();
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
103 echo $OUTPUT->header();
104 echo $renderer->admin_remove_service_function_confirmation($function, $service);
105 echo $OUTPUT->footer();
109 //or remove the function from the service, then redirect to the function list
110 $webservicemanager->remove_external_function_from_service($function->name
,
112 redirect($functionlisturl);
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();