Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
/mod/chat/ -> view.php (source)

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

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