From cadb96f29e0c9581ae0d2039a03cce6f4978cd0b Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 20 Feb 2004 10:27:24 +0000 Subject: [PATCH] GUI to allow disabling of user email addresses (from user profile) --- lib/moodlelib.php | 6 +++++- lib/weblib.php | 16 +++++++++++----- user/view.php | 30 +++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 82975cdea4..190d0653c2 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1239,7 +1239,11 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml="", $a include_once("$CFG->libdir/phpmailer/class.phpmailer.php"); - if (!$user) { + if (empty($user)) { + return false; + } + + if (!empty($user->emailstop)) { return false; } diff --git a/lib/weblib.php b/lib/weblib.php index f7dd9fe14f..f504b24a65 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -2059,17 +2059,23 @@ function obfuscate_text($plaintext) { return $obfuscated; } -function obfuscate_mailto($email, $label="") { +function obfuscate_mailto($email, $label="", $dimmed=false) { /// This function uses the above two functions to generate a fully /// obfuscated email link, ready to use. if (empty($label)) { $label = $email; } - return sprintf('%s', obfuscate_text('mailto'), - obfuscate_email($email), - obfuscate_text($email), - obfuscate_text($label)); + if ($dimmed) { + $title = get_string('emaildisable'); + $dimmed = ' class="dimmed"'; + } else { + $title = ''; + $dimmed = ''; + } + return sprintf("%s", + obfuscate_text('mailto'), obfuscate_email($email), + obfuscate_text($label)); } function print_paging_bar($totalcount, $page, $perpage, $baseurl) { diff --git a/user/view.php b/user/view.php index 6836f66e91..5f1aad0cc4 100644 --- a/user/view.php +++ b/user/view.php @@ -7,6 +7,8 @@ require_variable($id); require_variable($course); + optional_variable($enable, ""); + optional_variable($disable, ""); if (! $user = get_record("user", "id", $id) ) { @@ -110,7 +112,33 @@ } if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category) or isteacher($course->id)) { - print_row(get_string("email").":", obfuscate_mailto($user->email)); + + if (isteacheredit($course->id) or $currentuser) { /// Can use the enable/disable email stuff + if (!empty($_GET['enable'])) { /// Recieved a paramter to enable the email address + set_field('user', 'emailstop', 0, 'id', $user->id); + $user->emailstop = 0; + } + if (!empty($_GET['disable'])) { /// Recieved a paramter to disable the email address + set_field('user', 'emailstop', 1, 'id', $user->id); + $user->emailstop = 1; + } + if ($user->emailstop) { + $switchparam = 'enable'; + $switchtitle = get_string('emaildisable'); + $switchpix = 'show.gif'; + } else { + $switchparam = 'disable'; + $switchtitle = get_string('emailenable'); + $switchpix = 'hide.gif'; + } + $emailswitch = " id&course=$course->id&$switchparam=$user->id\">". + "pixpath/t/$switchpix\">"; + } else { + $emailswitch = ''; + } + + print_row(get_string("email").":", obfuscate_mailto($user->email, '', $user->emailstop)."$emailswitch"); } if ($user->url) { -- 2.39.5