File:  [LON-CAPA] / loncom / interface / lonchatfetch.pm
Revision 1.11: download - view: text, annotated - select for diffs
Mon Jun 23 21:30:42 2003 UTC (21 years ago) by albertel
Branches: MAIN
CVS tags: version_0_99_3, HEAD
- BUG# 1779, if TeX throws errors in chat mode show a generic error message to all, show the tTex error messages to the person who wrote it.

    1: # The LearningOnline Network
    2: # Chat Fetching
    3: #
    4: # $Id: lonchatfetch.pm,v 1.11 2003/06/23 21:30:42 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::lonchatfetch;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common);
   33: use Apache::lontexconvert;
   34: use Apache::loncommon;
   35: use Apache::lonnet;
   36: 
   37: sub handler {
   38:     my $r = shift;
   39: 
   40:     my $loaderror=&Apache::lonnet::overloaderror($r);
   41:     if ($loaderror) { return $loaderror; }
   42:     $loaderror=
   43:        &Apache::lonnet::overloaderror($r,
   44:          $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
   45:     if ($loaderror) { return $loaderror; }
   46: 
   47:     $r->content_type('text/html');
   48:     $r->send_http_header;
   49:     return OK if $r->header_only;
   50: 
   51: # ------------------------------------------------------------ retrieve entries
   52: 
   53:     my $cnum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
   54:     my $cdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
   55:     my $chome=$ENV{'course.'.$ENV{'request.course.id'}.'.home'};
   56: 
   57:     my @entries=split(/\:/,
   58:        &Apache::lonnet::reply(
   59:         "chatretr:$cdom:$cnum:$ENV{'user.domain'}:$ENV{'user.name'}",$chome));
   60: # Figure out what the last valid entry-id is
   61:     my ($lastid,$thentime,$idnum);
   62:     foreach (@entries) {
   63: 	$_=~/^(\w+)/;
   64:         if ($1 ne 'active_participant') {
   65: 	    $lastid=$1;
   66:             ($thentime,$idnum)=split(/\_/,$lastid);
   67: 	}
   68:     }
   69: # ----------------------------------------------------------- Can see identity?
   70:     my $crs='/'.$ENV{'request.course.id'};
   71:     if ($ENV{'request.course.sec'}) {
   72:        $crs.='_'.$ENV{'request.course.sec'};
   73:     }                 
   74:     $crs=~s/\_/\//g;
   75:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
   76: # -------------------------------------------------------- see which ones apply
   77:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['lastid']);
   78:     my $include=0;
   79:     my $newstuff='';
   80:     my $bottomid='';
   81:     unless ($ENV{'form.lastid'}) { 
   82:        $include=1; 
   83:        $newstuff='<html><body bgcolor="#FFFFFF">';
   84:     }
   85:     my @participants=();
   86:     foreach (@entries) {
   87: 	my ($id,$msg,$udom)=split(/\:/,&Apache::lonnet::unescape($_));
   88:  	if ($id eq 'active_participant') {
   89:            chomp($udom);
   90: 	   $participants[$#participants+1]=
   91:            &Apache::loncommon::nickname($msg,$udom);
   92: 	} elsif ($include) {
   93: 	    chomp($msg);
   94: 	    my ($msgtime,$msgnum)=split(/\_/,$id);
   95: 	    my ($sdom,$snum,$anon,$contrib)=split(/\:/,
   96: 					     &Apache::lonnet::unescape($msg));
   97: 	    $contrib=&Apache::lonnet::unescape($contrib);
   98: 	    $contrib=~s/\n/\<br \/\>/g;
   99: 	    ($contrib,my $errors)=&Apache::lontexconvert::msgtexconverted($contrib);
  100: 	    if ($errors) { $contrib.="[Message not fully displayed due to incorrect embedded TeX]"; }
  101: 	    if ($errors && $snum eq $ENV{'user.name'} &&
  102: 		$sdom eq $ENV{'user.domain'} ) {
  103: 		$contrib.="<br />[TeX error message: $errors]";
  104: 	    }
  105: 	    $contrib=~s/\n/ /g;
  106: 	    $contrib=~s/\'/\&\#39\;/g;
  107: 	    my $sender='';
  108: 	    if ($seeid) {
  109: 		$sender=&Apache::loncommon::plainname($snum,$sdom);
  110: 		my $nick=&Apache::loncommon::nickname($snum,$sdom);
  111: 		if (($nick) && ($nick ne $sender)) {
  112: 		    $sender.=' '.$nick;
  113: 		}
  114: 		if ($anon) { $sender.=' [Anon]' };
  115: 	    } elsif (!$anon) {
  116: 		$sender=&Apache::loncommon::nickname($snum,$sdom);
  117: 	    } else {
  118: 		$sender=&Apache::loncommon::screenname($snum,$sdom);
  119: 		unless ($sender) { $sender="Anonymous"; }
  120: 	    }
  121: 	    $sender=~s/\'/\"/g;
  122: 	    my $color=$sender;
  123: 	    $color=~tr/a-j/0-9/;
  124: 	    $color=~tr/A-J/0-9/;
  125: 	    $color=~tr/k-t/0-9/;
  126: 	    $color=~tr/K-T/0-9/;
  127: 	    $color=~tr/u-z/0-5/;
  128: 	    $color=~tr/U-Z/0-5/;
  129: 	    $color=~s/\D//g;
  130: 	    $color=substr($color,0,6);
  131: 	    my $timestamp=localtime($msgtime);
  132: 	    my ($mhour,$mmin,$msec)=($timestamp=~/(\d\d)\:(\d\d)\:(\d\d)/);
  133: 	    $newstuff.='<font color="#'.$color.'"><a name="'.$id.'"><b>'.
  134: 		$sender.'</b> ('.$mhour.':'.$mmin.':'.$msec.'): '.
  135: 		$contrib."</font><br>";
  136: 	    $bottomid=$id;
  137: 	} else {
  138: 	    $_=~/^(\w+)/;
  139: 	    if ($1 eq $ENV{'form.lastid'}) { $include=1; }
  140: 	}
  141:     }
  142:     my $participant_output=join('<br />',sort @participants);
  143:     $r->print(<<ENDDOCUMENT);
  144: <html>
  145: <head>
  146: <title>The LearningOnline Network with CAPA</title>
  147:   <meta HTTP-EQUIV="Refresh" CONTENT="5; url=/adm/chatfetch?lastid=$lastid">
  148: </head>
  149: <body bgcolor="#FFFFFF">
  150: <script>
  151: parent.chatout.document.writeln('$newstuff');
  152: parent.chatout.scroll(0,10000000);
  153: </script>
  154: $participant_output
  155: </body>
  156: </html>
  157: ENDDOCUMENT
  158:     return OK;
  159: } 
  160: 
  161: 1;
  162: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>