Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / blocks / messages / block_messages.php
blob3d211854155227dfcb9e8949dfc3d63e5a07d0d0
1 <?PHP //$Id$
3 class block_messages extends block_base {
4 function init() {
5 $this->title = get_string('messages','message');
6 $this->version = 2004122800;
9 function get_content() {
10 global $USER, $CFG;
12 if ($this->content !== NULL) {
13 return $this->content;
16 $this->content = new stdClass;
17 $this->content->text = '';
18 $this->content->footer = '';
20 if (empty($this->instance) or empty($USER->id) or isguest() or empty($CFG->messaging)) {
21 return $this->content;
24 $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>...';
26 $users = get_records_sql("SELECT m.useridfrom as id, COUNT(m.useridfrom) as count,
27 u.firstname, u.lastname, u.picture, u.lastaccess
28 FROM {$CFG->prefix}user u,
29 {$CFG->prefix}message m
30 WHERE m.useridto = '$USER->id'
31 AND u.id = m.useridfrom
32 GROUP BY m.useridfrom, u.firstname,u.lastname,u.picture,u.lastaccess");
35 //Now, we have in users, the list of users to show
36 //Because they are online
37 if (!empty($users)) {
38 $this->content->text .= '<ul class="list">';
39 foreach ($users as $user) {
40 $timeago = format_time(time() - $user->lastaccess);
41 $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.'">';
42 $this->content->text .= print_user_picture($user->id, $this->instance->pageid, $user->picture, 0, true, false, '', false);
43 $this->content->text .= fullname($user).'</a></div>';
44 $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>';
45 $this->content->text .= '</div></li>';
47 $this->content->text .= '</ul>';
48 } else {
49 $this->content->text .= '<div class="info">';
50 $this->content->text .= get_string('nomessages', 'message');
51 $this->content->text .= '</div>';
54 return $this->content;