File:  [LON-CAPA] / loncom / interface / lonchatfetch.pm
Revision 1.32: download - view: text, annotated - select for diffs
Wed Nov 29 19:45:55 2006 UTC (17 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_8_X, version_2_8_2, version_2_8_1, version_2_8_0, version_2_7_X, version_2_7_99_1, version_2_7_99_0, version_2_7_1, version_2_7_0, version_2_6_X, version_2_6_99_1, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_X, version_2_5_99_1, version_2_5_99_0, version_2_5_2, version_2_5_1, version_2_5_0, version_2_4_X, version_2_4_99_0, version_2_4_2, version_2_4_1, version_2_4_0, version_2_3_X, version_2_3_99_0, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_99_1, version_2_2_99_0, HEAD, GCI_1
Eliminate $_

Replace @ with : as separator between username and domain

Enable blocking of display of chat during communication blocks.

    1: # The LearningOnline Network
    2: # Chat Fetching
    3: #
    4: # $Id: lonchatfetch.pm,v 1.32 2006/11/29 19:45:55 raeburn 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: use Apache::longroup;
   37: use Apache::lonlocal;
   38: use lib '/home/httpd/lib/perl/';
   39: use LONCAPA;
   40:  
   41: 
   42: sub handler {
   43:     my $r = shift;
   44: 
   45:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   46: 					    ['lastid','group']);
   47:     my ($group,$grouptitle);
   48:     my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
   49:     my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
   50:     if (defined($env{'form.group'})) {
   51:         $group = $env{'form.group'};
   52:         if ((! &Apache::lonnet::allowed('pgc',$env{'request.course.id'}.'/'.
   53: 				       $group)) &&
   54:            (! &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
   55:          ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')))) {
   56:             return HTTP_NOT_ACCEPTABLE;
   57:         }
   58:         my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
   59:         if (%curr_groups) {
   60:             my %group_info = 
   61: 		&Apache::longroup::get_group_settings($curr_groups{$group});
   62:             $grouptitle = 
   63: 		'<b>'.&unescape($group_info{description}).
   64: 		'</b><br />';
   65:         }
   66:     } elsif (! &Apache::lonnet::allowed('pch',$env{'request.course.id'}.
   67:              ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
   68:         ) {
   69:         return HTTP_NOT_ACCEPTABLE;
   70:     }
   71: 
   72:     my $loaderror=&Apache::lonnet::overloaderror($r);
   73:     if ($loaderror) { return $loaderror; }
   74:     $loaderror=
   75:        &Apache::lonnet::overloaderror($r,
   76:          $env{'course.'.$env{'request.course.id'}.'.home'});
   77:     if ($loaderror) { return $loaderror; }
   78: 
   79:     &Apache::loncommon::content_type($r,'text/html');
   80:     $r->send_http_header;
   81:     return OK if $r->header_only;
   82: 
   83: # ------------------------------------------------------------ retrieve entries
   84: 
   85:     my $chome=$env{'course.'.$env{'request.course.id'}.'.home'};
   86: 
   87:     my @entries=split(/\:/,
   88:        &Apache::lonnet::reply(
   89:         "chatretr:$cdom:$cnum:$env{'user.domain'}:$env{'user.name'}:$group",
   90:         $chome));
   91: # Figure out what the last valid entry-id is
   92:     my ($lastid,$thentime,$idnum);
   93:     foreach my $entry (@entries) {
   94: 	$entry =~/^(\w+)/;
   95:         if ($1 ne 'active_participant') {
   96: 	    $lastid=$1;
   97:             ($thentime,$idnum)=split(/\_/,$lastid);
   98: 	}
   99:     }
  100: # ----------------------------------------------------------- Can see identity?
  101:     my $seeid = &get_seeid_status();
  102: # -------------------------------------------------------- see which ones apply
  103:     my $include=0;
  104:     my $header;
  105:     my $newstuff='';
  106:     my $bottomid='';
  107:     unless ($env{'form.lastid'}) { 
  108: 	$include=1; 
  109: 	$header = 
  110: 	    &Apache::loncommon::start_page(undef,undef,
  111: 					   {'only_body' => 1,
  112: 					    'bgcolor'   => '#FFFFFF',
  113: 					    'js_ready'  => 1,});
  114:     }
  115:     my @participants=();
  116:     foreach my $entry (@entries) {
  117: 	my ($id,$msg,$udom)=split(/\:/,&unescape($entry));
  118:  	if ($id eq 'active_participant') {
  119:            chomp($udom);
  120: 	   my $participant= &Apache::loncommon::nickname($msg,$udom);
  121: 	   unless ($participant=~/\w/) { $participant=$msg.':'.$udom; }
  122: 	   $participants[$#participants+1]=$participant;
  123: 	} elsif ($include) {
  124: 	    chomp($msg);
  125: 	    my ($msgtime,$msgnum)=split(/\_/,$id);
  126: 	    my ($sdom,$snum,$anon,$contrib)=split(/\:/,
  127: 					     &unescape($msg));
  128: 	    $contrib=&unescape($contrib);
  129: 	    &Apache::lonfeedback::newline_to_br(\$contrib);
  130: 	    ($contrib,my $errors)=&Apache::lontexconvert::msgtexconverted($contrib);
  131: 	    if ($errors) { $contrib.=&mt('[Message not fully displayed due to incorrect embedded TeX]'); }
  132: 	    if ($errors && $snum eq $env{'user.name'} &&
  133: 		$sdom eq $env{'user.domain'} ) {
  134: 		$contrib.='<br />'.&mt('[TeX error message: [_1]',$errors);
  135: 	    }
  136: 	    $contrib=~s/\n/ /g;
  137: 	    $contrib=~s/\'/\&\#39\;/g;
  138: 	    my $sender='';
  139: 	    if ($seeid) {
  140: 		$sender=&Apache::loncommon::plainname($snum,$sdom);
  141: 		my $nick=&Apache::loncommon::nickname($snum,$sdom);
  142: 		if (($nick) && ($nick ne $sender)) {
  143: 		    $sender.=' '.$nick;
  144: 		}
  145: 		unless ($sender) { $sender=$snum.':'.$sdom; }
  146: 		if ($anon) { $sender.=' [Anon]' };
  147: 	    } elsif (!$anon) {
  148: 		$sender=&Apache::loncommon::nickname($snum,$sdom);
  149: 		unless ($sender) { $sender=$snum.':'.$sdom; }
  150: 	    } else {
  151: 		$sender=&Apache::loncommon::screenname($snum,$sdom);
  152: 		unless ($sender) { $sender=&mt("Anonymous"); }
  153: 	    }
  154: 	    $sender=~s/\'/\&\#39\;/g;
  155: 	    my $color=$sender;
  156: 	    $color=~tr/a-j/0-9/;
  157: 	    $color=~tr/A-J/0-9/;
  158: 	    $color=~tr/k-t/0-9/;
  159: 	    $color=~tr/K-T/0-9/;
  160: 	    $color=~tr/u-z/0-5/;
  161: 	    $color=~tr/U-Z/0-5/;
  162: 	    $color=~s/\D//g;
  163: 	    $color=substr($color,0,6);
  164: 	    my $timestamp=localtime($msgtime);
  165: 	    my ($mhour,$mmin,$msec)=($timestamp=~/(\d\d)\:(\d\d)\:(\d\d)/);
  166: 	    $newstuff.='<font color="#'.$color.'"><a name="LC_'.$id.'"></a><b>'.
  167: 		$sender.'</b> ('.$mhour.':'.$mmin.':'.$msec.'): '.
  168: 		$contrib."</font><br />";
  169: 	    $bottomid='LC_'.$id;
  170: 	} else {
  171: 	    $entry=~/^(\w+)/;
  172: 	    if ($1 eq $env{'form.lastid'}) { $include=1; }
  173: 	}
  174:     }
  175:     my $participant_output=join('<br />',sort @participants);
  176:     my $refresh_cmd = "/adm/chatfetch?lastid=$lastid";
  177:     if (defined($group)) {
  178:         $refresh_cmd .= "&amp;group=$group";
  179:     }
  180:     my $headarg;
  181:     my ($blocked,$blocktext) = &blockstatus();
  182:     if ($blocked) {
  183:         $newstuff = $blocktext;
  184:         $headarg =  {'only_body' => 1,};
  185:     } else {
  186:         $headarg = {'redirect'  => [5,$refresh_cmd,1],
  187:                                     'only_body' => 1,};
  188:     }
  189:     my $start_page = &Apache::loncommon::start_page('Chat',undef,$headarg); 
  190:     my $end_page = &Apache::loncommon::end_page();
  191:     $r->print(<<ENDDOCUMENT);
  192: $start_page
  193: <script type="text/javascript">
  194: parent.chatout.document.writeln('$header$newstuff');
  195: parent.chatout.scroll(0,10000000);
  196: </script>
  197: $grouptitle
  198: $participant_output
  199: $end_page
  200: ENDDOCUMENT
  201:     return OK;
  202: }
  203: 
  204: sub get_seeid_status {
  205:     my $crs='/'.$env{'request.course.id'};
  206:     my $seeid;
  207:     if (exists($env{'form.group'})) {
  208:         $seeid = &Apache::lonnet::allowed('rci',$crs.'/'.$env{'form.group'});
  209:     } else {
  210:         if ($env{'request.course.sec'}) {
  211:             $crs.='_'.$env{'request.course.sec'};
  212:         }
  213:         $crs=~s/\_/\//g;
  214:         $seeid=&Apache::lonnet::allowed('rin',$crs);
  215:     }
  216:     return $seeid;
  217: }
  218: 
  219: sub blockstatus {
  220:     my ($blocked,$output);
  221:     my %setters;
  222:     my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'chat');
  223:     if ($startblock && $endblock) {
  224:         $blocked = 1;
  225:         my $endblocktime = &Apache::lonlocal::locallocaltime($endblock);
  226:         $output .= &mt('Chat will be unavailable to you until [_1] because communication is blocked in one or more of your courses: <br/><br />',$endblocktime); 
  227:         foreach my $course (keys(%setters)) {
  228:             my %courseinfo=&Apache::lonnet::coursedescription($course);
  229:             for (my $i=0; $i<@{$setters{$course}{staff}}; $i++) {
  230:                 my ($uname,$udom) = @{$setters{$course}{staff}[$i]};
  231:                 my $fullname = &Apache::loncommon::plainname($uname,$udom);
  232:                 my ($openblock,$closeblock) = @{$setters{$course}{times}[$i]};
  233:                 $openblock = &Apache::lonlocal::locallocaltime($openblock);
  234:                 $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
  235:                 $output .= &mt('Block for [_1] starts: [_2], ends [_3], set by: [_4]<br />',$courseinfo{'description'},$openblock,$closeblock,$fullname);
  236:             }
  237:         }
  238:     }
  239:     return ($blocked,$output);
  240: }
  241: 
  242: 1;
  243: __END__

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