File:  [LON-CAPA] / loncom / interface / lonchatfetch.pm
Revision 1.14: download - view: text, annotated - select for diffs
Sun Jun 27 17:36:57 2004 UTC (19 years, 10 months ago) by www
Branches: MAIN
CVS tags: version_1_3_X, version_1_3_3, version_1_3_2, version_1_3_1, version_1_3_0, version_1_2_X, version_1_2_99_1, version_1_2_99_0, version_1_2_1, version_1_2_0, version_1_1_99_5, version_1_1_99_4, version_1_1_99_3, version_1_1_99_2, version_1_1_99_1, HEAD
Bug #3086: show username in CHAT for nameless folks

    1: # The LearningOnline Network
    2: # Chat Fetching
    3: #
    4: # $Id: lonchatfetch.pm,v 1.14 2004/06/27 17:36:57 www 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 :http);
   33: use Apache::lontexconvert;
   34: use Apache::loncommon;
   35: use Apache::lonnet;
   36: 
   37: sub handler {
   38:     my $r = shift;
   39: 
   40:     if (! &Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
   41:              ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))
   42:         ) {
   43:         return HTTP_NOT_ACCEPTABLE;
   44:     }
   45: 
   46:     my $loaderror=&Apache::lonnet::overloaderror($r);
   47:     if ($loaderror) { return $loaderror; }
   48:     $loaderror=
   49:        &Apache::lonnet::overloaderror($r,
   50:          $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
   51:     if ($loaderror) { return $loaderror; }
   52: 
   53:     $r->content_type('text/html');
   54:     $r->send_http_header;
   55:     return OK if $r->header_only;
   56: 
   57: # ------------------------------------------------------------ retrieve entries
   58: 
   59:     my $cnum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
   60:     my $cdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
   61:     my $chome=$ENV{'course.'.$ENV{'request.course.id'}.'.home'};
   62: 
   63:     my @entries=split(/\:/,
   64:        &Apache::lonnet::reply(
   65:         "chatretr:$cdom:$cnum:$ENV{'user.domain'}:$ENV{'user.name'}",$chome));
   66: # Figure out what the last valid entry-id is
   67:     my ($lastid,$thentime,$idnum);
   68:     foreach (@entries) {
   69: 	$_=~/^(\w+)/;
   70:         if ($1 ne 'active_participant') {
   71: 	    $lastid=$1;
   72:             ($thentime,$idnum)=split(/\_/,$lastid);
   73: 	}
   74:     }
   75: # ----------------------------------------------------------- Can see identity?
   76:     my $crs='/'.$ENV{'request.course.id'};
   77:     if ($ENV{'request.course.sec'}) {
   78:        $crs.='_'.$ENV{'request.course.sec'};
   79:     }                 
   80:     $crs=~s/\_/\//g;
   81:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
   82: # -------------------------------------------------------- see which ones apply
   83:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['lastid']);
   84:     my $include=0;
   85:     my $newstuff='';
   86:     my $bottomid='';
   87:     unless ($ENV{'form.lastid'}) { 
   88:        $include=1; 
   89:        $newstuff='<html><body bgcolor="#FFFFFF">';
   90:     }
   91:     my @participants=();
   92:     foreach (@entries) {
   93: 	my ($id,$msg,$udom)=split(/\:/,&Apache::lonnet::unescape($_));
   94:  	if ($id eq 'active_participant') {
   95:            chomp($udom);
   96: 	   my $participant= &Apache::loncommon::nickname($msg,$udom);
   97: 	   unless ($participant=~/\w/) { $participant=$msg.'@'.$udom; }
   98: 	   $participants[$#participants+1]=$participant;
   99: 	} elsif ($include) {
  100: 	    chomp($msg);
  101: 	    my ($msgtime,$msgnum)=split(/\_/,$id);
  102: 	    my ($sdom,$snum,$anon,$contrib)=split(/\:/,
  103: 					     &Apache::lonnet::unescape($msg));
  104: 	    $contrib=&Apache::lonnet::unescape($contrib);
  105: 	    $contrib=~s/\n/\<br \/\>/g;
  106: 	    ($contrib,my $errors)=&Apache::lontexconvert::msgtexconverted($contrib);
  107: 	    if ($errors) { $contrib.="[Message not fully displayed due to incorrect embedded TeX]"; }
  108: 	    if ($errors && $snum eq $ENV{'user.name'} &&
  109: 		$sdom eq $ENV{'user.domain'} ) {
  110: 		$contrib.="<br />[TeX error message: $errors]";
  111: 	    }
  112: 	    $contrib=~s/\n/ /g;
  113: 	    $contrib=~s/\'/\&\#39\;/g;
  114: 	    my $sender='';
  115: 	    if ($seeid) {
  116: 		$sender=&Apache::loncommon::plainname($snum,$sdom);
  117: 		my $nick=&Apache::loncommon::nickname($snum,$sdom);
  118: 		if (($nick) && ($nick ne $sender)) {
  119: 		    $sender.=' '.$nick;
  120: 		}
  121: 		unless ($sender) { $sender=$snum.'@'.$sdom; }
  122: 		if ($anon) { $sender.=' [Anon]' };
  123: 	    } elsif (!$anon) {
  124: 		$sender=&Apache::loncommon::nickname($snum,$sdom);
  125: 		unless ($sender) { $sender=$snum.'@'.$sdom; }
  126: 	    } else {
  127: 		$sender=&Apache::loncommon::screenname($snum,$sdom);
  128: 		unless ($sender) { $sender="Anonymous"; }
  129: 	    }
  130: 	    $sender=~s/\'/\&\#39\;/g;
  131: 	    my $color=$sender;
  132: 	    $color=~tr/a-j/0-9/;
  133: 	    $color=~tr/A-J/0-9/;
  134: 	    $color=~tr/k-t/0-9/;
  135: 	    $color=~tr/K-T/0-9/;
  136: 	    $color=~tr/u-z/0-5/;
  137: 	    $color=~tr/U-Z/0-5/;
  138: 	    $color=~s/\D//g;
  139: 	    $color=substr($color,0,6);
  140: 	    my $timestamp=localtime($msgtime);
  141: 	    my ($mhour,$mmin,$msec)=($timestamp=~/(\d\d)\:(\d\d)\:(\d\d)/);
  142: 	    $newstuff.='<font color="#'.$color.'"><a name="'.$id.'"><b>'.
  143: 		$sender.'</b> ('.$mhour.':'.$mmin.':'.$msec.'): '.
  144: 		$contrib."</font><br>";
  145: 	    $bottomid=$id;
  146: 	} else {
  147: 	    $_=~/^(\w+)/;
  148: 	    if ($1 eq $ENV{'form.lastid'}) { $include=1; }
  149: 	}
  150:     }
  151:     my $participant_output=join('<br />',sort @participants);
  152:     $r->print(<<ENDDOCUMENT);
  153: <html>
  154: <head>
  155: <title>The LearningOnline Network with CAPA</title>
  156:   <meta HTTP-EQUIV="Refresh" CONTENT="5; url=/adm/chatfetch?lastid=$lastid">
  157: </head>
  158: <body bgcolor="#FFFFFF">
  159: <script>
  160: parent.chatout.document.writeln('$newstuff');
  161: parent.chatout.scroll(0,10000000);
  162: </script>
  163: $participant_output
  164: </body>
  165: </html>
  166: ENDDOCUMENT
  167:     return OK;
  168: } 
  169: 
  170: 1;
  171: __END__

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