MDL-10294, MDL-10028, changing messaging/bulk messaging system

This commit is contained in:
toyomoyo 2007-11-21 07:53:42 +00:00
parent 9fcea62308
commit 576ad29016
9 changed files with 62 additions and 29 deletions

View File

@ -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';

View File

@ -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(

View File

@ -46,6 +46,7 @@
scrolling="yes" marginwidth="10" marginheight="10" frameborder="0" />
<frame src="refresh.php?id=<?php p($user->id)?>&amp;name=<?php echo urlencode(fullname($user)) ?>" name="refresh"
scrolling="no" marginwidth="0" marginheight="0" frameborder="0" />
<frame src="send.php?id=<?php p($user->id)?>" name="send"
scrolling="no" marginwidth="2" marginheight="2" frameborder="0" />
</frameset>

View File

@ -113,9 +113,11 @@ function message_print_contacts() {
print_user_picture($contact->id, SITEID, $contact->picture, 20, false, true, 'userwindow');
echo '</td>';
echo '<td class="contact">';
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 '</td>';
echo '<td class="link">'.$strcontact.'&nbsp;'.$strhistory.'</td>';
echo '</tr>';
@ -148,8 +150,9 @@ function message_print_contacts() {
echo '</td>';
echo '<td class="contact">';
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 '</td>';
echo '<td class="link">'.$strcontact.'&nbsp;'.$strhistory.'</td>';
echo '</tr>';
@ -180,9 +183,11 @@ function message_print_contacts() {
print_user_picture($messageuser->useridfrom, SITEID, $messageuser->picture, 20, false, true, 'userwindow');
echo '</td>';
echo '<td class="contact">';
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 '</td>';
echo '<td class="link">&nbsp;'.$strcontact.'&nbsp;'.$strblock.'&nbsp;'.$strhistory.'</td>';
echo '</tr>';
@ -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 '</td>';
echo '<td class="link">'.$strcontact.'</td>';
@ -564,6 +570,7 @@ function message_print_user ($user=false, $iscontact=false, $isblocked=false) {
message_contact_link($user->id, 'block');
}
echo '<br />';
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 .= '<hr /><p><a href="'.$CFG->wwwroot.'/message/index.php?popup=1">'.$tagline.'</a></p>';
// MDL-10294, do not print link if messaging is disabled
if ($CFG->messaging) {
$messagehtml .= '<hr /><p><a href="'.$CFG->wwwroot.'/message/index.php?popup=1">'.$tagline.'</a></p>';
}
} 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);
}
}

View File

@ -1,17 +1,20 @@
<?php // $Id$
require('../config.php');
require('lib.php');
require('../config.php');
require('lib.php');
require_login();
require_login();
if (isguest()) {
redirect($CFG->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</script>\n\n";
echo '</body></html>';
}
?>

View File

@ -642,15 +642,12 @@
echo '<input type="button" onclick="checkall()" value="'.get_string('selectall').'" /> ';
echo '<input type="button" onclick="checknone()" value="'.get_string('deselectall').'" /> ';
$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');

View File

@ -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) {

View File

@ -470,7 +470,7 @@
echo '</form>';
}
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)";

View File

@ -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