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

1.1       www         1: # The LearningOnline Network
                      2: # Chat Fetching
                      3: #
1.26    ! albertel    4: # $Id: lonchatfetch.pm,v 1.25 2006/05/30 12:46:08 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;
1.12      matthew    32: use Apache::Constants qw(:common :http);
1.1       www        33: use Apache::lontexconvert;
1.4       www        34: use Apache::loncommon;
                     35: use Apache::lonnet;
1.24      raeburn    36: use Apache::longroup;
1.25      www        37: use lib '/home/httpd/lib/perl/';
                     38: use LONCAPA;
                     39:  
1.1       www        40: 
                     41: sub handler {
                     42:     my $r = shift;
1.12      matthew    43: 
1.22      albertel   44:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     45: 					    ['lastid','group']);
1.21      raeburn    46:     my ($group,$grouptitle);
                     47:     my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
                     48:     my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                     49:     if (defined($env{'form.group'})) {
                     50:         $group = $env{'form.group'};
                     51:         if (! &Apache::lonnet::allowed('pgc',$env{'request.course.id'}.'/'.
1.22      albertel   52: 				       $group) ) {
1.21      raeburn    53:             return HTTP_NOT_ACCEPTABLE;
                     54:         }
1.24      raeburn    55:         my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
1.23      albertel   56:         if (%curr_groups) {
1.22      albertel   57:             my %group_info = 
1.24      raeburn    58: 		&Apache::longroup::get_group_settings($curr_groups{$group});
1.22      albertel   59:             $grouptitle = 
1.25      www        60: 		'<b>'.&unescape($group_info{description}).
1.22      albertel   61: 		'</b><br />';
1.21      raeburn    62:         }
                     63:     } elsif (! &Apache::lonnet::allowed('pch',$env{'request.course.id'}.
1.17      albertel   64:              ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.12      matthew    65:         ) {
                     66:         return HTTP_NOT_ACCEPTABLE;
                     67:     }
1.6       www        68: 
                     69:     my $loaderror=&Apache::lonnet::overloaderror($r);
                     70:     if ($loaderror) { return $loaderror; }
                     71:     $loaderror=
                     72:        &Apache::lonnet::overloaderror($r,
1.17      albertel   73:          $env{'course.'.$env{'request.course.id'}.'.home'});
1.6       www        74:     if ($loaderror) { return $loaderror; }
                     75: 
1.16      albertel   76:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        77:     $r->send_http_header;
                     78:     return OK if $r->header_only;
                     79: 
                     80: # ------------------------------------------------------------ retrieve entries
                     81: 
1.17      albertel   82:     my $chome=$env{'course.'.$env{'request.course.id'}.'.home'};
1.4       www        83: 
1.1       www        84:     my @entries=split(/\:/,
1.8       www        85:        &Apache::lonnet::reply(
1.21      raeburn    86:         "chatretr:$cdom:$cnum:$env{'user.domain'}:$env{'user.name'}:$group",
                     87:         $chome));
1.10      www        88: # Figure out what the last valid entry-id is
                     89:     my ($lastid,$thentime,$idnum);
                     90:     foreach (@entries) {
                     91: 	$_=~/^(\w+)/;
                     92:         if ($1 ne 'active_participant') {
                     93: 	    $lastid=$1;
                     94:             ($thentime,$idnum)=split(/\_/,$lastid);
                     95: 	}
                     96:     }
1.4       www        97: # ----------------------------------------------------------- Can see identity?
1.21      raeburn    98:     my $seeid = &get_seeid_status();
1.1       www        99: # -------------------------------------------------------- see which ones apply
                    100:     my $include=0;
                    101:     my $newstuff='';
1.3       www       102:     my $bottomid='';
1.17      albertel  103:     unless ($env{'form.lastid'}) { 
1.20      albertel  104: 	$include=1; 
                    105: 	$newstuff .=
                    106: 	    &Apache::loncommon::start_page(undef,undef,
                    107: 					   {'only_body' => 1,
                    108: 					    'bgcolor'   => '#FFFFFF',
                    109: 					    'js_ready'  => 1,});
1.26    ! albertel  110: 	# removing the CSS reference for now
        !           111: 	# see BUG# 4839
        !           112:         # to fix, need to either write the whole webpage to the bottom frame
        !           113:         # everytime or store the page in a js variable somewhere.
        !           114: 	$newstuff =~ s|(<link.*?/>)||;
1.2       www       115:     }
1.9       www       116:     my @participants=();
1.1       www       117:     foreach (@entries) {
1.25      www       118: 	my ($id,$msg,$udom)=split(/\:/,&unescape($_));
1.9       www       119:  	if ($id eq 'active_participant') {
                    120:            chomp($udom);
1.14      www       121: 	   my $participant= &Apache::loncommon::nickname($msg,$udom);
                    122: 	   unless ($participant=~/\w/) { $participant=$msg.'@'.$udom; }
                    123: 	   $participants[$#participants+1]=$participant;
1.9       www       124: 	} elsif ($include) {
                    125: 	    chomp($msg);
                    126: 	    my ($msgtime,$msgnum)=split(/\_/,$id);
                    127: 	    my ($sdom,$snum,$anon,$contrib)=split(/\:/,
1.25      www       128: 					     &unescape($msg));
                    129: 	    $contrib=&unescape($contrib);
1.18      albertel  130: 	    &Apache::lonfeedback::newline_to_br(\$contrib);
1.11      albertel  131: 	    ($contrib,my $errors)=&Apache::lontexconvert::msgtexconverted($contrib);
                    132: 	    if ($errors) { $contrib.="[Message not fully displayed due to incorrect embedded TeX]"; }
1.17      albertel  133: 	    if ($errors && $snum eq $env{'user.name'} &&
                    134: 		$sdom eq $env{'user.domain'} ) {
1.11      albertel  135: 		$contrib.="<br />[TeX error message: $errors]";
                    136: 	    }
1.9       www       137: 	    $contrib=~s/\n/ /g;
                    138: 	    $contrib=~s/\'/\&\#39\;/g;
                    139: 	    my $sender='';
                    140: 	    if ($seeid) {
                    141: 		$sender=&Apache::loncommon::plainname($snum,$sdom);
                    142: 		my $nick=&Apache::loncommon::nickname($snum,$sdom);
                    143: 		if (($nick) && ($nick ne $sender)) {
                    144: 		    $sender.=' '.$nick;
                    145: 		}
1.14      www       146: 		unless ($sender) { $sender=$snum.'@'.$sdom; }
1.9       www       147: 		if ($anon) { $sender.=' [Anon]' };
                    148: 	    } elsif (!$anon) {
                    149: 		$sender=&Apache::loncommon::nickname($snum,$sdom);
1.14      www       150: 		unless ($sender) { $sender=$snum.'@'.$sdom; }
1.7       www       151: 	    } else {
1.9       www       152: 		$sender=&Apache::loncommon::screenname($snum,$sdom);
                    153: 		unless ($sender) { $sender="Anonymous"; }
1.7       www       154: 	    }
1.13      www       155: 	    $sender=~s/\'/\&\#39\;/g;
1.9       www       156: 	    my $color=$sender;
                    157: 	    $color=~tr/a-j/0-9/;
                    158: 	    $color=~tr/A-J/0-9/;
                    159: 	    $color=~tr/k-t/0-9/;
                    160: 	    $color=~tr/K-T/0-9/;
                    161: 	    $color=~tr/u-z/0-5/;
                    162: 	    $color=~tr/U-Z/0-5/;
                    163: 	    $color=~s/\D//g;
                    164: 	    $color=substr($color,0,6);
                    165: 	    my $timestamp=localtime($msgtime);
                    166: 	    my ($mhour,$mmin,$msec)=($timestamp=~/(\d\d)\:(\d\d)\:(\d\d)/);
1.26    ! albertel  167: 	    $newstuff.='<font color="#'.$color.'"><a name="LC_'.$id.'"></a><b>'.
1.9       www       168: 		$sender.'</b> ('.$mhour.':'.$mmin.':'.$msec.'): '.
1.26    ! albertel  169: 		$contrib."</font><br />";
        !           170: 	    $bottomid='LC_'.$id;
1.9       www       171: 	} else {
                    172: 	    $_=~/^(\w+)/;
1.17      albertel  173: 	    if ($1 eq $env{'form.lastid'}) { $include=1; }
1.9       www       174: 	}
1.1       www       175:     }
1.9       www       176:     my $participant_output=join('<br />',sort @participants);
1.21      raeburn   177:     my $refresh_cmd = "/adm/chatfetch?lastid=$lastid";
                    178:     if (defined($group)) {
1.26    ! albertel  179:         $refresh_cmd .= "&amp;group=$group";
1.21      raeburn   180:     }
1.19      albertel  181:     my $start_page = 
                    182: 	&Apache::loncommon::start_page('Chat',undef,
1.21      raeburn   183: 				       {'redirect'  => [5,$refresh_cmd],
1.19      albertel  184: 					'only_body' => 1,});
                    185:     my $end_page = &Apache::loncommon::end_page();
1.1       www       186:     $r->print(<<ENDDOCUMENT);
1.19      albertel  187: $start_page
                    188: <script type="text/javascript">
1.1       www       189: parent.chatout.document.writeln('$newstuff');
1.3       www       190: parent.chatout.scroll(0,10000000);
1.1       www       191: </script>
1.21      raeburn   192: $grouptitle
1.9       www       193: $participant_output
1.19      albertel  194: $end_page
1.1       www       195: ENDDOCUMENT
                    196:     return OK;
1.21      raeburn   197: }
                    198: 
1.22      albertel  199: sub get_seeid_status {
1.21      raeburn   200:     my $crs='/'.$env{'request.course.id'};
                    201:     my $seeid;
                    202:     if (exists($env{'form.group'})) {
                    203:         $seeid = &Apache::lonnet::allowed('rci',$crs.'/'.$env{'form.group'});
                    204:     } else {
                    205:         if ($env{'request.course.sec'}) {
                    206:             $crs.='_'.$env{'request.course.sec'};
                    207:         }
                    208:         $crs=~s/\_/\//g;
                    209:         $seeid=&Apache::lonnet::allowed('rin',$crs);
                    210:     }
                    211:     return $seeid;
                    212: }
1.1       www       213: 
                    214: 1;
                    215: __END__

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