/** * Print a row of contactlist displaying user picture, messages waiting and * block links etc * @param object $contact contact object containing all fields required for $OUTPUT->user_picture() * @param bool $incontactlist is the user a contact of ours? * @param bool $isblocked is the user blocked? * @param string $selectcontacturl the url to send the user to when a contact's name is clicked * @param bool $showactionlinks display action links next to the other users (add contact, block user etc) * @param object $selecteduser the user the current user is viewing (if any). They will be highlighted. */ function message_print_contactlist_user($contact, $incontactlist = true, $isblocked = false, $selectcontacturl = null, $showactionlinks = true, $selecteduser=null) { global $OUTPUT, $USER; $fullname = fullname($contact); $fullnamelink = $fullname; $linkclass = ''; if (!empty($selecteduser) && $contact->id == $selecteduser->id) { $linkclass = 'messageselecteduser'; } /// are there any unread messages for this contact? if ($contact->messagecount > 0 ){ $fullnamelink = '<strong>'.$fullnamelink.' ('.$contact->messagecount.')</strong>'; } $strcontact = $strblock = $strhistory = null; 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'); } echo html_writer::start_tag('tr'); echo html_writer::start_tag('td', array('class' => 'pix')); echo $OUTPUT->user_picture($contact, array('size' => 20, 'courseid' => SITEID)); echo html_writer::end_tag('td'); echo html_writer::start_tag('td', array('class' => 'contact')); $popupoptions = array( 'height' => MESSAGE_DISCUSSION_HEIGHT, 'width' => MESSAGE_DISCUSSION_WIDTH, 'menubar' => false, 'location' => false, 'status' => true, 'scrollbars' => true, 'resizable' => true); $link = $action = null; if (!empty($selectcontacturl)) { $link = new moodle_url($selectcontacturl.'&user2='.$contact->id); } else { //can $selectcontacturl be removed and maybe the be removed and hardcoded? $link = new moodle_url("/message/index.php?id=$contact->id"); $action = new popup_action('click', $link, "message_$contact->id", $popupoptions); } echo $OUTPUT->action_link($link, $fullnamelink, $action, array('class' => $linkclass,'title' => get_string('sendmessageto', 'message', $fullname))); echo html_writer::end_tag('td'); echo html_writer::tag('td', ' '.$strcontact.$strblock.' '.$strhistory, array('class' => 'link')); echo html_writer::end_tag('tr'); }
add_to_log(SITEID, 'message', 'unblock contact', 'history.php?user1=' . $unblockcontact . '&user2=' . $USER->id, $unblockcontact); message_unblock_contact($unblockcontact); } //$PAGE->set_title('Message History'); $PAGE->set_generaltype('popup'); echo $OUTPUT->header(); echo '<table width="100%" cellpadding="0" cellspacing="0"><tr>'; echo '<td width="100">'; $userpic = moodle_user_picture::make($user, SITEID); $userpic->size = 48; $userpic->link = true; echo $OUTPUT->user_picture($userpic) . '</td>'; echo '<td valign="middle" align="center">'; echo '<div class="name">' . fullname($user) . '</div>'; echo '<div class="commands">'; if ($contact = $DB->get_record('message_contacts', array('userid' => $USER->id, 'contactid' => $user->id))) { if ($contact->blocked) { message_contact_link($user->id, 'add', false, 'user.php?id=' . $user->id, true); message_contact_link($user->id, 'unblock', false, 'user.php?id=' . $user->id, true); } else { message_contact_link($user->id, 'remove', false, 'user.php?id=' . $user->id, true); message_contact_link($user->id, 'block', false, 'user.php?id=' . $user->id, true); } } else { message_contact_link($user->id, 'add', false, 'user.php?id=' . $user->id, true); message_contact_link($user->id, 'block', false, 'user.php?id=' . $user->id, true); } message_history_link($user->id, 0, false, '', '', 'both'); echo '</div>'; echo '</td></tr></table>'; echo $OUTPUT->footer();
/** * Print a row of contactlist displaying user picture, messages waiting and * block links etc * * @param object $contact contact object containing all fields required for $OUTPUT->user_picture() * @param bool $incontactlist is the user a contact of ours? * @param bool $isblocked is the user blocked? * @param string $selectcontacturl the url to send the user to when a contact's name is clicked * @param bool $showactionlinks display action links next to the other users (add contact, block user etc) * @param object $selecteduser the user the current user is viewing (if any). They will be highlighted. * @return void */ function message_print_contactlist_user($contact, $incontactlist = true, $isblocked = false, $selectcontacturl = null, $showactionlinks = true, $selecteduser = null) { global $OUTPUT, $USER, $COURSE; $fullname = fullname($contact); $fullnamelink = $fullname; $output = ''; $linkclass = ''; if (!empty($selecteduser) && $contact->id == $selecteduser->id) { $linkclass = 'messageselecteduser'; } // Are there any unread messages for this contact? if ($contact->messagecount > 0) { $fullnamelink = '<strong>' . $fullnamelink . ' (' . $contact->messagecount . ')</strong>'; } $strcontact = $strblock = $strhistory = null; if ($showactionlinks) { // Show block and delete links if user is real user. if (core_user::is_real_user($contact->id)) { $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'); } $output .= html_writer::start_tag('div', array('class' => 'pix')); $output .= $OUTPUT->user_picture($contact, array('size' => 20, 'courseid' => $COURSE->id)); $output .= html_writer::end_tag('div'); $popupoptions = array('height' => MESSAGE_DISCUSSION_HEIGHT, 'width' => MESSAGE_DISCUSSION_WIDTH, 'menubar' => false, 'location' => false, 'status' => true, 'scrollbars' => true, 'resizable' => true); $link = $action = null; if (!empty($selectcontacturl)) { $link = new moodle_url($selectcontacturl . '&user2=' . $contact->id); } else { //can $selectcontacturl be removed and maybe the be removed and hardcoded? $link = new moodle_url("/message/index.php?id={$contact->id}"); $action = new popup_action('click', $link, "message_{$contact->id}", $popupoptions); } if (strlen($strcontact . $strblock . $strhistory) > 0) { $output .= html_writer::tag('div', $strcontact . $strblock . $strhistory, array('class' => 'link')); $output .= html_writer::start_tag('div', array('class' => 'contact')); $linkattr = array('class' => $linkclass, 'title' => get_string('sendmessageto', 'message', $fullname)); $output .= $OUTPUT->action_link($link, $fullnamelink, $action, $linkattr); $output .= html_writer::end_tag('div'); } else { $output .= html_writer::start_tag('div', array('class' => 'contact nolinks')); $linkattr = array('class' => $linkclass, 'title' => get_string('sendmessageto', 'message', $fullname)); $output .= $OUTPUT->action_link($link, $fullnamelink, $action, $linkattr); $output .= html_writer::end_tag('div'); } return $output; }
/** * Print a row of contactlist displaying user picture, messages waiting and * block links etc * @param $contact contact object containing all fields required for print_user_picture() * @param $incontactlist is the user a contact of ours? */ function message_print_contactlist_user($contact, $incontactlist = true) { $fullname = fullname($contact); $fullnamelink = $fullname; /// are there any unread messages for this contact? if ($contact->messagecount > 0) { $fullnamelink = '<strong>' . $fullnamelink . ' (' . $contact->messagecount . ')</strong>'; } if ($incontactlist) { $strcontact = message_contact_link($contact->id, 'remove', true); $strblock = ''; } else { $strcontact = message_contact_link($contact->id, 'add', true); $strblock = ' ' . message_contact_link($contact->id, 'block', true); } $strhistory = message_history_link($contact->id, 0, true, '', '', 'icon'); echo '<tr><td class="pix">'; print_user_picture($contact, SITEID, $contact->picture, 20, false, true, 'userwindow'); echo '</td>'; echo '<td class="contact">'; link_to_popup_window("/message/discussion.php?id={$contact->id}", "message_{$contact->id}", $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname), 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500'); echo '</td>'; echo '<td class="link"> ' . $strcontact . $strblock . ' ' . $strhistory . '</td>'; echo '</tr>'; }
function message_print_search_results($frm) { global $USER, $CFG; echo '<div align="center">'; /// search for person if (!empty($frm->personsubmit) and !empty($frm->name)) { if (optional_param('mycourses', 0, PARAM_BOOL)) { $users = array(); $mycourses = get_my_courses($USER->id); foreach ($mycourses as $mycourse) { if (is_array($susers = message_search_users($mycourse->id, $frm->name))) { foreach ($susers as $suser) { $users[$suser->id] = $suser; } } } } else { $users = message_search_users(SITEID, $frm->name); } if (!empty($users)) { echo '<strong>' . get_string('userssearchresults', 'message', count($users)) . '</strong>'; echo '<table class="message_users">'; foreach ($users as $user) { if (($contact = message_get_contact($user->id)) !== false) { if ($contact->blocked == 0) { /// not blocked $strcontact = message_contact_link($user->id, 'remove', true); $strblock = message_contact_link($user->id, 'block', true); } else { // blocked $strcontact = message_contact_link($user->id, 'add', true); $strblock = message_contact_link($user->id, 'unblock', true); } } else { $strcontact = message_contact_link($user->id, 'add', true); $strblock = message_contact_link($user->id, 'block', true); } $strhistory = message_history_link($user->id, 0, true, '', '', 'icon'); echo '<tr><td class="pix">'; print_user_picture($user->id, SITEID, $user->picture, 20, false, true, 'userwindow'); echo '</td>'; echo '<td class="contact">'; link_to_popup_window("/message/discussion.php?id={$user->id}", "message_{$user->id}", fullname($user), 500, 500, get_string('sendmessageto', 'message', fullname($user)), 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500'); echo '</td>'; echo '<td class="link">' . $strcontact . '</td>'; echo '<td class="link">' . $strblock . '</td>'; echo '<td class="link">' . $strhistory . '</td>'; echo '</tr>'; } echo '</table>'; } else { notify(get_string('nosearchresults', 'message')); } /// search messages for keywords } else { if (!empty($frm->keywordssubmit) and !empty($frm->keywords)) { $keywordstring = clean_text(trim($frm->keywords)); $keywords = explode(' ', $keywordstring); $tome = false; $fromme = false; $courseid = 'none'; 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) { /// get a list of contacts if (($contacts = get_records('message_contacts', 'userid', $USER->id, '', 'contactid, blocked')) === false) { $contacts = array(); } /// print heading with number of results echo '<p class="heading">' . get_string('keywordssearchresults', 'message', count($messages)) . ' ("' . s($keywordstring) . '")</p>'; /// print table headings echo '<table class="searchresults" cellspacing="0">'; echo '<tr>'; echo '<td><strong>' . get_string('from') . '</strong></td>'; echo '<td><strong>' . get_string('to') . '</strong></td>'; echo '<td><strong>' . get_string('message', 'message') . '</strong></td>'; echo '<td><strong>' . get_string('timesent', 'message') . '</strong></td>'; echo "</tr>\n"; $blockedcount = 0; $dateformat = get_string('strftimedatetime'); $strcontext = get_string('context', 'message'); foreach ($messages as $message) { /// ignore messages to and from blocked users unless $frm->includeblocked is set if (!optional_param('includeblocked', 0, PARAM_BOOL) and (isset($contacts[$message->useridfrom]) and $contacts[$message->useridfrom]->blocked == 1 or isset($contacts[$message->useridto]) and $contacts[$message->useridto]->blocked == 1)) { $blockedcount++; continue; } /// load up user to record if ($message->useridto !== $USER->id) { $userto = get_record('user', 'id', $message->useridto); $tocontact = (array_key_exists($message->useridto, $contacts) and $contacts[$message->useridto]->blocked == 0); $toblocked = (array_key_exists($message->useridto, $contacts) and $contacts[$message->useridto]->blocked == 1); } else { $userto = false; $tocontact = false; $toblocked = false; } /// load up user from record if ($message->useridfrom !== $USER->id) { $userfrom = get_record('user', 'id', $message->useridfrom); $fromcontact = (array_key_exists($message->useridfrom, $contacts) and $contacts[$message->useridfrom]->blocked == 0); $fromblocked = (array_key_exists($message->useridfrom, $contacts) and $contacts[$message->useridfrom]->blocked == 1); } else { $userfrom = false; $fromcontact = false; $fromblocked = false; } /// find date string for this message $date = usergetdate($message->timecreated); $datestring = $date['year'] . $date['mon'] . $date['mday']; /// print out message row echo '<tr valign="top">'; echo '<td class="contact">'; message_print_user($userfrom, $fromcontact, $fromblocked); echo '</td>'; echo '<td class="contact">'; message_print_user($userto, $tocontact, $toblocked); echo '</td>'; echo '<td class="summary">' . message_get_fragment($message->message, $keywords); echo '<br /><div class="link">'; message_history_link($message->useridto, $message->useridfrom, false, $keywordstring, 'm' . $message->id, $strcontext); echo '</div>'; echo '</td>'; echo '<td class="date">' . userdate($message->timecreated, $dateformat) . '</td>'; echo "</tr>\n"; } if ($blockedcount > 0) { echo '<tr><td colspan="4" align="center">' . get_string('blockedmessages', 'message', $blockedcount) . '</td></tr>'; } echo '</table>'; } else { notify(get_string('nosearchresults', 'message')); } /// what the ????, probably an empty search string, duh! } else { notify(get_string('emptysearchstring', 'message')); } } echo '<br />'; print_single_button('index.php', array('tab' => 'search'), get_string('newsearch', 'message')); echo '</div>'; }
/** * Print a row of contactlist displaying user picture, messages waiting and * block links etc * @param $contact contact object containing all fields required for $OUTPUT->user_picture() * @param $incontactlist is the user a contact of ours? */ function message_print_contactlist_user($contact, $incontactlist = true) { global $OUTPUT; $fullname = fullname($contact); $fullnamelink = $fullname; /// are there any unread messages for this contact? if ($contact->messagecount > 0) { $fullnamelink = '<strong>' . $fullnamelink . ' (' . $contact->messagecount . ')</strong>'; } if ($incontactlist) { $strcontact = message_contact_link($contact->id, 'remove', true); $strblock = ''; } else { $strcontact = message_contact_link($contact->id, 'add', true); $strblock = ' ' . message_contact_link($contact->id, 'block', true); } $strhistory = message_history_link($contact->id, 0, true, '', '', 'icon'); echo '<tr><td class="pix">'; $userpic = moodle_user_picture::make($contact, SITEID); $userpic->size = 20; $userpic->link = true; echo $OUTPUT->user_picture($userpic); echo '</td>'; echo '<td class="contact">'; $popupoptions = array('height' => 500, 'width' => 500, 'menubar' => false, 'location' => false, 'status' => true, 'scrollbars' => true, 'resizable' => true); $link = html_link::make("/message/discussion.php?id={$contact->id}", $fullnamelink); $link->add_action(new popup_action('click', $link->url, "message_{$contact->id}", $popupoptions)); $link->title = get_string('sendmessageto', 'message', $fullname); echo $OUTPUT->link($link); echo '</td>'; echo '<td class="link"> ' . $strcontact . $strblock . ' ' . $strhistory . '</td>'; echo '</tr>'; }