';
echo '
'.get_string('messages', 'message').'
';
$allmessages = array();
$playbeep = false;
$options = new stdClass();
$options->para = false;
$options->newlines = true;
$params = array('uid1'=>$USER->id ,'userid1'=>$userid, 'start1'=>$start, 'uid2'=>$USER->id ,'userid2'=>$userid, 'start2'=>$start);
if ($newonly) {
$lastsql1 = " AND timecreated > :last1";
$lastsql2 = " AND timecreated > :last2";
$params['last1'] = $last;
$params['last2'] = $last;
} else {
$lastsql1 = "";
$lastsql2 = "";
}
//LR: change here the way to
if ($messages = $DB->get_records_select('message_read', "(useridto = :uid1 AND useridfrom = :userid1 AND timeread > :start1 $lastsql1) OR (useridto = :userid2 AND useridfrom = :uid2 AND timeread > :start2 $lastsql2)", $params)) {
foreach ($messages as $message) {
$time = userdate($message->timecreated, get_string('strftimedatetimeshort'));
if ($message->useridfrom == $USER->id) {
$fullname = $mefullname;
} else {
$fullname = $userfullname;
}
if ($message->fullmessageformat == FORMAT_HTML){
$printmessage = format_text($message->fullmessagehtml, $message->fullmessageformat, $options, 0);
} else{
$printmessage = format_text($message->fullmessage, $message->fullmessageformat, $options, 0);
}
$printmessage = '
'.$fullname.' '.
'['.$time.']: '.
''.$printmessage.'
';
$i=0;
$sortkey = $message->timecreated."$i"; // we need string because we would run out of int range
while (array_key_exists($sortkey, $allmessages)) {
$i++;
$sortkey = $message->timecreated."$i";
}
$allmessages[$sortkey] = $printmessage;
}
}
if ($messages = $DB->get_records_select('message', "useridto = :userid1 AND useridfrom = :uid1 $lastsql1", $params)) {
foreach ($messages as $message) {
$time = userdate($message->timecreated, get_string('strftimedatetimeshort'));
if ($message->fullmessageformat == FORMAT_HTML){
$printmessage = format_text($message->fullmessagehtml, $message->fullmessageformat, $options, 0);
} else{
$printmessage = format_text($message->fullmessage, $message->fullmessageformat, $options, 0);
}
$printmessage = '
'.$mefullname.' '.
'['.$time.']: '.
''.$printmessage.'
';
$i=0;
$sortkey = $message->timecreated."$i"; // we need string because we would run out of int range
while (array_key_exists($sortkey, $allmessages)) {
$i++;
$sortkey = $message->timecreated."$i";
}
$allmessages[$sortkey] = $printmessage;
}
}
/*Get still to be read message, use message/lib.php function*/
$messages = message_get_popup_messages($USER->id, $userid);
if ($messages) {
foreach ($messages as $message) {
$time = userdate($message->timecreated, get_string('strftimedatetimeshort'));
if ($message->fullmessageformat == FORMAT_HTML){
$printmessage = format_text($message->fullmessagehtml, $message->fullmessageformat, $options, 0);
} else{
$printmessage = format_text($message->fullmessage, $message->fullmessageformat, $options, 0);
}
$printmessage = '
'.$userfullname.' '.
'['.$time.']: '.
''.$printmessage.'
';
$i=0;
$sortkey = $message->timecreated."$i"; // we need string because we would run out of int range
while (array_key_exists($sortkey, $allmessages)) {
$i++;
$sortkey = $message->timecreated."$i";
}
$allmessages[$sortkey] = $printmessage;
if ($message->timecreated < $start) {
$start = $message->timecreated; // move start back so that we see all current history
}
}
$playbeep = true;
}
/* old code, to be deleted
if ($messages = $DB->get_records_select('message', "useridto = :uid2 AND useridfrom = userid2 $lastsql2", $params)) {
foreach ($messages as $message) {
$time = userdate($message->timecreated, get_string('strftimedatetimeshort'));
$printmessage = format_text($message->message, $message->format, $options, 0);
$printmessage = '
'.$userfullname.' '.
'['.$time.']: '.
''.$printmessage.'
';
$i=0;
$sortkey = $message->timecreated."$i"; // we need string because we would run out of int range
while (array_key_exists($sortkey, $allmessages)) {
$i++;
$sortkey = $message->timecreated."$i";
}
$allmessages[$sortkey] = $printmessage;
/// Move the entry to the other table
$messageid = $message->id;
unset($message->id);
$message->timeread = time();
$DB->insert_record('message_read', $message);
$DB->delete_records('message', array('id'=>$messageid));
if ($message->timecreated < $start) {
$start = $message->timecreated; // move start back so that we see all current history
}
}
$playbeep = true;
}*/
krsort($allmessages);
if (empty($allmessages)) {
echo get_string('nomessagesfound', 'message');
} else {
echo '
';
foreach ($allmessages as $message) {
echo '- ';
echo $message;
echo '
';
}
echo '
';
if ($playbeep and get_user_preferences('message_beepnewmessage', 0)) {
echo '
';
}
}
echo '