MDL-20410 - remove set_focuscontrol
[moodle.git] / admin / registration / index.php
CommitLineData
07ab0c80 1<?php
f57c4047 2
07ab0c80 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 * @package moodle
20 * @subpackage registration
21 * @author Jerome Mouneyrac <jerome@mouneyrac.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
23 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
24 *
25 * On this page the administrator select if he wants to register on Moodle.org or
26 * a specific hub
f57c4047 27 */
07ab0c80 28
29require('../../config.php');
30
f57c4047 31require_once($CFG->libdir . '/adminlib.php');
32require_once($CFG->dirroot . '/admin/registration/lib.php');
33require_once($CFG->dirroot . '/admin/registration/forms.php');
34require_once($CFG->dirroot . '/course/publish/lib.php');
35require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
07ab0c80 36
37admin_externalpage_setup('registrationindex');
38
39$renderer = $PAGE->get_renderer('core', 'register');
40
f57c4047 41$unregistration = optional_param('unregistration', 0, PARAM_INT);
42$cleanregdata = optional_param('cleanregdata', 0, PARAM_BOOL);
43$confirm = optional_param('confirm', 0, PARAM_INT);
44$huburl = optional_param('huburl', '', PARAM_URL);
45$cancel = optional_param('cancel', null, PARAM_ALPHA);
46
47$registrationmanager = new registration_manager();
48$publicationmanager = new course_publish_manager();
49$errormessage = '';
50if (empty($cancel) and $unregistration and $confirm and confirm_sesskey()) {
51
52 $hub = $registrationmanager->get_registeredhub($huburl);
53
54 //unpublish course and unregister the site by web service
55 if (!$cleanregdata) {
56
57 //check if we need to unpublish courses
58 //enrollable courses
59 $unpublishalladvertisedcourses = optional_param('unpublishalladvertisedcourses', 0, PARAM_INT);
60 $hubcourseids = array();
61 if ($unpublishalladvertisedcourses) {
62 $enrollablecourses = $publicationmanager->get_publications($huburl, null, 1);
63 if (!empty($enrollablecourses)) {
64 foreach ($enrollablecourses as $enrollablecourse) {
65 $hubcourseids[] = $enrollablecourse->hubcourseid;
66 }
67 }
68 }
69 //downloadable courses
70 $unpublishalluploadedcourses = optional_param('unpublishalluploadedcourses', 0, PARAM_INT);
71 if ($unpublishalluploadedcourses) {
72 $downloadablecourses = $publicationmanager->get_publications($huburl, null, 0);
73 if (!empty($downloadablecourses)) {
74 foreach ($downloadablecourses as $downloadablecourse) {
75 $hubcourseids[] = $downloadablecourse->hubcourseid;
76 }
77 }
78 }
79
80 //unpublish the courses by web service
81 if (!empty($hubcourseids)) {
82 $function = 'hub_unregister_courses';
83 $params = array($hubcourseids);
84 $serverurl = $huburl . "/local/hub/webservice/webservices.php";
85 $xmlrpcclient = new webservice_xmlrpc_client();
86 try {
87 $result = $xmlrpcclient->call($serverurl, $hub->token, $function, $params);
88 //delete the published courses
89 if (!empty($enrollablecourses)) {
90 $publicationmanager->delete_hub_publications($huburl, 1);
91 }
92 if (!empty($downloadablecourses)) {
93 $publicationmanager->delete_hub_publications($huburl, 0);
94 }
95 } catch (Exception $e) {
96 $errormessage = $e->getMessage();
97 $errormessage .= html_writer::empty_tag('br') .
98 get_string('errorunpublishcourses', 'hub');
99 $confirm = false;
100 $cleanregdata = 1;
101 }
102 }
5bfbe04e 103 }
f57c4047 104
5bfbe04e 105 //course unpublish went ok, unregister the site now
106 if ($confirm) {
107 $function = 'hub_unregister_site';
108 $params = array();
109 $serverurl = $huburl . "/local/hub/webservice/webservices.php";
110 $xmlrpcclient = new webservice_xmlrpc_client();
111 try {
112 $result = $xmlrpcclient->call($serverurl, $hub->token, $function, $params);
113 } catch (Exception $e) {
114 if (!$cleanregdata) {
f57c4047 115 $errormessage = $e->getMessage();
116 $confirm = false;
117 $cleanregdata = 1;
118 }
119 }
120 }
121
122 //check that we are still processing the unregistration,
123 //it could have been unset if an exception were previsouly catched
124 if ($confirm) {
125 $registrationmanager->delete_registeredhub($huburl);
126 }
127}
128
07ab0c80 129echo $OUTPUT->header();
f57c4047 130
131//do not check sesskey if confirm = false because this script is linked into email message
132if (!empty($errormessage)) {
133 echo $OUTPUT->notification(get_string('unregistrationerror', 'hub', $errormessage));
134}
135if (empty($cancel) and $unregistration and !$confirm) {
136 $hub = $registrationmanager->get_registeredhub($huburl);
137 echo $OUTPUT->heading(get_string('unregisterfrom', 'hub', $hub->hubname), 3, 'main');
138 if ($cleanregdata) {
139 $siteunregistrationform = new site_clean_registration_data_form('',
140 array('huburl' => $huburl, 'hubname' => $hub->hubname));
141 } else {
142 $siteunregistrationform = new site_unregistration_form('',
143 array('huburl' => $huburl, 'hubname' => $hub->hubname));
144 }
145 $siteunregistrationform->display();
146} else {
147 echo $OUTPUT->heading(get_string('registeron', 'hub'), 3, 'main');
148 echo $renderer->registrationselector();
5cbbcc1a 149
150
151 if (extension_loaded('xmlrpc')) {
152 $hubs = $registrationmanager->get_registered_on_hubs();
153 if (!empty($hubs)) {
154 echo $OUTPUT->heading(get_string('registeredon', 'hub'), 3, 'main');
155 echo $renderer->registeredonhublisting($hubs);
156 }
157 } else { //display notice about xmlrpc
158 $xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
159 $xmlrpcnotification .= get_string('xmlrpcdisabledregistration', 'hub');
160 echo $OUTPUT->notification($xmlrpcnotification);
f57c4047 161 }
162}
03d9401e 163echo $OUTPUT->footer();