Merge branch 'MDL-26435_rem_commented_out_code' of git://github.com/andyjdavis/moodle
[moodle.git] / mod / chat / view.php
blob1033edcf298fe1636e1143a79569fe7afc5f6f08
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /// This page prints a particular instance of chat
20 require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
21 require_once($CFG->dirroot . '/mod/chat/lib.php');
22 require_once($CFG->libdir . '/completionlib.php');
24 $id = optional_param('id', 0, PARAM_INT);
25 $c = optional_param('c', 0, PARAM_INT);
26 $edit = optional_param('edit', -1, PARAM_BOOL);
28 if ($id) {
29 if (! $cm = get_coursemodule_from_id('chat', $id)) {
30 print_error('invalidcoursemodule');
33 if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
34 print_error('coursemisconf');
37 chat_update_chat_times($cm->instance);
39 if (! $chat = $DB->get_record('chat', array('id'=>$cm->instance))) {
40 print_error('invalidid', 'chat');
43 } else {
44 chat_update_chat_times($c);
46 if (! $chat = $DB->get_record('chat', array('id'=>$c))) {
47 print_error('coursemisconf');
49 if (! $course = $DB->get_record('course', array('id'=>$chat->course))) {
50 print_error('coursemisconf');
52 if (! $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
53 print_error('invalidcoursemodule');
57 require_course_login($course, true, $cm);
59 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
60 $PAGE->set_context($context);
62 // show some info for guests
63 if (isguestuser()) {
64 $PAGE->set_title(format_string($chat->name));
65 echo $OUTPUT->header();
66 echo $OUTPUT->confirm('<p>'.get_string('noguests', 'chat').'</p>'.get_string('liketologin'),
67 get_login_url(), $CFG->wwwroot.'/course/view.php?id='.$course->id);
69 echo $OUTPUT->footer();
70 exit;
73 add_to_log($course->id, 'chat', 'view', "view.php?id=$cm->id", $chat->id, $cm->id);
75 $strenterchat = get_string('enterchat', 'chat');
76 $stridle = get_string('idle', 'chat');
77 $strcurrentusers = get_string('currentusers', 'chat');
78 $strnextsession = get_string('nextsession', 'chat');
80 $title = $course->shortname . ': ' . format_string($chat->name);
82 // Initialize $PAGE
83 $PAGE->set_url('/mod/chat/view.php', array('id' => $cm->id));
84 $PAGE->set_title($title);
85 $PAGE->set_heading($course->fullname);
87 /// Print the page header
88 echo $OUTPUT->header();
90 /// Check to see if groups are being used here
91 $groupmode = groups_get_activity_groupmode($cm);
92 $currentgroup = groups_get_activity_group($cm, true);
93 groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/view.php?id=$cm->id");
95 // url parameters
96 $params = array();
97 if ($currentgroup) {
98 $groupselect = " AND groupid = '$currentgroup'";
99 $groupparam = "&amp;groupid=$currentgroup";
100 $params['groupid'] = $currentgroup;
101 } else {
102 $groupselect = "";
103 $groupparam = "";
106 echo $OUTPUT->heading(format_string($chat->name));
108 if ($chat->intro) {
109 echo $OUTPUT->box(format_module_intro('chat', $chat, $cm->id), 'generalbox', 'intro');
112 if (has_capability('mod/chat:chat', $context)) {
113 /// Print the main part of the page
114 echo $OUTPUT->box_start('generalbox', 'enterlink');
116 $now = time();
117 $span = $chat->chattime - $now;
118 if ($chat->chattime and $chat->schedule and ($span>0)) { // A chat is scheduled
119 echo '<p>';
120 echo get_string('sessionstart', 'chat', format_time($span));
121 echo '</p>';
124 if (empty($USER->screenreader)) {
125 $params['id'] = $chat->id;
126 $chattarget = new moodle_url("/mod/chat/gui_$CFG->chat_method/index.php", $params);
127 echo '<p>';
128 echo $OUTPUT->action_link($chattarget, $strenterchat, new popup_action('click', $chattarget, "chat$course->id$chat->id$groupparam", array('height' => 500, 'width' => 700)));
129 echo '</p>';
132 // if user is using screen reader, then there is no need to display this link again
133 // users with screenreader set, will only see 1 link, to the manual refresh page
134 // for better accessibility
135 // show frame/js-less alternative
136 $params['id'] = $chat->id;
137 $link = new moodle_url('/mod/chat/gui_basic/index.php', $params);
138 $action = new popup_action('click', $link, "chat{$course->id}{$chat->id}{$groupparam}", array('height' => 500, 'width' => 700));
139 echo '<p>';
140 echo $OUTPUT->action_link($link, get_string('noframesjs', 'message'), $action, array('title'=>get_string('modulename', 'chat')));
141 echo '</p>';
143 if ($chat->studentlogs or has_capability('mod/chat:readlog', $context)) {
144 if ($msg = $DB->get_records_select('chat_messages', "chatid = ? $groupselect", array($chat->id))) {
145 echo '<p>';
146 echo html_writer::link(new moodle_url('/mod/chat/report.php', array('id'=>$cm->id)), get_string('viewreport', 'chat'));
147 echo '</p>';
152 echo $OUTPUT->box_end();
154 } else {
155 echo $OUTPUT->box_start('generalbox', 'notallowenter');
156 echo '<p>'.get_string('notallowenter', 'chat').'</p>';
157 echo $OUTPUT->box_end();
160 chat_delete_old_users();
162 if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) {
163 $timenow = time();
164 echo $OUTPUT->box_start('generalbox', 'chatcurrentusers');
165 echo $OUTPUT->heading($strcurrentusers, 4);
166 echo '<table>';
167 foreach ($chatusers as $chatuser) {
168 $lastping = $timenow - $chatuser->lastmessageping;
169 echo '<tr><td class="chatuserimage">';
170 $url = new moodle_url('/user/view.php', array('id'=>$chatuser->id, 'course'=>$chat->course));
171 echo html_writer::link($url, $OUTPUT->user_picture($chatuser));
172 echo '</td><td class="chatuserdetails">';
173 echo '<p>'.fullname($chatuser).'</p>';
174 echo '<span class="idletime">'.$stridle.': '.format_time($lastping).'</span>';
175 echo '</td></tr>';
177 echo '</table>';
178 echo $OUTPUT->box_end();
181 $completion = new completion_info($course);
182 $completion->set_module_viewed($cm);
184 echo $OUTPUT->footer();