|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00019 00020 require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); 00021 require_once($CFG->dirroot . '/mod/chat/lib.php'); 00022 require_once($CFG->libdir . '/completionlib.php'); 00023 00024 $id = optional_param('id', 0, PARAM_INT); 00025 $c = optional_param('c', 0, PARAM_INT); 00026 $edit = optional_param('edit', -1, PARAM_BOOL); 00027 00028 if ($id) { 00029 if (! $cm = get_coursemodule_from_id('chat', $id)) { 00030 print_error('invalidcoursemodule'); 00031 } 00032 00033 if (! $course = $DB->get_record('course', array('id'=>$cm->course))) { 00034 print_error('coursemisconf'); 00035 } 00036 00037 chat_update_chat_times($cm->instance); 00038 00039 if (! $chat = $DB->get_record('chat', array('id'=>$cm->instance))) { 00040 print_error('invalidid', 'chat'); 00041 } 00042 00043 } else { 00044 chat_update_chat_times($c); 00045 00046 if (! $chat = $DB->get_record('chat', array('id'=>$c))) { 00047 print_error('coursemisconf'); 00048 } 00049 if (! $course = $DB->get_record('course', array('id'=>$chat->course))) { 00050 print_error('coursemisconf'); 00051 } 00052 if (! $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) { 00053 print_error('invalidcoursemodule'); 00054 } 00055 } 00056 00057 require_course_login($course, true, $cm); 00058 00059 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00060 $PAGE->set_context($context); 00061 00062 // show some info for guests 00063 if (isguestuser()) { 00064 $PAGE->set_title(format_string($chat->name)); 00065 echo $OUTPUT->header(); 00066 echo $OUTPUT->confirm('<p>'.get_string('noguests', 'chat').'</p>'.get_string('liketologin'), 00067 get_login_url(), $CFG->wwwroot.'/course/view.php?id='.$course->id); 00068 00069 echo $OUTPUT->footer(); 00070 exit; 00071 } 00072 00073 add_to_log($course->id, 'chat', 'view', "view.php?id=$cm->id", $chat->id, $cm->id); 00074 00075 $strenterchat = get_string('enterchat', 'chat'); 00076 $stridle = get_string('idle', 'chat'); 00077 $strcurrentusers = get_string('currentusers', 'chat'); 00078 $strnextsession = get_string('nextsession', 'chat'); 00079 00080 $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))); 00081 $title = $courseshortname . ': ' . format_string($chat->name); 00082 00083 // Mark viewed by user (if required) 00084 $completion = new completion_info($course); 00085 $completion->set_module_viewed($cm); 00086 00087 // Initialize $PAGE 00088 $PAGE->set_url('/mod/chat/view.php', array('id' => $cm->id)); 00089 $PAGE->set_title($title); 00090 $PAGE->set_heading($course->fullname); 00091 00093 echo $OUTPUT->header(); 00094 00096 $groupmode = groups_get_activity_groupmode($cm); 00097 $currentgroup = groups_get_activity_group($cm, true); 00098 groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/view.php?id=$cm->id"); 00099 00100 // url parameters 00101 $params = array(); 00102 if ($currentgroup) { 00103 $groupselect = " AND groupid = '$currentgroup'"; 00104 $groupparam = "&groupid=$currentgroup"; 00105 $params['groupid'] = $currentgroup; 00106 } else { 00107 $groupselect = ""; 00108 $groupparam = ""; 00109 } 00110 00111 echo $OUTPUT->heading(format_string($chat->name)); 00112 00113 if ($chat->intro) { 00114 echo $OUTPUT->box(format_module_intro('chat', $chat, $cm->id), 'generalbox', 'intro'); 00115 } 00116 00117 if (has_capability('mod/chat:chat', $context)) { 00119 echo $OUTPUT->box_start('generalbox', 'enterlink'); 00120 00121 $now = time(); 00122 $span = $chat->chattime - $now; 00123 if ($chat->chattime and $chat->schedule and ($span>0)) { // A chat is scheduled 00124 echo '<p>'; 00125 echo get_string('sessionstart', 'chat', format_time($span)); 00126 echo '</p>'; 00127 } 00128 00129 if (empty($USER->screenreader)) { 00130 $params['id'] = $chat->id; 00131 $chattarget = new moodle_url("/mod/chat/gui_$CFG->chat_method/index.php", $params); 00132 echo '<p>'; 00133 echo $OUTPUT->action_link($chattarget, $strenterchat, new popup_action('click', $chattarget, "chat$course->id$chat->id$groupparam", array('height' => 500, 'width' => 700))); 00134 echo '</p>'; 00135 } 00136 00137 // if user is using screen reader, then there is no need to display this link again 00138 // users with screenreader set, will only see 1 link, to the manual refresh page 00139 // for better accessibility 00140 // show frame/js-less alternative 00141 $params['id'] = $chat->id; 00142 $link = new moodle_url('/mod/chat/gui_basic/index.php', $params); 00143 $action = new popup_action('click', $link, "chat{$course->id}{$chat->id}{$groupparam}", array('height' => 500, 'width' => 700)); 00144 echo '<p>'; 00145 echo $OUTPUT->action_link($link, get_string('noframesjs', 'message'), $action, array('title'=>get_string('modulename', 'chat'))); 00146 echo '</p>'; 00147 00148 if ($chat->studentlogs or has_capability('mod/chat:readlog', $context)) { 00149 if ($msg = $DB->get_records_select('chat_messages', "chatid = ? $groupselect", array($chat->id))) { 00150 echo '<p>'; 00151 echo html_writer::link(new moodle_url('/mod/chat/report.php', array('id'=>$cm->id)), get_string('viewreport', 'chat')); 00152 echo '</p>'; 00153 } 00154 } 00155 00156 00157 echo $OUTPUT->box_end(); 00158 00159 } else { 00160 echo $OUTPUT->box_start('generalbox', 'notallowenter'); 00161 echo '<p>'.get_string('notallowenter', 'chat').'</p>'; 00162 echo $OUTPUT->box_end(); 00163 } 00164 00165 chat_delete_old_users(); 00166 00167 if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) { 00168 $timenow = time(); 00169 echo $OUTPUT->box_start('generalbox', 'chatcurrentusers'); 00170 echo $OUTPUT->heading($strcurrentusers, 4); 00171 echo '<table>'; 00172 foreach ($chatusers as $chatuser) { 00173 $lastping = $timenow - $chatuser->lastmessageping; 00174 echo '<tr><td class="chatuserimage">'; 00175 $url = new moodle_url('/user/view.php', array('id'=>$chatuser->id, 'course'=>$chat->course)); 00176 echo html_writer::link($url, $OUTPUT->user_picture($chatuser)); 00177 echo '</td><td class="chatuserdetails">'; 00178 echo '<p>'.fullname($chatuser).'</p>'; 00179 echo '<span class="idletime">'.$stridle.': '.format_time($lastping).'</span>'; 00180 echo '</td></tr>'; 00181 } 00182 echo '</table>'; 00183 echo $OUTPUT->box_end(); 00184 } 00185 00186 echo $OUTPUT->footer();