[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/mod/chat/ -> view.php (source)

   1  <?php  // $Id: view.php,v 1.61.2.5 2008/10/08 07:51:40 dongsheng Exp $
   2  
   3  /// This page prints a particular instance of chat
   4  
   5      require_once('../../config.php');
   6      require_once ('lib.php');
   7      require_once($CFG->libdir.'/blocklib.php');
   8      require_once ('pagelib.php');
   9      
  10      $id   = optional_param('id', 0, PARAM_INT);
  11      $c    = optional_param('c', 0, PARAM_INT);
  12      $edit = optional_param('edit', -1, PARAM_BOOL);
  13  
  14      if ($id) {
  15          if (! $cm = get_coursemodule_from_id('chat', $id)) {
  16              error('Course Module ID was incorrect');
  17          }
  18  
  19          if (! $course = get_record('course', 'id', $cm->course)) {
  20              error('Course is misconfigured');
  21          }
  22  
  23          chat_update_chat_times($cm->instance);
  24  
  25          if (! $chat = get_record('chat', 'id', $cm->instance)) {
  26              error('Course module is incorrect');
  27          }
  28  
  29      } else {
  30          chat_update_chat_times($c);
  31  
  32          if (! $chat = get_record('chat', 'id', $c)) {
  33              error('Course module is incorrect');
  34          }
  35          if (! $course = get_record('course', 'id', $chat->course)) {
  36              error('Course is misconfigured');
  37          }
  38          if (! $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
  39              error('Course Module ID was incorrect');
  40          }
  41      }
  42  
  43  
  44      require_course_login($course, true, $cm);
  45      
  46      $context = get_context_instance(CONTEXT_MODULE, $cm->id);
  47      
  48      // show some info for guests
  49      if (isguestuser()) {
  50          $navigation = build_navigation('', $cm);
  51          print_header_simple(format_string($chat->name), '', $navigation,
  52                        '', '', true, '', navmenu($course, $cm));
  53          $wwwroot = $CFG->wwwroot.'/login/index.php';
  54          if (!empty($CFG->loginhttps)) {
  55              $wwwroot = str_replace('http:','https:', $wwwroot);
  56          }
  57  
  58          notice_yesno(get_string('noguests', 'chat').'<br /><br />'.get_string('liketologin'),
  59                  $wwwroot, $CFG->wwwroot.'/course/view.php?id='.$course->id);
  60  
  61          print_footer($course);
  62          exit;
  63  
  64      } else {
  65          require_capability('mod/chat:chat', $context);
  66      }
  67  
  68      add_to_log($course->id, 'chat', 'view', "view.php?id=$cm->id", $chat->id, $cm->id);
  69  
  70  // Initialize $PAGE, compute blocks
  71  
  72      $PAGE       = page_create_instance($chat->id);
  73      $pageblocks = blocks_setup($PAGE);
  74      $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
  75  
  76  /// Print the page header
  77  
  78      $strenterchat    = get_string('enterchat', 'chat');
  79      $stridle         = get_string('idle', 'chat');
  80      $strcurrentusers = get_string('currentusers', 'chat');
  81      $strnextsession  = get_string('nextsession', 'chat');
  82  
  83      if (($edit != -1) and $PAGE->user_allowed_editing()) {
  84          $USER->editing = $edit;
  85      }
  86  
  87      $PAGE->print_header($course->shortname.': %fullname%');
  88  
  89      echo '<table id="layout-table"><tr>';
  90  
  91      $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
  92      foreach ($lt as $column) {
  93          switch ($column) {
  94              case 'left':
  95  
  96                  if(!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
  97                      echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
  98                      print_container_start();
  99                      blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
 100                      print_container_end();
 101                      echo '</td>';
 102                  }
 103                  break;
 104  
 105              case 'middle':
 106  
 107                  echo '<td id="middle-column">';
 108                  print_container_start();
 109  
 110                  /// Check to see if groups are being used here
 111                  $groupmode = groups_get_activity_groupmode($cm);
 112                  $currentgroup = groups_get_activity_group($cm, true);
 113                  groups_print_activity_menu($cm, "view.php?id=$cm->id");
 114  
 115                  if ($currentgroup) {
 116                      $groupselect = " AND groupid = '$currentgroup'";
 117                      $groupparam = "&amp;groupid=$currentgroup";
 118                  } else {
 119                      $groupselect = "";
 120                      $groupparam = "";
 121                  }
 122  
 123                  if ($chat->studentlogs or has_capability('mod/chat:readlog',$context)) {
 124                      if ($msg = get_records_select('chat_messages', "chatid = '$chat->id' $groupselect", '', 'id', '', 1)) {
 125                          echo '<div class="reportlink">';
 126                          echo "<a href=\"report.php?id=$cm->id\">".
 127                              get_string('viewreport', 'chat').'</a>';
 128                          echo '</div>';
 129                      }
 130                  }
 131  
 132  
 133                  print_heading(format_string($chat->name));
 134  
 135                  /// Print the main part of the page
 136                  print_box_start('generalbox', 'enterlink');
 137                  // users with screenreader set, will only see 1 link, to the manual refresh page
 138                  // for better accessibility
 139                  if (!empty($USER->screenreader)) {
 140                      $chattarget = "/mod/chat/gui_basic/index.php?id=$chat->id$groupparam";
 141                  } else {
 142                      $chattarget = "/mod/chat/gui_$CFG->chat_method/index.php?id=$chat->id$groupparam"; 
 143                  }
 144  
 145                  echo '<p>';
 146                  link_to_popup_window ($chattarget,
 147                          "chat$course->id$chat->id$groupparam", "$strenterchat", 500, 700, get_string('modulename', 'chat'));
 148                  echo '</p>';
 149  
 150                  // if user is using screen reader, then there is no need to display this link again
 151                  if ($CFG->chat_method == 'header_js' && empty($USER->screenreader)) {
 152                      // show frame/js-less alternative
 153                      echo '<p>(';
 154                              link_to_popup_window ("/mod/chat/gui_basic/index.php?id=$chat->id$groupparam",
 155                                  "chat$course->id$chat->id$groupparam", get_string('noframesjs', 'message'), 500, 700, get_string('modulename', 'chat'));
 156                              echo ')</p>';
 157                  }
 158  
 159                  print_box_end();
 160  
 161  
 162                  if ($chat->chattime and $chat->schedule) {  // A chat is scheduled
 163                      echo "<p class=\"nextchatsession\">$strnextsession: ".userdate($chat->chattime).' ('.usertimezone($USER->timezone).')</p>';
 164                  } else {
 165                      echo '<br />';
 166                  }
 167  
 168                  if ($chat->intro) {
 169                      print_box(format_text($chat->intro), 'generalbox', 'intro');
 170                  }
 171  
 172                  chat_delete_old_users();
 173  
 174                  if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) {
 175                      $timenow = time();
 176                      print_simple_box_start('center');
 177                      print_heading($strcurrentusers);
 178                      echo '<table id="chatcurrentusers">';
 179                      foreach ($chatusers as $chatuser) {
 180                          $lastping = $timenow - $chatuser->lastmessageping;
 181                          echo '<tr><td class="chatuserimage">';
 182                          echo "<a href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$chat->course\">";
 183                          print_user_picture($chatuser, 0, $chatuser->picture, false, false, false);
 184                          echo '</a></td><td class="chatuserdetails">';
 185                          echo '<p>';
 186                          echo fullname($chatuser).'<br />';
 187                          echo "<span class=\"idletime\">$stridle: ".format_time($lastping)."</span>";
 188                          echo '</p>';
 189                          echo '</td></tr>';
 190                      }
 191                      echo '</table>';
 192                      print_simple_box_end();
 193                  }
 194  
 195                  print_container_end();
 196                  echo '</td>';
 197  
 198                  break;
 199          }
 200      }
 201      
 202      echo '</tr></table>';
 203  
 204      print_footer($course);
 205  
 206  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7