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