Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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 admin 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 ('forms.php');
  28  require_once($CFG->dirroot . '/webservice/lib.php');
  29  
  30  admin_externalpage_setup('externalservice');
  31  
  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();
  38  }
  39  $PAGE->navbar->add(get_string('externalservice', 'webservice'));
  40  
  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;
  49  
  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;
  58      }
  59      //The user has confirmed the deletion, delete and redirect
  60      $webservicemanager->delete_service($service->id);
  61      $params = array(
  62          'objectid' => $service->id
  63      );
  64      $event = \core\event\webservice_service_deleted::create($params);
  65      $event->add_record_snapshot('external_services', $service);
  66      $event->trigger();
  67      redirect($returnurl);
  68  }
  69  
  70  /// EDIT/CREATE/CANCEL operations => at the end redirect to add function page / main service page
  71  $mform = new external_service_form(null, $service);
  72  if ($mform->is_cancelled()) {
  73      redirect($returnurl);
  74  } else if ($servicedata = $mform->get_data()) {
  75      $servicedata = (object) $servicedata;
  76      if (!empty($servicedata->requiredcapability) && $servicedata->requiredcapability == "norequiredcapability") {
  77          $servicedata->requiredcapability = "";
  78      }
  79  
  80      //create operation
  81      if (empty($servicedata->id)) {
  82          $servicedata->id = $webservicemanager->add_external_service($servicedata);
  83          $params = array(
  84              'objectid' => $servicedata->id
  85          );
  86          $event = \core\event\webservice_service_created::create($params);
  87          $event->trigger();
  88  
  89          //redirect to the 'add functions to service' page
  90          $addfunctionpage = new moodle_url(
  91                          $CFG->wwwroot . '/' . $CFG->admin . '/webservice/service_functions.php',
  92                          array('id' => $servicedata->id));
  93          $returnurl = $addfunctionpage->out(false);
  94      } else {
  95          //update operation
  96          $webservicemanager->update_external_service($servicedata);
  97          $params = array(
  98              'objectid' => $servicedata->id
  99          );
 100          $event = \core\event\webservice_service_updated::create($params);
 101          $event->trigger();
 102      }
 103  
 104      redirect($returnurl);
 105  }
 106  
 107  //OUTPUT edit/create form
 108  echo $OUTPUT->header();
 109  $mform->display();
 110  echo $OUTPUT->footer();
 111