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
);
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');
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();
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");
91 $groupselect = " AND groupid = '$currentgroup'";
92 $groupparam = "&groupid=$currentgroup";
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>';
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";
117 $chattarget = "/mod/chat/gui_$CFG->chat_method/index.php?id=$chat->id$groupparam";
120 link_to_popup_window ($chattarget,
121 "chat$course->id$chat->id$groupparam", "<p>$strenterchat</p>", 500, 700, get_string('modulename', 'chat'));
123 // if user is using screen reader, then there is no need to display this link again
124 if ($CFG->chat_method
== 'header_js' && empty($USER->screenreader
)) {
125 // show frame/js-less alternative
126 link_to_popup_window ("/mod/chat/gui_basic/index.php?id=$chat->id$groupparam",
127 "chat$course->id$chat->id$groupparam", '<p>('.get_string('noframesjs', 'message').')</p>', 500, 700, get_string('modulename', 'chat'));
132 } else if (isguestuser()) {
133 $wwwroot = $CFG->wwwroot
.'/login/index.php';
134 if (!empty($CFG->loginhttps
)) {
135 $wwwroot = str_replace('http:','https:', $wwwroot);
138 notice_yesno(get_string('noguests', 'chat').'<br /><br />'.get_string('liketologin'),
139 $wwwroot, $CFG->wwwroot
.'/course/view.php?id='.$course->id
);
141 print_footer($course);
145 // show some error message
146 require_capability('mod/chat:chat', $context);
150 if ($chat->chattime
and $chat->schedule
) { // A chat is scheduled
151 echo "<p class=\"nextchatsession\">$strnextsession: ".userdate($chat->chattime
).' ('.usertimezone($USER->timezone
).')</p>';
157 print_box(format_text($chat->intro
), 'generalbox', 'intro');
160 chat_delete_old_users();
162 if ($chatusers = chat_get_users($chat->id
, $currentgroup)) {
164 print_simple_box_start('center');
165 print_heading($strcurrentusers);
166 echo '<table id="chatcurrentusers">';
167 foreach ($chatusers as $chatuser) {
168 $lastping = $timenow - $chatuser->lastmessageping
;
169 echo '<tr><td class="chatuserimage">';
170 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&course=$chat->course\">";
171 print_user_picture($chatuser->id
, 0, $chatuser->picture
, false, false, false);
172 echo '</a></td><td class="chatuserdetails">';
174 echo fullname($chatuser).'<br />';
175 echo "<span class=\"idletime\">$stridle: ".format_time($lastping)."</span>";
180 print_simple_box_end();
185 if (!empty($THEME->customcorners
)) print_custom_corners_end();
186 echo '</td></tr></table>';
188 print_footer($course);