[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
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_once(dirname(dirname(dirname(__FILE__))) . '/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 print_error('invalidcoursemodule'); 30 } 31 32 if (! $course = $DB->get_record('course', array('id' => $cm->course))) { 33 print_error('coursemisconf'); 34 } 35 36 chat_update_chat_times($cm->instance); 37 38 if (! $chat = $DB->get_record('chat', array('id' => $cm->instance))) { 39 print_error('invalidid', 'chat'); 40 } 41 42 } else { 43 chat_update_chat_times($c); 44 45 if (! $chat = $DB->get_record('chat', array('id' => $c))) { 46 print_error('coursemisconf'); 47 } 48 if (! $course = $DB->get_record('course', array('id' => $chat->course))) { 49 print_error('coursemisconf'); 50 } 51 if (! $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) { 52 print_error('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 // Show some info for guests. 62 if (isguestuser()) { 63 $PAGE->set_title($chat->name); 64 echo $OUTPUT->header(); 65 echo $OUTPUT->confirm('<p>'.get_string('noguests', 'chat').'</p>'.get_string('liketologin'), 66 get_login_url(), $CFG->wwwroot.'/course/view.php?id='.$course->id); 67 68 echo $OUTPUT->footer(); 69 exit; 70 } 71 72 // Log this request - the problem here is that the view page 73 // does not display the chat content which is actually in a new window. 74 $params = array( 75 'objectid' => $chat->id, 76 'context' => $context 77 ); 78 $event = \mod_chat\event\course_module_viewed::create($params); 79 $event->add_record_snapshot('chat', $chat); 80 $event->trigger(); 81 82 $strenterchat = get_string('enterchat', 'chat'); 83 $stridle = get_string('idle', 'chat'); 84 $strcurrentusers = get_string('currentusers', 'chat'); 85 $strnextsession = get_string('nextsession', 'chat'); 86 87 $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); 88 $title = $courseshortname . ': ' . format_string($chat->name); 89 90 // Mark viewed by user (if required). 91 $completion = new completion_info($course); 92 $completion->set_module_viewed($cm); 93 94 // Initialize $PAGE. 95 $PAGE->set_url('/mod/chat/view.php', array('id' => $cm->id)); 96 $PAGE->set_title($title); 97 $PAGE->set_heading($course->fullname); 98 99 // Print the page header. 100 echo $OUTPUT->header(); 101 102 // Check to see if groups are being used here. 103 $groupmode = groups_get_activity_groupmode($cm); 104 $currentgroup = groups_get_activity_group($cm, true); 105 106 // URL parameters. 107 $params = array(); 108 if ($currentgroup) { 109 $groupselect = " AND groupid = '$currentgroup'"; 110 $groupparam = "_group{$currentgroup}"; 111 $params['groupid'] = $currentgroup; 112 } else { 113 $groupselect = ""; 114 $groupparam = ""; 115 } 116 117 echo $OUTPUT->heading(format_string($chat->name), 2); 118 119 if ($chat->intro) { 120 echo $OUTPUT->box(format_module_intro('chat', $chat, $cm->id), 'generalbox', 'intro'); 121 } 122 123 groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/view.php?id=$cm->id"); 124 125 if (has_capability('mod/chat:chat', $context)) { 126 // Print the main part of the page. 127 echo $OUTPUT->box_start('generalbox', 'enterlink'); 128 129 $now = time(); 130 $span = $chat->chattime - $now; 131 if ($chat->chattime and $chat->schedule and ($span > 0)) { // A chat is scheduled. 132 echo '<p>'; 133 echo get_string('sessionstart', 'chat', format_time($span)); 134 echo '</p>'; 135 } 136 137 $params['id'] = $chat->id; 138 $chattarget = new moodle_url("/mod/chat/gui_$CFG->chat_method/index.php", $params); 139 echo '<p>'; 140 echo $OUTPUT->action_link($chattarget, 141 $strenterchat, 142 new popup_action('click', $chattarget, "chat{$course->id}_{$chat->id}{$groupparam}", 143 array('height' => 500, 'width' => 700))); 144 echo '</p>'; 145 146 $params['id'] = $chat->id; 147 $link = new moodle_url('/mod/chat/gui_basic/index.php', $params); 148 $action = new popup_action('click', $link, "chat{$course->id}_{$chat->id}{$groupparam}", 149 array('height' => 500, 'width' => 700)); 150 echo '<p>'; 151 echo $OUTPUT->action_link($link, get_string('noframesjs', 'message'), $action, 152 array('title' => get_string('modulename', 'chat'))); 153 echo '</p>'; 154 155 if ($chat->studentlogs or has_capability('mod/chat:readlog', $context)) { 156 if ($msg = $DB->get_records_select('chat_messages', "chatid = ? $groupselect", array($chat->id))) { 157 echo '<p>'; 158 echo html_writer::link(new moodle_url('/mod/chat/report.php', array('id' => $cm->id)), 159 get_string('viewreport', 'chat')); 160 echo '</p>'; 161 } 162 } 163 164 echo $OUTPUT->box_end(); 165 166 } else { 167 echo $OUTPUT->box_start('generalbox', 'notallowenter'); 168 echo '<p>'.get_string('notallowenter', 'chat').'</p>'; 169 echo $OUTPUT->box_end(); 170 } 171 172 chat_delete_old_users(); 173 174 if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) { 175 $timenow = time(); 176 echo $OUTPUT->box_start('generalbox', 'chatcurrentusers'); 177 echo $OUTPUT->heading($strcurrentusers, 3); 178 echo '<table>'; 179 foreach ($chatusers as $chatuser) { 180 $lastping = $timenow - $chatuser->lastmessageping; 181 echo '<tr><td class="chatuserimage">'; 182 $url = new moodle_url('/user/view.php', array('id' => $chatuser->id, 'course' => $chat->course)); 183 echo html_writer::link($url, $OUTPUT->user_picture($chatuser)); 184 echo '</td><td class="chatuserdetails">'; 185 echo '<p>'.fullname($chatuser).'</p>'; 186 echo '<span class="idletime">'.$stridle.': '.format_time($lastping).'</span>'; 187 echo '</td></tr>'; 188 } 189 echo '</table>'; 190 echo $OUTPUT->box_end(); 191 } 192 193 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |