* contexturlname - the display text for contexturl
*
* @param object $eventdata information about the message (component, userfrom, userto, ...)
- * @return boolean success
+ * @return int|false the ID of the new message or false if there was a problem with a processor
*/
function message_send($eventdata) {
global $CFG, $DB;
+ //new message ID to return
+ $messageid = false;
+
//TODO: we need to solve problems with database transactions here somehow, for now we just prevent transactions - sorry
$DB->transactions_forbidden();
- //flag we'll return indicating that all processors ran successfully
- $success = true;
-
if (is_int($eventdata->userto)) {
mtrace('message_send() userto is a user ID when it should be a user object');
$eventdata->userto = $DB->get_record('user', array('id' => $eventdata->useridto));
if ($processor=='none' && $savemessage->notification) {
//if they have deselected all processors and its a notification mark it read. The user doesnt want to be bothered
$savemessage->timeread = time();
- $DB->insert_record('message_read', $savemessage);
+ $messageid = $DB->insert_record('message_read', $savemessage);
} else { // Process the message
// Store unread message just in case we can not send it
- $savemessage->id = $DB->insert_record('message', $savemessage);
+ $messageid = $savemessage->id = $DB->insert_record('message', $savemessage);
$eventdata->savedmessageid = $savemessage->id;
// Try to deliver the message to each processor
if (!$pclass->send_message($eventdata)) {
debugging('Error calling message processor '.$procname);
- $success = false;
+ $messageid = false;
}
}
} else {
debugging('Error finding message processor '.$procname);
- $success = false;
+ $messageid = false;
}
}
//unread. To prevent this mark the message read if messaging is disabled
if (empty($CFG->messaging)) {
require_once($CFG->dirroot.'/message/lib.php');
- message_mark_message_read($savemessage, time());
+ $messageid = message_mark_message_read($savemessage, time());
} else if ( $DB->count_records('message_working', array('unreadmessageid' => $savemessage->id)) == 0){
//if there is no more processors that want to process this we can move message to message_read
require_once($CFG->dirroot.'/message/lib.php');
- message_mark_message_read($savemessage, time(), true);
+ $messageid = message_mark_message_read($savemessage, time(), true);
}
}
}
- return $success;
+ return $messageid;
}
$history = optional_param('history', MESSAGE_HISTORY_SHORT, PARAM_INT);
$search = optional_param('search', '', PARAM_CLEAN); //TODO: use PARAM_RAW, but make sure we use s() and p() properly
-$user1id = optional_param('user', $USER->id, PARAM_INT);
-$user2id = optional_param('id', 0, PARAM_INT);
+//the same param as 1.9 and the param we have been logging. Use this parameter.
+$user1id = optional_param(MESSAGE_USER1_PARAM, $USER->id, PARAM_INT);
+//2.0 shipped using this param. Retaining it only for compatibility. It should be removed.
+$user1id = optional_param('user', $user1id, PARAM_INT);
+
+//the same param as 1.9 and the param we have been logging. Use this parameter.
+$user2id = optional_param(MESSAGE_USER2_PARAM, 0, PARAM_INT);
+//2.0 shipped using this param. Retaining it only for compatibility. It should be removed.
+$user2id = optional_param('id', $user2id, PARAM_INT);
$addcontact = optional_param('addcontact', 0, PARAM_INT); // adding a contact
$removecontact = optional_param('removecontact', 0, PARAM_INT); // removing a contact
$messageid = message_post_message($user1, $user2, $data->message, FORMAT_MOODLE, 'direct');
if (!empty($messageid)) {
+ //including the id of the user sending the message in the logged URL so the URL works for admins
+ //note message ID may be misleading as the message may potentially get a different ID when moved from message to message_read
+ add_to_log(SITEID, 'message', 'write', 'index.php?user='.$user1->id.'&id='.$user2->id.'&history=1#m'.$messageid, $user1->id);
redirect($CFG->wwwroot . '/message/index.php?usergroup='.$usergroup.'&id='.$user2->id);
}
}
define('VIEW_COURSE','course_');
define('VIEW_SEARCH','search');
+define('MESSAGE_USER1_PARAM','user1');
+define('MESSAGE_USER2_PARAM','user2');
+
define('SHOW_ACTION_LINKS_IN_CONTACT_LIST', true);
define('MESSAGE_SEARCH_MAX_RESULTS', 200);
/**
* Inserts a message into the database, but also forwards it
* via other means if appropriate.
+ * @return int|false the ID of the new message or false
*/
function message_post_message($userfrom, $userto, $message, $format, $messagetype) {
global $SITE, $CFG, $USER;
* @param message an object with an object property ie $message->id which is an id in the message table
* @param int $timeread the timestamp for when the message should be marked read. Usually time().
* @param bool $messageworkingempty Is the message_working table already confirmed empty for this message?
-* @return void
+* @return int the ID of the message in the message_read table
*/
function message_mark_message_read($message, $timeread, $messageworkingempty=false) {
global $DB;
if (!$messageworkingempty) {
$DB->delete_records('message_working', array('unreadmessageid' => $messageid));
}
- $DB->insert_record('message_read', $message);
+ $messagereadid = $DB->insert_record('message_read', $message);
$DB->delete_records('message', array('id' => $messageid));
+ return $messagereadid;
}
// send confirmation if required
if ($sendconfirm) {
// send the email and update stats
- switch (quiz_send_confirmation($a)) {
+ switch (!empty(quiz_send_confirmation($a))) {
case true:
$emailresult['good']++;
break;