Moodle release 4.0
[moodle.git] / admin / mnet / services.php
blobd5048ebb9ac798934febbc993459605d099c5da1
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 admin_externalpage_setup('mnetpeers');
36 $hostid = required_param('hostid', PARAM_INT);
38 $mnet_peer = new mnet_peer();
39 $mnet_peer->set_id($hostid);
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();
46 if (!isset($formdata->subscribe)) {
47 $formdata->subscribe = array();
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;
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));
61 } elseif (false == $host2service && ($publish == 1 || $subscribe == 1)) {
62 $host2service = new stdClass();
63 $host2service->hostid = $hostid;
64 $host2service->serviceid = $key;
66 $host2service->publish = $publish;
67 $host2service->subscribe = $subscribe;
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);
76 $redirecturl = new moodle_url('/admin/mnet/services.php?hostid=' . $hostid);
77 redirect($redirecturl, get_string('changessaved'));
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();
89 echo $OUTPUT->footer();