weekly release 2.4.6+
[moodle.git] / admin / webservice / service.php
bloba933ec4af411ee924e00a2d989a852c21418aae6
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 admin 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('forms.php');
28 require_once($CFG->dirroot . '/webservice/lib.php');
30 admin_externalpage_setup('externalservice');
32 //define nav bar
33 $node = $PAGE->settingsnav->find('externalservice', navigation_node::TYPE_SETTING);
34 $newnode = $PAGE->settingsnav->find('externalservices', navigation_node::TYPE_SETTING);
35 if ($node && $newnode) {
36 $node->display = false;
37 $newnode->make_active();
39 $PAGE->navbar->add(get_string('externalservice', 'webservice'));
41 //Retrieve few general parameters
42 $id = required_param('id', PARAM_INT);
43 $action = optional_param('action', '', PARAM_ALPHANUMEXT);
44 $confirm = optional_param('confirm', 0, PARAM_BOOL);
45 $webservicemanager = new webservice;
46 $renderer = $PAGE->get_renderer('core', 'webservice');
47 $returnurl = $CFG->wwwroot . "/" . $CFG->admin . "/settings.php?section=externalservices";
48 $service = $id ? $webservicemanager->get_external_service_by_id($id, MUST_EXIST) : null;
50 /// DELETE operation
51 if ($action == 'delete' and confirm_sesskey() and $service and empty($service->component)) {
52 //Display confirmation Page
53 if (!$confirm) {
54 echo $OUTPUT->header();
55 echo $renderer->admin_remove_service_confirmation($service);
56 echo $OUTPUT->footer();
57 die;
59 //The user has confirmed the deletion, delete and redirect
60 $webservicemanager->delete_service($service->id);
61 add_to_log(SITEID, 'webservice', 'delete', $returnurl, get_string('deleteservice', 'webservice', $service));
62 redirect($returnurl);
65 /// EDIT/CREATE/CANCEL operations => at the end redirect to add function page / main service page
66 $mform = new external_service_form(null, $service);
67 if ($mform->is_cancelled()) {
68 redirect($returnurl);
69 } else if ($servicedata = $mform->get_data()) {
70 $servicedata = (object) $servicedata;
71 if (!empty($servicedata->requiredcapability) && $servicedata->requiredcapability == "norequiredcapability") {
72 $servicedata->requiredcapability = "";
75 //create operation
76 if (empty($servicedata->id)) {
77 $servicedata->id = $webservicemanager->add_external_service($servicedata);
78 add_to_log(SITEID, 'webservice', 'add', $returnurl, get_string('addservice', 'webservice', $servicedata));
80 //redirect to the 'add functions to service' page
81 $addfunctionpage = new moodle_url(
82 $CFG->wwwroot . '/' . $CFG->admin . '/webservice/service_functions.php',
83 array('id' => $servicedata->id));
84 $returnurl = $addfunctionpage->out(false);
85 } else {
86 //update operation
87 $webservicemanager->update_external_service($servicedata);
88 add_to_log(SITEID, 'webservice', 'edit', $returnurl, get_string('editservice', 'webservice', $servicedata));
91 redirect($returnurl);
94 //OUTPUT edit/create form
95 echo $OUTPUT->header();
96 $mform->display();
97 echo $OUTPUT->footer();