Skip to content

Commit

Permalink
Merge branch 'MDL-25616_recent_messages' of git://github.com/andyjdav…
Browse files Browse the repository at this point in the history
…is/moodle

Conflicts fixed:
	message/index.php
	message/lib.php
  • Loading branch information
stronk7 committed Feb 15, 2011
2 parents 07e21f6 + bcab42d commit c04c06d
Show file tree
Hide file tree
Showing 6 changed files with 782 additions and 316 deletions.
2 changes: 1 addition & 1 deletion admin/user/user_bulk_message.php
Expand Up @@ -30,7 +30,7 @@
//TODO we should probably support all text formats here or only FORMAT_MOODLE //TODO we should probably support all text formats here or only FORMAT_MOODLE
//For now bulk messaging is still using the html editor and its supplying html //For now bulk messaging is still using the html editor and its supplying html
//so we have to use html format for it to be displayed correctly //so we have to use html format for it to be displayed correctly
message_post_message($USER, $user, $msg, FORMAT_HTML, 'direct'); message_post_message($USER, $user, $msg, FORMAT_HTML);
} }
$rs->close(); $rs->close();
redirect($return); redirect($return);
Expand Down
3 changes: 3 additions & 0 deletions lang/en/message.php
Expand Up @@ -65,6 +65,8 @@
$string['loggedoffdescription'] = 'When I\'m offline'; $string['loggedoffdescription'] = 'When I\'m offline';
$string['managecontacts'] = 'Manage my contacts'; $string['managecontacts'] = 'Manage my contacts';
$string['mostrecent'] = 'Recent messages'; $string['mostrecent'] = 'Recent messages';
$string['mostrecentconversations'] = 'Recent conversations';
$string['mostrecentnotifications'] = 'Recent notifications';
$string['mailsent'] = 'Your message was sent via email.'; $string['mailsent'] = 'Your message was sent via email.';
$string['maxmessages'] = 'Maximum number of messages to show in the discussion history'; $string['maxmessages'] = 'Maximum number of messages to show in the discussion history';
$string['message'] = 'Message'; $string['message'] = 'Message';
Expand Down Expand Up @@ -93,6 +95,7 @@
$string['processortag'] = 'Destination'; $string['processortag'] = 'Destination';
$string['providers_config'] = 'Configure notification methods for incoming messages'; $string['providers_config'] = 'Configure notification methods for incoming messages';
$string['providerstag'] = 'Source'; $string['providerstag'] = 'Source';
$string['recent'] = 'Recent';
$string['readmessages'] = '{$a} read messages'; $string['readmessages'] = '{$a} read messages';
$string['removecontact'] = 'Remove contact'; $string['removecontact'] = 'Remove contact';
$string['savemysettings'] = 'Save my settings'; $string['savemysettings'] = 'Save my settings';
Expand Down
65 changes: 37 additions & 28 deletions message/index.php
Expand Up @@ -37,7 +37,10 @@
print_error('disabled', 'message'); print_error('disabled', 'message');
} }


//VIEW_PARAM is the preferred URL parameter but we'll still accept usergroup in case its referenced externally
$usergroup = optional_param('usergroup', VIEW_UNREAD_MESSAGES, PARAM_ALPHANUMEXT); $usergroup = optional_param('usergroup', VIEW_UNREAD_MESSAGES, PARAM_ALPHANUMEXT);
$viewing = optional_param(VIEW_PARAM, $usergroup, PARAM_ALPHANUMEXT);

$history = optional_param('history', MESSAGE_HISTORY_SHORT, PARAM_INT); $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 $search = optional_param('search', '', PARAM_CLEAN); //TODO: use PARAM_RAW, but make sure we use s() and p() properly


Expand Down Expand Up @@ -68,13 +71,15 @@
$url->param('id', $user2id); $url->param('id', $user2id);
} }


if ($usergroup !== 0) { if ($user2id !== 0) {
if ($user2id !== 0 && $usergroup==VIEW_SEARCH) { //Switch view back to contacts if:
//if theyve searched and selected a user change the view back to contacts so the search button is displayed //1) theyve searched and selected a user
$usergroup = VIEW_CONTACTS; //2) they've viewed recent messages or notifications and clicked through to a user
if ($viewing == VIEW_SEARCH || $viewing == VIEW_SEARCH || $viewing == VIEW_RECENT_NOTIFICATIONS) {
$viewing = VIEW_CONTACTS;
} }
$url->param('usergroup', $usergroup);
} }
$url->param('viewing', $viewing);


$PAGE->set_url($url); $PAGE->set_url($url);


Expand All @@ -87,8 +92,8 @@
$user1 = null; $user1 = null;
$currentuser = true; $currentuser = true;
$showcontactactionlinks = SHOW_ACTION_LINKS_IN_CONTACT_LIST; $showcontactactionlinks = SHOW_ACTION_LINKS_IN_CONTACT_LIST;
if ($user1id!=$USER->id) { if ($user1id != $USER->id) {
$user1 = $DB->get_record('user', array('id'=>$user1id)); $user1 = $DB->get_record('user', array('id' => $user1id));
if (!$user1) { if (!$user1) {
print_error('invaliduserid'); print_error('invaliduserid');
} }
Expand All @@ -101,23 +106,23 @@


$user2 = null; $user2 = null;
if (!empty($user2id)) { if (!empty($user2id)) {
$user2 = $DB->get_record("user", array("id"=>$user2id)); $user2 = $DB->get_record("user", array("id" => $user2id));
if (!$user2) { if (!$user2) {
print_error('invaliduserid'); print_error('invaliduserid');
} }
} }
unset($user2id); unset($user2id);


//the current user isnt involved in this discussion at all //the current user isnt involved in this discussion at all
if ($user1->id!=$USER->id && $user2->id!=$USER->id && !has_capability('moodle/site:readallmessages', $context)) { if ($user1->id != $USER->id && (!empty($user2) && $user2->id != $USER->id) && !has_capability('moodle/site:readallmessages', $context)) {
print_error('accessdenied','admin'); print_error('accessdenied','admin');
} }


/// Process any contact maintenance requests there may be /// Process any contact maintenance requests there may be
if ($addcontact and confirm_sesskey()) { if ($addcontact and confirm_sesskey()) {
add_to_log(SITEID, 'message', 'add contact', 'index.php?user1='.$addcontact.'&user2='.$USER->id, $addcontact); add_to_log(SITEID, 'message', 'add contact', 'index.php?user1='.$addcontact.'&user2='.$USER->id, $addcontact);
message_add_contact($addcontact); message_add_contact($addcontact);
redirect($CFG->wwwroot . '/message/index.php?usergroup=contacts&id='.$addcontact); redirect($CFG->wwwroot . '/message/index.php?'.VIEW_PARAM.'=contacts&id='.$addcontact);
} }
if ($removecontact and confirm_sesskey()) { if ($removecontact and confirm_sesskey()) {
add_to_log(SITEID, 'message', 'remove contact', 'index.php?user1='.$removecontact.'&user2='.$USER->id, $removecontact); add_to_log(SITEID, 'message', 'remove contact', 'index.php?user1='.$removecontact.'&user2='.$USER->id, $removecontact);
Expand All @@ -137,7 +142,7 @@
if ($currentuser && !empty($user2) && has_capability('moodle/site:sendmessage', $context)) { if ($currentuser && !empty($user2) && has_capability('moodle/site:sendmessage', $context)) {


// Check that the user is not blocking us!! // Check that the user is not blocking us!!
if ($contact = $DB->get_record('message_contacts', array('userid'=>$user2->id, 'contactid'=>$user1->id))) { if ($contact = $DB->get_record('message_contacts', array('userid' => $user2->id, 'contactid' => $user1->id))) {
if ($contact->blocked and !has_capability('moodle/site:readallmessages', $context)) { if ($contact->blocked and !has_capability('moodle/site:readallmessages', $context)) {
$messageerror = get_string('userisblockingyou', 'message'); $messageerror = get_string('userisblockingyou', 'message');
} }
Expand All @@ -163,12 +168,12 @@
print_error('invalidsesskey'); print_error('invalidsesskey');
} }


$messageid = message_post_message($user1, $user2, $data->message, FORMAT_MOODLE, 'direct'); $messageid = message_post_message($user1, $user2, $data->message, FORMAT_MOODLE);
if (!empty($messageid)) { if (!empty($messageid)) {
//including the id of the user sending the message in the logged URL so the URL works for admins //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 //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); 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); redirect($CFG->wwwroot . '/message/index.php?'.VIEW_PARAM.'='.$viewing.'&id='.$user2->id);
} }
} }
} }
Expand Down Expand Up @@ -201,35 +206,35 @@
if ($countunread>0) { if ($countunread>0) {
//mark the messages we're going to display as read //mark the messages we're going to display as read
message_mark_messages_read($user1->id, $user2->id); message_mark_messages_read($user1->id, $user2->id);
if($usergroup==VIEW_UNREAD_MESSAGES) { if($viewing == VIEW_UNREAD_MESSAGES) {
$viewingnewmessages = true; $viewingnewmessages = true;
} }
} }
} }
$countunreadtotal = message_count_unread_messages($user1); $countunreadtotal = message_count_unread_messages($user1);


if ($countunreadtotal==0 && $usergroup==VIEW_UNREAD_MESSAGES && empty($user2)) { if ($countunreadtotal == 0 && $viewing == VIEW_UNREAD_MESSAGES && empty($user2)) {
//default to showing the search //default to showing the search
$usergroup = VIEW_SEARCH; $viewing = VIEW_SEARCH;
} }


$blockedusers = message_get_blocked_users($user1, $user2); $blockedusers = message_get_blocked_users($user1, $user2);
$countblocked = count($blockedusers); $countblocked = count($blockedusers);


list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts($user1, $user2); list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts($user1, $user2);


message_print_contact_selector($countunreadtotal, $usergroup, $user1, $user2, $blockedusers, $onlinecontacts, $offlinecontacts, $strangers, $showcontactactionlinks, $page); message_print_contact_selector($countunreadtotal, $viewing, $user1, $user2, $blockedusers, $onlinecontacts, $offlinecontacts, $strangers, $showcontactactionlinks, $page);


echo html_writer::start_tag('div', array('class'=>'messagearea mdl-align')); echo html_writer::start_tag('div', array('class' => 'messagearea mdl-align'));
if (!empty($user2)) { if (!empty($user2)) {


echo html_writer::start_tag('div', array('class'=>'mdl-left messagehistory')); echo html_writer::start_tag('div', array('class' => 'mdl-left messagehistory'));


$visible = 'visible'; $visible = 'visible';
$hidden = 'hiddenelement'; //cant just use hidden as mform adds that class to its fieldset for something else $hidden = 'hiddenelement'; //cant just use hidden as mform adds that class to its fieldset for something else


$recentlinkclass = $recentlabelclass = $historylinkclass = $historylabelclass = $visible; $recentlinkclass = $recentlabelclass = $historylinkclass = $historylabelclass = $visible;
if ($history==MESSAGE_HISTORY_ALL) { if ($history == MESSAGE_HISTORY_ALL) {
$displaycount = 0; $displaycount = 0;


$recentlabelclass = $historylinkclass = $hidden; $recentlabelclass = $historylinkclass = $hidden;
Expand All @@ -249,25 +254,25 @@
$recentlinkclass = $historylabelclass = $hidden; $recentlinkclass = $historylabelclass = $hidden;
} }


$messagehistorylink = html_writer::start_tag('div', array('class'=>'mdl-align messagehistorytype')); $messagehistorylink = html_writer::start_tag('div', array('class' => 'mdl-align messagehistorytype'));
$messagehistorylink .= html_writer::link($PAGE->url->out(false).'&history='.MESSAGE_HISTORY_ALL, $messagehistorylink .= html_writer::link($PAGE->url->out(false).'&history='.MESSAGE_HISTORY_ALL,
get_string('messagehistoryfull','message'), get_string('messagehistoryfull','message'),
array('class'=>$historylinkclass)); array('class' => $historylinkclass));


$messagehistorylink .= html_writer::start_tag('span', array('class'=>$historylabelclass)); $messagehistorylink .= html_writer::start_tag('span', array('class' => $historylabelclass));
$messagehistorylink .= get_string('messagehistoryfull','message'); $messagehistorylink .= get_string('messagehistoryfull','message');
$messagehistorylink .= html_writer::end_tag('span'); $messagehistorylink .= html_writer::end_tag('span');


$messagehistorylink .= ' | '.html_writer::link($PAGE->url->out(false).'&history='.MESSAGE_HISTORY_SHORT, $messagehistorylink .= ' | '.html_writer::link($PAGE->url->out(false).'&history='.MESSAGE_HISTORY_SHORT,
get_string('mostrecent','message'), get_string('mostrecent','message'),
array('class'=>$recentlinkclass)); array('class' => $recentlinkclass));


$messagehistorylink .= html_writer::start_tag('span', array('class'=>$recentlabelclass)); $messagehistorylink .= html_writer::start_tag('span', array('class' => $recentlabelclass));
$messagehistorylink .= get_string('mostrecent','message'); $messagehistorylink .= get_string('mostrecent','message');
$messagehistorylink .= html_writer::end_tag('span'); $messagehistorylink .= html_writer::end_tag('span');


if ($viewingnewmessages) { if ($viewingnewmessages) {
$messagehistorylink .= ' | '.html_writer::start_tag('span');//, array('class'=>$historyclass) $messagehistorylink .= ' | '.html_writer::start_tag('span');//, array('class' => $historyclass)
$messagehistorylink .= get_string('unreadnewmessages','message',$displaycount); $messagehistorylink .= get_string('unreadnewmessages','message',$displaycount);
$messagehistorylink .= html_writer::end_tag('span'); $messagehistorylink .= html_writer::end_tag('span');
} }
Expand All @@ -279,7 +284,7 @@


//send message form //send message form
if ($currentuser && has_capability('moodle/site:sendmessage', $context)) { if ($currentuser && has_capability('moodle/site:sendmessage', $context)) {
echo html_writer::start_tag('div', array('class'=>'mdl-align messagesend')); echo html_writer::start_tag('div', array('class' => 'mdl-align messagesend'));
if (!empty($messageerror)) { if (!empty($messageerror)) {
echo $OUTPUT->heading($messageerror, 3); echo $OUTPUT->heading($messageerror, 3);
} else { } else {
Expand All @@ -293,8 +298,12 @@
} }
echo html_writer::end_tag('div'); echo html_writer::end_tag('div');
} }
} else if ($usergroup==VIEW_SEARCH) { } else if ($viewing == VIEW_SEARCH) {
message_print_search($advancedsearch, $user1); message_print_search($advancedsearch, $user1);
} else if ($viewing == VIEW_RECENT_CONVERSATIONS) {
message_print_recent_conversations($user1);
} else if ($viewing == VIEW_RECENT_NOTIFICATIONS) {
message_print_recent_notifications($user1);
} }
echo html_writer::end_tag('div'); echo html_writer::end_tag('div');


Expand Down

0 comments on commit c04c06d

Please sign in to comment.