Annotation of loncom/interface/lonmsgdisplay.pm, revision 1.4

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

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