|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 require_once('../../../config.php'); 00003 require_once('../lib.php'); 00004 00005 $id = required_param('id', PARAM_INT); 00006 $groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers 00007 $theme = optional_param('theme', 'compact', PARAM_SAFEDIR); 00008 00009 $url = new moodle_url('/mod/chat/gui_ajax/index.php', array('id'=>$id)); 00010 if ($groupid !== 0) { 00011 $url->param('groupid', $groupid); 00012 } 00013 $PAGE->set_url($url); 00014 00015 $chat = $DB->get_record('chat', array('id'=>$id), '*', MUST_EXIST); 00016 $course = $DB->get_record('course', array('id'=>$chat->course), '*', MUST_EXIST); 00017 $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id, false, MUST_EXIST); 00018 00019 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00020 require_login($course->id, false, $cm); 00021 require_capability('mod/chat:chat', $context); 00022 00024 if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used 00025 if ($groupid = groups_get_activity_group($cm)) { 00026 if (!$group = groups_get_group($groupid)) { 00027 print_error('invalidgroupid'); 00028 } 00029 $groupname = ': '.$group->name; 00030 } else { 00031 $groupname = ': '.get_string('allparticipants'); 00032 } 00033 } else { 00034 $groupid = 0; 00035 $groupname = ''; 00036 } 00037 00038 // if requested theme doesn't exist, use default 'bubble' theme 00039 if (!file_exists(dirname(__FILE__) . '/theme/'.$theme.'/chat.css')) { 00040 $theme = 'compact'; 00041 } 00042 00043 // login chat room 00044 if (!$chat_sid = chat_login_user($chat->id, 'ajax', $groupid, $course)) { 00045 print_error('cantlogin', 'chat'); 00046 } 00047 $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))); 00048 $module = array( 00049 'name' => 'mod_chat_ajax', // chat gui's are not real plugins, we have to break the naming standards for JS modules here :-( 00050 'fullpath' => '/mod/chat/gui_ajax/module.js', 00051 'requires' => array('base', 'dom', 'event', 'event-mouseenter', 'event-key', 'json-parse', 'io', 'overlay', 'yui2-resize', 'yui2-layout', 'yui2-menu'), 00052 'strings' => array(array('send', 'chat'), array('sending', 'chat'), array('inputarea', 'chat'), array('userlist', 'chat'), 00053 array('modulename', 'chat'), array('beep', 'chat'), array('talk', 'chat')) 00054 ); 00055 $modulecfg = array( 00056 'home'=>$CFG->httpswwwroot.'/mod/chat/view.php?id='.$cm->id, 00057 'chaturl'=>$CFG->httpswwwroot.'/mod/chat/gui_ajax/index.php?id='.$id, 00058 'theme'=>$theme, 00059 'userid'=>$USER->id, 00060 'sid'=>$chat_sid, 00061 'timer'=>3000, 00062 'chat_lasttime'=>0, 00063 'chat_lastrow'=>null, 00064 'chatroom_name' => $courseshortname . ": " . format_string($chat->name, true) . $groupname 00065 ); 00066 $PAGE->requires->js_init_call('M.mod_chat_ajax.init', array($modulecfg), false, $module); 00067 00068 $PAGE->set_title(get_string('modulename', 'chat').": $courseshortname: ".format_string($chat->name,true)."$groupname"); 00069 $PAGE->add_body_class('yui-skin-sam'); 00070 $PAGE->set_pagelayout('embedded'); 00071 $PAGE->requires->css('/mod/chat/gui_ajax/theme/'.$theme.'/chat.css'); 00072 00073 echo $OUTPUT->header(); 00074 echo $OUTPUT->box('<ul id="users-list"></ul>', '', 'chat-userlist'); 00075 echo $OUTPUT->box('', '', 'chat-options'); 00076 echo $OUTPUT->box('<ul id="messages-list"></ul>', '', 'chat-messages'); 00077 $table = new html_table(); 00078 $table->data = array( 00079 array(' » <input type="text" disabled="true" id="input-message" value="Loading..." size="50" /> <input type="button" id="button-send" value="'.get_string('send', 'chat').'" /> <a id="choosetheme" href="###">'.get_string('themes').' » </a>') 00080 ); 00081 echo $OUTPUT->box(html_writer::table($table), '', 'chat-input-area'); 00082 echo $OUTPUT->box('', '', 'chat-notify'); 00083 echo $OUTPUT->footer();