Moodle 2.0.3 release
[moodle.git] / admin / registration / index.php
blobb1a2d91224d60d766dd0bbd0e13ed28668495fac
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 select if he wants to register on Moodle.org or
26 * a specific hub
29 require('../../config.php');
31 require_once($CFG->libdir . '/adminlib.php');
32 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
33 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/forms.php');
34 require_once($CFG->dirroot . '/course/publish/lib.php');
35 require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
37 admin_externalpage_setup('registrationindex');
39 $renderer = $PAGE->get_renderer('core', 'register');
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);
47 $registrationmanager = new registration_manager();
48 $publicationmanager = new course_publish_manager();
49 $errormessage = '';
50 if (empty($cancel) and $unregistration and $confirm and confirm_sesskey()) {
52 $hub = $registrationmanager->get_registeredhub($huburl);
54 //unpublish course and unregister the site by web service
55 if (!$cleanregdata) {
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;
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;
80 //unpublish the courses by web service
81 if (!empty($hubcourseids)) {
82 $function = 'hub_unregister_courses';
83 $params = array('courseids' => $hubcourseids);
84 $serverurl = $huburl . "/local/hub/webservice/webservices.php";
85 $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
86 try {
87 $result = $xmlrpcclient->call($function, $params);
88 //delete the published courses
89 if (!empty($enrollablecourses)) {
90 $publicationmanager->delete_hub_publications($huburl, 1);
92 if (!empty($downloadablecourses)) {
93 $publicationmanager->delete_hub_publications($huburl, 0);
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;
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($serverurl, $hub->token);
111 try {
112 $result = $xmlrpcclient->call($function, $params);
113 } catch (Exception $e) {
114 if (!$cleanregdata) {
115 $errormessage = $e->getMessage();
116 $confirm = false;
117 $cleanregdata = 1;
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);
129 echo $OUTPUT->header();
131 //do not check sesskey if confirm = false because this script is linked into email message
132 if (!empty($errormessage)) {
133 echo $OUTPUT->notification(get_string('unregistrationerror', 'hub', $errormessage));
135 if (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));
145 $siteunregistrationform->display();
146 } else {
147 $registeredonmoodleorg = false;
148 $moodleorghub = $registrationmanager->get_registeredhub(HUB_MOODLEORGHUBURL);
149 if (!empty($moodleorghub)) {
150 $registeredonmoodleorg = true;
153 echo $OUTPUT->heading(get_string('registeron', 'hub'), 3, 'main');
154 echo $renderer->registrationselector($registeredonmoodleorg);
156 if (extension_loaded('xmlrpc')) {
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);
162 } else { //display notice about xmlrpc
163 $xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
164 $xmlrpcnotification .= get_string('xmlrpcdisabledregistration', 'hub');
165 echo $OUTPUT->notification($xmlrpcnotification);
168 echo $OUTPUT->footer();