PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/mod/chat/gui_ajax/index.php

http://github.com/moodle/moodle
PHP | 110 lines | 84 code | 9 blank | 17 comment | 11 complexity | fd6f63556b30fc0b8db931507e5b41da MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  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. require_once('../../../config.php');
  17. require_once('../lib.php');
  18. $id = required_param('id', PARAM_INT);
  19. $groupid = optional_param('groupid', 0, PARAM_INT); // Only for teachers.
  20. $theme = optional_param('theme', 'course_theme', PARAM_SAFEDIR); // The value course_theme == the current theme.
  21. $url = new moodle_url('/mod/chat/gui_ajax/index.php', array('id' => $id));
  22. if ($groupid !== 0) {
  23. $url->param('groupid', $groupid);
  24. }
  25. $PAGE->set_url($url);
  26. $PAGE->set_popup_notification_allowed(false); // No popup notifications in the chat window.
  27. $PAGE->requires->strings_for_js(array('coursetheme', 'bubble', 'compact'), 'mod_chat');
  28. $chat = $DB->get_record('chat', array('id' => $id), '*', MUST_EXIST);
  29. $course = $DB->get_record('course', array('id' => $chat->course), '*', MUST_EXIST);
  30. $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id, false, MUST_EXIST);
  31. $context = context_module::instance($cm->id);
  32. require_login($course, false, $cm);
  33. require_capability('mod/chat:chat', $context);
  34. // Check to see if groups are being used here.
  35. if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used.
  36. if ($groupid = groups_get_activity_group($cm)) {
  37. if (!$group = groups_get_group($groupid)) {
  38. print_error('invalidgroupid');
  39. }
  40. $groupname = ': '.$group->name;
  41. } else {
  42. $groupname = ': '.get_string('allparticipants');
  43. }
  44. } else {
  45. $groupid = 0;
  46. $groupname = '';
  47. }
  48. // If requested theme doesn't exist, use default 'bubble' theme.
  49. if ($theme != 'course_theme' and !file_exists(__DIR__ . '/theme/'.$theme.'/chat.css')) {
  50. $theme = 'compact';
  51. }
  52. // Log into the chat room.
  53. if (!$chatsid = chat_login_user($chat->id, 'ajax', $groupid, $course)) {
  54. print_error('cantlogin', 'chat');
  55. }
  56. $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
  57. $module = array(
  58. 'name' => 'mod_chat_ajax', // Chat gui's are not real plugins, we have to break the naming standards for JS modules here.
  59. 'fullpath' => '/mod/chat/gui_ajax/module.js',
  60. 'requires' => array('base', 'dom', 'event', 'event-mouseenter', 'event-key', 'json-parse', 'io', 'overlay', 'yui2-resize',
  61. 'yui2-layout', 'yui2-menu'),
  62. 'strings' => array(array('send', 'chat'), array('sending', 'chat'), array('inputarea', 'chat'), array('userlist', 'chat'),
  63. array('modulename', 'chat'), array('beep', 'chat'), array('talk', 'chat'))
  64. );
  65. $modulecfg = array(
  66. 'home' => $CFG->wwwroot.'/mod/chat/view.php?id='.$cm->id,
  67. 'chaturl' => $CFG->wwwroot.'/mod/chat/gui_ajax/index.php?id='.$id,
  68. 'theme' => $theme,
  69. 'userid' => $USER->id,
  70. 'sid' => $chatsid,
  71. 'timer' => 3000,
  72. 'chat_lasttime' => 0,
  73. 'chat_lastrow' => null,
  74. 'chatroom_name' => $courseshortname . ": " . format_string($chat->name, true) . $groupname
  75. );
  76. $PAGE->requires->js_init_call('M.mod_chat_ajax.init', array($modulecfg), false, $module);
  77. $PAGE->set_title(get_string('modulename', 'chat').": $courseshortname: ".format_string($chat->name, true)."$groupname");
  78. $PAGE->add_body_class('yui-skin-sam');
  79. $PAGE->set_pagelayout('embedded');
  80. if ( $theme != 'course_theme') {
  81. $PAGE->requires->css('/mod/chat/gui_ajax/theme/'.$theme.'/chat.css');
  82. }
  83. echo $OUTPUT->header();
  84. echo $OUTPUT->box(html_writer::tag('h2', get_string('participants'), array('class' => 'accesshide')) .
  85. '<ul id="users-list" class="list-group"></ul>', '', 'chat-userlist');
  86. echo $OUTPUT->box('', '', 'chat-options');
  87. echo $OUTPUT->box(html_writer::tag('h2', get_string('messages', 'chat'), array('class' => 'accesshide')) .
  88. '<ul id="messages-list"></ul>', '', 'chat-messages');
  89. $table = new html_table();
  90. $table->data = array(
  91. array('<div class="form-inline"><label class="accesshide" for="input-message">'.get_string('entermessage', 'chat').' </label>'.
  92. '<span class="form-group"><input type="text" disabled="true" class="form-control" ' .
  93. 'id="input-message" value="Loading..." size="48" /></span>'.
  94. '<span class="form-group"><input type="button" id="button-send" class="btn btn-secondary mx-1" ' .
  95. 'value="'.get_string('send', 'chat').'" /></span> <span class="form-group"><a id="choosetheme" href="###">'.
  96. get_string('themes').
  97. ' &raquo; </a></span></div>'));
  98. echo $OUTPUT->box(html_writer::tag('h2', get_string('composemessage', 'chat'), array('class' => 'accesshide')) .
  99. html_writer::table($table), '', 'chat-input-area');
  100. echo $OUTPUT->box('', '', 'chat-notify');
  101. echo $OUTPUT->footer();