File:  [LON-CAPA] / loncom / interface / lonmsg.pm
Revision 1.162: download - view: text, annotated - select for diffs
Fri Dec 9 20:54:26 2005 UTC (18 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Use packagemsg() and unpackagemsg() routines in lonmsg.pm to store and retrieve DC mail, and eliminate packagmail() and unpackagemail() routines  (no longer needed) from lonnotify.pm.

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

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