MDL-16221
[moodle-linuxchix.git] / mod / chat / view.php
blob9637f60366210cd4d8158af6d4b3aa5bb5654b0c
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;
64 } else {
65 require_capability('mod/chat:chat', $context);
68 add_to_log($course->id, 'chat', 'view', "view.php?id=$cm->id", $chat->id, $cm->id);
70 // Initialize $PAGE, compute blocks
72 $PAGE = page_create_instance($chat->id);
73 $pageblocks = blocks_setup($PAGE);
74 $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
76 /// Print the page header
78 $strenterchat = get_string('enterchat', 'chat');
79 $stridle = get_string('idle', 'chat');
80 $strcurrentusers = get_string('currentusers', 'chat');
81 $strnextsession = get_string('nextsession', 'chat');
83 if (($edit != -1) and $PAGE->user_allowed_editing()) {
84 $USER->editing = $edit;
87 $PAGE->print_header($course->shortname.': %fullname%');
89 echo '<table id="layout-table"><tr>';
91 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
92 foreach ($lt as $column) {
93 switch ($column) {
94 case 'left':
96 if(!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
97 echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
98 print_container_start();
99 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
100 print_container_end();
101 echo '</td>';
103 break;
105 case 'middle':
107 echo '<td id="middle-column">';
108 print_container_start();
110 /// Check to see if groups are being used here
111 $groupmode = groups_get_activity_groupmode($cm);
112 $currentgroup = groups_get_activity_group($cm, true);
113 groups_print_activity_menu($cm, "view.php?id=$cm->id");
115 if ($currentgroup) {
116 $groupselect = " AND groupid = '$currentgroup'";
117 $groupparam = "&amp;groupid=$currentgroup";
118 } else {
119 $groupselect = "";
120 $groupparam = "";
123 if ($chat->studentlogs or has_capability('mod/chat:readlog',$context)) {
124 echo '<div class="reportlink">';
125 echo "<a href=\"report.php?id=$cm->id\">".
126 get_string('viewreport', 'chat').'</a>';
127 echo '</div>';
131 print_heading(format_string($chat->name));
133 /// Print the main part of the page
134 print_box_start('generalbox', 'enterlink');
135 // users with screenreader set, will only see 1 link, to the manual refresh page
136 // for better accessibility
137 if (!empty($USER->screenreader)) {
138 $chattarget = "/mod/chat/gui_basic/index.php?id=$chat->id$groupparam";
139 } else {
140 $chattarget = "/mod/chat/gui_$CFG->chat_method/index.php?id=$chat->id$groupparam";
143 echo '<p>';
144 link_to_popup_window ($chattarget,
145 "chat$course->id$chat->id$groupparam", "$strenterchat", 500, 700, get_string('modulename', 'chat'));
146 echo '</p>';
148 // if user is using screen reader, then there is no need to display this link again
149 if ($CFG->chat_method == 'header_js' && empty($USER->screenreader)) {
150 // show frame/js-less alternative
151 echo '<p>(';
152 link_to_popup_window ("/mod/chat/gui_basic/index.php?id=$chat->id$groupparam",
153 "chat$course->id$chat->id$groupparam", get_string('noframesjs', 'message'), 500, 700, get_string('modulename', 'chat'));
154 echo ')</p>';
157 print_box_end();
160 if ($chat->chattime and $chat->schedule) { // A chat is scheduled
161 echo "<p class=\"nextchatsession\">$strnextsession: ".userdate($chat->chattime).' ('.usertimezone($USER->timezone).')</p>';
162 } else {
163 echo '<br />';
166 if ($chat->intro) {
167 print_box(format_text($chat->intro), 'generalbox', 'intro');
170 chat_delete_old_users();
172 if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) {
173 $timenow = time();
174 print_simple_box_start('center');
175 print_heading($strcurrentusers);
176 echo '<table id="chatcurrentusers">';
177 foreach ($chatusers as $chatuser) {
178 $lastping = $timenow - $chatuser->lastmessageping;
179 echo '<tr><td class="chatuserimage">';
180 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$chat->course\">";
181 print_user_picture($chatuser, 0, $chatuser->picture, false, false, false);
182 echo '</a></td><td class="chatuserdetails">';
183 echo '<p>';
184 echo fullname($chatuser).'<br />';
185 echo "<span class=\"idletime\">$stridle: ".format_time($lastping)."</span>";
186 echo '</p>';
187 echo '</td></tr>';
189 echo '</table>';
190 print_simple_box_end();
193 print_container_end();
194 echo '</td>';
196 break;
200 echo '</tr></table>';
202 print_footer($course);