File:  [LON-CAPA] / loncom / interface / lonmsg.pm
Revision 1.165: download - view: text, annotated - select for diffs
Wed Dec 21 22:58:07 2005 UTC (18 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_1_0, version_2_0_99_1, HEAD
Be sure to set %status equal to the hash retrieved by lonnet::get();

    1: # The LearningOnline Network with CAPA
    2: # Routines for messaging
    3: #
    4: # $Id: lonmsg.pm,v 1.165 2005/12/21 22:58:07 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: 
   30: package Apache::lonmsg;
   31: 
   32: =pod
   33: 
   34: =head1 NAME
   35: 
   36: Apache::lonmsg: supports internal messaging
   37: 
   38: =head1 SYNOPSIS
   39: 
   40: lonmsg provides routines for sending messages, receiving messages, and
   41: a handler to allow users to read, send, and delete messages.
   42: 
   43: =head1 OVERVIEW
   44: 
   45: =head2 Messaging Overview
   46: 
   47: X<messages>LON-CAPA provides an internal messaging system similar to
   48: email, but customized for LON-CAPA's usage. LON-CAPA implements its
   49: own messaging system, rather then building on top of email, because of
   50: the features LON-CAPA messages can offer that conventional e-mail can
   51: not:
   52: 
   53: =over 4
   54: 
   55: =item * B<Critical messages>: A message the recipient B<must>
   56: acknowlegde receipt of before they are allowed to continue using the
   57: system, preventing a user from claiming they never got a message
   58: 
   59: =item * B<Receipts>: LON-CAPA can reliably send reciepts informing the
   60: sender that it has been read; again, useful for preventing students
   61: from claiming they did not see a message. (While conventional e-mail
   62: has some reciept support, it's sporadic, e-mail client-specific, and
   63: generally the receiver can opt to not send one, making it useless in
   64: this case.)
   65: 
   66: =item * B<Context>: LON-CAPA knows about the sender, such as where
   67: they are in a course. When a student mails an instructor asking for
   68: help on the problem, the instructor receives not just the student's
   69: question, but all submissions the student has made up to that point,
   70: the user's rendering of the problem, and the complete view the student
   71: saw of the resource, including discussion up to that point. Finally,
   72: the instructor is reading all of this inside of LON-CAPA, not their
   73: email program, so they have full access to LON-CAPA's grading
   74: interface, or other features they may wish to use in response to the
   75: student's query.
   76: 
   77: =item * B<Blocking>: LON-CAPA can block display of e-mails that are 
   78: sent to a student during an online exam. A course coordinator or
   79: instructor can set an open and close date/time for scheduled online
   80: exams in a course. If a user uses the LON-CAPA internal messaging 
   81: system to display e-mails during the scheduled blocking event,  
   82: display of all e-mail sent during the blocking period will be 
   83: suppressed, and a message of explanation, including details of the 
   84: currently active blocking periods will be displayed instead. A user 
   85: who has a course coordinator or instructor role in a course will be
   86: unaffected by any blocking periods for the course, unless the user
   87: also has a student role in the course, AND has selected the student role.
   88: 
   89: =back
   90: 
   91: Users can ask LON-CAPA to forward messages to conventional e-mail
   92: addresses on their B<PREF> screen, but generally, LON-CAPA messages
   93: are much more useful than traditional email can be made to be, even
   94: with HTML support.
   95: 
   96: Right now, this document will cover just how to send a message, since
   97: it is likely you will not need to programmatically read messages,
   98: since lonmsg already implements that functionality.
   99: 
  100: The routines used to package messages and unpackage messages are not
  101: only used by lonmsg when creating/extracting messages for LON-CAPA's
  102: internal messaging system, but also by lonnotify.pm which is available
  103: for use by Domain Coordinators to broadcast standard e-mail to specified
  104: users in their domain.  The XML packaging used in the two cases is very
  105: similar.  The differences are the use of <recuser>$uname</recuser> and 
  106: <recdomain>$udom</recdomain> in stored internal messages, compared 
  107: with <recipient username="$uname:$udom">$email</recipient> in stored
  108: Domain Coordinator e-mail for the storage of information about 
  109: recipients of the message/e-mail.
  110: 
  111: =head1 FUNCTIONS
  112: 
  113: =over 4
  114: 
  115: =cut
  116: 
  117: use strict;
  118: use Apache::lonnet;
  119: use vars qw($msgcount);
  120: use HTML::TokeParser();
  121: use Apache::Constants qw(:common);
  122: use Apache::loncommon();
  123: use Apache::lontexconvert();
  124: use HTML::Entities();
  125: use Mail::Send;
  126: use Apache::lonlocal;
  127: use Apache::loncommunicate;
  128: use Apache::lonfeedback;
  129: use Apache::lonrss();
  130: 
  131: # Querystring component with sorting type
  132: my $sqs;
  133: my $startdis;
  134: my $interdis;
  135: 
  136: # ===================================================================== Package
  137: 
  138: sub packagemsg {
  139:     my ($subject,$message,$citation,$baseurl,$attachmenturl,
  140: 	$recuser,$recdomain,$msgid,$type)=@_;
  141:     $message =&HTML::Entities::encode($message,'<>&"');
  142:     $citation=&HTML::Entities::encode($citation,'<>&"');
  143:     $subject =&HTML::Entities::encode($subject,'<>&"');
  144:     #remove machine specification
  145:     $baseurl =~ s|^http://[^/]+/|/|;
  146:     $baseurl =&HTML::Entities::encode($baseurl,'<>&"');
  147:     #remove machine specification
  148:     $attachmenturl =~ s|^http://[^/]+/|/|;
  149:     $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
  150:     my $course_context;
  151:     if (defined($env{'form.replyid'})) {
  152:         my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
  153:                    split(/\:/,&Apache::lonnet::unescape($env{'form.replyid'}));
  154:         $course_context = $origcid;
  155:     }
  156:     foreach my $key (keys(%env)) {
  157:         if ($key=~/^form\.(rep)?rec\_(.*)$/) {
  158:             my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =
  159:                                     split(/\:/,&Apache::lonnet::unescape($2));
  160:             $course_context = $origcid;
  161:             last;
  162:         }
  163:     }
  164:     unless(defined($course_context)) {
  165:         $course_context = $env{'request.course.id'};
  166:     }
  167:     my $now=time;
  168:     $msgcount++;
  169:     unless(defined($msgid)) {
  170:         $msgid = &buildmsgid($now,$subject,$env{'user.name'},$env{'user.domain'},
  171:                             $msgcount,$course_context,$$);
  172:     }
  173:     my $result='<sendername>'.$env{'user.name'}.'</sendername>'.
  174:            '<senderdomain>'.$env{'user.domain'}.'</senderdomain>'.
  175:            '<subject>'.$subject.'</subject>'.
  176: 	   '<time>'.&Apache::lonlocal::locallocaltime($now).'</time>'.
  177: 	   '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
  178:            '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
  179: 	   '<client>'.$ENV{'REMOTE_ADDR'}.'</client>'.
  180: 	   '<browsertype>'.$env{'browser.type'}.'</browsertype>'.
  181: 	   '<browseros>'.$env{'browser.os'}.'</browseros>'.
  182: 	   '<browserversion>'.$env{'browser.version'}.'</browserversion>'.
  183:            '<browsermathml>'.$env{'browser.mathml'}.'</browsermathml>'.
  184: 	   '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
  185: 	   '<courseid>'.$course_context.'</courseid>'.
  186: 	   '<coursesec>'.$env{'request.course.sec'}.'</coursesec>'.
  187: 	   '<role>'.$env{'request.role'}.'</role>'.
  188: 	   '<resource>'.$env{'request.filename'}.'</resource>'.
  189:            '<msgid>'.$msgid.'</msgid>';
  190:     if (ref($recuser) eq 'ARRAY') {
  191:         for (my $i=0; $i<@{$recuser}; $i++) {
  192:             if ($type eq 'dcmail') {
  193:                 my ($username,$email) = split(/:/,$$recuser[$i]);
  194:                 $username = &Apache::lonnet::unescape($username);
  195:                 $email = &Apache::lonnet::unescape($email);
  196:                 $username = &HTML::Entities::encode($username,'<>&"');
  197:                 $email = &HTML::Entities::encode($email,'<>&"');
  198:                 $result .= '<recipient username="'.$username.'">'.
  199:                                             $email.'</recipient>';
  200:             } else {
  201:                 $result .= '<recuser>'.$$recuser[$i].'</recuser>'.
  202:                            '<recdomain>'.$$recdomain[$i].'</recdomain>';
  203:             }
  204:         }
  205:     } else {
  206:         $result .= '<recuser>'.$recuser.'</recuser>'.
  207:                    '<recdomain>'.$recdomain.'</recdomain>';
  208:     }
  209:     $result .= '<message>'.$message.'</message>';
  210:     if (defined($citation)) {
  211: 	$result.='<citation>'.$citation.'</citation>';
  212:     }
  213:     if (defined($baseurl)) {
  214: 	$result.= '<baseurl>'.$baseurl.'</baseurl>';
  215:     }
  216:     if (defined($attachmenturl)) {
  217: 	$result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>';
  218:     }
  219:     return $msgid,$result;
  220: }
  221: 
  222: # ================================================== Unpack message into a hash
  223: 
  224: sub unpackagemsg {
  225:     my ($message,$notoken)=@_;
  226:     my %content=();
  227:     my $parser=HTML::TokeParser->new(\$message);
  228:     my $token;
  229:     while ($token=$parser->get_token) {
  230:        if ($token->[0] eq 'S') {
  231: 	   my $entry=$token->[1];
  232:            my $value=$parser->get_text('/'.$entry);
  233:            if (($entry eq 'recuser') || ($entry eq 'recdomain')) {
  234:                push(@{$content{$entry}},$value);
  235:            } elsif ($entry eq 'recipient') {
  236:                my $username = $token->[2]{'username'};
  237:                $username = &HTML::Entities::decode($username,'<>&"');
  238:                $content{$entry}{$username} = $value;
  239:            } else {
  240:                $content{$entry}=$value;
  241:            }
  242:        }
  243:     }
  244:     if ($content{'attachmenturl'}) {
  245:        my ($fname)=($content{'attachmenturl'}=~m|/([^/]+)$|);
  246:        if ($notoken) {
  247: 	   $content{'message'}.='<p>'.&mt('Attachment').': <tt>'.$fname.'</tt>';
  248:        } else {
  249: 	   &Apache::lonnet::allowuploaded('/adm/msg',
  250: 					  $content{'attachmenturl'});
  251: 	   $content{'message'}.='<p>'.&mt('Attachment').
  252: 	       ': <a href="'.$content{'attachmenturl'}.'"><tt>'.
  253: 	       $fname.'</tt></a>';
  254:        }
  255:     }
  256:     return %content;
  257: }
  258: 
  259: # ======================================================= Get info out of msgid
  260: 
  261: sub buildmsgid {
  262:     my ($now,$subject,$uname,$udom,$msgcount,$course_context,$pid) = @_;
  263:     $subject=&Apache::lonnet::escape($subject);
  264:     return(&Apache::lonnet::escape($now.':'.$subject.':'.$uname.':'.
  265:            $udom.':'.$msgcount.':'.$course_context.':'.$pid));
  266: }
  267: 
  268: sub unpackmsgid {
  269:     my ($msgid,$folder,$skipstatus)=@_;
  270:     $msgid=&Apache::lonnet::unescape($msgid);
  271:     my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid)=split(/\:/,
  272:                           &Apache::lonnet::unescape($msgid));
  273:     my %status=();
  274:     unless ($skipstatus) {
  275:         my $suffix=&foldersuffix($folder);
  276:         %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
  277:         if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
  278:         unless ($status{$msgid}) { $status{$msgid}='new'; }
  279:     }
  280:     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid);
  281: }
  282: 
  283: 
  284: sub sendemail {
  285:     my ($to,$subject,$body)=@_;
  286:     $body=
  287:     "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n".
  288:     "*** ".&mt('Please do not reply to this address.')."\n\n".$body;
  289:     my $msg = new Mail::Send;
  290:     $msg->to($to);
  291:     $msg->subject('[LON-CAPA] '.$subject);
  292:     if (my $fh = $msg->open()) {
  293: 	print $fh $body;
  294: 	$fh->close;
  295:     }
  296: }
  297: 
  298: # ==================================================== Send notification emails
  299: 
  300: sub sendnotification {
  301:     my ($to,$touname,$toudom,$subj,$crit,$text)=@_;
  302:     my $sender=$env{'environment.firstname'}.' '.$env{'environment.lastname'};
  303:     unless ($sender=~/\w/) { 
  304: 	$sender=$env{'user.name'}.'@'.$env{'user.domain'};
  305:     }
  306:     my $critical=($crit?' critical':'');
  307:     $text=~s/\&lt\;/\</gs;
  308:     $text=~s/\&gt\;/\>/gs;
  309:     $text=~s/\<\/*[^\>]+\>//gs;
  310:     my $url='http://'.
  311:       $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}.
  312:       '/adm/email?username='.$touname.'&domain='.$toudom;
  313:     my $body=(<<ENDMSG);
  314: You received a$critical message from $sender in LON-CAPA. The subject is
  315: 
  316:  $subj
  317: 
  318: === Excerpt ============================================================
  319: $text
  320: ========================================================================
  321: 
  322: Use
  323: 
  324:  $url
  325: 
  326: to access the full message.
  327: ENDMSG
  328:     &sendemail($to,'New'.$critical.' message from '.$sender,$body);
  329: }
  330: # ============================================================= Check for email
  331: 
  332: sub newmail {
  333:     if ((time-$env{'user.mailcheck.time'})>300) {
  334:         my %what=&Apache::lonnet::get('email_status',['recnewemail']);
  335:         &Apache::lonnet::appenv('user.mailcheck.time'=>time);
  336:         if ($what{'recnewemail'}>0) { return 1; }
  337:     }
  338:     return 0;
  339: }
  340: 
  341: # =============================== Automated message to the author of a resource
  342: 
  343: =pod
  344: 
  345: =item * B<author_res_msg($filename, $message)>: Sends message $message to the owner
  346:     of the resource with the URI $filename.
  347: 
  348: =cut
  349: 
  350: sub author_res_msg {
  351:     my ($filename,$message)=@_;
  352:     unless ($message) { return 'empty'; }
  353:     $filename=&Apache::lonnet::declutter($filename);
  354:     my ($domain,$author,@dummy)=split(/\//,$filename);
  355:     my $homeserver=&Apache::lonnet::homeserver($author,$domain);
  356:     if ($homeserver ne 'no_host') {
  357:        my $id=unpack("%32C*",$message);
  358:        my $msgid;
  359:        ($msgid,$message)=&packagemsg($filename,$message);
  360:        return &Apache::lonnet::reply('put:'.$domain.':'.$author.
  361:          ':nohist_res_msgs:'.
  362:           &Apache::lonnet::escape($filename.'_'.$id).'='.
  363:           &Apache::lonnet::escape($message),$homeserver);
  364:     }
  365:     return 'no_host';
  366: }
  367: 
  368: # =========================================== Retrieve author resource messages
  369: 
  370: sub retrieve_author_res_msg {
  371:     my $url=shift;
  372:     $url=&Apache::lonnet::declutter($url);
  373:     my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
  374:     my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$domain,$author);
  375:     my $msgs='';
  376:     foreach (keys %errormsgs) {
  377: 	if ($_=~/^\Q$url\E\_\d+$/) {
  378: 	    my %content=&unpackagemsg($errormsgs{$_});
  379: 	    $msgs.='<p><img src="/adm/lonMisc/bomb.gif" /><b>'.
  380: 		$content{'time'}.'</b>: '.$content{'message'}.
  381: 		'<br /></p>';
  382: 	}
  383:     } 
  384:     return $msgs;     
  385: }
  386: 
  387: 
  388: # =============================== Delete all author messages related to one URL
  389: 
  390: sub del_url_author_res_msg {
  391:     my $url=shift;
  392:     $url=&Apache::lonnet::declutter($url);
  393:     my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
  394:     my @delmsgs=();
  395:     foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
  396: 	if ($_=~/^\Q$url\E\_\d+$/) {
  397: 	    push (@delmsgs,$_);
  398: 	}
  399:     }
  400:     return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
  401: }
  402: # =================================== Clear out all author messages in URL path
  403: 
  404: sub clear_author_res_msg {
  405:     my $url=shift;
  406:     $url=&Apache::lonnet::declutter($url);
  407:     my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
  408:     my @delmsgs=();
  409:     foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
  410: 	if ($_=~/^\Q$url\E/) {
  411: 	    push (@delmsgs,$_);
  412: 	}
  413:     }
  414:     return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
  415: }
  416: # ================= Return hash with URLs for which there is a resource message
  417: 
  418: sub all_url_author_res_msg {
  419:     my ($author,$domain)=@_;
  420:     my %returnhash=();
  421:     foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
  422: 	$_=~/^(.+)\_\d+/;
  423: 	$returnhash{$1}=1;
  424:     }
  425:     return %returnhash;
  426: }
  427: 
  428: # ================================================== Critical message to a user
  429: 
  430: sub user_crit_msg_raw {
  431:     my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
  432: # Check if allowed missing
  433:     my $status='';
  434:     my $msgid='undefined';
  435:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
  436:     my $text=$message;
  437:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
  438:     if ($homeserver ne 'no_host') {
  439:        ($msgid,$message)=&packagemsg($subject,$message);
  440:        if ($sendback) { $message.='<sendback>true</sendback>'; }
  441:        $status=&Apache::lonnet::critical(
  442:            'put:'.$domain.':'.$user.':critical:'.
  443:            &Apache::lonnet::escape($msgid).'='.
  444:            &Apache::lonnet::escape($message),$homeserver);
  445:         if (defined($sentmessage)) {
  446:             $$sentmessage = $message;
  447:         }
  448:     } else {
  449:        $status='no_host';
  450:     }
  451: # Notifications
  452:     my %userenv = &Apache::lonnet::get('environment',['critnotification',
  453:                                                       'permanentemail'],
  454:                                        $domain,$user);
  455:     if ($userenv{'critnotification'}) {
  456:       &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1,
  457: 			$text);
  458:     }
  459:     if ($toperm && $userenv{'permanentemail'}) {
  460:       &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,1,
  461: 			$text);
  462:     }
  463: # Log this
  464:     &Apache::lonnet::logthis(
  465:       'Sending critical email '.$msgid.
  466:       ', log status: '.
  467:       &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
  468:                          $env{'user.home'},
  469:       'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
  470:       .$status));
  471:     return $status;
  472: }
  473: 
  474: # New routine that respects "forward" and calls old routine
  475: 
  476: =pod
  477: 
  478: =item * B<user_crit_msg($user, $domain, $subject, $message, $sendback)>: Sends
  479:     a critical message $message to the $user at $domain. If $sendback is true,
  480:     a reciept will be sent to the current user when $user recieves the message.
  481: 
  482: =cut
  483: 
  484: sub user_crit_msg {
  485:     my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
  486:     my $status='';
  487:     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
  488:                                        $domain,$user);
  489:     my $msgforward=$userenv{'msgforward'};
  490:     if ($msgforward) {
  491:        foreach (split(/\,/,$msgforward)) {
  492: 	 my ($forwuser,$forwdomain)=split(/\:/,$_);
  493:          $status.=
  494: 	   &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
  495:                 $sendback,$toperm,$sentmessage).' ';
  496:        }
  497:     } else { 
  498: 	$status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage);
  499:     }
  500:     return $status;
  501: }
  502: 
  503: # =================================================== Critical message received
  504: 
  505: sub user_crit_received {
  506:     my $msgid=shift;
  507:     my %message=&Apache::lonnet::get('critical',[$msgid]);
  508:     my %contents=&unpackagemsg($message{$msgid},1);
  509:     my $status='rec: '.($contents{'sendback'}?
  510:      &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
  511:                      &mt('Receipt').': '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.', '.$contents{'subject'},
  512:                      &mt('User').' '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.
  513:                      ' acknowledged receipt of message'."\n".'   "'.
  514:                      $contents{'subject'}.'"'."\n".&mt('dated').' '.
  515:                      $contents{'time'}.".\n"
  516:                      ):'no msg req');
  517:     $status.=' trans: '.
  518:      &Apache::lonnet::put(
  519:      'nohist_email',{$contents{'msgid'} => $message{$msgid}});
  520:     $status.=' del: '.
  521:      &Apache::lonnet::del('critical',[$contents{'msgid'}]);
  522:     &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
  523:                          $env{'user.home'},'Received critical message '.
  524:                          $contents{'msgid'}.
  525:                          ', '.$status);
  526:     return $status;
  527: }
  528: 
  529: # ======================================================== Normal communication
  530: 
  531: sub user_normal_msg_raw {
  532:     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
  533: 	$toperm,$currid,$newid,$sentmessage)=@_;
  534: # Check if allowed missing
  535:     my $status='';
  536:     my $msgid='undefined';
  537:     my $text=$message;
  538:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
  539:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
  540:     if ($homeserver ne 'no_host') {
  541:        ($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl,
  542:                                      $attachmenturl,$user,$domain,$currid);
  543: # Store in user folder
  544:        $status=&Apache::lonnet::critical(
  545:            'put:'.$domain.':'.$user.':nohist_email:'.
  546:            &Apache::lonnet::escape($msgid).'='.
  547:            &Apache::lonnet::escape($message),$homeserver);
  548: # Save new message received time
  549:        &Apache::lonnet::put
  550:                          ('email_status',{'recnewemail'=>time},$domain,$user);
  551: # Into sent-mail folder unless a broadcast message or critical message
  552:        unless (($env{'request.course.id'}) && 
  553:                (($env{'form.sendmode'} eq 'group')  || 
  554:                (($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
  555:                (&Apache::lonnet::allowed('srm',$env{'request.course.id'})))) {
  556:            $status .= &store_sent_mail($msgid,$message);
  557:        }
  558:     } else {
  559:        $status='no_host';
  560:     }
  561:     if (defined($newid)) {
  562:         $$newid = $msgid;
  563:     }
  564:     if (defined($sentmessage)) {
  565:         $$sentmessage = $message;
  566:     }
  567: 
  568: # Notifications
  569:     my %userenv = &Apache::lonnet::get('environment',['notification',
  570:                                                       'permanentemail'],
  571:                                        $domain,$user);
  572:     if ($userenv{'notification'}) {
  573: 	&sendnotification($userenv{'notification'},$user,$domain,$subject,0,
  574: 			  $text);
  575:     }
  576:     if ($toperm && $userenv{'permanentemail'}) {
  577:       &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,0,
  578: 			$text);
  579:     }
  580:     &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
  581:                          $env{'user.home'},
  582:       'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
  583:     return $status;
  584: }
  585: 
  586: # New routine that respects "forward" and calls old routine
  587: 
  588: =pod
  589: 
  590: =item * B<user_normal_msg($user, $domain, $subject, $message,
  591:     $citation, $baseurl, $attachmenturl)>: Sends a message to the
  592:     $user at $domain, with subject $subject and message $message.
  593: 
  594: =cut
  595: 
  596: sub user_normal_msg {
  597:     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
  598: 	$toperm,$sentmessage)=@_;
  599:     my $status='';
  600:     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
  601:                                        $domain,$user);
  602:     my $msgforward=$userenv{'msgforward'};
  603:     if ($msgforward) {
  604:        foreach (split(/\,/,$msgforward)) {
  605: 	 my ($forwuser,$forwdomain)=split(/\:/,$_);
  606:          $status.=
  607: 	  &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
  608: 	$citation,$baseurl,$attachmenturl,$toperm,undef,undef,$sentmessage).' ';
  609:        }
  610:     } else { 
  611: 	$status=&user_normal_msg_raw($user,$domain,$subject,$message,
  612: 	    $citation,$baseurl,$attachmenturl,$toperm,undef,undef,$sentmessage);
  613:     }
  614:     return $status;
  615: }
  616: 
  617: sub store_sent_mail {
  618:     my ($msgid,$message) = @_;
  619:         my $status =' '.&Apache::lonnet::critical(
  620:                    'put:'.$env{'user.domain'}.':'.$env{'user.name'}.
  621:                                               ':nohist_email_sent:'.
  622:                    &Apache::lonnet::escape($msgid).'='.
  623:                    &Apache::lonnet::escape($message),$env{'user.home'});
  624:     return $status;
  625: }
  626: 
  627: # ============================================================ List all folders
  628: 
  629: sub folderlist {
  630:     my $folder=shift;
  631:     my @allfolders=&Apache::lonnet::getkeys('email_folders');
  632:     if ($allfolders[0]=~/^error:/) { @allfolders=(); }
  633:     return '<form method="post" action="/adm/email">'.
  634: 	&mt('Folder').': '.
  635: 	&Apache::loncommon::select_form($folder,'folder',
  636: 			     ('' => &mt('INBOX'),'trash' => &mt('TRASH'),
  637: 			      'new' => &mt('New Messages Only'),
  638:                               'critical' => &mt('Critical'),
  639: 			      'sent' => &mt('Sent Messages'),
  640: 			      map { $_ => $_ } @allfolders)).
  641: 			      ' '.&mt('Show').
  642: 			      '<select name="interdis">'.
  643: 			      join("\n",map { '<option value="'.$_.'"'.
  644: 	 ($_==$interdis?' selected="selected"':'').'>'.$_.'</option>' }
  645: 				   (10,20,50,100,200)).'</select>'.	
  646:    '<input type="submit" value="'.&mt('View Folder').'" /><br />'.
  647:     '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" />'.
  648: 			      ($folder=~/^(new|critical)/?'</form>':'');
  649: }
  650: 
  651: sub scrollbuttons {
  652:     my ($start,$maxdis,$first,$finish,$total)=@_;
  653:     unless ($total>0) { return ''; }
  654:     $start++; $maxdis++;$first++;$finish++;
  655:     return
  656:    &mt('Page').': '. 
  657:    '<input type="submit" name="firstview" value="'.&mt('First').'" />'.
  658:    '<input type="submit" name="prevview" value="'.&mt('Previous').'" />'.
  659:    '<input type="text" size="5" name="startdis" value="'.$start.'" onChange="this.form.submit()" /> of '.$maxdis.
  660:    '<input type="submit" name="nextview" value="'.&mt('Next').'" />'.
  661:    '<input type="submit" name="lastview" value="'.&mt('Last').'" /><br />'.
  662:    &mt('Showing messages [_1] through [_2] of [_3]',$first,$finish,$total).'</form>';
  663: }
  664: 
  665: # =============================================================== Folder suffix
  666: 
  667: sub foldersuffix {
  668:     my $folder=shift;
  669:     unless ($folder) { return ''; }
  670:     return '_'.&Apache::lonnet::escape($folder);
  671: }
  672: 
  673: # =============================================================== Status Change
  674: 
  675: sub statuschange {
  676:     my ($msgid,$newstatus,$folder)=@_;
  677:     my $suffix=&foldersuffix($folder);
  678:     my %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
  679:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
  680:     unless ($status{$msgid}) { $status{$msgid}='new'; }
  681:     unless (($status{$msgid} eq 'replied') || 
  682:             ($status{$msgid} eq 'forwarded')) {
  683: 	&Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
  684:     }
  685:     if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
  686: 	&Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
  687:     }
  688:     if ($newstatus eq 'deleted') {
  689:        &movemsg(&Apache::lonnet::unescape($msgid),$folder,'trash');
  690:    }
  691: }
  692: 
  693: # ============================================================= Make new folder
  694: 
  695: sub makefolder {
  696:     my ($newfolder)=@_;
  697:     if (($newfolder eq 'sent')
  698:      || ($newfolder eq 'critical')
  699:      || ($newfolder eq 'trash')
  700:      || ($newfolder eq 'new')) { return; }
  701:     &Apache::lonnet::put('email_folders',{$newfolder => time});
  702: }
  703: 
  704: # ======================================================== Move between folders
  705: 
  706: sub movemsg {
  707:     my ($msgid,$srcfolder,$trgfolder)=@_;
  708:     if ($srcfolder eq 'new') { $srcfolder=''; }
  709:     my $srcsuffix=&foldersuffix($srcfolder);
  710:     my $trgsuffix=&foldersuffix($trgfolder);
  711: 
  712: # Copy message
  713:     my %message=&Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid]);
  714:     &Apache::lonnet::put('nohist_email'.$trgsuffix,{$msgid => $message{$msgid}});
  715: 
  716: # Copy status
  717:     unless ($trgfolder eq 'trash') {
  718: 	my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]);
  719: 	&Apache::lonnet::put('email_status'.$trgsuffix,{$msgid => $status{$msgid}});
  720:     }
  721: # Delete orginals
  722:     &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]);
  723:     &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]);
  724: }
  725: 
  726: # ======================================================= Display a course list
  727: 
  728: sub discourse {
  729:     my $r=shift;
  730:     my $classlist = &Apache::loncoursedata::get_classlist();
  731:     my $now=time;
  732:     my %lt=&Apache::lonlocal::texthash('cfa' => 'Check All',
  733:             'cfs' => 'Check Section/Group',
  734:             'cfn' => 'Uncheck All');
  735:     $r->print(<<ENDDISHEADER);
  736: <input type="hidden" name="sendmode" value="group" />
  737: <script>
  738:     function checkall() {
  739: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
  740:             if 
  741:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
  742: 	      document.forms.compemail.elements[i].checked=true;
  743:             }
  744:         }
  745:     }
  746: 
  747:     function checksec() {
  748: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
  749:             if 
  750:           (document.forms.compemail.elements[i].name.indexOf
  751:            ('send_to_&&&'+document.forms.compemail.chksec.value)==0) {
  752: 	      document.forms.compemail.elements[i].checked=true;
  753:             }
  754:         }
  755:     }
  756: 
  757:     function uncheckall() {
  758: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
  759:             if 
  760:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
  761: 	      document.forms.compemail.elements[i].checked=false;
  762:             }
  763:         }
  764:     }
  765: </script>
  766: <input type="button" onClick="checkall()" value="$lt{'cfa'}" />&nbsp;
  767: <input type="button" onClick="checksec()" value="$lt{'cfs'}" />
  768: <input type="text" size="5" name="chksec" />&nbsp;
  769: <input type="button" onClick="uncheckall()" value="$lt{'cfn'}" />
  770: <p>
  771: ENDDISHEADER
  772:     my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
  773:     $r->print('<table>');
  774:     foreach my $role (sort keys %coursepersonnel) {
  775:         foreach (split(/\,/,$coursepersonnel{$role})) {
  776:             my ($puname,$pudom)=split(/\:/,$_);
  777:             $r->print('<tr><td><label>'.
  778:                       '<input type="checkbox" name="send_to_&&&&&&_'.
  779:                       $puname.':'.$pudom.'" /> '.
  780:                       &Apache::loncommon::plainname($puname,$pudom).
  781:                       '</label></td>'.
  782:                       '<td>('.$_.'),</td><td><i>'.$role.'</i></td></tr>');
  783:         }
  784:     }
  785:     $r->print('</table><table>');
  786:     my $sort = sub {
  787: 	my $aname=lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]);
  788: 	if (!$aname) { $aname=$a; }
  789: 	my $bname=lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]);
  790: 	if (!$bname) { $bname=$b; }
  791: 	return $aname cmp $bname;
  792:     };
  793:     foreach my $student (sort $sort (keys(%{$classlist}))) {
  794: 	my $info=$classlist->{$student};
  795:         my ($sname,$sdom,$status,$fullname,$section) =
  796:             (@{$info}[&Apache::loncoursedata::CL_SNAME(),
  797:                       &Apache::loncoursedata::CL_SDOM(),
  798:                       &Apache::loncoursedata::CL_STATUS(),
  799:                       &Apache::loncoursedata::CL_FULLNAME(),
  800:                       &Apache::loncoursedata::CL_SECTION()]);
  801:         next if ($status ne 'Active');
  802: 	next if ($env{'request.course.sec'} &&
  803: 		 $section ne $env{'request.course.sec'});
  804:         my $key = 'send_to_&&&'.$section.'&&&_'.$student;
  805:         if (! defined($fullname) || $fullname eq '') { $fullname = $sname; }
  806:         $r->print('<tr><td><label>'.
  807:                   qq{<input type="checkbox" name="$key" />}.('&nbsp;'x2).
  808:                   $fullname.'</label></td><td>'.$sname.'@'.$sdom.'</td><td>'.$section.
  809:                   '</td></tr>');
  810:     }
  811:     $r->print('</table>');
  812: }
  813: 
  814: # ==================================================== Display Critical Message
  815: 
  816: sub discrit {
  817:     my $r=shift;
  818:     my $header = '<h1><font color=red>'.&mt('Critical Messages').'</font></h1>'.
  819:         '<form action="/adm/email" method="POST">'.
  820:         '<input type="hidden" name="confirm" value="true" />';
  821:     my %what=&Apache::lonnet::dump('critical');
  822:     my $result = '';
  823:     foreach (sort keys %what) {
  824:         my %content=&unpackagemsg($what{$_});
  825:         next if ($content{'senderdomain'} eq '');
  826:         $result.='<hr />'.&mt('From').': <b>'.
  827: &Apache::loncommon::aboutmewrapper(
  828:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
  829: $content{'sendername'}.'@'.
  830:             $content{'senderdomain'}.') '.$content{'time'}.
  831:             '<br />'.&mt('Subject').': '.$content{'subject'}.
  832:             '<br /><pre>'.
  833:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
  834:             '</pre><small>'.
  835: &mt('You have to confirm that you received this message. After confirmation, this message will be moved to your regular inbox').
  836:             '</small><br />'.
  837:             '<input type="submit" name="rec_'.$_.'" value="'.&mt('Confirm Receipt').'" />'.
  838:             '<input type="submit" name="reprec_'.$_.'" '.
  839:                   'value="'.&mt('Confirm Receipt and Reply').'" />';
  840:     }
  841:     # Check to see if there were any messages.
  842:     if ($result eq '') {
  843:         $result = "<h2>".&mt('You have no critical messages.')."</h2>".
  844: 	    '<a href="/adm/roles">'.&mt('Select a course').'</a><br />'.
  845:             '<a href="/adm/email">'.&mt('Communicate').'</a>';
  846:     } else {
  847:         $r->print($header);
  848:     }
  849:     $r->print($result);
  850:     $r->print('<input type="hidden" name="displayedcrit" value="true" /></form>');
  851: }
  852: 
  853: sub sortedmessages {
  854:     my ($blocked,$startblock,$endblock,$numblocked,$folder) = @_;
  855:     my $suffix=&foldersuffix($folder);
  856:     my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
  857:     #unpack the varibles and repack into temp for sorting
  858:     my @temp;
  859:     foreach (@messages) {
  860: 	my $msgid=&Apache::lonnet::escape($_);
  861: 	my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)=
  862: 	    &Apache::lonmsg::unpackmsgid($msgid,$folder);
  863:         my $description = &get_course_desc($fromcid);
  864: 	my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
  865: 		     $msgid,$description);
  866:         # Check whether message was sent during blocking period.
  867:         if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
  868:             my $escid = &Apache::lonnet::unescape($msgid);
  869:             $$blocked{$escid} = 'ON';
  870:             $$numblocked ++;
  871:         } else { 
  872:             push @temp ,\@temp1;
  873:         }
  874:     }
  875:     #default sort
  876:     @temp = sort  {$a->[0] <=> $b->[0]} @temp;    
  877:     if ($env{'form.sortedby'} eq "date"){
  878:         @temp = sort  {$a->[0] <=> $b->[0]} @temp;    
  879:     }
  880:     if ($env{'form.sortedby'} eq "revdate"){
  881:     	@temp = sort  {$b->[0] <=> $a->[0]} @temp; 
  882:     }
  883:     if ($env{'form.sortedby'} eq "user"){
  884: 	@temp = sort  {lc($a->[2]) cmp lc($b->[2])} @temp;
  885:     }
  886:     if ($env{'form.sortedby'} eq "revuser"){
  887: 	@temp = sort  {lc($b->[2]) cmp lc($a->[2])} @temp;
  888:     }
  889:     if ($env{'form.sortedby'} eq "domain"){
  890:         @temp = sort  {$a->[3] cmp $b->[3]} @temp;
  891:     }
  892:     if ($env{'form.sortedby'} eq "revdomain"){
  893:         @temp = sort  {$b->[3] cmp $a->[3]} @temp;
  894:     }
  895:     if ($env{'form.sortedby'} eq "subject"){
  896:         @temp = sort  {lc($a->[1]) cmp lc($b->[1])} @temp;
  897:     }
  898:     if ($env{'form.sortedby'} eq "revsubject"){
  899:         @temp = sort  {lc($b->[1]) cmp lc($a->[1])} @temp;
  900:     }
  901:     if ($env{'form.sortedby'} eq "course"){
  902:         @temp = sort  {lc($a->[6]) cmp lc($b->[6])} @temp;
  903:     }
  904:     if ($env{'form.sortedby'} eq "revcourse"){
  905:         @temp = sort  {lc($b->[6]) cmp lc($a->[6])} @temp;
  906:     }
  907:     if ($env{'form.sortedby'} eq "status"){
  908:         @temp = sort  {$a->[4] cmp $b->[4]} @temp;
  909:     }
  910:     if ($env{'form.sortedby'} eq "revstatus"){
  911:         @temp = sort  {$b->[4] cmp $a->[4]} @temp;
  912:     }
  913:     return @temp;
  914: }
  915: 
  916: sub get_course_desc {
  917:     my ($fromcid) = @_;
  918:     my $description; 
  919:     if (defined($env{'course.'.$fromcid.'.description'})) {
  920:        $description = $env{'course.'.$fromcid.'.description'};
  921:     } else {
  922:        my %courseinfo=&Apache::lonnet::coursedescription($fromcid);
  923:         $description = $courseinfo{'description'};
  924:     }
  925:     return $description;
  926: }
  927: 
  928: # ======================================================== Display new messages
  929: 
  930: 
  931: sub disnew {
  932:     my $r=shift;
  933:     my %lt=&Apache::lonlocal::texthash(
  934: 				       'nm' => 'New Messages',
  935: 				       'su' => 'Subject',
  936:                                        'co' => 'Course',
  937: 				       'da' => 'Date',
  938: 				       'us' => 'Username',
  939: 				       'op' => 'Open',
  940: 				       'do' => 'Domain'
  941: 				       );
  942:     my @msgids = sort split(/\&/,&Apache::lonnet::reply
  943:                             ('keys:'.$env{'user.domain'}.':'.
  944:                              $env{'user.name'}.':nohist_email',
  945:                              $env{'user.home'}));
  946:     my @newmsgs;
  947:     my %setters = ();
  948:     my $startblock = 0;
  949:     my $endblock = 0;
  950:     my %blocked = ();
  951:     my $numblocked = 0;
  952:     # Check for blocking of display because of scheduled online exams.
  953:     &blockcheck(\%setters,\$startblock,\$endblock);
  954:     foreach (@msgids) {
  955:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
  956: 	    &Apache::lonmsg::unpackmsgid($_);
  957:         if (defined($sendtime) && $sendtime!~/error/) {
  958:             my $description = &get_course_desc($fromcid);
  959:             my $numsendtime = $sendtime;
  960:             $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
  961:             if ($status eq 'new') {
  962:                 if ($numsendtime >= $startblock && ($numsendtime <= $endblock && $endblock > 0) ) {
  963:                     $blocked{$_} = 'ON';
  964:                     $numblocked ++;
  965:                 } else {
  966:                     push @newmsgs, { 
  967:                         msgid    => $_,
  968:                         sendtime => $sendtime,
  969:                         shortsub => &Apache::lonnet::unescape($shortsubj),
  970:                         from     => $fromname,
  971:                         fromdom  => $fromdom,
  972:                         course   => $description 
  973:                         }
  974:                 }
  975:             }
  976:         }
  977:     }
  978:     if ($#newmsgs >= 0) {
  979:         $r->print(<<TABLEHEAD);
  980: <h2>$lt{'nm'}</h2>
  981: <table border=2><tr><th>&nbsp</th>
  982: <th>$lt{'da'}</th><th>$lt{'us'}</th><th>$lt{'do'}</th><th>$lt{'su'}</th><th>$lt{'co'}</th></tr>
  983: TABLEHEAD
  984:         foreach my $msg (@newmsgs) {
  985:             $r->print(<<"ENDLINK");
  986: <tr class="new" bgcolor="#FFBB77" onMouseOver="javascript:style.backgroundColor='#DD9955'" 
  987: onMouseOut="javascript:style.backgroundColor='#FFBB77'">
  988: <td><a href="/adm/email?dismode=new&display=$msg->{'msgid'}">$lt{'op'}</a></td>
  989: ENDLINK
  990:             foreach ('sendtime','from','fromdom','shortsub','course') {
  991:                 $r->print("<td>$msg->{$_}</td>");
  992:             }
  993:             $r->print("</td></tr>");
  994:         }
  995:         $r->print('</table>'.&Apache::loncommon::endbodytag().'</html>');
  996:     } elsif ($numblocked == 0) {
  997:         $r->print("<h3>".&mt('You have no unread messages')."</h3>");
  998:     }
  999:     if ($numblocked > 0) {
 1000:         my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
 1001:         my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
 1002:         if ($numblocked == 1) {
 1003:             $r->print("<h3>".&mt('You have').' '.$numblocked.' '.&mt('blocked unread message').".</h3>");
 1004:             $r->print(&mt('This message is not viewable because').' ');
 1005:         } else {
 1006:             $r->print("<h3>".&mt('You have').' '.$numblocked.' '.&mt('blocked unread messages').".</h3>");
 1007:             $r->print(&mt('These').' '.$numblocked.' '.&mt('messages are not viewable because '));
 1008:         }
 1009:         $r->print(
 1010: &mt('display of LON-CAPA messages sent to you by other students between').' '.$beginblock.' '.&mt('and').' '.$finishblock.' '.&mt('is currently being blocked because of online exams').'.');
 1011:         &build_block_table($r,$startblock,$endblock,\%setters);
 1012:     }
 1013: }
 1014: 
 1015: 
 1016: # ======================================================== Display all messages
 1017: 
 1018: sub disall {
 1019:     my ($r,$folder)=@_;
 1020:     $r->print(&folderlist($folder));
 1021:     if ($folder eq 'new') {
 1022: 	&disnew($r);
 1023:     } elsif ($folder eq 'critical') {
 1024: 	&discrit($r);
 1025:     } else {
 1026: 	&disfolder($r,$folder);
 1027:     }
 1028: }
 1029: 
 1030: # ============================================================ Display a folder
 1031: 
 1032: sub disfolder {
 1033:     my ($r,$folder)=@_;
 1034:     my %blocked = ();
 1035:     my %setters = ();
 1036:     my $startblock;
 1037:     my $endblock;
 1038:     my $numblocked = 0;
 1039:     &blockcheck(\%setters,\$startblock,\$endblock);
 1040:     $r->print(<<ENDDISHEADER);
 1041: <script>
 1042:     function checkall() {
 1043: 	for (i=0; i<document.forms.disall.elements.length; i++) {
 1044:             if 
 1045:           (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
 1046: 	      document.forms.disall.elements[i].checked=true;
 1047:             }
 1048:         }
 1049:     }
 1050: 
 1051:     function uncheckall() {
 1052: 	for (i=0; i<document.forms.disall.elements.length; i++) {
 1053:             if 
 1054:           (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
 1055: 	      document.forms.disall.elements[i].checked=false;
 1056:             }
 1057:         }
 1058:     }
 1059: </script>
 1060: ENDDISHEADER
 1061:     my $fsqs='&folder='.$folder;
 1062:     my @temp=sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder);
 1063:     my $totalnumber=$#temp+1;
 1064:     unless ($totalnumber>0) {
 1065: 	$r->print('<h2>'.&mt('Empty Folder').'</h2>');
 1066: 	return;
 1067:     }
 1068:     unless ($interdis) {
 1069: 	$interdis=20;
 1070:     }
 1071:     my $number=int($totalnumber/$interdis);
 1072:     if (($startdis<0) || ($startdis>$number)) { $startdis=$number; }
 1073:     my $firstdis=$interdis*$startdis;
 1074:     if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; }
 1075:     my $lastdis=$firstdis+$interdis-1;
 1076:     if ($lastdis>$#temp) { $lastdis=$#temp; }
 1077:     $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber));
 1078:     $r->print('<form method="post" name="disall" action="/adm/email">'.
 1079: 	      '<table border=2><tr><th colspan="3">&nbsp</th><th>');
 1080:     if ($env{'form.sortedby'} eq "revdate") {
 1081: 	$r->print('<a href = "?sortedby=date'.$fsqs.'">'.&mt('Date').'</a></th>');
 1082:     } else {
 1083: 	$r->print('<a href = "?sortedby=revdate'.$fsqs.'">'.&mt('Date').'</a></th>');
 1084:     }
 1085:     $r->print('<th>');
 1086:     if ($env{'form.sortedby'} eq "revuser") {
 1087: 	$r->print('<a href = "?sortedby=user'.$fsqs.'">'.&mt('Username').'</a>');
 1088:     } else {
 1089: 	$r->print('<a href = "?sortedby=revuser'.$fsqs.'">'.&mt('Username').'</a>');
 1090:     }
 1091:     $r->print('</th><th>');
 1092:     if ($env{'form.sortedby'} eq "revdomain") {
 1093: 	$r->print('<a href = "?sortedby=domain'.$fsqs.'">'.&mt('Domain').'</a>');
 1094:     } else {
 1095: 	$r->print('<a href = "?sortedby=revdomain'.$fsqs.'">'.&mt('Domain').'</a>');
 1096:     }
 1097:     $r->print('</th><th>');
 1098:     if ($env{'form.sortedby'} eq "revsubject") {
 1099: 	$r->print('<a href = "?sortedby=subject'.$fsqs.'">'.&mt('Subject').'</a>');
 1100:     } else {
 1101:     	$r->print('<a href = "?sortedby=revsubject'.$fsqs.'">'.&mt('Subject').'</a>');
 1102:     }
 1103:     $r->print('</th><th>');
 1104:     if ($env{'form.sortedby'} eq "revcourse") {
 1105:         $r->print('<a href = "?sortedby=course'.$fsqs.'">'.&mt('Course').'</a>');
 1106:     } else {
 1107:         $r->print('<a href = "?sortedby=revcourse'.$fsqs.'">'.&mt('Course').'</a>');
 1108:     }
 1109:     $r->print('</th><th>');
 1110:     if ($env{'form.sortedby'} eq "revstatus") {
 1111: 	$r->print('<a href = "?sortedby=status'.$fsqs.'">'.&mt('Status').'</a></th>');
 1112:     } else {
 1113:      	$r->print('<a href = "?sortedby=revstatus'.$fsqs.'">'.&mt('Status').'</a></th>');
 1114:     }
 1115:     $r->print("</tr>\n");
 1116:     for (my $n=$firstdis;$n<=$lastdis;$n++) {
 1117: 	my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,$description)= @{$temp[$n]};
 1118: 	if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
 1119: 	    if ($status eq 'new') {
 1120: 		$r->print('<tr bgcolor="#FFBB77" onMouseOver="javascript:style.backgroundColor=\'#DD9955\'"  onMouseOut="javascript:style.backgroundColor=\'#FFBB77\'">');
 1121: 	    } elsif ($status eq 'read') {
 1122: 		$r->print('<tr bgcolor="#BBBB77" onMouseOver="javascript:style.backgroundColor=\'#999944\'"  onMouseOut="javascript:style.backgroundColor=\'#BBBB77\'">');
 1123: 	    } elsif ($status eq 'replied') {
 1124: 		$r->print('<tr bgcolor="#AAAA88" onMouseOver="javascript:style.backgroundColor=\'#888855\'"  onMouseOut="javascript:style.backgroundColor=\'#AAAA88\'">'); 
 1125: 	    } else {
 1126: 		$r->print('<tr bgcolor="#99BBBB" onMouseOver="javascript:style.backgroundColor=\'#669999\'"  onMouseOut="javascript:style.backgroundColor=\'#99BBBB\'">');
 1127: 	    }
 1128: 	    $r->print('<td><input type="checkbox" name="delmark_'.$origID.'" /></td><td><a href="/adm/email?display='.$origID.$sqs. 
 1129: 		      '">'.&mt('Open').'</a></td><td>'.
 1130: 		      ($folder ne 'trash'?'<a href="/adm/email?markdel='.$origID.$sqs.
 1131: 		      '">'.&mt('Delete'):'&nbsp').'</a></td>'.
 1132: 		      '<td>'.&Apache::lonlocal::locallocaltime($sendtime).'</td><td>'.
 1133: 		      $fromname.'</td><td>'.$fromdomain.'</td><td>'.
 1134: 		      &Apache::lonnet::unescape($shortsubj).'</td><td>'.
 1135:                       $description.'</td><td>'.$status.'</td></tr>'."\n");
 1136: 	} elsif ($status eq 'deleted') {
 1137: # purge
 1138: 	    &movemsg(&Apache::lonnet::unescape($origID),$folder,'trash');
 1139: 	}
 1140:     }   
 1141:     $r->print("</table>\n<p>".
 1142:   '<a href="javascript:checkall()">'.&mt('Check All').'</a>&nbsp;'.
 1143:   '<a href="javascript:uncheckall()">'.&mt('Uncheck All').'</a></p>'.
 1144:   '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" />');
 1145:     if ($folder ne 'trash') {
 1146: 	$r->print(
 1147: 	      '<p><input type="submit" name="markeddel" value="'.&mt('Delete Checked').'" /></p>');
 1148:     }
 1149:     $r->print('<p><input type="submit" name="markedmove" value="'.&mt('Move Checked to Folder').'" />');
 1150:     my @allfolders=&Apache::lonnet::getkeys('email_folders');
 1151:     if ($allfolders[0]=~/^error:/) { @allfolders=(); }
 1152:     $r->print(
 1153: 	&Apache::loncommon::select_form('','movetofolder',
 1154: 			     ( map { $_ => $_ } @allfolders))
 1155: 	      );
 1156:     my $postedstartdis=$startdis+1;
 1157:     $r->print('<input type="hidden" name="folder" value="'.$folder.'" /><input type="hidden" name="startdis" value="'.$postedstartdis.'" /><input type="hidden" name="interdis" value="'.$env{'form.interdis'}.'" /></form>');
 1158:     if ($numblocked > 0) {
 1159:         my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
 1160:         my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
 1161:         $r->print('<br /><br />'.
 1162:                   $numblocked.' '.&mt('message(s) is/are not viewable because display of LON-CAPA messages sent to you by other students between').' '.$beginblock.' '.&mt('and').' '.$finishblock.' '.&mt('is currently being blocked because of online exams.'));
 1163:         &build_block_table($r,$startblock,$endblock,\%setters);
 1164:     }
 1165: }
 1166: 
 1167: # ============================================================== Compose output
 1168: 
 1169: sub compout {
 1170:     my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode)=@_;
 1171:     my $suffix=&foldersuffix($folder);
 1172: 
 1173:     if ($broadcast eq 'individual') {
 1174: 	&printheader($r,'/adm/email?compose=individual',
 1175: 	     'Send a Message');
 1176:     } elsif ($broadcast) {
 1177: 	&printheader($r,'/adm/email?compose=group',
 1178: 	     'Broadcast Message');
 1179:     } elsif ($forwarding) {
 1180: 	&Apache::lonhtmlcommon::add_breadcrumb
 1181:         ({href=>"/adm/email?display=".&Apache::lonnet::escape($forwarding),
 1182:           text=>"Display Message"});
 1183: 	&printheader($r,'/adm/email?forward='.&Apache::lonnet::escape($forwarding),
 1184: 	     'Forwarding a Message');
 1185:     } elsif ($replying) {
 1186: 	&Apache::lonhtmlcommon::add_breadcrumb
 1187:         ({href=>"/adm/email?display=".&Apache::lonnet::escape($replying),
 1188:           text=>"Display Message"});
 1189: 	&printheader($r,'/adm/email?replyto='.&Apache::lonnet::escape($replying),
 1190: 	     'Replying to a Message');
 1191:     } elsif ($replycrit) {
 1192: 	$r->print('<h3>'.&mt('Replying to a Critical Message').'</h3>');
 1193: 	$replying=$replycrit;
 1194:     } else {
 1195: 	&printheader($r,'/adm/email?compose=upload',
 1196: 	     'Distribute from Uploaded File');
 1197:     }
 1198: 
 1199:     my $dispcrit='';
 1200:     my $dissub='';
 1201:     my $dismsg='';
 1202:     my $disbase='';
 1203:     my $func=&mt('Send New');
 1204:     my %lt=&Apache::lonlocal::texthash('us' => 'Username',
 1205: 				       'do' => 'Domain',
 1206: 				       'ad' => 'Additional Recipients',
 1207: 				       'sb' => 'Subject',
 1208: 				       'ca' => 'Cancel',
 1209: 				       'ma' => 'Mail');
 1210: 
 1211:     if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
 1212: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
 1213:          $dispcrit=
 1214:  '<p><label><input type="checkbox" name="critmsg" /> '.&mt('Send as critical message').'</label> ' . $crithelp . 
 1215:  '</p><p>'.
 1216:  '<label><input type="checkbox" name="sendbck" /> '.&mt('Send as critical message').'  ' .
 1217:  &mt('and return receipt') . '</label>' . $crithelp . 
 1218:  '</p><p><label><input type="checkbox" name="permanent" /> '.
 1219: &mt('Send copy to permanent email address (if known)').'</label></p>'.
 1220: '<!-- <p><label><input type="checkbox" name="rsspost" /> '.
 1221: 		  &mt('Include in course RSS newsfeed').'</label></p>-->';      }
 1222:     my %message;
 1223:     my %content;
 1224:     my $defdom=$env{'user.domain'};
 1225:     if ($forwarding) {
 1226: 	%message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]);
 1227: 	%content=&unpackagemsg($message{$forwarding},$folder);
 1228: 	$dispcrit.='<input type="hidden" name="forwid" value="'.
 1229: 	    $forwarding.'" />';
 1230: 	$func=&mt('Forward');
 1231: 	
 1232: 	$dissub=&mt('Forwarding').': '.$content{'subject'};
 1233: 	$dismsg=&mt('Forwarded message from').' '.
 1234: 	    $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
 1235: 	if ($content{'baseurl'}) {
 1236: 	    $disbase='<input type="hidden" name="baseurl" value="'.&Apache::lonnet::escape($content{'baseurl'}).'" />';
 1237: 	}
 1238:     }
 1239:     if ($replying) {
 1240: 	%message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
 1241: 	%content=&unpackagemsg($message{$replying},$folder);
 1242: 	$dispcrit.='<input type="hidden" name="replyid" value="'.
 1243: 	    $replying.'" />';
 1244: 	$func=&mt('Send Reply to');
 1245: 	
 1246: 	$dissub=&mt('Reply').': '.$content{'subject'};       
 1247: 	$dismsg='> '.$content{'message'};
 1248: 	$dismsg=~s/\r/\n/g;
 1249: 	$dismsg=~s/\f/\n/g;
 1250: 	$dismsg=~s/\n+/\n\> /g;
 1251: 	if ($content{'baseurl'}) {
 1252: 	    $disbase='<input type="hidden" name="baseurl" value="'.&Apache::lonnet::escape($content{'baseurl'}).'" />';
 1253: 	    if ($env{'user.adv'}) {
 1254: 		$disbase.='<label><input type="checkbox" name="storebasecomment" />'.&mt('Store message for re-use').
 1255: 		    '</label> <a href="/adm/email?showcommentbaseurl='.
 1256: 		    &Apache::lonnet::escape($content{'baseurl'}).'" target="comments">'.
 1257: 		    &mt('Show re-usable messages').'</a><br />';
 1258: 	    }
 1259: 	}
 1260:     }
 1261:     my $citation=&displayresource(%content);
 1262:     if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
 1263:       $r->print(
 1264:                 '<form action="/adm/email"  name="compemail" method="post"'.
 1265:                 ' enctype="multipart/form-data">'."\n".
 1266:                 '<input type="hidden" name="sendmail" value="on" />'."\n".
 1267:                 '<table>');
 1268:     unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
 1269: 	if ($replying) {
 1270: 	    $r->print('<tr><td colspan="2">'.&mt('Replying to').' '.
 1271: 		      &Apache::loncommon::aboutmewrapper(
 1272: 							 &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
 1273: 		      $content{'sendername'}.'@'.
 1274: 		      $content{'senderdomain'}.')'.
 1275: 		      '<input type="hidden" name="recuname" value="'.$content{'sendername'}.'" />'.
 1276: 		      '<input type="hidden" name="recdomain" value="'.$content{'senderdomain'}.'" />'.
 1277: 		      '</td></tr>');
 1278: 	} else {
 1279: 	    my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
 1280: 	    my $selectlink=&Apache::loncommon::selectstudent_link
 1281: 	    ('compemail','recuname','recdomain');
 1282: 	    $r->print(<<"ENDREC");
 1283: <tr><td>$lt{'us'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recname'}" /></td><td rowspan="2">$selectlink</td></tr>
 1284: <tr><td>$lt{'do'}:</td>
 1285: <td>$domform</td></tr>
 1286: ENDREC
 1287:         }
 1288:     }
 1289:     my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
 1290:     if ($broadcast ne 'upload') {
 1291:        $r->print(<<"ENDCOMP");
 1292: <tr><td>$lt{'ad'}<br /><tt>username\@domain,username\@domain, ...
 1293: </tt></td><td>
 1294: <input type="text" size="50" name="additionalrec" /></td></tr>
 1295: <tr><td>$lt{'sb'}:</td><td><input type="text" size="50" name="subject" value="$dissub" />
 1296: </td></tr></table>
 1297: $latexHelp
 1298: <textarea name="message" id="message" cols="80" rows="15" wrap="hard">$dismsg
 1299: </textarea></p><br />
 1300: $dispcrit
 1301: $disbase
 1302: <input type="hidden" name="folder" value="$folder" />
 1303: <input type="hidden" name="dismode" value="$dismode" />
 1304: <input type="submit" name="send" value="$func $lt{'ma'}" />
 1305: <input type="submit" name="cancel" value="$lt{'ca'}" /><hr />
 1306: $citation
 1307: ENDCOMP
 1308:     } else { # $broadcast is 'upload'
 1309: 	$r->print(<<ENDUPLOAD);
 1310: <input type="hidden" name="sendmode" value="upload" />
 1311: <input type="hidden" name="send" value="on" />
 1312: <h3>Generate messages from a file</h3>
 1313: <p>
 1314: Subject: <input type="text" size="50" name="subject" />
 1315: </p>
 1316: <p>General message text<br />
 1317: <textarea name="message" id="message" cols="60" rows="10" wrap="hard">$dismsg
 1318: </textarea></p>
 1319: <p>
 1320: The file format for the uploaded portion of the message is:
 1321: <pre>
 1322: username1\@domain1: text
 1323: username2\@domain2: text
 1324: username3\@domain1: text
 1325: </pre>
 1326: </p>
 1327: <p>
 1328: The messages will be assembled from all lines with the respective 
 1329: <tt>username\@domain</tt>, and appended to the general message text.</p>
 1330: <p>
 1331: <input type="file" name="upfile" size="40" /></p><p>
 1332: $dispcrit
 1333: <input type="submit" value="Upload and Send" /></p>
 1334: ENDUPLOAD
 1335:     }
 1336:     if ($broadcast eq 'group') {
 1337:        &discourse;
 1338:     }
 1339:     $r->print('</form>'.
 1340: 	      &Apache::lonfeedback::generate_preview_button('compemail','message').
 1341: 	      &Apache::lonhtmlcommon::htmlareaselectactive('message'));
 1342: }
 1343: 
 1344: # ---------------------------------------------------- Display all face to face
 1345: 
 1346: sub retrieve_instructor_comments {
 1347:     my ($user,$domain)=@_;
 1348:     my $target=$env{'form.grade_target'};
 1349:     if (! $env{'request.course.id'}) { return; }
 1350:     if (! &Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
 1351: 	return;
 1352:     }
 1353:     my %records=&Apache::lonnet::dump('nohist_email',
 1354: 			 $env{'course.'.$env{'request.course.id'}.'.domain'},
 1355: 			 $env{'course.'.$env{'request.course.id'}.'.num'},
 1356:                          '%255b'.$user.'%253a'.$domain.'%255d');
 1357:     my $result='';
 1358:     foreach (sort(keys(%records))) {
 1359:         my %content=&unpackagemsg($records{$_});
 1360:         next if ($content{'senderdomain'} eq '');
 1361:         next if ($content{'subject'} !~ /^Record/);
 1362: 	# &Apache::lonfeedback::newline_to_br(\$content{'message'});
 1363: 	$result.='Recorded by '.
 1364:             $content{'sendername'}.'@'.$content{'senderdomain'}."\n";
 1365:         $result.=
 1366:             &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
 1367:      }
 1368:     return $result;
 1369: }
 1370: 
 1371: sub disfacetoface {
 1372:     my ($r,$user,$domain)=@_;
 1373:     my $target=$env{'form.grade_target'};
 1374:     unless ($env{'request.course.id'}) { return; }
 1375:     unless (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
 1376: 	return;
 1377:     }
 1378:     my %records=&Apache::lonnet::dump('nohist_email',
 1379: 			 $env{'course.'.$env{'request.course.id'}.'.domain'},
 1380: 			 $env{'course.'.$env{'request.course.id'}.'.num'},
 1381:                          '%255b'.$user.'%253a'.$domain.'%255d');
 1382:     my $result='';
 1383:     foreach (sort keys %records) {
 1384:         my %content=&unpackagemsg($records{$_});
 1385:         next if ($content{'senderdomain'} eq '');
 1386: 	&Apache::lonfeedback::newline_to_br(\$content{'message'});
 1387:         if ($content{'subject'}=~/^Record/) {
 1388: 	    $result.='<h3>'.&mt('Record').'</h3>';
 1389:         } elsif ($content{'subject'}=~/^Broadcast/) {
 1390:             $result .='<h3>'.&mt('Broadcast Message').'</h3>';
 1391:             if ($content{'subject'}=~/^Broadcast\./) {
 1392:                 %content=&unpackagemsg($content{'message'});
 1393:                 $content{'message'}=
 1394:                     '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
 1395:                     $content{'message'};
 1396:             }    
 1397:         } else {
 1398:             $result.='<h3>'.&mt('Critical Message').'</h3>';
 1399:             %content=&unpackagemsg($content{'message'});
 1400:             $content{'message'}=
 1401:                 '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
 1402: 		$content{'message'};
 1403:         }
 1404:         $result.=&mt('By').': <b>'.
 1405: &Apache::loncommon::aboutmewrapper(
 1406:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
 1407: $content{'sendername'}.'@'.
 1408:             $content{'senderdomain'}.') '.$content{'time'}.
 1409:             '<br /><pre>'.
 1410:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
 1411: 	      '</pre>';
 1412:      }
 1413:     # Check to see if there were any messages.
 1414:     if ($result eq '') {
 1415: 	if ($target ne 'tex') { 
 1416: 	    $r->print("<p><b>".&mt("No notes, face-to-face discussion records, critical messages, or broadcast messages in this course.")."</b></p>");
 1417: 	} else {
 1418: 	    $r->print('\textbf{'.&mt("No notes, face-to-face discussion records, critical messages or broadcast messages in this course.").'}\\\\');
 1419: 	}
 1420:     } else {
 1421:        $r->print($result);
 1422:     }
 1423: }
 1424: 
 1425: # ---------------------------------------------------------------- Face to face
 1426: 
 1427: sub facetoface {
 1428:     my ($r,$stage)=@_;
 1429:     unless (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
 1430: 	return;
 1431:     }
 1432:     &printheader($r,
 1433: 		 '/adm/email?recordftf=query',
 1434: 		 "User Notes, Face-to-Face, Critical Messages, Broadcast Messages");
 1435: # from query string
 1436: 
 1437:     if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
 1438:     if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
 1439: 
 1440:     my $defdom=$env{'user.domain'};
 1441: # already filled in
 1442:     if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
 1443: # generate output
 1444:     my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
 1445:     my $stdbrws = &Apache::loncommon::selectstudent_link
 1446: 	('stdselect','recuname','recdomain');
 1447:     my %lt=&Apache::lonlocal::texthash('user' => 'Username',
 1448: 				       'dom' => 'Domain',
 1449: 				       'head' => 'User Notes, Records of Face-To-Face Discussions, Critical Messages, and Broadcast Messages in Course',
 1450: 				       'subm' => 'Retrieve discussion and message records',
 1451: 				       'newr' => 'New Record (record is visible to course faculty and staff)',
 1452: 				       'post' => 'Post this Record');
 1453:     $r->print(<<"ENDTREC");
 1454: <h3>$lt{'head'}</h3>
 1455: <form method="post" action="/adm/email" name="stdselect">
 1456: <input type="hidden" name="recordftf" value="retrieve" />
 1457: <table>
 1458: <tr><td>$lt{'user'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recuname'}" /></td>
 1459: <td rowspan="2">
 1460: $stdbrws
 1461: <input type="submit" value="$lt{'subm'}" /></td>
 1462: </tr>
 1463: <tr><td>$lt{'dom'}:</td>
 1464: <td>$domform</td></tr>
 1465: </table>
 1466: </form>
 1467: ENDTREC
 1468:     if (($stage ne 'query') &&
 1469:         ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
 1470:         chomp($env{'form.newrecord'});
 1471:         if ($env{'form.newrecord'}) {
 1472:            my $recordtxt = $env{'form.newrecord'};
 1473:            &user_normal_msg_raw(
 1474:             $env{'course.'.$env{'request.course.id'}.'.num'},
 1475:             $env{'course.'.$env{'request.course.id'}.'.domain'},
 1476:             &mt('Record').
 1477: 	     ' ['.$env{'form.recuname'}.':'.$env{'form.recdomain'}.']',
 1478: 	    $recordtxt);
 1479:         }
 1480:         $r->print('<h3>'.&Apache::loncommon::plainname($env{'form.recuname'},
 1481: 				     $env{'form.recdomain'}).'</h3>');
 1482:         &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
 1483: 	$r->print(<<ENDRHEAD);
 1484: <form method="post" action="/adm/email">
 1485: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
 1486: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
 1487: ENDRHEAD
 1488:         $r->print(<<ENDBFORM);
 1489: <hr />$lt{'newr'}<br />
 1490: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
 1491: <br />
 1492: <input type="hidden" name="recordftf" value="post" />
 1493: <input type="submit" value="$lt{'post'}" />
 1494: </form>
 1495: ENDBFORM
 1496:     }
 1497: }
 1498: 
 1499: # ----------------------------------------------------------- Blocking during exams
 1500: 
 1501: sub examblock {
 1502:     my ($r,$action) = @_;
 1503:     unless ($env{'request.course.id'}) { return;}
 1504:     unless (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) { $r->print('Not allowed'); }
 1505:     my %lt=&Apache::lonlocal::texthash(
 1506:             'comb' => 'Communication Blocking',
 1507:             'cbds' => 'Communication blocking during scheduled exams',
 1508:             'desc' => 'You can use communication blocking to prevent students enrolled in this course from displaying LON-CAPA messages sent by other students during an online exam. As blocking of communication could potentially interrupt legitimate communication between students who are also both enrolled in a different LON-CAPA course, please be careful that you select the correct start and end times for your scheduled exam when setting or modifying these parameters.',
 1509:              'mecb' => 'Modify existing communication blocking periods',
 1510:              'ncbc' => 'No communication blocks currently stored'
 1511:     );
 1512: 
 1513:     my %ltext = &Apache::lonlocal::texthash(
 1514:             'dura' => 'Duration',
 1515:             'setb' => 'Set by',
 1516:             'even' => 'Event',
 1517:             'actn' => 'Action',
 1518:             'star' => 'Start',
 1519:             'endd' => 'End'
 1520:     );
 1521: 
 1522:     &printheader($r,'/adm/email?block=display',$lt{'comb'});
 1523:     $r->print('<h3>'.$lt{'cbds'}.'</h3>');
 1524: 
 1525:     if ($action eq 'store') {
 1526:         &blockstore($r);
 1527:     }
 1528: 
 1529:     $r->print($lt{'desc'}.'<br /><br />
 1530:                <form name="blockform" method="post" action="/adm/email?block=store">
 1531:              ');
 1532: 
 1533:     $r->print('<h4>'.$lt{'mecb'}.'</h4>');
 1534:     my %records = ();
 1535:     my $blockcount = 0;
 1536:     my $parmcount = 0;
 1537:     &get_blockdates(\%records,\$blockcount);
 1538:     if ($blockcount > 0) {
 1539:         $parmcount = &display_blocker_status($r,\%records,\%ltext);
 1540:     } else {
 1541:         $r->print($lt{'ncbc'}.'<br /><br />');
 1542:     }
 1543:     &display_addblocker_table($r,$parmcount,\%ltext);
 1544:     my $endbody=&Apache::loncommon::endbodytag();
 1545:     $r->print(<<"END");
 1546: <br />
 1547: <input type="hidden" name="blocktotal" value="$blockcount" />
 1548: <input type ="submit" value="Save Changes" />
 1549: </form>
 1550: $endbody
 1551: </html>
 1552: END
 1553:     return;
 1554: }
 1555: 
 1556: sub blockstore {
 1557:     my $r = shift;
 1558:     my %lt=&Apache::lonlocal::texthash(
 1559:             'tfcm' => 'The following changes were made',
 1560:             'cbps' => 'communication blocking period(s)',
 1561:             'werm' => 'was/were removed',
 1562:             'wemo' => 'was/were modified',
 1563:             'wead' => 'was/were added',
 1564:             'ncwm' => 'No changes were made.' 
 1565:     );
 1566:     my %adds = ();
 1567:     my %removals = ();
 1568:     my %cancels = ();
 1569:     my $modtotal = 0;
 1570:     my $canceltotal = 0;
 1571:     my $addtotal = 0;
 1572:     my %blocking = ();
 1573:     $r->print('<h3>'.$lt{'head'}.'</h3>');
 1574:     foreach (keys %env) {
 1575:         if ($_ =~ m/^form\.modify_(\w+)$/) {
 1576:             $adds{$1} = $1;
 1577:             $removals{$1} = $1;
 1578:             $modtotal ++;
 1579:         } elsif ($_ =~ m/^form\.cancel_(\d+)$/) {
 1580:             $cancels{$1} = $1;
 1581:             unless ( defined($removals{$1}) ) {
 1582:                 $removals{$1} = $1;
 1583:                 $canceltotal ++;
 1584:             }
 1585:         } elsif ($_ =~ m/^form\.add_(\d+)$/) {
 1586:             $adds{$1} = $1;
 1587:             $addtotal ++;
 1588:         }
 1589:     }
 1590: 
 1591:     foreach (keys %removals) {
 1592:         my $hashkey = $env{'form.key_'.$_};
 1593:         &Apache::lonnet::del('comm_block',["$hashkey"],
 1594:                          $env{'course.'.$env{'request.course.id'}.'.domain'},
 1595:                          $env{'course.'.$env{'request.course.id'}.'.num'}
 1596:                          );
 1597:     }
 1598:     foreach (keys %adds) {
 1599:         unless ( defined($cancels{$_}) ) {
 1600:             my ($newstart,$newend) = &get_dates_from_form($_);
 1601:             my $newkey = $newstart.'____'.$newend;
 1602:             $blocking{$newkey} = $env{'user.name'}.'@'.$env{'user.domain'}.':'.$env{'form.title_'.$_};
 1603:         }
 1604:     }
 1605:     if ($addtotal + $modtotal > 0) {
 1606:         &Apache::lonnet::put('comm_block',\%blocking,
 1607:                      $env{'course.'.$env{'request.course.id'}.'.domain'},
 1608:                      $env{'course.'.$env{'request.course.id'}.'.num'}
 1609:                      );
 1610:     }
 1611:     my $chgestotal = $canceltotal + $modtotal + $addtotal;
 1612:     if ($chgestotal > 0) {
 1613:         $r->print($lt{'tfcm'}.'<ul>');
 1614:         if ($canceltotal > 0) {
 1615:             $r->print('<li>'.$canceltotal.' '.$lt{'cbps'},' '.$lt{'werm'}.'</li>');
 1616:         }
 1617:         if ($modtotal > 0) {
 1618:             $r->print('<li>'.$modtotal.' '.$lt{'cbps'},' '.$lt{'wemo'}.'</li>');
 1619:         }
 1620:         if ($addtotal > 0) {
 1621:             $r->print('<li>'.$addtotal.' '.$lt{'cbps'},' '.$lt{'wead'}.'</li>');
 1622:         }
 1623:         $r->print('</ul>');
 1624:     } else {
 1625:         $r->print($lt{'ncwm'});
 1626:     }
 1627:     $r->print('<br />');
 1628:     return;
 1629: }
 1630: 
 1631: sub get_dates_from_form {
 1632:     my $item = shift;
 1633:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
 1634:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
 1635:     return ($startdate,$enddate);
 1636: }
 1637: 
 1638: sub get_blockdates {
 1639:     my ($records,$blockcount) = @_;
 1640:     $$blockcount = 0;
 1641:     %{$records} = &Apache::lonnet::dump('comm_block',
 1642:                          $env{'course.'.$env{'request.course.id'}.'.domain'},
 1643:                          $env{'course.'.$env{'request.course.id'}.'.num'}
 1644:                          );
 1645:     $$blockcount = keys %{$records};
 1646:                                                                                                              
 1647:     foreach (keys %{$records}) {
 1648:         if ($_ eq 'error: 2 tie(GDBM) Failed while attempting dump') {
 1649:             $$blockcount = 0;
 1650:             last;
 1651:         }
 1652:     }
 1653: }
 1654: 
 1655: sub display_blocker_status {
 1656:     my ($r,$records,$ltext) = @_;
 1657:     my $parmcount = 0;
 1658:     my @bgcols = ("#eeeeee","#dddddd");
 1659:     my $function = &Apache::loncommon::get_users_function();
 1660:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
 1661:                                                     $env{'user.domain'});
 1662:     my %lt = &Apache::lonlocal::texthash(
 1663:         'modi' => 'Modify',
 1664:         'canc' => 'Cancel',
 1665:     );
 1666:     $r->print(<<"END");
 1667: <table border="0" cellpadding="0" cellspacing="0">
 1668:  <tr>
 1669:   <td width="100%" bgcolor="#000000">
 1670:    <table width="100%" border="0" cellpadding="1" cellspacing="0">
 1671:     <tr>
 1672:      <td width="100%" bgcolor="#000000">
 1673:       <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
 1674:        <tr bgcolor="$color">
 1675:         <td><b>$$ltext{'dura'}</b></td>
 1676:         <td><b>$$ltext{'setb'}</b></td>
 1677:         <td><b>$$ltext{'even'}</b></td>
 1678:         <td><b>$$ltext{'actn'}?</b></td>
 1679:        </tr>
 1680: END
 1681:     foreach (sort keys %{$records}) {
 1682:         my $iter = $parmcount%2;
 1683:         my $onchange = 'onFocus="javascript:window.document.forms['.
 1684:                        "'blockform'].elements['modify_".$parmcount."'].".
 1685:                        'checked=true;"';
 1686:         my ($start,$end) = split/____/,$_;
 1687:         my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
 1688:         my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
 1689:         my ($setter,$title) = split/:/,$$records{$_};
 1690:         my ($setuname,$setudom) = split/@/,$setter;
 1691:         my $settername = &Apache::loncommon::plainname($setuname,$setudom);
 1692:         $r->print(<<"END");
 1693:        <tr bgcolor="$bgcols[$iter]">
 1694:         <td>$$ltext{'star'}:&nbsp;$startform<br/>$$ltext{'endd'}:&nbsp;&nbsp;$endform</td>
 1695:         <td>$settername</td>
 1696:         <td><input type="text" name="title_$parmcount" size="15" value="$title" /><input type="hidden" name="key_$parmcount" value="$_" /></td>
 1697:         <td><label>$lt{'modi'}?&nbsp;<input type="checkbox" name="modify_$parmcount" /></label><br /><label>$lt{'canc'}?&nbsp;&nbsp;<input type="checkbox" name="cancel_$parmcount" /></label>
 1698:        </tr>
 1699: END
 1700:         $parmcount ++;
 1701:     }
 1702:     $r->print(<<"END");
 1703:       </table>
 1704:      </td>
 1705:     </tr>
 1706:    </table>
 1707:   </td>
 1708:  </tr>
 1709: </table>
 1710: <br />
 1711: <br />
 1712: END
 1713:     return $parmcount;
 1714: }
 1715: 
 1716: sub display_addblocker_table {
 1717:     my ($r,$parmcount,$ltext) = @_;
 1718:     my $start = time;
 1719:     my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
 1720:     my $onchange = 'onFocus="javascript:window.document.forms['.
 1721:                    "'blockform'].elements['add_".$parmcount."'].".
 1722:                    'checked=true;"';
 1723:     my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
 1724:     my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
 1725:     my $function = &Apache::loncommon::get_users_function();
 1726:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
 1727:                                                     $env{'user.domain'});
 1728:     my %lt = &Apache::lonlocal::texthash(
 1729:         'addb' => 'Add block',
 1730:         'exam' => 'e.g., Exam 1',
 1731:         'addn' => 'Add new communication blocking periods'
 1732:     );
 1733:     $r->print(<<"END");
 1734: <h4>$lt{'addn'}</h4> 
 1735: <table border="0" cellpadding="0" cellspacing="0">
 1736:  <tr>
 1737:   <td width="100%" bgcolor="#000000">
 1738:    <table width="100%" border="0" cellpadding="1" cellspacing="0">
 1739:     <tr>
 1740:      <td width="100%" bgcolor="#000000">
 1741:       <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
 1742:        <tr bgcolor="#CCCCFF">
 1743:         <td><b>$$ltext{'dura'}</b></td>
 1744:         <td><b>$$ltext{'even'} $lt{'exam'}</b></td>
 1745:         <td><b>$$ltext{'actn'}?</b></td>
 1746:        </tr>
 1747:        <tr bgcolor="#eeeeee">
 1748:         <td>$$ltext{'star'}:&nbsp;$startform<br />$$ltext{'endd'}:&nbsp;&nbsp;$endform</td>
 1749:         <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
 1750:         <td><label>$lt{'addb'}?&nbsp;<input type="checkbox" name="add_$parmcount" value="1" /></label></td>
 1751:        </tr>
 1752:       </table>
 1753:      </td>
 1754:     </tr>
 1755:    </table>
 1756:   </td>
 1757:  </tr>
 1758: </table>
 1759: END
 1760:     return;
 1761: }
 1762: 
 1763: sub blockcheck {
 1764:     my ($setters,$startblock,$endblock) = @_;
 1765:     # Retrieve active student roles and active course coordinator/instructor roles
 1766:     my @livecses = ();
 1767:     my @staffcses = ();
 1768:     $$startblock = 0;
 1769:     $$endblock = 0;
 1770:     foreach (keys %env) {
 1771:         if ($_ =~ m-^user\.role\.(st|cc|in)\./(.+)$-) {
 1772:             my $role = $1;
 1773:             my $cse = $2;
 1774:             $cse =~ s|/|_|;
 1775:             if ($env{$_} =~ m/^(\d*)\.(\d*)$/) {
 1776:                 unless (($2 > 0 && $2 < time) || ($1 > time)) {
 1777:                     if ($role eq 'st') {
 1778:                         push @livecses, $cse;
 1779:                     } else {
 1780:                         unless (grep/^$cse$/,@staffcses) {
 1781:                             push @staffcses, $cse;
 1782:                         }
 1783:                     }
 1784:                 }
 1785:             }
 1786:         } elsif ($_ =~ m-user\.role\.cr/(\w+)/(\w+)/([^/]+)\./(.+)$- ) { 
 1787:             my $rolepriv = $env{'user.role..rolesdef_'.$3};
 1788:         }
 1789:     }
 1790:     # Retrieve blocking times and identity of blocker for active courses for students.
 1791:     if (@livecses > 0) {
 1792:         foreach my $cse (@livecses) {
 1793:             my ($cdom,$crs) = split/_/,$cse;
 1794:             if ( (grep/^$cse$/,@staffcses) && ($env{'request.role'} !~ m-^st\./$cdom/$crs$-) ) {
 1795:                 next;
 1796:             } else {
 1797:                 %{$$setters{$cse}} = ();
 1798:                 @{$$setters{$cse}{'staff'}} = ();
 1799:                 @{$$setters{$cse}{'times'}} = ();
 1800:                 my %records = &Apache::lonnet::dump('comm_block',$cdom,$crs);
 1801:                 foreach (keys %records) {
 1802:                     if ($_ =~ m/^(\d+)____(\d+)$/) {
 1803:                         if ($1 <= time && $2 >= time) {
 1804:                             my ($staff,$title) = split/:/,$records{$_};
 1805:                             push @{$$setters{$cse}{'staff'}}, $staff;
 1806:                             push @{$$setters{$cse}{'times'}}, $_;
 1807:                             if ( ($$startblock == 0) || ($$startblock > $1) ) {
 1808:                                 $$startblock = $1;
 1809:                             }
 1810:                             if ( ($$endblock == 0) || ($$endblock < $2) ) {
 1811:                                 $$endblock = $2;
 1812:                             }
 1813:                         }
 1814:                     }
 1815:                 }
 1816:             }
 1817:         }
 1818:     }
 1819: }
 1820: 
 1821: sub build_block_table {
 1822:     my ($r,$startblock,$endblock,$setters) = @_;
 1823:     my $function = &Apache::loncommon::get_users_function();
 1824:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
 1825:                                                     $env{'user.domain'});
 1826:     my %lt = &Apache::lonlocal::texthash(
 1827:         'cacb' => 'Currently active communication blocks',
 1828:         'cour' => 'Course',
 1829:         'dura' => 'Duration',
 1830:         'blse' => 'Block set by'
 1831:     ); 
 1832:     $r->print(<<"END");
 1833: <br /<br />$lt{'cacb'}:<br /><br />
 1834: <table border="0" cellpadding="0" cellspacing="0">
 1835:  <tr>
 1836:   <td width="100%" bgcolor="#000000">
 1837:    <table width="100%" border="0" cellpadding="1" cellspacing="0">
 1838:     <tr>
 1839:      <td width="100%" bgcolor="#000000">
 1840:       <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
 1841:        <tr bgcolor="$color">
 1842:         <td><b>$lt{'cour'}</b></td>
 1843:         <td><b>$lt{'dura'}</b></td>
 1844:         <td><b>$lt{'blse'}</b></td>
 1845:        </tr>
 1846: END
 1847:     foreach (keys %{$setters}) {
 1848:         my %courseinfo=&Apache::lonnet::coursedescription($_);
 1849:         for (my $i=0; $i<@{$$setters{$_}{staff}}; $i++) {
 1850:             my ($uname,$udom) = split/\@/,$$setters{$_}{staff}[$i];
 1851:             my $fullname = &Apache::loncommon::plainname($uname,$udom);
 1852:             my ($openblock,$closeblock) = split/____/,$$setters{$_}{times}[$i];
 1853:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
 1854:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
 1855:             $r->print('<tr><td>'.$courseinfo{'description'}.'</td>'.
 1856:                       '<td>'.$openblock.' to '.$closeblock.'</td>'.
 1857:                       '<td>'.$fullname.' ('.$uname.'@'.$udom.
 1858:                       ')</td></tr>');
 1859:         }
 1860:     }
 1861:     $r->print('</table></td></tr></table></td></tr></table>');
 1862: }
 1863: 
 1864: # ----------------------------------------------------------- Display a message
 1865: 
 1866: sub displaymessage {
 1867:     my ($r,$msgid,$folder)=@_;
 1868:     my $suffix=&foldersuffix($folder);
 1869:     my %blocked = ();
 1870:     my %setters = ();
 1871:     my $startblock = 0;
 1872:     my $endblock = 0;
 1873:     my $numblocked = 0;
 1874: # info to generate "next" and "previous" buttons and check if message is blocked
 1875:     &blockcheck(\%setters,\$startblock,\$endblock);
 1876:     my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder);
 1877:     if ( $blocked{$msgid} eq 'ON' ) {
 1878:         &printheader($r,'/adm/email',&mt('Display a Message'));
 1879:         $r->print(&mt('You attempted to display a message that is currently blocked because you are enrolled in one or more courses for which there is an ongoing online exam.'));
 1880:         &build_block_table($r,$startblock,$endblock,\%setters);
 1881:         return;
 1882:     }
 1883:     &statuschange($msgid,'read',$folder);
 1884:     my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
 1885:     my %content=&unpackagemsg($message{$msgid});
 1886: 
 1887:     my $counter=0;
 1888:     $r->print('<pre>');
 1889:     my $escmsgid=&Apache::lonnet::escape($msgid);
 1890:     foreach (@messages) {
 1891: 	if ($_->[5] eq $escmsgid){
 1892: 	    last;
 1893: 	}
 1894: 	$counter++;
 1895:     }
 1896:     $r->print('</pre>');
 1897:     my $number_of_messages = scalar(@messages); #subtract 1 for last index
 1898: # start output
 1899:     &printheader($r,'/adm/email?display='.&Apache::lonnet::escape($msgid),'Display a Message','',$content{'baseurl'});
 1900:     my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'});
 1901: # Functions
 1902:     $r->print('<table border="2" width="100%"><tr bgcolor="#FFFFAA"><td>'.&mt('Functions').':</td>'.
 1903: 	      '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).$sqs.
 1904: 	      '"><b>'.&mt('Reply').'</b></a></td>'.
 1905: 	      '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).$sqs.
 1906: 	      '"><b>'.&mt('Forward').'</b></a></td>'.
 1907: 	      '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).$sqs.
 1908: 	      '"><b>'.&mt('Mark Unread').'</b></a></td>'.
 1909: 	      '<td><a href="/adm/email?markdel='.&Apache::lonnet::escape($msgid).$sqs.
 1910: 	      '"><b>'.&mt('Delete').'</b></a></td>'.
 1911: 	      '<td><a href="/adm/email?'.$sqs.
 1912: 	      ($env{'form.dismode'} eq 'new'?'&folder=new':'').
 1913: 	      '"><b>'.&mt('Back to Folder Display').'</b></a></td>');
 1914:     if ($counter > 0){
 1915: 	$r->print('<td><a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.
 1916: 		  '"><b>'.&mt('Previous').'</b></a></td>');
 1917:     }
 1918:     if ($counter < $number_of_messages - 1){
 1919: 	$r->print('<td><a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.
 1920: 		  '"><b>'.&mt('Next').'</b></a></td>');
 1921:     }
 1922:     $r->print('</tr></table>');
 1923:     if ($env{'user.adv'}) {
 1924: 	$r->print('<table border="2" width="100%"><tr bgcolor="#FFAAAA"><td>'.&mt('Currently available actions (will open extra window)').':</td>');
 1925: 	my $symb=&Apache::lonnet::symbread($content{'baseurl'});      
 1926: 	if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
 1927: 		$r->print('<td><b>'.&Apache::loncommon::track_student_link(&mt('View recent activity'),$content{'sendername'},$content{'senderdomain'},'check').'</b></td>');
 1928: 	    }
 1929: 	if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
 1930: 	    $r->print('<td><b>'.&Apache::loncommon::pprmlink(&mt('Set/Change parameters'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
 1931: 	}
 1932: 	if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
 1933: 	    $r->print('<td><b>'.&Apache::loncommon::pgrdlink(&mt('Set/Change grades'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
 1934: 	}
 1935: 	$r->print('</tr></table>');
 1936:     }
 1937:     my $tolist;
 1938:     my @recipients = ();
 1939:     for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
 1940:         $recipients[$i] =  &Apache::loncommon::aboutmewrapper(
 1941:            &Apache::loncommon::plainname($content{'recuser'}[$i],
 1942:                                       $content{'recdomain'}[$i]),
 1943:               $content{'recuser'}[$i],$content{'recdomain'}[$i]).
 1944:        ' ('.$content{'recuser'}[$i].' at '.$content{'recdomain'}[$i].') ';
 1945:     }
 1946:     $tolist = join(', ',@recipients);
 1947:     $r->print('<br /><b>'.&mt('Subject').':</b> '.$content{'subject'}.
 1948: 	      ($folder ne 'sent'?'<br /><b>'.&mt('From').':</b> '.
 1949: 	      &Apache::loncommon::aboutmewrapper(
 1950: 						 &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
 1951: 						 $content{'sendername'},$content{'senderdomain'}).' ('.
 1952: 	      $content{'sendername'}.' at '.
 1953: 	      $content{'senderdomain'}.') ':'<br /><b>'.&mt('To').':</b> '.
 1954:               $tolist).
 1955: 	      ($content{'courseid'}?'<br /><b>'.&mt('Course').':</b> '.$courseinfo{'description'}.
 1956: 	       ($content{'coursesec'}?' ('.&mt('Group/Section').': '.$content{'coursesec'}.')':''):'').
 1957: 	      '<br /><b>'.&mt('Time').':</b> '.$content{'time'}.
 1958: 	      ($content{'baseurl'}?'<br /><b>'.&mt('Refers to').':</b> <a href="'.$content{'baseurl'}.'">'.
 1959: 	       $content{'baseurl'}.' ('.&Apache::lonnet::gettitle($content{'baseurl'}).')</a>':'').
 1960: 	      '<p><pre>'.
 1961: 	      &Apache::lontexconvert::msgtexconverted($content{'message'},1).
 1962: 	      '</pre><hr />'.&displayresource(%content).'</p>');
 1963:     return;   
 1964: }
 1965: 
 1966: # =========================================================== Show the citation
 1967: 
 1968: sub displayresource {
 1969:     my %content=@_;
 1970: #
 1971: # If the recipient is in the same course that the message was sent from and
 1972: # has sufficient privileges, show "all details," else show citation
 1973: #
 1974:     if (($env{'request.course.id'} eq $content{'courseid'})
 1975:      && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
 1976: 	my $symb=&Apache::lonnet::symbread($content{'baseurl'});
 1977: # Could not get a symb, give up
 1978: 	unless ($symb) { return $content{'citation'}; }
 1979: # Have a symb, can render
 1980: 	return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
 1981: 	    &Apache::loncommon::get_previous_attempt($symb,
 1982: 						     $content{'sendername'},
 1983: 						     $content{'senderdomain'},
 1984: 						     $content{'courseid'}).
 1985: 	    '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
 1986: 	    &Apache::loncommon::get_student_view($symb,
 1987: 						 $content{'sendername'},
 1988: 						 $content{'senderdomain'},
 1989: 						 $content{'courseid'}).
 1990: 	    '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
 1991: 	    &Apache::loncommon::get_student_answers($symb,
 1992: 						    $content{'sendername'},
 1993: 						    $content{'senderdomain'},
 1994: 						    $content{'courseid'});
 1995:     } else {
 1996: 	return $content{'citation'};
 1997:     }
 1998: }
 1999: 
 2000: # ================================================================== The Header
 2001: 
 2002: sub header {
 2003:     my ($r,$title,$baseurl)=@_;
 2004:     $r->print(&Apache::lonxml::xmlbegin().
 2005: 	      '<head>'.&Apache::lonxml::fontsettings().
 2006: 	      '<title>Communication and Messages</title>'.
 2007: 	      &Apache::lonhtmlcommon::htmlareaheaders());
 2008:     if ($baseurl) {
 2009: 	$r->print("<base href=\"http://$ENV{'SERVER_NAME'}/$baseurl\" />");
 2010:     }
 2011:     $r->print(&Apache::loncommon::studentbrowser_javascript().'</head>'.
 2012: 	      &Apache::loncommon::bodytag('Communication and Messages'));
 2013:         $r->print(&Apache::lonhtmlcommon::breadcrumbs
 2014:                   (undef,($title?$title:'Communication and Messages')));
 2015: 
 2016: }
 2017: 
 2018: # ---------------------------------------------------------------- Print header
 2019: 
 2020: sub printheader {
 2021:     my ($r,$url,$desc,$title,$baseurl)=@_;
 2022:     &Apache::lonhtmlcommon::add_breadcrumb
 2023: 	({href=>$url,
 2024: 	  text=>$desc});
 2025:     &header($r,$title,$baseurl);
 2026: }
 2027: 
 2028: # ------------------------------------------------------------ Store the comment
 2029: 
 2030: sub storecomment {
 2031:     my ($r)=@_;
 2032:     my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
 2033:     my $cleanmsgtxt='';
 2034:     foreach (split(/[\n\r]/,$msgtxt)) {
 2035: 	unless ($_=~/^\s*(\>|\&gt\;)/) {
 2036: 	    $cleanmsgtxt.=$_."\n";
 2037: 	}
 2038:     }
 2039:     my $key=&Apache::lonnet::escape($env{'form.baseurl'}).'___'.time;
 2040:     &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
 2041: }
 2042: 
 2043: sub storedcommentlisting {
 2044:     my ($r)=@_;
 2045:     my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
 2046:        '^'.&Apache::lonnet::escape(&Apache::lonnet::escape($env{'form.showcommentbaseurl'})));
 2047:     $r->print(&Apache::lonxml::xmlbegin().'<head>'.
 2048: 	      &Apache::lonxml::fontsettings().'</head><body>');
 2049:     if ((keys %msgs)[0]=~/^error\:/) {
 2050: 	$r->print(&mt('No stored comments yet.'));
 2051:     } else {
 2052: 	my $found=0;
 2053: 	foreach (sort keys %msgs) {
 2054: 	    $r->print("\n".$msgs{$_}."<hr />");
 2055: 	    $found=1;
 2056: 	}
 2057: 	unless ($found) {
 2058: 	    $r->print(&mt('No stored comments yet for this resource.'));
 2059: 	}
 2060:     }
 2061: }
 2062: 
 2063: # ---------------------------------------------------------------- Send an email
 2064: 
 2065: sub sendoffmail {
 2066:     my ($r,$folder)=@_;
 2067:     my $suffix=&foldersuffix($folder);
 2068:     my $sendstatus='';
 2069:     my %specialmsg_status;
 2070:     my $numspecial = 0;
 2071:     if ($env{'form.send'}) {
 2072: 	&printheader($r,'','Messages being sent.');
 2073: 	$r->rflush();
 2074: 	my %content=();
 2075: 	undef %content;
 2076: 	if ($env{'form.forwid'}) {
 2077: 	    my $msgid=$env{'form.forwid'};
 2078: 	    my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
 2079: 	    %content=&unpackagemsg($message{$msgid},1);
 2080: 	    &statuschange($msgid,'forwarded',$folder);
 2081: 	    $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
 2082: 		$content{'message'};
 2083: 	}
 2084: 	if ($env{'form.replyid'}) {
 2085: 	    my $msgid=$env{'form.replyid'};
 2086: 	    my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
 2087: 	    %content=&unpackagemsg($message{$msgid},1);
 2088: 	    &statuschange($msgid,'replied',$folder);
 2089: 	}
 2090: 	my %toaddr=();
 2091: 	undef %toaddr;
 2092: 	if ($env{'form.sendmode'} eq 'group') {
 2093: 	    foreach (keys %env) {
 2094: 		if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
 2095: 		    $toaddr{$1}='';
 2096: 		}
 2097: 	    }
 2098: 	} elsif ($env{'form.sendmode'} eq 'upload') {
 2099: 	    foreach (split(/[\n\r\f]+/,$env{'form.upfile'})) {
 2100: 		my ($rec,$txt)=split(/\s*\:\s*/,$_);
 2101: 		if ($txt) {
 2102: 		    $rec=~s/\@/\:/;
 2103: 		    $toaddr{$rec}.=$txt."\n";
 2104: 		}
 2105: 	    }
 2106: 	} else {
 2107: 	    $toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
 2108: 	}
 2109: 	if ($env{'form.additionalrec'}) {
 2110: 	    foreach (split(/\,/,$env{'form.additionalrec'})) {
 2111: 		my ($auname,$audom)=split(/\@/,$_);
 2112: 		$toaddr{$auname.':'.$audom}='';
 2113: 	    }
 2114: 	}
 2115: 
 2116:         my $savemsg;
 2117:         my $msgtype;
 2118:         my %sentmessage;
 2119:         if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
 2120:             (&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) {
 2121:             $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
 2122:             $msgtype = 'critical';
 2123:         } else {
 2124:             $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
 2125:         }
 2126: 	
 2127: 	foreach (keys %toaddr) {
 2128: 	    my ($recuname,$recdomain)=split(/\:/,$_);
 2129:             my $msgtxt = $savemsg;
 2130: 	    if ($toaddr{$_}) { $msgtxt.='<hr />'.$toaddr{$_}; }
 2131: 	    my $thismsg;
 2132: 	    if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) && 
 2133: 		(&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) {
 2134: 		$r->print(&mt('Sending critical message').' '.$recuname.'@'.$recdomain.': ');
 2135: 		$thismsg=&user_crit_msg($recuname,$recdomain,
 2136: 					&Apache::lonfeedback::clear_out_html($env{'form.subject'}),
 2137: 					$msgtxt,
 2138: 					$env{'form.sendbck'},$env{'form.permanent'},\$sentmessage{$_});
 2139: 	    } else {
 2140: 		$r->print(&mt('Sending').' '.$recuname.'@'.$recdomain.': ');
 2141: 		$thismsg=&user_normal_msg($recuname,$recdomain,
 2142: 					  &Apache::lonfeedback::clear_out_html($env{'form.subject'}),
 2143: 					  $msgtxt,
 2144: 					  $content{'citation'},undef,undef,$env{'form.permanent'},\$sentmessage{$_});
 2145:             }
 2146: 	    if (($env{'request.course.id'}) && (($msgtype eq 'critical') || 
 2147:                                          ($env{'form.sendmode'} eq 'group'))) {
 2148: 	        $specialmsg_status{$recuname.':'.$recdomain}  = $thismsg;
 2149:                 if ($thismsg eq 'ok') {
 2150:                     $numspecial ++;
 2151:                 }
 2152: 	    }
 2153: 	    $r->print($thismsg.'<br />');
 2154: 	    $sendstatus.=' '.$thismsg;
 2155: 	}
 2156:         if (($env{'request.course.id'}) && (($env{'form.sendmode'} eq 'group')
 2157:                                               || ($msgtype eq 'critical'))) {
 2158:             my $subj_prefix;
 2159:             if ($msgtype eq 'critical') {
 2160:                 $subj_prefix = 'Critical.';
 2161:             } else {
 2162:                 $subj_prefix = 'Broadcast.';
 2163:             }
 2164:             my ($specialmsgid,$specialresult);
 2165:             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 2166:             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 2167:             my $course_str = &Apache::lonnet::escape('['.$cnum.':'.$cdom.']');
 2168: 
 2169:             if ($numspecial) {
 2170:                 $specialresult = &user_normal_msg_raw($cnum,$cdom,$subj_prefix.
 2171:                     ' '.$course_str,$savemsg,undef,undef,undef,
 2172:                     undef,undef,\$specialmsgid);
 2173:                 $specialmsgid = &Apache::lonnet::unescape($specialmsgid);
 2174:             }
 2175:             if ($specialresult eq 'ok') {
 2176:                 my $record_sent;
 2177:                 my @recusers = ();
 2178:                 my @recudoms = ();
 2179:                 my ($stamp,$msgsubj,$msgname,$msgdom,$msgcount,$context,$pid) = 
 2180:                             split(/\:/,&Apache::lonnet::unescape($specialmsgid));
 2181:                 foreach my $recipient (sort(keys(%toaddr))) {
 2182:                     if ($specialmsg_status{$recipient} eq 'ok') {
 2183:                         my $usersubj = $subj_prefix.'['.$recipient.']';
 2184:                         my $usermsgid = &buildmsgid($stamp,$usersubj,$msgname,
 2185:                                               $msgdom,$msgcount,$context,$pid);
 2186:                         &user_normal_msg_raw($cnum,$cdom,$subj_prefix.
 2187:                         ' ['.$recipient.']',$sentmessage{$recipient},
 2188:                         undef,undef,undef,undef,$usermsgid);
 2189:                         my ($uname,$udom) = split/:/,$recipient;
 2190:                         push(@recusers,$uname);
 2191:                         push(@recudoms,$udom);
 2192:                     }
 2193:                 }
 2194:                 if (@recusers) {
 2195:                     my $specialmessage;
 2196:                     my $sentsubj = $subj_prefix.' ('.$numspecial.' sent) '.
 2197:                     &Apache::lonfeedback::clear_out_html($env{'form.subject'});
 2198:                     $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
 2199:                     my $sentmsgid = &buildmsgid($stamp,$sentsubj,$msgname,
 2200:                                               $msgdom,$msgcount,$context,$pid);
 2201:                     ($specialmsgid,$specialmessage) =
 2202:                          &packagemsg(&Apache::lonfeedback::clear_out_html(
 2203:                              $env{'form.subject'}),$savemsg,undef,undef,undef,
 2204:                                             \@recusers,\@recudoms,$sentmsgid);
 2205:                     $record_sent = &store_sent_mail($specialmsgid,$specialmessage);
 2206:                 }
 2207:             } else {
 2208:                 &Apache::lonnet::logthis('Failed to create record of critical message or broadcast in '.$env{'course.'.$env{'request.course.id'}.'.num'}.' at '.$env{'course.'.$env{'request.course.id'}.'.domain'}.' - no msgid generated');
 2209:             }
 2210:         }
 2211:     } else {
 2212: 	&printheader($r,'','No messages sent.'); 
 2213:     }
 2214:     if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
 2215: 	$r->print('<br /><font color="green">'.&mt('Completed.').'</font>');
 2216: 	if ($env{'form.displayedcrit'}) {
 2217: 	    &discrit($r);
 2218: 	} else {
 2219: 	    &Apache::loncommunicate::menu($r);
 2220: 	}
 2221:     } else {
 2222: 	$r->print(
 2223: 		  '<h2><font color="red">'.&mt('Could not deliver message').'</font></h2>'.
 2224: 		  &mt('Please use the browser "Back" button and correct the recipient addresses')
 2225: 		  );
 2226:     }
 2227: }
 2228: 
 2229: # ===================================================================== Handler
 2230: 
 2231: sub handler {
 2232:     my $r=shift;
 2233: 
 2234: # ----------------------------------------------------------- Set document type
 2235:     
 2236:     &Apache::loncommon::content_type($r,'text/html');
 2237:     $r->send_http_header;
 2238:     
 2239:     return OK if $r->header_only;
 2240:     
 2241: # --------------------------- Get query string for limited number of parameters
 2242:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 2243:         ['display','replyto','forward','markread','markdel','markunread',
 2244:          'sendreply','compose','sendmail','critical','recname','recdom',
 2245:          'recordftf','sortedby','block','folder','startdis','interdis',
 2246: 	 'showcommentbaseurl','dismode']);
 2247:     $sqs='&sortedby='.$env{'form.sortedby'};
 2248: 
 2249: # ------------------------------------------------------ They checked for email
 2250:     unless ($env{'form.block'}) {
 2251:         &Apache::lonnet::put('email_status',{'recnewemail'=>0});
 2252:     }
 2253: 
 2254: # ----------------------------------------------------------------- Breadcrumbs
 2255: 
 2256:     &Apache::lonhtmlcommon::clear_breadcrumbs();
 2257:     &Apache::lonhtmlcommon::add_breadcrumb
 2258:         ({href=>"/adm/communicate",
 2259:           text=>"Communication/Messages",
 2260:           faq=>12,bug=>'Communication Tools',});
 2261: 
 2262: # ------------------------------------------------------------------ Get Folder
 2263: 
 2264:     my $folder=$env{'form.folder'};
 2265:     unless ($folder) { 
 2266: 	$folder=''; 
 2267:     } else {
 2268: 	$sqs.='&folder='.&Apache::lonnet::escape($folder);
 2269:     }
 2270: # ------------------------------------------------------------ Get Display Mode
 2271: 
 2272:     my $dismode=$env{'form.dismode'};
 2273:     unless ($dismode) { 
 2274: 	$dismode=''; 
 2275:     } else {
 2276: 	$sqs.='&dismode='.&Apache::lonnet::escape($dismode);
 2277:     }
 2278: 
 2279: # --------------------------------------------------------------------- Display
 2280: 
 2281:     $startdis=$env{'form.startdis'};
 2282:     $startdis--;
 2283:     unless ($startdis) { $startdis=0; }
 2284: 
 2285:     $interdis=$env{'form.interdis'};
 2286:     unless ($interdis) { $interdis=20; }
 2287:     $sqs.='&interdis='.$interdis;
 2288: 
 2289:     if ($env{'form.firstview'}) {
 2290: 	$startdis=0;
 2291:     }
 2292:     if ($env{'form.lastview'}) {
 2293: 	$startdis=-1;
 2294:     }
 2295:     if ($env{'form.prevview'}) {
 2296: 	$startdis--;
 2297:     }
 2298:     if ($env{'form.nextview'}) {
 2299: 	$startdis++;
 2300:     }
 2301:     my $postedstartdis=$startdis+1;
 2302:     $sqs.='&startdis='.$postedstartdis;
 2303: 
 2304: # --------------------------------------------------------------- Render Output
 2305: 
 2306:     if ($env{'form.display'}) {
 2307: 	&displaymessage($r,$env{'form.display'},$folder);
 2308:     } elsif ($env{'form.replyto'}) {
 2309: 	&compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode);
 2310:     } elsif ($env{'form.confirm'}) {
 2311: 	&printheader($r,'','Confirmed Receipt');
 2312: 	foreach (keys %env) {
 2313: 	    if ($_=~/^form\.rec\_(.*)$/) {
 2314: 		$r->print('<b>'.&mt('Confirming Receipt').':</b> '.
 2315: 			  &user_crit_received($1).'<br>');
 2316: 	    }
 2317: 	    if ($_=~/^form\.reprec\_(.*)$/) {
 2318: 		my $msgid=$1;
 2319: 		$r->print('<b>'.&mt('Confirming Receipt').':</b> '.
 2320: 			  &user_crit_received($msgid).'<br>');
 2321: 		&compout($r,'','','',$msgid);
 2322: 	    }
 2323: 	}
 2324: 	&discrit($r);
 2325:     } elsif ($env{'form.critical'}) {
 2326: 	&printheader($r,'','Displaying Critical Messages');
 2327: 	&discrit($r);
 2328:     } elsif ($env{'form.forward'}) {
 2329: 	&compout($r,$env{'form.forward'},undef,undef,undef,$folder);
 2330:     } elsif ($env{'form.markdel'}) {
 2331: 	&printheader($r,'','Deleted Message');
 2332: 	&statuschange($env{'form.markdel'},'deleted',$folder);
 2333: 	&Apache::loncommunicate::menu($r);
 2334: 	&disall($r,($folder?$folder:$dismode));
 2335:     } elsif ($env{'form.markedmove'}) {
 2336: 	my $total=0;
 2337: 	foreach (keys %env) {
 2338: 	    if ($_=~/^form\.delmark_(.*)$/) {
 2339: 		&movemsg(&Apache::lonnet::unescape($1),$folder,
 2340: 			 $env{'form.movetofolder'});
 2341: 		$total++;
 2342: 	    }
 2343: 	}
 2344: 	&printheader($r,'','Moved Messages');
 2345: 	$r->print('Moved '.$total.' message(s)<p>');
 2346: 	&Apache::loncommunicate::menu($r);
 2347: 	&disall($r,($folder?$folder:$dismode));
 2348:     } elsif ($env{'form.markeddel'}) {
 2349: 	my $total=0;
 2350: 	foreach (keys %env) {
 2351: 	    if ($_=~/^form\.delmark_(.*)$/) {
 2352: 		&statuschange(&Apache::lonnet::unescape($1),'deleted',$folder);
 2353: 		$total++;
 2354: 	    }
 2355: 	}
 2356: 	&printheader($r,'','Deleted Messages');
 2357: 	$r->print('Deleted '.$total.' message(s)<p>');
 2358: 	&Apache::loncommunicate::menu($r);
 2359: 	&disall($r,($folder?$folder:$dismode));
 2360:     } elsif ($env{'form.markunread'}) {
 2361: 	&printheader($r,'','Marked Message as Unread');
 2362: 	&statuschange($env{'form.markunread'},'new');
 2363: 	&Apache::loncommunicate::menu($r);
 2364: 	&disall($r,($folder?$folder:$dismode));
 2365:     } elsif ($env{'form.compose'}) {
 2366: 	&compout($r,'','',$env{'form.compose'});
 2367:     } elsif ($env{'form.recordftf'}) {
 2368: 	&facetoface($r,$env{'form.recordftf'});
 2369:     } elsif ($env{'form.block'}) {
 2370:         &examblock($r,$env{'form.block'});
 2371:     } elsif ($env{'form.sendmail'}) {
 2372: 	&sendoffmail($r,$folder);
 2373: 	if ($env{'form.storebasecomment'}) {
 2374: 	    &storecomment($r);
 2375: 	}
 2376: 	if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
 2377: 	    &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
 2378: 				      $env{'course.'.$env{'request.course.id'}.'.domain'},
 2379: 				      'Course_Announcements',
 2380: 				      $env{'form.subject'},
 2381: 				      $env{'form.message'},'/adm/communicate','public');
 2382: 	}
 2383: 	&disall($r,($folder?$folder:$dismode));
 2384:     } elsif ($env{'form.newfolder'}) {
 2385: 	&printheader($r,'','New Folder');
 2386: 	&makefolder($env{'form.newfolder'});
 2387: 	&Apache::loncommunicate::menu($r);
 2388: 	&disall($r,$env{'form.newfolder'});
 2389:     } elsif ($env{'form.showcommentbaseurl'}) {
 2390: 	&storedcommentlisting($r);
 2391:     } else {
 2392: 	&printheader($r,'','Display All Messages');
 2393: 	&Apache::loncommunicate::menu($r); 
 2394: 	&disall($r,($folder?$folder:$dismode));
 2395:     }
 2396:     $r->print(&Apache::loncommon::endbodytag().'</html>');
 2397:     return OK;
 2398: }
 2399: # ================================================= Main program, reset counter
 2400: 
 2401: BEGIN {
 2402:     $msgcount=0;
 2403: }
 2404: 
 2405: =pod
 2406: 
 2407: =back
 2408: 
 2409: =cut
 2410: 
 2411: 1; 
 2412: 
 2413: __END__
 2414: 
 2415: 
 2416: 
 2417: 
 2418: 
 2419: 
 2420: 

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