adding current groupid to grade_export class - soon to be used in plugins
[moodle-pu.git] / mod / chat / view.php
blob8ad9e46a3eeac0e4e738175bc15c39cd999e3a4e
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 = groups_get_activity_groupmode($cm);
88 $currentgroup = groups_get_activity_group($cm, true);
89 groups_print_activity_menu($cm, "view.php?id=$cm->id");
91 if ($currentgroup) {
92 $groupselect = " AND groupid = '$currentgroup'";
93 $groupparam = "&amp;groupid=$currentgroup";
94 } else {
95 $groupselect = "";
96 $groupparam = "";
99 if ($chat->studentlogs or has_capability('mod/chat:readlog',$context)) {
100 echo '<div class="reportlink">';
101 echo "<a href=\"report.php?id=$cm->id\">".
102 get_string('viewreport', 'chat').'</a>';
103 echo '</div>';
107 print_heading(format_string($chat->name));
109 /// Print the main part of the page
111 if (has_capability('mod/chat:chat',$context)) {
112 print_box_start('generalbox', 'enterlink');
113 // users with screenreader set, will only see 1 link, to the manual refresh page
114 // for better accessibility
115 if (!empty($USER->screenreader)) {
116 $chattarget = "/mod/chat/gui_basic/index.php?id=$chat->id$groupparam";
117 } else {
118 $chattarget = "/mod/chat/gui_$CFG->chat_method/index.php?id=$chat->id$groupparam";
121 echo '<p>';
122 link_to_popup_window ($chattarget,
123 "chat$course->id$chat->id$groupparam", "$strenterchat", 500, 700, get_string('modulename', 'chat'));
124 echo '</p>';
126 // if user is using screen reader, then there is no need to display this link again
127 if ($CFG->chat_method == 'header_js' && empty($USER->screenreader)) {
128 // show frame/js-less alternative
129 echo '<p>(';
130 link_to_popup_window ("/mod/chat/gui_basic/index.php?id=$chat->id$groupparam",
131 "chat$course->id$chat->id$groupparam", get_string('noframesjs', 'message'), 500, 700, get_string('modulename', 'chat'));
132 echo ')</p>';
135 print_box_end();
137 } else if (isguestuser()) {
138 $wwwroot = $CFG->wwwroot.'/login/index.php';
139 if (!empty($CFG->loginhttps)) {
140 $wwwroot = str_replace('http:','https:', $wwwroot);
143 notice_yesno(get_string('noguests', 'chat').'<br /><br />'.get_string('liketologin'),
144 $wwwroot, $CFG->wwwroot.'/course/view.php?id='.$course->id);
146 print_footer($course);
147 exit;
149 } else {
150 // show some error message
151 require_capability('mod/chat:chat', $context);
155 if ($chat->chattime and $chat->schedule) { // A chat is scheduled
156 echo "<p class=\"nextchatsession\">$strnextsession: ".userdate($chat->chattime).' ('.usertimezone($USER->timezone).')</p>';
157 } else {
158 echo '<br />';
161 if ($chat->intro) {
162 print_box(format_text($chat->intro), 'generalbox', 'intro');
165 chat_delete_old_users();
167 if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) {
168 $timenow = time();
169 print_simple_box_start('center');
170 print_heading($strcurrentusers);
171 echo '<table id="chatcurrentusers">';
172 foreach ($chatusers as $chatuser) {
173 $lastping = $timenow - $chatuser->lastmessageping;
174 echo '<tr><td class="chatuserimage">';
175 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$chat->course\">";
176 print_user_picture($chatuser->id, 0, $chatuser->picture, false, false, false);
177 echo '</a></td><td class="chatuserdetails">';
178 echo '<p>';
179 echo fullname($chatuser).'<br />';
180 echo "<span class=\"idletime\">$stridle: ".format_time($lastping)."</span>";
181 echo '</p>';
182 echo '</td></tr>';
184 echo '</table>';
185 print_simple_box_end();
189 /// Finish the page
190 if (!empty($THEME->customcorners)) print_custom_corners_end();
191 echo '</td></tr></table>';
193 print_footer($course);