$message_users = null;
- $sql = "SELECT m.id, u.firstname, u.lastname FROM {message} m
+ $messagesql = "SELECT m.id, m.smallmessage, u.firstname, u.lastname FROM {message} m
JOIN {message_working} mw ON m.id=mw.unreadmessageid
JOIN {message_processors} p ON mw.processorid=p.id
JOIN {user} u ON m.useridfrom=u.id
-WHERE m.useridto = :userid AND m.timecreated > :ts AND p.name='popup'";
+WHERE m.useridto = :userid AND p.name='popup'";
+
+ $sql = $messagesql.' AND m.timecreated > :ts';
$message_users = $DB->get_records_sql($sql, array('userid'=>$USER->id, 'ts'=>$USER->message_lastpopup));
if (empty($message_users)) {
//if the user was last notified over an hour ago remind them of any new messages regardless of when they were sent
$canrenotify = (time() - $USER->message_lastpopup) > 3600;
if ($canrenotify) {
- $sql = "SELECT m.id, u.firstname, u.lastname FROM {message} m
-JOIN {message_working} mw ON m.id=mw.unreadmessageid
-JOIN {message_processors} p ON mw.processorid=p.id
-JOIN {user} u ON m.useridfrom=u.id
-WHERE m.useridto = :userid AND p.name='popup'";
- $message_users = $DB->get_records_sql($sql, array('userid'=>$USER->id));
+ $message_users = $DB->get_records_sql($messagesql, array('userid'=>$USER->id));
}
}
if (count($message_users)>1) {
$strmessages = get_string('unreadnewmessages', 'message', count($message_users));
} else {
- $strmessages = get_string('unreadnewmessage', 'message', fullname(reset($message_users)) );
+ $message_users = reset($message_users);
+ $strmessages = get_string('unreadnewmessage', 'message', fullname($message_users) );
+
+ if (!empty($message_users->smallmessage)) {
+ //display the first 200 chars of the message in the popup
+ $smallmessage = null;
+ if (strlen($message_users->smallmessage>200)) {
+ $smallmessage = substr($message_users->smallmessage,0,200).'...';
+ } else {
+ $smallmessage = $message_users->smallmessage;
+ }
+ $strmessages .= '<div id="usermessage">'.$smallmessage.'</div>';
+ }
}
$strgomessage = get_string('gotomessages', 'message');
$time = userdate($message->timecreated, $dateformat);
$options = new stdClass();
$options->para = false;
- $messagetext = format_text($message->fullmessage, $message->fullmessageformat, $options);
+
+ //if supplied display small messages as fullmessage may contain boilerplate text that shouldnt appear in the messaging UI
+ if (!empty($message->smallmessage)) {
+ $messagetext = format_text($message->smallmessage, null, $options);
+ } else {
+ $messagetext = format_text($message->fullmessage, $message->fullmessageformat, $options);
+ }
+
if ($keywords) {
$messagetext = highlight($keywords, $messagetext);
}
$eventdata->fullmessage = $message;
$eventdata->fullmessageformat = $format;
$eventdata->fullmessagehtml = '';
- $eventdata->smallmessage = '';
+ $eventdata->smallmessage = $message;
$s = new stdClass();
$s->sitename = $SITE->shortname;
$s->url = $CFG->wwwroot.'/message/index.php?id='.$userfrom->id;//.'&user='.$userto->id;
$emailtagline = get_string('emailtagline', 'message', $s);
- $eventdata->footer = "\n\n---------------------------------------------------------------------\n".$emailtagline;
- $eventdata->footerhtml = "<br /><br />---------------------------------------------------------------------<br />".$emailtagline;
+ //$eventdata->footer = "\n\n---------------------------------------------------------------------\n".$emailtagline;
+ if (!empty($eventdata->fullmessage)) {
+ $eventdata->fullmessage .= "\n\n---------------------------------------------------------------------\n".$emailtagline;
+ }
+ //$eventdata->footerhtml = "<br /><br />---------------------------------------------------------------------<br />".$emailtagline;
+ if (!empty($eventdata->fullmessagehtml)) {
+ $eventdata->fullmessagehtml .= "<br /><br />---------------------------------------------------------------------<br />".$emailtagline;
+ }
$eventdata->timecreated = time();
return message_send($eventdata);
$userto->email = $usertoemailaddress;
}
- //concatenating the footer on here so that it appears on emails but not within the saved message
- $messagetosend = null;
- if (!empty($message->fullmessage)) {
- $messagetosend = $message->fullmessage.$message->footer;
- }
-
- $messagetosendhtml = null;
- if (!empty($message->fullmessagehtml)) {
- $messagetosendhtml = $message->fullmessagehtml.$message->footerhtml;
- }
-
$result = email_to_user($userto, $userfrom,
- $message->subject, $messagetosend, $messagetosendhtml);
+ $message->subject, $message->fullmessage, $message->fullmessagehtml);
return $result===true; //email_to_user() can return true, false or "emailstop"
//return true;//do we want to report an error if email sending fails?
public function send_message($message) {
global $DB;
- //do we want to prevent users from messaging themselves?
- //if ($message->useridfrom==$message->useridto) {
+ //prevent users from getting popup notifications of messages to themselves (happens with forum notifications)
+ if ($message->useridfrom!=$message->useridto) {
+ $processor = $DB->get_record('message_processors', array('name'=>'popup'));
+ $procmessage = new stdClass();
+ $procmessage->unreadmessageid = $message->id;
+ $procmessage->processorid = $processor->id;
- $processor = $DB->get_record('message_processors', array('name'=>'popup'));
- $procmessage = new stdClass();
- $procmessage->unreadmessageid = $message->id;
- $procmessage->processorid = $processor->id;
-
- //save this message for later delivery
- $DB->insert_record('message_working', $procmessage);
+ //save this message for later delivery
+ $DB->insert_record('message_working', $procmessage);
+ }
return true;
}
$string['postincontext'] = 'See this post in context';
$string['postmailinfo'] = 'This is a copy of a message posted on the {$a} website.
-To add your reply via the website, click on this link:';
+To reply click on this link:';
$string['postmailnow'] = '<p>This post will be mailed out immediately to all forum subscribers.</p>';
$string['postrating1'] = 'Mostly Separate Knowing';
$string['postrating2'] = 'Separate and Connected';
$string['shortpost'] = 'Short post';
$string['showsubscribers'] = 'Show/edit current subscribers';
$string['singleforum'] = 'A single simple discussion';
+$string['smallmessage'] = '{$a->user} posted in {$a->forumname}<br />To view: {$a->replylink}';
$string['startedby'] = 'Started by';
$string['subject'] = 'Subject';
$string['subscribe'] = 'Subscribe to this forum';
$eventdata->fullmessage = $posttext;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = $posthtml;
- $eventdata->smallmessage = '';
+
+ $smallmessagestrings = new stdClass();
+ $smallmessagestrings->user = fullname($userfrom);
+ $smallmessagestrings->forumname = "{$course->shortname}->".format_string($forum->name,true);
+ $smallmessagestrings->replylink = "$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id#p$post->id";
+ $smallmessagestrings->message = $post->message;
+ $eventdata->smallmessage = get_string('smallmessage', 'forum', $smallmessagestrings);
$mailresult = message_send($eventdata);
if (!$mailresult){
.messagesearchresults td span {white-space:nowrap;}
#newmessageoverlay {background-color:LightGrey;padding:20px;position:fixed;bottom:0;right:0;}
+#newmessageoverlay #usermessage {padding:10px;font-weight:bold;}
.ie6 #newmessageoverlay {position:static;}