MDL-41311 tool_generator: remove legacy code
[moodle.git] / admin / registration / index.php
blob42f1c07b51d5043bee270fb93aa4389f1cbff4c9
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 * @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
25 * On this page the administrator selects which hub he wants to register,
26 * except for MOOCH. Admins can register with MOOCH with the top admin menu "Registration" link.
27 * On this page the administrator can also unregister from any hubs, including MOOCH.
30 require('../../config.php');
32 require_once($CFG->libdir . '/adminlib.php');
33 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
34 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/forms.php');
35 require_once($CFG->dirroot . '/course/publish/lib.php');
36 require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
38 admin_externalpage_setup('registrationhubs');
40 $renderer = $PAGE->get_renderer('core', 'register');
42 $unregistration = optional_param('unregistration', 0, PARAM_INT);
43 $cleanregdata = optional_param('cleanregdata', 0, PARAM_BOOL);
44 $confirm = optional_param('confirm', 0, PARAM_INT);
45 $huburl = optional_param('huburl', '', PARAM_URL);
46 $cancel = optional_param('cancel', null, PARAM_ALPHA);
48 $registrationmanager = new registration_manager();
49 $publicationmanager = new course_publish_manager();
50 $errormessage = '';
51 if (empty($cancel) and $unregistration and $confirm and confirm_sesskey()) {
53 $hub = $registrationmanager->get_registeredhub($huburl);
55 //unpublish course and unregister the site by web service
56 if (!$cleanregdata) {
58 //check if we need to unpublish courses
59 //enrollable courses
60 $unpublishalladvertisedcourses = optional_param('unpublishalladvertisedcourses', 0, PARAM_INT);
61 $hubcourseids = array();
62 if ($unpublishalladvertisedcourses) {
63 $enrollablecourses = $publicationmanager->get_publications($huburl, null, 1);
64 if (!empty($enrollablecourses)) {
65 foreach ($enrollablecourses as $enrollablecourse) {
66 $hubcourseids[] = $enrollablecourse->hubcourseid;
70 //downloadable courses
71 $unpublishalluploadedcourses = optional_param('unpublishalluploadedcourses', 0, PARAM_INT);
72 if ($unpublishalluploadedcourses) {
73 $downloadablecourses = $publicationmanager->get_publications($huburl, null, 0);
74 if (!empty($downloadablecourses)) {
75 foreach ($downloadablecourses as $downloadablecourse) {
76 $hubcourseids[] = $downloadablecourse->hubcourseid;
81 //unpublish the courses by web service
82 if (!empty($hubcourseids)) {
83 $function = 'hub_unregister_courses';
84 $params = array('courseids' => $hubcourseids);
85 $serverurl = $huburl . "/local/hub/webservice/webservices.php";
86 $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
87 try {
88 $result = $xmlrpcclient->call($function, $params);
89 //delete the published courses
90 if (!empty($enrollablecourses)) {
91 $publicationmanager->delete_hub_publications($huburl, 1);
93 if (!empty($downloadablecourses)) {
94 $publicationmanager->delete_hub_publications($huburl, 0);
96 } catch (Exception $e) {
97 $errormessage = $e->getMessage();
98 $errormessage .= html_writer::empty_tag('br') .
99 get_string('errorunpublishcourses', 'hub');
100 $confirm = false;
101 $cleanregdata = 1;
106 //course unpublish went ok, unregister the site now
107 if ($confirm) {
108 $function = 'hub_unregister_site';
109 $params = array();
110 $serverurl = $huburl . "/local/hub/webservice/webservices.php";
111 $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
112 try {
113 $result = $xmlrpcclient->call($function, $params);
114 } catch (Exception $e) {
115 if (!$cleanregdata) {
116 $errormessage = $e->getMessage();
117 $confirm = false;
118 $cleanregdata = 1;
123 //check that we are still processing the unregistration,
124 //it could have been unset if an exception were previsouly catched
125 if ($confirm) {
126 $registrationmanager->delete_registeredhub($huburl);
130 if (empty($cancel) and $unregistration and !$confirm) {
132 echo $OUTPUT->header();
134 //do not check sesskey if confirm = false because this script is linked into email message
135 if (!empty($errormessage)) {
136 echo $OUTPUT->notification(get_string('unregistrationerror', 'hub', $errormessage));
139 $hub = $registrationmanager->get_registeredhub($huburl);
140 echo $OUTPUT->heading(get_string('unregisterfrom', 'hub', $hub->hubname), 3, 'main');
141 if ($cleanregdata) {
142 $siteunregistrationform = new site_clean_registration_data_form('',
143 array('huburl' => $huburl, 'hubname' => $hub->hubname));
144 } else {
145 $siteunregistrationform = new site_unregistration_form('',
146 array('huburl' => $huburl, 'hubname' => $hub->hubname));
149 $siteunregistrationform->display();
150 } else {
151 $registeredonmoodleorg = false;
152 $moodleorghub = $registrationmanager->get_registeredhub(HUB_MOODLEORGHUBURL);
153 if (!empty($moodleorghub)) {
154 $registeredonmoodleorg = true;
157 // load the hub selector form
158 $hubselectorform = new hub_selector_form();
159 $fromform = $hubselectorform->get_data();
160 $selectedhuburl = optional_param('publichub', false, PARAM_URL);
161 $unlistedhuburl = optional_param('unlistedurl', false, PARAM_TEXT);
162 $password = optional_param('password', '', PARAM_RAW);
163 $registeringhuburl = null;
164 if (!empty($unlistedhuburl)) {
165 if (clean_param($unlistedhuburl, PARAM_URL) !== '') {
166 $registeringhuburl = $unlistedhuburl;
168 } else if (!empty($selectedhuburl)) {
169 $registeringhuburl = $selectedhuburl;
172 // a hub has been selected, redirect to the hub registration page
173 if (empty($cancel) and !empty($registeringhuburl) and confirm_sesskey()) {
174 $hubname = optional_param(clean_param($registeringhuburl, PARAM_ALPHANUMEXT), '', PARAM_TEXT);
175 $params = array('sesskey' => sesskey(), 'huburl' => $registeringhuburl,
176 'password' => $password, 'hubname' => $hubname);
177 redirect(new moodle_url($CFG->wwwroot . "/" . $CFG->admin . "/registration/register.php",
178 $params));
181 echo $OUTPUT->header();
183 //check if the site is registered on Moodle.org and display a message about registering on MOOCH
184 $registered = $DB->count_records('registration_hubs', array('huburl' => HUB_MOODLEORGHUBURL, 'confirmed' => 1));
185 if (empty($registered)) {
186 $warningmsg = get_string('registermoochtips', 'hub');
187 $warningmsg .= $renderer->single_button(new moodle_url('register.php', array('huburl' => HUB_MOODLEORGHUBURL
188 , 'hubname' => 'Moodle.org')), get_string('register', 'admin'));
189 echo $renderer->box($warningmsg, 'buttons mdl-align generalbox adminwarning');
192 //do not check sesskey if confirm = false because this script is linked into email message
193 if (!empty($errormessage)) {
194 echo $OUTPUT->notification(get_string('unregistrationerror', 'hub', $errormessage));
197 echo $OUTPUT->heading(get_string('registerwith', 'hub'));
199 $hubselectorform->display();
201 if (extension_loaded('xmlrpc')) {
202 $hubs = $registrationmanager->get_registered_on_hubs();
203 if (!empty($hubs)) {
204 echo $OUTPUT->heading(get_string('registeredon', 'hub'), 3, 'main');
205 echo $renderer->registeredonhublisting($hubs);
207 } else { //display notice about xmlrpc
208 $xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
209 $xmlrpcnotification .= get_string('xmlrpcdisabledregistration', 'hub');
210 echo $OUTPUT->notification($xmlrpcnotification);
213 echo $OUTPUT->footer();