--- loncom/interface/lonchat.pm	2005/02/17 08:50:20	1.9
+++ loncom/interface/lonchat.pm	2009/01/12 04:11:25	1.17
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Chat
 #
-# $Id: lonchat.pm,v 1.9 2005/02/17 08:50:20 albertel Exp $
+# $Id: lonchat.pm,v 1.17 2009/01/12 04:11:25 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -31,38 +31,58 @@ package Apache::lonchat;
 use strict;
 use Apache::Constants qw(:common :http);
 use Apache::loncommon;
+use Apache::lonnet;
+use Apache::lonlocal;
 
 sub handler {
     my $r = shift;
     &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;
     return OK if $r->header_only;
-    if (! &Apache::lonnet::allowed('plc',$ENV{'request.course.id'}.
-              ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:'')
+    
+    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['group']);
+    my ($group,$group_elem);
+    if (defined($env{'form.group'})) {
+        $group = $env{'form.group'};
+        $group_elem = '<input type="hidden" name="group" value="'.$group.'" />'; 
+        if ((! &Apache::lonnet::allowed('pgc',$env{'request.course.id'}.'/'.
+                                                                    $group))
+            && (! &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')))) {
+            return HTTP_NOT_ACCEPTABLE;
+        }
+    } else {
+        if (! &Apache::lonnet::allowed('plc',$env{'request.course.id'}.
+              ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')
                                    )) {
-        return HTTP_NOT_ACCEPTABLE;
+            return HTTP_NOT_ACCEPTABLE;
+        }
     }
 
-    if ($ENV{'form.newchat'}) {
-	&Apache::lonnet::chatsend(&Apache::lonfeedback::clear_out_html($ENV{'form.newchat'}),$ENV{'form.anonymous'});
+    if ($env{'form.newchat'}) {
+	&Apache::lonnet::chatsend(&Apache::lonfeedback::clear_out_html($env{'form.newchat'}),$env{'form.anonymous'},$group);
     }
 # --------------------------------------------------- Print login screen header
-    my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
-    my $html=&Apache::lonxml::xmlbegin();
+    my $latexHelp = Apache::loncommon::helpLatexCheatsheet(undef,undef,1);
+    my %loaditems = (onload => 'this.document.chatentry.newchat.focus();');
+    my $start_page = 
+	&Apache::loncommon::start_page('Chat',undef,
+				       {'only_body'   => 1,
+					'add_entries' => \%loaditems,});
+    my $end_page = &Apache::loncommon::end_page();
+    my %lt = &Apache::lonlocal::texthash(
+                                        anon => 'Post Anonymous',
+                                        post => 'Post',
+                                      );         
     $r->print(<<ENDDOCUMENT);
-$html
-<head>
-<title>The LearningOnline Network with CAPA</title>
-</head>
-<body bgcolor="#FFFFFF" onLoad="this.document.chatentry.newchat.focus();">
+$start_page
 <form method="post" name="chatentry">
 $latexHelp
 <input type="text" size="60" name="newchat">
-<input value="Post Anonymous" name="anonymous" type="submit">
-<input value="Post" name="newentry" type="submit">
+<input value="$lt{'anon'}" name="anonymous" type="submit">
+<input value="$lt{'post'}" name="newentry" type="submit">
+$group_elem
 </form>
-</body>
-</html>
+$end_page
 ENDDOCUMENT
     return OK;
 }