Merge branch 'MDL-59169-master' of https://github.com/nwp90/moodle
[moodle.git] / admin / mnet / delete.php
blob03eac9bcf138e3fca9dc38ef233bed32ffb70cb5
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 * Page to allow the administrator to delete networked hosts, with a confirm message
22 * @package core
23 * @subpackage mnet
24 * @copyright 2007 Donal McMullan
25 * @copyright 2007 Martin Langhoff
26 * @copyright 2010 Penny Leach
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 require(__DIR__.'/../../config.php');
31 require_once($CFG->libdir . '/adminlib.php');
33 $step = optional_param('step', 'verify', PARAM_ALPHA);
34 $hostid = required_param('hostid', PARAM_INT);
37 require_login();
39 $context = context_system::instance();
40 require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
42 $mnet = get_mnet_environment();
44 $PAGE->set_url('/admin/mnet/delete.php');
45 admin_externalpage_setup('mnetpeer' . $hostid);
47 require_sesskey();
49 $mnet_peer = new mnet_peer();
50 $mnet_peer->set_id($hostid);
52 if ('verify' == $step) {
53 echo $OUTPUT->header();
54 echo $OUTPUT->heading(get_string('deleteaserver', 'mnet'));
55 if ($live_users = $mnet_peer->count_live_sessions() > 0) {
56 echo $OUTPUT->notification(get_string('usersareonline', 'mnet', $live_users));
58 $yesurl = new moodle_url('/admin/mnet/delete.php', array('hostid' => $mnet_peer->id, 'step' => 'delete'));
59 $nourl = new moodle_url('/admin/mnet/peers.php');
60 echo $OUTPUT->confirm(get_string('reallydeleteserver', 'mnet') . ': ' . $mnet_peer->name, $yesurl, $nourl);
61 echo $OUTPUT->footer();
62 } elseif ('delete' == $step) {
63 $mnet_peer->delete();
64 redirect(new moodle_url('/admin/mnet/peers.php'), get_string('hostdeleted', 'mnet'), 5);