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