Annotation of loncom/interface/lonmsg.pm, revision 1.173.2.2

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

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