|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00018 /* 00019 * @package moodle 00020 * @subpackage registration 00021 * @author Jerome Mouneyrac <jerome@mouneyrac.com> 00022 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL 00023 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com 00024 * 00025 * On this page the administrator select if he wants to register on Moodle.org or 00026 * a specific hub 00027 */ 00028 00029 require('../../config.php'); 00030 00031 require_once($CFG->libdir . '/adminlib.php'); 00032 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php'); 00033 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/forms.php'); 00034 require_once($CFG->dirroot . '/course/publish/lib.php'); 00035 require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php"); 00036 00037 admin_externalpage_setup('registrationindex'); 00038 00039 $renderer = $PAGE->get_renderer('core', 'register'); 00040 00041 $unregistration = optional_param('unregistration', 0, PARAM_INT); 00042 $cleanregdata = optional_param('cleanregdata', 0, PARAM_BOOL); 00043 $confirm = optional_param('confirm', 0, PARAM_INT); 00044 $huburl = optional_param('huburl', '', PARAM_URL); 00045 $cancel = optional_param('cancel', null, PARAM_ALPHA); 00046 00047 $registrationmanager = new registration_manager(); 00048 $publicationmanager = new course_publish_manager(); 00049 $errormessage = ''; 00050 if (empty($cancel) and $unregistration and $confirm and confirm_sesskey()) { 00051 00052 $hub = $registrationmanager->get_registeredhub($huburl); 00053 00054 //unpublish course and unregister the site by web service 00055 if (!$cleanregdata) { 00056 00057 //check if we need to unpublish courses 00058 //enrollable courses 00059 $unpublishalladvertisedcourses = optional_param('unpublishalladvertisedcourses', 0, PARAM_INT); 00060 $hubcourseids = array(); 00061 if ($unpublishalladvertisedcourses) { 00062 $enrollablecourses = $publicationmanager->get_publications($huburl, null, 1); 00063 if (!empty($enrollablecourses)) { 00064 foreach ($enrollablecourses as $enrollablecourse) { 00065 $hubcourseids[] = $enrollablecourse->hubcourseid; 00066 } 00067 } 00068 } 00069 //downloadable courses 00070 $unpublishalluploadedcourses = optional_param('unpublishalluploadedcourses', 0, PARAM_INT); 00071 if ($unpublishalluploadedcourses) { 00072 $downloadablecourses = $publicationmanager->get_publications($huburl, null, 0); 00073 if (!empty($downloadablecourses)) { 00074 foreach ($downloadablecourses as $downloadablecourse) { 00075 $hubcourseids[] = $downloadablecourse->hubcourseid; 00076 } 00077 } 00078 } 00079 00080 //unpublish the courses by web service 00081 if (!empty($hubcourseids)) { 00082 $function = 'hub_unregister_courses'; 00083 $params = array('courseids' => $hubcourseids); 00084 $serverurl = $huburl . "/local/hub/webservice/webservices.php"; 00085 $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token); 00086 try { 00087 $result = $xmlrpcclient->call($function, $params); 00088 //delete the published courses 00089 if (!empty($enrollablecourses)) { 00090 $publicationmanager->delete_hub_publications($huburl, 1); 00091 } 00092 if (!empty($downloadablecourses)) { 00093 $publicationmanager->delete_hub_publications($huburl, 0); 00094 } 00095 } catch (Exception $e) { 00096 $errormessage = $e->getMessage(); 00097 $errormessage .= html_writer::empty_tag('br') . 00098 get_string('errorunpublishcourses', 'hub'); 00099 $confirm = false; 00100 $cleanregdata = 1; 00101 } 00102 } 00103 } 00104 00105 //course unpublish went ok, unregister the site now 00106 if ($confirm) { 00107 $function = 'hub_unregister_site'; 00108 $params = array(); 00109 $serverurl = $huburl . "/local/hub/webservice/webservices.php"; 00110 $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token); 00111 try { 00112 $result = $xmlrpcclient->call($function, $params); 00113 } catch (Exception $e) { 00114 if (!$cleanregdata) { 00115 $errormessage = $e->getMessage(); 00116 $confirm = false; 00117 $cleanregdata = 1; 00118 } 00119 } 00120 } 00121 00122 //check that we are still processing the unregistration, 00123 //it could have been unset if an exception were previsouly catched 00124 if ($confirm) { 00125 $registrationmanager->delete_registeredhub($huburl); 00126 } 00127 } 00128 00129 echo $OUTPUT->header(); 00130 00131 //do not check sesskey if confirm = false because this script is linked into email message 00132 if (!empty($errormessage)) { 00133 echo $OUTPUT->notification(get_string('unregistrationerror', 'hub', $errormessage)); 00134 } 00135 if (empty($cancel) and $unregistration and !$confirm) { 00136 $hub = $registrationmanager->get_registeredhub($huburl); 00137 echo $OUTPUT->heading(get_string('unregisterfrom', 'hub', $hub->hubname), 3, 'main'); 00138 if ($cleanregdata) { 00139 $siteunregistrationform = new site_clean_registration_data_form('', 00140 array('huburl' => $huburl, 'hubname' => $hub->hubname)); 00141 } else { 00142 $siteunregistrationform = new site_unregistration_form('', 00143 array('huburl' => $huburl, 'hubname' => $hub->hubname)); 00144 } 00145 $siteunregistrationform->display(); 00146 } else { 00147 $registeredonmoodleorg = false; 00148 $moodleorghub = $registrationmanager->get_registeredhub(HUB_MOODLEORGHUBURL); 00149 if (!empty($moodleorghub)) { 00150 $registeredonmoodleorg = true; 00151 } 00152 00153 echo $OUTPUT->heading(get_string('registeron', 'hub'), 3, 'main'); 00154 echo $renderer->registrationselector($registeredonmoodleorg); 00155 00156 if (extension_loaded('xmlrpc')) { 00157 $hubs = $registrationmanager->get_registered_on_hubs(); 00158 if (!empty($hubs)) { 00159 echo $OUTPUT->heading(get_string('registeredon', 'hub'), 3, 'main'); 00160 echo $renderer->registeredonhublisting($hubs); 00161 } 00162 } else { //display notice about xmlrpc 00163 $xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); 00164 $xmlrpcnotification .= get_string('xmlrpcdisabledregistration', 'hub'); 00165 echo $OUTPUT->notification($xmlrpcnotification); 00166 } 00167 } 00168 echo $OUTPUT->footer();