Updated the HEAD build version to 20091015
[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() {
6b608f8f 10 global $USER, $CFG, $DB, $OUTPUT;
bc8ccf6b 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 = '';
3179b000 23
4cdb8d70 24 if (empty($this->instance) or empty($USER->id) or isguestuser() 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
f28f2d90 30 $users = $DB->get_records_sql("SELECT m.useridfrom AS id, COUNT(m.useridfrom) AS count,
31 u.firstname, u.lastname, u.picture, u.imagealt, u.lastaccess
32 FROM {user} u, {message} m
33 WHERE m.useridto = ? AND u.id = m.useridfrom
34 GROUP BY m.useridfrom, u.firstname,u.lastname,u.picture,u.lastaccess,u.imagealt", array($USER->id));
bc8ccf6b 35
36
37 //Now, we have in users, the list of users to show
38 //Because they are online
39 if (!empty($users)) {
80381122 40 $this->content->text .= '<ul class="list">';
bc8ccf6b 41 foreach ($users as $user) {
3cebccea 42 $timeago = format_time(time() - $user->lastaccess);
8a083dc7 43 $this->content->text .= '<li class="listentry"><div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.SITEID.'" title="'.$timeago.'">';
cda9c83d 44 $this->content->text .= $OUTPUT->user_picture(moodle_user_picture::make($user, SITEID));
440d1648 45 $this->content->text .= fullname($user).'</a></div>';
6b608f8f 46 $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->old_icon_url('t/message') . '" alt="" />&nbsp;'.$user->count.'</a>';
440d1648 47 $this->content->text .= '</div></li>';
bc8ccf6b 48 }
80381122 49 $this->content->text .= '</ul>';
bc8ccf6b 50 } else {
440d1648 51 $this->content->text .= '<div class="info">';
80381122 52 $this->content->text .= get_string('nomessages', 'message');
53 $this->content->text .= '</div>';
bc8ccf6b 54 }
55
56 return $this->content;
57 }
58}
59
60?>