mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
Merge branch 'wip-MDL-60108-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
b6b299ddae
@ -699,6 +699,7 @@ if (!$cache and moodle_needs_upgrading()) {
|
||||
if (during_initial_install()) {
|
||||
set_config('rolesactive', 1); // after this, during_initial_install will return false.
|
||||
set_config('adminsetuppending', 1);
|
||||
set_config('registrationpending', 1); // Remind to register site after all other setup is finished.
|
||||
// we need this redirect to setup proper session
|
||||
upgrade_finished("index.php?sessionstarted=1&lang=$CFG->lang");
|
||||
}
|
||||
@ -814,6 +815,9 @@ if (isset($SESSION->pluginuninstallreturn)) {
|
||||
}
|
||||
}
|
||||
|
||||
// If site registration needs updating, redirect.
|
||||
\core\hub\registration::registration_reminder('/admin/index.php');
|
||||
|
||||
// Everything should now be set up, and the user is an admin
|
||||
|
||||
// Print default admin page with notifications.
|
||||
|
@ -64,8 +64,10 @@ echo $OUTPUT->heading(get_string('registrationconfirmed', 'hub'), 3, 'main');
|
||||
echo $OUTPUT->notification(get_string('registrationconfirmedon', 'hub'), 'notifysuccess');
|
||||
|
||||
// Display continue button.
|
||||
$registrationpage = new moodle_url('/admin/registration/index.php');
|
||||
$continuebutton = $OUTPUT->render(new single_button($registrationpage, get_string('continue')));
|
||||
$returnurl = !empty($SESSION->registrationredirect) ? clean_param($SESSION->registrationredirect, PARAM_LOCALURL) : null;
|
||||
unset($SESSION->registrationredirect);
|
||||
$continueurl = new moodle_url($returnurl ?: '/admin/registration/index.php');
|
||||
$continuebutton = $OUTPUT->render(new single_button($continueurl, get_string('continue')));
|
||||
$continuebutton = html_writer::tag('div', $continuebutton, array('class' => 'mdl-align'));
|
||||
echo $continuebutton;
|
||||
|
||||
|
@ -53,17 +53,25 @@ if ($unregistration && \core\hub\registration::is_registered()) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$isinitialregistration = \core\hub\registration::show_after_install(true);
|
||||
if (!$returnurl = optional_param('returnurl', null, PARAM_LOCALURL)) {
|
||||
$returnurl = $isinitialregistration ? '/admin/index.php' : '/admin/registration/index.php';
|
||||
}
|
||||
|
||||
$siteregistrationform = new \core\hub\site_registration_form();
|
||||
$siteregistrationform->set_data(['returnurl' => $returnurl]);
|
||||
if ($fromform = $siteregistrationform->get_data()) {
|
||||
|
||||
// Save the settings.
|
||||
\core\hub\registration::save_site_info($fromform);
|
||||
|
||||
if (\core\hub\registration::is_registered()) {
|
||||
\core\hub\registration::update_manual();
|
||||
redirect(new moodle_url('/admin/registration/index.php'));
|
||||
if (\core\hub\registration::update_manual()) {
|
||||
redirect(new moodle_url($returnurl));
|
||||
}
|
||||
redirect(new moodle_url('/admin/registration/index.php', ['returnurl' => $returnurl]));
|
||||
} else {
|
||||
\core\hub\registration::register();
|
||||
\core\hub\registration::register($returnurl);
|
||||
// This method will redirect away.
|
||||
}
|
||||
|
||||
@ -80,13 +88,15 @@ if (\core\hub\registration::is_registered()) {
|
||||
$lastupdated = \core\hub\registration::get_last_updated();
|
||||
if ($lastupdated == 0) {
|
||||
$registrationmessage = get_string('pleaserefreshregistrationunknown', 'admin');
|
||||
} else if (\core\hub\registration::get_new_registration_fields()) {
|
||||
$registrationmessage = get_string('pleaserefreshregistrationnewdata', 'admin');
|
||||
} else {
|
||||
$lastupdated = userdate($lastupdated, get_string('strftimedate', 'langconfig'));
|
||||
$registrationmessage = get_string('pleaserefreshregistration', 'admin', $lastupdated);
|
||||
$notificationtype = \core\output\notification::NOTIFY_INFO;
|
||||
}
|
||||
echo $OUTPUT->notification($registrationmessage, $notificationtype);
|
||||
} else {
|
||||
} else if (!$isinitialregistration) {
|
||||
$registrationmessage = get_string('registrationwarning', 'admin');
|
||||
echo $OUTPUT->notification($registrationmessage, $notificationtype);
|
||||
}
|
||||
@ -94,6 +104,8 @@ if (\core\hub\registration::is_registered()) {
|
||||
// Heading.
|
||||
if (\core\hub\registration::is_registered()) {
|
||||
echo $OUTPUT->heading(get_string('updatesite', 'hub', 'Moodle.net'));
|
||||
} else if ($isinitialregistration) {
|
||||
echo $OUTPUT->heading(get_string('completeregistration', 'hub'));
|
||||
} else {
|
||||
echo $OUTPUT->heading(get_string('registerwithmoodleorg', 'admin'));
|
||||
}
|
||||
@ -107,5 +119,7 @@ if (\core\hub\registration::is_registered()) {
|
||||
// Unregister link.
|
||||
$unregisterhuburl = new moodle_url("/admin/registration/index.php", ['unregistration' => 1]);
|
||||
echo html_writer::div(html_writer::link($unregisterhuburl, get_string('unregister', 'hub')), 'unregister');
|
||||
} else if ($isinitialregistration) {
|
||||
echo html_writer::div(html_writer::link(new moodle_url($returnurl), get_string('skipregistration', 'hub')), 'skipregistration');
|
||||
}
|
||||
echo $OUTPUT->footer();
|
||||
|
@ -36,14 +36,6 @@ class core_register_renderer extends plugin_renderer_base {
|
||||
* @return string
|
||||
*/
|
||||
public function moodleorg_registration_message() {
|
||||
$moodleorgstatslink = html_writer::link('http://moodle.net/stats',
|
||||
get_string('statsmoodleorg', 'admin'),
|
||||
array('target' => '_blank'));
|
||||
|
||||
$moodleorgregmsg = get_string('registermoodleorg', 'admin');
|
||||
$items = array(get_string('registermoodleorgli1', 'admin'),
|
||||
get_string('registermoodleorgli2', 'admin', $moodleorgstatslink));
|
||||
$moodleorgregmsg .= html_writer::alist($items);
|
||||
return $moodleorgregmsg;
|
||||
return format_text(get_string('registermoodlenet', 'admin'), FORMAT_MARKDOWN, ['noclean' => true]);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,9 @@ if ($hassiteconfig && moodle_needs_upgrading()) {
|
||||
redirect(new moodle_url('/admin/index.php'));
|
||||
}
|
||||
|
||||
// If site registration needs updating, redirect.
|
||||
\core\hub\registration::registration_reminder('/admin/search.php');
|
||||
|
||||
admin_externalpage_setup('search', '', array('query' => $query)); // now hidden page
|
||||
|
||||
$adminroot = admin_get_root(); // need all settings here
|
||||
|
@ -66,6 +66,9 @@ if ($hassiteconfig && moodle_needs_upgrading()) {
|
||||
redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
|
||||
}
|
||||
|
||||
// If site registration needs updating, redirect.
|
||||
\core\hub\registration::registration_reminder('/index.php');
|
||||
|
||||
if (get_home_page() != HOMEPAGE_SITE) {
|
||||
// Redirect logged-in users to My Moodle overview if required.
|
||||
$redirect = optional_param('redirect', 1, PARAM_BOOL);
|
||||
|
@ -844,6 +844,7 @@ $string['pgclusterdescription'] = 'PostgreSQL version/cluster parameter for comm
|
||||
$string['phpfloatproblem'] = 'Detected unexpected problem in handling of PHP float numbers - {$a}';
|
||||
$string['pleaserefreshregistration'] = 'Your site is registered. Registration last updated {$a}.<br />The \'Site registration\' scheduled task keeps your registration up to date. You can also manually update your registration at any time.';
|
||||
$string['pleaserefreshregistrationunknown'] = 'Your site has been registered but the registration date is unknown. Please update your registration using the \'Update registration\' button or ensure that the \'Site registration\' scheduled task is enabled so your registration is automatically updated.';
|
||||
$string['pleaserefreshregistrationnewdata'] = 'Registration information has been changed. Please confirm it using the \'Update registration\' button.';
|
||||
$string['plugin'] = 'Plugin';
|
||||
$string['plugins'] = 'Plugins';
|
||||
$string['pluginscheck'] = 'Plugin dependencies check';
|
||||
@ -939,6 +940,15 @@ $string['quizattemptsupgradedmessage'] = 'In Moodle 2.1 there was a major upgrad
|
||||
$string['recaptchaprivatekey'] = 'ReCAPTCHA secret key';
|
||||
$string['recaptchapublickey'] = 'ReCAPTCHA site key';
|
||||
$string['register'] = 'Register your site';
|
||||
$string['registermoodlenet'] = 'We\'d love to stay in touch for important things for your Moodle site!
|
||||
|
||||
By registering,
|
||||
|
||||
* You are contributing to our collective knowledge about the users of Moodle which helps us improve Moodle and all our community services
|
||||
* You’ll be one of the first to find out about important notifications such as security alerts and new Moodle releases.
|
||||
* You can access and activate mobile push notifications from your Moodle site through our free [Moodle Mobile app](https://download.moodle.org/mobile/)
|
||||
* Optionally, your site can be included as a proud member and supporter of the Moodle community on the [list of registered sites](https://moodle.net/stats).
|
||||
';
|
||||
$string['registermoodleorg'] = 'When you register your site';
|
||||
$string['registermoodleorgli1'] = 'You are added to a low-volume mailing list for important notifications such as security alerts and new releases of Moodle.';
|
||||
$string['registermoodleorgli2'] = 'Statistics about your site will be added to the {$a} of the worldwide Moodle community.';
|
||||
|
@ -154,3 +154,5 @@ moodleorghubname,core_admin
|
||||
hubs,core_admin
|
||||
quickdownloadcalendar,core_calendar
|
||||
ical,core_calendar
|
||||
privacy,core_hub
|
||||
privacy_help,core_hub
|
||||
|
@ -36,6 +36,7 @@ $string['audiencestudents'] = 'Students';
|
||||
$string['audienceadmins'] = 'Moodle administrators';
|
||||
$string['badgesnumber'] = 'Number of badges ({$a})';
|
||||
$string['communityremoved'] = 'That course link has been removed from your list';
|
||||
$string['completeregistration'] = 'Complete registration with Moodle.net';
|
||||
$string['confirmregistration'] = 'Confirm registration';
|
||||
$string['contributornames'] = 'Other contributors';
|
||||
$string['contributornames_help'] = 'You can use this field to list the names of anyone else who contributed to this course.';
|
||||
@ -114,8 +115,6 @@ $string['postaladdress'] = 'Postal address';
|
||||
$string['postaladdress_help'] = 'Postal address of this site, or of the entity represented by this site.';
|
||||
$string['postsnumber'] = 'Number of posts ({$a})';
|
||||
$string['previousregistrationdeleted'] = 'The previous registration has been deleted from {$a}. You can restart the registration process. Thank you.';
|
||||
$string['privacy'] = 'Privacy';
|
||||
$string['privacy_help'] = 'The hub may want to display a list of registered sites. If it does then you can choose whether or not you want to appear on that list.';
|
||||
$string['publicationinfo'] = 'Course publication information';
|
||||
$string['publishcourse'] = 'Publish {$a}';
|
||||
$string['publishcourseon'] = 'Publish on {$a}';
|
||||
@ -152,35 +151,42 @@ $string['shareon'] = 'Upload this course to {$a}';
|
||||
$string['sharepublication_help'] = 'Uploading this course to a community server will enable people to download it and install it on their own Moodle sites.';
|
||||
$string['siteadmin'] = 'Administrator';
|
||||
$string['siteadmin_help'] = 'The full name of the site administrator.';
|
||||
$string['sitecommnews'] = 'Updates about Moodle news and features';
|
||||
$string['sitecommnews_help'] = 'You have the option of subscribing to our low volume email list including a newsletter about happenings in the Moodle community. ';
|
||||
$string['sitecommnewsno'] = 'No, I do not want to receive any email from Moodle HQ';
|
||||
$string['sitecommnewsyes'] = 'Yes please, include me in Moodle’s regular e-newsletter updates';
|
||||
$string['sitecountry'] = 'Country';
|
||||
$string['sitecountry_help'] = 'The country your organisation is in.';
|
||||
$string['sitecountry_help'] = 'The country your organisation or institution is located in.';
|
||||
$string['sitedesc'] = 'Description';
|
||||
$string['sitedesc_help'] = 'This description of your site may be shown in the site listing. Please use plain text only.';
|
||||
$string['sitedesc_help'] = 'Provide some information about how you are using Moodle.';
|
||||
$string['sitegeolocation'] = 'Geolocation';
|
||||
$string['sitegeolocation_help'] = 'In future we may provide location-based searching in the hubs. If you want to specify the location for your site use a latitude/longitude value here (eg: -31.947884,115.871285). One way to find this is to use Google Maps.';
|
||||
$string['siteemail'] = 'Email address';
|
||||
$string['siteemail_help'] = 'You need to provide an email address so the hub administrator can contact you if necessary. This will not be used for any other purpose. It is recommended to enter a email address related to a position (example: sitemanager@example.com) and not directly to a person.';
|
||||
$string['siteemail'] = 'Admin email address';
|
||||
$string['siteemail_help'] = 'An email address is necessary so that Moodle HQ can contact you if required. It may also be used for other purposes as you allow below. We recommend a generic email address related to a position (eg.: sitemanager@example.com), not a personal address.';
|
||||
$string['sitelang'] = 'Language';
|
||||
$string['sitelang_help'] = 'Your site language will be displayed on the site listing.';
|
||||
$string['sitelang_help'] = 'What is the main language used on your Moodle site?';
|
||||
$string['sitename'] = 'Name';
|
||||
$string['sitename_help'] = 'The name of the site will be shown on the site listing if the hub allows that.';
|
||||
$string['sitephone'] = 'Phone';
|
||||
$string['sitephone_help'] = 'Your phone number will only be seen by the hub administrator.';
|
||||
$string['siteprivacy'] = 'Privacy';
|
||||
$string['siteprivacynotpublished'] = 'Please do not publish this site';
|
||||
$string['siteprivacypublished'] = 'Publish the site name only';
|
||||
$string['siteprivacylinked'] = 'Publish the site name with a link';
|
||||
$string['siteregistrationcontact'] = 'Contact form';
|
||||
$string['siteregistrationcontact_help'] = 'If you allow it, other people may be able to contact you via a contact form on the hub. They will never be able to see your email address.';
|
||||
$string['siteregistrationemail'] = 'Email notifications';
|
||||
$string['siteregistrationemail_help'] = 'If you enable this the hub administrator may email you to inform you of important news like security issues.';
|
||||
$string['siteprivacy'] = 'Site listing';
|
||||
$string['siteprivacy_help'] = 'You can choose to have your site listed publicly in the list of registered sites, with or without a link to your site.';
|
||||
$string['siteprivacynotpublished'] = 'Do not list my site';
|
||||
$string['siteprivacypublished'] = 'Only display my site name';
|
||||
$string['siteprivacylinked'] = 'Display my site name with the link';
|
||||
$string['siteregistrationcontact'] = 'Display contact form';
|
||||
$string['siteregistrationcontact_help'] = 'If you allow it, other people in our Moodle community (who need a login account) can contact you via a form on our Moodle community site. However, they will never be able to see your email address.';
|
||||
$string['siteregistrationemail'] = 'Notifications about important security and technical issues.';
|
||||
$string['siteregistrationemail_help'] = 'You have the option of subscribing to our low volume email list for important news (on security issues or new releases).';
|
||||
$string['siteregistrationupdated'] = 'Site registration updated';
|
||||
$string['siterelease'] = 'Moodle release';
|
||||
$string['sitereleasenum'] = 'Moodle release ({$a})';
|
||||
$string['siterelease_help'] = 'Moodle release number of this site.';
|
||||
$string['siteurl'] = 'Site URL';
|
||||
$string['siteurl_help'] = 'The URL is the address of this site. If privacy settings allow people to see site addresses then this is the URL that will be used.';
|
||||
$string['siteversion'] = 'Moodle version';
|
||||
$string['siteversion_help'] = 'The Moodle version of this site.';
|
||||
$string['skipregistration'] = 'Skip';
|
||||
$string['subject'] = 'Subject';
|
||||
$string['subject_help'] = 'Select the main subject area which the course covers.';
|
||||
$string['status'] = 'Listing status';
|
||||
@ -200,6 +206,7 @@ $string['unregistrationerror'] = 'An error occurred when the site tried to unreg
|
||||
$string['update'] = 'Update';
|
||||
$string['updatesite'] = 'Update registration on {$a}';
|
||||
$string['updatestatus'] = 'Check it now.';
|
||||
$string['usedifferentemail'] = 'Use different email';
|
||||
$string['urlalreadyregistered'] = 'Your site seems to be already registered on Moodle.net, which means something has gone wrong. Please contact the Moodle.net administrator to reset your registration so you can try again.';
|
||||
$string['usersnumber'] = 'Number of users ({$a})';
|
||||
$string['wrongtoken'] = 'The registration failed for some unknown reason (network?). Please try again.';
|
||||
@ -240,6 +247,8 @@ $string['nosearch'] = 'Don\'t publish hub or courses';
|
||||
$string['notregisteredonmoodleorg'] = 'Your administrator needs to register this site with moodle.org.';
|
||||
$string['orenterprivatehub'] = 'Alternatively, enter a private hub URL:';
|
||||
$string['prioritise'] = 'Prioritise';
|
||||
$string['privacy'] = 'Privacy';
|
||||
$string['privacy_help'] = 'The hub may want to display a list of registered sites. If it does then you can choose whether or not you want to appear on that list.';
|
||||
$string['private'] = 'Private';
|
||||
$string['privatehuburl'] = 'Private hub URL';
|
||||
$string['publichub'] = 'Public hub';
|
||||
|
@ -1567,8 +1567,8 @@ $string['refresh'] = 'Refresh';
|
||||
$string['refreshingevents'] = 'Refreshing events';
|
||||
$string['registration'] = 'Moodle registration';
|
||||
$string['registrationcontact'] = 'Contact from the public';
|
||||
$string['registrationcontactno'] = 'No, I do not want a contact form in the site listing';
|
||||
$string['registrationcontactyes'] = 'Yes, provide a form for prospective Moodlers to contact me';
|
||||
$string['registrationcontactno'] = 'No, I do not want to be contacted by other people';
|
||||
$string['registrationcontactyes'] = 'Yes, provide a form for other Moodlers to contact me';
|
||||
$string['registrationemail'] = 'Email notifications';
|
||||
$string['registrationinfo'] = '<p>This page allows you to register your Moodle site with moodle.org. Registration is free.
|
||||
The main benefit of registering is that you will be added to a low-volume mailing list
|
||||
@ -1579,9 +1579,9 @@ for important notifications such as security alerts and new releases of Moodle.<
|
||||
<p>If you choose, you can allow your site name, country and URL to be added to the public list of Moodle Sites.</p>
|
||||
<p>All new registrations are verified manually before they are added to the list, but once you are added you can update your registration (and your entry on the public list) at any time by resubmitting this form.</p>';
|
||||
$string['registrationinfotitle'] = 'Registration information';
|
||||
$string['registrationno'] = 'No, I do not want to receive email';
|
||||
$string['registrationno'] = 'No, I do not want to receive any email from Moodle HQ';
|
||||
$string['registrationsend'] = 'Send registration information to moodle.org';
|
||||
$string['registrationyes'] = 'Yes, please notify me about important issues';
|
||||
$string['registrationyes'] = 'Yes, notify me about important news (e.g. security issues or releases) ';
|
||||
$string['reject'] = 'Reject';
|
||||
$string['rejectdots'] = 'Reject...';
|
||||
$string['reload'] = 'Reload';
|
||||
|
@ -29,6 +29,7 @@ use moodle_exception;
|
||||
use moodle_url;
|
||||
use context_system;
|
||||
use stdClass;
|
||||
use html_writer;
|
||||
|
||||
/**
|
||||
* Methods to use when publishing and searching courses on moodle.net
|
||||
@ -39,9 +40,22 @@ use stdClass;
|
||||
*/
|
||||
class registration {
|
||||
|
||||
/** @var Fields used in a site registration form */
|
||||
/** @var Fields used in a site registration form.
|
||||
* IMPORTANT: any new fields with non-empty defaults have to be added to CONFIRM_NEW_FIELDS */
|
||||
const FORM_FIELDS = ['name', 'description', 'contactname', 'contactemail', 'contactphone', 'imageurl', 'privacy', 'street',
|
||||
'regioncode', 'countrycode', 'geolocation', 'contactable', 'emailalert', 'language'];
|
||||
'regioncode', 'countrycode', 'geolocation', 'contactable', 'emailalert', 'emailalertemail', 'commnews', 'commnewsemail', 'language'];
|
||||
|
||||
/** @var List of new FORM_FIELDS or siteinfo fields added indexed by the version when they were added.
|
||||
* If site was already registered, admin will be promted to confirm new registration data manually. Until registration is manually confirmed,
|
||||
* the scheduled task updating registration will be paused.
|
||||
* Keys of this array are not important as long as they increment, use current date to avoid confusions.
|
||||
*/
|
||||
const CONFIRM_NEW_FIELDS = [
|
||||
2017092200 => [
|
||||
'commnews', // Receive communication news. This was added in 3.4 and is "On" by default. Admin must confirm or opt-out.
|
||||
'mobileservicesenabled', 'mobilenotificationsenabled', 'registereduserdevices', 'registeredactiveuserdevices' // Mobile stats added in 3.4.
|
||||
],
|
||||
];
|
||||
|
||||
/** @var Site privacy: not displayed */
|
||||
const HUB_SITENOTPUBLISHED = 'notdisplayed';
|
||||
@ -162,7 +176,6 @@ class registration {
|
||||
$siteinfo['modulenumberaverage'] = average_number_of_courses_modules();
|
||||
|
||||
// Version and url.
|
||||
$siteinfo['moodleversion'] = $CFG->version;
|
||||
$siteinfo['moodlerelease'] = $CFG->release;
|
||||
$siteinfo['url'] = $CFG->wwwroot;
|
||||
|
||||
@ -182,9 +195,56 @@ class registration {
|
||||
}
|
||||
}
|
||||
|
||||
// IMPORTANT: any new fields in siteinfo have to be added to the constant CONFIRM_NEW_FIELDS.
|
||||
|
||||
return $siteinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Human-readable summary of data that will be sent to moodle.net
|
||||
*
|
||||
* @param array $siteinfo result of get_site_info()
|
||||
* @return string
|
||||
*/
|
||||
public static function get_stats_summary($siteinfo) {
|
||||
$fieldsneedconfirm = self::get_new_registration_fields();
|
||||
$summary = html_writer::tag('p', get_string('sendfollowinginfo_help', 'hub')) .
|
||||
html_writer::start_tag('ul');
|
||||
|
||||
$mobileservicesenabled = $siteinfo['mobileservicesenabled'] ? get_string('yes') : get_string('no');
|
||||
$mobilenotificationsenabled = $siteinfo['mobilenotificationsenabled'] ? get_string('yes') : get_string('no');
|
||||
$moodlerelease = $siteinfo['moodlerelease'];
|
||||
if (preg_match('/^(\d+\.\d.*?)[\. ]/', $moodlerelease, $matches)) {
|
||||
$moodlerelease = $matches[1];
|
||||
}
|
||||
$senddata = [
|
||||
'moodlerelease' => get_string('sitereleasenum', 'hub', $moodlerelease),
|
||||
'courses' => get_string('coursesnumber', 'hub', $siteinfo['courses']),
|
||||
'users' => get_string('usersnumber', 'hub', $siteinfo['users']),
|
||||
'enrolments' => get_string('roleassignmentsnumber', 'hub', $siteinfo['enrolments']),
|
||||
'posts' => get_string('postsnumber', 'hub', $siteinfo['posts']),
|
||||
'questions' => get_string('questionsnumber', 'hub', $siteinfo['questions']),
|
||||
'resources' => get_string('resourcesnumber', 'hub', $siteinfo['resources']),
|
||||
'badges' => get_string('badgesnumber', 'hub', $siteinfo['badges']),
|
||||
'issuedbadges' => get_string('issuedbadgesnumber', 'hub', $siteinfo['issuedbadges']),
|
||||
'participantnumberaverage' => get_string('participantnumberaverage', 'hub',
|
||||
format_float($siteinfo['participantnumberaverage'], 2)),
|
||||
'modulenumberaverage' => get_string('modulenumberaverage', 'hub',
|
||||
format_float($siteinfo['modulenumberaverage'], 2)),
|
||||
'mobileservicesenabled' => get_string('mobileservicesenabled', 'hub', $mobileservicesenabled),
|
||||
'mobilenotificationsenabled' => get_string('mobilenotificationsenabled', 'hub', $mobilenotificationsenabled),
|
||||
'registereduserdevices' => get_string('registereduserdevices', 'hub', $siteinfo['registereduserdevices']),
|
||||
'registeredactiveuserdevices' => get_string('registeredactiveuserdevices', 'hub', $siteinfo['registeredactiveuserdevices']),
|
||||
];
|
||||
|
||||
foreach ($senddata as $key => $str) {
|
||||
$class = in_array($key, $fieldsneedconfirm) ? ' needsconfirmation mark' : '';
|
||||
$summary .= html_writer::tag('li', $str, ['class' => 'site' . $key . $class]);
|
||||
}
|
||||
$summary .= html_writer::end_tag('ul');
|
||||
return $summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save registration info locally so it can be retrieved when registration needs to be updated
|
||||
*
|
||||
@ -195,6 +255,9 @@ class registration {
|
||||
foreach (self::FORM_FIELDS as $field) {
|
||||
set_config('site_' . $field . '_' . $cleanhuburl, $formdata->$field, 'hub');
|
||||
}
|
||||
// Even if the the connection with moodle.net fails, admin has manually submitted the form which means they don't need
|
||||
// to be redirected to the site registration page any more.
|
||||
set_config('site_regupdateversion_' . $cleanhuburl, max(array_keys(self::CONFIRM_NEW_FIELDS)), 'hub');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -235,6 +298,11 @@ class registration {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self::get_new_registration_fields()) {
|
||||
mtrace(get_string('pleaserefreshregistrationnewdata', 'admin'));
|
||||
return;
|
||||
}
|
||||
|
||||
$siteinfo = self::get_site_info();
|
||||
api::update_registration($siteinfo);
|
||||
$DB->update_record('registration_hubs', ['id' => $registration->id, 'timemodified' => time()]);
|
||||
@ -286,10 +354,11 @@ class registration {
|
||||
* Moodle.net will check that the site is accessible, register it and redirect back
|
||||
* to /admin/registration/confirmregistration.php
|
||||
*
|
||||
* @param string $returnurl
|
||||
* @throws \coding_exception
|
||||
*/
|
||||
public static function register() {
|
||||
global $DB;
|
||||
public static function register($returnurl) {
|
||||
global $DB, $SESSION;
|
||||
|
||||
if (self::is_registered()) {
|
||||
// Caller of this method must make sure that site is not registered.
|
||||
@ -313,6 +382,7 @@ class registration {
|
||||
$params = self::get_site_info();
|
||||
$params['token'] = $hub->token;
|
||||
|
||||
$SESSION->registrationredirect = $returnurl;
|
||||
redirect(new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/siteregistration.php', $params));
|
||||
}
|
||||
|
||||
@ -407,4 +477,72 @@ class registration {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does admin need to be redirected to the registration page after install?
|
||||
*
|
||||
* @param bool|null $markasviewed if set to true will mark the registration form as viewed and admin will not be redirected
|
||||
* to the registration form again (regardless of whether the site was registered or not).
|
||||
* @return bool
|
||||
*/
|
||||
public static function show_after_install($markasviewed = null) {
|
||||
global $CFG;
|
||||
if (self::is_registered()) {
|
||||
$showregistration = false;
|
||||
$markasviewed = true;
|
||||
} else {
|
||||
$showregistration = !empty($CFG->registrationpending);
|
||||
if ($showregistration) {
|
||||
$host = parse_url($CFG->wwwroot, PHP_URL_HOST);
|
||||
if ($host === 'localhost' || preg_match('|^127\.\d+\.\d+\.\d+$|', $host)) {
|
||||
// If it's a localhost, don't redirect to registration, it won't work anyway.
|
||||
$showregistration = false;
|
||||
$markasviewed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($markasviewed !== null) {
|
||||
set_config('registrationpending', !$markasviewed);
|
||||
}
|
||||
return $showregistration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of the fields in the registration form that were added since registration or last manual update
|
||||
*
|
||||
* If this list is not empty the scheduled task will be paused and admin will be reminded to update registration manually.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_new_registration_fields() {
|
||||
$fieldsneedconfirm = [];
|
||||
if (!self::is_registered()) {
|
||||
// Nothing to update if site is not registered.
|
||||
return $fieldsneedconfirm;
|
||||
}
|
||||
|
||||
$cleanhuburl = clean_param(HUB_MOODLEORGHUBURL, PARAM_ALPHANUMEXT);
|
||||
$lastupdated = (int)get_config('hub', 'site_regupdateversion_' . $cleanhuburl);
|
||||
foreach (self::CONFIRM_NEW_FIELDS as $version => $fields) {
|
||||
if ($version > $lastupdated) {
|
||||
$fieldsneedconfirm = array_merge($fieldsneedconfirm, $fields);
|
||||
}
|
||||
}
|
||||
return $fieldsneedconfirm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the site registration form if it's a new install or registration needs updating
|
||||
*
|
||||
* @param string|moodle_url $url
|
||||
*/
|
||||
public static function registration_reminder($url) {
|
||||
if (!has_capability('moodle/site:config', context_system::instance())) {
|
||||
return;
|
||||
}
|
||||
if (self::show_after_install() || self::get_new_registration_fields()) {
|
||||
$returnurl = new moodle_url($url);
|
||||
redirect(new moodle_url('/admin/registration/index.php', ['returnurl' => $returnurl->out_as_local_url(false)]));
|
||||
}
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ namespace core\hub;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use context_course;
|
||||
use stdClass;
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
@ -63,25 +64,27 @@ class site_registration_form extends \moodleform {
|
||||
'language' => explode('_', current_language())[0],
|
||||
'geolocation' => '',
|
||||
'emailalert' => 1,
|
||||
'commnews' => 1
|
||||
|
||||
]);
|
||||
|
||||
// Fields that need to be highlighted.
|
||||
$highlightfields = registration::get_new_registration_fields();
|
||||
|
||||
$mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('sitename', 'hub'),
|
||||
array('class' => 'registration_textfield'));
|
||||
$mform->addRule('name', $strrequired, 'required', null, 'client');
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addHelpButton('name', 'sitename', 'hub');
|
||||
|
||||
$mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), registration::site_privacy_options());
|
||||
$mform->setType('privacy', PARAM_ALPHA);
|
||||
$mform->addHelpButton('privacy', 'privacy', 'hub');
|
||||
$mform->addHelpButton('privacy', 'siteprivacy', 'hub');
|
||||
unset($options);
|
||||
|
||||
$mform->addElement('textarea', 'description', get_string('sitedesc', 'hub'),
|
||||
array('rows' => 8, 'cols' => 41));
|
||||
$mform->addRule('description', $strrequired, 'required', null, 'client');
|
||||
array('rows' => 3, 'cols' => 41));
|
||||
$mform->setType('description', PARAM_TEXT);
|
||||
$mform->addHelpButton('description', 'sitedesc', 'hub');
|
||||
|
||||
@ -91,8 +94,8 @@ class site_registration_form extends \moodleform {
|
||||
$mform->setType('language', PARAM_ALPHANUMEXT);
|
||||
$mform->addHelpButton('language', 'sitelang', 'hub');
|
||||
|
||||
$mform->addElement('textarea', 'street', get_string('postaladdress', 'hub'),
|
||||
array('rows' => 4, 'cols' => 41));
|
||||
// Postal address was part of this form before but not any more.
|
||||
$mform->addElement('hidden', 'street');
|
||||
$mform->setType('street', PARAM_TEXT);
|
||||
$mform->addHelpButton('street', 'postaladdress', 'hub');
|
||||
|
||||
@ -105,22 +108,19 @@ class site_registration_form extends \moodleform {
|
||||
$mform->addHelpButton('countrycode', 'sitecountry', 'hub');
|
||||
$mform->addRule('countrycode', $strrequired, 'required', null, 'client');
|
||||
|
||||
$mform->addElement('text', 'geolocation', get_string('sitegeolocation', 'hub'),
|
||||
array('class' => 'registration_textfield'));
|
||||
// Geolocation was part of this form before but not any more.
|
||||
$mform->addElement('hidden', 'geolocation');
|
||||
$mform->setType('geolocation', PARAM_RAW);
|
||||
$mform->addHelpButton('geolocation', 'sitegeolocation', 'hub');
|
||||
|
||||
$mform->addElement('text', 'contactname', get_string('siteadmin', 'hub'),
|
||||
array('class' => 'registration_textfield'));
|
||||
$mform->addRule('contactname', $strrequired, 'required', null, 'client');
|
||||
// Admin name was part of this form before but not any more.
|
||||
$mform->addElement('hidden', 'contactname');
|
||||
$mform->setType('contactname', PARAM_TEXT);
|
||||
$mform->addHelpButton('contactname', 'siteadmin', 'hub');
|
||||
|
||||
$mform->addElement('text', 'contactphone', get_string('sitephone', 'hub'),
|
||||
array('class' => 'registration_textfield'));
|
||||
$mform->addElement('hidden', 'contactphone');
|
||||
$mform->setType('contactphone', PARAM_TEXT);
|
||||
$mform->addHelpButton('contactphone', 'sitephone', 'hub');
|
||||
$mform->setForceLtr('contactphone');
|
||||
|
||||
$mform->addElement('text', 'contactemail', get_string('siteemail', 'hub'),
|
||||
array('class' => 'registration_textfield'));
|
||||
@ -134,79 +134,30 @@ class site_registration_form extends \moodleform {
|
||||
$mform->addElement('select', 'contactable', get_string('siteregistrationcontact', 'hub'), $options);
|
||||
$mform->setType('contactable', PARAM_INT);
|
||||
$mform->addHelpButton('contactable', 'siteregistrationcontact', 'hub');
|
||||
$mform->hideIf('contactable', 'privacy', 'eq', registration::HUB_SITENOTPUBLISHED);
|
||||
unset($options);
|
||||
|
||||
$options = array();
|
||||
$options[0] = get_string("registrationno");
|
||||
$options[1] = get_string("registrationyes");
|
||||
$mform->addElement('select', 'emailalert', get_string('siteregistrationemail', 'hub'), $options);
|
||||
$mform->setType('emailalert', PARAM_INT);
|
||||
$mform->addHelpButton('emailalert', 'siteregistrationemail', 'hub');
|
||||
unset($options);
|
||||
$this->add_select_with_email('emailalert', 'siteregistrationemail', [
|
||||
0 => get_string('registrationno'),
|
||||
1 => get_string('registrationyes'),
|
||||
]);
|
||||
|
||||
$this->add_select_with_email('commnews', 'sitecommnews', [
|
||||
0 => get_string('sitecommnewsno', 'hub'),
|
||||
1 => get_string('sitecommnewsyes', 'hub'),
|
||||
], in_array('commnews', $highlightfields));
|
||||
|
||||
// TODO site logo.
|
||||
$mform->addElement('hidden', 'imageurl', ''); // TODO: temporary.
|
||||
$mform->setType('imageurl', PARAM_URL);
|
||||
|
||||
$mform->addElement('header', 'sitestats', get_string('sendfollowinginfo', 'hub'));
|
||||
$mform->setExpanded('sitestats', !empty($highlightfields));
|
||||
$mform->addElement('static', 'urlstring', get_string('siteurl', 'hub'), $siteinfo['url']);
|
||||
$mform->addHelpButton('urlstring', 'siteurl', 'hub');
|
||||
|
||||
$mform->addElement('static', 'versionstring', get_string('siteversion', 'hub'), $CFG->version);
|
||||
$mform->addElement('hidden', 'moodleversion', $siteinfo['moodleversion']);
|
||||
$mform->setType('moodleversion', PARAM_INT);
|
||||
$mform->addHelpButton('versionstring', 'siteversion', 'hub');
|
||||
|
||||
$mform->addElement('static', 'releasestring', get_string('siterelease', 'hub'), $CFG->release);
|
||||
$mform->addElement('hidden', 'moodlerelease', $siteinfo['moodlerelease']);
|
||||
$mform->setType('moodlerelease', PARAM_TEXT);
|
||||
$mform->addHelpButton('releasestring', 'siterelease', 'hub');
|
||||
|
||||
// Display statistic that are going to be retrieve by moodle.net.
|
||||
|
||||
$mform->addElement('static', 'courseslabel', get_string('sendfollowinginfo', 'hub'),
|
||||
" " . get_string('coursesnumber', 'hub', $siteinfo['courses']));
|
||||
$mform->addHelpButton('courseslabel', 'sendfollowinginfo', 'hub');
|
||||
|
||||
$mform->addElement('static', 'userslabel', '',
|
||||
" " . get_string('usersnumber', 'hub', $siteinfo['users']));
|
||||
|
||||
$mform->addElement('static', 'roleassignmentslabel', '',
|
||||
" " . get_string('roleassignmentsnumber', 'hub', $siteinfo['enrolments']));
|
||||
|
||||
$mform->addElement('static', 'postslabel', '',
|
||||
" " . get_string('postsnumber', 'hub', $siteinfo['posts']));
|
||||
|
||||
$mform->addElement('static', 'questionslabel', '',
|
||||
" " . get_string('questionsnumber', 'hub', $siteinfo['questions']));
|
||||
|
||||
$mform->addElement('static', 'resourceslabel', '',
|
||||
" " . get_string('resourcesnumber', 'hub', $siteinfo['resources']));
|
||||
|
||||
$mform->addElement('static', 'badgeslabel', '',
|
||||
" " . get_string('badgesnumber', 'hub', $siteinfo['badges']));
|
||||
|
||||
$mform->addElement('static', 'issuedbadgeslabel', '',
|
||||
" " . get_string('issuedbadgesnumber', 'hub', $siteinfo['issuedbadges']));
|
||||
|
||||
$mform->addElement('static', 'participantnumberaveragelabel', '',
|
||||
" " . get_string('participantnumberaverage', 'hub', $siteinfo['participantnumberaverage']));
|
||||
|
||||
$mform->addElement('static', 'modulenumberaveragelabel', '',
|
||||
" " . get_string('modulenumberaverage', 'hub', $siteinfo['modulenumberaverage']));
|
||||
|
||||
$mobileservicestatus = $siteinfo['mobileservicesenabled'] ? get_string('yes') : get_string('no');
|
||||
$mform->addElement('static', 'mobileservicesenabledlabel', '',
|
||||
" " . get_string('mobileservicesenabled', 'hub', $mobileservicestatus));
|
||||
|
||||
$mobilenotificationsstatus = $siteinfo['mobilenotificationsenabled'] ? get_string('yes') : get_string('no');
|
||||
$mform->addElement('static', 'mobilenotificationsenabledlabel', '',
|
||||
" " . get_string('mobilenotificationsenabled', 'hub', $mobilenotificationsstatus));
|
||||
|
||||
$mform->addElement('static', 'registereduserdeviceslabel', '',
|
||||
" " . get_string('registereduserdevices', 'hub', $siteinfo['registereduserdevices']));
|
||||
|
||||
$mform->addElement('static', 'registeredactiveuserdeviceslabel', '',
|
||||
" " . get_string('registeredactiveuserdevices', 'hub', $siteinfo['registeredactiveuserdevices']));
|
||||
$mform->addElement('static', 'siteinfosummary', get_string('sendfollowinginfo', 'hub'), registration::get_stats_summary($siteinfo));
|
||||
|
||||
// Check if it's a first registration or update.
|
||||
if (registration::is_registered()) {
|
||||
@ -219,8 +170,120 @@ class site_registration_form extends \moodleform {
|
||||
|
||||
$this->add_action_buttons(false, $buttonlabel);
|
||||
|
||||
$mform->addElement('hidden', 'returnurl');
|
||||
$mform->setType('returnurl', PARAM_LOCALURL);
|
||||
|
||||
$this->set_data($siteinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add yes/no select with additional checkbox allowing to specify another email
|
||||
*
|
||||
* @param string $elementname
|
||||
* @param string $stridentifier
|
||||
* @param array|null $options options for the select element
|
||||
* @param bool $highlight highlight as a new field
|
||||
*/
|
||||
protected function add_select_with_email($elementname, $stridentifier, $options = null, $highlight = false) {
|
||||
$mform = $this->_form;
|
||||
|
||||
if ($options === null) {
|
||||
$options = [0 => get_string('no'), 1 => get_string('yes')];
|
||||
}
|
||||
|
||||
$group = [
|
||||
$mform->createElement('select', $elementname, get_string($stridentifier, 'hub'), $options),
|
||||
$mform->createElement('static', $elementname . 'sep', '', '<br/>'),
|
||||
$mform->createElement('advcheckbox', $elementname . 'newemail', '', get_string('usedifferentemail', 'hub'),
|
||||
['onchange' => "this.form.elements['{$elementname}email'].focus();"]),
|
||||
$mform->createElement('text', $elementname . 'email', get_string('email'))
|
||||
];
|
||||
|
||||
$element = $mform->addElement('group', $elementname . 'group', get_string($stridentifier, 'hub'), $group, '', false);
|
||||
if ($highlight) {
|
||||
$element->setAttributes(['class' => $element->getAttribute('class') . ' needsconfirmation mark']);
|
||||
}
|
||||
$mform->hideIf($elementname . 'email', $elementname, 'eq', 0);
|
||||
$mform->hideIf($elementname . 'newemail', $elementname, 'eq', 0);
|
||||
$mform->hideIf($elementname . 'email', $elementname . 'newemail', 'notchecked');
|
||||
$mform->setType($elementname, PARAM_INT);
|
||||
$mform->setType($elementname . 'email', PARAM_RAW_TRIMMED); // E-mail will be validated in validation().
|
||||
$mform->addHelpButton($elementname . 'group', $stridentifier, 'hub');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load in existing data as form defaults
|
||||
*
|
||||
* @param stdClass|array $defaultvalues object or array of default values
|
||||
*/
|
||||
public function set_data($defaultvalues) {
|
||||
if (is_object($defaultvalues)) {
|
||||
$defaultvalues = (array)$defaultvalues;
|
||||
}
|
||||
$defaultvalues['emailalertnewemail'] = !empty($defaultvalues['emailalert']) && !empty($defaultvalues['emailalertemail']);
|
||||
if (empty($defaultvalues['emailalertnewemail'])) {
|
||||
$defaultvalues['emailalertemail'] = '';
|
||||
}
|
||||
$defaultvalues['commnewsnewemail'] = !empty($defaultvalues['commnews']) && !empty($defaultvalues['commnewsemail']);
|
||||
if (empty($defaultvalues['commnewsnewemail'])) {
|
||||
$defaultvalues['commnewsemail'] = '';
|
||||
}
|
||||
parent::set_data($defaultvalues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation of the form data
|
||||
*
|
||||
* @param array $data array of ("fieldname"=>value) of submitted data
|
||||
* @param array $files array of uploaded files "element_name"=>tmp_file_path
|
||||
* @return array of "element_name"=>"error_description" if there are errors,
|
||||
* or an empty array if everything is OK
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
$errors = parent::validation($data, $files);
|
||||
// Validate optional emails. We do not use PARAM_EMAIL because it blindly clears the field if it is not a valid email.
|
||||
if (!empty($data['emailalert']) && !empty($data['emailalertnewemail']) && !validate_email($data['emailalertemail'])) {
|
||||
$errors['emailalertgroup'] = get_string('invalidemail');
|
||||
}
|
||||
if (!empty($data['commnews']) && !empty($data['commnewsnewemail']) && !validate_email($data['commnewsemail'])) {
|
||||
$errors['commnewsgroup'] = get_string('invalidemail');
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the form data
|
||||
*
|
||||
* @return stdClass
|
||||
*/
|
||||
public function get_data() {
|
||||
if ($data = parent::get_data()) {
|
||||
// Never return '*newemail' checkboxes, always return 'emailalertemail' and 'commnewsemail' even if not applicable.
|
||||
if (empty($data->emailalert) || empty($data->emailalertnewemail)) {
|
||||
$data->emailalertemail = null;
|
||||
}
|
||||
unset($data->emailalertnewemail);
|
||||
if (empty($data->commnews) || empty($data->commnewsnewemail)) {
|
||||
$data->commnewsemail = null;
|
||||
}
|
||||
unset($data->commnewsnewemail);
|
||||
// Always return 'contactable'.
|
||||
$data->contactable = empty($data->contactable) ? 0 : 1;
|
||||
|
||||
if (debugging('', DEBUG_DEVELOPER)) {
|
||||
// Display debugging message for developers who added fields to the form and forgot to add them to registration::FORM_FIELDS.
|
||||
$keys = array_diff(array_keys((array)$data), ['returnurl', 'mform_isexpanded_id_sitestats', 'submitbutton', 'update']);
|
||||
if ($extrafields = array_diff($keys, registration::FORM_FIELDS)) {
|
||||
debugging('Found extra fields in the form results: ' . join(', ', $extrafields), DEBUG_DEVELOPER);
|
||||
}
|
||||
if ($missingfields = array_diff(registration::FORM_FIELDS, $keys)) {
|
||||
debugging('Some fields are missing in the form results: ' . join(', ', $missingfields), DEBUG_DEVELOPER);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -525,4 +525,7 @@ function install_cli_database(array $options, $interactive) {
|
||||
if (isset($options['summary'])) {
|
||||
$DB->set_field('course', 'summary', $options['summary'], array('format' => 'site'));
|
||||
}
|
||||
|
||||
// Redirect to site registration on first login.
|
||||
set_config('registrationpending', 1);
|
||||
}
|
||||
|
@ -854,3 +854,7 @@ img.iconsmall {
|
||||
#overriderolestable .overriddenpermission {
|
||||
background-color: @warningBackground;
|
||||
}
|
||||
|
||||
#page-admin-registration-index form .mark {
|
||||
background-color: @warningBackground;
|
||||
}
|
||||
|
@ -5562,6 +5562,9 @@ img.iconsmall {
|
||||
#overriderolestable .overriddenpermission {
|
||||
background-color: #fcf8e3;
|
||||
}
|
||||
#page-admin-registration-index form .mark {
|
||||
background-color: #fcf8e3;
|
||||
}
|
||||
/* calendar.less */
|
||||
.calendar_event_category {
|
||||
background-color: #d8bfd8;
|
||||
|
Loading…
x
Reference in New Issue
Block a user