Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
/mod/chat/ -> view.php (source)

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   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(__DIR__.'/../../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  // Initialize $PAGE.
  62  $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
  63  $title = $courseshortname . ': ' . format_string($chat->name);
  64  $PAGE->set_url('/mod/chat/view.php', ['id' => $cm->id]);
  65  $PAGE->set_title($title);
  66  $PAGE->set_heading($course->fullname);
  67  $PAGE->add_body_class('limitedwidth');
  68  
  69  // Show some info for guests.
  70  if (isguestuser()) {
  71      echo $OUTPUT->header();
  72      echo $OUTPUT->confirm('<p>'.get_string('noguests', 'chat').'</p>'.get_string('liketologin'),
  73              get_login_url(), $CFG->wwwroot.'/course/view.php?id='.$course->id);
  74  
  75      echo $OUTPUT->footer();
  76      exit;
  77  }
  78  
  79  // Completion and trigger events.
  80  chat_view($chat, $course, $cm, $context);
  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  // Print the page header.
  88  echo $OUTPUT->header();
  89  
  90  // Check to see if groups are being used here.
  91  $groupmode = groups_get_activity_groupmode($cm);
  92  $currentgroup = groups_get_activity_group($cm, true);
  93  
  94  // URL parameters.
  95  $params = array();
  96  if ($currentgroup) {
  97      $groupselect = " AND groupid = '$currentgroup'";
  98      $groupparam = "_group{$currentgroup}";
  99      $params['groupid'] = $currentgroup;
 100  } else {
 101      $groupselect = "";
 102      $groupparam = "";
 103  }
 104  
 105  echo $OUTPUT->heading(format_string($chat->name), 2);
 106  
 107  // Render the activity information.
 108  $cminfo = cm_info::create($cm);
 109  $completiondetails = \core_completion\cm_completion_details::get_instance($cminfo, $USER->id);
 110  $activitydates = \core\activity_dates::get_dates_for_module($cminfo, $USER->id);
 111  echo $OUTPUT->activity_information($cminfo, $completiondetails, $activitydates);
 112  
 113  if ($chat->intro) {
 114      echo $OUTPUT->box(format_module_intro('chat', $chat, $cm->id), 'generalbox', 'intro');
 115  }
 116  
 117  groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/view.php?id=$cm->id");
 118  
 119  if (has_capability('mod/chat:chat', $context)) {
 120      // Print the main part of the page.
 121      echo $OUTPUT->box_start('generalbox', 'enterlink');
 122  
 123      $now = time();
 124      $chattime = $chat->chattime ?? 0;
 125      $span = $chattime - $now;
 126      if (!empty($chat->schedule) && $span > 0) {
 127          echo html_writer::tag('p', get_string('sessionstartsin', 'chat', format_time($span)));
 128      }
 129  
 130      $params['id'] = $chat->id;
 131      $chattarget = new moodle_url("/mod/chat/gui_$CFG->chat_method/index.php", $params);
 132      echo '<p>';
 133      echo $OUTPUT->action_link($chattarget,
 134                                $strenterchat,
 135                                new popup_action('click', $chattarget, "chat{$course->id}_{$chat->id}{$groupparam}",
 136                                                 array('height' => 500, 'width' => 700)));
 137      echo '</p>';
 138  
 139      $params['id'] = $chat->id;
 140      $link = new moodle_url('/mod/chat/gui_basic/index.php', $params);
 141      $action = new popup_action('click', $link, "chat{$course->id}_{$chat->id}{$groupparam}",
 142                                 array('height' => 500, 'width' => 700));
 143      echo '<p>';
 144      echo $OUTPUT->action_link($link, get_string('noframesjs', 'message'), $action,
 145                                array('title' => get_string('modulename', 'chat')));
 146      echo '</p>';
 147  
 148      if ($chat->studentlogs or has_capability('mod/chat:readlog', $context)) {
 149          if ($msg = chat_get_session_messages($chat->id, $currentgroup)) {
 150              echo '<p>';
 151              echo html_writer::link(new moodle_url('/mod/chat/report.php', array('id' => $cm->id)),
 152                                     get_string('viewreport', 'chat'));
 153              echo '</p>';
 154          }
 155      }
 156  
 157      echo $OUTPUT->box_end();
 158  
 159  } else {
 160      echo $OUTPUT->box_start('generalbox', 'notallowenter');
 161      echo '<p>'.get_string('notallowenter', 'chat').'</p>';
 162      echo $OUTPUT->box_end();
 163  }
 164  
 165  chat_delete_old_users();
 166  
 167  if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) {
 168      $timenow = time();
 169      echo $OUTPUT->box_start('generalbox', 'chatcurrentusers');
 170      echo $OUTPUT->heading($strcurrentusers, 3);
 171      echo '<table>';
 172      foreach ($chatusers as $chatuser) {
 173          $lastping = $timenow - $chatuser->lastmessageping;
 174          echo '<tr><td class="chatuserimage">';
 175          $url = new moodle_url('/user/view.php', array('id' => $chatuser->id, 'course' => $chat->course));
 176          echo html_writer::link($url, $OUTPUT->user_picture($chatuser));
 177          echo '</td><td class="chatuserdetails">';
 178          echo '<p>'.fullname($chatuser).'</p>';
 179          echo '<span class="idletime">'.$stridle.': '.format_time($lastping).'</span>';
 180          echo '</td></tr>';
 181      }
 182      echo '</table>';
 183      echo $OUTPUT->box_end();
 184  }
 185  
 186  echo $OUTPUT->footer();