/** * Print $user1's contacts. Called by message_print_contact_selector() * @param array $onlinecontacts $user1's contacts which are online * @param array $offlinecontacts $user1's contacts which are offline * @param array $strangers users which are not contacts but who have messaged $user1 * @param string $contactselecturl the url to send the user to when a contact's name is clicked * @param int $minmessages The minimum number of unread messages required from a user for them to be displayed * Typically 0 (show all contacts) or 1 (only show contacts from whom we have a new message) * @param bool $showactionlinks show action links (add/remove contact etc) next to the users * @param string $titletodisplay Optionally specify a title to display above the participants * @param object $user2 the user $user1 is talking to. They will be highlighted if they appear in the list of contacts * @return void */ function message_print_contacts($onlinecontacts, $offlinecontacts, $strangers, $contactselecturl=null, $minmessages=0, $showactionlinks=true, $titletodisplay=null, $user2=null) { global $CFG, $PAGE, $OUTPUT; $countonlinecontacts = count($onlinecontacts); $countofflinecontacts = count($offlinecontacts); $countstrangers = count($strangers); $isuserblocked = null; if ($countonlinecontacts + $countofflinecontacts == 0) { echo html_writer::tag('div', get_string('contactlistempty', 'message'), array('class' => 'heading')); } echo html_writer::start_tag('table', array('id' => 'message_contacts', 'class' => 'boxaligncenter')); if (!empty($titletodisplay)) { message_print_heading($titletodisplay); } if($countonlinecontacts) { /// print out list of online contacts if (empty($titletodisplay)) { message_print_heading(get_string('onlinecontacts', 'message', $countonlinecontacts)); } $isuserblocked = false; $isusercontact = true; foreach ($onlinecontacts as $contact) { if ($minmessages == 0 || $contact->messagecount >= $minmessages) { message_print_contactlist_user($contact, $isusercontact, $isuserblocked, $contactselecturl, $showactionlinks, $user2); } } } if ($countofflinecontacts) { /// print out list of offline contacts if (empty($titletodisplay)) { message_print_heading(get_string('offlinecontacts', 'message', $countofflinecontacts)); } $isuserblocked = false; $isusercontact = true; foreach ($offlinecontacts as $contact) { if ($minmessages == 0 || $contact->messagecount >= $minmessages) { message_print_contactlist_user($contact, $isusercontact, $isuserblocked, $contactselecturl, $showactionlinks, $user2); } } } /// print out list of incoming contacts if ($countstrangers) { message_print_heading(get_string('incomingcontacts', 'message', $countstrangers)); $isuserblocked = false; $isusercontact = false; foreach ($strangers as $stranger) { if ($minmessages == 0 || $stranger->messagecount >= $minmessages) { message_print_contactlist_user($stranger, $isusercontact, $isuserblocked, $contactselecturl, $showactionlinks, $user2); } } } echo html_writer::end_tag('table'); if ($countstrangers && ($countonlinecontacts + $countofflinecontacts == 0)) { // Extra help echo html_writer::tag('div','('.get_string('addsomecontactsincoming', 'message').')',array('class' => 'note')); } }
/** * Print $user1's contacts. Called by message_print_contact_selector() * * @param array $onlinecontacts $user1's contacts which are online * @param array $offlinecontacts $user1's contacts which are offline * @param array $strangers users which are not contacts but who have messaged $user1 * @param string $contactselecturl the url to send the user to when a contact's name is clicked * @param int $minmessages The minimum number of unread messages required from a user for them to be displayed * Typically 0 (show all contacts) or 1 (only show contacts from whom we have a new message) * @param bool $showactionlinks show action links (add/remove contact etc) next to the users * @param string $titletodisplay Optionally specify a title to display above the participants * @param object $user2 the user $user1 is talking to. They will be highlighted if they appear in the list of contacts * @return void */ function message_print_contacts($onlinecontacts, $offlinecontacts, $strangers, $contactselecturl = null, $minmessages = 0, $showactionlinks = true, $titletodisplay = null, $user2 = null) { global $CFG, $PAGE, $OUTPUT; $countonlinecontacts = count($onlinecontacts); $countofflinecontacts = count($offlinecontacts); $countstrangers = count($strangers); $isuserblocked = null; if ($countonlinecontacts + $countofflinecontacts == 0) { echo html_writer::tag('div', get_string('contactlistempty', 'message'), array('class' => 'heading')); } if (!empty($titletodisplay)) { echo html_writer::tag('div', $titletodisplay, array('class' => 'heading')); } if ($countonlinecontacts) { // Print out list of online contacts. if (empty($titletodisplay)) { echo html_writer::tag('div', get_string('onlinecontacts', 'message', $countonlinecontacts), array('class' => 'heading')); } $isuserblocked = false; $isusercontact = true; $contacts = ''; foreach ($onlinecontacts as $contact) { if ($minmessages == 0 || $contact->messagecount >= $minmessages) { $content = message_print_contactlist_user($contact, $isusercontact, $isuserblocked, $contactselecturl, $showactionlinks, $user2); $contacts .= html_writer::tag('li', $content); } } if (strlen($contacts) > 0) { echo html_writer::tag('ul', $contacts, array('id' => 'message-onlinecontacts', 'class' => 'message-contacts')); } } if ($countofflinecontacts) { // Print out list of offline contacts. if (empty($titletodisplay)) { echo html_writer::tag('div', get_string('offlinecontacts', 'message', $countofflinecontacts), array('class' => 'heading')); } $isuserblocked = false; $isusercontact = true; $contacts = ''; foreach ($offlinecontacts as $contact) { if ($minmessages == 0 || $contact->messagecount >= $minmessages) { $content = message_print_contactlist_user($contact, $isusercontact, $isuserblocked, $contactselecturl, $showactionlinks, $user2); $contacts .= html_writer::tag('li', $content); } } if (strlen($contacts) > 0) { echo html_writer::tag('ul', $contacts, array('id' => 'message-offlinecontacts', 'class' => 'message-contacts')); } } // Print out list of incoming contacts. if ($countstrangers) { echo html_writer::tag('div', get_string('incomingcontacts', 'message', $countstrangers), array('class' => 'heading')); $isuserblocked = false; $isusercontact = false; $contacts = ''; foreach ($strangers as $stranger) { if ($minmessages == 0 || $stranger->messagecount >= $minmessages) { $content = message_print_contactlist_user($stranger, $isusercontact, $isuserblocked, $contactselecturl, $showactionlinks, $user2); $contacts .= html_writer::tag('li', $content); } } if (strlen($contacts) > 0) { echo html_writer::tag('ul', $contacts, array('id' => 'message-incommingcontacts', 'class' => 'message-contacts')); } } if ($countstrangers && $countonlinecontacts + $countofflinecontacts == 0) { // Extra help echo html_writer::tag('div', '(' . get_string('addsomecontactsincoming', 'message') . ')', array('class' => 'note')); } }
function message_print_contacts() { global $USER, $CFG, $DB, $PAGE, $OUTPUT; $timetoshowusers = 300; //Seconds default if (isset($CFG->block_online_users_timetosee)) { $timetoshowusers = $CFG->block_online_users_timetosee * 60; } // time which a user is counting as being active since $timefrom = time() - $timetoshowusers; // 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 $strangers = array(); // get all in our contactlist who are not blocked in our contact list // and count messages we have waiting from each of them $contactsql = "SELECT u.id, u.firstname, u.lastname, u.picture, \n u.imagealt, u.lastaccess, count(m.id) as messagecount\n FROM {message_contacts} mc\n JOIN {user} u ON u.id = mc.contactid\n LEFT OUTER JOIN {message} m ON m.useridfrom = mc.contactid AND m.useridto = ?\n WHERE mc.userid = ? AND mc.blocked = 0 \n GROUP BY u.id, u.firstname, u.lastname, u.picture,\n u.imagealt, u.lastaccess\n ORDER BY u.firstname ASC;"; if ($rs = $DB->get_recordset_sql($contactsql, array($USER->id, $USER->id))) { foreach ($rs as $rd) { if ($rd->lastaccess >= $timefrom) { // they have been active recently, so are counted online $onlinecontacts[] = $rd; } else { $offlinecontacts[] = $rd; } } unset($rd); $rs->close(); } // get messages from anyone who isn't in our contact list and count the number // of messages we have from each of them $strangersql = "SELECT u.id, u.firstname, u.lastname, u.picture, \n u.imagealt, u.lastaccess, count(m.id) as messagecount\n FROM {message} m\n JOIN {user} u ON u.id = m.useridfrom\n LEFT OUTER JOIN {message_contacts} mc ON mc.contactid = m.useridfrom AND mc.userid = m.useridto\n WHERE mc.id IS NULL AND m.useridto = ? \n GROUP BY u.id, u.firstname, u.lastname, u.picture,\n u.imagealt, u.lastaccess\n ORDER BY u.firstname ASC;"; if ($rs = $DB->get_recordset_sql($strangersql, array($USER->id))) { foreach ($rs as $rd) { $strangers[] = $rd; } unset($rd); $rs->close(); } $countonlinecontacts = count($onlinecontacts); $countofflinecontacts = count($offlinecontacts); $countstrangers = count($strangers); if ($countonlinecontacts + $countofflinecontacts == 0) { echo '<div class="heading">'; print_string('contactlistempty', 'message'); echo '</div>'; echo '<div class="note">'; print_string('addsomecontacts', 'message', $CFG->wwwroot . '/message/index.php?tab=search'); echo '</div>'; } echo '<table id="message_contacts" class="boxaligncenter" cellspacing="2" cellpadding="0" border="0">'; if ($countonlinecontacts) { /// print out list of online contacts echo '<tr><td colspan="3" class="heading">'; echo get_string('onlinecontacts', 'message', $countonlinecontacts); echo '</td></tr>'; foreach ($onlinecontacts as $contact) { message_print_contactlist_user($contact); } } echo '<tr><td colspan="3"> </td></tr>'; if ($countofflinecontacts) { /// print out list of offline contacts echo '<tr><td colspan="3" class="heading">'; echo get_string('offlinecontacts', 'message', $countofflinecontacts); echo '</td></tr>'; foreach ($offlinecontacts as $contact) { message_print_contactlist_user($contact); } echo '<tr><td colspan="3"> </td></tr>'; } /// print out list of incoming contacts if ($countstrangers) { echo '<tr><td colspan="3" class="heading">'; echo get_string('incomingcontacts', 'message', $countstrangers); echo '</td></tr>'; foreach ($strangers as $stranger) { message_print_contactlist_user($stranger, false); } } echo '</table>'; if ($countstrangers && $countonlinecontacts + $countofflinecontacts == 0) { // Extra help echo '<div class="note">('; print_string('addsomecontactsincoming', 'message'); echo ')</div>'; } echo '<br />'; $autorefresh = '<p align="center" class="note">' . get_string('pagerefreshes', 'message', $CFG->message_contacts_refresh) . '</p>'; $autorefresh = addslashes_js($autorefresh); // js escaping $PAGE->requires->js('message/message.js'); $PAGE->requires->js_function_call('refresh_page', array(60 * 1000, $PAGE->url->out())); echo $OUTPUT->container_start('messagejsautorefresh note center'); echo get_string('pagerefreshes', 'message', $CFG->message_contacts_refresh); echo $OUTPUT->container_end(); echo $OUTPUT->container_start('messagejsmanualrefresh aligncenter'); echo $OUTPUT->button(html_form::make_button('index.php', false, get_string('refresh'))); echo $OUTPUT->container_end(); }
function message_print_contacts() { global $USER, $CFG; $timetoshowusers = 300; //Seconds default if (isset($CFG->block_online_users_timetosee)) { $timetoshowusers = $CFG->block_online_users_timetosee * 60; } // time which a user is counting as being active since $timefrom = time() - $timetoshowusers; // 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 $strangers = array(); // get all in our contactlist who are not blocked in our contact list // and count messages we have waiting from each of them $contactsql = "SELECT u.id, u.firstname, u.lastname, u.picture, \n u.imagealt, u.lastaccess, count(m.id) as messagecount\n FROM {$CFG->prefix}message_contacts mc\n JOIN {$CFG->prefix}user u\n ON u.id = mc.contactid\n LEFT OUTER JOIN {$CFG->prefix}message m\n ON m.useridfrom = mc.contactid\n AND m.useridto = {$USER->id}\n WHERE mc.userid = {$USER->id}\n AND mc.blocked = 0 \n GROUP BY u.id, u.firstname, u.lastname, u.picture,\n u.imagealt, u.lastaccess\n ORDER BY u.firstname ASC;"; if ($rs = get_recordset_sql($contactsql)) { while ($rd = rs_fetch_next_record($rs)) { if ($rd->lastaccess >= $timefrom) { // they have been active recently, so are counted online $onlinecontacts[] = $rd; } else { $offlinecontacts[] = $rd; } } unset($rd); rs_close($rs); } // get messages from anyone who isn't in our contact list and count the number // of messages we have from each of them $strangersql = "SELECT u.id, u.firstname, u.lastname, u.picture, \n u.imagealt, u.lastaccess, count(m.id) as messagecount\n FROM {$CFG->prefix}message m\n JOIN {$CFG->prefix}user u \n ON u.id = m.useridfrom\n LEFT OUTER JOIN {$CFG->prefix}message_contacts mc\n ON mc.contactid = m.useridfrom AND \n mc.userid = m.useridto\n WHERE mc.id IS NULL AND m.useridto = {$USER->id} \n GROUP BY u.id, u.firstname, u.lastname, u.picture,\n u.imagealt, u.lastaccess\n ORDER BY u.firstname ASC;"; if ($rs = get_recordset_sql($strangersql)) { while ($rd = rs_fetch_next_record($rs)) { $strangers[] = $rd; } unset($rd); rs_close($rs); } $countonlinecontacts = count($onlinecontacts); $countofflinecontacts = count($offlinecontacts); $countstrangers = count($strangers); if ($countonlinecontacts + $countofflinecontacts == 0) { echo '<div class="heading">'; print_string('contactlistempty', 'message'); echo '</div>'; echo '<div class="note">'; print_string('addsomecontacts', 'message', $CFG->wwwroot . '/message/index.php?tab=search'); echo '</div>'; } echo '<table id="message_contacts" class="boxaligncenter" cellspacing="2" cellpadding="0" border="0">'; if ($countonlinecontacts) { /// print out list of online contacts echo '<tr><td colspan="3" class="heading">'; echo get_string('onlinecontacts', 'message', $countonlinecontacts); echo '</td></tr>'; foreach ($onlinecontacts as $contact) { message_print_contactlist_user($contact); } } echo '<tr><td colspan="3"> </td></tr>'; if ($countofflinecontacts) { /// print out list of offline contacts echo '<tr><td colspan="3" class="heading">'; echo get_string('offlinecontacts', 'message', $countofflinecontacts); echo '</td></tr>'; foreach ($offlinecontacts as $contact) { message_print_contactlist_user($contact); } echo '<tr><td colspan="3"> </td></tr>'; } /// print out list of incoming contacts if ($countstrangers) { echo '<tr><td colspan="3" class="heading">'; echo get_string('incomingcontacts', 'message', $countstrangers); echo '</td></tr>'; foreach ($strangers as $stranger) { message_print_contactlist_user($stranger, false); } } echo '</table>'; if ($countstrangers && $countonlinecontacts + $countofflinecontacts == 0) { // Extra help echo '<div class="note">('; print_string('addsomecontactsincoming', 'message'); echo ')</div>'; } echo '<br />'; $autorefresh = '<p align="center" class="note">' . get_string('pagerefreshes', 'message', $CFG->message_contacts_refresh) . '</p>'; $autorefresh = addslashes_js($autorefresh); // js escaping // gracefully degrade JS autorefresh echo '<script type="text/javascript"> //<![CDATA[ document.write("' . $autorefresh . '") //]]> </script>'; echo '<noscript><div class="button aligncenter">'; echo print_single_button('index.php', false, get_string('refresh')); echo '</div></noscript>'; }
function message_print_contacts($onlinecontacts, $offlinecontacts, $strangers, $refresh = true, $contactselecturl = null, $minmessages = 0, $showactionlinks = true, $titletodisplay = null, $user2 = null) { global $CFG, $PAGE, $OUTPUT; $countonlinecontacts = count($onlinecontacts); $countofflinecontacts = count($offlinecontacts); $countstrangers = count($strangers); if ($countonlinecontacts + $countofflinecontacts == 0) { echo '<div class="heading">'; print_string('contactlistempty', 'message'); echo '</div>'; //echo '<div class="note">'; //print_string('addsomecontacts', 'message', message_remove_url_params($PAGE->url).'?tab=search'); //echo '</div>'; } 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 ($countonlinecontacts) { /// print out list of online contacts if (empty($titletodisplay)) { echo '<tr><td colspan="3" class="heading">'; echo get_string('onlinecontacts', 'message', $countonlinecontacts); echo '</td></tr>'; } foreach ($onlinecontacts as $contact) { if ($minmessages == 0 || $contact->messagecount >= $minmessages) { message_print_contactlist_user($contact, IS_CONTACT, IS_NOT_BLOCKED, $contactselecturl, $showactionlinks, $user2); } } } if ($countofflinecontacts) { /// print out list of offline contacts if (empty($titletodisplay)) { echo '<tr><td colspan="3" class="heading">'; echo get_string('offlinecontacts', 'message', $countofflinecontacts); echo '</td></tr>'; } foreach ($offlinecontacts as $contact) { if ($minmessages == 0 || $contact->messagecount >= $minmessages) { message_print_contactlist_user($contact, IS_CONTACT, IS_NOT_BLOCKED, $contactselecturl, $showactionlinks, $user2); } } echo '<tr><td colspan="3"> </td></tr>'; } /// print out list of incoming contacts if ($countstrangers) { echo '<tr><td colspan="3" class="heading">'; echo get_string('incomingcontacts', 'message', $countstrangers); echo '</td></tr>'; foreach ($strangers as $stranger) { if ($minmessages == 0 || $stranger->messagecount >= $minmessages) { message_print_contactlist_user($stranger, IS_NOT_CONTACT, IS_NOT_BLOCKED, $contactselecturl, $showactionlinks, $user2); } } } echo '</table>'; if ($countstrangers && $countonlinecontacts + $countofflinecontacts == 0) { // Extra help echo '<div class="note">('; print_string('addsomecontactsincoming', 'message'); echo ')</div>'; } echo '<br />'; if ($refresh) { $PAGE->requires->js_init_call('M.core_message.init_refresh_page', array(60 * 1000, $PAGE->url->out(false))); echo $OUTPUT->container_start('messagejsautorefresh note center'); echo get_string('pagerefreshes', 'message', $CFG->message_contacts_refresh); echo $OUTPUT->container_end(); echo $OUTPUT->container_start('messagejsmanualrefresh aligncenter'); echo $OUTPUT->single_button(message_remove_url_params($PAGE->url), get_string('refresh')); echo $OUTPUT->container_end(); } }