moodle/mod/chat/view.php

203 lines
7.5 KiB
PHP
Raw Normal View History

<?php // $Id$
/// This page prints a particular instance of chat
require_once('../../config.php');
require_once('lib.php');
require_once($CFG->libdir.'/blocklib.php');
require_once('pagelib.php');
2006-04-23 20:58:06 +00:00
$id = optional_param('id', 0, PARAM_INT);
$c = optional_param('c', 0, PARAM_INT);
$edit = optional_param('edit', -1, PARAM_BOOL);
if ($id) {
if (! $cm = get_coursemodule_from_id('chat', $id)) {
2008-06-06 08:46:48 +00:00
print_error('invalidcoursemodule');
}
2008-06-06 08:46:48 +00:00
if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('coursemisconf');
}
chat_update_chat_times($cm->instance);
2008-06-06 08:46:48 +00:00
if (! $chat = $DB->get_record('chat', array('id'=>$cm->instance))) {
print_error('invalidid', 'chat');
}
} else {
chat_update_chat_times($c);
2008-06-06 08:46:48 +00:00
if (! $chat = $DB->get_record('chat', array('id'=>$c))) {
print_error('coursemisconf');
}
2008-06-08 15:49:36 +00:00
if (! $course = $DB->get_record('course', array('id'=>$chat->course))) {
2008-06-06 08:46:48 +00:00
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
2008-06-06 08:46:48 +00:00
print_error('invalidcoursemodule');
}
}
require_course_login($course, true, $cm);
2006-08-09 13:45:49 +00:00
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// show some info for guests
if (isguestuser()) {
$navigation = build_navigation('', $cm);
print_header_simple(format_string($chat->name), '', $navigation,
'', '', true, '', navmenu($course, $cm));
$wwwroot = $CFG->wwwroot.'/login/index.php';
if (!empty($CFG->loginhttps)) {
$wwwroot = str_replace('http:','https:', $wwwroot);
}
notice_yesno(get_string('noguests', 'chat').'<br /><br />'.get_string('liketologin'),
$wwwroot, $CFG->wwwroot.'/course/view.php?id='.$course->id);
print_footer($course);
exit;
} else {
require_capability('mod/chat:chat', $context);
}
2006-08-09 13:45:49 +00:00
add_to_log($course->id, 'chat', 'view', "view.php?id=$cm->id", $chat->id, $cm->id);
2005-02-09 15:47:22 +00:00
// Initialize $PAGE, compute blocks
$PAGE = page_create_instance($chat->id);
$pageblocks = blocks_setup($PAGE);
2005-02-09 15:47:22 +00:00
$blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
/// Print the page header
$strenterchat = get_string('enterchat', 'chat');
$stridle = get_string('idle', 'chat');
$strcurrentusers = get_string('currentusers', 'chat');
$strnextsession = get_string('nextsession', 'chat');
2006-04-23 20:58:06 +00:00
if (($edit != -1) and $PAGE->user_allowed_editing()) {
$USER->editing = $edit;
2005-02-09 15:47:22 +00:00
}
$PAGE->print_header($course->shortname.': %fullname%');
echo '<table id="layout-table"><tr>';
2005-02-09 15:47:22 +00:00
$lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
foreach ($lt as $column) {
switch ($column) {
case 'left':
if(!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
print_container_start();
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
print_container_end();
echo '</td>';
}
break;
case 'middle':
echo '<td id="middle-column">';
print_container_start();
/// Check to see if groups are being used here
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
groups_print_activity_menu($cm, "view.php?id=$cm->id");
if ($currentgroup) {
$groupparam = "&amp;groupid=$currentgroup";
} else {
$groupparam = "";
}
if ($chat->studentlogs or has_capability('mod/chat:readlog',$context)) {
echo '<div class="reportlink">';
echo "<a href=\"report.php?id=$cm->id\">".
get_string('viewreport', 'chat').'</a>';
echo '</div>';
}
print_heading(format_string($chat->name));
/// Print the main part of the page
print_box_start('generalbox', 'enterlink');
// users with screenreader set, will only see 1 link, to the manual refresh page
// for better accessibility
if (!empty($USER->screenreader)) {
$chattarget = "/mod/chat/gui_basic/index.php?id=$chat->id$groupparam";
} else {
$chattarget = "/mod/chat/gui_$CFG->chat_method/index.php?id=$chat->id$groupparam";
}
echo '<p>';
link_to_popup_window ($chattarget,
"chat$course->id$chat->id$groupparam", "$strenterchat", 500, 700, get_string('modulename', 'chat'));
echo '</p>';
// if user is using screen reader, then there is no need to display this link again
if ($CFG->chat_method == 'header_js' && empty($USER->screenreader)) {
// show frame/js-less alternative
echo '<p>(';
link_to_popup_window ("/mod/chat/gui_basic/index.php?id=$chat->id$groupparam",
"chat$course->id$chat->id$groupparam", get_string('noframesjs', 'message'), 500, 700, get_string('modulename', 'chat'));
echo ')</p>';
}
print_box_end();
if ($chat->chattime and $chat->schedule) { // A chat is scheduled
echo "<p class=\"nextchatsession\">$strnextsession: ".userdate($chat->chattime).' ('.usertimezone($USER->timezone).')</p>';
} else {
echo '<br />';
}
if ($chat->intro) {
print_box(format_text($chat->intro), 'generalbox', 'intro');
}
chat_delete_old_users();
if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) {
$timenow = time();
print_simple_box_start('center');
print_heading($strcurrentusers);
echo '<table id="chatcurrentusers">';
foreach ($chatusers as $chatuser) {
$lastping = $timenow - $chatuser->lastmessageping;
echo '<tr><td class="chatuserimage">';
echo "<a href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$chat->course\">";
print_user_picture($chatuser, 0, $chatuser->picture, false, false, false);
echo '</a></td><td class="chatuserdetails">';
echo '<p>';
echo fullname($chatuser).'<br />';
echo "<span class=\"idletime\">$stridle: ".format_time($lastping)."</span>";
echo '</p>';
echo '</td></tr>';
}
echo '</table>';
print_simple_box_end();
}
print_container_end();
echo '</td>';
break;
2005-04-25 19:10:14 +00:00
}
}
echo '</tr></table>';
2005-02-09 15:47:22 +00:00
print_footer($course);
?>