Commit 2814975b authored by Maria Sorica's avatar Maria Sorica Committed by Robert Lyon
Browse files

Bug 1746259: Show the T&C on the after login page

behatnotneeded

Change-Id: I3bf21e40c957fd97b7c1b0d836ed340bebeb7616
parent 94533acc
......@@ -765,39 +765,53 @@ function privacy_form($ignoreagreevalue = false) {
}
foreach ($latestversions as $privacy) {
$privacytitle = $privacy->institution == 'mahara' ? get_string('siteprivacystatement', 'admin') : get_string('institutionprivacystatement', 'admin');
if ($privacy->type == 'privacy') {
$title = get_string('institutionprivacystatement', 'admin');
if ($privacy->institution == 'mahara') {
$title = get_string('siteprivacystatement', 'admin');
}
}
else {
$title = get_string('institutiontermsstatement', 'admin');
if ($privacy->institution == 'mahara') {
$title = get_string('sitetermsstatement', 'admin');
}
}
$smarty = smarty_core();
$smarty->assign('privacy', $privacy);
$smarty->assign('privacytitle', $privacytitle);
$smarty->assign('privacytitle', $title);
$smarty->assign('privacytime', format_date(strtotime($privacy->ctime)));
$smarty->assign('ignoreagreevalue', $ignoreagreevalue);
$htmlbegin = $smarty->fetch('privacy_panel_begin.tpl');
//Build form elements.
$elements[$privacy->institution . 'text'] = array(
$elements[$privacy->institution . $privacy->type . 'text'] = array(
'type' => 'markup',
'value' => $htmlbegin,
);
$elements[$privacy->institution . 'id'] = array(
$elements[$privacy->institution . $privacy->type . 'id'] = array(
'type' => 'hidden',
'value' => $privacy->id,
);
$elements[$privacy->institution] = array(
$elements[$privacy->institution . $privacy->type] = array(
'type' => 'switchbox',
'title' => get_string('privacyagreement', 'admin'),
'description' => $privacy->agreed ? get_string('privacyagreedto', 'admin', format_date(strtotime($privacy->agreedtime))) : '',
'title' => get_string('privacyagreement', 'admin', get_string($privacy->type . 'lowcase', 'admin')),
'description' => $privacy->agreed ? get_string('privacyagreedto', 'admin',
get_string($privacy->type . 'lowcase', 'admin'), format_date(strtotime($privacy->agreedtime))) : '',
'defaultvalue' => $privacy->agreed ? true : false,
'disabled' => ($privacy->agreed && $ignoreagreevalue) ? true : false,
'required' => true,
);
$elements[$privacy->institution . 'switch'] = array(
$elements[$privacy->institution . $privacy->type . 'switch'] = array(
'type' => 'hidden',
'value' => ($privacy->agreed && $ignoreagreevalue) ? 'disabled' : 'enabled',
);
$smarty = smarty_core();
$smarty->assign('ignoreagreevalue', $ignoreagreevalue);
$htmlend = $smarty->fetch('privacy_panel_end.tpl');
$elements[$privacy->institution . 'text2'] = array(
$elements[$privacy->institution . $privacy->type . 'text2'] = array(
'type' => 'markup',
'value' => $htmlend,
);
......@@ -838,7 +852,7 @@ function auth_check_required_fields() {
// Build the agree with privacy statement form.
$form = privacy_form(true);
define('TITLE', get_string('privacy', 'admin'));
define('TITLE', get_string('legal', 'admin'));
$smarty = smarty();
setpageicon($smarty, 'icon-umbrella');
if ($USER->get('parentuser')) {
......@@ -1240,13 +1254,20 @@ function requiredfields_submit(Pieform $form, $values) {
function agreetoprivacy_submit(Pieform $form, $values) {
global $USER, $SESSION;
$userinstitutions = array_keys($USER->get('institutions'));
array_push($userinstitutions, 'mahara');
$institutions = array('maharaprivacy', 'maharatermsandconditions');
$userinstitution = array_keys($USER->get('institutions'));
if (!empty($userinstitution)) {
array_push($userinstitution, $userinstitution[0] . 'termsandconditions', $userinstitution[0] . 'privacy');
array_shift($userinstitution);
$institutions = array_merge($institutions, $userinstitution);
}
$hasrefused = param_integer('hasrefused', 0);
$reason = param_variable('reason', '');
$whathasbeenrefused = array();
foreach ($userinstitutions as $institution) {
foreach ($institutions as $institution) {
// check if the institution has a privacy statement
// if not, it depends on the site one and we can skip it
// if yes, check if the user has already accepted it (switch is disabled)
......@@ -1256,23 +1277,26 @@ function agreetoprivacy_submit(Pieform $form, $values) {
try {
$agreed = (empty($values[$institution]) ? 0 : $values[$institution]);
save_user_reply_to_agreement($USER->get('id'), $values[$institution . 'id'], $agreed);
$SESSION->add_ok_msg(get_string('agreementsaved', 'admin'));
if ($hasrefused) {
// Send a message to the institution/site admin informing that the user has refused the privacy statement.
$institution = new Institution($institution);
$institution->send_admin_institution_refused_privacy_message($USER->get('id'), $reason);
suspend_user($USER->get('id'), 'privacyrefusal');
$SESSION->add_ok_msg(get_string('usersuspended', 'admin'));
$USER->logout();
redirect();
if (!$agreed) {
array_push($whathasbeenrefused, strpos($institution , 'privacy') ? 'privacylowcase' : 'termsandconditionslowcase');
}
$SESSION->add_ok_msg(get_string('agreementsaved', 'admin'));
}
catch (SQLException $e) {
$SESSION->add_ok_msg(get_string('savefailed', 'admin'));
}
}
// Moved this here to allow all refused items to be saved in the DB.
if ($hasrefused) {
// Send a message to the institution/site admin informing that the user has refused the privacy statement.
$institution = new Institution(str_replace(array('privacy', 'termsandconditions'), array('', ''), $institution));
$institution->send_admin_institution_refused_privacy_message($USER->get('id'), $reason, $whathasbeenrefused);
suspend_user($USER->get('id'), $whathasbeenrefused);
$SESSION->add_ok_msg(get_string('usersuspended', 'admin'));
$USER->logout();
redirect();
}
$USER->renew();
redirect();
}
......
......@@ -25,7 +25,8 @@ function showTab(el) {
}
$(el).removeClass("js-hidden");
$(el + '-text').removeClass("js-hidden");
// Useful in case an institution has just one type of content
// Institution Legal: Useful in case an institution has just one type of content (privacy/T&C).
if (typeof types != 'undefined') {
showNoContentAddOne(el);
}
......
......@@ -1351,16 +1351,17 @@ $string['addoneversionlink'] = '<a href="%s">Add one</a> if you need it.';
$string['privacyversionfor'] = 'Privacy statement for version "%s" is as follows:';
$string['termsversionfor'] = 'Terms and conditions for version "%s" is as follows:';
$string['institutionprivacystatement'] = 'Institution privacy statement';
$string['institutiontermsstatement'] = 'Institution terms and conditions';
$string['userprivacypagedescription'] = 'Displayed are the current privacy statements to which you consented.';
$string['lastupdated'] = 'Last updated on';
$string['newprivacy'] = 'Before entering your account, please read the privacy statement displayed below.';
$string['privacyagreement'] = 'I consent to this privacy statement';
$string['newprivacy'] = 'Before entering your account, please read the information displayed below.';
$string['privacyagreement'] = 'I consent to this %s';
$string['privacyagreementdescription'] = 'By choosing "Yes", you give your consent to the clauses of the privacy statement above.';
$string['privacyagreedto'] = 'You agreed to this privacy statement in %s.';
$string['privacyagreedto'] = 'You agreed to this %s in %s.';
$string['agreementsaved'] = 'Agreement saved';
$string['refuseprivacy'] = 'Refuse privacy statement';
$string['refuseprivacy'] = 'Refuse privacy statement or terms and condititons';
$string['confirmprivacyrefusal'] = 'Are you really sure you wish to continue?';
$string['privacyrefusaldetails'] = 'If you do not consent to the privacy statement, your account will be suspended.';
$string['privacyrefusaldetails'] = 'If you do not consent to the privacy statements or terms and conditions, your account will be suspended.';
$string['privacyrefusal'] = 'Refused to consent to the privacy statement.';
$string['registerprivacyrefusal'] = 'Your account will not be created when you do not consent to the privacy statement.';
$string['registerprivacydetails'] = 'Please read the privacy statement. If you do not consent to it, you cannot create an account on the site.';
......@@ -1368,3 +1369,6 @@ $string['enterreason'] = 'Please enter the reason of refusal here...';
$string['hasrefused'] = 'has refused the privacy statement';
$string['privacylowcase'] = 'privacy statement';
$string['termsandconditionslowcase'] = 'terms and conditions';
$string['hasrefused'] = 'has refused the %s';
$string['privacyandtotheterms'] = 'privacy statement and to the terms and conditions';
$string['privacyandtheterms'] = 'privacy statement and the terms and conditions';
......@@ -769,7 +769,7 @@ The %s Team';
$string['institutionmemberrefusedprivacy'] = 'Hello %s,
The user %s, with the username %s, has refused the privacy statement. Their user account was suspended.
The user %s, with the username %s, has refused the %s. Their user account was suspended.
%s %s
Please contact the user via email at %s if you wish to discuss the refusal.
......@@ -886,7 +886,7 @@ $string['youraccounthasbeensuspendedtextcron'] = 'Your account at %s has been su
$string['youraccounthasbeensuspendedreasontext'] = "Your account at %s has been suspended by %s. Reason:\n\n%s";
$string['youraccounthasbeensuspendedreasontextcron'] = "Your account at %s has been suspended. Reason:\n\n%s";
$string['youraccounthasbeenunsuspendedtext2'] = 'Your account at %s has been unsuspended. You may once again log in and use the site.'; // can't provide a login link because we don't know how they log in - it might be by xmlrpc
$string['youraccounthasbeensuspendedtext3'] = 'Your account on %s has been suspended because you refused to consent to the privacy statement';
$string['youraccounthasbeensuspendedtext3'] = 'Your account on %s has been suspended because you refused to consent to the %s.';
// size of stuff
$string['sizemb'] = 'MB';
......
......@@ -472,8 +472,9 @@ class Institution {
*
* @param integer $studentid The id of the user who has refused the privacy statement.
* @param string $reason The reson why the user refused the privacy statement.
* @param array $whathasbeenrefused The content (privacy statement or terms or both) that the user has refused.
*/
public function send_admin_institution_refused_privacy_message($studentid, $reason) {
public function send_admin_institution_refused_privacy_message($studentid, $reason, $whathasbeenrefused) {
$student = new User();
$student->find_by_id($studentid);
$studentname = display_name($student, null, true);
......@@ -489,6 +490,7 @@ class Institution {
$thereasonis = get_string('thereasonis', 'mahara');
$reason = '"' . urldecode($reason) . '"';
}
$contentrefused = count($whathasbeenrefused) > 1 ? 'privacyandtheterms' : $whathasbeenrefused[0];
// check if there are admins - otherwise there are no site admins?!?!?
if (count($admins) > 0) {
require_once('activity.php');
......@@ -499,9 +501,9 @@ class Institution {
$user->find_by_id($id);
$message = (object) array(
'users' => array($id),
'subject' => $studentname . ' ' . get_string('hasrefused', 'admin'),
'subject' => $studentname . ' ' . get_string('hasrefused', 'admin', get_string($contentrefused, 'admin')),
'message' => get_string_from_language($lang, 'institutionmemberrefusedprivacy', 'mahara',
$user->firstname, $studentname, $student->username,
$user->firstname, $studentname, $student->username, get_string($contentrefused, 'admin'),
$thereasonis, $reason, $student->email, get_config('sitename')),
);
activity_occurred('maharamessage', $message);
......
......@@ -1426,7 +1426,7 @@ function suspend_user($suspendeduserid, $reason, $suspendinguserid=null) {
$suspendrec = new StdClass;
$suspendrec->id = $suspendeduserid;
$suspendrec->suspendedcusr = $suspendinguserid;
$suspendrec->suspendedreason = $reason == 'privacyrefusal' ? get_string($reason, 'admin') : $reason;
$suspendrec->suspendedreason = is_array($reason) ? get_string('privacyrefusal', 'admin') : $reason;
$suspendrec->suspendedctime = db_format_timestamp(time());
update_record('usr', $suspendrec, 'id');
......@@ -1449,9 +1449,9 @@ function suspend_user($suspendeduserid, $reason, $suspendinguserid=null) {
get_config('sitename'), display_name($suspendinguserid, $suspendeduserid));
}
}
else if ($reason == 'privacyrefusal') {
$message->message = get_string_from_language($lang, 'youraccounthasbeensuspendedtext3', 'mahara',
get_config('sitename'));
else if (is_array($reason)) {
$message->message = get_string_from_language($lang, 'youraccounthasbeensuspendedtext3', 'mahara',
get_config('sitename'), get_string(count($reason) == 1 ? $reason[0] : 'privacyandtotheterms', 'admin'));
}
else {
if ($iscron) {
......
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