<?php // $Id$
-
+
require('../config.php');
require('lib.php');
}
/// Script parameters
- $userid = required_param('id', PARAM_INT);
+ $userid = required_param('id', PARAM_INT);
+ $noframesjs = optional_param('noframesjs', 0, PARAM_BOOL);
/// Check the user we are talking to is valid
if (! $user = get_record('user', 'id', $userid)) {
error("User ID was incorrect");
}
-/// Print frameset to contain all the various panes
- @header('Content-Type: text/html; charset=utf-8');
+/// 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');
+
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html>
<title><?php echo get_string('discussion', 'message').': '.fullname($user) ?></title>
</head>
<frameset rows="110,*,0,200">
- <noframes><body>Sorry, but support for Frames is required to use Messaging</body></noframes>
+ <noframes><body><?php
+ echo '<a href="discussion.php?id='.$userid.'&noframesjs=1">'.get_string('noframesjs', 'message').'<a/>';
+ ?></body></noframes>
- <frame src="user.php?id=<?php p($user->id)?>&frame=user" name="user"
+ <frame src="user.php?id=<?php p($user->id)?>&frame=user" name="user"
scrolling="no" marginwidth="0" marginheight="0" frameborder="0" />
- <frame src="messages.php" name="messages"
+ <frame src="messages.php" name="messages"
scrolling="yes" marginwidth="10" marginheight="10" frameborder="0" />
- <frame src="refresh.php?id=<?php p($user->id)?>&name=<?php echo urlencode(fullname($user)) ?>" name="refresh"
+ <frame src="refresh.php?id=<?php p($user->id)?>&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"
+ <frame src="send.php?id=<?php p($user->id)?>" name="send"
scrolling="no" marginwidth="2" marginheight="2" frameborder="0" />
</frameset>
</html>
+
+<?php
+ die;
+ }
+
+/// user wants simple frame&js-less mode
+
+ $start = optional_param('start', time(), PARAM_INT);
+ $message = optional_param('message', '', PARAM_CLEAN);
+ $format = optional_param('format', FORMAT_MOODLE, PARAM_INT);
+ $refresh = optional_param('refresh', '', PARAM_RAW);
+
+ $addcontact = optional_param('addcontact', 0, PARAM_INT); // adding a contact
+ $removecontact = optional_param('removecontact', 0, PARAM_INT); // removing a contact
+ $blockcontact = optional_param('blockcontact', 0, PARAM_INT); // blocking a contact
+ $unblockcontact = optional_param('unblockcontact', 0, PARAM_INT); // unblocking a contact
+
+ if ($addcontact and confirm_sesskey()) {
+ add_to_log(SITEID, 'message', 'add contact',
+ 'discussion.php?user1='.$addcontact.'&user2='.$USER->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 = get_record('message_contacts', 'userid', $user->id, 'contactid', $USER->id)) {
+ if ($contact->blocked and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
+ print_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!
+ print_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);
+ }
+
+
+ $userfullname = fullname($user);
+ $mefullname = fullname($USER);
+
+ print_header(get_string('discussion', 'message').': '.fullname($user));
+ echo '<div class="message-discussion-noframes">';
+ echo '<div id="userinfo">';
+ echo print_user_picture($user->id, SITEID, $user->picture, 48, true, true, 'userwindow');
+ echo '<div class="name"><h1>'.get_string('discussion', 'message').': '.$userfullname.'</h1></div>';
+ echo '<div class="commands"><ul>';
+ if ($contact = get_record('message_contacts', 'userid', $USER->id, 'contactid', $user->id)) {
+ if ($contact->blocked) {
+ echo '<li>';
+ message_contact_link($user->id, 'add', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs, true);
+ echo '</li><li>';
+ message_contact_link($user->id, 'unblock', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs, true);
+ echo '</li>';
+ } else {
+ echo '<li>';
+ message_contact_link($user->id, 'remove', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs, true);
+ echo '</li><li>';
+ message_contact_link($user->id, 'block', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs, true);
+ echo '</li>';
+ }
+ } else {
+ echo '<li>';
+ message_contact_link($user->id, 'add', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs, true);
+ echo '</li><li>';
+ message_contact_link($user->id, 'block', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs, true);
+ echo '</li>';
+ }
+ echo '<li>';
+ message_history_link($user->id, 0, false, '', '', 'both');
+ echo '</li>';
+ echo '</ul>';
+ echo '</div>';
+ echo '</div>'; // class="userinfo"
+
+ echo '<div id="send">';
+ echo '<form name="editing" method="post" action="discussion.php">';
+ echo '<input type="hidden" name="id" value="'.$user->id.'" />';
+ echo '<input type="hidden" name="start" value="'.$start.'" />';
+ echo '<input type="hidden" name="noframesjs" value="'.$noframesjs.'" />';
+ echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
+
+ $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0));
+ echo '<h1><label for="edit-message">'.get_string('sendmessage', 'message').'</label></h1>';
+ if ($usehtmleditor) {
+ print_textarea(true, 8, 34, 100, 100, 'message', $refreshedmessage);
+ use_html_editor('message', 'formatblock subscript superscript copy cut paste clean undo redo justifyleft justifycenter justifyright justifyfull lefttoright righttoleft insertorderedlist insertunorderedlist outdent indent inserthorizontalrule createanchor nolink inserttable');
+ echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
+ } else {
+ print_textarea(false, 8, 60, 0, 0, 'message', $refreshedmessage);
+ echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE.'" />';
+ }
+ echo '<br /><input type="submit" value="'.get_string('sendmessage', 'message').'" /> ';
+ echo '<input type="submit" name="refresh" value="'.get_string('refresh', 'message').'" />';
+ echo '</form>';
+ echo '</div>';
+
+ echo '<div id="messages">';
+ echo '<h1>'.get_string('messages', 'message').'</h1>';
+
+ $allmessages = array();
+ $playbeep = false;
+ $options = new object();
+ $options->para = false;
+ $options->newlines = true;
+
+ if ($messages = get_records_select('message_read', "(useridto = '$USER->id' AND useridfrom = '$userid' AND timeread > '$start') OR (useridto = '$userid' AND useridfrom = '$USER->id' AND timeread > '$start')")) {
+ foreach ($messages as $message) {
+ $time = userdate($message->timecreated, get_string('strftimedaytime'));
+
+ if ($message->useridfrom == $USER->id) {
+ $fullname = $mefullname;
+ } else {
+ $fullname = $userfullname;
+ }
+
+ $printmessage = format_text($message->message, $message->format, $options, 0);
+ $printmessage = str_replace("\r", ' ', $printmessage);
+ $printmessage = str_replace("\n", ' ', $printmessage);
+ $printmessage = '<div class="message other"><span class="author">'.$fullname.'</span> '.
+ '<span class="time">['.$time.']</span>: '.
+ '<span class="content">'.$printmessage.'</span></div>';
+ $allmessages[$message->timecreated] = $printmessage;
+ }
+ }
+
+ if ($messages = get_records_select('message', "useridto = '$userid' AND useridfrom = '$USER->id'")) {
+ foreach ($messages as $message) {
+ $time = userdate($message->timecreated, get_string('strftimedaytime'));
+
+ $printmessage = format_text($message->message, $message->format, $options, 0);
+ $printmessage = str_replace("\r", ' ', $printmessage);
+ $printmessage = str_replace("\n", ' ', $printmessage);
+ $printmessage = '<div class="message other"><span class="author">'.$mefullname.'</span> '.
+ '<span class="time">['.$time.']</span>: '.
+ '<span class="content">'.$printmessage.'</span></div>';
+ $allmessages[$message->timecreated] = $printmessage; // hack alert - let's hope users will not post exactly at the same time
+ }
+ }
+
+ if ($messages = get_records_select('message', "useridto = '$USER->id' AND useridfrom = '$userid'")) {
+ foreach ($messages as $message) {
+ $time = userdate($message->timecreated, get_string('strftimedaytime'));
+
+ $printmessage = format_text($message->message, $message->format, $options, 0);
+ $printmessage = str_replace("\r", ' ', $printmessage);
+ $printmessage = str_replace("\n", ' ', $printmessage);
+ $printmessage = '<div class="message other"><span class="author">'.$userfullname.'</span> '.
+ '<span class="time">['.$time.']</span>: '.
+ '<span class="content">'.$printmessage.'</span></div>';
+ $allmessages[$message->timecreated] = $printmessage;
+
+ /// Move the entry to the other table
+
+ $messageid = $message->id;
+ unset($message->id);
+ $message->timeread = time();
+ $message = addslashes_object($message);
+ if (insert_record('message_read', $message)) {
+ delete_records('message', '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 {
+ foreach ($allmessages as $message) {
+ echo $message;
+ }
+ if ($playbeep and get_user_preferences('message_beepnewmessage', 0)) {
+ echo '<embed src="bell.wav" autostart="true" hidden="true" name="bell" />';
+ }
+ }
+
+ echo '</div></div>';
+
+ print_footer('none');
+?>
\ No newline at end of file
}
$timefrom = time()-$timetoshowusers;
-
+
/// get lists of contacts and unread messages
$onlinecontacts = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.picture, mc.blocked
FROM {$CFG->prefix}user u, {$CFG->prefix}message_contacts mc
- WHERE mc.userid='$USER->id' AND u.id=mc.contactid AND u.lastaccess>=$timefrom
- AND mc.blocked='0'
+ WHERE mc.userid='$USER->id' AND u.id=mc.contactid AND u.lastaccess>=$timefrom
+ AND mc.blocked='0'
ORDER BY u.firstname ASC");
$offlinecontacts = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.picture, mc.blocked
FROM {$CFG->prefix}user u, {$CFG->prefix}message_contacts mc
WHERE mc.userid='$USER->id' AND u.id=mc.contactid AND u.lastaccess<$timefrom
- AND mc.blocked='0'
+ AND mc.blocked='0'
ORDER BY u.firstname ASC");
- $unreadmessages = get_records_sql("SELECT m.id, m.useridfrom, u.firstname, u.lastname, u.picture
- FROM {$CFG->prefix}user u, {$CFG->prefix}message m
+ $unreadmessages = get_records_sql("SELECT m.id, m.useridfrom, u.firstname, u.lastname, u.picture
+ FROM {$CFG->prefix}user u, {$CFG->prefix}message m
WHERE m.useridto='$USER->id' AND u.id=m.useridfrom");
$blockedcontacts = get_records_select('message_contacts', "userid='$USER->id' AND blocked='1'", '', 'contactid, id');
if (empty($offlinecontacts)) $offlinecontacts = array();
if (empty($blockedcontacts)) $blockedcontacts = array();
foreach ($unreadmessages as $unreadmessage) {
- if (array_key_exists($unreadmessage->useridfrom, $onlinecontacts) or
+ if (array_key_exists($unreadmessage->useridfrom, $onlinecontacts) or
array_key_exists($unreadmessage->useridfrom, $offlinecontacts) or
array_key_exists($unreadmessage->useridfrom, $blockedcontacts) ) {
continue;
}
if(!empty($onlinecontacts) || !empty($offlinecontacts) || !empty($unknownmessages)) {
-
+
echo '<table id="message_contacts" align="center" cellspacing="2" cellpadding="0" border="0">';
-
+
if(!empty($onlinecontacts)) {
/// print out list of online contacts
-
+
echo '<tr><td colspan="3" class="heading">';
echo get_string('onlinecontacts', 'message', $countonlinecontacts);
echo '</td></tr>';
-
+
if (!empty($onlinecontacts)) {
foreach ($onlinecontacts as $contact) {
if ($contact->blocked == 1) continue;
/// link to remove from contact list
$strcontact = message_contact_link($contact->id, 'remove', true);
$strhistory = message_history_link($contact->id, 0, true, '', '', 'icon');
-
+
echo '<tr><td class="pix">';
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",
+ 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 '<tr><td colspan="3"> </td></tr>';
}
-
+
if (!empty($offlinecontacts)) {
/// print out list of offline 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",
+ 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 '<tr><td colspan="3"> </td></tr>';
}
-
+
/// print out list of incoming contacts
if (!empty($unknownmessages)) {
echo '<tr><td colspan="3" class="heading">';
$fullnamelink = '<strong>'.$fullnamelink.' ('.$messageuser->count.')</strong>';
}
/// link to add to contact list
-
+
$strcontact = message_contact_link($messageuser->useridfrom, 'add', true);
$strblock = message_contact_link($messageuser->useridfrom, 'block', true);
$strhistory = message_history_link($messageuser->useridfrom, 0, true, '', '', 'icon');
-
+
echo '<tr><td class="pix">';
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",
+ 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 '</table>';
-
+
if (!empty($unknownmessages) && ($countonlinecontacts + $countofflinecontacts == 0)) { // Extra help
echo '<div class="note">(';
print_string('addsomecontactsincoming', 'message');
echo ')</div>';
}
-
+
}
- echo '<br /><p align="center" class="note">'.get_string('pagerefreshes', 'message', $CFG->message_contacts_refresh).'</p>';
+ echo '<br />';
+ $autorefresh = '<p align="center" class="note">'.get_string('pagerefreshes', 'message', $CFG->message_contacts_refresh).'</p>';
+ $autorefresh = addslashes($autorefresh); // js escaping
+
+ // gracefully degrade JS autorefresh
+ echo '<script type="text/javascript">
+//<![CDATA[
+document.write("'.$autorefresh.'")
+//]]>
+</script>';
+ echo '<noscript><div align="center">';
+ echo print_single_button('index.php', false, get_string('refresh', 'message'));
+ echo '</div></noscript>';
}
function message_count_messages($messagearray, $field='', $value='') {
if (!is_array($messagearray)) return 0;
if ($field == '' or empty($messagearray)) return count($messagearray);
-
+
$count = 0;
foreach ($messagearray as $message) {
$count += ($message->$field == $value) ? 1 : 0;
function message_print_search() {
global $USER;
-
+
if ($frm = data_submitted()) {
-
+
message_print_search_results($frm);
-
+
} else {
/*
-/// unfinished buggy code disabled in search.html anyway
+/// unfinished buggy code disabled in search.html anyway
// find all courses this use has readallmessages capabilities in
if ($teachers = get_user_capability_course('moodle/site:readallmessages')) {
$courses = get_courses('all', 'c.sortorder ASC', 'c.id, c.shortname');
function message_print_settings() {
global $USER;
-
+
if ($frm = data_submitted()) {
$pref = array();
$pref['message_beepnewmessage'] = (isset($frm->beepnewmessage)) ? '1' : '0';
$pref['message_blocknoncontacts'] = (isset($frm->blocknoncontacts)) ? '1' : '0';
$pref['message_usehtmleditor'] = (isset($frm->usehtmleditor)) ? '1' : '0';
+ $pref['message_noframesjs'] = (isset($frm->noframesjs)) ? '1' : '0';
$pref['message_emailmessages'] = (isset($frm->emailmessages)) ? '1' : '0';
$pref['message_emailtimenosee'] = ((int)$frm->emailtimenosee > 0) ? (int)$frm->emailtimenosee : '10';
$pref['message_emailaddress'] = (!empty($frm->emailaddress)) ? $frm->emailaddress : $USER->email;
$pref['message_emailformat'] = (isset($frm->emailformat)) ? $frm->emailformat : FORMAT_PLAIN;
set_user_preferences($pref);
-
+
redirect('index.php', get_string('settingssaved', 'message'), 1);
}
$cbbeepnewmessage = (get_user_preferences('message_beepnewmessage', 0) == '1') ? 'checked="checked"' : '';
$cbblocknoncontacts = (get_user_preferences('message_blocknoncontacts', 0) == '1') ? 'checked="checked"' : '';
$cbusehtmleditor = (get_user_preferences('message_usehtmleditor', 0) == '1') ? 'checked="checked"' : '';
+ $cbnoframesjs = (get_user_preferences('message_noframesjs', 0) == '1') ? 'checked="checked"' : '';
$cbemailmessages = (get_user_preferences('message_emailmessages', 1) == '1') ? 'checked="checked"' : '';
$txemailaddress = get_user_preferences('message_emailaddress', $USER->email);
$txemailtimenosee = get_user_preferences('message_emailtimenosee', 10);
'emailformat',
get_user_preferences('message_emailformat', FORMAT_PLAIN),
false, '', '0', true );
-
+
include('settings.html');
}
function message_add_contact($contactid, $blocked=0) {
global $USER;
-
+
if (!record_exists('user', 'id', $contactid)) { // invalid userid
return false;
}
-
+
if (($contact = get_record('message_contacts', 'userid', $USER->id, 'contactid', $contactid)) !== false) {
/// record already exists - we may be changing blocking status
-
+
if ($contact->blocked !== $blocked) {
/// change to blocking status
$contact->blocked = $blocked;
/// no changes to blocking status
return true;
}
-
+
} else {
/// new contact record
unset($contact);
global $USER;
return get_record('message_contacts', 'userid', $USER->id, 'contactid', $contactid);
}
-
+
function message_print_search_results($frm) {
/// search for person
if (!empty($frm->personsubmit) and !empty($frm->name)) {
-
+
if (optional_param('mycourses', 0, PARAM_BOOL)) {
$users = array();
$mycourses = get_my_courses($USER->id);
echo '<strong>'.get_string('userssearchresults', 'message', count($users)).'</strong>';
echo '<table class="message_users">';
foreach ($users as $user) {
-
+
if (($contact = message_get_contact($user->id)) !== false) {
if ($contact->blocked == 0) { /// not blocked
$strcontact = message_contact_link($user->id, 'remove', true);
$strblock = message_contact_link($user->id, 'block', true);
}
$strhistory = message_history_link($user->id, 0, true, '', '', 'icon');
-
+
echo '<tr><td class="pix">';
print_user_picture($user->id, SITEID, $user->picture, 20, false, true, 'userwindow');
echo '</td>';
echo '<td class="contact">';
- link_to_popup_window("/message/discussion.php?id=$user->id", "message_$user->id", fullname($user),
+ 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>';
echo '<td class="link">'.$strblock.'</td>';
echo '<td class="link">'.$strhistory.'</td>';
echo '</tr>';
}
echo '</table>';
-
+
} else {
notify(get_string('nosearchresults', 'message'));
}
-
-
+
+
/// search messages for keywords
} else if (!empty($frm->keywordssubmit) and !empty($frm->keywords)) {
$keywordstring = clean_text(trim($frm->keywords));
}
if (($messages = message_search($keywords, $fromme, $tome, $courseid)) !== false) {
-
+
/// get a list of contacts
if (($contacts = get_records('message_contacts', 'userid', $USER->id, '', 'contactid, blocked') ) === false) {
$contacts = array();
$blockedcount ++;
continue;
}
-
+
/// load up user to record
if ($message->useridto !== $USER->id) {
$userto = get_record('user', 'id', $message->useridto);
- $tocontact = (array_key_exists($message->useridto, $contacts) and
+ $tocontact = (array_key_exists($message->useridto, $contacts) and
($contacts[$message->useridto]->blocked == 0) );
- $toblocked = (array_key_exists($message->useridto, $contacts) and
+ $toblocked = (array_key_exists($message->useridto, $contacts) and
($contacts[$message->useridto]->blocked == 1) );
} else {
$userto = false;
$tocontact = false;
$toblocked = false;
}
-
+
/// load up user from record
if ($message->useridfrom !== $USER->id) {
$userfrom = get_record('user', 'id', $message->useridfrom);
- $fromcontact = (array_key_exists($message->useridfrom, $contacts) and
+ $fromcontact = (array_key_exists($message->useridfrom, $contacts) and
($contacts[$message->useridfrom]->blocked == 0) );
- $fromblocked = (array_key_exists($message->useridfrom, $contacts) and
+ $fromblocked = (array_key_exists($message->useridfrom, $contacts) and
($contacts[$message->useridfrom]->blocked == 1) );
} else {
$userfrom = false;
echo '</td>';
echo '<td class="summary">'.message_get_fragment($message->message, $keywords);
echo '<br /><div class="link">';
- message_history_link($message->useridto, $message->useridfrom, false,
+ message_history_link($message->useridto, $message->useridfrom, false,
$keywordstring, 'm'.$message->id, $strcontext);
echo '</div>';
echo '</td>';
echo '<td class="date">'.userdate($message->timecreated, $dateformat).'</td>';
echo "</tr>\n";
}
-
+
if ($blockedcount > 0) {
echo '<tr><td colspan="4" align="center">'.get_string('blockedmessages', 'message', $blockedcount).'</td></tr>';
}
echo '</table>';
-
+
} else {
notify(get_string('nosearchresults', 'message'));
}
message_contact_link($user->id, 'block');
}
echo '<br />';
- link_to_popup_window("/message/discussion.php?id=$user->id", "message_$user->id",
+ 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');
}
$fulllink = $strmessagehistory;
}
- $str = link_to_popup_window("/message/history.php?user1=$userid1&user2=$userid2$keywords$position",
- "message_history_$userid1", $fulllink, 500, 500, $strmessagehistory,
+ $str = link_to_popup_window("/message/history.php?user1=$userid1&user2=$userid2$keywords$position",
+ "message_history_$userid1", $fulllink, 500, 500, $strmessagehistory,
'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500', true);
$str = '<span class="history">'.$str.'</span>';
/**
* Search through course users
*
- * If $coursid specifies the site course then this function searches
+ * If $coursid specifies the site course then this function searches
* through all undeleted and confirmed users
*
* @uses $CFG
* @param int $courseid The course in question.
* @param string $searchtext ?
* @param string $sort ?
- * @param string $exceptions ?
+ * @param string $exceptions ?
* @return array An array of {@link $USER} records.
* @todo Finish documenting this function
*/
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$contextlists = get_related_contexts_string($context);
-
+
// everyone who has a role assignement in this course or higher
$users = get_records_sql("SELECT $fields
FROM {$CFG->prefix}user u,
{$CFG->prefix}role_assignments ra
- WHERE $select
+ WHERE $select
AND ra.contextid $contextlists
AND u.id = ra.userid
AND ($fullname $LIKE '%$searchtext%')
global $CFG, $USER;
/// If no userid sent then assume current user
- if ($userid == 0) $userid = $USER->id;
+ if ($userid == 0) $userid = $USER->id;
/// Some differences in SQL syntax
$LIKE = sql_ilike();
if ($courseid == SITEID) { /// admin is searching all messages
$m_read = get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.message, m.timecreated
- FROM {$CFG->prefix}message_read m
+ FROM {$CFG->prefix}message_read m
WHERE $messagesearch");
$m_unread = get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.message, m.timecreated
- FROM {$CFG->prefix}message m
+ FROM {$CFG->prefix}message m
WHERE $messagesearch");
-
+
if ($m_read === false) $m_read = array();
if ($m_unread === false) $m_unread = array();
-
+
} elseif ($courseid !== 'none') {
/// This has not been implemented due to security concerns
} else {
-
+
if ($fromme and $tome) $messagesearch .= "AND (m.useridfrom='$userid' OR m.useridto='$userid') ";
elseif ($fromme) $messagesearch .= "AND m.useridfrom='$userid' ";
elseif ($tome) $messagesearch .= "AND m.useridto='$userid' ";
-
+
$m_read = get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.message, m.timecreated
- FROM {$CFG->prefix}message_read m
+ FROM {$CFG->prefix}message_read m
WHERE $messagesearch");
$m_unread = get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.message, m.timecreated
- FROM {$CFG->prefix}message m
+ FROM {$CFG->prefix}message m
WHERE $messagesearch");
-
+
if ($m_read === false) $m_read = array();
if ($m_unread === false) $m_unread = array();
-
+
}
/// The keys may be duplicated in $m_read and $m_unread so we can't
$stopzone = false;
$truncate = 0;
if ($minlength == 0) $minlength = MESSAGE_SHORTLENGTH;
-
+
for ($i=0; $i<$length; $i++) {
$char = $message[$i];
function message_get_history($user1, $user2) {
- $messages = get_records_select('message_read', "(useridto = '$user1->id' AND useridfrom = '$user2->id') OR
- (useridto = '$user2->id' AND useridfrom = '$user1->id')",
+ $messages = get_records_select('message_read', "(useridto = '$user1->id' AND useridfrom = '$user2->id') OR
+ (useridto = '$user2->id' AND useridfrom = '$user1->id')",
'timecreated');
- if ($messages_new = get_records_select('message', "(useridto = '$user1->id' AND useridfrom = '$user2->id') OR
- (useridto = '$user2->id' AND useridfrom = '$user1->id')",
+ if ($messages_new = get_records_select('message', "(useridto = '$user1->id' AND useridfrom = '$user2->id') OR
+ (useridto = '$user2->id' AND useridfrom = '$user1->id')",
'timecreated')) {
foreach ($messages_new as $message) {
$messages[] = $message;
$message = stripslashes_safe($message);
$tagline = get_string('emailtagline', 'message', $SITE->shortname);
-
+
$messagesubject = message_shorten_message(strip_tags($message), 30).'...';
$messagetext = format_text_email($message, $format).
}
-/*
+/*
* Returns a list of all user ids who have used messaging in the site
* This was the simple way to code the SQL ... is it going to blow up
* on large datasets?