2009-11-01 13:17:47 +00:00
|
|
|
<?php
|
2010-05-20 06:26:40 +00:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2014-07-23 09:58:29 +08:00
|
|
|
// This page prints a particular instance of chat.
|
2003-07-25 06:47:06 +00:00
|
|
|
|
2016-02-26 17:47:58 +11:00
|
|
|
require(__DIR__.'/../../config.php');
|
2010-05-20 06:26:40 +00:00
|
|
|
require_once($CFG->dirroot . '/mod/chat/lib.php');
|
2010-11-17 07:56:40 +00:00
|
|
|
require_once($CFG->libdir . '/completionlib.php');
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2010-05-20 06:26:40 +00:00
|
|
|
$id = optional_param('id', 0, PARAM_INT);
|
|
|
|
$c = optional_param('c', 0, PARAM_INT);
|
|
|
|
$edit = optional_param('edit', -1, PARAM_BOOL);
|
2003-07-07 06:44:16 +00:00
|
|
|
|
2010-05-20 06:26:40 +00:00
|
|
|
if ($id) {
|
|
|
|
if (! $cm = get_coursemodule_from_id('chat', $id)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('invalidcoursemodule');
|
2003-07-07 06:44:16 +00:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:58:29 +08:00
|
|
|
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('coursemisconf');
|
2010-05-20 06:26:40 +00:00
|
|
|
}
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2010-05-20 06:26:40 +00:00
|
|
|
chat_update_chat_times($cm->instance);
|
2007-12-16 13:57:21 +00:00
|
|
|
|
2014-07-23 09:58:29 +08:00
|
|
|
if (! $chat = $DB->get_record('chat', array('id' => $cm->instance))) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('invalidid', 'chat');
|
2007-12-16 13:57:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-20 06:26:40 +00:00
|
|
|
} else {
|
|
|
|
chat_update_chat_times($c);
|
2009-05-06 09:29:05 +00:00
|
|
|
|
2014-07-23 09:58:29 +08:00
|
|
|
if (! $chat = $DB->get_record('chat', array('id' => $c))) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('coursemisconf');
|
2010-05-20 06:26:40 +00:00
|
|
|
}
|
2014-07-23 09:58:29 +08:00
|
|
|
if (! $course = $DB->get_record('course', array('id' => $chat->course))) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('coursemisconf');
|
2005-02-09 15:47:22 +00:00
|
|
|
}
|
2010-05-20 06:26:40 +00:00
|
|
|
if (! $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('invalidcoursemodule');
|
2010-05-20 06:26:40 +00:00
|
|
|
}
|
|
|
|
}
|
2005-02-09 15:47:22 +00:00
|
|
|
|
2010-05-20 06:26:40 +00:00
|
|
|
require_course_login($course, true, $cm);
|
2009-05-06 09:25:54 +00:00
|
|
|
|
2012-07-26 14:50:54 +08:00
|
|
|
$context = context_module::instance($cm->id);
|
2010-07-28 04:12:16 +00:00
|
|
|
$PAGE->set_context($context);
|
2009-05-06 09:25:54 +00:00
|
|
|
|
2022-03-14 10:50:52 +01:00
|
|
|
// Initialize $PAGE.
|
|
|
|
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
|
|
|
|
$title = $courseshortname . ': ' . format_string($chat->name);
|
|
|
|
$PAGE->set_url('/mod/chat/view.php', ['id' => $cm->id]);
|
|
|
|
$PAGE->set_title($title);
|
|
|
|
$PAGE->set_heading($course->fullname);
|
|
|
|
$PAGE->add_body_class('limitedwidth');
|
|
|
|
|
2014-07-23 09:58:29 +08:00
|
|
|
// Show some info for guests.
|
2010-05-20 06:26:40 +00:00
|
|
|
if (isguestuser()) {
|
2009-09-07 04:08:56 +00:00
|
|
|
echo $OUTPUT->header();
|
2010-05-20 06:26:40 +00:00
|
|
|
echo $OUTPUT->confirm('<p>'.get_string('noguests', 'chat').'</p>'.get_string('liketologin'),
|
|
|
|
get_login_url(), $CFG->wwwroot.'/course/view.php?id='.$course->id);
|
2005-02-09 15:47:22 +00:00
|
|
|
|
2010-05-20 06:26:40 +00:00
|
|
|
echo $OUTPUT->footer();
|
|
|
|
exit;
|
|
|
|
}
|
2008-07-24 03:15:03 +00:00
|
|
|
|
2015-07-27 14:00:11 +02:00
|
|
|
// Completion and trigger events.
|
|
|
|
chat_view($chat, $course, $cm, $context);
|
2009-07-09 07:35:03 +00:00
|
|
|
|
2010-05-20 06:26:40 +00:00
|
|
|
$strenterchat = get_string('enterchat', 'chat');
|
|
|
|
$stridle = get_string('idle', 'chat');
|
|
|
|
$strcurrentusers = get_string('currentusers', 'chat');
|
2009-07-09 07:35:03 +00:00
|
|
|
|
2014-07-23 09:58:29 +08:00
|
|
|
// Check to see if groups are being used here.
|
2010-05-20 06:26:40 +00:00
|
|
|
$groupmode = groups_get_activity_groupmode($cm);
|
|
|
|
$currentgroup = groups_get_activity_group($cm, true);
|
2010-05-04 05:09:30 +00:00
|
|
|
|
2014-07-23 09:58:29 +08:00
|
|
|
// URL parameters.
|
2010-09-24 06:10:53 +00:00
|
|
|
$params = array();
|
2010-05-20 06:26:40 +00:00
|
|
|
if ($currentgroup) {
|
|
|
|
$groupselect = " AND groupid = '$currentgroup'";
|
2013-10-12 00:52:55 +08:00
|
|
|
$groupparam = "_group{$currentgroup}";
|
2010-09-24 06:10:53 +00:00
|
|
|
$params['groupid'] = $currentgroup;
|
2010-05-20 06:26:40 +00:00
|
|
|
} else {
|
|
|
|
$groupselect = "";
|
|
|
|
$groupparam = "";
|
|
|
|
}
|
2009-07-09 07:35:03 +00:00
|
|
|
|
2021-09-21 09:14:11 +08:00
|
|
|
// Print the page header.
|
|
|
|
echo $OUTPUT->header();
|
2009-07-09 07:35:03 +00:00
|
|
|
|
2010-11-17 07:56:40 +00:00
|
|
|
if (has_capability('mod/chat:chat', $context)) {
|
2009-07-09 07:35:03 +00:00
|
|
|
|
2010-11-17 07:56:40 +00:00
|
|
|
$now = time();
|
2021-04-20 14:29:22 +10:00
|
|
|
$chattime = $chat->chattime ?? 0;
|
|
|
|
$span = $chattime - $now;
|
|
|
|
if (!empty($chat->schedule) && $span > 0) {
|
2021-07-14 13:31:18 +08:00
|
|
|
$attributes = ['class' => 'border bg-light rounded p-2'];
|
|
|
|
echo html_writer::tag('p', get_string('sessionstartsin', 'chat', format_time($span)), $attributes);
|
2009-07-09 07:35:03 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 11:29:56 +08:00
|
|
|
$params['id'] = $chat->id;
|
|
|
|
$chattarget = new moodle_url("/mod/chat/gui_$CFG->chat_method/index.php", $params);
|
2022-02-01 12:13:38 +01:00
|
|
|
echo html_writer::start_div('container-fluid tertiary-navigation');
|
2021-07-14 13:31:18 +08:00
|
|
|
echo html_writer::start_div('row');
|
2022-02-01 12:13:38 +01:00
|
|
|
echo html_writer::start_div('navitem');
|
2014-07-23 09:58:29 +08:00
|
|
|
echo $OUTPUT->action_link($chattarget,
|
|
|
|
$strenterchat,
|
|
|
|
new popup_action('click', $chattarget, "chat{$course->id}_{$chat->id}{$groupparam}",
|
2021-07-14 13:31:18 +08:00
|
|
|
array('height' => 500, 'width' => 700)), ['class' => 'btn btn-primary']);
|
|
|
|
echo html_writer::end_div();
|
2022-02-01 12:13:38 +01:00
|
|
|
echo html_writer::start_div('navitem');
|
2009-07-09 07:35:03 +00:00
|
|
|
|
2010-09-24 06:10:53 +00:00
|
|
|
$params['id'] = $chat->id;
|
|
|
|
$link = new moodle_url('/mod/chat/gui_basic/index.php', $params);
|
2014-07-23 09:58:29 +08:00
|
|
|
$action = new popup_action('click', $link, "chat{$course->id}_{$chat->id}{$groupparam}",
|
|
|
|
array('height' => 500, 'width' => 700));
|
|
|
|
echo $OUTPUT->action_link($link, get_string('noframesjs', 'message'), $action,
|
2021-07-14 13:31:18 +08:00
|
|
|
array('title' => get_string('modulename', 'chat'), 'class' => 'btn btn-secondary'));
|
|
|
|
echo html_writer::end_div();
|
|
|
|
echo html_writer::end_div();
|
|
|
|
echo html_writer::end_div();
|
2010-05-20 06:26:40 +00:00
|
|
|
|
2022-02-01 12:13:38 +01:00
|
|
|
// Print the main part of the page.
|
|
|
|
echo $OUTPUT->box_start('generalbox', 'enterlink');
|
|
|
|
|
2021-07-14 13:31:18 +08:00
|
|
|
if (($chat->studentlogs or has_capability('mod/chat:readlog', $context)) && !$PAGE->has_secondary_navigation()) {
|
2017-09-22 16:12:21 +02:00
|
|
|
if ($msg = chat_get_session_messages($chat->id, $currentgroup)) {
|
2009-07-09 07:35:03 +00:00
|
|
|
echo '<p>';
|
2014-07-23 09:58:29 +08:00
|
|
|
echo html_writer::link(new moodle_url('/mod/chat/report.php', array('id' => $cm->id)),
|
|
|
|
get_string('viewreport', 'chat'));
|
2009-07-09 07:35:03 +00:00
|
|
|
echo '</p>';
|
|
|
|
}
|
|
|
|
}
|
2021-12-22 10:36:05 +08:00
|
|
|
groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/view.php?id=$cm->id");
|
2005-02-09 15:47:22 +00:00
|
|
|
|
2010-05-20 06:26:40 +00:00
|
|
|
echo $OUTPUT->box_end();
|
|
|
|
|
|
|
|
} else {
|
2021-12-22 10:36:05 +08:00
|
|
|
groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/view.php?id=$cm->id");
|
2010-05-20 06:26:40 +00:00
|
|
|
echo $OUTPUT->box_start('generalbox', 'notallowenter');
|
|
|
|
echo '<p>'.get_string('notallowenter', 'chat').'</p>';
|
|
|
|
echo $OUTPUT->box_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
chat_delete_old_users();
|
|
|
|
|
|
|
|
if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) {
|
|
|
|
$timenow = time();
|
|
|
|
echo $OUTPUT->box_start('generalbox', 'chatcurrentusers');
|
2013-08-22 12:03:23 +07:00
|
|
|
echo $OUTPUT->heading($strcurrentusers, 3);
|
2010-05-20 06:26:40 +00:00
|
|
|
echo '<table>';
|
|
|
|
foreach ($chatusers as $chatuser) {
|
|
|
|
$lastping = $timenow - $chatuser->lastmessageping;
|
|
|
|
echo '<tr><td class="chatuserimage">';
|
2014-07-23 09:58:29 +08:00
|
|
|
$url = new moodle_url('/user/view.php', array('id' => $chatuser->id, 'course' => $chat->course));
|
2010-05-20 06:26:40 +00:00
|
|
|
echo html_writer::link($url, $OUTPUT->user_picture($chatuser));
|
|
|
|
echo '</td><td class="chatuserdetails">';
|
|
|
|
echo '<p>'.fullname($chatuser).'</p>';
|
|
|
|
echo '<span class="idletime">'.$stridle.': '.format_time($lastping).'</span>';
|
|
|
|
echo '</td></tr>';
|
|
|
|
}
|
|
|
|
echo '</table>';
|
|
|
|
echo $OUTPUT->box_end();
|
|
|
|
}
|
2009-11-01 13:17:47 +00:00
|
|
|
|
2010-05-20 06:26:40 +00:00
|
|
|
echo $OUTPUT->footer();
|