Annotation of loncom/interface/lonchatfetch.pm, revision 1.4

1.1       www         1: # The LearningOnline Network
                      2: # Chat Fetching
                      3: #
1.4     ! www         4: # $Id: lonchatfetch.pm,v 1.3 2002/08/14 16:24:00 www Exp $
1.1       www         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;
1.4     ! www        34: use Apache::loncommon;
        !            35: use Apache::lonnet;
1.1       www        36: 
                     37: sub handler {
                     38:     my $r = shift;
                     39:     $r->content_type('text/html');
                     40:     $r->send_http_header;
                     41:     return OK if $r->header_only;
                     42: 
                     43: # ------------------------------------------------------------ retrieve entries
                     44: 
                     45:     my $cnum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                     46:     my $cdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                     47:     my $chome=$ENV{'course.'.$ENV{'request.course.id'}.'.home'};
1.4     ! www        48: 
1.1       www        49:     my @entries=split(/\:/,
                     50:                        &Apache::lonnet::reply("chatretr:$cdom:$cnum",$chome));
                     51:     my ($lastid)=($entries[$#entries]=~/^(\w+)/);
                     52:     my ($thentime,$idnum)=split(/\_/,$lastid);
1.4     ! www        53: # ----------------------------------------------------------- Can see identity?
        !            54:     my $crs='/'.$ENV{'request.course.id'};
        !            55:     if ($ENV{'request.course.sec'}) {
        !            56:        $crs.='_'.$ENV{'request.course.sec'};
        !            57:     }                 
        !            58:     $crs=~s/\_/\//g;
        !            59:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.1       www        60: # -------------------------------------------------------- see which ones apply
                     61:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['lastid']);
                     62:     my $include=0;
                     63:     my $newstuff='';
1.3       www        64:     my $bottomid='';
1.2       www        65:     unless ($ENV{'form.lastid'}) { 
                     66:        $include=1; 
                     67:        $newstuff='<html><body bgcolor="#FFFFFF">';
                     68:     }
1.1       www        69:     foreach (@entries) {
                     70: 	if ($include) {
                     71:             my ($id,$msg)=split(/\:/,&Apache::lonnet::unescape($_));
                     72:             chomp($msg);
                     73:             my ($msgtime,$msgnum)=split(/\_/,$id);
                     74:             my ($sdom,$snum,$anon,$contrib)=split(/\:/,
                     75:                                               &Apache::lonnet::unescape($msg));
                     76:             $contrib=&Apache::lonnet::unescape($contrib);
                     77:             $contrib=~s/\n/\<br \/\>/g;
                     78: 	    $contrib=&Apache::lontexconvert::msgtexconverted($contrib);
                     79:             $contrib=~s/\n/ /g;
                     80:             $contrib=~s/\'/\&\#39\;/g;
1.4     ! www        81:             my $sender='';
        !            82:             unless (($anon) && (!$seeid)) {
        !            83:                $sender=&Apache::loncommon::plainname($snum,$sdom);
        !            84: 	        if ($anon) { $sender.=' [Anon]' };
        !            85:             } else {
        !            86: 		$sender=&Apache::loncommon::screenname($snum,$sdom);
        !            87:                 unless ($sender) { $sender="Anonymous"; }
1.1       www        88:             }
1.4     ! www        89:             $sender=~s/\'/\"/g;
        !            90:             my $color=$sender;
        !            91:             $color=~tr/a-j/0-9/;
        !            92:             $color=~tr/A-J/0-9/;
        !            93:             $color=~tr/k-t/0-9/;
        !            94:             $color=~tr/K-T/0-9/;
        !            95:             $color=~tr/u-z/0-5/;
        !            96:             $color=~tr/U-Z/0-5/;
        !            97:             $color=~s/\D//g;
        !            98:             $color=substr($color,0,6);
        !            99:             my $timestamp=localtime($msgtime);
        !           100:             my ($mhour,$mmin,$msec)=($timestamp=~/(\d\d)\:(\d\d)\:(\d\d)/);
        !           101: 	    $newstuff.='<font color="#'.$color.'"><a name="'.$id.'"><b>'.
        !           102:                        $sender.'</b> ('.$mhour.':'.$mmin.':'.$msec.'): '.
        !           103:                        $contrib."</font><br>";
1.3       www       104:             $bottomid=$id;
1.1       www       105:         } else {
                    106:             $_=~/^(\w+)/;
                    107:             if ($1 eq $ENV{'form.lastid'}) { $include=1; }
                    108:         }
                    109:     }
                    110:     $r->print(<<ENDDOCUMENT);
                    111: <html>
                    112: <head>
                    113: <title>The LearningOnline Network with CAPA</title>
                    114:   <meta HTTP-EQUIV="Refresh" CONTENT="5; url=/adm/chatfetch?lastid=$lastid">
                    115: </head>
                    116: <body bgcolor="#FFFFFF">
                    117: <script>
                    118: parent.chatout.document.writeln('$newstuff');
1.3       www       119: parent.chatout.scroll(0,10000000);
1.1       www       120: </script>
                    121: </body>
                    122: </html>
                    123: ENDDOCUMENT
                    124:     return OK;
                    125: } 
                    126: 
                    127: 1;
                    128: __END__

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