[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/chat/gui_ajax/ -> index.php (source)

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1