MDL-14967 DB upgrades. Not finished yet.
[moodle.git] / blocks / messages / block_messages.php
CommitLineData
bc8ccf6b 1<?PHP //$Id$
2
3class block_messages extends block_base {
4 function init() {
5 $this->title = get_string('messages','message');
433c242f 6 $this->version = 2007101509;
bc8ccf6b 7 }
8
9 function get_content() {
10 global $USER, $CFG;
11
094d92a4 12 if (!$CFG->messaging) {
13 return '';
14 }
15
bc8ccf6b 16 if ($this->content !== NULL) {
17 return $this->content;
18 }
19
20 $this->content = new stdClass;
21 $this->content->text = '';
b603ccb7 22 $this->content->footer = '';
bc8ccf6b 23
cdf39255 24 if (empty($this->instance) or empty($USER->id) or isguest() or empty($CFG->messaging)) {
bc8ccf6b 25 return $this->content;
26 }
27
80381122 28 $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 29
30 $users = get_records_sql("SELECT m.useridfrom as id, COUNT(m.useridfrom) as count,
65bcf17b 31 u.firstname, u.lastname, u.picture, u.imagealt, u.lastaccess
bc8ccf6b 32 FROM {$CFG->prefix}user u,
33 {$CFG->prefix}message m
34 WHERE m.useridto = '$USER->id'
35 AND u.id = m.useridfrom
2b0689c9 36 GROUP BY m.useridfrom, u.firstname,u.lastname,u.picture,u.lastaccess,u.imagealt");
bc8ccf6b 37
38
39 //Now, we have in users, the list of users to show
40 //Because they are online
41 if (!empty($users)) {
80381122 42 $this->content->text .= '<ul class="list">';
bc8ccf6b 43 foreach ($users as $user) {
3cebccea 44 $timeago = format_time(time() - $user->lastaccess);
440d1648 45 $this->content->text .= '<li class="listentry"><div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->instance->pageid.'" title="'.$timeago.'">';
65bcf17b 46 $this->content->text .= print_user_picture($user, $this->instance->pageid, $user->picture, 0, true, false, '', false);
440d1648 47 $this->content->text .= fullname($user).'</a></div>';
48 $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="'.$CFG->pixpath.'/t/message.gif" alt="" />&nbsp;'.$user->count.'</a>';
49 $this->content->text .= '</div></li>';
bc8ccf6b 50 }
80381122 51 $this->content->text .= '</ul>';
bc8ccf6b 52 } else {
440d1648 53 $this->content->text .= '<div class="info">';
80381122 54 $this->content->text .= get_string('nomessages', 'message');
55 $this->content->text .= '</div>';
bc8ccf6b 56 }
57
58 return $this->content;
59 }
60}
61
62?>