From 576ad290165016e973a4b118f42a741ae41cd3ae Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Wed, 21 Nov 2007 07:53:42 +0000 Subject: [PATCH] MDL-10294, MDL-10028, changing messaging/bulk messaging system --- lang/en_utf8/role.php | 1 + lib/db/access.php | 12 ++++++++++++ message/discussion.php | 1 + message/lib.php | 32 +++++++++++++++++++++++++------- message/send.php | 23 +++++++++++++---------- user/index.php | 7 ++----- user/messageselect.php | 11 ++++++----- user/view.php | 2 +- version.php | 2 +- 9 files changed, 62 insertions(+), 29 deletions(-) diff --git a/lang/en_utf8/role.php b/lang/en_utf8/role.php index 3141c4458f..e90d35f041 100644 --- a/lang/en_utf8/role.php +++ b/lang/en_utf8/role.php @@ -141,6 +141,7 @@ $string['site:langeditmaster'] = 'Edit master language packages'; $string['site:manageblocks'] = 'Manage site-level blocks'; $string['site:readallmessages'] = 'Read all messages on site'; $string['site:restore'] = 'Restore courses'; +$string['site:sendmessage'] = 'Send messages to any user'; $string['site:trustcontent'] = 'Trust submitted content'; $string['site:uploadusers'] = 'Upload new users from file'; $string['site:viewfullnames'] = 'Always see full names of users'; diff --git a/lib/db/access.php b/lib/db/access.php index 953d762714..29fc73547a 100644 --- a/lib/db/access.php +++ b/lib/db/access.php @@ -120,6 +120,18 @@ $moodle_capabilities = array( 'editingteacher' => CAP_ALLOW ) ), + + 'moodle/site:sendmessage' => array( + + 'riskbitmask' => RISK_PERSONAL, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_SYSTEM, + 'legacy' => array( + 'admin' => CAP_ALLOW, + 'user' => CAP_ALLOW + ) + ), 'moodle/site:approvecourse' => array( diff --git a/message/discussion.php b/message/discussion.php index d1c61834d9..bfd4e20574 100644 --- a/message/discussion.php +++ b/message/discussion.php @@ -46,6 +46,7 @@ scrolling="yes" marginwidth="10" marginheight="10" frameborder="0" /> + diff --git a/message/lib.php b/message/lib.php index e134fe03ef..5c8c4452ae 100644 --- a/message/lib.php +++ b/message/lib.php @@ -113,9 +113,11 @@ function message_print_contacts() { print_user_picture($contact->id, SITEID, $contact->picture, 20, false, true, 'userwindow'); echo ''; echo ''; + link_to_popup_window("/message/discussion.php?id=$contact->id", "message_$contact->id", $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname), 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500'); + echo ''; echo ''.$strcontact.' '.$strhistory.''; echo ''; @@ -148,8 +150,9 @@ function message_print_contacts() { echo ''; echo ''; link_to_popup_window("/message/discussion.php?id=$contact->id", "message_$contact->id", - $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname), - 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500'); + $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname), + 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500'); + echo ''; echo ''.$strcontact.' '.$strhistory.''; echo ''; @@ -180,9 +183,11 @@ function message_print_contacts() { print_user_picture($messageuser->useridfrom, SITEID, $messageuser->picture, 20, false, true, 'userwindow'); echo ''; echo ''; + link_to_popup_window("/message/discussion.php?id=$messageuser->useridfrom", "message_$messageuser->useridfrom", $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname), 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500'); + echo ''; echo ' '.$strcontact.' '.$strblock.' '.$strhistory.''; echo ''; @@ -396,6 +401,7 @@ function message_print_search_results($frm) { link_to_popup_window("/message/discussion.php?id=$user->id", "message_$user->id", fullname($user), 500, 500, get_string('sendmessageto', 'message', fullname($user)), 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500'); + echo ''; echo ''.$strcontact.''; @@ -564,6 +570,7 @@ function message_print_user ($user=false, $iscontact=false, $isblocked=false) { message_contact_link($user->id, 'block'); } echo '
'; + link_to_popup_window("/message/discussion.php?id=$user->id", "message_$user->id", fullname($user), 400, 400, get_string('sendmessageto', 'message', fullname($user)), 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500'); @@ -987,22 +994,28 @@ function message_post_message($userfrom, $userto, $message, $format, $messagetyp $savemessage->timecreated = time(); $savemessage->messagetype = 'direct'; - if (!$savemessage->id = insert_record('message', $savemessage)) { - return false; + if ($CFG->messaging) { + if (!$savemessage->id = insert_record('message', $savemessage)) { + return false; + } + $emailforced = false; + } else { // $CFG->messaging is not on, we need to force sending of emails + $emailforced = true; + $savemessage->id = true; } /// Check to see if anything else needs to be done with it $preference = (object)get_user_preferences(NULL, NULL, $userto->id); - if (!isset($preference->message_emailmessages) || $preference->message_emailmessages) { // Receiver wants mail forwarding + if ($emailforced || (!isset($preference->message_emailmessages) || $preference->message_emailmessages)) { // Receiver wants mail forwarding if (!isset($preference->message_emailtimenosee)) { $preference->message_emailtimenosee = 10; } if (!isset($preference->message_emailformat)) { $preference->message_emailformat = FORMAT_HTML; } - if ((time() - $userto->lastaccess) > ((int)$preference->message_emailtimenosee * 60)) { // Long enough + if ($emailforced || (time() - $userto->lastaccess) > ((int)$preference->message_emailtimenosee * 60)) { // Long enough $message = stripslashes_safe($message); $tagline = get_string('emailtagline', 'message', $SITE->shortname); @@ -1014,7 +1027,10 @@ function message_post_message($userfrom, $userto, $message, $format, $messagetyp if (isset($preference->message_emailformat) and $preference->message_emailformat == FORMAT_HTML) { $messagehtml = format_text($message, $format); - $messagehtml .= '

'.$tagline.'

'; + // MDL-10294, do not print link if messaging is disabled + if ($CFG->messaging) { + $messagehtml .= '

'.$tagline.'

'; + } } else { $messagehtml = NULL; } @@ -1022,9 +1038,11 @@ function message_post_message($userfrom, $userto, $message, $format, $messagetyp if (!empty($preference->message_emailaddress)) { $userto->email = $preference->message_emailaddress; // Use custom messaging address } + if (email_to_user($userto, $userfrom, $messagesubject, $messagetext, $messagehtml)) { $CFG->messagewasjustemailed = true; } + sleep(3); } } diff --git a/message/send.php b/message/send.php index 6edc15c8c8..c8d085a533 100644 --- a/message/send.php +++ b/message/send.php @@ -1,17 +1,20 @@ wwwroot); - } +if (isguest()) { + redirect($CFG->wwwroot); +} + +if (empty($CFG->messaging)) { + error("Messaging is disabled on this site"); +} + +if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM))) { - if (empty($CFG->messaging)) { - error("Messaging is disabled on this site"); - } /// Don't use print_header, for more speed $stylesheetshtml = ''; @@ -121,5 +124,5 @@ echo "\n-->\n\n\n"; echo ''; - +} ?> diff --git a/user/index.php b/user/index.php index fcc43594b0..b8e250429d 100644 --- a/user/index.php +++ b/user/index.php @@ -642,15 +642,12 @@ echo ' '; echo ' '; $displaylist = array(); - // fix for MDL-8885, only show this if user has capability - if (has_capability('moodle/site:readallmessages', $context) && !empty($CFG->messaging)) { - $displaylist['messageselect.php'] = get_string('messageselectadd'); - } + $displaylist['messageselect.php'] = get_string('messageselectadd'); if (has_capability('moodle/notes:manage', $context) && $context->id != $frontpagectx->id) { $displaylist['addnote.php'] = get_string('addnewnote', 'notes'); $displaylist['groupaddnote.php'] = get_string('groupaddnewnote', 'notes'); } - + if ($context->id != $frontpagectx->id) { $displaylist['extendenrol.php'] = get_string('extendenrol'); $displaylist['groupextendenrol.php'] = get_string('groupextendenrol'); diff --git a/user/messageselect.php b/user/messageselect.php index 49ee850d73..28f1e89c6d 100644 --- a/user/messageselect.php +++ b/user/messageselect.php @@ -17,12 +17,9 @@ } require_login(); - require_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_COURSE, $id)); - // fix for MDL-10112 - if (empty($CFG->messaging)) { - error("Messaging is disabled on this site"); - } + require_capability('moodle/course:bulkmessaging', get_context_instance(CONTEXT_COURSE, $id)); + if (empty($SESSION->emailto)) { $SESSION->emailto = array(); @@ -72,6 +69,10 @@ print_header($strtitle,$strtitle,$navigation,$formstart); + // if messaging is disabled on site, we can still allow users with capabilities to send emails instead + if (empty($CFG->messaging)) { + notify("Messaging is disabled on this site, emails will be sent instead"); + } if ($count) { if ($count == 1) { diff --git a/user/view.php b/user/view.php index 0dc5e48529..f25006bd2f 100644 --- a/user/view.php +++ b/user/view.php @@ -470,7 +470,7 @@ echo ''; } - if (!empty($CFG->messaging) and !isguest()) { + if (!empty($CFG->messaging) and !isguest() and has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM))) { if (!empty($USER->id) and ($USER->id == $user->id)) { if ($countmessages = count_records('message', 'useridto', $user->id)) { $messagebuttonname = get_string("messages", "message")."($countmessages)"; diff --git a/version.php b/version.php index 9d234f5631..c7523a6c8b 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2007101503; // YYYYMMDD = date + $version = 2007101504; // YYYYMMDD = date // XY = increments within a single day $release = '2.0 dev'; // Human-friendly version name -- 2.39.5