MDL-22054 startinging blocks to pluginname
[moodle.git] / blocks / messages / block_messages.php
CommitLineData
4ca6cfbf 1<?php
bc8ccf6b 2
3class block_messages extends block_base {
4 function init() {
ef1e4c21 5 $this->title = get_string('pluginname', 'block_messages');
433c242f 6 $this->version = 2007101509;
bc8ccf6b 7 }
8
9 function get_content() {
6b608f8f 10 global $USER, $CFG, $DB, $OUTPUT;
bc8ccf6b 11
094d92a4 12 if (!$CFG->messaging) {
b58961ac 13 $this->content->text = '';
14 if ($this->page->user_is_editing()) {
15 $this->content->text = get_string('disabled', 'message');
16 }
4ca6cfbf 17 return $this->content;
094d92a4 18 }
19
bc8ccf6b 20 if ($this->content !== NULL) {
21 return $this->content;
22 }
23
24 $this->content = new stdClass;
25 $this->content->text = '';
b603ccb7 26 $this->content->footer = '';
3179b000 27
4f0c2d00 28 if (empty($this->instance) or !isloggedin() or isguestuser() or empty($CFG->messaging)) {
bc8ccf6b 29 return $this->content;
30 }
31
80381122 32 $this->content->footer = '<a href="'.$CFG->wwwroot.'/message/index.php" onclick="this.target=\'message\'; return openpopup(\'/message/index.php\', \'message\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);">'.get_string('messages', 'message').'</a>...';
bc8ccf6b 33
f28f2d90 34 $users = $DB->get_records_sql("SELECT m.useridfrom AS id, COUNT(m.useridfrom) AS count,
35 u.firstname, u.lastname, u.picture, u.imagealt, u.lastaccess
4ca6cfbf 36 FROM {user} u, {message} m
f28f2d90 37 WHERE m.useridto = ? AND u.id = m.useridfrom
38 GROUP BY m.useridfrom, u.firstname,u.lastname,u.picture,u.lastaccess,u.imagealt", array($USER->id));
bc8ccf6b 39
40
41 //Now, we have in users, the list of users to show
42 //Because they are online
43 if (!empty($users)) {
80381122 44 $this->content->text .= '<ul class="list">';
bc8ccf6b 45 foreach ($users as $user) {
3cebccea 46 $timeago = format_time(time() - $user->lastaccess);
8a083dc7 47 $this->content->text .= '<li class="listentry"><div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.SITEID.'" title="'.$timeago.'">';
812dbaf7 48 $this->content->text .= $OUTPUT->user_picture($user, array('courseid'=>SITEID)); //TODO: user might not have capability to view frontpage profile :-(
440d1648 49 $this->content->text .= fullname($user).'</a></div>';
b5d0cafc 50 $this->content->text .= '<div class="message"><a href="'.$CFG->wwwroot.'/message/discussion.php?id='.$user->id.'" onclick="this.target=\'message_'.$user->id.'\'; return openpopup(\'/message/discussion.php?id='.$user->id.'\', \'message_'.$user->id.'\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);"><img class="iconsmall" src="'.$OUTPUT->pix_url('t/message') . '" alt="" />&nbsp;'.$user->count.'</a>';
440d1648 51 $this->content->text .= '</div></li>';
bc8ccf6b 52 }
4ca6cfbf 53 $this->content->text .= '</ul>';
bc8ccf6b 54 } else {
440d1648 55 $this->content->text .= '<div class="info">';
80381122 56 $this->content->text .= get_string('nomessages', 'message');
4ca6cfbf 57 $this->content->text .= '</div>';
bc8ccf6b 58 }
59
60 return $this->content;
61 }
62}
63
4ca6cfbf 64