MDL-60751 core_calendar: remove useless NULL_ALLOWED parameter
[moodle.git] / admin / mnet / services.php
blob79e46e9f58c846ea4f75033def8aad5dc561ea26
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/>.
19 /**
20 * This page is for configuring which services are published/subscribed on a host
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
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();
33 require_login();
34 admin_externalpage_setup('mnetpeers');
36 $context = context_system::instance();
37 require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
39 $hostid = required_param('hostid', PARAM_INT);
41 $mnet_peer = new mnet_peer();
42 $mnet_peer->set_id($hostid);
44 $mform = new mnet_services_form(null, array('peer' => $mnet_peer));
45 if ($formdata = $mform->get_data()) {
46 if (!isset($formdata->publish)) {
47 $formdata->publish = array();
49 if (!isset($formdata->subscribe)) {
50 $formdata->subscribe = array();
52 foreach($formdata->exists as $key => $value) {
53 $host2service = $DB->get_record('mnet_host2service', array('hostid'=>$hostid, 'serviceid'=>$key));
54 $publish = (array_key_exists($key, $formdata->publish)) ? $formdata->publish[$key] : 0;
55 $subscribe = (array_key_exists($key, $formdata->subscribe)) ? $formdata->subscribe[$key] : 0;
57 if ($publish != 1 && $subscribe != 1) {
58 if (false == $host2service) {
59 // We don't have or need a record - do nothing!
60 } else {
61 // We don't need the record - delete it
62 $DB->delete_records('mnet_host2service', array('hostid' => $hostid, 'serviceid'=>$key));
64 } elseif (false == $host2service && ($publish == 1 || $subscribe == 1)) {
65 $host2service = new stdClass();
66 $host2service->hostid = $hostid;
67 $host2service->serviceid = $key;
69 $host2service->publish = $publish;
70 $host2service->subscribe = $subscribe;
72 $host2service->id = $DB->insert_record('mnet_host2service', $host2service);
73 } elseif ($host2service->publish != $publish || $host2service->subscribe != $subscribe) {
74 $host2service->publish = $publish;
75 $host2service->subscribe = $subscribe;
76 $DB->update_record('mnet_host2service', $host2service);
79 $redirecturl = new moodle_url('/admin/mnet/services.php?hostid=' . $hostid);
80 redirect($redirecturl, get_string('changessaved'));
83 echo $OUTPUT->header();
84 $currenttab = 'mnetservices';
85 require_once($CFG->dirroot . '/' . $CFG->admin . '/mnet/tabs.php');
86 echo $OUTPUT->box_start();
87 $s = mnet_get_service_info($mnet_peer, false); // basic data only
88 $mform->set_data($s);
89 $mform->display();
90 echo $OUTPUT->box_end();
92 echo $OUTPUT->footer();