See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 // This page prints a particular instance of chat. 18 19 require(__DIR__.'/../../config.php'); 20 require_once($CFG->dirroot . '/mod/chat/lib.php'); 21 require_once($CFG->libdir . '/completionlib.php'); 22 23 $id = optional_param('id', 0, PARAM_INT); 24 $c = optional_param('c', 0, PARAM_INT); 25 $edit = optional_param('edit', -1, PARAM_BOOL); 26 27 if ($id) { 28 if (! $cm = get_coursemodule_from_id('chat', $id)) { 29 throw new \moodle_exception('invalidcoursemodule'); 30 } 31 32 if (! $course = $DB->get_record('course', array('id' => $cm->course))) { 33 throw new \moodle_exception('coursemisconf'); 34 } 35 36 chat_update_chat_times($cm->instance); 37 38 if (! $chat = $DB->get_record('chat', array('id' => $cm->instance))) { 39 throw new \moodle_exception('invalidid', 'chat'); 40 } 41 42 } else { 43 chat_update_chat_times($c); 44 45 if (! $chat = $DB->get_record('chat', array('id' => $c))) { 46 throw new \moodle_exception('coursemisconf'); 47 } 48 if (! $course = $DB->get_record('course', array('id' => $chat->course))) { 49 throw new \moodle_exception('coursemisconf'); 50 } 51 if (! $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) { 52 throw new \moodle_exception('invalidcoursemodule'); 53 } 54 } 55 56 require_course_login($course, true, $cm); 57 58 $context = context_module::instance($cm->id); 59 $PAGE->set_context($context); 60 61 // Initialize $PAGE. 62 $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); 63 $title = $courseshortname . ': ' . format_string($chat->name); 64 $PAGE->set_url('/mod/chat/view.php', ['id' => $cm->id]); 65 $PAGE->set_title($title); 66 $PAGE->set_heading($course->fullname); 67 $PAGE->add_body_class('limitedwidth'); 68 69 // Show some info for guests. 70 if (isguestuser()) { 71 echo $OUTPUT->header(); 72 echo $OUTPUT->confirm('<p>'.get_string('noguests', 'chat').'</p>'.get_string('liketologin'), 73 get_login_url(), $CFG->wwwroot.'/course/view.php?id='.$course->id); 74 75 echo $OUTPUT->footer(); 76 exit; 77 } 78 79 // Completion and trigger events. 80 chat_view($chat, $course, $cm, $context); 81 82 $strenterchat = get_string('enterchat', 'chat'); 83 $stridle = get_string('idle', 'chat'); 84 $strcurrentusers = get_string('currentusers', 'chat'); 85 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 90 // URL parameters. 91 $params = array(); 92 if ($currentgroup) { 93 $groupselect = " AND groupid = '$currentgroup'"; 94 $groupparam = "_group{$currentgroup}"; 95 $params['groupid'] = $currentgroup; 96 } else { 97 $groupselect = ""; 98 $groupparam = ""; 99 } 100 101 // Print the page header. 102 echo $OUTPUT->header(); 103 104 if (has_capability('mod/chat:chat', $context)) { 105 106 $now = time(); 107 $chattime = $chat->chattime ?? 0; 108 $span = $chattime - $now; 109 if (!empty($chat->schedule) && $span > 0) { 110 $attributes = ['class' => 'border bg-light rounded p-2']; 111 echo html_writer::tag('p', get_string('sessionstartsin', 'chat', format_time($span)), $attributes); 112 } 113 114 $params['id'] = $chat->id; 115 $chattarget = new moodle_url("/mod/chat/gui_$CFG->chat_method/index.php", $params); 116 echo html_writer::start_div('container-fluid tertiary-navigation'); 117 echo html_writer::start_div('row'); 118 echo html_writer::start_div('navitem'); 119 echo $OUTPUT->action_link($chattarget, 120 $strenterchat, 121 new popup_action('click', $chattarget, "chat{$course->id}_{$chat->id}{$groupparam}", 122 array('height' => 500, 'width' => 700)), ['class' => 'btn btn-primary']); 123 echo html_writer::end_div(); 124 echo html_writer::start_div('navitem'); 125 126 $params['id'] = $chat->id; 127 $link = new moodle_url('/mod/chat/gui_basic/index.php', $params); 128 $action = new popup_action('click', $link, "chat{$course->id}_{$chat->id}{$groupparam}", 129 array('height' => 500, 'width' => 700)); 130 echo $OUTPUT->action_link($link, get_string('noframesjs', 'message'), $action, 131 array('title' => get_string('modulename', 'chat'), 'class' => 'btn btn-secondary')); 132 echo html_writer::end_div(); 133 echo html_writer::end_div(); 134 echo html_writer::end_div(); 135 136 // Print the main part of the page. 137 echo $OUTPUT->box_start('generalbox', 'enterlink'); 138 139 if (($chat->studentlogs or has_capability('mod/chat:readlog', $context)) && !$PAGE->has_secondary_navigation()) { 140 if ($msg = chat_get_session_messages($chat->id, $currentgroup)) { 141 echo '<p>'; 142 echo html_writer::link(new moodle_url('/mod/chat/report.php', array('id' => $cm->id)), 143 get_string('viewreport', 'chat')); 144 echo '</p>'; 145 } 146 } 147 groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/view.php?id=$cm->id"); 148 149 echo $OUTPUT->box_end(); 150 151 } else { 152 groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/view.php?id=$cm->id"); 153 echo $OUTPUT->box_start('generalbox', 'notallowenter'); 154 echo '<p>'.get_string('notallowenter', 'chat').'</p>'; 155 echo $OUTPUT->box_end(); 156 } 157 158 chat_delete_old_users(); 159 160 if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) { 161 $timenow = time(); 162 echo $OUTPUT->box_start('generalbox', 'chatcurrentusers'); 163 echo $OUTPUT->heading($strcurrentusers, 3); 164 echo '<table>'; 165 foreach ($chatusers as $chatuser) { 166 $lastping = $timenow - $chatuser->lastmessageping; 167 echo '<tr><td class="chatuserimage">'; 168 $url = new moodle_url('/user/view.php', array('id' => $chatuser->id, 'course' => $chat->course)); 169 echo html_writer::link($url, $OUTPUT->user_picture($chatuser)); 170 echo '</td><td class="chatuserdetails">'; 171 echo '<p>'.fullname($chatuser).'</p>'; 172 echo '<span class="idletime">'.$stridle.': '.format_time($lastping).'</span>'; 173 echo '</td></tr>'; 174 } 175 echo '</table>'; 176 echo $OUTPUT->box_end(); 177 } 178 179 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body