MDL-37801 mod_glossary - encode / decode links to 'showentry' pages during backup...
[moodle.git] / mod / chat / view.php
blob4daae972b5f0a13286d17e54372ed34b3c32b2b7
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 = context_module::instance($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 $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
81 $title = $courseshortname . ': ' . format_string($chat->name);
83 // Mark viewed by user (if required)
84 $completion = new completion_info($course);
85 $completion->set_module_viewed($cm);
87 // Initialize $PAGE
88 $PAGE->set_url('/mod/chat/view.php', array('id' => $cm->id));
89 $PAGE->set_title($title);
90 $PAGE->set_heading($course->fullname);
92 /// Print the page header
93 echo $OUTPUT->header();
95 /// Check to see if groups are being used here
96 $groupmode = groups_get_activity_groupmode($cm);
97 $currentgroup = groups_get_activity_group($cm, true);
98 groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/view.php?id=$cm->id");
100 // url parameters
101 $params = array();
102 if ($currentgroup) {
103 $groupselect = " AND groupid = '$currentgroup'";
104 $groupparam = "&amp;groupid=$currentgroup";
105 $params['groupid'] = $currentgroup;
106 } else {
107 $groupselect = "";
108 $groupparam = "";
111 echo $OUTPUT->heading(format_string($chat->name));
113 if ($chat->intro) {
114 echo $OUTPUT->box(format_module_intro('chat', $chat, $cm->id), 'generalbox', 'intro');
117 if (has_capability('mod/chat:chat', $context)) {
118 /// Print the main part of the page
119 echo $OUTPUT->box_start('generalbox', 'enterlink');
121 $now = time();
122 $span = $chat->chattime - $now;
123 if ($chat->chattime and $chat->schedule and ($span>0)) { // A chat is scheduled
124 echo '<p>';
125 echo get_string('sessionstart', 'chat', format_time($span));
126 echo '</p>';
129 $params['id'] = $chat->id;
130 $chattarget = new moodle_url("/mod/chat/gui_$CFG->chat_method/index.php", $params);
131 echo '<p>';
132 echo $OUTPUT->action_link($chattarget, $strenterchat, new popup_action('click', $chattarget, "chat$course->id$chat->id$groupparam", array('height' => 500, 'width' => 700)));
133 echo '</p>';
135 $params['id'] = $chat->id;
136 $link = new moodle_url('/mod/chat/gui_basic/index.php', $params);
137 $action = new popup_action('click', $link, "chat{$course->id}{$chat->id}{$groupparam}", array('height' => 500, 'width' => 700));
138 echo '<p>';
139 echo $OUTPUT->action_link($link, get_string('noframesjs', 'message'), $action, array('title'=>get_string('modulename', 'chat')));
140 echo '</p>';
142 if ($chat->studentlogs or has_capability('mod/chat:readlog', $context)) {
143 if ($msg = $DB->get_records_select('chat_messages', "chatid = ? $groupselect", array($chat->id))) {
144 echo '<p>';
145 echo html_writer::link(new moodle_url('/mod/chat/report.php', array('id'=>$cm->id)), get_string('viewreport', 'chat'));
146 echo '</p>';
151 echo $OUTPUT->box_end();
153 } else {
154 echo $OUTPUT->box_start('generalbox', 'notallowenter');
155 echo '<p>'.get_string('notallowenter', 'chat').'</p>';
156 echo $OUTPUT->box_end();
159 chat_delete_old_users();
161 if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) {
162 $timenow = time();
163 echo $OUTPUT->box_start('generalbox', 'chatcurrentusers');
164 echo $OUTPUT->heading($strcurrentusers, 4);
165 echo '<table>';
166 foreach ($chatusers as $chatuser) {
167 $lastping = $timenow - $chatuser->lastmessageping;
168 echo '<tr><td class="chatuserimage">';
169 $url = new moodle_url('/user/view.php', array('id'=>$chatuser->id, 'course'=>$chat->course));
170 echo html_writer::link($url, $OUTPUT->user_picture($chatuser));
171 echo '</td><td class="chatuserdetails">';
172 echo '<p>'.fullname($chatuser).'</p>';
173 echo '<span class="idletime">'.$stridle.': '.format_time($lastping).'</span>';
174 echo '</td></tr>';
176 echo '</table>';
177 echo $OUTPUT->box_end();
180 echo $OUTPUT->footer();