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