File:  [LON-CAPA] / loncom / interface / lonchatfetch.pm
Revision 1.6: download - view: text, annotated - select for diffs
Mon Sep 16 20:15:10 2002 UTC (21 years, 9 months ago) by www
Branches: MAIN
CVS tags: version_0_6_2, version_0_6, HEAD
Overload protection - frivolous to generate all of these hits if machine
overloaded.

    1: # The LearningOnline Network
    2: # Chat Fetching
    3: #
    4: # $Id: lonchatfetch.pm,v 1.6 2002/09/16 20:15:10 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);
   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("chatretr:$cdom:$cnum",$chome));
   59:     my ($lastid)=($entries[$#entries]=~/^(\w+)/);
   60:     my ($thentime,$idnum)=split(/\_/,$lastid);
   61: # ----------------------------------------------------------- Can see identity?
   62:     my $crs='/'.$ENV{'request.course.id'};
   63:     if ($ENV{'request.course.sec'}) {
   64:        $crs.='_'.$ENV{'request.course.sec'};
   65:     }                 
   66:     $crs=~s/\_/\//g;
   67:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
   68: # -------------------------------------------------------- see which ones apply
   69:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['lastid']);
   70:     my $include=0;
   71:     my $newstuff='';
   72:     my $bottomid='';
   73:     unless ($ENV{'form.lastid'}) { 
   74:        $include=1; 
   75:        $newstuff='<html><body bgcolor="#FFFFFF">';
   76:     }
   77:     foreach (@entries) {
   78: 	if ($include) {
   79:             my ($id,$msg)=split(/\:/,&Apache::lonnet::unescape($_));
   80:             chomp($msg);
   81:             my ($msgtime,$msgnum)=split(/\_/,$id);
   82:             my ($sdom,$snum,$anon,$contrib)=split(/\:/,
   83:                                               &Apache::lonnet::unescape($msg));
   84:             $contrib=&Apache::lonnet::unescape($contrib);
   85:             $contrib=~s/\n/\<br \/\>/g;
   86: 	    $contrib=&Apache::lontexconvert::msgtexconverted($contrib);
   87:             $contrib=~s/\n/ /g;
   88:             $contrib=~s/\'/\&\#39\;/g;
   89:             my $sender='';
   90:             if ($seeid) {
   91:                $sender=&Apache::loncommon::plainname($snum,$sdom);
   92:                my $nick=&Apache::loncommon::nickname($snum,$sdom);
   93:                if (($nick) && ($nick ne $sender)) {
   94: 		   $sender.=' '.$nick;
   95:                }
   96: 	       if ($anon) { $sender.=' [Anon]' };
   97:             } elsif (!$anon) {
   98:                $sender=&Apache::loncommon::nickname($snum,$sdom);
   99:             } else {
  100: 		$sender=&Apache::loncommon::screenname($snum,$sdom);
  101:                 unless ($sender) { $sender="Anonymous"; }
  102:             }
  103:             $sender=~s/\'/\"/g;
  104:             my $color=$sender;
  105:             $color=~tr/a-j/0-9/;
  106:             $color=~tr/A-J/0-9/;
  107:             $color=~tr/k-t/0-9/;
  108:             $color=~tr/K-T/0-9/;
  109:             $color=~tr/u-z/0-5/;
  110:             $color=~tr/U-Z/0-5/;
  111:             $color=~s/\D//g;
  112:             $color=substr($color,0,6);
  113:             my $timestamp=localtime($msgtime);
  114:             my ($mhour,$mmin,$msec)=($timestamp=~/(\d\d)\:(\d\d)\:(\d\d)/);
  115: 	    $newstuff.='<font color="#'.$color.'"><a name="'.$id.'"><b>'.
  116:                        $sender.'</b> ('.$mhour.':'.$mmin.':'.$msec.'): '.
  117:                        $contrib."</font><br>";
  118:             $bottomid=$id;
  119:         } else {
  120:             $_=~/^(\w+)/;
  121:             if ($1 eq $ENV{'form.lastid'}) { $include=1; }
  122:         }
  123:     }
  124:     $r->print(<<ENDDOCUMENT);
  125: <html>
  126: <head>
  127: <title>The LearningOnline Network with CAPA</title>
  128:   <meta HTTP-EQUIV="Refresh" CONTENT="5; url=/adm/chatfetch?lastid=$lastid">
  129: </head>
  130: <body bgcolor="#FFFFFF">
  131: <script>
  132: parent.chatout.document.writeln('$newstuff');
  133: parent.chatout.scroll(0,10000000);
  134: </script>
  135: </body>
  136: </html>
  137: ENDDOCUMENT
  138:     return OK;
  139: } 
  140: 
  141: 1;
  142: __END__

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