MDL-16106 report - fix old double-column trick causing problems in backup logs. Thank...
[moodle.git] / mod / chat / view.php
blob5fb345bbaeb69d22aea0de3b215bcb37bf176a1a
1 <?php // $Id$
3 /// This page prints a particular instance of chat
5 require_once('../../config.php');
6 require_once('lib.php');
7 require_once($CFG->libdir.'/blocklib.php');
8 require_once('pagelib.php');
10 $id = optional_param('id', 0, PARAM_INT);
11 $c = optional_param('c', 0, PARAM_INT);
12 $edit = optional_param('edit', -1, PARAM_BOOL);
14 if ($id) {
15 if (! $cm = get_coursemodule_from_id('chat', $id)) {
16 error('Course Module ID was incorrect');
19 if (! $course = get_record('course', 'id', $cm->course)) {
20 error('Course is misconfigured');
23 chat_update_chat_times($cm->instance);
25 if (! $chat = get_record('chat', 'id', $cm->instance)) {
26 error('Course module is incorrect');
29 } else {
30 chat_update_chat_times($c);
32 if (! $chat = get_record('chat', 'id', $c)) {
33 error('Course module is incorrect');
35 if (! $course = get_record('course', 'id', $chat->course)) {
36 error('Course is misconfigured');
38 if (! $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
39 error('Course Module ID was incorrect');
44 require_course_login($course, true, $cm);
46 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
48 // show some info for guests
49 if (isguestuser()) {
50 $navigation = build_navigation('', $cm);
51 print_header_simple(format_string($chat->name), '', $navigation,
52 '', '', true, '', navmenu($course, $cm));
53 $wwwroot = $CFG->wwwroot.'/login/index.php';
54 if (!empty($CFG->loginhttps)) {
55 $wwwroot = str_replace('http:','https:', $wwwroot);
58 notice_yesno(get_string('noguests', 'chat').'<br /><br />'.get_string('liketologin'),
59 $wwwroot, $CFG->wwwroot.'/course/view.php?id='.$course->id);
61 print_footer($course);
62 exit;
66 add_to_log($course->id, 'chat', 'view', "view.php?id=$cm->id", $chat->id, $cm->id);
68 // Initialize $PAGE, compute blocks
70 $PAGE = page_create_instance($chat->id);
71 $pageblocks = blocks_setup($PAGE);
72 $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
74 /// Print the page header
76 $strenterchat = get_string('enterchat', 'chat');
77 $stridle = get_string('idle', 'chat');
78 $strcurrentusers = get_string('currentusers', 'chat');
79 $strnextsession = get_string('nextsession', 'chat');
81 if (($edit != -1) and $PAGE->user_allowed_editing()) {
82 $USER->editing = $edit;
85 $PAGE->print_header($course->shortname.': %fullname%');
87 echo '<table id="layout-table"><tr>';
89 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
90 foreach ($lt as $column) {
91 switch ($column) {
92 case 'left':
94 if(!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
95 echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
96 print_container_start();
97 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
98 print_container_end();
99 echo '</td>';
101 break;
103 case 'middle':
105 echo '<td id="middle-column">';
106 print_container_start();
108 /// Check to see if groups are being used here
109 $groupmode = groups_get_activity_groupmode($cm);
110 $currentgroup = groups_get_activity_group($cm, true);
111 groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/view.php?id=$cm->id");
113 if ($currentgroup) {
114 $groupselect = " AND groupid = '$currentgroup'";
115 $groupparam = "&amp;groupid=$currentgroup";
116 } else {
117 $groupselect = "";
118 $groupparam = "";
121 if ($chat->studentlogs or has_capability('mod/chat:readlog',$context)) {
122 if ($msg = get_records_select('chat_messages', "chatid = '$chat->id' $groupselect", '', 'id', '', 1)) {
123 echo '<div class="reportlink">';
124 echo "<a href=\"report.php?id=$cm->id\">".
125 get_string('viewreport', 'chat').'</a>';
126 echo '</div>';
131 print_heading(format_string($chat->name));
133 if (has_capability('mod/chat:chat',$context)) {
134 /// Print the main part of the page
135 print_box_start('generalbox', 'enterlink');
136 // users with screenreader set, will only see 1 link, to the manual refresh page
137 // for better accessibility
138 if (!empty($USER->screenreader)) {
139 $chattarget = "/mod/chat/gui_basic/index.php?id=$chat->id$groupparam";
140 } else {
141 $chattarget = "/mod/chat/gui_$CFG->chat_method/index.php?id=$chat->id$groupparam";
144 echo '<p>';
145 link_to_popup_window ($chattarget,
146 "chat$course->id$chat->id$groupparam", "$strenterchat", 500, 700, get_string('modulename', 'chat'));
147 echo '</p>';
149 // if user is using screen reader, then there is no need to display this link again
150 if ($CFG->chat_method == 'header_js' && empty($USER->screenreader)) {
151 // show frame/js-less alternative
152 echo '<p>(';
153 link_to_popup_window ("/mod/chat/gui_basic/index.php?id=$chat->id$groupparam",
154 "chat$course->id$chat->id$groupparam", get_string('noframesjs', 'message'), 500, 700, get_string('modulename', 'chat'));
155 echo ')</p>';
158 print_box_end();
160 } else {
161 print_box_start('generalbox', 'notallowenter');
162 echo '<p>'.get_string('notallowenter', 'chat').'</p>';
163 print_box_end();
166 if ($chat->chattime and $chat->schedule) { // A chat is scheduled
167 echo "<p class=\"nextchatsession\">$strnextsession: ".userdate($chat->chattime).' ('.usertimezone($USER->timezone).')</p>';
168 } else {
169 echo '<br />';
172 if ($chat->intro) {
173 print_box(format_text($chat->intro), 'generalbox', 'intro');
176 chat_delete_old_users();
178 if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) {
179 $timenow = time();
180 print_simple_box_start('center');
181 print_heading($strcurrentusers);
182 echo '<table id="chatcurrentusers">';
183 foreach ($chatusers as $chatuser) {
184 $lastping = $timenow - $chatuser->lastmessageping;
185 echo '<tr><td class="chatuserimage">';
186 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$chat->course\">";
187 print_user_picture($chatuser, 0, $chatuser->picture, false, false, false);
188 echo '</a></td><td class="chatuserdetails">';
189 echo '<p>';
190 echo fullname($chatuser).'<br />';
191 echo "<span class=\"idletime\">$stridle: ".format_time($lastping)."</span>";
192 echo '</p>';
193 echo '</td></tr>';
195 echo '</table>';
196 print_simple_box_end();
199 print_container_end();
200 echo '</td>';
202 break;
206 echo '</tr></table>';
208 print_footer($course);