Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
1 <?php 2 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. 14 // 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/>. 17 18 /** 19 * Web services function UI 20 * 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 24 */ 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'); 30 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); 35 36 admin_externalpage_setup('externalservicefunctions'); 37 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(); 43 } 44 $PAGE->navbar->add(get_string('functions', 'webservice'), 45 new moodle_url('/' . $CFG->admin . '/webservice/service_functions.php', array('id' => $serviceid))); 46 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)); 52 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)); 61 62 //cancelled add operation, redirect to function list page 63 if ($mform->is_cancelled()) { 64 redirect($functionlisturl); 65 } 66 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); 78 } 79 } 80 redirect($functionlisturl); 81 } 82 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; 89 } 90 91 break; 92 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); 100 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; 107 } 108 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); 113 } 114 break; 115 } 116 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(); 123
title
Description
Body
title
Description
Body
title
Description
Body
title
Body