. /** * Part of the message section of Moodle * * @author Luis Rodrigues and Martin Dougiamas * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @package message */ require('../config.php'); require('lib.php'); require_login(); $PAGE->set_context(get_system_context()); if (isguestuser()) { redirect($CFG->wwwroot); } if (empty($CFG->messaging)) { print_error('disabled', 'message'); } /// Script parameters $userid = required_param('id', PARAM_INT); $noframesjs = optional_param('noframesjs', 0, PARAM_BOOL); $url = new moodle_url('/message/discussion.php', array('id'=>$userid)); if ($noframesjs !== 0) { $url->param('noframesjs', $noframesjs); } $PAGE->set_url($url); /// Check the user we are talking to is valid if (! $user = $DB->get_record('user', array('id'=>$userid))) { print_error('invaliduserid'); } if ($user->deleted) { $PAGE->set_pagelayout('popup'); $PAGE->set_title(get_string('discussion', 'message').': '.fullname($user)); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('userdeleted'), 1); echo $OUTPUT->footer(); die; } /// Check if frame&jsless mode selected if (!get_user_preferences('message_noframesjs', 0) and !$noframesjs) { /// Print frameset to contain all the various panes @header('Content-Type: text/html; charset=utf-8'); ?> <?php echo get_string('discussion', 'message').': '.fullname($user) ?> <body><?php echo '<a href="discussion.php?id='.$userid.'&amp;noframesjs=1">'.get_string('noframesjs', 'message').'</a>'; ?></body> id, $addcontact); message_add_contact($addcontact); } if ($removecontact and confirm_sesskey()) { add_to_log(SITEID, 'message', 'remove contact', 'discussion.php?user1='.$removecontact.'&user2='.$USER->id, $removecontact); message_remove_contact($removecontact); } if ($blockcontact and confirm_sesskey()) { add_to_log(SITEID, 'message', 'block contact', 'discussion.php?user1='.$blockcontact.'&user2='.$USER->id, $blockcontact); message_block_contact($blockcontact); } if ($unblockcontact and confirm_sesskey()) { add_to_log(SITEID, 'message', 'unblock contact', 'history.php?user1='.$unblockcontact.'&user2='.$USER->id, $unblockcontact); message_unblock_contact($unblockcontact); } /// Check that the user is not blocking us!! if ($contact = $DB->get_record('message_contacts', array('userid'=>$user->id, 'contactid'=>$USER->id))) { if ($contact->blocked and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM))) { echo $OUTPUT->heading(get_string('userisblockingyou', 'message')); exit; } } if (get_user_preferences('message_blocknoncontacts', 0, $user->id)) { // User is blocking non-contacts if (empty($contact)) { // We are not a contact! echo $OUTPUT->heading(get_string('userisblockingyounoncontact', 'message')); exit; } } $refreshedmessage = ''; if (!empty($refresh) and data_submitted()) { $refreshedmessage = $message; } else if (empty($refresh) and data_submitted() and confirm_sesskey()) { if ($message!='') { message_post_message($USER, $user, $message, $format, 'direct'); } redirect('discussion.php?id='.$userid.'&start='.$start.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last); } $userfullname = fullname($user); $mefullname = fullname($USER); $PAGE->set_pagelayout('popup'); $PAGE->set_title(get_string('discussion', 'message').': '.fullname($user)); echo $OUTPUT->header(); echo '
'; echo '
'; echo $OUTPUT->user_picture($user, array('size'=>48, 'courseid'=>SITEID)); echo '

'.$userfullname.'

'; echo '
    '; if ($contact = $DB->get_record('message_contacts', array('userid'=>$USER->id, 'contactid'=>$user->id))) { if ($contact->blocked) { echo '
  • '; message_contact_link($user->id, 'add', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true); echo '
  • '; message_contact_link($user->id, 'unblock', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true); echo '
  • '; } else { echo '
  • '; message_contact_link($user->id, 'remove', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true); echo '
  • '; message_contact_link($user->id, 'block', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true); echo '
  • '; } } else { echo '
  • '; message_contact_link($user->id, 'add', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true); echo '
  • '; message_contact_link($user->id, 'block', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true); echo '
  • '; } echo '
  • '; message_history_link($user->id, 0, false, '', '', 'both'); echo '
  • '; echo '
'; echo '
'; echo '
'; // class="userinfo" echo '
'; echo '
'; $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0)); echo '

'; echo '
'; if ($usehtmleditor) { print_textarea(true, 8, 34, 100, 100, 'message', $refreshedmessage); echo ''; } else { print_textarea(false, 8, 50, 0, 0, 'message', $refreshedmessage); echo ''; } echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ' '; echo ''; echo ''; echo '
'; echo '
'; echo '
'; echo '
'; 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 ''; if ($playbeep and get_user_preferences('message_beepnewmessage', 0)) { echo ''; } } echo '
'; echo $OUTPUT->footer(); ?>