Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/webservice/service_functions.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00025 require_once('../../config.php');
00026 require_once($CFG->libdir . '/adminlib.php');
00027 require_once($CFG->libdir . '/externallib.php');
00028 require_once($CFG->dirroot . '/webservice/lib.php');
00029 require_once('forms.php');
00030 
00031 $serviceid = required_param('id', PARAM_INT);
00032 $functionid = optional_param('fid', 0, PARAM_INT);
00033 $action = optional_param('action', '', PARAM_ACTION);
00034 $confirm = optional_param('confirm', 0, PARAM_BOOL);
00035 
00036 admin_externalpage_setup('externalservicefunctions');
00037 
00038 //define nav bar
00039 $PAGE->set_url('/' . $CFG->admin . '/websevice/service_functions.php', array('id' => $serviceid));
00040 $node = $PAGE->settingsnav->find('externalservices', navigation_node::TYPE_SETTING);
00041 if ($node) {
00042     $node->make_active();
00043 }
00044 $PAGE->navbar->add(get_string('functions', 'webservice'),
00045         new moodle_url('/' . $CFG->admin . '/webservice/service_functions.php', array('id' => $serviceid)));
00046 
00047 $service = $DB->get_record('external_services', array('id' => $serviceid), '*', MUST_EXIST);
00048 $webservicemanager = new webservice();
00049 $renderer = $PAGE->get_renderer('core', 'webservice');
00050 $functionlisturl = new moodle_url('/' . $CFG->admin . '/webservice/service_functions.php',
00051         array('id' => $serviceid));
00052 
00053 // Add or Delete operations
00054 switch ($action) {
00055     case 'add':
00056         $PAGE->navbar->add(get_string('addfunctions', 'webservice'));
00058         if (confirm_sesskey() and $service and empty($service->component)) {
00059             $mform = new external_service_functions_form(null,
00060                     array('action' => 'add', 'id' => $service->id));
00061 
00062             //cancelled add operation, redirect to function list page
00063             if ($mform->is_cancelled()) {
00064                 redirect($functionlisturl);
00065             }
00066 
00067             //add the function to the service then redirect to function list page
00068             if ($data = $mform->get_data()) {
00069                 ignore_user_abort(true); // no interruption here!
00070                 foreach ($data->fids as $fid) {
00071                     $function = $webservicemanager->get_external_function_by_id(
00072                             $fid, MUST_EXIST);
00073                     // make sure the function is not there yet
00074                     if (!$webservicemanager->service_function_exists($function->name,
00075                             $service->id)) {
00076                         $webservicemanager->add_external_function_to_service(
00077                                 $function->name, $service->id);
00078                     }
00079                 }
00080                 redirect($functionlisturl);
00081             }
00082 
00083             //Add function operation page output
00084             echo $OUTPUT->header();
00085             echo $OUTPUT->heading($service->name);
00086             $mform->display();
00087             echo $OUTPUT->footer();
00088             die;
00089         }
00090 
00091         break;
00092 
00093     case 'delete':
00094         $PAGE->navbar->add(get_string('removefunction', 'webservice'));
00096         if (confirm_sesskey() and $service and empty($service->component)) {
00097             //check that the function to remove exists
00098             $function = $webservicemanager->get_external_function_by_id(
00099                             $functionid, MUST_EXIST);
00100 
00101             //display confirmation page
00102             if (!$confirm) {
00103                 echo $OUTPUT->header();
00104                 echo $renderer->admin_remove_service_function_confirmation($function, $service);
00105                 echo $OUTPUT->footer();
00106                 die;
00107             }
00108 
00109             //or remove the function from the service, then redirect to the function list
00110             $webservicemanager->remove_external_function_from_service($function->name,
00111                    $service->id);
00112             redirect($functionlisturl);
00113         }
00114         break;
00115 }
00116 
00118 echo $OUTPUT->header();
00119 echo $OUTPUT->heading(get_string('addservicefunction', 'webservice', $service->name));
00120 $functions = $webservicemanager->get_external_functions(array($service->id));
00121 echo $renderer->admin_service_function_list($functions, $service);
00122 echo $OUTPUT->footer();
00123 
 All Data Structures Namespaces Files Functions Variables Enumerations