Merge branch 'w23_MDL-33007_m23_buggyiconv' of git://github.com/skodak/moodle
[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');
a8e174cc 32require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
33require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/forms.php');
f57c4047 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';
2a4eec82 83 $params = array('courseids' => $hubcourseids);
f57c4047 84 $serverurl = $huburl . "/local/hub/webservice/webservices.php";
001251f2 85 $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
f57c4047 86 try {
001251f2 87 $result = $xmlrpcclient->call($function, $params);
f57c4047 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";
001251f2 110 $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
5bfbe04e 111 try {
001251f2 112 $result = $xmlrpcclient->call($function, $params);
5bfbe04e 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 {
29ca816c 147 $registeredonmoodleorg = false;
148 $moodleorghub = $registrationmanager->get_registeredhub(HUB_MOODLEORGHUBURL);
149 if (!empty($moodleorghub)) {
150 $registeredonmoodleorg = true;
6e9cd669 151 }
29ca816c 152
f57c4047 153 echo $OUTPUT->heading(get_string('registeron', 'hub'), 3, 'main');
29ca816c 154 echo $renderer->registrationselector($registeredonmoodleorg);
5cbbcc1a 155
6e9cd669 156 if (extension_loaded('xmlrpc')) {
5cbbcc1a 157 $hubs = $registrationmanager->get_registered_on_hubs();
158 if (!empty($hubs)) {
159 echo $OUTPUT->heading(get_string('registeredon', 'hub'), 3, 'main');
160 echo $renderer->registeredonhublisting($hubs);
161 }
162 } else { //display notice about xmlrpc
0d5fae12 163 $xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
5cbbcc1a 164 $xmlrpcnotification .= get_string('xmlrpcdisabledregistration', 'hub');
165 echo $OUTPUT->notification($xmlrpcnotification);
f57c4047 166 }
167}
03d9401e 168echo $OUTPUT->footer();