MDL-7956 Add frameless and JSless message composition option
This commit is contained in:
@@ -34,6 +34,7 @@ $string['messages'] = 'Messages';
|
||||
$string['messaging'] = 'Messaging';
|
||||
$string['mycontacts'] = 'My Contacts';
|
||||
$string['newsearch'] = 'New search';
|
||||
$string['noframesjs'] = 'Version without frames and JavaScript';
|
||||
$string['nomessages'] = 'No messages waiting';
|
||||
$string['nomessagesfound'] = 'No messages were found';
|
||||
$string['nosearchresults'] = 'There were no results from your search';
|
||||
@@ -46,6 +47,7 @@ $string['onlymycourses'] = 'Only in my courses';
|
||||
$string['onlytome'] = 'Only messages to me';
|
||||
$string['pagerefreshes'] = 'This page refreshes automatically every $a seconds';
|
||||
$string['readmessages'] = '$a read messages';
|
||||
$string['refresh'] = 'Refresh';
|
||||
$string['removecontact'] = 'Remove contact';
|
||||
$string['savemysettings'] = 'Save my settings';
|
||||
$string['search'] = 'Search';
|
||||
|
||||
+228
-9
@@ -1,5 +1,5 @@
|
||||
<?php // $Id$
|
||||
|
||||
|
||||
require('../config.php');
|
||||
require('lib.php');
|
||||
|
||||
@@ -14,15 +14,20 @@
|
||||
}
|
||||
|
||||
/// 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>
|
||||
@@ -31,15 +36,229 @@
|
||||
<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');
|
||||
?>
|
||||
+92
-78
@@ -25,22 +25,22 @@ function message_print_contacts() {
|
||||
}
|
||||
$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');
|
||||
@@ -61,7 +61,7 @@ function message_print_contacts() {
|
||||
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;
|
||||
@@ -86,16 +86,16 @@ function message_print_contacts() {
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -108,12 +108,12 @@ function message_print_contacts() {
|
||||
/// 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>';
|
||||
@@ -123,7 +123,7 @@ function message_print_contacts() {
|
||||
}
|
||||
echo '<tr><td colspan="3"> </td></tr>';
|
||||
}
|
||||
|
||||
|
||||
if (!empty($offlinecontacts)) {
|
||||
/// print out list of offline contacts
|
||||
|
||||
@@ -147,7 +147,7 @@ function message_print_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>';
|
||||
@@ -157,7 +157,7 @@ function message_print_contacts() {
|
||||
echo '<tr><td colspan="3"> </td></tr>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// print out list of incoming contacts
|
||||
if (!empty($unknownmessages)) {
|
||||
echo '<tr><td colspan="3" class="heading">';
|
||||
@@ -171,16 +171,16 @@ function message_print_contacts() {
|
||||
$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>';
|
||||
@@ -190,18 +190,30 @@ function message_print_contacts() {
|
||||
}
|
||||
|
||||
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>';
|
||||
}
|
||||
|
||||
|
||||
@@ -215,7 +227,7 @@ function message_print_contacts() {
|
||||
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;
|
||||
@@ -226,14 +238,14 @@ function message_count_messages($messagearray, $field='', $value='') {
|
||||
|
||||
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');
|
||||
@@ -250,7 +262,7 @@ function message_print_search() {
|
||||
|
||||
function message_print_settings() {
|
||||
global $USER;
|
||||
|
||||
|
||||
if ($frm = data_submitted()) {
|
||||
|
||||
$pref = array();
|
||||
@@ -258,13 +270,14 @@ function message_print_settings() {
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -272,6 +285,7 @@ function message_print_settings() {
|
||||
$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);
|
||||
@@ -280,7 +294,7 @@ function message_print_settings() {
|
||||
'emailformat',
|
||||
get_user_preferences('message_emailformat', FORMAT_PLAIN),
|
||||
false, '', '0', true );
|
||||
|
||||
|
||||
include('settings.html');
|
||||
}
|
||||
|
||||
@@ -288,14 +302,14 @@ function message_print_settings() {
|
||||
|
||||
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;
|
||||
@@ -304,7 +318,7 @@ function message_add_contact($contactid, $blocked=0) {
|
||||
/// no changes to blocking status
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
/// new contact record
|
||||
unset($contact);
|
||||
@@ -333,7 +347,7 @@ function message_get_contact($contactid) {
|
||||
global $USER;
|
||||
return get_record('message_contacts', 'userid', $USER->id, 'contactid', $contactid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function message_print_search_results($frm) {
|
||||
@@ -343,7 +357,7 @@ 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);
|
||||
@@ -360,7 +374,7 @@ function message_print_search_results($frm) {
|
||||
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);
|
||||
@@ -374,28 +388,28 @@ function message_print_search_results($frm) {
|
||||
$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));
|
||||
@@ -427,7 +441,7 @@ function message_print_search_results($frm) {
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -459,26 +473,26 @@ function message_print_search_results($frm) {
|
||||
$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;
|
||||
@@ -500,20 +514,20 @@ function message_print_search_results($frm) {
|
||||
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'));
|
||||
}
|
||||
@@ -550,7 +564,7 @@ function message_print_user ($user=false, $iscontact=false, $isblocked=false) {
|
||||
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');
|
||||
}
|
||||
@@ -633,8 +647,8 @@ function message_history_link($userid1, $userid2=0, $returnstr=false, $keywords=
|
||||
$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>';
|
||||
@@ -651,7 +665,7 @@ function message_history_link($userid1, $userid2=0, $returnstr=false, $keywords=
|
||||
/**
|
||||
* 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
|
||||
@@ -659,7 +673,7 @@ function message_history_link($userid1, $userid2=0, $returnstr=false, $keywords=
|
||||
* @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
|
||||
*/
|
||||
@@ -694,12 +708,12 @@ function message_search_users($courseid, $searchtext, $sort='', $exceptions='')
|
||||
|
||||
$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%')
|
||||
@@ -720,7 +734,7 @@ function message_search($searchterms, $fromme=true, $tome=true, $courseid='none'
|
||||
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();
|
||||
@@ -778,34 +792,34 @@ function message_search($searchterms, $fromme=true, $tome=true, $courseid='none'
|
||||
|
||||
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
|
||||
@@ -833,7 +847,7 @@ function message_shorten_message($message, $minlength=0) {
|
||||
$stopzone = false;
|
||||
$truncate = 0;
|
||||
if ($minlength == 0) $minlength = MESSAGE_SHORTLENGTH;
|
||||
|
||||
|
||||
|
||||
for ($i=0; $i<$length; $i++) {
|
||||
$char = $message[$i];
|
||||
@@ -921,11 +935,11 @@ function message_get_fragment($message, $keywords) {
|
||||
|
||||
|
||||
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;
|
||||
@@ -992,7 +1006,7 @@ function message_post_message($userfrom, $userto, $message, $format, $messagetyp
|
||||
|
||||
$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).
|
||||
@@ -1016,7 +1030,7 @@ function message_post_message($userfrom, $userto, $message, $format, $messagetyp
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* 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?
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
<?php // $Id$
|
||||
|
||||
|
||||
require('../config.php');
|
||||
|
||||
define('MESSAGE_DEFAULT_REFRESH', 5);
|
||||
@@ -47,12 +47,12 @@
|
||||
@ob_implicit_flush(true);
|
||||
@ob_end_flush();
|
||||
|
||||
if ($messages = get_records_select('message', "useridto = '$USER->id' AND useridfrom = '$userid'",
|
||||
if ($messages = get_records_select('message', "useridto = '$USER->id' AND useridfrom = '$userid'",
|
||||
'timecreated')) {
|
||||
foreach ($messages as $message) {
|
||||
$time = userdate($message->timecreated, get_string('strftimedaytime'));
|
||||
|
||||
$options = NULL;
|
||||
$options = new object();
|
||||
$options->para = false;
|
||||
$options->newlines = true;
|
||||
$printmessage = format_text($message->message, $message->format, $options, 0);
|
||||
@@ -67,7 +67,7 @@
|
||||
|
||||
/// Move the entry to the other table
|
||||
$message->timeread = time();
|
||||
$message->message = addslashes($message->message);
|
||||
$message = addslashes_object($message);
|
||||
$messageid = $message->id;
|
||||
unset($message->id);
|
||||
if (insert_record('message_read', $message)) {
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
<?php // $Id$
|
||||
|
||||
|
||||
require('../config.php');
|
||||
require('lib.php');
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
if ($message and confirm_sesskey()) { /// Current user has just sent a message
|
||||
if ($message!='' and confirm_sesskey()) { /// Current user has just sent a message
|
||||
|
||||
/// Save it to the database...
|
||||
$messageid = message_post_message($USER, $user, addslashes($message), $format, 'direct');
|
||||
@@ -107,8 +107,9 @@
|
||||
}
|
||||
echo '<br /><input type="submit" value="'.get_string('sendmessage', 'message').'" />';
|
||||
echo '</form>';
|
||||
echo '<div class="noframesjslink"><a target="_parent" href="discussion.php?id='.$userid.'&noframesjs=1">'.get_string('noframesjs', 'message').'</a></div>';
|
||||
echo '</center>';
|
||||
|
||||
|
||||
echo "\n<script type=\"text/javascript\">\n<!--\n"; /// Focus on the textarea
|
||||
echo 'document.getElementById("edit-message").focus();'."\n";
|
||||
echo "\n-->\n</script>\n\n";
|
||||
|
||||
@@ -20,8 +20,12 @@
|
||||
<td align="right"><input type="checkbox" name="usehtmleditor" id="usehtmleditor" <?php echo $cbusehtmleditor ?> /></td>
|
||||
<td colspan="2"><label for="usehtmleditor"><?php print_string('htmleditor') ?></label></td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right"><input type="checkbox" name="noframesjs" id="noframesjs" <?php echo $cbnoframesjs ?> /></td>
|
||||
<td colspan="2"><label for="noframesjs"><?php print_string('noframesjs', 'message') ?></label></td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
<tr valign="top">
|
||||
<td><input type="checkbox" name="emailmessages" id="emailmessages" <?php echo $cbemailmessages ?> /></td>
|
||||
<td colspan="2"><label for="emailmessages"><?php print_string('emailmessages', 'message') ?></label></td>
|
||||
|
||||
@@ -491,6 +491,27 @@ body#grade-index .grades .header {
|
||||
*** Message
|
||||
***/
|
||||
|
||||
.message-discussion-noframes #userinfo .name h1 {
|
||||
font-weight: bold;
|
||||
font-size:1em;
|
||||
}
|
||||
|
||||
.message-discussion-noframes #userinfo .commands {
|
||||
font-size:0.8em;
|
||||
}
|
||||
|
||||
.message-discussion-noframes #send h1 {
|
||||
font-size:1em;
|
||||
}
|
||||
|
||||
.message .noframesjslink {
|
||||
font-size:0.8em;
|
||||
}
|
||||
|
||||
.message-discussion-noframes #messages h1 {
|
||||
font-size:1em;
|
||||
}
|
||||
|
||||
.message .link {
|
||||
font-size:0.8em;
|
||||
}
|
||||
|
||||
@@ -1360,6 +1360,56 @@ body#grade-index .grades .weighted {
|
||||
*** Message
|
||||
***/
|
||||
|
||||
.message-discussion-noframes #userinfo .userpicture {
|
||||
float:left;
|
||||
}
|
||||
|
||||
.message-discussion-noframes #userinfo .name h1 {
|
||||
margin:0px;
|
||||
}
|
||||
|
||||
.message-discussion-noframes #userinfo .name {
|
||||
text-align:left;
|
||||
margin-left:60px;
|
||||
}
|
||||
|
||||
.message-discussion-noframes #userinfo .commands {
|
||||
text-align:left;
|
||||
margin-left:60px;
|
||||
}
|
||||
|
||||
.message-discussion-noframes #userinfo .commands ul {
|
||||
margin:0px;
|
||||
padding:0px;
|
||||
list-style-type:none;
|
||||
display:inline;
|
||||
}
|
||||
|
||||
.message-discussion-noframes #userinfo .commands ul li {
|
||||
display:inline;
|
||||
padding-right:16px;
|
||||
}
|
||||
|
||||
.message-discussion-noframes #send {
|
||||
padding-top:10px;
|
||||
clear:both;
|
||||
}
|
||||
|
||||
.message-discussion-noframes #send h1 {
|
||||
margin:0px;
|
||||
}
|
||||
.message-discussion-noframes #messages {
|
||||
padding-top:10px;
|
||||
}
|
||||
|
||||
.message-discussion-noframes #send h1 {
|
||||
margin:0px;
|
||||
}
|
||||
|
||||
.message .noframesjslink {
|
||||
margin-top:20px;
|
||||
}
|
||||
|
||||
.message .link {
|
||||
vertical-align:middle;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user