2009-09-29 03:54:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Library functions for messaging
|
|
|
|
*
|
|
|
|
* @copyright Luis Rodrigues
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
* @package message
|
|
|
|
*/
|
2004-12-16 12:40:36 +00:00
|
|
|
|
2008-07-24 08:38:03 +00:00
|
|
|
require_once($CFG->libdir.'/eventslib.php');
|
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
|
|
|
|
define ('MESSAGE_SHORTLENGTH', 300);
|
2010-11-11 06:11:43 +00:00
|
|
|
|
2010-11-11 09:17:47 +00:00
|
|
|
//$PAGE isnt set if we're being loaded by cron which doesnt display popups anyway
|
|
|
|
if (isset($PAGE)) {
|
|
|
|
$PAGE->set_popup_notification_allowed(false); // We are in a message window (so don't pop up a new one)
|
|
|
|
}
|
2005-01-03 10:49:40 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
define ('MESSAGE_DISCUSSION_WIDTH',600);
|
|
|
|
define ('MESSAGE_DISCUSSION_HEIGHT',500);
|
|
|
|
|
|
|
|
define ('MESSAGE_SHORTVIEW_LIMIT', 8);//the maximum number of messages to show on the short message history
|
|
|
|
|
|
|
|
define ('CONTACT_ID','id');
|
|
|
|
|
|
|
|
define('MESSAGE_HISTORY_SHORT',0);
|
|
|
|
define('MESSAGE_HISTORY_ALL',1);
|
|
|
|
|
|
|
|
//some constants used as function arguments. Just to make function calls a bit more understandable
|
|
|
|
define('IS_CONTACT',true);
|
|
|
|
define('IS_NOT_CONTACT',false);
|
|
|
|
|
|
|
|
define('IS_BLOCKED',true);
|
|
|
|
define('IS_NOT_BLOCKED',false);
|
|
|
|
|
|
|
|
define('VIEW_UNREAD_MESSAGES','unread');
|
|
|
|
define('VIEW_CONTACTS','contacts');
|
|
|
|
define('VIEW_BLOCKED','blockedusers');
|
|
|
|
define('VIEW_COURSE','course_');
|
2010-11-02 06:09:10 +00:00
|
|
|
define('VIEW_SEARCH','search');
|
2010-06-25 08:16:10 +00:00
|
|
|
|
2010-10-06 07:39:49 +00:00
|
|
|
define('SHOW_ACTION_LINKS_IN_CONTACT_LIST', true);
|
2010-06-25 08:16:10 +00:00
|
|
|
|
2010-07-07 07:49:08 +00:00
|
|
|
define('MESSAGE_SEARCH_MAX_RESULTS', 200);
|
|
|
|
|
2010-10-21 06:40:15 +00:00
|
|
|
define('MESSAGE_CONTACTS_PER_PAGE',10);
|
|
|
|
|
2005-04-05 07:44:41 +00:00
|
|
|
if (!isset($CFG->message_contacts_refresh)) { // Refresh the contacts list every 60 seconds
|
2005-04-05 07:31:13 +00:00
|
|
|
$CFG->message_contacts_refresh = 60;
|
2005-01-03 10:49:40 +00:00
|
|
|
}
|
2005-04-14 09:28:07 +00:00
|
|
|
if (!isset($CFG->message_chat_refresh)) { // Look for new comments every 5 seconds
|
|
|
|
$CFG->message_chat_refresh = 5;
|
2005-01-03 10:49:40 +00:00
|
|
|
}
|
2005-01-03 15:20:56 +00:00
|
|
|
if (!isset($CFG->message_offline_time)) {
|
|
|
|
$CFG->message_offline_time = 300;
|
|
|
|
}
|
2004-12-16 12:40:36 +00:00
|
|
|
|
2010-10-21 06:40:15 +00:00
|
|
|
function message_print_contact_selector($countunreadtotal, $usergroup, $user1, $user2, $blockedusers, $onlinecontacts, $offlinecontacts, $strangers, $showcontactactionlinks, $page=0) {
|
2010-06-25 08:16:10 +00:00
|
|
|
global $PAGE;
|
2010-07-04 18:36:34 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
echo html_writer::start_tag('div', array('class'=>'contactselector mdl-align'));
|
|
|
|
|
|
|
|
//if 0 unread messages and they've requested unread messages then show contacts
|
|
|
|
if ($countunreadtotal==0 && $usergroup==VIEW_UNREAD_MESSAGES) {
|
|
|
|
$usergroup = VIEW_CONTACTS;
|
|
|
|
}
|
|
|
|
|
2010-06-29 03:01:14 +00:00
|
|
|
//if they have no blocked users and they've requested blocked users switch them over to contacts
|
|
|
|
if (count($blockedusers)==0 && $usergroup==VIEW_BLOCKED) {
|
|
|
|
$usergroup = VIEW_CONTACTS;
|
|
|
|
}
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
$onlyactivecourses = true;
|
|
|
|
$courses = enrol_get_users_courses($user1->id, $onlyactivecourses);
|
|
|
|
$coursecontexts = message_get_course_contexts($courses);//we need one of these again so holding on to them
|
|
|
|
|
2010-06-25 08:37:01 +00:00
|
|
|
$strunreadmessages = null;
|
|
|
|
if ($countunreadtotal>0) { //if there are unread messages
|
|
|
|
$strunreadmessages = get_string('unreadmessages','message', $countunreadtotal);
|
|
|
|
}
|
|
|
|
|
|
|
|
message_print_usergroup_selector($usergroup, $courses, $coursecontexts, $countunreadtotal, count($blockedusers), $strunreadmessages);
|
2010-06-25 08:16:10 +00:00
|
|
|
|
|
|
|
$refreshpage = false;
|
|
|
|
|
|
|
|
if ($usergroup==VIEW_UNREAD_MESSAGES) {
|
|
|
|
message_print_contacts($onlinecontacts, $offlinecontacts, $strangers, $refreshpage, $PAGE->url, 1, $showcontactactionlinks,$strunreadmessages, $user2);
|
2010-11-02 06:09:10 +00:00
|
|
|
} else if ($usergroup==VIEW_CONTACTS || $usergroup==VIEW_SEARCH) {
|
2010-06-29 06:57:21 +00:00
|
|
|
message_print_contacts($onlinecontacts, $offlinecontacts, $strangers, $refreshpage, $PAGE->url, 0, $showcontactactionlinks, $strunreadmessages, $user2);
|
2010-06-25 08:16:10 +00:00
|
|
|
} else if ($usergroup==VIEW_BLOCKED) {
|
|
|
|
message_print_blocked_users($blockedusers, $PAGE->url, $showcontactactionlinks, null, $user2);
|
|
|
|
} else if (substr($usergroup, 0, 7)==VIEW_COURSE) {
|
|
|
|
$courseidtoshow = intval(substr($usergroup, 7));
|
|
|
|
|
|
|
|
if (!empty($courseidtoshow)
|
|
|
|
&& array_key_exists($courseidtoshow, $coursecontexts)
|
|
|
|
&& has_capability('moodle/course:viewparticipants', $coursecontexts[$courseidtoshow])) {
|
|
|
|
|
2010-11-02 06:09:10 +00:00
|
|
|
message_print_participants($coursecontexts[$courseidtoshow], $courseidtoshow, $PAGE->url, $showcontactactionlinks, null, $page, $user2);
|
2010-06-25 08:16:10 +00:00
|
|
|
} else {
|
2010-09-17 19:41:02 +00:00
|
|
|
//shouldn't get here. User trying to access a course they're not in perhaps.
|
2010-06-29 07:27:24 +00:00
|
|
|
add_to_log(SITEID, 'message', 'view', 'index.php', $usergroup);
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-02 06:09:10 +00:00
|
|
|
echo html_writer::start_tag('form', array('action'=>'index.php','method'=>'GET'));
|
2010-06-25 08:16:10 +00:00
|
|
|
echo html_writer::start_tag('fieldset');
|
2010-11-02 06:09:10 +00:00
|
|
|
$managebuttonclass = 'visible';
|
|
|
|
if ($usergroup==VIEW_SEARCH) {
|
|
|
|
$managebuttonclass = 'hiddenelement';
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
2010-10-06 07:44:41 +00:00
|
|
|
$strmanagecontacts = get_string('search','message');
|
2010-11-02 06:09:10 +00:00
|
|
|
echo html_writer::empty_tag('input', array('type'=>'hidden','name'=>'usergroup','value'=>VIEW_SEARCH));
|
2010-06-25 08:16:10 +00:00
|
|
|
echo html_writer::empty_tag('input', array('type'=>'submit','value'=>$strmanagecontacts,'class'=>$managebuttonclass));
|
|
|
|
echo html_writer::end_tag('fieldset');
|
|
|
|
echo html_writer::end_tag('form');
|
2010-11-02 06:09:10 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
echo html_writer::end_tag('div');
|
|
|
|
}
|
|
|
|
|
2010-11-02 06:09:10 +00:00
|
|
|
function message_print_participants($context, $courseid, $contactselecturl=null, $showactionlinks=true, $titletodisplay=null, $page=0, $user2=null) {
|
2010-10-21 06:40:15 +00:00
|
|
|
global $DB, $USER, $PAGE, $OUTPUT;
|
2010-06-25 08:16:10 +00:00
|
|
|
|
2010-10-21 06:40:15 +00:00
|
|
|
$countparticipants = count_enrolled_users($context);
|
|
|
|
$participants = get_enrolled_users($context, '', 0, 'u.*', '', $page*MESSAGE_CONTACTS_PER_PAGE, MESSAGE_CONTACTS_PER_PAGE);
|
2011-01-27 11:46:37 +01:00
|
|
|
|
2010-10-21 06:40:15 +00:00
|
|
|
$pagingbar = new paging_bar($countparticipants, $page, MESSAGE_CONTACTS_PER_PAGE, $PAGE->url, 'page');
|
|
|
|
echo $OUTPUT->render($pagingbar);
|
2010-07-04 18:36:34 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
echo '<table id="message_participants" class="boxaligncenter" cellspacing="2" cellpadding="0" border="0">';
|
|
|
|
|
|
|
|
if (!empty($titletodisplay)) {
|
|
|
|
echo "<tr><td colspan='3' class='heading'>$titletodisplay</td></tr>";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($titletodisplay)) {
|
|
|
|
echo '<tr><td colspan="3" class="heading">';
|
|
|
|
echo get_string('participants');
|
|
|
|
echo '</td></tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
//todo these need to come from somewhere if the course participants list is to show users with unread messages
|
|
|
|
$iscontact = true;
|
|
|
|
$isblocked = false;
|
|
|
|
foreach ($participants as $participant) {
|
|
|
|
if ($participant->id != $USER->id) {
|
|
|
|
$participant->messagecount = 0;//todo it would be nice if the course participant could report new messages
|
2010-11-02 06:09:10 +00:00
|
|
|
message_print_contactlist_user($participant, $iscontact, $isblocked, $contactselecturl, $showactionlinks, $user2);
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//$participants->close();
|
|
|
|
|
|
|
|
echo '</table>';
|
|
|
|
}
|
|
|
|
|
|
|
|
function message_get_blocked_users($user1=null, &$user2=null) {
|
|
|
|
global $DB, $USER;
|
|
|
|
|
|
|
|
if (empty($user1)) {
|
|
|
|
$user1 = $USER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($user2)) {
|
|
|
|
$user2->isblocked = false;
|
|
|
|
}
|
|
|
|
|
2010-07-04 18:36:34 +00:00
|
|
|
$userfields = user_picture::fields('u', array('lastaccess'));
|
|
|
|
$blockeduserssql = "SELECT $userfields, COUNT(m.id) AS messagecount
|
|
|
|
FROM {message_contacts} mc
|
|
|
|
JOIN {user} u ON u.id = mc.contactid
|
|
|
|
LEFT OUTER JOIN {message} m ON m.useridfrom = mc.contactid AND m.useridto = :user1id1
|
|
|
|
WHERE mc.userid = :user1id2 AND mc.blocked = 1
|
|
|
|
GROUP BY $userfields
|
|
|
|
ORDER BY u.firstname ASC";
|
2010-06-25 08:16:10 +00:00
|
|
|
$rs = $DB->get_recordset_sql($blockeduserssql, array('user1id1'=>$user1->id, 'user1id2'=>$user1->id));
|
|
|
|
|
|
|
|
$blockedusers = array();
|
|
|
|
if (!empty($rs)) {
|
|
|
|
foreach($rs as $rd) {
|
|
|
|
$blockedusers[] = $rd;
|
|
|
|
|
|
|
|
if (!empty($user2) && $user2->id==$rd->id) {
|
|
|
|
$user2->isblocked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($rd);
|
|
|
|
$rs->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $blockedusers;
|
|
|
|
}
|
|
|
|
|
2010-11-02 06:09:10 +00:00
|
|
|
function message_print_blocked_users(&$blockedusers, $contactselecturl=null, $showactionlinks=true, $titletodisplay=null, $user2=null) {
|
2010-06-25 08:16:10 +00:00
|
|
|
global $DB, $USER;
|
|
|
|
|
|
|
|
$countblocked = count($blockedusers);
|
|
|
|
|
|
|
|
echo '<table id="message_contacts" class="boxaligncenter" cellspacing="2" cellpadding="0" border="0">';
|
|
|
|
|
|
|
|
if (!empty($titletodisplay)) {
|
|
|
|
echo "<tr><td colspan='3' class='heading'>$titletodisplay</td></tr>";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($countblocked) {
|
|
|
|
echo '<tr><td colspan="3" class="heading">';
|
|
|
|
echo get_string('blockedusers', 'message', $countblocked);
|
|
|
|
echo '</td></tr>';
|
|
|
|
|
|
|
|
foreach ($blockedusers as $blockeduser) {
|
2010-11-02 06:09:10 +00:00
|
|
|
message_print_contactlist_user($blockeduser, IS_NOT_CONTACT, IS_BLOCKED, $contactselecturl, $showactionlinks, $user2);
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '</table>';
|
|
|
|
}
|
|
|
|
|
|
|
|
function message_get_contacts($user1=null, &$user2=null) {
|
|
|
|
global $DB, $CFG, $USER;
|
2004-12-16 12:40:36 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
if (empty($user1)) {
|
|
|
|
$user1 = $USER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($user2)) {
|
|
|
|
$user2->iscontact = false;
|
|
|
|
}
|
2004-12-28 13:49:15 +00:00
|
|
|
|
|
|
|
$timetoshowusers = 300; //Seconds default
|
|
|
|
if (isset($CFG->block_online_users_timetosee)) {
|
|
|
|
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
|
|
|
|
}
|
|
|
|
|
2008-01-15 13:48:34 +00:00
|
|
|
// time which a user is counting as being active since
|
|
|
|
$timefrom = time()-$timetoshowusers;
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2008-01-15 13:48:34 +00:00
|
|
|
// people in our contactlist who are online
|
|
|
|
$onlinecontacts = array();
|
|
|
|
// people in our contactlist who are offline
|
|
|
|
$offlinecontacts = array();
|
|
|
|
// people who are not in our contactlist but have sent us a message
|
2010-07-01 02:12:46 +00:00
|
|
|
$strangers = array();
|
|
|
|
|
2010-07-04 18:36:34 +00:00
|
|
|
$userfields = user_picture::fields('u', array('lastaccess'));
|
2008-01-15 13:48:34 +00:00
|
|
|
|
2009-11-01 12:22:45 +00:00
|
|
|
// get all in our contactlist who are not blocked in our contact list
|
2008-01-15 13:48:34 +00:00
|
|
|
// and count messages we have waiting from each of them
|
2010-07-04 18:36:34 +00:00
|
|
|
$contactsql = "SELECT $userfields, COUNT(m.id) AS messagecount
|
2008-06-05 13:41:16 +00:00
|
|
|
FROM {message_contacts} mc
|
|
|
|
JOIN {user} u ON u.id = mc.contactid
|
|
|
|
LEFT OUTER JOIN {message} m ON m.useridfrom = mc.contactid AND m.useridto = ?
|
2009-11-01 12:22:45 +00:00
|
|
|
WHERE mc.userid = ? AND mc.blocked = 0
|
2010-07-04 18:36:34 +00:00
|
|
|
GROUP BY $userfields
|
2009-09-16 22:28:44 +00:00
|
|
|
ORDER BY u.firstname ASC";
|
2008-06-05 13:41:16 +00:00
|
|
|
|
2011-01-04 17:36:47 +01:00
|
|
|
$rs = $DB->get_recordset_sql($contactsql, array($user1->id, $user1->id));
|
|
|
|
foreach ($rs as $rd) {
|
|
|
|
if ($rd->lastaccess >= $timefrom) {
|
|
|
|
// they have been active recently, so are counted online
|
|
|
|
$onlinecontacts[] = $rd;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$offlinecontacts[] = $rd;
|
|
|
|
}
|
2010-06-25 08:16:10 +00:00
|
|
|
|
2011-01-04 17:36:47 +01:00
|
|
|
if (!empty($user2) && $user2->id==$rd->id) {
|
|
|
|
$user2->iscontact = true;
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
2008-01-15 13:48:34 +00:00
|
|
|
}
|
2011-01-04 17:36:47 +01:00
|
|
|
$rs->close();
|
2008-01-15 13:48:34 +00:00
|
|
|
|
|
|
|
// get messages from anyone who isn't in our contact list and count the number
|
|
|
|
// of messages we have from each of them
|
2010-07-04 18:36:34 +00:00
|
|
|
$strangersql = "SELECT $userfields, count(m.id) as messagecount
|
2008-06-05 13:41:16 +00:00
|
|
|
FROM {message} m
|
|
|
|
JOIN {user} u ON u.id = m.useridfrom
|
|
|
|
LEFT OUTER JOIN {message_contacts} mc ON mc.contactid = m.useridfrom AND mc.userid = m.useridto
|
2009-11-01 12:22:45 +00:00
|
|
|
WHERE mc.id IS NULL AND m.useridto = ?
|
2010-07-04 18:36:34 +00:00
|
|
|
GROUP BY $userfields
|
2009-09-16 22:28:44 +00:00
|
|
|
ORDER BY u.firstname ASC";
|
2008-06-05 13:41:16 +00:00
|
|
|
|
2011-01-04 17:36:47 +01:00
|
|
|
$rs = $DB->get_recordset_sql($strangersql, array($USER->id));
|
|
|
|
foreach ($rs as $rd) {
|
|
|
|
$strangers[] = $rd;
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
2011-01-04 17:36:47 +01:00
|
|
|
$rs->close();
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
return array($onlinecontacts, $offlinecontacts, $strangers);
|
|
|
|
}
|
|
|
|
|
2010-11-02 03:05:11 +00:00
|
|
|
function message_print_contacts($onlinecontacts, $offlinecontacts, $strangers, $refresh=true, $contactselecturl=null, $minmessages=0, $showactionlinks=true, $titletodisplay=null, $user2=null) {
|
2010-06-25 08:16:10 +00:00
|
|
|
global $CFG, $PAGE, $OUTPUT;
|
|
|
|
|
2008-01-15 13:48:34 +00:00
|
|
|
$countonlinecontacts = count($onlinecontacts);
|
|
|
|
$countofflinecontacts = count($offlinecontacts);
|
|
|
|
$countstrangers = count($strangers);
|
|
|
|
|
2005-04-21 04:57:54 +00:00
|
|
|
if ($countonlinecontacts + $countofflinecontacts == 0) {
|
2005-04-23 14:38:57 +00:00
|
|
|
echo '<div class="heading">';
|
2005-04-20 19:28:14 +00:00
|
|
|
print_string('contactlistempty', 'message');
|
2005-04-21 04:57:54 +00:00
|
|
|
echo '</div>';
|
2010-06-29 03:01:14 +00:00
|
|
|
//echo '<div class="note">';
|
|
|
|
//print_string('addsomecontacts', 'message', message_remove_url_params($PAGE->url).'?tab=search');
|
|
|
|
//echo '</div>';
|
2005-04-20 19:28:14 +00:00
|
|
|
}
|
|
|
|
|
2008-05-02 05:15:26 +00:00
|
|
|
echo '<table id="message_contacts" class="boxaligncenter" cellspacing="2" cellpadding="0" border="0">';
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
if (!empty($titletodisplay)) {
|
|
|
|
echo "<tr><td colspan='3' class='heading'>$titletodisplay</td></tr>";
|
|
|
|
}
|
|
|
|
|
2008-01-15 13:48:34 +00:00
|
|
|
if($countonlinecontacts) {
|
|
|
|
/// print out list of online contacts
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
if (empty($titletodisplay)) {
|
|
|
|
echo '<tr><td colspan="3" class="heading">';
|
|
|
|
echo get_string('onlinecontacts', 'message', $countonlinecontacts);
|
|
|
|
echo '</td></tr>';
|
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2008-01-15 13:48:34 +00:00
|
|
|
foreach ($onlinecontacts as $contact) {
|
2010-06-25 08:16:10 +00:00
|
|
|
if ($minmessages==0 || $contact->messagecount>=$minmessages) {
|
2010-11-02 03:05:11 +00:00
|
|
|
message_print_contactlist_user($contact, IS_CONTACT, IS_NOT_BLOCKED, $contactselecturl, $showactionlinks, $user2);
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
2005-04-20 19:28:14 +00:00
|
|
|
}
|
2008-01-15 13:48:34 +00:00
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2008-01-15 13:48:34 +00:00
|
|
|
if ($countofflinecontacts) {
|
|
|
|
/// print out list of offline contacts
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
if (empty($titletodisplay)) {
|
|
|
|
echo '<tr><td colspan="3" class="heading">';
|
|
|
|
echo get_string('offlinecontacts', 'message', $countofflinecontacts);
|
|
|
|
echo '</td></tr>';
|
|
|
|
}
|
2007-11-21 07:53:42 +00:00
|
|
|
|
2008-01-15 13:48:34 +00:00
|
|
|
foreach ($offlinecontacts as $contact) {
|
2010-06-25 08:16:10 +00:00
|
|
|
if ($minmessages==0 || $contact->messagecount>=$minmessages) {
|
2010-11-02 03:05:11 +00:00
|
|
|
message_print_contactlist_user($contact, IS_CONTACT, IS_NOT_BLOCKED, $contactselecturl, $showactionlinks, $user2);
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
2005-04-20 19:28:14 +00:00
|
|
|
}
|
2008-01-15 13:48:34 +00:00
|
|
|
echo '<tr><td colspan="3"> </td></tr>';
|
|
|
|
}
|
2005-04-20 19:28:14 +00:00
|
|
|
|
2008-01-15 13:48:34 +00:00
|
|
|
/// print out list of incoming contacts
|
|
|
|
if ($countstrangers) {
|
|
|
|
echo '<tr><td colspan="3" class="heading">';
|
|
|
|
echo get_string('incomingcontacts', 'message', $countstrangers);
|
|
|
|
echo '</td></tr>';
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2008-01-15 13:48:34 +00:00
|
|
|
foreach ($strangers as $stranger) {
|
2010-06-29 14:57:45 +00:00
|
|
|
if ($minmessages==0 || $stranger->messagecount>=$minmessages) {
|
2010-11-02 03:05:11 +00:00
|
|
|
message_print_contactlist_user($stranger, IS_NOT_CONTACT, IS_NOT_BLOCKED, $contactselecturl, $showactionlinks, $user2);
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
2005-04-23 14:38:57 +00:00
|
|
|
}
|
2008-01-15 13:48:34 +00:00
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2008-01-15 13:48:34 +00:00
|
|
|
echo '</table>';
|
2005-04-20 19:28:14 +00:00
|
|
|
|
2008-01-15 13:48:34 +00:00
|
|
|
if ($countstrangers && ($countonlinecontacts + $countofflinecontacts == 0)) { // Extra help
|
|
|
|
echo '<div class="note">(';
|
|
|
|
print_string('addsomecontactsincoming', 'message');
|
|
|
|
echo ')</div>';
|
2005-04-20 19:28:14 +00:00
|
|
|
}
|
2005-01-01 04:23:09 +00:00
|
|
|
|
2006-12-25 22:34:05 +00:00
|
|
|
echo '<br />';
|
2005-03-17 20:39:30 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
if ($refresh) {
|
|
|
|
$PAGE->requires->js_init_call('M.core_message.init_refresh_page', array(60*1000, $PAGE->url->out(false)));
|
2009-06-30 08:33:29 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
echo $OUTPUT->container_start('messagejsautorefresh note center');
|
|
|
|
echo get_string('pagerefreshes', 'message', $CFG->message_contacts_refresh);
|
|
|
|
echo $OUTPUT->container_end();
|
2009-06-30 08:33:29 +00:00
|
|
|
|
2010-07-13 00:41:38 +00:00
|
|
|
echo $OUTPUT->container_start('messagejsmanualrefresh aligncenter');
|
|
|
|
echo $OUTPUT->single_button(message_remove_url_params($PAGE->url), get_string('refresh'));
|
|
|
|
echo $OUTPUT->container_end();
|
|
|
|
}
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
|
|
|
|
2010-06-25 08:37:01 +00:00
|
|
|
function message_print_usergroup_selector($usergroup, &$courses, &$coursecontexts, $countunreadtotal, $countblocked, $strunreadmessages) {
|
|
|
|
$strblockedusers = null;
|
2010-06-29 03:01:14 +00:00
|
|
|
$options = array();
|
2010-06-25 08:16:10 +00:00
|
|
|
|
|
|
|
if ($countunreadtotal>0) { //if there are unread messages
|
2010-06-29 03:01:14 +00:00
|
|
|
$options[VIEW_UNREAD_MESSAGES] = $strunreadmessages;
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$strcontacts = get_string('mycontacts', 'message');
|
|
|
|
$options[VIEW_CONTACTS] = $strcontacts;
|
|
|
|
|
|
|
|
if (!empty($courses)) {
|
|
|
|
$courses_options = array();
|
|
|
|
|
|
|
|
foreach($courses as $course) {
|
|
|
|
if (has_capability('moodle/course:viewparticipants', $coursecontexts[$course->id])) {
|
2010-07-12 13:51:10 +00:00
|
|
|
$courses_options[VIEW_COURSE.$course->id] = $course->shortname;
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($courses_options)) {
|
|
|
|
$options[] = array(get_string('courses')=>$courses_options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-01 09:01:45 +00:00
|
|
|
if ($countblocked>0) {
|
|
|
|
$strblockedusers = get_string('blockedusers','message', $countblocked);
|
|
|
|
$options[VIEW_BLOCKED] = $strblockedusers;
|
|
|
|
}
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
echo html_writer::start_tag('form', array('id'=>'usergroupform','method'=>'get','action'=>''));
|
2010-06-28 03:07:02 +00:00
|
|
|
echo html_writer::start_tag('fieldset');
|
|
|
|
echo html_writer::select($options, 'usergroup', $usergroup, false, array('id'=>'usergroup','onchange'=>'this.form.submit()'));
|
|
|
|
echo html_writer::end_tag('fieldset');
|
2010-06-25 08:16:10 +00:00
|
|
|
echo html_writer::end_tag('form');
|
|
|
|
}
|
|
|
|
|
|
|
|
function message_get_course_contexts(&$courses) {
|
|
|
|
$coursecontexts = array();
|
|
|
|
|
|
|
|
foreach($courses as $course) {
|
|
|
|
$coursecontexts[$course->id] = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $coursecontexts;
|
|
|
|
}
|
|
|
|
|
2010-07-02 08:08:11 +00:00
|
|
|
/**
|
|
|
|
* strip off action parameters like 'removecontact'
|
|
|
|
*/
|
2010-06-25 08:16:10 +00:00
|
|
|
function message_remove_url_params($moodleurl) {
|
|
|
|
$newurl = new moodle_url($moodleurl);
|
|
|
|
$newurl->remove_params('addcontact','removecontact','blockcontact','unblockcontact');
|
|
|
|
return $newurl->out();
|
|
|
|
}
|
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
|
|
|
|
/// $messagearray is an array of objects
|
|
|
|
/// $field is a valid property of object
|
|
|
|
/// $value is the value $field should equal to be counted
|
|
|
|
/// if $field is empty then return count of the whole array
|
|
|
|
/// if $field is non-existent then return 0;
|
|
|
|
function message_count_messages($messagearray, $field='', $value='') {
|
|
|
|
if (!is_array($messagearray)) return 0;
|
|
|
|
if ($field == '' or empty($messagearray)) return count($messagearray);
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
$count = 0;
|
|
|
|
foreach ($messagearray as $message) {
|
|
|
|
$count += ($message->$field == $value) ? 1 : 0;
|
|
|
|
}
|
|
|
|
return $count;
|
2004-12-16 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
/**
|
|
|
|
* Returns the count of unread messages for user. Either from a specific user or from all users.
|
|
|
|
* @global <type> $USER
|
|
|
|
* @global <type> $DB
|
|
|
|
* @param object $user1 the first user. Defaults to $USER
|
|
|
|
* @param object $user2 the second user. If null this function will count all of user 1's unread messages.
|
|
|
|
* @return int the count of $user1's unread messages
|
|
|
|
*/
|
|
|
|
function message_count_unread_messages($user1=null, $user2=null) {
|
|
|
|
global $USER, $DB;
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
if (empty($user1)) {
|
|
|
|
$user1 = $USER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($user2)) {
|
|
|
|
return $DB->count_records_select('message', "useridto = ? AND useridfrom = ?",
|
|
|
|
array($user1->id, $user2->id), "COUNT('id')");
|
|
|
|
} else {
|
|
|
|
return $DB->count_records_select('message', "useridto = ?",
|
|
|
|
array($user1->id), "COUNT('id')");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function message_count_blocked_users($user1=null) {
|
|
|
|
global $USER, $DB;
|
|
|
|
|
|
|
|
if (empty($user1)) {
|
|
|
|
$user1 = $USER;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT count(mc.id)
|
|
|
|
FROM {message_contacts} mc
|
|
|
|
WHERE mc.userid = :userid AND mc.blocked = 1";
|
|
|
|
$params = array('userid'=>$user1->id);
|
|
|
|
|
|
|
|
return $DB->count_records_sql($sql, $params);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @global <type> $USER
|
|
|
|
* @global <type> $PAGE
|
|
|
|
* @global <type> $OUTPUT
|
|
|
|
* @param boolean advancedsearch show basic or advanced search form
|
|
|
|
* @return boolean was a search performed?
|
|
|
|
*/
|
|
|
|
function message_print_search($advancedsearch = false, $user1=null) {
|
|
|
|
global $USER, $PAGE, $OUTPUT;
|
|
|
|
|
|
|
|
$frm = data_submitted();
|
2010-07-04 18:36:34 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
$doingsearch = false;
|
|
|
|
if ($frm) {
|
2011-01-27 11:46:37 +01:00
|
|
|
if (confirm_sesskey()) {
|
|
|
|
$doingsearch = !empty($frm->combinedsubmit) || !empty($frm->keywords) || (!empty($frm->personsubmit) and !empty($frm->name));
|
|
|
|
} else {
|
|
|
|
$frm = false;
|
|
|
|
}
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
if (!empty($frm->combinedsearch)) {
|
|
|
|
$combinedsearchstring = $frm->combinedsearch;
|
|
|
|
} else {
|
2010-10-25 09:29:34 +00:00
|
|
|
//$combinedsearchstring = get_string('searchcombined','message').'...';
|
|
|
|
$combinedsearchstring = '';
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2010-10-25 09:29:34 +00:00
|
|
|
//$PAGE->requires->js_init_call('M.core_message.init_search_page', array($combinedsearchstring));
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
if ($doingsearch) {
|
|
|
|
if ($advancedsearch) {
|
2010-07-04 18:36:34 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
$messagesearch = '';
|
|
|
|
if (!empty($frm->keywords)) {
|
|
|
|
$messagesearch = $frm->keywords;
|
|
|
|
}
|
|
|
|
$personsearch = '';
|
|
|
|
if (!empty($frm->name)) {
|
|
|
|
$personsearch = $frm->name;
|
|
|
|
}
|
|
|
|
include('search_advanced.html');
|
|
|
|
} else {
|
|
|
|
include('search.html');
|
|
|
|
}
|
|
|
|
|
|
|
|
$showicontext = false;
|
|
|
|
message_print_search_results($frm, $showicontext, $user1);
|
|
|
|
|
|
|
|
return true;
|
2004-12-16 12:40:36 +00:00
|
|
|
} else {
|
2006-10-22 19:20:02 +00:00
|
|
|
/*
|
2006-12-25 22:34:05 +00:00
|
|
|
/// unfinished buggy code disabled in search.html anyway
|
2006-09-19 01:44:33 +00:00
|
|
|
// find all courses this use has readallmessages capabilities in
|
|
|
|
if ($teachers = get_user_capability_course('moodle/site:readallmessages')) {
|
2004-12-16 12:40:36 +00:00
|
|
|
$courses = get_courses('all', 'c.sortorder ASC', 'c.id, c.shortname');
|
|
|
|
$cs = '<select name="courseselect">';
|
|
|
|
foreach ($teachers as $tcourse) {
|
2006-09-19 01:44:33 +00:00
|
|
|
$cs .= "<option value=\"$tcourse->course\">".$courses[$tcourse->id]->shortname."</option>\n";
|
2004-12-16 12:40:36 +00:00
|
|
|
}
|
|
|
|
$cs .= '</select>';
|
|
|
|
}
|
2006-10-22 19:20:02 +00:00
|
|
|
*/
|
2010-06-25 08:16:10 +00:00
|
|
|
|
|
|
|
if ($advancedsearch) {
|
|
|
|
$personsearch = $messagesearch = '';
|
|
|
|
include('search_advanced.html');
|
|
|
|
} else {
|
|
|
|
include('search.html');
|
|
|
|
}
|
|
|
|
return false;
|
2004-12-16 12:40:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function message_print_settings() {
|
2010-09-17 19:35:43 +00:00
|
|
|
global $USER, $OUTPUT, $PAGE;
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2008-09-25 22:42:58 +00:00
|
|
|
if ($frm = data_submitted() and confirm_sesskey()) {
|
2005-01-23 05:49:39 +00:00
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
$pref = array();
|
|
|
|
$pref['message_beepnewmessage'] = (isset($frm->beepnewmessage)) ? '1' : '0';
|
2005-04-23 06:26:10 +00:00
|
|
|
$pref['message_blocknoncontacts'] = (isset($frm->blocknoncontacts)) ? '1' : '0';
|
2004-12-28 13:49:15 +00:00
|
|
|
|
|
|
|
set_user_preferences($pref);
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
redirect(message_remove_url_params($PAGE->url), get_string('settingssaved', 'message'), 1);
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
|
|
|
|
2005-01-03 10:49:40 +00:00
|
|
|
$cbbeepnewmessage = (get_user_preferences('message_beepnewmessage', 0) == '1') ? 'checked="checked"' : '';
|
2005-04-23 06:26:10 +00:00
|
|
|
$cbblocknoncontacts = (get_user_preferences('message_blocknoncontacts', 0) == '1') ? 'checked="checked"' : '';
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
include('settings.html');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function message_add_contact($contactid, $blocked=0) {
|
2008-06-05 13:41:16 +00:00
|
|
|
global $USER, $DB;
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2008-06-05 13:41:16 +00:00
|
|
|
if (!$DB->record_exists('user', array('id'=>$contactid))) { // invalid userid
|
2004-12-28 13:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2008-06-05 13:41:16 +00:00
|
|
|
if (($contact = $DB->get_record('message_contacts', array('userid'=>$USER->id, 'contactid'=>$contactid))) !== false) {
|
2004-12-28 13:49:15 +00:00
|
|
|
/// record already exists - we may be changing blocking status
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
if ($contact->blocked !== $blocked) {
|
|
|
|
/// change to blocking status
|
|
|
|
$contact->blocked = $blocked;
|
2008-06-05 13:41:16 +00:00
|
|
|
return $DB->update_record('message_contacts', $contact);
|
2004-12-28 13:49:15 +00:00
|
|
|
} else {
|
|
|
|
/// no changes to blocking status
|
|
|
|
return true;
|
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2004-12-16 12:40:36 +00:00
|
|
|
} else {
|
2004-12-28 13:49:15 +00:00
|
|
|
/// new contact record
|
|
|
|
unset($contact);
|
|
|
|
$contact->userid = $USER->id;
|
|
|
|
$contact->contactid = $contactid;
|
|
|
|
$contact->blocked = $blocked;
|
2008-06-05 13:41:16 +00:00
|
|
|
return $DB->insert_record('message_contacts', $contact, false);
|
2004-12-16 12:40:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
function message_remove_contact($contactid) {
|
2008-06-05 13:41:16 +00:00
|
|
|
global $USER, $DB;
|
|
|
|
return $DB->delete_records('message_contacts', array('userid'=>$USER->id, 'contactid'=>$contactid));
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function message_unblock_contact($contactid) {
|
2008-06-05 13:41:16 +00:00
|
|
|
global $USER, $DB;
|
|
|
|
return $DB->delete_records('message_contacts', array('userid'=>$USER->id, 'contactid'=>$contactid));
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function message_block_contact($contactid) {
|
|
|
|
return message_add_contact($contactid, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
function message_get_contact($contactid) {
|
2008-06-05 13:41:16 +00:00
|
|
|
global $USER, $DB;
|
|
|
|
return $DB->get_record('message_contacts', array('userid'=>$USER->id, 'contactid'=>$contactid));
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
function message_print_search_results($frm, $showicontext=false, $user1=null) {
|
|
|
|
global $USER, $CFG, $DB, $OUTPUT, $PAGE;
|
|
|
|
|
|
|
|
if (empty($user1)) {
|
|
|
|
$user1 = $USER;
|
|
|
|
}
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
echo '<div class="mdl-left">';
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
$personsearch = false;
|
|
|
|
$personsearchstring = null;
|
2004-12-28 13:49:15 +00:00
|
|
|
if (!empty($frm->personsubmit) and !empty($frm->name)) {
|
2010-06-25 08:16:10 +00:00
|
|
|
$personsearch = true;
|
|
|
|
$personsearchstring = $frm->name;
|
|
|
|
} else if (!empty($frm->combinedsubmit) and !empty($frm->combinedsearch)) {
|
|
|
|
$personsearch = true;
|
|
|
|
$personsearchstring = $frm->combinedsearch;
|
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
/// search for person
|
|
|
|
if ($personsearch) {
|
2006-12-18 17:10:35 +00:00
|
|
|
if (optional_param('mycourses', 0, PARAM_BOOL)) {
|
2004-12-28 13:49:15 +00:00
|
|
|
$users = array();
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$mycourses = enrol_get_my_courses();
|
2004-12-28 13:49:15 +00:00
|
|
|
foreach ($mycourses as $mycourse) {
|
2010-06-25 08:16:10 +00:00
|
|
|
if (is_array($susers = message_search_users($mycourse->id, $personsearchstring))) {
|
2004-12-28 13:49:15 +00:00
|
|
|
foreach ($susers as $suser) $users[$suser->id] = $suser;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-06-25 08:16:10 +00:00
|
|
|
$users = message_search_users(SITEID, $personsearchstring);
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($users)) {
|
2010-07-07 07:49:08 +00:00
|
|
|
echo html_writer::start_tag('p', array('class'=>'heading searchresultcount'));
|
|
|
|
echo get_string('userssearchresults', 'message', count($users));
|
|
|
|
echo html_writer::end_tag('p');
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
echo '<table class="messagesearchresults">';
|
2004-12-28 13:49:15 +00:00
|
|
|
foreach ($users as $user) {
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2008-01-15 16:10:58 +00:00
|
|
|
if ( $user->contactlistid ) {
|
|
|
|
if ($user->blocked == 0) { /// not blocked
|
2010-06-25 08:16:10 +00:00
|
|
|
$strcontact = message_contact_link($user->id, 'remove', true, null, $showicontext);
|
|
|
|
$strblock = message_contact_link($user->id, 'block', true, null, $showicontext);
|
2004-12-28 13:49:15 +00:00
|
|
|
} else { // blocked
|
2010-06-25 08:16:10 +00:00
|
|
|
$strcontact = message_contact_link($user->id, 'add', true, null, $showicontext);
|
|
|
|
$strblock = message_contact_link($user->id, 'unblock', true, null, $showicontext);
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-06-25 08:16:10 +00:00
|
|
|
$strcontact = message_contact_link($user->id, 'add', true, null, $showicontext);
|
|
|
|
$strblock = message_contact_link($user->id, 'block', true, null, $showicontext);
|
|
|
|
}
|
|
|
|
|
|
|
|
//should we show just the icon or icon and text?
|
|
|
|
$histicontext = 'icon';
|
|
|
|
if ($showicontext) {
|
|
|
|
$histicontext = 'both';
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
2010-06-25 08:16:10 +00:00
|
|
|
$strhistory = message_history_link($USER->id, $user->id, true, '', '', $histicontext);
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2005-04-23 14:38:57 +00:00
|
|
|
echo '<tr><td class="pix">';
|
2009-12-27 19:47:21 +00:00
|
|
|
echo $OUTPUT->user_picture($user, array('size'=>20, 'courseid'=>SITEID));
|
2004-12-28 13:49:15 +00:00
|
|
|
echo '</td>';
|
2005-04-23 14:38:57 +00:00
|
|
|
echo '<td class="contact">';
|
2009-08-20 13:15:29 +00:00
|
|
|
$popupoptions = array(
|
2010-06-25 08:16:10 +00:00
|
|
|
'height' => MESSAGE_DISCUSSION_HEIGHT,
|
|
|
|
'width' => MESSAGE_DISCUSSION_WIDTH,
|
2009-08-20 13:15:29 +00:00
|
|
|
'menubar' => false,
|
|
|
|
'location' => false,
|
|
|
|
'status' => true,
|
|
|
|
'scrollbars' => true,
|
|
|
|
'resizable' => true);
|
|
|
|
|
2010-06-29 07:27:24 +00:00
|
|
|
$link = new moodle_url("/message/index.php?id=$user->id");
|
2010-06-25 08:16:10 +00:00
|
|
|
//$action = new popup_action('click', $link, "message_$user->id", $popupoptions);
|
|
|
|
$action = null;
|
2010-02-11 18:50:55 +00:00
|
|
|
echo $OUTPUT->action_link($link, fullname($user), $action, array('title'=>get_string('sendmessageto', 'message', fullname($user))));
|
2007-11-21 07:53:42 +00:00
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
echo '</td>';
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2005-04-23 14:38:57 +00:00
|
|
|
echo '<td class="link">'.$strcontact.'</td>';
|
|
|
|
echo '<td class="link">'.$strblock.'</td>';
|
|
|
|
echo '<td class="link">'.$strhistory.'</td>';
|
2004-12-28 13:49:15 +00:00
|
|
|
echo '</tr>';
|
|
|
|
}
|
|
|
|
echo '</table>';
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
} else {
|
2010-07-07 07:49:08 +00:00
|
|
|
echo html_writer::start_tag('p', array('class'=>'heading searchresultcount'));
|
2010-06-25 08:16:10 +00:00
|
|
|
echo get_string('userssearchresults', 'message', 0).'<br /><br />';
|
2010-07-07 07:49:08 +00:00
|
|
|
echo html_writer::end_tag('p');
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
// search messages for keywords
|
|
|
|
$messagesearch = false;
|
|
|
|
$messagesearchstring = null;
|
|
|
|
if (!empty($frm->keywords)) {
|
|
|
|
$messagesearch = true;
|
|
|
|
$messagesearchstring = clean_text(trim($frm->keywords));
|
|
|
|
} else if (!empty($frm->combinedsubmit) and !empty($frm->combinedsearch)) {
|
|
|
|
$messagesearch = true;
|
|
|
|
$messagesearchstring = clean_text(trim($frm->combinedsearch));
|
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
if ($messagesearch) {
|
|
|
|
if ($messagesearchstring) {
|
|
|
|
$keywords = explode(' ', $messagesearchstring);
|
2009-01-19 04:53:26 +00:00
|
|
|
} else {
|
|
|
|
$keywords = array();
|
|
|
|
}
|
2004-12-28 13:49:15 +00:00
|
|
|
$tome = false;
|
|
|
|
$fromme = false;
|
|
|
|
$courseid = 'none';
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
if (empty($frm->keywordsoption)) {
|
|
|
|
$frm->keywordsoption = 'allmine';
|
|
|
|
}
|
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
switch ($frm->keywordsoption) {
|
|
|
|
case 'tome':
|
|
|
|
$tome = true;
|
|
|
|
break;
|
|
|
|
case 'fromme':
|
|
|
|
$fromme = true;
|
|
|
|
break;
|
|
|
|
case 'allmine':
|
|
|
|
$tome = true;
|
|
|
|
$fromme = true;
|
|
|
|
break;
|
|
|
|
case 'allusers':
|
|
|
|
$courseid = SITEID;
|
|
|
|
break;
|
|
|
|
case 'courseusers':
|
|
|
|
$courseid = $frm->courseid;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$tome = true;
|
|
|
|
$fromme = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($messages = message_search($keywords, $fromme, $tome, $courseid)) !== false) {
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
/// get a list of contacts
|
2008-06-05 13:41:16 +00:00
|
|
|
if (($contacts = $DB->get_records('message_contacts', array('userid'=>$USER->id), '', 'contactid, blocked') ) === false) {
|
2004-12-29 03:54:33 +00:00
|
|
|
$contacts = array();
|
|
|
|
}
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2004-12-29 03:54:33 +00:00
|
|
|
/// print heading with number of results
|
2010-07-07 07:49:08 +00:00
|
|
|
echo html_writer::start_tag('p', array('class'=>'heading searchresultcount'));
|
|
|
|
$countresults = count($messages);
|
|
|
|
if ($countresults==MESSAGE_SEARCH_MAX_RESULTS) {
|
|
|
|
echo get_string('keywordssearchresultstoomany', 'message', $countresults).' ("'.s($messagesearchstring).'")';
|
|
|
|
} else {
|
2010-10-25 09:29:34 +00:00
|
|
|
echo get_string('keywordssearchresults', 'message', $countresults);
|
2010-07-07 07:49:08 +00:00
|
|
|
}
|
|
|
|
echo html_writer::end_tag('p');
|
2004-12-29 03:54:33 +00:00
|
|
|
|
|
|
|
/// print table headings
|
2010-06-25 08:16:10 +00:00
|
|
|
echo '<table class="messagesearchresults" cellspacing="0">';
|
2010-07-07 07:49:08 +00:00
|
|
|
|
|
|
|
$headertdstart = html_writer::start_tag('td', array('class'=>'messagesearchresultscol'));
|
|
|
|
$headertdend = html_writer::end_tag('td');
|
2004-12-29 03:54:33 +00:00
|
|
|
echo '<tr>';
|
2010-07-07 07:49:08 +00:00
|
|
|
echo $headertdstart.get_string('from').$headertdend;
|
|
|
|
echo $headertdstart.get_string('to').$headertdend;
|
|
|
|
echo $headertdstart.get_string('message', 'message').$headertdend;
|
|
|
|
echo $headertdstart.get_string('timesent', 'message').$headertdend;
|
2004-12-29 03:54:33 +00:00
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
$blockedcount = 0;
|
2008-05-08 03:49:51 +00:00
|
|
|
$dateformat = get_string('strftimedatetimeshort');
|
2005-01-03 12:16:06 +00:00
|
|
|
$strcontext = get_string('context', 'message');
|
2004-12-28 13:49:15 +00:00
|
|
|
foreach ($messages as $message) {
|
2004-12-29 03:54:33 +00:00
|
|
|
|
|
|
|
/// ignore messages to and from blocked users unless $frm->includeblocked is set
|
2006-12-18 17:10:35 +00:00
|
|
|
if (!optional_param('includeblocked', 0, PARAM_BOOL) and (
|
2004-12-29 03:54:33 +00:00
|
|
|
( isset($contacts[$message->useridfrom]) and ($contacts[$message->useridfrom]->blocked == 1)) or
|
|
|
|
( isset($contacts[$message->useridto] ) and ($contacts[$message->useridto]->blocked == 1))
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
$blockedcount ++;
|
2004-12-28 13:49:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2004-12-29 03:54:33 +00:00
|
|
|
/// load up user to record
|
|
|
|
if ($message->useridto !== $USER->id) {
|
2008-06-05 13:41:16 +00:00
|
|
|
$userto = $DB->get_record('user', array('id'=>$message->useridto));
|
2006-12-25 22:34:05 +00:00
|
|
|
$tocontact = (array_key_exists($message->useridto, $contacts) and
|
2004-12-29 03:54:33 +00:00
|
|
|
($contacts[$message->useridto]->blocked == 0) );
|
2006-12-25 22:34:05 +00:00
|
|
|
$toblocked = (array_key_exists($message->useridto, $contacts) and
|
2004-12-29 03:54:33 +00:00
|
|
|
($contacts[$message->useridto]->blocked == 1) );
|
|
|
|
} else {
|
|
|
|
$userto = false;
|
|
|
|
$tocontact = false;
|
|
|
|
$toblocked = false;
|
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2004-12-29 03:54:33 +00:00
|
|
|
/// load up user from record
|
|
|
|
if ($message->useridfrom !== $USER->id) {
|
2008-06-05 13:41:16 +00:00
|
|
|
$userfrom = $DB->get_record('user', array('id'=>$message->useridfrom));
|
2006-12-25 22:34:05 +00:00
|
|
|
$fromcontact = (array_key_exists($message->useridfrom, $contacts) and
|
2004-12-29 03:54:33 +00:00
|
|
|
($contacts[$message->useridfrom]->blocked == 0) );
|
2006-12-25 22:34:05 +00:00
|
|
|
$fromblocked = (array_key_exists($message->useridfrom, $contacts) and
|
2004-12-29 03:54:33 +00:00
|
|
|
($contacts[$message->useridfrom]->blocked == 1) );
|
|
|
|
} else {
|
|
|
|
$userfrom = false;
|
|
|
|
$fromcontact = false;
|
|
|
|
$fromblocked = false;
|
|
|
|
}
|
|
|
|
|
2005-01-01 11:47:18 +00:00
|
|
|
/// find date string for this message
|
|
|
|
$date = usergetdate($message->timecreated);
|
|
|
|
$datestring = $date['year'].$date['mon'].$date['mday'];
|
|
|
|
|
2004-12-29 03:54:33 +00:00
|
|
|
/// print out message row
|
|
|
|
echo '<tr valign="top">';
|
2005-04-23 14:38:57 +00:00
|
|
|
echo '<td class="contact">';
|
2010-06-25 08:16:10 +00:00
|
|
|
message_print_user($userfrom, $fromcontact, $fromblocked, $showicontext);
|
2004-12-28 13:49:15 +00:00
|
|
|
echo '</td>';
|
2005-04-23 14:38:57 +00:00
|
|
|
echo '<td class="contact">';
|
2010-06-25 08:16:10 +00:00
|
|
|
message_print_user($userto, $tocontact, $toblocked, $showicontext);
|
2004-12-28 13:49:15 +00:00
|
|
|
echo '</td>';
|
2009-01-19 04:35:09 +00:00
|
|
|
echo '<td class="summary">'.message_get_fragment($message->fullmessage, $keywords);
|
2005-04-23 14:38:57 +00:00
|
|
|
echo '<br /><div class="link">';
|
2010-06-25 08:16:10 +00:00
|
|
|
|
2010-09-17 19:41:02 +00:00
|
|
|
//find the user involved that isn't the current user
|
2010-06-25 08:16:10 +00:00
|
|
|
$user2id = null;
|
|
|
|
if ($user1->id == $message->useridto) {
|
|
|
|
$user2id = $message->useridfrom;
|
|
|
|
} else {
|
|
|
|
$user2id = $message->useridto;
|
|
|
|
}
|
|
|
|
message_history_link($user1->id, $user2id, false,
|
|
|
|
$messagesearchstring, 'm'.$message->id, $strcontext);
|
2005-01-03 15:20:56 +00:00
|
|
|
echo '</div>';
|
2005-01-01 11:47:18 +00:00
|
|
|
echo '</td>';
|
2005-04-23 14:38:57 +00:00
|
|
|
echo '<td class="date">'.userdate($message->timecreated, $dateformat).'</td>';
|
2004-12-29 03:54:33 +00:00
|
|
|
echo "</tr>\n";
|
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2005-01-01 11:47:18 +00:00
|
|
|
if ($blockedcount > 0) {
|
|
|
|
echo '<tr><td colspan="4" align="center">'.get_string('blockedmessages', 'message', $blockedcount).'</td></tr>';
|
|
|
|
}
|
2004-12-28 13:49:15 +00:00
|
|
|
echo '</table>';
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
} else {
|
2010-11-02 03:09:56 +00:00
|
|
|
echo '<p class="heading">'.get_string('keywordssearchresults', 'message', 0).'</p>';
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
if (!$personsearch && !$messagesearch) {
|
2010-09-17 19:41:02 +00:00
|
|
|
//they didn't enter any search terms
|
2009-08-18 05:20:12 +00:00
|
|
|
echo $OUTPUT->notification(get_string('emptysearchstring', 'message'));
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 09:01:45 +00:00
|
|
|
//echo '<br />';
|
|
|
|
//echo $OUTPUT->single_button(new moodle_url($PAGE->url, array('tab' => 'search')), get_string('newsearch', 'message'));
|
2004-12-28 13:49:15 +00:00
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
function message_print_user ($user=false, $iscontact=false, $isblocked=false, $includeicontext=false) {
|
2009-08-20 08:41:47 +00:00
|
|
|
global $USER, $OUTPUT;
|
2009-11-01 12:22:45 +00:00
|
|
|
|
2004-12-29 03:54:33 +00:00
|
|
|
if ($user === false) {
|
2009-12-27 19:47:21 +00:00
|
|
|
echo $OUTPUT->user_picture($USER, array('size'=>20, 'courseid'=>SITEID));
|
2004-12-29 03:54:33 +00:00
|
|
|
} else {
|
2010-10-25 09:29:34 +00:00
|
|
|
echo $OUTPUT->user_picture($user, array('size'=>20, 'courseid'=>SITEID));
|
2005-01-01 11:47:18 +00:00
|
|
|
echo ' ';
|
2010-06-25 08:16:10 +00:00
|
|
|
|
|
|
|
$return = false;
|
|
|
|
$script = null;
|
2004-12-29 03:54:33 +00:00
|
|
|
if ($iscontact) {
|
2010-06-25 08:16:10 +00:00
|
|
|
message_contact_link($user->id, 'remove', $return, $script, $includeicontext);
|
2004-12-29 03:54:33 +00:00
|
|
|
} else {
|
2010-06-25 08:16:10 +00:00
|
|
|
message_contact_link($user->id, 'add', $return, $script, $includeicontext);
|
2004-12-29 03:54:33 +00:00
|
|
|
}
|
|
|
|
echo ' ';
|
|
|
|
if ($isblocked) {
|
2010-06-25 08:16:10 +00:00
|
|
|
message_contact_link($user->id, 'unblock', $return, $script, $includeicontext);
|
2004-12-29 03:54:33 +00:00
|
|
|
} else {
|
2010-06-25 08:16:10 +00:00
|
|
|
message_contact_link($user->id, 'block', $return, $script, $includeicontext);
|
2004-12-29 03:54:33 +00:00
|
|
|
}
|
2005-01-01 11:47:18 +00:00
|
|
|
echo '<br />';
|
2007-11-21 07:53:42 +00:00
|
|
|
|
2009-08-20 13:15:29 +00:00
|
|
|
$popupoptions = array(
|
2010-06-25 08:16:10 +00:00
|
|
|
'height' => MESSAGE_DISCUSSION_HEIGHT,
|
|
|
|
'width' => MESSAGE_DISCUSSION_WIDTH,
|
2009-08-20 13:15:29 +00:00
|
|
|
'menubar' => false,
|
|
|
|
'location' => false,
|
|
|
|
'status' => true,
|
|
|
|
'scrollbars' => true,
|
|
|
|
'resizable' => true);
|
|
|
|
|
2010-06-29 07:27:24 +00:00
|
|
|
$link = new moodle_url("/message/index.php?id=$user->id");
|
2010-06-25 08:16:10 +00:00
|
|
|
//$action = new popup_action('click', $link, "message_$user->id", $popupoptions);
|
|
|
|
$action = null;
|
2010-02-11 18:50:55 +00:00
|
|
|
echo $OUTPUT->action_link($link, fullname($user), $action, array('title'=>get_string('sendmessageto', 'message', fullname($user))));
|
2009-08-20 13:15:29 +00:00
|
|
|
|
2004-12-29 03:54:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// linktype can be: add, remove, block, unblock
|
2010-06-25 08:16:10 +00:00
|
|
|
function message_contact_link($userid, $linktype='add', $return=false, $script=null, $text=false, $icon=true) {
|
|
|
|
global $USER, $CFG, $OUTPUT, $PAGE;
|
2005-01-01 11:47:18 +00:00
|
|
|
|
2010-06-28 02:07:45 +00:00
|
|
|
//hold onto the strings as we're probably creating a bunch of links
|
2005-01-01 11:47:18 +00:00
|
|
|
static $str;
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
if (empty($script)) {
|
2010-07-02 08:08:11 +00:00
|
|
|
//strip off previous action params like 'removecontact'
|
2010-11-02 07:58:16 +00:00
|
|
|
$script = message_remove_url_params($PAGE->url);
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
|
|
|
|
2005-01-01 11:47:18 +00:00
|
|
|
if (empty($str->blockcontact)) {
|
|
|
|
$str->blockcontact = get_string('blockcontact', 'message');
|
|
|
|
$str->unblockcontact = get_string('unblockcontact', 'message');
|
|
|
|
$str->removecontact = get_string('removecontact', 'message');
|
|
|
|
$str->addcontact = get_string('addcontact', 'message');
|
|
|
|
}
|
|
|
|
|
2005-04-14 09:28:07 +00:00
|
|
|
$command = $linktype.'contact';
|
|
|
|
$string = $str->{$command};
|
2010-06-28 02:07:45 +00:00
|
|
|
|
|
|
|
$safealttext = s($string);
|
|
|
|
|
|
|
|
$safestring = '';
|
2010-07-04 18:36:34 +00:00
|
|
|
if (!empty($text)) {
|
2010-06-28 02:07:45 +00:00
|
|
|
$safestring = $safealttext;
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$img = '';
|
|
|
|
if ($icon) {
|
2010-06-28 02:07:45 +00:00
|
|
|
$iconpath = null;
|
|
|
|
switch ($linktype) {
|
|
|
|
case 'block':
|
|
|
|
$iconpath = 't/block';
|
|
|
|
break;
|
|
|
|
case 'unblock':
|
|
|
|
$iconpath = 't/userblue';
|
|
|
|
break;
|
|
|
|
case 'remove':
|
|
|
|
$iconpath = 'i/cross_red_big';
|
|
|
|
break;
|
|
|
|
case 'add':
|
|
|
|
default:
|
|
|
|
$iconpath = 't/addgreen';
|
|
|
|
}
|
|
|
|
|
|
|
|
$img = '<img src="'.$OUTPUT->pix_url($iconpath).'" class="iconsmall" alt="'.$safealttext.'" />';
|
2004-12-29 03:54:33 +00:00
|
|
|
}
|
2005-04-14 09:28:07 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
$output = '<span class="'.$linktype.'contact">'.
|
2005-04-14 09:28:07 +00:00
|
|
|
'<a href="'.$script.'&'.$command.'='.$userid.
|
2010-10-13 03:28:16 +00:00
|
|
|
'&sesskey='.sesskey().'" title="'.$safealttext.'">'.
|
2010-06-25 08:16:10 +00:00
|
|
|
$img.
|
2010-06-28 02:07:45 +00:00
|
|
|
$safestring.'</a></span>';
|
2005-04-14 09:28:07 +00:00
|
|
|
|
2005-01-01 11:47:18 +00:00
|
|
|
if ($return) {
|
|
|
|
return $output;
|
2004-12-29 03:54:33 +00:00
|
|
|
} else {
|
2005-01-01 11:47:18 +00:00
|
|
|
echo $output;
|
2004-12-29 03:54:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
function message_history_link($userid1, $userid2, $returnstr=false, $keywords='', $position='', $linktext='') {
|
2009-07-02 11:09:15 +00:00
|
|
|
global $USER, $CFG, $OUTPUT;
|
2005-01-01 04:37:40 +00:00
|
|
|
|
2005-04-23 06:08:33 +00:00
|
|
|
static $strmessagehistory;
|
|
|
|
|
|
|
|
if (empty($strmessagehistory)) {
|
|
|
|
$strmessagehistory = get_string('messagehistory', 'message');
|
|
|
|
}
|
2005-03-27 06:30:41 +00:00
|
|
|
|
2005-01-01 11:47:18 +00:00
|
|
|
if ($position) {
|
|
|
|
$position = "#$position";
|
|
|
|
}
|
2005-01-03 12:16:06 +00:00
|
|
|
if ($keywords) {
|
|
|
|
$keywords = "&search=".urlencode($keywords);
|
|
|
|
}
|
2005-01-01 04:37:40 +00:00
|
|
|
|
2005-04-23 06:08:33 +00:00
|
|
|
if ($linktext == 'icon') { // Icon only
|
2009-12-16 21:50:45 +00:00
|
|
|
$fulllink = '<img src="'.$OUTPUT->pix_url('t/log') . '" class="iconsmall" alt="'.$strmessagehistory.'" />';
|
2005-04-23 06:08:33 +00:00
|
|
|
} else if ($linktext == 'both') { // Icon and standard name
|
2009-12-16 21:50:45 +00:00
|
|
|
$fulllink = '<img src="'.$OUTPUT->pix_url('t/log') . '" class="iconsmall" alt="" />';
|
2005-04-23 06:08:33 +00:00
|
|
|
$fulllink .= ' '.$strmessagehistory;
|
|
|
|
} else if ($linktext) { // Custom name
|
|
|
|
$fulllink = $linktext;
|
|
|
|
} else { // Standard name only
|
|
|
|
$fulllink = $strmessagehistory;
|
2005-01-03 10:49:40 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 13:15:29 +00:00
|
|
|
$popupoptions = array(
|
|
|
|
'height' => 500,
|
|
|
|
'width' => 500,
|
|
|
|
'menubar' => false,
|
|
|
|
'location' => false,
|
|
|
|
'status' => true,
|
|
|
|
'scrollbars' => true,
|
|
|
|
'resizable' => true);
|
|
|
|
|
2010-06-29 07:27:24 +00:00
|
|
|
$link = new moodle_url('/message/index.php?history='.MESSAGE_HISTORY_ALL."&user=$userid1&id=$userid2$keywords$position");
|
2010-06-25 08:16:10 +00:00
|
|
|
//$action = new popup_action('click', $link, "message_history_$userid1", $popupoptions);
|
|
|
|
$action = null;
|
2010-02-11 18:50:55 +00:00
|
|
|
$str = $OUTPUT->action_link($link, $fulllink, $action, array('title'=>$strmessagehistory));
|
2005-01-01 04:37:40 +00:00
|
|
|
|
2005-04-14 09:28:07 +00:00
|
|
|
$str = '<span class="history">'.$str.'</span>';
|
|
|
|
|
2005-01-01 04:37:40 +00:00
|
|
|
if ($returnstr) {
|
|
|
|
return $str;
|
|
|
|
} else {
|
|
|
|
echo $str;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2004-12-28 13:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search through course users
|
|
|
|
*
|
2006-12-25 22:34:05 +00:00
|
|
|
* If $coursid specifies the site course then this function searches
|
2004-12-28 13:49:15 +00:00
|
|
|
* through all undeleted and confirmed users
|
|
|
|
*
|
2008-01-15 16:10:58 +00:00
|
|
|
* @uses $CFG, $USER
|
2004-12-28 13:49:15 +00:00
|
|
|
* @uses SITEID
|
|
|
|
* @param int $courseid The course in question.
|
|
|
|
* @param string $searchtext ?
|
|
|
|
* @param string $sort ?
|
2006-12-25 22:34:05 +00:00
|
|
|
* @param string $exceptions ?
|
2004-12-28 13:49:15 +00:00
|
|
|
* @return array An array of {@link $USER} records.
|
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
|
|
|
function message_search_users($courseid, $searchtext, $sort='', $exceptions='') {
|
2008-06-05 13:41:16 +00:00
|
|
|
global $CFG, $USER, $DB;
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2008-06-09 19:48:24 +00:00
|
|
|
$fullname = $DB->sql_fullname();
|
2004-12-28 13:49:15 +00:00
|
|
|
|
|
|
|
if (!empty($exceptions)) {
|
|
|
|
$except = ' AND u.id NOT IN ('. $exceptions .') ';
|
|
|
|
} else {
|
|
|
|
$except = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($sort)) {
|
|
|
|
$order = ' ORDER BY '. $sort;
|
|
|
|
} else {
|
|
|
|
$order = '';
|
|
|
|
}
|
|
|
|
|
2010-07-04 18:36:34 +00:00
|
|
|
$ufields = user_picture::fields('u');
|
2004-12-28 13:49:15 +00:00
|
|
|
if (!$courseid or $courseid == SITEID) {
|
2008-06-05 13:41:16 +00:00
|
|
|
$params = array($USER->id, "%$searchtext%");
|
2010-07-04 18:36:34 +00:00
|
|
|
return $DB->get_records_sql("SELECT $ufields, mc.id as contactlistid, mc.blocked
|
2008-06-05 13:54:30 +00:00
|
|
|
FROM {user} u
|
2008-06-05 13:41:16 +00:00
|
|
|
LEFT JOIN {message_contacts} mc
|
2009-11-01 12:22:45 +00:00
|
|
|
ON mc.contactid = u.id AND mc.userid = ?
|
2010-07-04 18:36:34 +00:00
|
|
|
WHERE u.deleted = '0' AND u.confirmed = '1'
|
2010-09-04 13:05:51 +00:00
|
|
|
AND (".$DB->sql_like($fullname, '?', false).")
|
2008-06-05 13:41:16 +00:00
|
|
|
$except
|
|
|
|
$order", $params);
|
2004-12-28 13:49:15 +00:00
|
|
|
} else {
|
2010-07-04 18:36:34 +00:00
|
|
|
//TODO: add enabled enrolment join here (skodak)
|
2006-09-19 01:44:33 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
|
|
|
$contextlists = get_related_contexts_string($context);
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2010-09-18 12:07:01 +00:00
|
|
|
// everyone who has a role assignment in this course or higher
|
2008-06-05 13:41:16 +00:00
|
|
|
$params = array($USER->id, "%$searchtext%");
|
2010-07-04 18:36:34 +00:00
|
|
|
$users = $DB->get_records_sql("SELECT $ufields,
|
|
|
|
FROM {user} u, mc.id as contactlistid, mc.blocked
|
2008-06-05 13:41:16 +00:00
|
|
|
JOIN {role_assignments} ra ON ra.userid = u.id
|
|
|
|
LEFT JOIN {message_contacts} mc
|
2009-11-01 12:22:45 +00:00
|
|
|
ON mc.contactid = u.id AND mc.userid = ?
|
2010-07-04 18:36:34 +00:00
|
|
|
WHERE u.deleted = '0' AND u.confirmed = '1'
|
2008-06-05 13:41:16 +00:00
|
|
|
AND ra.contextid $contextlists
|
2010-09-04 13:05:51 +00:00
|
|
|
AND (".$DB->sql_like($fullname, '?', false).")
|
2008-06-05 13:41:16 +00:00
|
|
|
$except
|
|
|
|
$order", $params);
|
2006-09-19 01:44:33 +00:00
|
|
|
|
|
|
|
return $users;
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-12-29 03:54:33 +00:00
|
|
|
function message_search($searchterms, $fromme=true, $tome=true, $courseid='none', $userid=0) {
|
2004-12-28 13:49:15 +00:00
|
|
|
/// Returns a list of posts found using an array of search terms
|
|
|
|
/// eg word +word -word
|
|
|
|
///
|
2008-06-05 13:41:16 +00:00
|
|
|
global $CFG, $USER, $DB;
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2004-12-29 03:54:33 +00:00
|
|
|
/// If no userid sent then assume current user
|
2006-12-25 22:34:05 +00:00
|
|
|
if ($userid == 0) $userid = $USER->id;
|
2004-12-29 03:54:33 +00:00
|
|
|
|
2006-09-26 05:07:05 +00:00
|
|
|
/// Some differences in SQL syntax
|
2008-06-05 13:54:30 +00:00
|
|
|
if ($DB->sql_regex_supported()) {
|
|
|
|
$REGEXP = $DB->sql_regex(true);
|
|
|
|
$NOTREGEXP = $DB->sql_regex(false);
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
|
|
|
|
2008-06-05 13:54:30 +00:00
|
|
|
$searchcond = array();
|
|
|
|
$params = array();
|
|
|
|
$i = 0;
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2010-07-07 07:49:08 +00:00
|
|
|
//preprocess search terms to check whether we have at least 1 eligible search term
|
|
|
|
//if we do we can drop words around it like 'a'
|
|
|
|
$dropshortwords = false;
|
|
|
|
foreach ($searchterms as $searchterm) {
|
|
|
|
if (strlen($searchterm) >= 2) {
|
|
|
|
$dropshortwords = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
foreach ($searchterms as $searchterm) {
|
2008-06-05 13:54:30 +00:00
|
|
|
$i++;
|
|
|
|
|
2010-09-04 14:52:47 +00:00
|
|
|
$NOT = false; /// Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle
|
2008-06-05 13:54:30 +00:00
|
|
|
|
2010-07-07 07:49:08 +00:00
|
|
|
if ($dropshortwords && strlen($searchterm) < 2) {
|
2004-12-28 13:49:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
2006-10-31 20:22:10 +00:00
|
|
|
/// Under Oracle and MSSQL, trim the + and - operators and perform
|
|
|
|
/// simpler LIKE search
|
2008-06-05 13:54:30 +00:00
|
|
|
if (!$DB->sql_regex_supported()) {
|
|
|
|
if (substr($searchterm, 0, 1) == '-') {
|
2010-09-04 14:52:47 +00:00
|
|
|
$NOT = true;
|
2008-06-05 13:54:30 +00:00
|
|
|
}
|
2006-10-31 20:22:10 +00:00
|
|
|
$searchterm = trim($searchterm, '+-');
|
|
|
|
}
|
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
if (substr($searchterm,0,1) == "+") {
|
|
|
|
$searchterm = substr($searchterm,1);
|
2008-06-05 13:54:30 +00:00
|
|
|
$searchterm = preg_quote($searchterm, '|');
|
2009-01-19 04:35:09 +00:00
|
|
|
$searchcond[] = "m.fullmessage $REGEXP :ss$i";
|
2008-06-05 13:54:30 +00:00
|
|
|
$params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)";
|
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
} else if (substr($searchterm,0,1) == "-") {
|
|
|
|
$searchterm = substr($searchterm,1);
|
2008-06-05 13:54:30 +00:00
|
|
|
$searchterm = preg_quote($searchterm, '|');
|
2009-01-19 04:35:09 +00:00
|
|
|
$searchcond[] = "m.fullmessage $NOTREGEXP :ss$i";
|
2008-06-05 13:54:30 +00:00
|
|
|
$params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)";
|
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
} else {
|
2010-09-04 14:52:47 +00:00
|
|
|
$searchcond[] = $DB->sql_like("m.fullmessage", ":ss$i", false, true, $NOT);
|
2008-06-05 13:54:30 +00:00
|
|
|
$params['ss'.$i] = "%$searchterm%";
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
2004-12-16 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
2008-06-05 13:54:30 +00:00
|
|
|
if (empty($searchcond)) {
|
2010-09-04 13:05:51 +00:00
|
|
|
$searchcond = " ".$DB->sql_like('m.fullmessage', ':ss1', false);
|
2009-01-19 04:53:26 +00:00
|
|
|
$params['ss1'] = "%";
|
|
|
|
} else {
|
|
|
|
$searchcond = implode(" AND ", $searchcond);
|
2006-10-22 19:42:27 +00:00
|
|
|
}
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2004-12-29 03:54:33 +00:00
|
|
|
/// There are several possibilities
|
|
|
|
/// 1. courseid = SITEID : The admin is searching messages by all users
|
|
|
|
/// 2. courseid = ?? : A teacher is searching messages by users in
|
|
|
|
/// one of their courses - currently disabled
|
|
|
|
/// 3. courseid = none : User is searching their own messages;
|
|
|
|
/// a. Messages from user
|
|
|
|
/// b. Messages to user
|
|
|
|
/// c. Messages to and from user
|
|
|
|
|
|
|
|
if ($courseid == SITEID) { /// admin is searching all messages
|
2009-01-19 04:35:09 +00:00
|
|
|
$m_read = $DB->get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.fullmessage, m.timecreated
|
2008-06-05 13:54:30 +00:00
|
|
|
FROM {message_read} m
|
2010-07-07 07:49:08 +00:00
|
|
|
WHERE $searchcond", $params, 0, MESSAGE_SEARCH_MAX_RESULTS);
|
2009-01-19 04:35:09 +00:00
|
|
|
$m_unread = $DB->get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.fullmessage, m.timecreated
|
2008-06-05 13:54:30 +00:00
|
|
|
FROM {message} m
|
2010-07-07 07:49:08 +00:00
|
|
|
WHERE $searchcond", $params, 0, MESSAGE_SEARCH_MAX_RESULTS);
|
2008-06-05 13:54:30 +00:00
|
|
|
|
|
|
|
} else if ($courseid !== 'none') {
|
2004-12-29 03:54:33 +00:00
|
|
|
/// This has not been implemented due to security concerns
|
2008-06-05 13:54:30 +00:00
|
|
|
$m_read = array();
|
|
|
|
$m_unread = array();
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2004-12-29 03:54:33 +00:00
|
|
|
} else {
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2008-06-05 13:54:30 +00:00
|
|
|
if ($fromme and $tome) {
|
|
|
|
$searchcond .= " AND (m.useridfrom=:userid1 OR m.useridto=:userid2)";
|
|
|
|
$params['userid1'] = $userid;
|
|
|
|
$params['userid2'] = $userid;
|
|
|
|
|
|
|
|
} else if ($fromme) {
|
|
|
|
$searchcond .= " AND m.useridfrom=:userid";
|
|
|
|
$params['userid'] = $userid;
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2008-06-05 13:54:30 +00:00
|
|
|
} else if ($tome) {
|
|
|
|
$searchcond .= " AND m.useridto=:userid";
|
|
|
|
$params['userid'] = $userid;
|
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2009-01-19 04:35:09 +00:00
|
|
|
$m_read = $DB->get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.fullmessage, m.timecreated
|
2008-06-05 13:54:30 +00:00
|
|
|
FROM {message_read} m
|
2010-07-07 07:49:08 +00:00
|
|
|
WHERE $searchcond", $params, 0, MESSAGE_SEARCH_MAX_RESULTS);
|
2009-01-19 04:35:09 +00:00
|
|
|
$m_unread = $DB->get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.fullmessage, m.timecreated
|
2008-06-05 13:54:30 +00:00
|
|
|
FROM {message} m
|
2010-07-07 07:49:08 +00:00
|
|
|
WHERE $searchcond", $params, 0, MESSAGE_SEARCH_MAX_RESULTS);
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
}
|
|
|
|
|
2004-12-29 03:54:33 +00:00
|
|
|
/// The keys may be duplicated in $m_read and $m_unread so we can't
|
|
|
|
/// do a simple concatenation
|
|
|
|
$message = array();
|
2008-06-05 13:54:30 +00:00
|
|
|
foreach ($m_read as $m) {
|
|
|
|
$messages[] = $m;
|
|
|
|
}
|
|
|
|
foreach ($m_unread as $m) {
|
|
|
|
$messages[] = $m;
|
|
|
|
}
|
2004-12-28 13:49:15 +00:00
|
|
|
|
|
|
|
return (empty($messages)) ? false : $messages;
|
2004-12-16 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// Borrowed with changes from mod/forum/lib.php
|
|
|
|
function message_shorten_message($message, $minlength=0) {
|
|
|
|
// Given a post object that we already know has a long message
|
|
|
|
// this function truncates the message nicely to the first
|
|
|
|
// sane place between $CFG->forum_longpost and $CFG->forum_shortpost
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
$tag = false;
|
|
|
|
$length = strlen($message);
|
|
|
|
$count = 0;
|
|
|
|
$stopzone = false;
|
|
|
|
$truncate = 0;
|
|
|
|
if ($minlength == 0) $minlength = MESSAGE_SHORTLENGTH;
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2004-12-28 13:49:15 +00:00
|
|
|
|
|
|
|
for ($i=0; $i<$length; $i++) {
|
|
|
|
$char = $message[$i];
|
|
|
|
|
|
|
|
switch ($char) {
|
|
|
|
case "<":
|
|
|
|
$tag = true;
|
|
|
|
break;
|
|
|
|
case ">":
|
|
|
|
$tag = false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!$tag) {
|
|
|
|
if ($stopzone) {
|
|
|
|
if ($char == '.' or $char == ' ') {
|
|
|
|
$truncate = $i+1;
|
|
|
|
break 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!$stopzone) {
|
|
|
|
if ($count > $minlength) {
|
|
|
|
$stopzone = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$truncate) {
|
|
|
|
$truncate = $i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return substr($message, 0, $truncate);
|
|
|
|
}
|
|
|
|
|
2005-01-03 12:16:06 +00:00
|
|
|
|
2008-06-05 13:54:30 +00:00
|
|
|
/**
|
2005-01-03 12:16:06 +00:00
|
|
|
* Given a string and an array of keywords, this function looks
|
|
|
|
* for the first keyword in the string, and then chops out a
|
|
|
|
* small section from the text that shows that word in context.
|
|
|
|
*/
|
|
|
|
function message_get_fragment($message, $keywords) {
|
|
|
|
|
2010-11-08 03:10:30 +00:00
|
|
|
$fullsize = 160;
|
2005-01-03 12:16:06 +00:00
|
|
|
$halfsize = (int)($fullsize/2);
|
|
|
|
|
|
|
|
$message = strip_tags($message);
|
|
|
|
|
|
|
|
foreach ($keywords as $keyword) { // Just get the first one
|
|
|
|
if ($keyword !== '') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (empty($keyword)) { // None found, so just return start of message
|
|
|
|
return message_shorten_message($message, 30);
|
|
|
|
}
|
|
|
|
|
|
|
|
$leadin = $leadout = '';
|
|
|
|
|
|
|
|
/// Find the start of the fragment
|
|
|
|
$start = 0;
|
|
|
|
$length = strlen($message);
|
|
|
|
|
|
|
|
$pos = strpos($message, $keyword);
|
|
|
|
if ($pos > $halfsize) {
|
|
|
|
$start = $pos - $halfsize;
|
|
|
|
$leadin = '...';
|
|
|
|
}
|
|
|
|
/// Find the end of the fragment
|
|
|
|
$end = $start + $fullsize;
|
|
|
|
if ($end > $length) {
|
|
|
|
$end = $length;
|
|
|
|
} else {
|
|
|
|
$leadout = '...';
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Pull out the fragment and format it
|
|
|
|
|
|
|
|
$fragment = substr($message, $start, $end - $start);
|
|
|
|
$fragment = $leadin.highlight(implode(' ',$keywords), $fragment).$leadout;
|
|
|
|
return $fragment;
|
|
|
|
}
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
//retrieve the messages between two users
|
2010-10-25 09:29:34 +00:00
|
|
|
function message_get_history($user1, $user2, $limitnum=0, $viewingnewmessages=false) {
|
|
|
|
global $DB, $CFG;
|
2008-06-05 13:41:16 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
$messages = array();
|
|
|
|
|
|
|
|
//we want messages sorted oldest to newest but if getting a subset of messages we need to sort
|
|
|
|
//desc to get the last $limitnum messages then flip the order in php
|
|
|
|
$sort = 'asc';
|
|
|
|
if ($limitnum>0) {
|
|
|
|
$sort = 'desc';
|
|
|
|
}
|
|
|
|
|
2010-10-25 09:29:34 +00:00
|
|
|
$notificationswhere = null;
|
|
|
|
//we have just moved new messages to read. If theyre here to see new messages dont hide notifications
|
|
|
|
if (!$viewingnewmessages && $CFG->messaginghidereadnotifications) {
|
|
|
|
$notificationswhere = 'AND notification=0';
|
|
|
|
}
|
|
|
|
|
2010-11-01 02:27:34 +00:00
|
|
|
//prevent notifications of your own actions appearing in your own message history
|
|
|
|
$ownnotificationwhere = ' AND NOT (useridfrom=? AND notification=1)';
|
|
|
|
|
2010-10-25 09:29:34 +00:00
|
|
|
if ($messages_read = $DB->get_records_select('message_read', "((useridto = ? AND useridfrom = ?) OR
|
2010-11-01 02:27:34 +00:00
|
|
|
(useridto = ? AND useridfrom = ?)) $notificationswhere $ownnotificationwhere",
|
|
|
|
array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id),
|
2010-06-25 08:16:10 +00:00
|
|
|
"timecreated $sort", '*', 0, $limitnum)) {
|
|
|
|
foreach ($messages_read as $message) {
|
|
|
|
$messages[$message->timecreated] = $message;
|
|
|
|
}
|
|
|
|
}
|
2010-11-01 02:27:34 +00:00
|
|
|
if ($messages_new = $DB->get_records_select('message', "((useridto = ? AND useridfrom = ?) OR
|
|
|
|
(useridto = ? AND useridfrom = ?)) $ownnotificationwhere",
|
|
|
|
array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id),
|
2010-06-25 08:16:10 +00:00
|
|
|
"timecreated $sort", '*', 0, $limitnum)) {
|
2005-01-01 04:23:09 +00:00
|
|
|
foreach ($messages_new as $message) {
|
2010-06-25 08:16:10 +00:00
|
|
|
$messages[$message->timecreated] = $message;
|
2005-01-01 04:23:09 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-25 08:16:10 +00:00
|
|
|
|
|
|
|
//if we only want the last $limitnum messages
|
2010-11-17 06:36:26 +00:00
|
|
|
ksort($messages);
|
|
|
|
$messagecount = count($messages);
|
|
|
|
if ($limitnum>0 && $messagecount>$limitnum) {
|
|
|
|
$messages = array_slice($messages, $messagecount-$limitnum, $limitnum, true);
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
2010-07-04 18:36:34 +00:00
|
|
|
|
2005-01-01 04:23:09 +00:00
|
|
|
return $messages;
|
|
|
|
}
|
|
|
|
|
2010-10-25 09:29:34 +00:00
|
|
|
function message_print_message_history($user1,$user2,$search='',$messagelimit=0, $messagehistorylink=false, $viewingnewmessages=false) {
|
2010-06-25 08:16:10 +00:00
|
|
|
global $CFG, $OUTPUT;
|
|
|
|
|
|
|
|
echo $OUTPUT->box_start('center');
|
|
|
|
echo '<table cellpadding="10" class="message_user_pictures"><tr>';
|
|
|
|
echo '<td align="center" id="user1">';
|
|
|
|
echo $OUTPUT->user_picture($user1, array('size'=>100, 'courseid'=>SITEID));
|
|
|
|
echo '<div class="heading">'.fullname($user1).'</div>';
|
|
|
|
echo '</td>';
|
|
|
|
echo '<td align="center">';
|
2010-08-12 18:38:56 +00:00
|
|
|
echo '<img src="'.$OUTPUT->pix_url('t/left').'" alt="'.get_string('from').'" />';
|
|
|
|
echo '<img src="'.$OUTPUT->pix_url('t/right').'" alt="'.get_string('to').'" />';
|
2010-06-25 08:16:10 +00:00
|
|
|
echo '</td>';
|
|
|
|
echo '<td align="center" id="user2">';
|
|
|
|
echo $OUTPUT->user_picture($user2, array('size'=>100, 'courseid'=>SITEID));
|
|
|
|
echo '<div class="heading">'.fullname($user2).'</div>';
|
|
|
|
|
|
|
|
if (isset($user2->iscontact) && isset($user2->isblocked)) {
|
|
|
|
$incontactlist = $user2->iscontact;
|
|
|
|
$isblocked = $user2->isblocked;
|
|
|
|
|
|
|
|
$script = null;
|
|
|
|
$text = true;
|
|
|
|
$icon = false;
|
|
|
|
|
|
|
|
$strcontact = message_get_contact_add_remove_link($incontactlist, $isblocked, $user2, $script, $text, $icon);
|
|
|
|
$strblock = message_get_contact_block_link($incontactlist, $isblocked, $user2, $script, $text, $icon);
|
2010-06-28 02:59:06 +00:00
|
|
|
$useractionlinks = $strcontact.' |'.$strblock;
|
|
|
|
|
|
|
|
echo html_writer::tag('div', $useractionlinks, array('class'=>'useractionlinks'));
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '</td>';
|
|
|
|
echo '</tr></table>';
|
|
|
|
echo $OUTPUT->box_end();
|
|
|
|
|
|
|
|
if (!empty($messagehistorylink)) {
|
|
|
|
echo $messagehistorylink;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get all the messages and print them
|
2010-10-25 09:29:34 +00:00
|
|
|
if ($messages = message_get_history($user1, $user2, $messagelimit, $viewingnewmessages)) {
|
2010-06-25 08:16:10 +00:00
|
|
|
$tablecontents = '';
|
|
|
|
|
2010-09-21 08:18:23 +00:00
|
|
|
$current = new stdClass();
|
2010-06-25 08:16:10 +00:00
|
|
|
$current->mday = '';
|
|
|
|
$current->month = '';
|
|
|
|
$current->year = '';
|
|
|
|
$messagedate = get_string('strftimetime');
|
|
|
|
$blockdate = get_string('strftimedaydate');
|
|
|
|
foreach ($messages as $message) {
|
2010-10-25 09:29:34 +00:00
|
|
|
if ($message->notification) {
|
|
|
|
$notificationclass = ' notification';
|
|
|
|
} else {
|
|
|
|
$notificationclass = null;
|
|
|
|
}
|
2010-06-25 08:16:10 +00:00
|
|
|
$date = usergetdate($message->timecreated);
|
|
|
|
if ($current->mday != $date['mday'] | $current->month != $date['month'] | $current->year != $date['year']) {
|
|
|
|
$current->mday = $date['mday'];
|
|
|
|
$current->month = $date['month'];
|
|
|
|
$current->year = $date['year'];
|
|
|
|
|
|
|
|
$tablecontents .= '<div class="mdl-align heading"><a name="'.$date['year'].$date['mon'].$date['mday'].'"></a>';
|
|
|
|
$tablecontents .= $OUTPUT->heading(userdate($message->timecreated, $blockdate), 4, 'center').'</div>';
|
|
|
|
}
|
|
|
|
if ($message->useridfrom == $user1->id) {
|
2010-10-25 09:29:34 +00:00
|
|
|
$tablecontents .= "<div class='mdl-left left $notificationclass'>".message_format_message($message, $user1, $messagedate, $search, 'me').'</div><br />';
|
2010-06-25 08:16:10 +00:00
|
|
|
} else {
|
2010-10-25 09:29:34 +00:00
|
|
|
$tablecontents .= "<div class='mdl-left right $notificationclass'>".message_format_message($message, $user2, $messagedate, $search, 'other').'</div><br />';
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo html_writer::nonempty_tag('div', $tablecontents, array('class'=>'mdl-left messagehistory'));
|
|
|
|
} else {
|
2010-07-12 12:56:49 +00:00
|
|
|
echo html_writer::nonempty_tag('div', '('.get_string('nomessagesfound', 'message').')', array('class'=>'mdl-align messagehistory'));
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-04 08:27:40 +00:00
|
|
|
function message_format_message(&$message, &$user, $format='', $keywords='', $class='other') {
|
2005-03-04 14:53:23 +00:00
|
|
|
|
|
|
|
static $dateformat;
|
|
|
|
|
|
|
|
if (empty($dateformat)) {
|
|
|
|
if ($format) {
|
|
|
|
$dateformat = $format;
|
|
|
|
} else {
|
2008-05-08 03:49:51 +00:00
|
|
|
$format = get_string('strftimedatetimeshort');
|
2005-03-04 14:53:23 +00:00
|
|
|
}
|
2005-01-01 04:23:09 +00:00
|
|
|
}
|
2005-03-04 14:53:23 +00:00
|
|
|
$time = userdate($message->timecreated, $dateformat);
|
2010-09-21 08:18:23 +00:00
|
|
|
$options = new stdClass();
|
2005-01-18 19:26:01 +00:00
|
|
|
$options->para = false;
|
2010-10-15 06:59:02 +00:00
|
|
|
|
|
|
|
//if supplied display small messages as fullmessage may contain boilerplate text that shouldnt appear in the messaging UI
|
|
|
|
if (!empty($message->smallmessage)) {
|
2010-11-17 06:36:26 +00:00
|
|
|
$messagetext = format_text($message->smallmessage, FORMAT_MOODLE, $options);
|
2010-10-15 06:59:02 +00:00
|
|
|
} else {
|
|
|
|
$messagetext = format_text($message->fullmessage, $message->fullmessageformat, $options);
|
|
|
|
}
|
|
|
|
|
2010-10-26 08:00:29 +00:00
|
|
|
if (!empty($message->contexturl)) {
|
|
|
|
$displaytext = null;
|
|
|
|
if (!empty($message->contexturlname)) {
|
|
|
|
$displaytext= $message->contexturlname;
|
|
|
|
} else {
|
|
|
|
$displaytext= $message->contexturl;
|
|
|
|
}
|
|
|
|
$messagetext .= html_writer::start_tag('div',array('class'=>'messagecontext'));
|
|
|
|
$messagetext .= get_string('view').': '.html_writer::tag('a', $displaytext, array('href' => $message->contexturl));
|
|
|
|
$messagetext .= html_writer::end_tag('div');
|
|
|
|
}
|
|
|
|
|
2005-01-03 12:16:06 +00:00
|
|
|
if ($keywords) {
|
|
|
|
$messagetext = highlight($keywords, $messagetext);
|
|
|
|
}
|
2010-10-26 08:00:29 +00:00
|
|
|
|
2010-06-28 03:07:02 +00:00
|
|
|
return '<div class="message '.$class.'"><a name="m'.$message->id.'"></a> <span class="time">'.$time.'</span>: <span class="content">'.$messagetext.'</span></div>';
|
2005-01-01 04:23:09 +00:00
|
|
|
}
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2008-06-05 13:41:16 +00:00
|
|
|
/**
|
2005-01-01 16:00:35 +00:00
|
|
|
* Inserts a message into the database, but also forwards it
|
|
|
|
* via other means if appropriate.
|
|
|
|
*/
|
|
|
|
function message_post_message($userfrom, $userto, $message, $format, $messagetype) {
|
2010-10-08 02:31:57 +00:00
|
|
|
global $SITE, $CFG, $USER;
|
2010-11-02 07:37:25 +00:00
|
|
|
|
2010-09-21 08:18:23 +00:00
|
|
|
$eventdata = new stdClass();
|
2010-07-06 01:52:32 +00:00
|
|
|
$eventdata->component = 'moodle';
|
2008-08-30 17:53:30 +00:00
|
|
|
$eventdata->name = 'instantmessage';
|
2008-07-24 08:38:03 +00:00
|
|
|
$eventdata->userfrom = $userfrom;
|
|
|
|
$eventdata->userto = $userto;
|
2010-11-02 07:37:25 +00:00
|
|
|
|
|
|
|
//using string manager directly so that strings in the message will be in the message recipients language rather than the senders
|
|
|
|
$eventdata->subject = get_string_manager()->get_string('unreadnewmessage', 'message', fullname($userfrom), $userto->lang);
|
|
|
|
|
2010-11-24 04:17:52 +00:00
|
|
|
if ($format==FORMAT_HTML) {
|
|
|
|
$eventdata->fullmessage = '';
|
|
|
|
$eventdata->fullmessagehtml = $message;
|
|
|
|
} else {
|
|
|
|
$eventdata->fullmessage = $message;
|
|
|
|
$eventdata->fullmessagehtml = '';
|
|
|
|
}
|
2011-01-27 11:46:37 +01:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
$eventdata->fullmessageformat = $format;
|
2010-11-24 04:17:52 +00:00
|
|
|
$eventdata->smallmessage = strip_tags($message);//strip just in case there are is any html that would break the popup notification
|
2010-10-08 02:31:57 +00:00
|
|
|
|
|
|
|
$s = new stdClass();
|
|
|
|
$s->sitename = $SITE->shortname;
|
2010-11-22 01:44:10 +00:00
|
|
|
$s->url = $CFG->wwwroot.'/message/index.php?user='.$userto->id.'&id='.$userfrom->id;
|
2010-10-08 02:31:57 +00:00
|
|
|
|
2010-11-02 07:37:25 +00:00
|
|
|
$emailtagline = get_string_manager()->get_string('emailtagline', 'message', $s, $userto->lang);
|
2010-10-15 06:59:02 +00:00
|
|
|
if (!empty($eventdata->fullmessage)) {
|
|
|
|
$eventdata->fullmessage .= "\n\n---------------------------------------------------------------------\n".$emailtagline;
|
|
|
|
}
|
|
|
|
if (!empty($eventdata->fullmessagehtml)) {
|
|
|
|
$eventdata->fullmessagehtml .= "<br /><br />---------------------------------------------------------------------<br />".$emailtagline;
|
|
|
|
}
|
2011-01-27 11:46:37 +01:00
|
|
|
|
2009-06-30 08:33:29 +00:00
|
|
|
$eventdata->timecreated = time();
|
2009-11-07 10:27:57 +00:00
|
|
|
return message_send($eventdata);
|
2005-01-01 16:00:35 +00:00
|
|
|
}
|
2004-12-28 13:49:15 +00:00
|
|
|
|
2005-02-12 17:17:32 +00:00
|
|
|
|
2008-06-05 13:41:16 +00:00
|
|
|
/**
|
2005-02-12 17:17:32 +00:00
|
|
|
* 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?
|
|
|
|
*/
|
|
|
|
function message_get_participants() {
|
2008-06-05 13:41:16 +00:00
|
|
|
global $CFG, $DB;
|
|
|
|
|
2008-06-05 13:55:37 +00:00
|
|
|
return $DB->get_records_sql("SELECT useridfrom as id,1 FROM {message}
|
|
|
|
UNION SELECT useridto as id,1 FROM {message}
|
|
|
|
UNION SELECT useridfrom as id,1 FROM {message_read}
|
|
|
|
UNION SELECT useridto as id,1 FROM {message_read}
|
|
|
|
UNION SELECT userid as id,1 FROM {message_contacts}
|
|
|
|
UNION SELECT contactid as id,1 from {message_contacts}");
|
2005-02-12 17:17:32 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 13:48:34 +00:00
|
|
|
/**
|
2009-11-01 12:22:45 +00:00
|
|
|
* Print a row of contactlist displaying user picture, messages waiting and
|
2008-01-15 13:48:34 +00:00
|
|
|
* block links etc
|
2009-08-20 08:41:47 +00:00
|
|
|
* @param $contact contact object containing all fields required for $OUTPUT->user_picture()
|
2008-01-15 13:48:34 +00:00
|
|
|
* @param $incontactlist is the user a contact of ours?
|
2010-06-25 08:16:10 +00:00
|
|
|
* @param $selectcontacturl string the url to send the user to when a contact's name is clicked
|
2008-01-15 13:48:34 +00:00
|
|
|
*/
|
2010-11-02 03:05:11 +00:00
|
|
|
function message_print_contactlist_user($contact, $incontactlist = true, $isblocked = false, $selectcontacturl = null, $showactionlinks = true, $selecteduser=null) {
|
2010-06-25 08:16:10 +00:00
|
|
|
global $OUTPUT, $USER;
|
2008-01-15 13:48:34 +00:00
|
|
|
$fullname = fullname($contact);
|
|
|
|
$fullnamelink = $fullname;
|
|
|
|
|
2010-11-02 03:05:11 +00:00
|
|
|
$linkclass = '';
|
|
|
|
if (!empty($selecteduser) && $contact->id==$selecteduser->id) {
|
|
|
|
$linkclass = 'messageselecteduser';
|
|
|
|
}
|
|
|
|
|
2008-01-15 13:48:34 +00:00
|
|
|
/// are there any unread messages for this contact?
|
|
|
|
if ($contact->messagecount > 0 ){
|
|
|
|
$fullnamelink = '<strong>'.$fullnamelink.' ('.$contact->messagecount.')</strong>';
|
|
|
|
}
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
$strcontact = $strblock = $strhistory = null;
|
2008-01-15 13:48:34 +00:00
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
if ($showactionlinks) {
|
|
|
|
$strcontact = message_get_contact_add_remove_link($incontactlist, $isblocked, $contact);
|
|
|
|
$strblock = message_get_contact_block_link($incontactlist, $isblocked, $contact);
|
|
|
|
$strhistory = message_history_link($USER->id, $contact->id, true, '', '', 'icon');
|
2008-01-15 13:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '<tr><td class="pix">';
|
2009-12-27 19:47:21 +00:00
|
|
|
echo $OUTPUT->user_picture($contact, array('size'=>20, 'courseid'=>SITEID));
|
2008-01-15 13:48:34 +00:00
|
|
|
echo '</td>';
|
|
|
|
echo '<td class="contact">';
|
2009-11-01 12:22:45 +00:00
|
|
|
|
2009-08-20 13:15:29 +00:00
|
|
|
$popupoptions = array(
|
2010-06-25 08:16:10 +00:00
|
|
|
'height' => MESSAGE_DISCUSSION_HEIGHT,
|
|
|
|
'width' => MESSAGE_DISCUSSION_WIDTH,
|
2009-08-20 13:15:29 +00:00
|
|
|
'menubar' => false,
|
|
|
|
'location' => false,
|
|
|
|
'status' => true,
|
|
|
|
'scrollbars' => true,
|
|
|
|
'resizable' => true);
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
$link = $action = null;
|
|
|
|
if (!empty($selectcontacturl)) {
|
|
|
|
$link = new moodle_url($selectcontacturl.'&'.CONTACT_ID.'='.$contact->id);
|
|
|
|
} else {
|
2010-11-01 07:34:32 +00:00
|
|
|
//can $selectcontacturl be removed and maybe the be removed and hardcoded?
|
|
|
|
$link = new moodle_url("/message/index.php?id=$contact->id");
|
2010-06-25 08:16:10 +00:00
|
|
|
$action = new popup_action('click', $link, "message_$contact->id", $popupoptions);
|
|
|
|
}
|
2010-11-02 03:05:11 +00:00
|
|
|
echo $OUTPUT->action_link($link, $fullnamelink, $action, array('class'=>$linkclass,'title'=>get_string('sendmessageto', 'message', $fullname)));
|
2008-01-15 13:48:34 +00:00
|
|
|
|
|
|
|
echo '</td>';
|
|
|
|
echo '<td class="link"> '.$strcontact.$strblock.' '.$strhistory.'</td>';
|
|
|
|
echo '</tr>';
|
|
|
|
}
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
function message_get_contact_add_remove_link($incontactlist, $isblocked, $contact, $script=null, $text=false, $icon=true) {
|
|
|
|
$strcontact = '';
|
|
|
|
|
|
|
|
if($incontactlist){
|
|
|
|
$strcontact = message_contact_link($contact->id, 'remove', true, $script, $text, $icon);
|
|
|
|
} else if ($isblocked) {
|
|
|
|
$strcontact = message_contact_link($contact->id, 'add', true, $script, $text, $icon);
|
|
|
|
} else{
|
|
|
|
$strcontact = message_contact_link($contact->id, 'add', true, $script, $text, $icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $strcontact;
|
|
|
|
}
|
|
|
|
|
|
|
|
function message_get_contact_block_link($incontactlist, $isblocked, $contact, $script=null, $text=false, $icon=true) {
|
|
|
|
$strblock = '';
|
|
|
|
|
|
|
|
//commented out to allow the user to block a contact without having to remove them first
|
|
|
|
/*if ($incontactlist) {
|
|
|
|
//$strblock = '';
|
|
|
|
} else*/
|
|
|
|
if ($isblocked) {
|
|
|
|
$strblock = ' '.message_contact_link($contact->id, 'unblock', true, $script, $text, $icon);
|
|
|
|
} else{
|
|
|
|
$strblock = ' '.message_contact_link($contact->id, 'block', true, $script, $text, $icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $strblock;
|
|
|
|
}
|
|
|
|
|
2009-04-26 22:56:56 +00:00
|
|
|
/**
|
|
|
|
* Moves unread messages from message table to message_read for a given from user
|
|
|
|
* @param object $userid User id
|
|
|
|
* @return boolean success
|
|
|
|
*/
|
|
|
|
function message_move_userfrom_unread2read($userid) {
|
|
|
|
|
|
|
|
global $DB;
|
|
|
|
|
2010-09-17 19:41:02 +00:00
|
|
|
// move all unread messages from message table to message_read
|
2009-04-26 22:56:56 +00:00
|
|
|
if ($messages = $DB->get_records_select('message', 'useridfrom = ?', array($userid), 'timecreated')) {
|
|
|
|
foreach ($messages as $message) {
|
2010-10-07 03:59:07 +00:00
|
|
|
message_mark_message_read($message, 0); //set timeread to 0 as the message was never read
|
2009-04-26 22:56:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-30 17:53:30 +00:00
|
|
|
function message_get_popup_messages($destuserid, $fromuserid=NULL){
|
|
|
|
global $DB;
|
2009-11-01 12:22:45 +00:00
|
|
|
|
2008-08-30 17:53:30 +00:00
|
|
|
$processor = $DB->get_record('message_processors', array('name' => 'popup'));
|
|
|
|
|
2009-06-30 08:33:29 +00:00
|
|
|
$messagesproc = $DB->get_records('message_working', array('processorid'=>$processor->id), 'id ASC');
|
2008-08-30 17:53:30 +00:00
|
|
|
|
|
|
|
//for every message to process check if it's for current user and process
|
|
|
|
$messages = array();
|
|
|
|
foreach ($messagesproc as $msgp){
|
|
|
|
$query = array('id'=>$msgp->unreadmessageid, 'useridto'=>$destuserid);
|
|
|
|
if ($fromuserid){
|
|
|
|
$query['useridfrom'] = $fromuserid;
|
|
|
|
}
|
|
|
|
if ($message = $DB->get_record('message', $query)){
|
|
|
|
$messages[] = $message;
|
|
|
|
/// Move the entry to the other table
|
|
|
|
$message->timeread = time();
|
|
|
|
$messageid = $message->id;
|
|
|
|
unset($message->id);
|
2009-11-01 12:22:45 +00:00
|
|
|
|
2008-08-30 17:53:30 +00:00
|
|
|
//delete what we've processed and check if can move message
|
|
|
|
$DB->delete_records('message_working', array('id' => $msgp->id));
|
|
|
|
if ( $DB->count_records('message_working', array('unreadmessageid'=>$messageid)) == 0){
|
2010-10-07 03:59:07 +00:00
|
|
|
message_mark_message_read($message, time(), true);
|
2008-08-30 17:53:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $messages;
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
|
|
|
|
2010-10-07 03:59:07 +00:00
|
|
|
/**
|
|
|
|
* marks ALL messages being sent from $fromuserid to $touserid as read
|
|
|
|
* @param int $touserid the id of the message recipient
|
|
|
|
* @param int $fromuserid the id of the message sender
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-07-06 01:52:32 +00:00
|
|
|
function message_mark_messages_read($touserid, $fromuserid){
|
2010-06-25 08:16:10 +00:00
|
|
|
global $DB;
|
|
|
|
|
2010-10-07 03:59:07 +00:00
|
|
|
$sql = 'SELECT m.* FROM {message} m WHERE m.useridto=:useridto AND m.useridfrom=:useridfrom';
|
2010-07-06 01:52:32 +00:00
|
|
|
$messages = $DB->get_recordset_sql($sql, array('useridto'=>$touserid,'useridfrom'=>$fromuserid));
|
|
|
|
|
2010-06-25 08:16:10 +00:00
|
|
|
foreach ($messages as $message) {
|
2010-10-07 03:59:07 +00:00
|
|
|
message_mark_message_read($message, time());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark a single message as read
|
|
|
|
* @param message an object with an object property ie $message->id which is an id in the message table
|
|
|
|
* @param int $timeread the timestamp for when the message should be marked read. Usually time().
|
|
|
|
* @param bool $messageworkingempty Is the message_working table already confirmed empty for this message?
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function message_mark_message_read($message, $timeread, $messageworkingempty=false) {
|
|
|
|
global $DB;
|
2011-01-27 11:46:37 +01:00
|
|
|
|
2010-10-07 03:59:07 +00:00
|
|
|
$message->timeread = $timeread;
|
2010-06-25 08:16:10 +00:00
|
|
|
|
2010-10-07 03:59:07 +00:00
|
|
|
$messageid = $message->id;
|
|
|
|
unset($message->id);//unset because it will get a new id on insert into message_read
|
2010-07-06 01:52:32 +00:00
|
|
|
|
2010-10-07 03:59:07 +00:00
|
|
|
//If any processors have pending actions abort them
|
|
|
|
if (!$messageworkingempty) {
|
|
|
|
$DB->delete_records('message_working', array('unreadmessageid' => $messageid));
|
2010-06-25 08:16:10 +00:00
|
|
|
}
|
2010-10-07 03:59:07 +00:00
|
|
|
$DB->insert_record('message_read', $message);
|
|
|
|
$DB->delete_records('message', array('id' => $messageid));
|
2010-06-29 14:57:45 +00:00
|
|
|
}
|