From a6a6b523ec8ae27b3186b819fa4a2757b8478804 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 23 Jun 2017 11:25:58 +0800 Subject: [PATCH] MDL-59496 registration: display unregistered warning consistently --- admin/registration/index.php | 9 ++----- admin/registration/register.php | 4 ++- admin/renderer.php | 26 ++++++++++++++++--- admin/search.php | 6 +++++ lang/en/admin.php | 1 + .../output/airnotifier/requestaccesskey.php | 9 +++---- 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/admin/registration/index.php b/admin/registration/index.php index 8b3301436b2..b9aeb18f8d7 100644 --- a/admin/registration/index.php +++ b/admin/registration/index.php @@ -181,13 +181,8 @@ if (empty($cancel) and $unregistration and !$confirm) { echo $OUTPUT->header(); //check if the site is registered on Moodle.org and display a message about registering on MOOCH - $registered = $DB->count_records('registration_hubs', array('huburl' => HUB_MOODLEORGHUBURL, 'confirmed' => 1)); - if (empty($registered)) { - $warningmsg = get_string('registermoochtips', 'hub'); - $warningmsg .= $renderer->single_button(new moodle_url('register.php', array('huburl' => HUB_MOODLEORGHUBURL - , 'hubname' => 'Moodle.org')), get_string('register', 'admin')); - echo $renderer->box($warningmsg, 'buttons mdl-align generalbox adminwarning'); - } + $adminrenderer = $PAGE->get_renderer('core', 'admin'); + echo $adminrenderer->warn_if_not_registered(); //do not check sesskey if confirm = false because this script is linked into email message if (!empty($errormessage)) { diff --git a/admin/registration/register.php b/admin/registration/register.php index 86ac1023742..15c30cd87fa 100644 --- a/admin/registration/register.php +++ b/admin/registration/register.php @@ -180,17 +180,19 @@ if (!empty($error)) { // Some Moodle.org registration explanation. if ($huburl == HUB_MOODLEORGHUBURL) { + $notificationtype = \core\output\notification::NOTIFY_ERROR; if (!empty($registeredhub->token)) { if ($registeredhub->timemodified == 0) { $registrationmessage = get_string('pleaserefreshregistrationunknown', 'admin'); } else { $lastupdated = userdate($registeredhub->timemodified, get_string('strftimedate', 'langconfig')); $registrationmessage = get_string('pleaserefreshregistration', 'admin', $lastupdated); + $notificationtype = \core\output\notification::NOTIFY_INFO; } } else { $registrationmessage = get_string('registrationwarning', 'admin'); } - echo $OUTPUT->notification($registrationmessage); + echo $OUTPUT->notification($registrationmessage, $notificationtype); echo $OUTPUT->heading(get_string('registerwithmoodleorg', 'admin')); $renderer = $PAGE->get_renderer('core', 'register'); diff --git a/admin/renderer.php b/admin/renderer.php index 2d6c362e0e9..5cea96e0ba9 100644 --- a/admin/renderer.php +++ b/admin/renderer.php @@ -782,17 +782,37 @@ class core_admin_renderer extends plugin_renderer_base { if (!$registered) { - $registerbutton = $this->single_button(new moodle_url('/admin/registration/register.php', + if (has_capability('moodle/site:config', context_system::instance())) { + $registerbutton = $this->single_button(new moodle_url('/admin/registration/register.php', array('huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.org')), get_string('register', 'admin')); + $str = 'registrationwarning'; + } else { + $registerbutton = ''; + $str = 'registrationwarningcontactadmin'; + } - return $this->warning( get_string('registrationwarning', 'admin') - . ' ' . $this->help_icon('registration', 'admin') . $registerbutton ); + return $this->warning( get_string($str, 'admin') + . ' ' . $this->help_icon('registration', 'admin') . $registerbutton , + 'error alert alert-danger'); } return ''; } + /** + * Return an admin page warning if site is not registered with moodle.org + * + * @since Moodle 3.3.2 + * @return string + */ + public function warn_if_not_registered() { + global $CFG; + require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php'); + $registrationmanager = new registration_manager(); + return $this->registration_warning($registrationmanager->get_registeredhub(HUB_MOODLEORGHUBURL) ? true : false); + } + /** * Helper method to render the information about the available Moodle update * diff --git a/admin/search.php b/admin/search.php index 7dd8e2c0a77..fb38431137b 100644 --- a/admin/search.php +++ b/admin/search.php @@ -38,6 +38,12 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->action) and // to modify them echo $OUTPUT->header($focus); +// Display a warning if site is not registered. +if (empty($query)) { + $adminrenderer = $PAGE->get_renderer('core', 'admin'); + echo $adminrenderer->warn_if_not_registered(); +} + echo $OUTPUT->heading(get_string('administrationsite')); if ($errormsg !== '') { diff --git a/lang/en/admin.php b/lang/en/admin.php index 11e67e53116..3f7bd918b8c 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -939,6 +939,7 @@ $string['registerwithmoodleorg'] = 'Register your site'; $string['registration'] = 'Registration'; $string['registration_help'] = 'It is recommended that you register your site in order to receive security alerts and access to Moodle.net, our course sharing platform.'; $string['registrationwarning'] = 'Your site is not yet registered.'; +$string['registrationwarningcontactadmin'] = 'Your site is not yet registered. Please notify your administrator.'; $string['releasenoteslink'] = 'For information about this version of Moodle, please see the online Release Notes'; $string['rememberusername'] = 'Remember username'; $string['rememberusername_desc'] = 'Enable if you want to store permanent cookies with usernames during user login. Permanent cookies may be considered a privacy issue if used without consent.'; diff --git a/message/output/airnotifier/requestaccesskey.php b/message/output/airnotifier/requestaccesskey.php index 0b5ff281b6f..3d1991fc3e2 100644 --- a/message/output/airnotifier/requestaccesskey.php +++ b/message/output/airnotifier/requestaccesskey.php @@ -23,7 +23,6 @@ */ require('../../../config.php'); -require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php'); define('AIRNOTIFIER_PUBLICURL', 'https://messages.moodle.net'); @@ -50,10 +49,10 @@ $msg = ""; // If we are requesting a key to the official message system, verify first that this site is registered. // This check is also done in Airnotifier. if (strpos($CFG->airnotifierurl, AIRNOTIFIER_PUBLICURL) !== false ) { - $registrationmanager = new registration_manager(); - if (!$registrationmanager->get_registeredhub(HUB_MOODLEORGHUBURL)) { - $msg = get_string('sitemustberegistered', 'message_airnotifier'); - $msg .= $OUTPUT->continue_button($returl); + $adminrenderer = $PAGE->get_renderer('core', 'admin'); + $msg = $adminrenderer->warn_if_not_registered(); + if ($msg) { + $msg .= html_writer::div(get_string('sitemustberegistered', 'message_airnotifier')); echo $OUTPUT->header(); echo $OUTPUT->box($msg, 'generalbox');