MDL-10910 Corrected two errors committed while fixing MDL-10870
[moodle-pu.git] / mod / chat / view.php
blob99d4d26b5ca646a8fff95c645be05bba0c07574b
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 if (!empty($THEME->customcorners)) {
11 require_once($CFG->dirroot.'/lib/custom_corners_lib.php');
14 $id = optional_param('id', 0, PARAM_INT);
15 $c = optional_param('c', 0, PARAM_INT);
16 $edit = optional_param('edit', -1, PARAM_BOOL);
18 if ($id) {
19 if (! $cm = get_coursemodule_from_id('chat', $id)) {
20 error('Course Module ID was incorrect');
23 if (! $course = get_record('course', 'id', $cm->course)) {
24 error('Course is misconfigured');
27 chat_update_chat_times($cm->instance);
29 if (! $chat = get_record('chat', 'id', $cm->instance)) {
30 error('Course module is incorrect');
33 } else {
34 chat_update_chat_times($c);
36 if (! $chat = get_record('chat', 'id', $c)) {
37 error('Course module is incorrect');
39 if (! $course = get_record('course', 'id', $chat->course)) {
40 error('Course is misconfigured');
42 if (! $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
43 error('Course Module ID was incorrect');
48 require_course_login($course, true, $cm);
50 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
52 add_to_log($course->id, 'chat', 'view', "view.php?id=$cm->id", $chat->id, $cm->id);
54 // Initialize $PAGE, compute blocks
56 $PAGE = page_create_instance($chat->id);
57 $pageblocks = blocks_setup($PAGE);
58 $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
60 /// Print the page header
62 $strenterchat = get_string('enterchat', 'chat');
63 $stridle = get_string('idle', 'chat');
64 $strcurrentusers = get_string('currentusers', 'chat');
65 $strnextsession = get_string('nextsession', 'chat');
67 if (($edit != -1) and $PAGE->user_allowed_editing()) {
68 $USER->editing = $edit;
71 $PAGE->print_header($course->shortname.': %fullname%');
73 echo '<table id="layout-table"><tr>';
75 if(!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
76 echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
77 if (!empty($THEME->customcorners)) print_custom_corners_start();
78 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
79 if (!empty($THEME->customcorners)) print_custom_corners_end();
80 echo '</td>';
83 echo '<td id="middle-column">';
84 if (!empty($THEME->customcorners)) print_custom_corners_start();
86 /// Check to see if groups are being used here
87 $groupmode = groupmode($course, $cm);
88 $currentgroup = setup_and_print_groups($course, $groupmode, "view.php?id=$cm->id");
90 if ($currentgroup) {
91 $groupselect = " AND groupid = '$currentgroup'";
92 $groupparam = "&amp;groupid=$currentgroup";
93 } else {
94 $groupselect = "";
95 $groupparam = "";
98 if ($chat->studentlogs or has_capability('mod/chat:readlog',$context)) {
99 echo '<div class="reportlink">';
100 echo "<a href=\"report.php?id=$cm->id\">".
101 get_string('viewreport', 'chat').'</a>';
102 echo '</div>';
106 print_heading(format_string($chat->name));
108 /// Print the main part of the page
110 if (has_capability('mod/chat:chat',$context)) {
111 print_box_start('generalbox', 'enterlink');
112 // users with screenreader set, will only see 1 link, to the manual refresh page
113 // for better accessibility
114 if (!empty($USER->screenreader)) {
115 $chattarget = "/mod/chat/gui_basic/index.php?id=$chat->id$groupparam";
116 } else {
117 $chattarget = "/mod/chat/gui_$CFG->chat_method/index.php?id=$chat->id$groupparam";
120 echo '<p>';
121 link_to_popup_window ($chattarget,
122 "chat$course->id$chat->id$groupparam", "$strenterchat", 500, 700, get_string('modulename', 'chat'));
123 echo '</p>';
125 // if user is using screen reader, then there is no need to display this link again
126 if ($CFG->chat_method == 'header_js' && empty($USER->screenreader)) {
127 // show frame/js-less alternative
128 echo '<p>(';
129 link_to_popup_window ("/mod/chat/gui_basic/index.php?id=$chat->id$groupparam",
130 "chat$course->id$chat->id$groupparam", get_string('noframesjs', 'message'), 500, 700, get_string('modulename', 'chat'));
131 echo ')</p>';
134 print_box_end();
136 } else if (isguestuser()) {
137 $wwwroot = $CFG->wwwroot.'/login/index.php';
138 if (!empty($CFG->loginhttps)) {
139 $wwwroot = str_replace('http:','https:', $wwwroot);
142 notice_yesno(get_string('noguests', 'chat').'<br /><br />'.get_string('liketologin'),
143 $wwwroot, $CFG->wwwroot.'/course/view.php?id='.$course->id);
145 print_footer($course);
146 exit;
148 } else {
149 // show some error message
150 require_capability('mod/chat:chat', $context);
154 if ($chat->chattime and $chat->schedule) { // A chat is scheduled
155 echo "<p class=\"nextchatsession\">$strnextsession: ".userdate($chat->chattime).' ('.usertimezone($USER->timezone).')</p>';
156 } else {
157 echo '<br />';
160 if ($chat->intro) {
161 print_box(format_text($chat->intro), 'generalbox', 'intro');
164 chat_delete_old_users();
166 if ($chatusers = chat_get_users($chat->id, $currentgroup)) {
167 $timenow = time();
168 print_simple_box_start('center');
169 print_heading($strcurrentusers);
170 echo '<table id="chatcurrentusers">';
171 foreach ($chatusers as $chatuser) {
172 $lastping = $timenow - $chatuser->lastmessageping;
173 echo '<tr><td class="chatuserimage">';
174 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$chat->course\">";
175 print_user_picture($chatuser->id, 0, $chatuser->picture, false, false, false);
176 echo '</a></td><td class="chatuserdetails">';
177 echo '<p>';
178 echo fullname($chatuser).'<br />';
179 echo "<span class=\"idletime\">$stridle: ".format_time($lastping)."</span>";
180 echo '</p>';
181 echo '</td></tr>';
183 echo '</table>';
184 print_simple_box_end();
188 /// Finish the page
189 if (!empty($THEME->customcorners)) print_custom_corners_end();
190 echo '</td></tr></table>';
192 print_footer($course);