Commit a0dacc85 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon

Bug 1795099: update weekly updates in site registration

behatnotneeded

Change-Id: I384b71783922d01a788fbe8396106f4a61acbe6c
parent 7a085456
......@@ -21,13 +21,14 @@ require(get_config('libroot') . 'registration.php');
define('TITLE', get_string('Registration', 'admin'));
// This runs register_site in registration.php, which is what displays the form and the button for emails.
if (!get_config('registration_lastsent')) {
if (!get_config('registration_lastsent')
|| get_config('new_registration_policy')) {
$register = register_site();
}
else {
if (get_config('new_registration_policy')) {
$registration_update = get_string('newregistrationpolicyinfo', 'admin');
}
}
else {
$registered = register_site(true);
$firstregistered = (get_config('registration_firstsent'));
// The $firstregistered might be false if site registered before we kept this info. Otherwise format as date.
......@@ -48,4 +49,21 @@ else if (isset($registered)) {
$smarty->assign('firstregistered', $firstregistered);
}
$js = <<<EOF
jQuery(function($) {
function update_weeklyupdates_options() {
var showweeklyupdates = $('#register_registeryesno').prop('checked');
if (showweeklyupdates) {
$('#register_sendweeklyupdates_container').removeClass('hidden');
}
else {
$('#register_sendweeklyupdates_container').addClass('hidden');
}
}
$('#register_registeryesno').on('click', update_weeklyupdates_options);
update_weeklyupdates_options();
});
EOF;
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->display('admin/registersite.tpl');
......@@ -247,9 +247,11 @@ $string['Field'] = 'Field';
$string['Value'] = 'Value';
$string['dataincluded'] = 'Data included';
$string['datathathavebeensent'] = 'Data that has been sent';
$string['sendweeklyupdates'] = 'Send weekly updates';
$string['sendweeklyupdatesdescription'] = 'Allow your site to send weekly updates to <a href="https://mahara.org/">mahara.org</a> with some statistics about your site.';
$string['newregistrationpolicyinfo'] = '<p>We have updated our registration data policy to require registered sites to provide weekly updates of their data. Please follow the link below to confirm or remove your registration.</p>';
$string['registerwithmahara'] = 'Register with mahara.org';
$string['remainregistered'] = 'Remain registered';
$string['registerwithmaharadescription'] = 'Once your site is registered with the Mahara project, you cannot unregister it.';
$string['Register'] = 'Register';
$string['Registration'] = 'Registration';
$string['registrationcancelled'] = 'You can choose to register at any time by going to the <a href="%sadmin/registersite.php">site registration page</a>.';
......@@ -259,14 +261,15 @@ $string['registermaharasite'] = 'Site registration';
$string['registeryoursitesummary'] = '
<p>Registering your Mahara site with <a href="https://mahara.org/">mahara.org</a> helps us to get a picture of the Mahara installations around the world.</p>';
$string['registeryourmaharasitedetail'] = '
<p>You can choose to register your Mahara site with <a href="https://mahara.org/">mahara.org</a>. Registration is free and helps us get a picture of the Mahara installations around the world.</p>
<p>You can see the information that will be sent to mahara.org. Nothing that can personally identify any of your users will be sent. If you choose to register, Mahara will automatically send your updated information to mahara.org once a week.</p>';
$string['registrationremoved'] = 'Your site\'s registration has been removed. You can re-register with mahara.org at any time.';
$string['sendingweeklyupdates'] = 'Currently, you are sending weekly updates.';
<p>You can register your Mahara site with the Mahara project. Registration is free and helps us get a picture of the Mahara installations around the world.</p>
<p>If you decide to send weekly updates, you can see the information that will be sent to the Mahara project. Nothing that can personally identify any of your users will be sent.</p>';
$string['sendingweeklyupdates1'] = 'You are sending weekly updates.';
$string['notsendingweeklyupdates'] = 'You are not sending weekly updates.';
$string['siteisregisteredsince'] = 'Your site has been registered with <a href="https://mahara.org/">mahara.org</a> since %s.';
$string['siteisregistered'] = 'Your site is registered with <a href="https://mahara.org/">mahara.org</a>.';
$string['registeredinfo'] = 'Updated information about your site is sent to mahara.org weekly. You can see what is sent in the &quot;Data included&quot; section below. Nothing that can personally identify any of your users is sent.</p><p>To remove the registration of your site, change the &quot;Remain registered&quot; switch to &quot;No&quot; and click the &quot;Save&quot; button.';
$string['siteregistrationpolicy'] = '<p>To ensure our statistics show accurately how Mahara is being used, registration now includes sending us weekly updates. Please review and confirm your registration by clicking &quot;Save&quot; below.</p>';
$string['startsendingdata'] = 'Your site is sending weekly updates to <a href="https://mahara.org/">mahara.org</a>';
$string['stoppedsendingdata'] = 'The weekly updates have been stopped';
// Close site
$string['Close'] = 'Close';
......
......@@ -41,9 +41,6 @@ EOF;
}
$info .= '</tbody></table>';
// Check if site is already registered and set the text for the Register swithbox accordingly
$register_label = ($registered) ? get_string('remainregistered', 'admin') : get_string('registerwithmahara', 'admin');
$form = array(
'name' => 'register',
'autofocus' => false,
......@@ -63,18 +60,26 @@ EOF;
),
'registeryesno' => array(
'type' => 'switchbox',
'title' => $register_label,
'defaultvalue' => get_config('registration_sendweeklyupdates'),
'title' => get_string('registerwithmahara', 'admin'),
'description' => get_string('registerwithmaharadescription', 'admin'),
'defaultvalue' => $registered,
'disabled' => $registered,
),
'sendweeklyupdates' => array(
'type' => 'switchbox',
'title' => get_string('sendweeklyupdates', 'admin'),
'description' => get_string('sendweeklyupdatesdescription', 'admin'),
'defaultvalue' => (!$registered || get_config('registration_sendweeklyupdates')),
'class' => 'hidden',
),
'register' => array(
'type' => 'submitcancel',
'class' => 'btn-primary',
'value' => array(get_string('save', 'mahara'), get_string('cancel', 'mahara')),
),
)
);
return pieform($form);
),
);
return pieform($form);
}
/**
* Runs when registration form is submitted
......@@ -83,24 +88,24 @@ function register_submit(Pieform $form, $values) {
global $SESSION;
// If there is a timecode in this field, the site was registered at this time.
$registered = get_config('registration_lastsent');
// Depending on if the site was registered previously and what value was submitted in the 'registeryesno' field,
$registered = get_config('registration_lastsent') && !get_config('new_registration_policy');
// Depending on if the site was registered previously and what value was submitted in the 'sendweeklyupdates' field,
// there are three options:
$registerchanged = (!$registered && $values['registeryesno']);
$weeklyupdateschanged =
($registered || $values['registeryesno']) &&
(get_config('registration_sendweeklyupdates') != $values['sendweeklyupdates']);
// 1. cancel (i.e, the user made no changes)
if (!$registered && !$values['registeryesno'] || $registered && $values['registeryesno']) {
// Not registered, not registering OR registered and registering - cancel
if ($registered && !get_config ('registration_firstsent')) {
set_config('registration_firstsent', time());
}
if (!$registerchanged && !$weeklyupdateschanged) {
register_cancel_register();
}
// 2. remove registation
else if ($registered && !$values['registeryesno']) {
remove_registration();
// 2. add/remove weekly updates
else if ($registered && $weeklyupdateschanged) {
update_weeklyupdates($values);
}
// 3. registering, continue
// 3. registering, continue
$result = registration_send_data();
$data = json_decode($result->data);
......@@ -113,7 +118,7 @@ function register_submit(Pieform $form, $values) {
if (!get_config('registration_firstsent')) {
set_config('registration_firstsent', time());
}
set_config('registration_sendweeklyupdates', $values['registeryesno']);
set_config('registration_sendweeklyupdates', $values['sendweeklyupdates']);
if (get_config('new_registration_policy')) {
set_config('new_registration_policy', false);
}
......@@ -141,17 +146,22 @@ function register_submit(Pieform $form, $values) {
}
/**
* Runs when the 'Remove' button is clicked
* Runs when the 'Weekly updates' switch is changed
*/
function remove_registration() {
function update_weeklyupdates($values) {
global $SESSION;
set_config('registration_lastsent', 0);
set_config('registration_sendweeklyupdates', 0);
set_config('registration_sendweeklyupdates', $values['sendweeklyupdates']);
if (get_config('new_registration_policy')) {
set_config('new_registration_policy', 0);
set_config('new_registration_policy', false);
}
if ($values['sendweeklyupdates']) {
$SESSION->add_ok_msg(get_string('startsendingdata', 'admin'), false);
}
else {
$SESSION->add_ok_msg(get_string('stoppedsendingdata', 'admin'));
}
$SESSION->add_ok_msg(get_string('registrationremoved', 'admin'));
redirect('/admin/index.php');
}
......@@ -162,7 +172,6 @@ function register_cancel_register() {
global $SESSION;
if (get_config('new_registration_policy')) {
set_config('new_registration_policy', 0);
$SESSION->add_ok_msg(get_string('registrationcancelled', 'admin', get_config('wwwroot')), false);
}
......
......@@ -85,7 +85,9 @@
<p>{str tag=siteisregisteredsince section=admin args=$firstregistered}</p>
{/if}
{if $sendweeklyupdates}
<p>{str tag=sendingweeklyupdates section=admin}</p>
<p>{str tag=sendingweeklyupdates1 section=admin}</p>
{else}
<p>{str tag=notsendingweeklyupdates section=admin}</p>
{/if}
</div>
<a class="panel-footer" href="{$WWWROOT}admin/registersite.php">{str tag=Registration section=admin} <span class="icon icon-arrow-circle-right pull-right" role="presentation" aria-hidden="true"></span></a>
......
......@@ -7,18 +7,16 @@
{str tag=siteregistrationpolicy section=admin}
{/if}
{if $register}
{str tag=registeryourmaharasitedetail section=admin args=$WWWROOT}
{str tag=registeryourmaharasitedetail section=admin}
{$register|safe}
{else}
{if $firstregistered}
<p><strong>{str tag=siteisregisteredsince section=admin args=$firstregistered}</strong></p>
{str tag=registeredinfo section=admin}
{$registered|safe}
{else}
<p><strong>{str tag=siteisregistered section=admin}</strong></p>
{str tag=registeredinfo section=admin}
{$registered|safe}
{/if}
{str tag=registeryourmaharasitedetail section=admin}
{$registered|safe}
{/if}
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment