diff --git a/lang/en_utf8/role.php b/lang/en_utf8/role.php
index 3141c4458f0..e90d35f041f 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 953d7627147..29fc73547a4 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 d1c61834d97..bfd4e20574f 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 e134fe03ef1..5c8c4452aeb 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 6edc15c8c8e..c8d085a5331 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 '