Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   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  /**
  20   * This page is for configuring which services are published/subscribed on a host
  21   *
  22   * @package    core
  23   * @subpackage mnet
  24   * @copyright  2010 Penny Leach
  25   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  
  28  require(__DIR__.'/../../config.php');
  29  require_once($CFG->libdir.'/adminlib.php');
  30  require_once($CFG->dirroot . '/' . $CFG->admin . '/mnet/services_form.php');
  31  $mnet = get_mnet_environment();
  32  
  33  admin_externalpage_setup('mnetpeers');
  34  
  35  
  36  $hostid = required_param('hostid', PARAM_INT);
  37  
  38  $mnet_peer = new mnet_peer();
  39  $mnet_peer->set_id($hostid);
  40  
  41  $mform = new mnet_services_form(null, array('peer' => $mnet_peer));
  42  if ($formdata = $mform->get_data()) {
  43      if (!isset($formdata->publish)) {
  44          $formdata->publish = array();
  45      }
  46      if (!isset($formdata->subscribe)) {
  47          $formdata->subscribe = array();
  48      }
  49      foreach($formdata->exists as $key => $value) {
  50          $host2service   = $DB->get_record('mnet_host2service', array('hostid'=>$hostid, 'serviceid'=>$key));
  51          $publish        = (array_key_exists($key, $formdata->publish)) ? $formdata->publish[$key] : 0;
  52          $subscribe      = (array_key_exists($key, $formdata->subscribe)) ? $formdata->subscribe[$key] : 0;
  53  
  54          if ($publish != 1 && $subscribe != 1) {
  55              if (false == $host2service) {
  56                  // We don't have or need a record - do nothing!
  57              } else {
  58                  // We don't need the record - delete it
  59                  $DB->delete_records('mnet_host2service', array('hostid' => $hostid, 'serviceid'=>$key));
  60              }
  61          } elseif (false == $host2service && ($publish == 1 || $subscribe == 1)) {
  62              $host2service = new stdClass();
  63              $host2service->hostid = $hostid;
  64              $host2service->serviceid = $key;
  65  
  66              $host2service->publish = $publish;
  67              $host2service->subscribe = $subscribe;
  68  
  69              $host2service->id = $DB->insert_record('mnet_host2service', $host2service);
  70          } elseif ($host2service->publish != $publish || $host2service->subscribe != $subscribe) {
  71              $host2service->publish   = $publish;
  72              $host2service->subscribe = $subscribe;
  73              $DB->update_record('mnet_host2service', $host2service);
  74          }
  75      }
  76      $redirecturl = new moodle_url('/admin/mnet/services.php?hostid=' . $hostid);
  77      redirect($redirecturl, get_string('changessaved'));
  78  }
  79  
  80  echo $OUTPUT->header();
  81  $currenttab = 'mnetservices';
  82  require_once($CFG->dirroot . '/' . $CFG->admin . '/mnet/tabs.php');
  83  echo $OUTPUT->box_start();
  84  $s = mnet_get_service_info($mnet_peer, false); // basic data only
  85  $mform->set_data($s);
  86  $mform->display();
  87  echo $OUTPUT->box_end();
  88  
  89  echo $OUTPUT->footer();