source: moodle/trunk/fuentes/admin/mnet/services.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

File size: 3.5 KB
Line 
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
28require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
29require_once($CFG->libdir.'/adminlib.php');
30require_once($CFG->dirroot . '/admin/mnet/services_form.php');
31$mnet = get_mnet_environment();
32
33require_login();
34admin_externalpage_setup('mnetpeers');
35
36$context = context_system::instance();
37require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
38
39$hostid = required_param('hostid', PARAM_INT);
40
41$mnet_peer = new mnet_peer();
42$mnet_peer->set_id($hostid);
43
44$mform = new mnet_services_form(null, array('peer' => $mnet_peer));
45if ($formdata = $mform->get_data()) {
46    if (!isset($formdata->publish)) {
47        $formdata->publish = array();
48    }
49    if (!isset($formdata->subscribe)) {
50        $formdata->subscribe = array();
51    }
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;
56
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));
63            }
64        } elseif (false == $host2service && ($publish == 1 || $subscribe == 1)) {
65            $host2service = new stdClass();
66            $host2service->hostid = $hostid;
67            $host2service->serviceid = $key;
68
69            $host2service->publish = $publish;
70            $host2service->subscribe = $subscribe;
71
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);
77        }
78    }
79    $redirecturl = new moodle_url('/admin/mnet/services.php?hostid=' . $hostid);
80    redirect($redirecturl, get_string('changessaved'));
81}
82
83echo $OUTPUT->header();
84$currenttab = 'mnetservices';
85require_once($CFG->dirroot . '/admin/mnet/tabs.php');
86echo $OUTPUT->box_start();
87$s = mnet_get_service_info($mnet_peer, false); // basic data only
88$mform->set_data($s);
89$mform->display();
90echo $OUTPUT->box_end();
91
92echo $OUTPUT->footer();
Note: See TracBrowser for help on using the repository browser.