From 5cbbcc1ae641cabe29754ec5ce98df69cbaf9841 Mon Sep 17 00:00:00 2001 From: jerome mouneyrac Date: Fri, 2 Jul 2010 03:40:12 +0000 Subject: [PATCH] registration MDL-22964 check if xmlrpc is enabled on the registration pages, publication pages and community block page. --- admin/registration/confirmregistration.php | 32 ++++++++++++++-------- admin/registration/index.php | 16 ++++++++--- blocks/community/communitycourse.php | 8 +++++- course/publish/index.php | 25 +++++++++++------ course/publish/metadata.php | 23 ++++++++++++---- lang/en/hub.php | 4 ++- 6 files changed, 76 insertions(+), 32 deletions(-) diff --git a/admin/registration/confirmregistration.php b/admin/registration/confirmregistration.php index 2371786de06..37e2f640500 100644 --- a/admin/registration/confirmregistration.php +++ b/admin/registration/confirmregistration.php @@ -1,4 +1,5 @@ libdir.'/adminlib.php'); -require_once($CFG->dirroot.'/admin/registration/lib.php'); +require_once($CFG->libdir . '/adminlib.php'); +require_once($CFG->dirroot . '/admin/registration/lib.php'); -$newtoken = optional_param('newtoken', '', PARAM_ALPHANUM); -$url = optional_param('url', '', PARAM_URL); -$hubname = optional_param('hubname', '', PARAM_TEXT); -$token = optional_param('token', '', PARAM_ALPHANUM); -$error = optional_param('error', '', PARAM_ALPHANUM); +$newtoken = optional_param('newtoken', '', PARAM_ALPHANUM); +$url = optional_param('url', '', PARAM_URL); +$hubname = optional_param('hubname', '', PARAM_TEXT); +$token = optional_param('token', '', PARAM_ALPHANUM); +$error = optional_param('error', '', PARAM_ALPHANUM); admin_externalpage_setup('siteregistrationconfirmed'); //check that we are waiting a confirmation from this hub, and check that the token is correct $registrationmanager = new registration_manager(); $registeredhub = $registrationmanager->get_unconfirmedhub($url); -if (!empty($registeredhub) and $registeredhub->token == $token) { +if (!empty($registeredhub) and $registeredhub->token == $token) { echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('registrationconfirmed', 'hub'), 3, 'main'); @@ -61,15 +62,22 @@ if (!empty($registeredhub) and $registeredhub->token == $token) { $registeredhub->confirmed = 1; $registeredhub->huname = $hubname; $registrationmanager->update_registeredhub($registeredhub); - + $notificationmessage = $OUTPUT->notification(get_string('registrationconfirmedon', 'hub', $hublink), 'notifysuccess'); } echo $notificationmessage; + + if (!extension_loaded('xmlrpc')) { + //display notice about xmlrpc + $xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); + $xmlrpcnotification .= get_string('xmlrpcdisabledregistration', 'hub'); + echo $OUTPUT->notification($xmlrpcnotification); + } + echo $OUTPUT->footer(); - } else { - throw new moodle_exception('wrongtoken', 'hub', $CFG->wwwroot.'/admin/registration/index.php'); + throw new moodle_exception('wrongtoken', 'hub', $CFG->wwwroot . '/admin/registration/index.php'); } diff --git a/admin/registration/index.php b/admin/registration/index.php index ae3d6068741..1abc2c5f8d3 100644 --- a/admin/registration/index.php +++ b/admin/registration/index.php @@ -146,10 +146,18 @@ if (empty($cancel) and $unregistration and !$confirm) { } else { echo $OUTPUT->heading(get_string('registeron', 'hub'), 3, 'main'); echo $renderer->registrationselector(); - $hubs = $registrationmanager->get_registered_on_hubs(); - if (!empty($hubs)) { - echo $OUTPUT->heading(get_string('registeredon', 'hub'), 3, 'main'); - echo $renderer->registeredonhublisting($hubs); + + + if (extension_loaded('xmlrpc')) { + $hubs = $registrationmanager->get_registered_on_hubs(); + if (!empty($hubs)) { + echo $OUTPUT->heading(get_string('registeredon', 'hub'), 3, 'main'); + echo $renderer->registeredonhublisting($hubs); + } + } else { //display notice about xmlrpc + $xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); + $xmlrpcnotification .= get_string('xmlrpcdisabledregistration', 'hub'); + echo $OUTPUT->notification($xmlrpcnotification); } } echo $OUTPUT->footer(); diff --git a/blocks/community/communitycourse.php b/blocks/community/communitycourse.php index 2944ce63cae..7ce155a8086 100644 --- a/blocks/community/communitycourse.php +++ b/blocks/community/communitycourse.php @@ -47,9 +47,15 @@ $search = optional_param('search', null, PARAM_TEXT); $usercansearch = has_capability('moodle/community:add', get_context_instance(CONTEXT_USER, $USER->id)); $usercandownload = has_capability('moodle/community:download', get_context_instance(CONTEXT_USER, $USER->id)); if (empty($usercansearch)) { + $notificationerror = get_string('cannotsearchcommunity', 'hub'); +} else if (!extension_loaded('xmlrpc')) { + $notificationerror = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); + $notificationerror .= get_string('xmlrpcdisabledcommunity', 'hub'); +} +if (!empty($notificationerror) ) { echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('searchcommunitycourse', 'block_community'), 3, 'main'); - echo $OUTPUT->notification(get_string('cannotsearchcommunity', 'hub')); + echo $OUTPUT->notification($notificationerror); echo $OUTPUT->footer(); die(); } diff --git a/course/publish/index.php b/course/publish/index.php index 9af10e5dfb3..3bdbb508e80 100644 --- a/course/publish/index.php +++ b/course/publish/index.php @@ -38,6 +38,22 @@ $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); require_login($course); +$PAGE->set_url('/course/publish/index.php', array('id' => $course->id)); +$PAGE->set_pagelayout('course'); +$PAGE->set_title(get_string('course') . ': ' . $course->fullname); +$PAGE->set_heading($course->fullname); + +//check that the PHP xmlrpc extension is enabled +if (!extension_loaded('xmlrpc')) { + $notificationerror = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); + $notificationerror .= get_string('xmlrpcdisabledpublish', 'hub'); + echo $OUTPUT->header(); + echo $OUTPUT->heading(get_string('publishcourse', 'hub', $course->shortname), 3, 'main'); + echo $OUTPUT->notification($notificationerror); + echo $OUTPUT->footer(); + die(); +} + if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $id))) { $publicationmanager = new course_publish_manager(); @@ -78,12 +94,6 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, } } - - $PAGE->set_url('/course/publish/index.php', array('id' => $course->id)); - $PAGE->set_pagelayout('course'); - $PAGE->set_title(get_string('course') . ': ' . $course->fullname); - $PAGE->set_heading($course->fullname); - //if the site os registered on no hub display an error page $registrationmanager = new registration_manager(); $registeredhubs = $registrationmanager->get_registered_on_hubs(); @@ -96,8 +106,7 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, } $renderer = $PAGE->get_renderer('core', 'publish'); - - + /// UNPUBLISH $cancel = optional_param('cancel', 0, PARAM_BOOL); if (!empty($cancel) and confirm_sesskey()) { diff --git a/course/publish/metadata.php b/course/publish/metadata.php index 56fe80b3b7b..247a6faff21 100644 --- a/course/publish/metadata.php +++ b/course/publish/metadata.php @@ -47,13 +47,24 @@ if (empty($id)) { $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); require_login($course); -if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $id))) { +//page settings +$PAGE->set_url('/course/publish/metadata.php', array('id' => $course->id)); +$PAGE->set_pagelayout('course'); +$PAGE->set_title(get_string('course') . ': ' . $course->fullname); +$PAGE->set_heading($course->fullname); - //page settings - $PAGE->set_url('/course/publish/metadata.php', array('id' => $course->id)); - $PAGE->set_pagelayout('course'); - $PAGE->set_title(get_string('course') . ': ' . $course->fullname); - $PAGE->set_heading($course->fullname); +//check that the PHP xmlrpc extension is enabled +if (!extension_loaded('xmlrpc')) { + $errornotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); + $errornotification .= get_string('xmlrpcdisabledpublish', 'hub'); + echo $OUTPUT->header(); + echo $OUTPUT->heading(get_string('publishcourse', 'hub', $course->shortname), 3, 'main'); + echo $OUTPUT->notification($errornotification); + echo $OUTPUT->footer(); + die(); +} + +if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $id))) { //retrieve hub name and hub url $huburl = optional_param('huburl', '', PARAM_URL); diff --git a/lang/en/hub.php b/lang/en/hub.php index 9f797a420ed..e2f8c95a4d4 100644 --- a/lang/en/hub.php +++ b/lang/en/hub.php @@ -260,4 +260,6 @@ $string['usersnumber'] = 'Number of users ({$a})'; $string['warning'] = 'WARNING'; $string['wrongtoken'] = 'The registration failed for some unknown reason (network?). Please try again.'; $string['wrongurlformat'] = 'Bad URL format'; - +$string['xmlrpcdisabledcommunity'] = 'The XML-RPC extension is not enabled on the server. You can not search and download courses.'; +$string['xmlrpcdisabledpublish'] = 'The XML-RPC extension is not enabled on the server. You can not publish courses or manage published courses.'; +$string['xmlrpcdisabledregistration'] = 'The XML-RPC extension is not enabled on the server. You will not be able to unregister or update your registration until you enable it.';