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

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # Routines for messaging display
                      3: #
1.62    ! raeburn     4: # $Id: lonmsgdisplay.pm,v 1.61 2007/01/04 02:02:36 raeburn 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: 
1.50      raeburn    77: =item * B<Blocking>: LON-CAPA can block selected communication 
                     78: features for students during an online exam. A course coordinator or
1.1       albertel   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();
1.27      albertel  128: use Apache::lonselstudent();
1.29      www       129: use lib '/home/httpd/lib/perl/';
                    130: use LONCAPA;
1.1       albertel  131: 
                    132: # Querystring component with sorting type
                    133: my $sqs;
                    134: my $startdis;
                    135: 
                    136: # ============================================================ List all folders
                    137: 
                    138: sub folderlist {
1.53      raeburn   139:     my ($folder,$msgstatus) = @_;
1.46      raeburn   140:     my %lt = &Apache::lonlocal::texthash(
                    141:                 actn => 'Action',
                    142:                 fold => 'Folder',
                    143:                 show => 'Show',
1.53      raeburn   144:                 status => 'Message Status',
1.46      raeburn   145:                 go   => 'Go',
1.50      raeburn   146:                 nnff => 'New Name for Folder',
                    147:                 newn => 'New Name',
                    148:                 thfm => 'The folder may not be renamed',
                    149:                 fmnb => 'folder may not be renamed as it is a folder provided by the system.',
                    150:                 asth => 'as this name is already in use for a system-provided or user-defined folder.',
                    151:                 the => 'The',
                    152:                 tnfm => 'The new folder may not be named',
                    153: 
1.46      raeburn   154:     );
                    155: 
                    156:     my %actions = &Apache::lonlocal::texthash(
                    157:                                 view => 'View Folder',
                    158:                                 rename => 'Rename Folder',
                    159:                                 delete => 'Delete Folder',
                    160:     );
                    161:     $actions{'select_form_order'} = ['view','rename','delete'];
                    162: 
1.53      raeburn   163:     my %statushash = &get_msgstatus_types();
                    164: 
                    165:     $statushash{'select_form_order'} = ['','new','read','replied','forwarded'];
                    166: 
1.46      raeburn   167:     my %permfolders = &get_permanent_folders();
                    168:     my $permlist = join("','",sort(keys(%permfolders)));
                    169:     my ($permlistkeys,$permlistvals);
                    170:     foreach my $key (sort(keys(%permfolders))) {
                    171:         $permlistvals .= $permfolders{$key}."','";
                    172:         $permlistkeys .= $key."','";
                    173:     }
                    174:     $permlistvals =~ s/','$//;
                    175:     $permlistkeys =~ s/','$//;
                    176:     my %gotfolders = &Apache::lonmsg::get_user_folders();
                    177:     my %userfolders;
                    178: 
                    179:     foreach my $key (keys(%gotfolders)) {
1.54      albertel  180:         $key =~ s/(['"])/\$1/g; #' stupid emacs
1.46      raeburn   181:         $userfolders{$key} = $key;
                    182:     }
                    183:     my @userorder = sort(keys(%userfolders));
                    184:     my %formhash = (%permfolders,%userfolders);
                    185:     my $folderlist = join("','",@userorder);
                    186:     $folderlist .= "','".$permlistvals;
                    187: 
1.53      raeburn   188:     $formhash{'select_form_order'} = ['','critical',@userorder,'sent','trash'];
1.46      raeburn   189:     my $output = qq|<script type="text/javascript">
                    190: function folder_choice(targetform,caller) {
                    191:     var permfolders_keys = new Array('$permlistkeys');
                    192:     var permfolders_vals = new Array('$permlistvals');
                    193:     var allfolders = new Array('$folderlist');
                    194:     if (caller == 'change') {
                    195:         if (targetform.folderaction.options[targetform.folderaction.selectedIndex].value == 'rename') {
                    196:             for (var i=0; i<permfolders_keys.length; i++) {
                    197:                 if (permfolders_keys[i] == targetform.folder.value) {
1.50      raeburn   198:                     alert("$lt{'the'} '"+permfolders_vals[i]+"' $lt{'fmnb'}");
1.46      raeburn   199:                     return;
                    200:                 }
                    201:             }
1.50      raeburn   202:             var foldername=prompt('$lt{'nnff'}','$lt{'newn'}');
1.46      raeburn   203:             if (foldername) {
                    204:                 targetform.renamed.value=foldername;
                    205:                 for (var i=0; i<allfolders.length; i++) {
                    206:                     if (allfolders[i] == foldername) {
1.50      raeburn   207:                         alert("$lt{'thfm'} '"+foldername+"' $lt{'asth'}");
1.46      raeburn   208:                         return;
                    209:                     }
                    210:                 }
                    211:                 targetform.submit();
                    212:             }
                    213:         }
                    214:         else {
                    215:             targetform.submit();
                    216:         }
                    217:     }
                    218:     if (caller == 'new') {
                    219:         var newname=targetform.newfolder.value;
                    220:         if (newname) {
                    221:             for (var i=0; i<allfolders.length; i++) {
                    222:                 if (allfolders[i] == newname) {
1.50      raeburn   223:                     alert("$lt{'tnfm'} '"+newname+"' $lt{'asth'}");
1.46      raeburn   224:                     return;
                    225:                 }
                    226:             }
                    227:             targetform.submit();
                    228:         }
                    229:     }
                    230: }
                    231: </script>|;
1.57      albertel  232:     my %show = ('select_form_order' => [10,20,50,100,200],
                    233: 		map {$_=>$_} (10,20,50,100,200));
                    234: 		
                    235: 		   
1.46      raeburn   236:     $output .= '
                    237: <form method="post" action="/adm/email" name="folderlist">
                    238: <table border="0" cellspacing="2" cellpadding="2">
                    239:  <tr>
                    240:   <td align="left">
                    241:    <table border="0" cellspacing="2" cellpadding="2">
                    242:     <tr>
                    243:      <td align="center"><b>'.$lt{'fold'}.'</b><br />'."\n".
1.47      albertel  244:          &Apache::loncommon::select_form($folder,'folder',%formhash).'
1.46      raeburn   245:      </td>
1.57      albertel  246:      <td align="center"><b>'.$lt{'show'}.'</b><br />'."\n".
                    247:          &Apache::loncommon::select_form($env{'form.interdis'},'interdis',
                    248: 					 %show).'
1.46      raeburn   249:      </td>
1.53      raeburn   250:      <td align="center"><b>'.$lt{'status'}.'</b><br />'."\n".
                    251:        &Apache::loncommon::select_form($msgstatus,'msgstatus',%statushash).'
                    252:      </td>
1.46      raeburn   253:      <td align="center"><b>'.$lt{'actn'}.'</b><br />'.
1.47      albertel  254:          &Apache::loncommon::select_form('view','folderaction',%actions).'
1.46      raeburn   255:      </td><td><br />'.
                    256:     '<input type="button" value="'.$lt{'go'}.'" onClick="javascript:folder_choice(this.form,'."'change'".');" />
                    257:      </td>
                    258:     </tr>
                    259:    </table>
                    260:   </td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
                    261:   <td align="right">
                    262:    <table><tr><td><br />
                    263:     <input type="button" value="'.&mt('Make New Folder').
                    264:     '" onClick="javascript:folder_choice(this.form,'."'new'".');" /></td>'.
1.48      albertel  265:     '<td align="center"><b>'.&mt('New Folder').'</b><br />'.
1.46      raeburn   266:     '<input type="text" size="15" name="newfolder" value="" />
                    267:     </td></tr></table>
                    268:   </td>
                    269:  </tr>
                    270: </table>'."\n".
1.1       albertel  271:     '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" />'.
1.46      raeburn   272:     '<input type="hidden" name="renamed" value="" />'.
1.53      raeburn   273:         ($folder=~/^critical/?'</form>':'');
1.46      raeburn   274:     return $output;
                    275: }
                    276: 
                    277: sub get_permanent_folders {
1.47      albertel  278:     my %permfolders = 
                    279: 	&Apache::lonlocal::texthash(''         => 'INBOX',
                    280: 				    'trash'    => 'TRASH',
                    281: 				    'critical' => 'Critical',
                    282: 				    'sent'     => 'Sent Messages',
                    283: 				    );
1.46      raeburn   284:     return %permfolders;
1.1       albertel  285: }
                    286: 
1.53      raeburn   287: sub get_msgstatus_types {
                    288:     my %statushash = &Apache::lonlocal::texthash(
                    289:                                 '' => 'Any',
                    290:                                 new => 'Unread',
                    291:                                 read => 'Read',
                    292:                                 replied => 'Replied to',
                    293:                                 forwarded => 'Forwarded',
                    294:     );
                    295:     return %statushash;
                    296: }
                    297: 
1.1       albertel  298: sub scrollbuttons {
1.53      raeburn   299:     my ($start,$maxdis,$first,$finish,$total,$msgstatus)=@_;
1.1       albertel  300:     unless ($total>0) { return ''; }
                    301:     $start++; $maxdis++;$first++;$finish++;
1.53      raeburn   302: 
                    303:     my %statushash = &get_msgstatus_types();
                    304:     my $status;
                    305:     if ($msgstatus eq '') {
                    306:         $status = &mt('All');
                    307:     } else {
                    308:         $status = $statushash{$msgstatus};
                    309:     }
1.1       albertel  310:     return
1.53      raeburn   311:    '<b>'.&mt('Page').'</b>: '. 
1.1       albertel  312:    '<input type="submit" name="firstview" value="'.&mt('First').'" />'.
                    313:    '<input type="submit" name="prevview" value="'.&mt('Previous').'" />'.
                    314:    '<input type="text" size="5" name="startdis" value="'.$start.'" onChange="this.form.submit()" /> of '.$maxdis.
                    315:    '<input type="submit" name="nextview" value="'.&mt('Next').'" />'.
                    316:    '<input type="submit" name="lastview" value="'.&mt('Last').'" /><br />'.
1.53      raeburn   317:    &mt('<b>[_1] messages</b>: showing messages [_2] through [_3] of [_4].',$status,$first,$finish,$total).'</form>';
1.1       albertel  318: }
                    319: # =============================================================== Status Change
                    320: 
                    321: sub statuschange {
                    322:     my ($msgid,$newstatus,$folder)=@_;
1.3       albertel  323:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
1.1       albertel  324:     my %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
                    325:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
                    326:     unless ($status{$msgid}) { $status{$msgid}='new'; }
                    327:     unless (($status{$msgid} eq 'replied') || 
                    328:             ($status{$msgid} eq 'forwarded')) {
                    329: 	&Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
                    330:     }
                    331:     if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
                    332: 	&Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
                    333:     }
                    334:     if ($newstatus eq 'deleted') {
1.9       albertel  335: 	return &movemsg($msgid,$folder,'trash');
                    336:     }
                    337:     return ;
1.1       albertel  338: }
                    339: 
                    340: # ============================================================= Make new folder
                    341: 
                    342: sub makefolder {
1.46      raeburn   343:     my ($newfolder) = @_;
                    344:     my %permfolders = &get_permanent_folders();
                    345:     my %userfolders = &Apache::lonmsg::get_user_folders();
                    346:     my ($outcome,$warning);
                    347:     if (defined($userfolders{$newfolder})) {
                    348:         return &mt('The folder name: "[_1]" is already in use for an existing folder.',$newfolder);
                    349:     }
                    350:     foreach my $perm (keys(%permfolders)) {
                    351:         if ($permfolders{$perm} eq $newfolder) {
                    352:             return &mt('The folder name: "[_1]" is already used for one of the folders automatically generated by the system.',$newfolder);
                    353:         }
                    354:     } 
                    355:     if (&get_msgfolder_lock() eq 'ok') {
                    356:         my %counter_hash = &Apache::lonnet::get('email_folders',["\0".'idcount']);
                    357:         my $lastcount = $counter_hash{"\0".'idcount'};
                    358:         my $folder_id = $lastcount + 1;
                    359:         while (defined($userfolders{$folder_id})) {
                    360:             $folder_id ++;
                    361:         }
1.47      albertel  362:         my %folderinfo = ( id      => $folder_id,
                    363:                            created => time, );
1.46      raeburn   364:         $outcome =  
1.47      albertel  365: 	    &Apache::lonnet::put('email_folders',{$newfolder => \%folderinfo,
                    366: 						  "\0".'idcount' => $folder_id});
1.46      raeburn   367:         my $releaseresult = &release_msgfolder_lock();
                    368:         if ($releaseresult ne 'ok') {
                    369:             $warning = $releaseresult;
                    370:         }
                    371:     } else {
1.47      albertel  372:         $outcome = 
                    373: 	    &mt('Error - could not obtain lock on email folders record.');
1.46      raeburn   374:     }
                    375:     return ($outcome,$warning);
1.1       albertel  376: }
                    377: 
1.46      raeburn   378: # ============================================================= Delete folder
                    379: 
                    380: sub deletefolder {
                    381:     my ($folder)=@_;
                    382:     my %permfolders = &get_permanent_folders();
                    383:     if (defined($permfolders{$folder})) {
1.56      albertel  384:         return &mt('The folder "[_1]" may not be deleted',$folder); 
1.46      raeburn   385:     }
                    386:     my %userfolders = &Apache::lonmsg::get_user_folders();
                    387:     if (!defined($userfolders{$folder})) {
1.56      albertel  388:         return &mt('The folder "[_1]" does not exist so deletion is not required.',
1.46      raeburn   389:                    $folder);
                    390:     }
                    391:     # check folder is empty;
                    392:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
                    393:     my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
                    394:     if (@messages > 0) {
1.56      albertel  395:         return &mt('The folder "[_1]" contains messages so it may not be deleted.',$folder).
1.46      raeburn   396:                '<br />'.
                    397:                &mt('Delete or move the messages to a different folder first.');
                    398:     }
                    399:     my $delresult = &Apache::lonnet::del('email_folders',[$folder]);
                    400:     return $delresult;
                    401: }
                    402: 
                    403: sub renamefolder {
                    404:     my ($folder) = @_;
                    405:     my $newname = $env{'form.renamed'};
                    406:     my %permfolders = &get_permanent_folders();
                    407:     if ($env{'form.renamed'} eq '') {
                    408:         return &mt('The folder "[_1]" may not be renamed to "[_2]" as the new name you requested is an invalid name.',$folder,$newname);
                    409:     }
                    410:     if (defined($permfolders{$newname})) {
                    411:         return &mt('The folder "[_1]" may not be renamed to "[_2]" as the new name you requested is reserved for folders provided automatically by the system.',$folder,$newname);
                    412:     }
                    413:     my %userfolders = &Apache::lonmsg::get_user_folders();
                    414:     if (defined($userfolders{$newname})) {
                    415:         return &mt('The folder "[_1]" may not be renamed to "[_2]" because the new name you requested is already being used for an existing folder.',$folder,$newname);
                    416:     }
                    417:     if (!defined($userfolders{$folder})) {
                    418:         return &mt('The folder "[_1]" could not be renamed to "[_2]" because the folder does not exist.',$folder,$newname);
                    419:     }
                    420:     my %folderinfo;
                    421:     if (ref($userfolders{$folder}) eq 'HASH') {
                    422:         %folderinfo = %{$userfolders{$folder}};
                    423:     } else {
1.47      albertel  424:         %folderinfo = ( id      => $folder,
                    425:                         created => $userfolders{$folder},);
1.46      raeburn   426:     }
                    427:     my $outcome =
                    428:      &Apache::lonnet::put('email_folders',{$newname => \%folderinfo});
                    429:     if ($outcome eq 'ok') {
                    430:         $outcome = &Apache::lonnet::del('email_folders',[$folder]);
                    431:     }
                    432:     return $outcome;
                    433: }
                    434: 
                    435: sub get_msgfolder_lock {
                    436:     # get lock for mail folder counter.
1.47      albertel  437:     my $lockhash = { "\0".'lock_counter' => time, };
1.46      raeburn   438:     my $tries = 0;
                    439:     my $gotlock = &Apache::lonnet::newput('email_folders',$lockhash);
                    440:     while (($gotlock ne 'ok') && $tries <3) {
                    441:         $tries ++;
1.47      albertel  442:         sleep(1);
1.46      raeburn   443:         $gotlock = &Apache::lonnet::newput('email_folders',$lockhash);
                    444:     }
                    445:     return $gotlock;
                    446: }
                    447: 
                    448: sub release_msgfolder_lock {
                    449:     #  remove lock
                    450:     my @del_lock = ("\0".'lock_counter');
                    451:     my $dellockoutcome=&Apache::lonnet::del('email_folders',\@del_lock);
                    452:     if ($dellockoutcome ne 'ok') {
                    453:         return ('<br />'.&mt('Warning: failed to release lock for counter').'<br />');
                    454:     } else {
                    455:         return 'ok';
                    456:     }
                    457: }
                    458: 
                    459: 
1.1       albertel  460: # ======================================================== Move between folders
                    461: 
                    462: sub movemsg {
                    463:     my ($msgid,$srcfolder,$trgfolder)=@_;
                    464:     if ($srcfolder eq 'new') { $srcfolder=''; }
1.3       albertel  465:     my $srcsuffix=&Apache::lonmsg::foldersuffix($srcfolder);
                    466:     my $trgsuffix=&Apache::lonmsg::foldersuffix($trgfolder);
1.9       albertel  467:     if ($srcsuffix eq $trgsuffix) {
                    468: 	return (0,&mt('Message not moved, Attempted to move message to the same folder as it already is in.'));
                    469:     }
1.1       albertel  470: 
                    471: # Copy message
                    472:     my %message=&Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid]);
1.9       albertel  473:     if (!exists($message{$msgid}) || $message{$msgid} eq '') {
1.32      albertel  474: 	if (&Apache::lonnet::error(%message)) {
1.9       albertel  475: 	    return (0,&mt('Message not moved, A network error occurred.'));
                    476: 	} else {
                    477: 	    return (0,&mt('Message not moved as the message is no longer in the source folder.'));
                    478: 	}
                    479:     }
                    480: 
                    481:     my $result =&Apache::lonnet::put('nohist_email'.$trgsuffix,
                    482: 				     {$msgid => $message{$msgid}});
1.32      albertel  483:     if (&Apache::lonnet::error($result)) {
1.9       albertel  484: 	return (0,&mt('Message not moved, A network error occurred.'));
                    485:     }
1.1       albertel  486: 
                    487: # Copy status
                    488:     unless ($trgfolder eq 'trash') {
1.9       albertel  489:        	my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]);
                    490: 	# a non-existant status is the mark of an unread msg
1.32      albertel  491: 	if (&Apache::lonnet::error(%status)) {
1.9       albertel  492: 	    return (0,&mt('Message copied to new folder but status was not, A network error occurred.'));
                    493: 	}
                    494: 	my $result=&Apache::lonnet::put('email_status'.$trgsuffix,
                    495: 					{$msgid => $status{$msgid}});
1.32      albertel  496: 	if (&Apache::lonnet::error($result)) {
1.9       albertel  497: 	    return (0,&mt('Message copied to new folder but status was not, A network error occurred.'));
                    498: 	}
1.1       albertel  499:     }
1.9       albertel  500: 
1.1       albertel  501: # Delete orginals
1.9       albertel  502:     my $result_del_msg = 
                    503: 	&Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]);
                    504:     my $result_del_stat =
                    505: 	&Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]);
1.32      albertel  506:     if (&Apache::lonnet::error($result_del_msg)) {
1.9       albertel  507: 	return (0,&mt('Message copied, but unable to delete the original from the source folder.'));
                    508:     }
1.32      albertel  509:     if (&Apache::lonnet::error($result_del_stat)) {
1.9       albertel  510: 	return (0,&mt('Message copied, but unable to delete the original status from the source folder.'));
                    511:     }
                    512: 
                    513:     return (1);
1.1       albertel  514: }
                    515: 
                    516: # ======================================================= Display a course list
                    517: 
                    518: sub discourse {
1.25      foxr      519:     my $result;
                    520:     my ($course_personnel,
                    521: 	$current_members,
                    522: 	$expired_members,
1.28      foxr      523: 	$future_members) = 
                    524: 	    &Apache::lonselstudent::get_people_in_class($env{'request.course.sec'});
1.25      foxr      525:     unshift @$current_members, (@$course_personnel);
                    526:     my %defaultUsers;
1.40      albertel  527:     
                    528:     $result .= '<input type="hidden" name="sendmode" value="group" />'."\n";
1.25      foxr      529: 
1.40      albertel  530:     $result .= &Apache::lonselstudent::render_student_list($current_members,
                    531: 							   "compemail",
                    532: 							   "current",
                    533: 							   \%defaultUsers,
                    534: 							   1,"selectedusers",1);
1.25      foxr      535: 
1.28      foxr      536:     $result .= &Apache::lonselstudent::render_student_list($expired_members,
                    537: 							   "compemail",
                    538: 							   "expired",
                    539: 							   \%defaultUsers,
                    540: 							   1, "selectedusers",0);
                    541:     $result .= &Apache::lonselstudent::render_student_list($future_members,
                    542: 							   "compemail",
                    543: 							   "future",
                    544: 							   \%defaultUsers,
                    545: 							   1, "selectedusers", 0);
1.25      foxr      546:     return $result;
                    547: }
                    548: 
1.38      raeburn   549: sub disgroup {
                    550:     my ($cdom,$cnum,$group,$viewgrps,$editgrps) = @_;
                    551:     my $result;
                    552:     #  Needs to be in a course
                    553:     if (!($env{'request.course.fn'})) {
                    554:         $result = &mt('Error: you must have a course role selected to be able to send a broadcast message to a group in the course.');
                    555:         return $result;
                    556:     }
                    557:     if ($cdom eq '' || $cnum eq '') {
                    558:         $result = &mt('Error: could not determine domain or number of course');
                    559:         return $result;
                    560:     }
                    561:     my ($memberinfo,$numitems) =
                    562:                  &Apache::longroup::group_memberlist($cdom,$cnum,$group,{},[]);
                    563:     my @statustypes = ('active');
                    564:     if ($viewgrps || $editgrps) {
                    565:         push(@statustypes,('future','previous'));
                    566:     }
                    567:     if (keys(%{$memberinfo}) == 0) {
                    568:         $result = &mt('As this group has no members, there are no '.
                    569:                       'recipients to select.');
                    570:         return $result;
                    571:     } else {
                    572:         $result = &mt('Select message recipients from the group members listed below.<br />');  
                    573:         my %Sortby = (
                    574:                          active   => {},
                    575:                          previous => {},
                    576:                          future   => {},
                    577:                      );
                    578:         my %lt = &Apache::lonlocal::texthash(
                    579:                                      'name'     => 'Name',
                    580:                                      'usnm'     => 'Username',
                    581:                                      'doma'     => 'Domain',
                    582:                                      'active'   => 'Active Members',
                    583:                                      'previous' => 'Former Members',
                    584:                                      'future'   => 'Future Members',
                    585:                                     );
                    586:         foreach my $user (sort(keys(%{$memberinfo}))) {
                    587:             my $status = $$memberinfo{$user}{status};
                    588:             if ($env{'form.'.$status.'.sortby'} eq 'fullname') {
                    589:                 push(@{$Sortby{$status}{$$memberinfo{$user}{fullname}}},$user);
                    590:             } elsif ($env{'form.'.$status.'.sortby'} eq 'username') {
                    591:                 push(@{$Sortby{$status}{$$memberinfo{$user}{uname}}},$user);
                    592:             } elsif ($env{'form.'.$status.'.sortby'} eq 'domain') {
                    593:                 push(@{$Sortby{$status}{$$memberinfo{$user}{udom}}},$user);
                    594:             } else {
                    595:                 push(@{$Sortby{$status}{$$memberinfo{$user}{fullname}}},$user);
                    596:             }
                    597:         }
                    598:         $result .= &group_check_uncheck();
                    599:         $result .= '<table border="0" cellspacing="8" cellpadding="2">'.
                    600:                    '<tr>';
                    601:         foreach my $status (@statustypes)  {
                    602:             if (ref($numitems) eq 'HASH') {
                    603:                 if ((defined($$numitems{$status})) && ($$numitems{$status})) {
1.39      raeburn   604:                     $result.='<td valign="top">'.
1.38      raeburn   605:                              '<fieldset><legend><b>'.$lt{$status}.
                    606:                              '</b></legend><nobr>'.
1.50      raeburn   607:                              '<input type="button" value="'.&mt('Check All').'" '.
1.38      raeburn   608:                              'onclick="javascript:toggleAll('."'".$status."','check'".')" />'.
                    609:                              '&nbsp;&nbsp;'.
1.50      raeburn   610:                              '<input type="button" value="'.&mt('Uncheck All').'" '.
1.38      raeburn   611:                              'onclick="javascript:toggleAll('."'".$status."','uncheck'".')" />'.
                    612:                              '</nobr></fieldset><br />'.
                    613:                              &Apache::loncommon::start_data_table().
                    614:                              &Apache::loncommon::start_data_table_header_row();
1.39      raeburn   615:                     $result .= "<th>$lt{'name'}</a></th>".
                    616:                                "<th>$lt{'usnm'}</a></th>".
                    617:                                "<th>$lt{'doma'}</a></th>".
1.38      raeburn   618:                     &Apache::loncommon::end_data_table_header_row();
                    619:                     foreach my $key (sort(keys(%{$Sortby{$status}}))) {
                    620:                         foreach my $user (@{$Sortby{$status}{$key}}) {
                    621:                             $result .=
                    622:                                 &Apache::loncommon::start_data_table_row().
                    623:                                 '<td><input type="checkbox" '.
                    624:                                 'name="selectedusers_forminput" value="'.
                    625:                                 $user.':'.$status.'" />'.
                    626:                                 $$memberinfo{$user}{'fullname'}.'</td>'.
                    627:                                 '<td>'.$$memberinfo{$user}{'uname'}.'</td>'.
                    628:                                 '<td>'.$$memberinfo{$user}{'udom'}.'</td>'.
                    629:                                 &Apache::loncommon::end_data_table_row();
                    630:                         }
                    631:                     }
                    632:                     $result .= &Apache::loncommon::end_data_table();
                    633:                 }
                    634:             }
                    635:             $result .= '</td><td>&nbsp;&nbsp;</td>';
                    636:         }
                    637:         $result .= '</tr></table>';
                    638:     }
                    639:     return $result;
                    640: }
                    641: 
                    642: sub group_check_uncheck {
                    643:     my $output = qq|
                    644: <script type="text/javascript">
                    645: function toggleAll(caller,action) {
                    646:     var pattern = new RegExp(":"+caller+"\$");
                    647:     if (typeof(document.compemail.selectedusers_forminput.length)=="undefined") {
                    648:         if (document.compemail.selectedusers_forminput.value.match(pattern)) {
                    649:             if (action == 'check') {
                    650:                 document.groupmail.selectedusers_forminput.checked = true;
                    651:             } else {
                    652:                 document.groupmail.selectedusers_forminput.checked = false;
                    653:             }
                    654:         }
                    655:     } else {
                    656:         for (var i=0; i<document.compemail.selectedusers_forminput.length; i++) {
                    657:             if (document.compemail.selectedusers_forminput[i].value.match(pattern)) {
                    658:                 if (action == 'check') {
                    659:                     document.compemail.selectedusers_forminput[i].checked = true;
                    660:                 } else {
                    661:                     document.compemail.selectedusers_forminput[i].checked = false;
                    662:                 }
                    663:             }
                    664:         }
                    665:     }
                    666: }
                    667: </script>
                    668:     |;
                    669: }
                    670: 
                    671: sub groupmail_header {
                    672:     my ($action,$group,$cdom,$cnum) = @_;
                    673:     my ($description,$refarg);
                    674:     if (!$cdom || !$cnum) {
                    675:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    676:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    677:     }
                    678:     if (exists($env{'form.ref'})) {
                    679:         $refarg = 'ref='.$env{'form.ref'};
                    680:     }
                    681:     if (!$group) {
                    682:         $group = $env{'form.group'};
                    683:     }
                    684:     if ($group eq '') {
                    685:         return  '';
                    686:     } else {
                    687:         my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
                    688:         if (defined($curr_groups{$group})) {
                    689:             my %groupinfo =
                    690:                     &Apache::longroup::get_group_settings($curr_groups{$group});
                    691:             $description = &unescape($groupinfo{'description'});
                    692:         }
                    693:     }
                    694:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    695:     if ($refarg) {
                    696:         &Apache::lonhtmlcommon::add_breadcrumb
                    697:             ({href=>"/adm/coursegroups",
                    698:               text=>"Groups",
                    699:               title=>"View course groups"});
                    700:     }
                    701:     &Apache::lonhtmlcommon::add_breadcrumb
                    702:         ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
                    703:           text=>"Group: $description",
                    704:           title=>"Go to group's home page"},
                    705:          {href=>"/adm/email?compose=group&amp;group=".
                    706:                 "$env{'form.group'}&amp;$refarg",
                    707:           text=>"Send a Message in a Group",
                    708:           title=>"Compose Group Email Message"},);
                    709:     if ($action eq 'sending') {
                    710:             &Apache::lonhtmlcommon::add_breadcrumb
                    711:                          ({text=>"Messages being sent.",
                    712:                            title=>"Messages sent"},);
                    713:     }
                    714:     my $groupheader = &Apache::loncommon::start_page('Group Email');
                    715:     $groupheader .= &Apache::lonhtmlcommon::breadcrumbs
                    716:                 ('Group - '.$env{'form.group'}.' Email');
                    717:     return $groupheader;
                    718: }
                    719: 
                    720: sub groupmail_sent {
                    721:     my ($group,$cdom,$cnum) = @_;
                    722:     my $refarg;
                    723:     if (exists($env{'form.ref'})) {
                    724:         $refarg = 'ref='.$env{'form.ref'};
                    725:     }
                    726:     my $output .= '<br /><br /><a href="/adm/email?compose=group&amp;group='.
                    727:                   $group.'&amp;'.$refarg.'">'.
                    728:                   &mt('Send another group email').'</a>'.'&nbsp;&nbsp;&nbsp;'.
                    729:                   '<a href="/adm/'.$cdom.'/'.$cnum.'/'.$group.'/smppg?'.
                    730:                   $refarg.'">'. &mt('Return to group page').'</a>';
                    731:     return $output;
                    732: }
                    733: 
1.1       albertel  734: # ==================================================== Display Critical Message
                    735: 
                    736: sub discrit {
                    737:     my $r=shift;
1.5       albertel  738:     my $header = '<h1><font color="red">'.&mt('Critical Messages').'</font></h1>'.
1.1       albertel  739:         '<form action="/adm/email" method="POST">'.
                    740:         '<input type="hidden" name="confirm" value="true" />';
                    741:     my %what=&Apache::lonnet::dump('critical');
                    742:     my $result = '';
1.42      raeburn   743:     foreach my $key (sort(keys(%what))) {
                    744:         my %content=&Apache::lonmsg::unpackagemsg($what{$key});
1.1       albertel  745:         next if ($content{'senderdomain'} eq '');
                    746:         $result.='<hr />'.&mt('From').': <b>'.
                    747: &Apache::loncommon::aboutmewrapper(
                    748:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14      albertel  749: $content{'sendername'}.':'.
1.1       albertel  750:             $content{'senderdomain'}.') '.$content{'time'}.
                    751:             '<br />'.&mt('Subject').': '.$content{'subject'}.
                    752:             '<br /><pre>'.
                    753:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
                    754:             '</pre><small>'.
                    755: &mt('You have to confirm that you received this message. After confirmation, this message will be moved to your regular inbox').
                    756:             '</small><br />'.
1.42      raeburn   757:             '<input type="submit" name="rec_'.$key.'" value="'.&mt('Confirm Receipt').'" />'.
                    758:             '<input type="submit" name="reprec_'.$key.'" '.
1.1       albertel  759:                   'value="'.&mt('Confirm Receipt and Reply').'" />';
                    760:     }
                    761:     # Check to see if there were any messages.
                    762:     if ($result eq '') {
                    763:         $result = "<h2>".&mt('You have no critical messages.')."</h2>".
1.38      raeburn   764: 	    '<a href="/adm/roles">'.&mt('Select a course').'</a><br />'.
1.1       albertel  765:             '<a href="/adm/email">'.&mt('Communicate').'</a>';
                    766:     } else {
                    767:         $r->print($header);
                    768:     }
                    769:     $r->print($result);
                    770:     $r->print('<input type="hidden" name="displayedcrit" value="true" /></form>');
                    771: }
                    772: 
                    773: sub sortedmessages {
1.53      raeburn   774:     my ($blocked,$startblock,$endblock,$numblocked,$folder,$msgstatus) = @_;
1.1       albertel  775:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
                    776:     my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
                    777:     #unpack the varibles and repack into temp for sorting
                    778:     my @temp;
                    779:     my %descriptions;
                    780:     my %status_cache = 
                    781: 	&Apache::lonnet::get('email_status'.&Apache::lonmsg::foldersuffix($folder),\@messages);
1.11      albertel  782: 
                    783:     my $get_received;
                    784:     if ($folder eq 'sent' 
                    785: 	&& ($env{'form.sortedby'} =~ m/^(rev)?(user|domain)$/)) {
                    786: 	$get_received = 1;
                    787:     }
                    788: 
                    789:     foreach my $msgid (@messages) {
1.29      www       790: 	my $esc_msgid=&escape($msgid);
1.59      raeburn   791: 	my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,$processid,$symb,$error) =
1.11      albertel  792: 	    &Apache::lonmsg::unpackmsgid($esc_msgid,$folder,undef,
1.1       albertel  793: 					 \%status_cache);
1.53      raeburn   794:         next if ($msgstatus ne '' && $msgstatus ne $status);
1.1       albertel  795:         my $description = &get_course_desc($fromcid,\%descriptions);
                    796: 	my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
1.11      albertel  797: 		     $esc_msgid,$description);
                    798: 	if ($get_received) {
                    799: 	    my %message = &Apache::lonnet::get('nohist_email'.$suffix,
                    800: 					       [$msgid]);
                    801: 	    my %content = &Apache::lonmsg::unpackagemsg($message{$msgid});
                    802: 	    push(@temp1,$content{'recuser'},$content{'recdomain'});
                    803: 	}
1.1       albertel  804:         # Check whether message was sent during blocking period.
                    805:         if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
1.11      albertel  806:             $$blocked{$msgid} = 'ON';
1.1       albertel  807:             $$numblocked ++;
                    808:         } else { 
                    809:             push @temp ,\@temp1;
                    810:         }
                    811:     }
                    812:     #default sort
                    813:     @temp = sort  {$a->[0] <=> $b->[0]} @temp;    
                    814:     if ($env{'form.sortedby'} eq "date"){
                    815:         @temp = sort  {$a->[0] <=> $b->[0]} @temp;    
                    816:     }
                    817:     if ($env{'form.sortedby'} eq "revdate"){
                    818:     	@temp = sort  {$b->[0] <=> $a->[0]} @temp; 
                    819:     }
                    820:     if ($env{'form.sortedby'} eq "user"){
1.11      albertel  821: 	if ($get_received) {
                    822: 	    @temp = sort  {lc($a->[7][0]) cmp lc($b->[7][0])} @temp;
                    823: 	} else {
                    824: 	    @temp = sort  {lc($a->[2])    cmp lc($b->[2])}    @temp;
                    825: 	}
1.1       albertel  826:     }
                    827:     if ($env{'form.sortedby'} eq "revuser"){
1.11      albertel  828: 	if ($get_received) {
                    829: 	    @temp = sort  {lc($b->[7][0]) cmp lc($a->[7][0])} @temp;
                    830: 	} else {
                    831: 	    @temp = sort  {lc($b->[2])    cmp lc($a->[2])}    @temp;
                    832: 	}
1.1       albertel  833:     }
                    834:     if ($env{'form.sortedby'} eq "domain"){
1.11      albertel  835: 	if ($get_received) {
                    836: 	    @temp = sort  {$a->[8][0] cmp $b->[8][0]} @temp;
                    837: 	} else {
                    838: 	    @temp = sort  {$a->[3]    cmp $b->[3]}    @temp;
                    839: 	}
1.1       albertel  840:     }
                    841:     if ($env{'form.sortedby'} eq "revdomain"){
1.11      albertel  842: 	if ($get_received) {
                    843: 	    @temp = sort  {$b->[8][0] cmp $a->[8][0]} @temp;
                    844: 	} else {
                    845: 	    @temp = sort  {$b->[3]    cmp $a->[3]}    @temp;
                    846: 	}
1.1       albertel  847:     }
                    848:     if ($env{'form.sortedby'} eq "subject"){
                    849:         @temp = sort  {lc($a->[1]) cmp lc($b->[1])} @temp;
                    850:     }
                    851:     if ($env{'form.sortedby'} eq "revsubject"){
                    852:         @temp = sort  {lc($b->[1]) cmp lc($a->[1])} @temp;
                    853:     }
                    854:     if ($env{'form.sortedby'} eq "course"){
                    855:         @temp = sort  {lc($a->[6]) cmp lc($b->[6])} @temp;
                    856:     }
                    857:     if ($env{'form.sortedby'} eq "revcourse"){
                    858:         @temp = sort  {lc($b->[6]) cmp lc($a->[6])} @temp;
                    859:     }
                    860:     if ($env{'form.sortedby'} eq "status"){
                    861:         @temp = sort  {$a->[4] cmp $b->[4]} @temp;
                    862:     }
                    863:     if ($env{'form.sortedby'} eq "revstatus"){
                    864:         @temp = sort  {$b->[4] cmp $a->[4]} @temp;
                    865:     }
                    866:     return @temp;
                    867: }
                    868: 
                    869: sub get_course_desc {
                    870:     my ($fromcid,$descriptions) = @_;
                    871:     my $description;
                    872:     if (!$fromcid) {
                    873:         return $description;
                    874:     } else {
                    875:         if (defined($$descriptions{$fromcid})) {
                    876:             $description = $$descriptions{$fromcid};
                    877:         } else {
                    878:             if (defined($env{'course.'.$fromcid.'.description'})) {
                    879:                 $description = $env{'course.'.$fromcid.'.description'};
                    880:             } else {
1.48      albertel  881:                 my %courseinfo=&Apache::lonnet::coursedescription($fromcid);
1.1       albertel  882:                 $description = $courseinfo{'description'};
                    883:             }
                    884:             $$descriptions{$fromcid} = $description;
                    885:         }
                    886:         return $description;
                    887:     }
                    888: }
                    889: 
                    890: # ======================================================== Display all messages
                    891: 
                    892: sub disall {
1.53      raeburn   893:     my ($r,$folder,$msgstatus)=@_;
1.57      albertel  894:     my %saveable = ('folder'    => 'scalar',
                    895: 		    'msgstatus' => 'scalar',
                    896: 		    'sortedby'  => 'scalar',
                    897: 		    'interdis'  => 'scalar',
                    898: 		    );
                    899:     &Apache::loncommon::store_settings('user','mail',\%saveable);
                    900:     &Apache::loncommon::restore_settings('user','mail',\%saveable);
                    901:     $folder    ||= $env{'form.folder'};
                    902:     $msgstatus ||= $env{'form.msgstatus'};
                    903:     $env{'form.interdis'} ||= 20;
                    904: 
1.53      raeburn   905:     $r->print(&folderlist($folder,$msgstatus));
                    906:     if ($folder eq 'critical') {
1.1       albertel  907: 	&discrit($r);
                    908:     } else {
1.53      raeburn   909: 	&disfolder($r,$folder,$msgstatus);
1.1       albertel  910:     }
                    911: }
                    912: 
                    913: # ============================================================ Display a folder
                    914: 
                    915: sub disfolder {
1.53      raeburn   916:     my ($r,$folder,$msgstatus)=@_;
                    917:     my %statushash = &get_msgstatus_types();
1.1       albertel  918:     my %blocked = ();
                    919:     my %setters = ();
                    920:     my $numblocked = 0;
1.44      raeburn   921:     my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53      raeburn   922:     my %lt = &Apache::lonlocal::texthash(
                    923:                       sede => 'Select a destination folder to which the messages will be moved.',
                    924:                       nome => 'No messages have been selected to apply ths action to.',
                    925:                       chec => 'Check the checkbox for at least one message.',  
                    926:     );
1.1       albertel  927:     $r->print(<<ENDDISHEADER);
1.16      albertel  928: <script type="text/javascript">
1.1       albertel  929:     function checkall() {
1.53      raeburn   930: 	for (i=0; i<document.forms.disall.delmark.length; i++) {
                    931: 	    document.forms.disall.delmark[i].checked=true;
1.1       albertel  932:         }
                    933:     }
                    934: 
                    935:     function uncheckall() {
1.53      raeburn   936: 	for (i=0; i<document.forms.disall.delmark.length; i++) {
                    937: 	    document.forms.disall.delmark[i].checked=false;
                    938:         }
                    939:     }
                    940:     function checkfoldermove() {
                    941:         if (document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value == 'markedmove') {
                    942:             if (document.disall.movetofolder.options[document.disall.movetofolder.selectedIndex].value == "") {
                    943:                 alert("$lt{'sede'}");
                    944:                 return;
1.1       albertel  945:             }
                    946:         }
1.53      raeburn   947:         return; 
1.1       albertel  948:     }
1.53      raeburn   949: 
                    950:     function validate_checkedaction() {
                    951:         document.disall.markedaction.value = document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value;
                    952:         if (document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value == 'markedmove') {
                    953:             if (document.disall.movetofolder.options[document.disall.movetofolder.selectedIndex].value == "") {
                    954:                 alert("$lt{'sede'}");
                    955:                 return;
                    956:             } 
                    957:         }
                    958:         var checktotal = 0;
                    959:         for (var i=0; i<document.forms.disall.delmark.length; i++) {
                    960:             if (document.forms.disall.delmark[i].checked) {
                    961:                 checktotal ++;
                    962:             }
                    963:         }
                    964:         if (checktotal == 0) {
                    965:             alert("$lt{'nome'}\\n$lt{'chec'}");
                    966:             return;
                    967:         }
                    968:         document.disall.submit();
                    969:     }
                    970: 
1.1       albertel  971: </script>
                    972: ENDDISHEADER
1.54      albertel  973: 
1.1       albertel  974:     my $fsqs='&folder='.$folder;
1.53      raeburn   975:     my @temp=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1       albertel  976:     my $totalnumber=$#temp+1;
1.53      raeburn   977:     if ($totalnumber < 1) {
                    978:         if ($msgstatus eq '') {
                    979: 	    $r->print('<h2>'.&mt('Empty Folder').'</h2>');
                    980:         } elsif ($msgstatus eq 'replied') {
                    981:             $r->print('<h2>'.&mt('You have not replied to any messages in this folder.').'</h2>');
                    982:         } else { 
1.55      albertel  983:             $r->print('<h2>'.&mt('There are no '.lc($statushash{$msgstatus}).' messages in this folder.').'</h2>');
1.53      raeburn   984:         }
1.1       albertel  985: 	return;
                    986:     }
1.57      albertel  987:     my $interdis = $env{'form.interdis'};
1.1       albertel  988:     my $number=int($totalnumber/$interdis);
1.57      albertel  989:     if ($totalnumber%$interdis == 0) {
                    990: 	$number--; 
1.53      raeburn   991:     }
                    992: 
1.1       albertel  993:     if (($startdis<0) || ($startdis>$number)) { $startdis=$number; }
                    994:     my $firstdis=$interdis*$startdis;
                    995:     if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; }
                    996:     my $lastdis=$firstdis+$interdis-1;
                    997:     if ($lastdis>$#temp) { $lastdis=$#temp; }
1.53      raeburn   998:     $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber,$msgstatus));
1.1       albertel  999:     $r->print('<form method="post" name="disall" action="/adm/email">'.
1.53      raeburn  1000: 	      '<table class="LC_mail_list"><tr><th colspan="1">&nbsp;</th><th>');
1.1       albertel 1001:     if ($env{'form.sortedby'} eq "revdate") {
                   1002: 	$r->print('<a href = "?sortedby=date'.$fsqs.'">'.&mt('Date').'</a></th>');
                   1003:     } else {
                   1004: 	$r->print('<a href = "?sortedby=revdate'.$fsqs.'">'.&mt('Date').'</a></th>');
                   1005:     }
                   1006:     $r->print('<th>');
                   1007:     if ($env{'form.sortedby'} eq "revuser") {
                   1008: 	$r->print('<a href = "?sortedby=user'.$fsqs.'">'.&mt('Username').'</a>');
                   1009:     } else {
                   1010: 	$r->print('<a href = "?sortedby=revuser'.$fsqs.'">'.&mt('Username').'</a>');
                   1011:     }
                   1012:     $r->print('</th><th>');
                   1013:     if ($env{'form.sortedby'} eq "revdomain") {
                   1014: 	$r->print('<a href = "?sortedby=domain'.$fsqs.'">'.&mt('Domain').'</a>');
                   1015:     } else {
                   1016: 	$r->print('<a href = "?sortedby=revdomain'.$fsqs.'">'.&mt('Domain').'</a>');
                   1017:     }
                   1018:     $r->print('</th><th>');
                   1019:     if ($env{'form.sortedby'} eq "revsubject") {
                   1020: 	$r->print('<a href = "?sortedby=subject'.$fsqs.'">'.&mt('Subject').'</a>');
                   1021:     } else {
                   1022:     	$r->print('<a href = "?sortedby=revsubject'.$fsqs.'">'.&mt('Subject').'</a>');
                   1023:     }
                   1024:     $r->print('</th><th>');
                   1025:     if ($env{'form.sortedby'} eq "revcourse") {
1.46      raeburn  1026:         $r->print('<a href = "?sortedby=course'.$fsqs.'">'.&mt('Course').'</a>');
1.1       albertel 1027:     } else {
1.46      raeburn  1028:         $r->print('<a href = "?sortedby=revcourse'.$fsqs.'">'.&mt('Course').'</a>');
1.1       albertel 1029:     }
                   1030:     $r->print('</th><th>');
                   1031:     if ($env{'form.sortedby'} eq "revstatus") {
                   1032: 	$r->print('<a href = "?sortedby=status'.$fsqs.'">'.&mt('Status').'</a></th>');
                   1033:     } else {
                   1034:      	$r->print('<a href = "?sortedby=revstatus'.$fsqs.'">'.&mt('Status').'</a></th>');
                   1035:     }
                   1036:     $r->print("</tr>\n");
1.6       albertel 1037: 
                   1038:     my $suffix = &Apache::lonmsg::foldersuffix($folder);
1.1       albertel 1039:     for (my $n=$firstdis;$n<=$lastdis;$n++) {
1.11      albertel 1040: 	my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,
                   1041: 	    $description,$recv_name,$recv_domain)= 
                   1042: 		@{$temp[$n]};
1.1       albertel 1043: 	if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
                   1044: 	    if ($status eq 'new') {
1.4       albertel 1045: 		$r->print('<tr class="LC_mail_new">');
1.1       albertel 1046: 	    } elsif ($status eq 'read') {
1.4       albertel 1047: 		$r->print('<tr class="LC_mail_read">');
1.1       albertel 1048: 	    } elsif ($status eq 'replied') {
1.4       albertel 1049: 		$r->print('<tr class="LC_mail_replied">'); 
1.1       albertel 1050: 	    } else {
1.4       albertel 1051: 		$r->print('<tr class="LC_mail_other">');
1.1       albertel 1052: 	    }
1.6       albertel 1053: 	    my ($dis_name,$dis_domain) = ($fromname,$fromdomain);
                   1054: 	    if ($folder eq 'sent') {
1.11      albertel 1055: 		if (defined($recv_name) && !defined($recv_domain)) {
                   1056: 		    $dis_name   = join('<br />',@{$recv_name});
                   1057: 		    $dis_domain = join('<br />',@{$recv_domain});
                   1058: 		} else {
1.29      www      1059: 		    my $msg_id  = &unescape($origID);
1.11      albertel 1060: 		    my %message = &Apache::lonnet::get('nohist_email'.$suffix,
                   1061: 						       [$msg_id]);
                   1062: 		    my %content = &Apache::lonmsg::unpackagemsg($message{$msg_id});
                   1063: 		    $dis_name   = join('<br />',@{$content{'recuser'}});
                   1064: 		    $dis_domain = join('<br />',@{$content{'recdomain'}});
                   1065: 		}
1.6       albertel 1066: 	    }
1.53      raeburn  1067:             my $localsenttime = &Apache::lonlocal::locallocaltime($sendtime);
                   1068:             my $count = $n +1;
                   1069: 	    $r->print('<td align="right"><nobr>'.(($status eq 'new')?'<b>':'').
                   1070:                       $count.'.'.(($status eq 'new')?'</b>':'').'&nbsp;'.
                   1071:                       '<input type="checkbox" name="delmark"'. 
                   1072:                       ' value="'.$origID.'" /></nobr></td>');
                   1073:             foreach my $item ($localsenttime,$dis_name,$dis_domain,$shortsubj) {
                   1074:                 $r->print('<td>'.(($status eq 'new')?'<b>':'').
1.61      raeburn  1075:                           '<a href="/adm/email?display='.$origID.$sqs.'">'.
1.53      raeburn  1076:                           $item.(($status eq 'new')?'</b>':'').'</td>');
                   1077:             }
                   1078:             my $showstatus;
                   1079:             my %statushash = &get_msgstatus_types();
                   1080:             if ($status eq '') {
                   1081:                 $showstatus = '';
                   1082:             } else {
                   1083:                 $showstatus = $statushash{$status};
                   1084:             }
                   1085: 	    $r->print('<td>'.(($status eq 'new')?'<b>':'').$description.
                   1086:                       (($status eq 'new')?'</b>':'').'</td><td>'.
                   1087:                       (($status eq 'new')?'<b>':'').$showstatus.
                   1088:                       (($status eq 'new')?'</b>':'').'</td></tr>'."\n");
1.1       albertel 1089: 	} elsif ($status eq 'deleted') {
                   1090: # purge
1.9       albertel 1091: 	    my ($result,$msg) = 
1.29      www      1092: 		&movemsg(&unescape($origID),$folder,'trash');
1.9       albertel 1093: 	    
1.1       albertel 1094: 	}
                   1095:     }   
1.53      raeburn  1096:     $r->print("</table>\n");
                   1097:     $r->print('<table border="0" cellspacing="2" cellpadding="2">
                   1098:  <tr>
                   1099:   <td>'.
                   1100:   '<input type="button" onclick="javascript:checkall()" value="'.&mt('Check All').'" /><br />'."\n".
                   1101:   '<input type="button" onclick="javascript:uncheckall()" value="'.&mt('Uncheck All').'" />'."\n".
                   1102:   '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" /></td><td>&nbsp;</td>'."\n".
                   1103:   '<td align="center"><b>'.&mt('Action').'</b><br />'."\n".
                   1104:   '  <select name="checkedaction" onchange="javascript:checkfoldermove()">'."\n");
                   1105: 
1.1       albertel 1106:     if ($folder ne 'trash') {
1.53      raeburn  1107:         $r->print('    <option value="markeddel">'.&mt('Delete').'</option>'."\n");
                   1108:     }
                   1109:     if ($msgstatus ne 'read') {
                   1110:         $r->print('    <option value="markedread">'.&mt('Mark Read').'</option>."\n"');
                   1111:     }
                   1112:     if ($msgstatus ne 'unread') {
                   1113:         $r->print('    <option value="markedunread">'.&mt('Mark Unread').'</option>'."\n");
1.1       albertel 1114:     }
1.53      raeburn  1115:     $r->print('   <option value="markedforward">'.&mt('Forward').'</option>'."\n");
1.54      albertel 1116: 
                   1117:     my %gotfolders = &Apache::lonmsg::get_user_folders();
1.53      raeburn  1118:     if (keys(%gotfolders) > 0) {
                   1119:         $r->print('   <option value="markedmove">'.&mt('Move to Folder ->').
                   1120:                   '</option>');
                   1121:     }
                   1122:     $r->print("\n".'</select></td>'."\n");
1.54      albertel 1123: 
1.53      raeburn  1124:     if (keys(%gotfolders) > 0) {
                   1125:         $r->print('<td align="center"><b>'.&mt('Destination folder').'<b><br />');
1.54      albertel 1126: 	my %userfolders;
1.53      raeburn  1127:         foreach my $key (keys(%gotfolders)) {
                   1128:             $userfolders{$key} = $key;
                   1129:         }
                   1130:         $userfolders{''} = "";
                   1131:         $r->print(&Apache::loncommon::select_form('','movetofolder',%userfolders).
                   1132:                   '</td>');
                   1133:     }
                   1134:     $r->print('<td>&nbsp;</td><td>&nbsp;&nbsp;'.
                   1135:               '<input type="button" name="go" value="'.&mt('Go').
                   1136:               '" onclick="javascript:validate_checkedaction()"/></td>'."\n".
                   1137:               '</tr></table>');
1.1       albertel 1138:     my $postedstartdis=$startdis+1;
1.53      raeburn  1139:     $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'}.'" /><input type="hidden" name="msgstatus" value="'.$msgstatus.'" ><input type="hidden" name="markedaction" value="" /></form>');
1.1       albertel 1140:     if ($numblocked > 0) {
                   1141:         my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
                   1142:         my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
                   1143:         $r->print('<br /><br />'.
1.51      raeburn  1144:                   &mt('[quant,_1,message is, messages are] not viewable because display of LON-CAPA messages sent to you by other students between [_2] and [_3] is currently being blocked because of online exams.',$numblocked,$beginblock,$finishblock));
1.44      raeburn  1145:         $r->print(&Apache::loncommon::build_block_table($startblock,$endblock,
                   1146:                                                         \%setters));
1.1       albertel 1147:     }
                   1148: }
                   1149: 
                   1150: # ============================================================== Compose output
                   1151: 
                   1152: sub compout {
1.53      raeburn  1153:     my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode,
                   1154:         $multiforward)=@_;
1.1       albertel 1155:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
1.38      raeburn  1156:     my ($cdom,$cnum,$group,$refarg);
                   1157:     if (exists($env{'form.group'})) {
                   1158:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1159:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   1160:         $group = $env{'form.group'};
                   1161:         my $action = 'composing';
                   1162:         $r->print(&groupmail_header($action,$group,$cdom,$cnum));
                   1163:     } elsif ($broadcast eq 'individual') {
1.1       albertel 1164: 	&printheader($r,'/adm/email?compose=individual',
                   1165: 	     'Send a Message');
                   1166:     } elsif ($broadcast) {
                   1167: 	&printheader($r,'/adm/email?compose=group',
                   1168: 	     'Broadcast Message');
                   1169:     } elsif ($forwarding) {
                   1170: 	&Apache::lonhtmlcommon::add_breadcrumb
1.29      www      1171:         ({href=>"/adm/email?display=".&escape($forwarding),
1.1       albertel 1172:           text=>"Display Message"});
1.29      www      1173: 	&printheader($r,'/adm/email?forward='.&escape($forwarding),
1.1       albertel 1174: 	     'Forwarding a Message');
                   1175:     } elsif ($replying) {
                   1176: 	&Apache::lonhtmlcommon::add_breadcrumb
1.29      www      1177:         ({href=>"/adm/email?display=".&escape($replying),
1.1       albertel 1178:           text=>"Display Message"});
1.29      www      1179: 	&printheader($r,'/adm/email?replyto='.&escape($replying),
1.1       albertel 1180: 	     'Replying to a Message');
                   1181:     } elsif ($replycrit) {
                   1182: 	$r->print('<h3>'.&mt('Replying to a Critical Message').'</h3>');
                   1183: 	$replying=$replycrit;
1.53      raeburn  1184:     } elsif ($multiforward) {
                   1185:         &Apache::lonhtmlcommon::add_breadcrumb
                   1186:         ({href=>"/adm/email?folder=".&escape($folder),
                   1187:           text=>"Display All Messages"});
                   1188:         &printheader($r,'/adm/email?compose=multiforward',
                   1189:              'Forwarding Multiple Messages');
                   1190:         $r->print(&mt('Each of the <b>[quant,_1,message]</b> you checked will be forwarded to the recipient(s) you select below.',$multiforward).'<br />');
1.1       albertel 1191:     } else {
                   1192: 	&printheader($r,'/adm/email?compose=upload',
                   1193: 	     'Distribute from Uploaded File');
                   1194:     }
                   1195: 
                   1196:     my $dispcrit='';
                   1197:     my $dissub='';
                   1198:     my $dismsg='';
                   1199:     my $disbase='';
                   1200:     my $func=&mt('Send New');
1.50      raeburn  1201:     my %lt=&Apache::lonlocal::texthash('us'  => 'Username',
                   1202: 				       'do'  => 'Domain',
                   1203: 				       'ad'  => 'Additional Recipients',
                   1204: 				       'sb'  => 'Subject',
                   1205: 				       'ca'  => 'Cancel',
                   1206: 				       'ma'  => 'Mail',
1.53      raeburn  1207:                                        'msg' => 'Messages',
1.50      raeburn  1208:                                        'gen' => 'Generate messages from a file',
                   1209:                                        'gmt' => 'General message text',
                   1210:                                        'tff' => 'The file format for the uploaded portion of the message is',
                   1211:                                        'uas' => 'Upload and Send',
                   1212:                                       );
1.1       albertel 1213:     if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                   1214: 	|| &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                   1215: 				    '/'.$env{'request.course.sec'})) {
                   1216: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
                   1217:          $dispcrit=
                   1218:  '<p><label><input type="checkbox" name="critmsg" /> '.&mt('Send as critical message').'</label> ' . $crithelp . 
                   1219:  '</p><p>'.
                   1220:  '<label><input type="checkbox" name="sendbck" /> '.&mt('Send as critical message').'  ' .
                   1221:  &mt('and return receipt') . '</label>' . $crithelp . 
                   1222:  '</p><p><label><input type="checkbox" name="permanent" /> '.
                   1223: &mt('Send copy to permanent email address (if known)').'</label></p>'.
                   1224: '<p><label><input type="checkbox" name="rsspost" /> '.
                   1225: 		  &mt('Include in course RSS newsfeed').'</label></p>';
                   1226:      }
                   1227:     my %message;
                   1228:     my %content;
                   1229:     my $defdom=$env{'user.domain'};
                   1230:     if ($forwarding) {
                   1231: 	%message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]);
                   1232: 	%content=&Apache::lonmsg::unpackagemsg($message{$forwarding},$folder);
                   1233: 	$dispcrit.='<input type="hidden" name="forwid" value="'.
                   1234: 	    $forwarding.'" />';
                   1235: 	$func=&mt('Forward');
                   1236: 	
                   1237: 	$dissub=&mt('Forwarding').': '.$content{'subject'};
                   1238: 	$dismsg=&mt('Forwarded message from').' '.
                   1239: 	    $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
                   1240: 	if ($content{'baseurl'}) {
1.29      www      1241: 	    $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1       albertel 1242: 	}
                   1243:     }
                   1244:     if ($replying) {
                   1245: 	%message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
                   1246: 	%content=&Apache::lonmsg::unpackagemsg($message{$replying},$folder);
                   1247: 	$dispcrit.='<input type="hidden" name="replyid" value="'.
                   1248: 	    $replying.'" />';
                   1249: 	$func=&mt('Send Reply to');
                   1250: 	
                   1251: 	$dissub=&mt('Reply').': '.$content{'subject'};       
                   1252: 	$dismsg='> '.$content{'message'};
                   1253: 	$dismsg=~s/\r/\n/g;
                   1254: 	$dismsg=~s/\f/\n/g;
                   1255: 	$dismsg=~s/\n+/\n\> /g;
                   1256: 	if ($content{'baseurl'}) {
1.29      www      1257: 	    $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1       albertel 1258: 	    if ($env{'user.adv'}) {
                   1259: 		$disbase.='<label><input type="checkbox" name="storebasecomment" />'.&mt('Store message for re-use').
                   1260: 		    '</label> <a href="/adm/email?showcommentbaseurl='.
1.29      www      1261: 		    &escape($content{'baseurl'}).'" target="comments">'.
1.1       albertel 1262: 		    &mt('Show re-usable messages').'</a><br />';
                   1263: 	    }
                   1264: 	}
                   1265:     }
                   1266:     my $citation=&displayresource(%content);
1.38      raeburn  1267:     my ($can_grp_broadcast,$viewgrps,$editgrps);
1.1       albertel 1268:     if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
1.23      www      1269:     if ($env{'form.text'}) { $dismsg=$env{'form.text'}; }
                   1270:     if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; }
                   1271:     $r->print(
1.1       albertel 1272:                 '<form action="/adm/email"  name="compemail" method="post"'.
                   1273:                 ' enctype="multipart/form-data">'."\n".
1.38      raeburn  1274:                 '<input type="hidden" name="sendmail" value="on" />'."\n");
                   1275:     if ($broadcast eq 'group' && $env{'form.group'} ne '') {
                   1276:         $can_grp_broadcast = 
                   1277:                 &Apache::lonnet::allowed('sgb',$env{'request.course.id'}.'/'.
                   1278:                                          $group);
                   1279:         $viewgrps = 
                   1280:                &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
                   1281:                ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
                   1282:         $editgrps = 
                   1283:                &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
                   1284:                ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
                   1285:         if ($viewgrps || $editgrps || $can_grp_broadcast) {
                   1286:             $r->print(&disgroup($cdom,$cnum,$group,$viewgrps,$editgrps));
                   1287:         }
                   1288:     }
                   1289:     $r->print('<table>');
                   1290:     if (($broadcast eq 'group') && ($group ne '') && 
                   1291:         (!$can_grp_broadcast && !$viewgrps && !$editgrps)) {
                   1292:         $r->print(&recipient_input_row($cdom,%lt));
                   1293:     } 
                   1294:     if (($broadcast ne 'group') && ($broadcast ne 'upload')) {
1.1       albertel 1295: 	if ($replying) {
                   1296: 	    $r->print('<tr><td colspan="2">'.&mt('Replying to').' '.
                   1297: 		      &Apache::loncommon::aboutmewrapper(
                   1298: 							 &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
1.14      albertel 1299: 		      $content{'sendername'}.':'.
1.1       albertel 1300: 		      $content{'senderdomain'}.')'.
                   1301: 		      '<input type="hidden" name="recuname" value="'.$content{'sendername'}.'" />'.
                   1302: 		      '<input type="hidden" name="recdomain" value="'.$content{'senderdomain'}.'" />'.
                   1303: 		      '</td></tr>');
                   1304: 	} else {
1.38      raeburn  1305:             $r->print(&recipient_input_row($defdom,%lt));
1.1       albertel 1306:         }
                   1307:     }
                   1308:     my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
1.53      raeburn  1309:     my $subj_size;
                   1310:     if ($multiforward) {
                   1311:         $r->print(&additional_rec_row(\%lt));
                   1312:         $r->print('<tr><td colspan="2">'.
                   1313:                   &mt('Unless you choose otherwise:').'<ul><li>'.
                   1314:         &mt("The subject in each forwarded message will be <i>'Forwarding:'</i> followed by the original subject.").'</li><li>'.
                   1315:         &mt("The message itself will begin with a first line: <i>'Forwarded message from'</i> followed by the original sender's name.").'</li></ul></td></tr>');
                   1316:         $func=&mt('Forward');
                   1317:         $dissub = &mt('Forwarding').': ';
                   1318:         $subj_size = '10';
                   1319:         my $extra = '&lt;'.&mt('original subject').'&gt;&nbsp;&nbsp;&nbsp;'.
                   1320:                     '<input type="radio" name="showorigsubj" value="1" checked="checked" />'.&mt('Yes').'&nbsp;<input type="radio" name="showorigsubj" value="0" />'.&mt('No');
                   1321:         $dismsg = &mt('Forwarded message from ').' ';
                   1322:         my $sender = &mt("sender's name");
                   1323:         $r->print(&msg_subject_row($dissub,\%lt,$subj_size,$extra));
                   1324:         $r->print('<tr><td>'.&mt('Message begins with:').'</td><td><input type="text" name="msgheader" value="'.$dismsg.'" />&nbsp;'.$sender.'&nbsp;&nbsp;&nbsp;<input type="radio" name="showorigsender" value="1" checked="checked" />'.&mt('Yes').'&nbsp;<input type="radio" name="showorigsender" value="0" />'.&mt('No').'<input type="hidden" name="multiforward" value="'.$multiforward.'" /></td></tr>
                   1325: </table>
                   1326: <br />'.
                   1327: $latexHelp.
                   1328: &mt("Any new text to display before the text of the original messages:").'<br />
                   1329: <textarea name="message" id="message" cols="80" rows="5" wrap="hard">
                   1330: </textarea></p><br />');
                   1331:         my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
                   1332:         foreach my $msg (@to_forward) {
                   1333:             $r->print('<input type="hidden" name="delmark" value="'.$msg.'" />');
                   1334:         }
                   1335:         $r->print(&submit_button_row($folder,$dismode,$func.' '.$lt{'msg'},
                   1336:                                      \%lt));
                   1337:     } elsif ($broadcast ne 'upload') {
                   1338:         $subj_size = '50';
                   1339:         $r->print(&additional_rec_row(\%lt));
                   1340:         $r->print(&msg_subject_row($dissub,\%lt,$subj_size));
                   1341:         $r->print(<<"ENDCOMP");
                   1342: </table>
1.1       albertel 1343: $latexHelp
                   1344: <textarea name="message" id="message" cols="80" rows="15" wrap="hard">$dismsg
                   1345: </textarea></p><br />
                   1346: $dispcrit
                   1347: $disbase
                   1348: ENDCOMP
1.53      raeburn  1349:         $r->print(&submit_button_row($folder,$dismode,$func.' '.$lt{'ma'},
                   1350:                                      \%lt));
                   1351:         $r->print($citation);
1.38      raeburn  1352:         if (exists($env{'form.ref'})) {
                   1353:             $r->print('<input type="hidden" name="ref" value="'.
                   1354:                       $env{'form.ref'}.'" />');
                   1355:         }
                   1356:         if (exists($env{'form.group'})) {
                   1357:             $r->print('<input type="hidden" name="group" value="'.
                   1358:                       $env{'form.group'}.'" />');
                   1359:         }
1.1       albertel 1360:     } else { # $broadcast is 'upload'
1.50      raeburn  1361: 	$r->print(<<ENDBLOCK);
1.1       albertel 1362: <input type="hidden" name="sendmode" value="upload" />
                   1363: <input type="hidden" name="send" value="on" />
1.50      raeburn  1364: <h3>$lt{'gen'}</h3>
1.1       albertel 1365: <p>
                   1366: Subject: <input type="text" size="50" name="subject" />
                   1367: </p>
1.50      raeburn  1368: <p>$lt{'gmt'}:<br />
1.1       albertel 1369: <textarea name="message" id="message" cols="60" rows="10" wrap="hard">$dismsg
                   1370: </textarea></p>
                   1371: <p>
1.50      raeburn  1372: $lt{'tff'}:
                   1373: ENDBLOCK
                   1374:        $r->print('
                   1375: <pre>'."\n".
                   1376: &mt('username1:domain1: text')."\n".
                   1377: &mt('username2:domain2: text')."\n".
                   1378: &mt('username3:domain1: text')."\n".
                   1379: '</pre>
1.1       albertel 1380: </p>
                   1381: <p>
1.50      raeburn  1382: '.&mt('The messages will be assembled from all lines with the respective'."\n".'<tt>username:domain</tt>, and appended to the general message text.'));
                   1383:         $r->print(<<ENDUPLOAD);
                   1384: </p>
1.1       albertel 1385: <p>
                   1386: <input type="file" name="upfile" size="40" /></p><p>
                   1387: $dispcrit
1.50      raeburn  1388: <input type="submit" value="$lt{'uas'}" /></p>
1.1       albertel 1389: ENDUPLOAD
                   1390:     }
                   1391:     if ($broadcast eq 'group') {
1.38      raeburn  1392:        if ($group eq '') {
                   1393:            my $studentsel = &discourse();
                   1394:            $r->print($studentsel);
                   1395:        }
1.1       albertel 1396:     }
1.36      albertel 1397:     if ($env{'form.displayedcrit'}) {
                   1398: 	$r->print('<input type="hidden" name="displayedcrit" value="true" />');
                   1399:     }
1.1       albertel 1400:     $r->print('</form>'.
                   1401: 	      &Apache::lonfeedback::generate_preview_button('compemail','message').
                   1402: 	      &Apache::lonhtmlcommon::htmlareaselectactive('message'));
                   1403: }
                   1404: 
                   1405: # ---------------------------------------------------- Display all face to face
                   1406: 
1.38      raeburn  1407: sub recipient_input_row {
                   1408:     my ($dom,%lt) = @_;
                   1409:     my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain');
                   1410:     my $selectlink=
                   1411:       &Apache::loncommon::selectstudent_link('compemail','recuname',
                   1412:                                              'recdomain');
                   1413:     my $output = <<"ENDREC";
                   1414: <tr><td>$lt{'us'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recname'}" /></td><td rowspan="2">$selectlink</td></tr>
                   1415: <tr><td>$lt{'do'}:</td>
                   1416: <td>$domform</td></tr>
                   1417: ENDREC
                   1418:     return $output;
                   1419: }
                   1420: 
1.53      raeburn  1421: sub additional_rec_row {
                   1422:     my ($lt) = @_;
                   1423:     my $output = <<"ENDADD";
                   1424: <tr><td>$lt->{'ad'}:<br /><tt>username:domain,username:domain, ...
                   1425: </tt></td><td>
                   1426: <input type="text" size="50" name="additionalrec" /></td></tr>
                   1427: ENDADD
                   1428:     return $output;
                   1429: }
                   1430: 
                   1431: sub submit_button_row {
                   1432:     my ($folder,$dismode,$sendtext,$lt) = @_;
                   1433:     my $output = qq| 
                   1434: <input type="hidden" name="folder" value="$folder" />
                   1435: <input type="hidden" name="dismode" value="$dismode" />
                   1436: <input type="submit" name="send" value="$sendtext" />
                   1437: <input type="submit" name="cancel" value="$lt->{'ca'}" /><hr />
                   1438: |;
                   1439:     return $output;
                   1440: }
                   1441: 
                   1442: sub msg_subject_row {
                   1443:     my ($dissub,$lt,$subj_size,$extra) = @_;
                   1444:     my $output = '<tr><td>'.$lt->{'sb'}.':</td><td><input type="text" size="'.
                   1445:                  $subj_size.'" name="subject" value="'.$dissub.'" />'.$extra.
                   1446:                  '</td></tr>';
                   1447:     return $output;
                   1448: }
                   1449: 
1.1       albertel 1450: sub retrieve_instructor_comments {
                   1451:     my ($user,$domain)=@_;
                   1452:     my $target=$env{'form.grade_target'};
                   1453:     if (! $env{'request.course.id'}) { return; }
1.49      albertel 1454:     if (! &Apache::lonnet::allowed('dff',$env{'request.course.id'})
                   1455: 	&& ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1       albertel 1456: 				      '/'.$env{'request.course.sec'})) {
                   1457: 	return;
                   1458:     }
                   1459:     my %records=&Apache::lonnet::dump('nohist_email',
                   1460: 			 $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1461: 			 $env{'course.'.$env{'request.course.id'}.'.num'},
                   1462:                          '%255b'.$user.'%253a'.$domain.'%255d');
                   1463:     my $result='';
1.42      raeburn  1464:     foreach my $key (sort(keys(%records))) {
                   1465:         my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1       albertel 1466:         next if ($content{'senderdomain'} eq '');
                   1467:         next if ($content{'subject'} !~ /^Record/);
                   1468: 	# &Apache::lonfeedback::newline_to_br(\$content{'message'});
                   1469: 	$result.='Recorded by '.
1.14      albertel 1470:             $content{'sendername'}.':'.$content{'senderdomain'}."\n";
1.1       albertel 1471:         $result.=
                   1472:             &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
                   1473:      }
                   1474:     return $result;
                   1475: }
                   1476: 
                   1477: sub disfacetoface {
                   1478:     my ($r,$user,$domain)=@_;
                   1479:     my $target=$env{'form.grade_target'};
                   1480:     unless ($env{'request.course.id'}) { return; }
1.49      albertel 1481:     if  (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
                   1482: 	 && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1       albertel 1483: 				       '/'.$env{'request.course.sec'})) {
1.50      raeburn  1484: 	$r->print(&mt('Not allowed'));
1.1       albertel 1485: 	return;
                   1486:     }
                   1487:     my %records=&Apache::lonnet::dump('nohist_email',
                   1488: 			 $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1489: 			 $env{'course.'.$env{'request.course.id'}.'.num'},
                   1490:                          '%255b'.$user.'%253a'.$domain.'%255d');
                   1491:     my $result='';
1.42      raeburn  1492:     foreach my $key (sort(keys(%records))) {
                   1493:         my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1       albertel 1494:         next if ($content{'senderdomain'} eq '');
                   1495: 	&Apache::lonfeedback::newline_to_br(\$content{'message'});
                   1496:         if ($content{'subject'}=~/^Record/) {
                   1497: 	    $result.='<h3>'.&mt('Record').'</h3>';
                   1498:         } elsif ($content{'subject'}=~/^Broadcast/) {
                   1499:             $result .='<h3>'.&mt('Broadcast Message').'</h3>';
                   1500:             if ($content{'subject'}=~/^Broadcast\./) {
                   1501:                 if (defined($content{'coursemsgid'})) {
1.29      www      1502:                     my $crsmsgid = &escape($content{'coursemsgid'});
1.1       albertel 1503:                     my $broadcast_message = &general_message($crsmsgid);
                   1504:                     $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$broadcast_message;
                   1505:                 } else {
                   1506:                     %content=&Apache::lonmsg::unpackagemsg($content{'message'});
                   1507:                     $content{'message'} =
                   1508:                     '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
                   1509:                     $content{'message'};
                   1510:                 }
                   1511:             }    
                   1512:         } else {
                   1513:             $result.='<h3>'.&mt('Critical Message').'</h3>';
                   1514:             if (defined($content{'coursemsgid'})) {
1.29      www      1515:                 my $crsmsgid=&escape($content{'coursemsgid'});
1.1       albertel 1516:                 my $critical_message = &general_message($crsmsgid);
                   1517:                 $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$critical_message;
                   1518:             } else {
                   1519:                 %content=&Apache::lonmsg::unpackagemsg($content{'message'});
                   1520:                 $content{'message'}=
                   1521:                 '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
                   1522: 		$content{'message'};
                   1523:             }
                   1524:         }
                   1525:         $result.=&mt('By').': <b>'.
                   1526: &Apache::loncommon::aboutmewrapper(
                   1527:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14      albertel 1528: $content{'sendername'}.':'.
1.1       albertel 1529:             $content{'senderdomain'}.') '.$content{'time'}.
                   1530:             '<br /><pre>'.
                   1531:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
                   1532: 	      '</pre>';
                   1533:      }
                   1534:     # Check to see if there were any messages.
                   1535:     if ($result eq '') {
1.33      albertel 1536:         my $lctype = lc(&Apache::loncommon::course_type());
1.1       albertel 1537: 	if ($target ne 'tex') { 
1.30      raeburn  1538: 	    $r->print("<p><b>".&mt('No notes, face-to-face discussion records, critical messages, or broadcast messages in this [_1].',$lctype)."</b></p>");
1.1       albertel 1539: 	} else {
1.30      raeburn  1540: 	    $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this [_1].',$lctype).'}\\\\');
1.1       albertel 1541: 	}
                   1542:     } else {
                   1543:        $r->print($result);
                   1544:     }
                   1545: }
                   1546: 
                   1547: sub general_message {
                   1548:     my ($crsmsgid) = @_;
                   1549:     my %general_content;
                   1550:     if ($crsmsgid) { 
                   1551:         my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid],
                   1552:                            $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1553:                            $env{'course.'.$env{'request.course.id'}.'.num'});
                   1554:         %general_content = &Apache::lonmsg::unpackagemsg($course_content{$crsmsgid});
                   1555:     }
                   1556:     return $general_content{'message'};
                   1557: }
                   1558: 
                   1559: # ---------------------------------------------------------------- Face to face
                   1560: 
                   1561: sub facetoface {
                   1562:     my ($r,$stage)=@_;
1.49      albertel 1563:     if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
                   1564: 	&& ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1       albertel 1565: 				      '/'.$env{'request.course.sec'})) {
1.50      raeburn  1566: 	$r->print(&mt('Not allowed'));
1.1       albertel 1567: 	return;
                   1568:     }
1.33      albertel 1569:     my $crstype = &Apache::loncommon::course_type();
                   1570:     my $leaders = ($crstype eq 'Group') ? 'coordinators and leaders'
                   1571:                                         : 'faculty and staff';
1.1       albertel 1572:     &printheader($r,
                   1573: 		 '/adm/email?recordftf=query',
                   1574: 		 "User Notes, Face-to-Face, Critical Messages, Broadcast Messages");
                   1575: # from query string
                   1576: 
                   1577:     if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
                   1578:     if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
                   1579: 
                   1580:     my $defdom=$env{'user.domain'};
                   1581: # already filled in
                   1582:     if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
                   1583: # generate output
                   1584:     my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
                   1585:     my $stdbrws = &Apache::loncommon::selectstudent_link
                   1586: 	('stdselect','recuname','recdomain');
                   1587:     my %lt=&Apache::lonlocal::texthash('user' => 'Username',
                   1588: 				       'dom' => 'Domain',
1.30      raeburn  1589: 				       'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, and Broadcast Messages in $crstype",
1.1       albertel 1590: 				       'subm' => 'Retrieve discussion and message records',
1.30      raeburn  1591: 				       'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')',
1.1       albertel 1592: 				       'post' => 'Post this Record');
                   1593:     $r->print(<<"ENDTREC");
                   1594: <h3>$lt{'head'}</h3>
                   1595: <form method="post" action="/adm/email" name="stdselect">
                   1596: <input type="hidden" name="recordftf" value="retrieve" />
                   1597: <table>
                   1598: <tr><td>$lt{'user'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recuname'}" /></td>
                   1599: <td rowspan="2">
                   1600: $stdbrws
                   1601: <input type="submit" value="$lt{'subm'}" /></td>
                   1602: </tr>
                   1603: <tr><td>$lt{'dom'}:</td>
                   1604: <td>$domform</td></tr>
                   1605: </table>
                   1606: </form>
                   1607: ENDTREC
                   1608:     if (($stage ne 'query') &&
                   1609:         ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
                   1610:         chomp($env{'form.newrecord'});
                   1611:         if ($env{'form.newrecord'}) {
1.31      albertel 1612: 	    &Apache::lonmsg::store_instructor_comment($env{'form.newrecord'},
                   1613: 						      $env{'form.recuname'},
                   1614: 						      $env{'form.recdomain'});
1.1       albertel 1615:         }
                   1616:         $r->print('<h3>'.&Apache::loncommon::plainname($env{'form.recuname'},
                   1617: 				     $env{'form.recdomain'}).'</h3>');
                   1618:         &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
                   1619: 	$r->print(<<ENDRHEAD);
                   1620: <form method="post" action="/adm/email">
                   1621: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
                   1622: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
                   1623: ENDRHEAD
                   1624:         $r->print(<<ENDBFORM);
                   1625: <hr />$lt{'newr'}<br />
                   1626: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
                   1627: <br />
                   1628: <input type="hidden" name="recordftf" value="post" />
                   1629: <input type="submit" value="$lt{'post'}" />
                   1630: </form>
                   1631: ENDBFORM
                   1632:     }
                   1633: }
                   1634: 
                   1635: # ----------------------------------------------------------- Blocking during exams
                   1636: 
                   1637: sub examblock {
                   1638:     my ($r,$action) = @_;
                   1639:     unless ($env{'request.course.id'}) { return;}
1.44      raeburn  1640:     if (!&Apache::lonnet::allowed('dcm',$env{'request.course.id'})
                   1641: 	&& ! &Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
1.1       albertel 1642: 				      '/'.$env{'request.course.sec'})) {
                   1643: 	$r->print('Not allowed');
                   1644: 	return;
                   1645:     }
1.34      albertel 1646:     my $usertype = (&Apache::loncommon::course_type() eq 'Group') ? 'members'
1.33      albertel 1647: 	                                                          : 'students';
1.1       albertel 1648:     my %lt=&Apache::lonlocal::texthash(
                   1649:             'comb' => 'Communication Blocking',
                   1650:             'cbds' => 'Communication blocking during scheduled exams',
1.30      raeburn  1651:             'desc' => "You can use communication blocking to prevent $usertype enrolled in this course from displaying LON-CAPA messages sent by other $usertype during an online exam. As blocking of communication could potentially interrupt legitimate communication between $usertype 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.",
1.1       albertel 1652:              'mecb' => 'Modify existing communication blocking periods',
1.50      raeburn  1653:              'ncbc' => 'No communication blocks currently stored',
                   1654:              'stor' => 'Store',
1.1       albertel 1655:     );
                   1656: 
                   1657:     my %ltext = &Apache::lonlocal::texthash(
                   1658:             'dura' => 'Duration',
                   1659:             'setb' => 'Set by',
                   1660:             'even' => 'Event',
1.44      raeburn  1661:             'blck' => 'Blocked?',
1.1       albertel 1662:             'actn' => 'Action',
                   1663:             'star' => 'Start',
                   1664:             'endd' => 'End'
                   1665:     );
                   1666: 
                   1667:     &printheader($r,'/adm/email?block=display',$lt{'comb'});
                   1668:     $r->print('<h3>'.$lt{'cbds'}.'</h3>');
                   1669: 
                   1670:     if ($action eq 'store') {
                   1671:         &blockstore($r);
                   1672:     }
                   1673: 
                   1674:     $r->print($lt{'desc'}.'<br /><br />
                   1675:                <form name="blockform" method="post" action="/adm/email?block=store">
                   1676:              ');
                   1677: 
                   1678:     $r->print('<h4>'.$lt{'mecb'}.'</h4>');
                   1679:     my %records = ();
                   1680:     my $blockcount = 0;
                   1681:     my $parmcount = 0;
                   1682:     &get_blockdates(\%records,\$blockcount);
                   1683:     if ($blockcount > 0) {
                   1684:         $parmcount = &display_blocker_status($r,\%records,\%ltext);
                   1685:     } else {
                   1686:         $r->print($lt{'ncbc'}.'<br /><br />');
                   1687:     }
                   1688:     &display_addblocker_table($r,$parmcount,\%ltext);
                   1689:     my $end_page=&Apache::loncommon::end_page();
                   1690:     $r->print(<<"END");
                   1691: <br />
                   1692: <input type="hidden" name="blocktotal" value="$blockcount" />
1.50      raeburn  1693: <input type ="submit" value="$lt{'stor'}" />
1.1       albertel 1694: </form>
                   1695: $end_page
                   1696: END
                   1697:     return;
                   1698: }
                   1699: 
                   1700: sub blockstore {
                   1701:     my $r = shift;
                   1702:     my %lt=&Apache::lonlocal::texthash(
                   1703:             'tfcm' => 'The following changes were made',
                   1704:             'ncwm' => 'No changes were made.' 
                   1705:     );
                   1706:     my %adds = ();
                   1707:     my %removals = ();
                   1708:     my %cancels = ();
                   1709:     my $modtotal = 0;
                   1710:     my $canceltotal = 0;
                   1711:     my $addtotal = 0;
                   1712:     my %blocking = ();
                   1713:     $r->print('<h3>'.$lt{'head'}.'</h3>');
1.42      raeburn  1714:     foreach my $envkey (keys(%env)) {
1.44      raeburn  1715:         if ($envkey =~ m/^form\.modify_(\d+)$/) {
1.1       albertel 1716:             $adds{$1} = $1;
                   1717:             $removals{$1} = $1;
                   1718:             $modtotal ++;
1.42      raeburn  1719:         } elsif ($envkey =~ m/^form\.cancel_(\d+)$/) {
1.1       albertel 1720:             $cancels{$1} = $1;
                   1721:             unless ( defined($removals{$1}) ) {
                   1722:                 $removals{$1} = $1;
                   1723:                 $canceltotal ++;
                   1724:             }
1.42      raeburn  1725:         } elsif ($envkey =~ m/^form\.add_(\d+)$/) {
1.1       albertel 1726:             $adds{$1} = $1;
                   1727:             $addtotal ++;
1.44      raeburn  1728:         } 
1.1       albertel 1729:     }
                   1730: 
1.42      raeburn  1731:     foreach my $key (keys(%removals)) {
                   1732:         my $hashkey = $env{'form.key_'.$key};
1.1       albertel 1733:         &Apache::lonnet::del('comm_block',["$hashkey"],
                   1734:                          $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1735:                          $env{'course.'.$env{'request.course.id'}.'.num'}
                   1736:                          );
                   1737:     }
1.42      raeburn  1738:     foreach my $key (keys(%adds)) {
                   1739:         unless ( defined($cancels{$key}) ) {
                   1740:             my ($newstart,$newend) = &get_dates_from_form($key);
1.1       albertel 1741:             my $newkey = $newstart.'____'.$newend;
1.44      raeburn  1742:             my $blocktypes = &get_block_choices($key);
                   1743:             $blocking{$newkey} = {
                   1744:                           setter => $env{'user.name'}.':'.$env{'user.domain'},
                   1745:                           event  => &escape($env{'form.title_'.$key}),
                   1746:                           blocks => $blocktypes,
                   1747:                         };
1.1       albertel 1748:         }
                   1749:     }
                   1750:     if ($addtotal + $modtotal > 0) {
                   1751:         &Apache::lonnet::put('comm_block',\%blocking,
                   1752:                      $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1753:                      $env{'course.'.$env{'request.course.id'}.'.num'}
                   1754:                      );
                   1755:     }
                   1756:     my $chgestotal = $canceltotal + $modtotal + $addtotal;
                   1757:     if ($chgestotal > 0) {
                   1758:         $r->print($lt{'tfcm'}.'<ul>');
                   1759:         if ($canceltotal > 0) {
1.50      raeburn  1760:             $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] removed.',$canceltotal).'</li>');
1.1       albertel 1761:         }
                   1762:         if ($modtotal > 0) {
1.50      raeburn  1763:             $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] modified.',$modtotal).'</li>');
1.1       albertel 1764:         }
                   1765:         if ($addtotal > 0) {
1.50      raeburn  1766:             $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] added.',$addtotal).'</li>');
1.1       albertel 1767:         }
                   1768:         $r->print('</ul>');
                   1769:     } else {
                   1770:         $r->print($lt{'ncwm'});
                   1771:     }
                   1772:     $r->print('<br />');
                   1773:     return;
                   1774: }
                   1775: 
                   1776: sub get_dates_from_form {
                   1777:     my $item = shift;
                   1778:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
                   1779:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
                   1780:     return ($startdate,$enddate);
                   1781: }
                   1782: 
                   1783: sub get_blockdates {
                   1784:     my ($records,$blockcount) = @_;
                   1785:     $$blockcount = 0;
                   1786:     %{$records} = &Apache::lonnet::dump('comm_block',
                   1787:                          $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1788:                          $env{'course.'.$env{'request.course.id'}.'.num'}
                   1789:                          );
1.15      albertel 1790:     $$blockcount = keys(%{$records});
                   1791: 
                   1792:     if ((keys(%{$records}))[0] =~ /^error: 2 /) {
                   1793: 	$records = {};
                   1794: 	$$blockcount = 0;
1.1       albertel 1795:     }
                   1796: }
                   1797: 
1.44      raeburn  1798: sub get_block_choices {
                   1799:     my $item = shift;
                   1800:     my $blocklist;
                   1801:     my ($typeorder,$types) = &blocktype_text();
                   1802:     foreach my $type (@{$typeorder}) {
                   1803:         if ($env{'form.'.$type.'_'.$item}) {
                   1804:             $blocklist->{$type} = 'on'; 
                   1805:         } else {
                   1806:             $blocklist->{$type} = 'off';
                   1807:         }
                   1808:     }
                   1809:     return $blocklist;
                   1810: }
                   1811: 
1.1       albertel 1812: sub display_blocker_status {
                   1813:     my ($r,$records,$ltext) = @_;
                   1814:     my $parmcount = 0;
1.16      albertel 1815:   
1.1       albertel 1816:     my %lt = &Apache::lonlocal::texthash(
                   1817:         'modi' => 'Modify',
                   1818:         'canc' => 'Cancel',
                   1819:     );
1.44      raeburn  1820:     my ($typeorder,$types) = &blocktype_text();
1.18      albertel 1821:     $r->print(&Apache::loncommon::start_data_table());
1.1       albertel 1822:     $r->print(<<"END");
1.16      albertel 1823:   <tr>
1.44      raeburn  1824:     <th>$ltext->{'dura'}</th>
                   1825:     <th>$ltext->{'setb'}</th>
                   1826:     <th>$ltext->{'even'}</th>
                   1827:     <th>$ltext->{'blck'}</th>
                   1828:     <th>$ltext->{'actn'}?</th>
1.16      albertel 1829:   </tr>
1.1       albertel 1830: END
1.18      albertel 1831:     foreach my $record (sort(keys(%{$records}))) {
1.1       albertel 1832:         my $onchange = 'onFocus="javascript:window.document.forms['.
                   1833:                        "'blockform'].elements['modify_".$parmcount."'].".
                   1834:                        'checked=true;"';
1.18      albertel 1835:         my ($start,$end) = split(/____/,$record);
1.1       albertel 1836:         my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
                   1837:         my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1.15      albertel 1838: 	
1.44      raeburn  1839: 	my ($setuname,$setudom,$title,$blocks) = 
                   1840: 	    &Apache::loncommon::parse_block_record($$records{$record});
1.21      albertel 1841: 	$title = &HTML::Entities::encode($title,'"<>&');
1.44      raeburn  1842:         my $settername = 
                   1843:            &Apache::loncommon::aboutmewrapper(
                   1844:                            &Apache::loncommon::plainname($setuname,$setudom),
                   1845:                            $setuname,$setudom);
1.18      albertel 1846:         $r->print(&Apache::loncommon::start_data_table_row());
1.1       albertel 1847:         $r->print(<<"END");
1.44      raeburn  1848:         <td>$ltext->{'star'}:&nbsp;$startform<br/>$ltext->{'endd'}:&nbsp;&nbsp;$endform</td>
1.1       albertel 1849:         <td>$settername</td>
1.18      albertel 1850:         <td><input type="text" name="title_$parmcount" size="15" value="$title" /><input type="hidden" name="key_$parmcount" value="$record" /></td>
1.44      raeburn  1851:         <td>
                   1852: END
                   1853:         foreach my $block (@{$typeorder}) {
                   1854:             my $blockstatus = '';
                   1855:             if ($blocks->{$block} eq 'on') {
                   1856:                 $blockstatus = 'checked="true"';
                   1857:             }
                   1858:             $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" '.$blockstatus.' value="1" />'.$types->{$block}.'</label><br />');
                   1859:         }
                   1860:         $r->print(<<"END");
                   1861:         </td>      
1.1       albertel 1862:         <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>
                   1863: END
1.18      albertel 1864:         $r->print(&Apache::loncommon::end_data_table_row());
                   1865:         $parmcount++;
1.1       albertel 1866:     }
                   1867:     $r->print(<<"END");
                   1868: </table>
                   1869: <br />
                   1870: <br />
                   1871: END
                   1872:     return $parmcount;
                   1873: }
                   1874: 
                   1875: sub display_addblocker_table {
                   1876:     my ($r,$parmcount,$ltext) = @_;
                   1877:     my $start = time;
                   1878:     my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
                   1879:     my $onchange = 'onFocus="javascript:window.document.forms['.
                   1880:                    "'blockform'].elements['add_".$parmcount."'].".
                   1881:                    'checked=true;"';
                   1882:     my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
                   1883:     my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
                   1884:     my %lt = &Apache::lonlocal::texthash(
                   1885:         'addb' => 'Add block',
                   1886:         'exam' => 'e.g., Exam 1',
                   1887:         'addn' => 'Add new communication blocking periods'
                   1888:     );
1.44      raeburn  1889:     my ($typeorder,$types) = &blocktype_text();
1.1       albertel 1890:     $r->print(<<"END");
                   1891: <h4>$lt{'addn'}</h4> 
1.18      albertel 1892: END
                   1893:     $r->print(&Apache::loncommon::start_data_table());
                   1894:     $r->print(<<"END");
1.16      albertel 1895:    <tr>
1.44      raeburn  1896:      <th>$ltext->{'dura'}</th>
                   1897:      <th>$ltext->{'even'} $lt{'exam'}</th>
                   1898:      <th>$ltext->{'blck'}</th>
                   1899:      <th>$ltext->{'actn'}?</th>
1.16      albertel 1900:    </tr>
1.18      albertel 1901: END
1.44      raeburn  1902:     $r->print(&Apache::loncommon::start_data_table_row());
1.18      albertel 1903:     $r->print(<<"END");
1.44      raeburn  1904:      <td>$ltext->{'star'}:&nbsp;$startform<br />$ltext->{'endd'}:&nbsp;&nbsp;$endform</td>
1.16      albertel 1905:      <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
1.44      raeburn  1906:      <td>
                   1907: END
                   1908:     foreach my $block (@{$typeorder}) {
                   1909:         $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" value="1" />'.$types->{$block}.'</label><br />');
                   1910:      }
                   1911:      $r->print(<<"END");
                   1912:      </td> 
1.16      albertel 1913:      <td><label>$lt{'addb'}?&nbsp;<input type="checkbox" name="add_$parmcount" value="1" /></label></td>
1.1       albertel 1914: END
1.18      albertel 1915:     $r->print(&Apache::loncommon::end_data_table_row());
                   1916:     $r->print(&Apache::loncommon::end_data_table());
1.1       albertel 1917:     return;
                   1918: }
                   1919: 
1.44      raeburn  1920: sub blocktype_text {
                   1921:     my %types = &Apache::lonlocal::texthash(
                   1922:         'com' => 'Messaging',
                   1923:         'chat' => 'Chat',
                   1924:         'boards' => 'Discussion',
                   1925:         'port' => 'Portfolio',
1.45      raeburn  1926:         'groups' => 'Groups',
                   1927:         'blogs' => 'Blogs',
1.18      albertel 1928:     );
1.45      raeburn  1929:     my $typeorder = ['com','chat','boards','port','groups','blogs'];
1.44      raeburn  1930:     return ($typeorder,\%types);
1.1       albertel 1931: }
                   1932: 
                   1933: # ----------------------------------------------------------- Display a message
                   1934: 
                   1935: sub displaymessage {
1.53      raeburn  1936:     my ($r,$msgid,$folder,$msgstatus)=@_;
1.1       albertel 1937:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
                   1938:     my %blocked = ();
                   1939:     my %setters = ();
                   1940:     my $numblocked = 0;
1.33      albertel 1941:     my $crstype = &Apache::loncommon::course_type();
1.30      raeburn  1942: 
1.1       albertel 1943: # info to generate "next" and "previous" buttons and check if message is blocked
1.44      raeburn  1944:     my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53      raeburn  1945:     my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1       albertel 1946:     if ( $blocked{$msgid} eq 'ON' ) {
                   1947:         &printheader($r,'/adm/email',&mt('Display a Message'));
                   1948:         $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.'));
                   1949:         &build_block_table($r,$startblock,$endblock,\%setters);
                   1950:         return;
                   1951:     }
1.59      raeburn  1952:     if ($msgstatus eq '') {
                   1953:         &statuschange($msgid,'read',$folder);
                   1954:     }
1.1       albertel 1955:     my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
                   1956:     my %content=&Apache::lonmsg::unpackagemsg($message{$msgid});
                   1957: 
                   1958:     my $counter=0;
                   1959:     $r->print('<pre>');
1.29      www      1960:     my $escmsgid=&escape($msgid);
1.1       albertel 1961:     foreach (@messages) {
                   1962: 	if ($_->[5] eq $escmsgid){
                   1963: 	    last;
                   1964: 	}
                   1965: 	$counter++;
                   1966:     }
                   1967:     $r->print('</pre>');
                   1968:     my $number_of_messages = scalar(@messages); #subtract 1 for last index
                   1969: # start output
1.29      www      1970:     &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'});
1.1       albertel 1971:     my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'});
                   1972: # Functions
                   1973:     $r->print('<table border="2" width="100%"><tr bgcolor="#FFFFAA"><td>'.&mt('Functions').':</td>'.
1.29      www      1974: 	      '<td><a href="/adm/email?replyto='.&escape($msgid).$sqs.
1.1       albertel 1975: 	      '"><b>'.&mt('Reply').'</b></a></td>'.
1.29      www      1976: 	      '<td><a href="/adm/email?forward='.&escape($msgid).$sqs.
1.1       albertel 1977: 	      '"><b>'.&mt('Forward').'</b></a></td>'.
1.29      www      1978: 	      '<td><a href="/adm/email?markunread='.&escape($msgid).$sqs.
1.1       albertel 1979: 	      '"><b>'.&mt('Mark Unread').'</b></a></td>'.
1.29      www      1980: 	      '<td><a href="/adm/email?markdel='.&escape($msgid).$sqs.
1.1       albertel 1981: 	      '"><b>'.&mt('Delete').'</b></a></td>'.
                   1982: 	      '<td><a href="/adm/email?'.$sqs.
                   1983: 	      '"><b>'.&mt('Back to Folder Display').'</b></a></td>');
                   1984:     if ($counter > 0){
                   1985: 	$r->print('<td><a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.
                   1986: 		  '"><b>'.&mt('Previous').'</b></a></td>');
                   1987:     }
                   1988:     if ($counter < $number_of_messages - 1){
                   1989: 	$r->print('<td><a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.
                   1990: 		  '"><b>'.&mt('Next').'</b></a></td>');
                   1991:     }
                   1992:     $r->print('</tr></table>');
1.59      raeburn  1993:     my $symb;
                   1994:     if (defined($content{'symb'})) {
                   1995:         $symb = $content{'symb'};
                   1996:     } elsif (defined($content{'baseurl'})) {
                   1997:         $symb=&Apache::lonnet::symbread($content{'baseurl'});
                   1998:     }
1.1       albertel 1999:     if ($env{'user.adv'}) {
                   2000: 	$r->print('<table border="2" width="100%"><tr bgcolor="#FFAAAA"><td>'.&mt('Currently available actions (will open extra window)').':</td>');
                   2001: 	if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
                   2002: 		$r->print('<td><b>'.&Apache::loncommon::track_student_link(&mt('View recent activity'),$content{'sendername'},$content{'senderdomain'},'check').'</b></td>');
                   2003: 	    }
                   2004: 	if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
                   2005: 	    $r->print('<td><b>'.&Apache::loncommon::pprmlink(&mt('Set/Change parameters'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
                   2006: 	}
                   2007: 	if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
                   2008: 	    $r->print('<td><b>'.&Apache::loncommon::pgrdlink(&mt('Set/Change grades'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
                   2009: 	}
                   2010: 	$r->print('</tr></table>');
                   2011:     }
                   2012:     my $tolist;
                   2013:     my @recipients = ();
                   2014:     for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
                   2015:         $recipients[$i] =  &Apache::loncommon::aboutmewrapper(
                   2016:            &Apache::loncommon::plainname($content{'recuser'}[$i],
                   2017:                                       $content{'recdomain'}[$i]),
                   2018:               $content{'recuser'}[$i],$content{'recdomain'}[$i]).
                   2019:        ' ('.$content{'recuser'}[$i].' at '.$content{'recdomain'}[$i].') ';
                   2020:     }
                   2021:     $tolist = join(', ',@recipients);
1.59      raeburn  2022:     my ($restitle,$baseurl,$refers_to);
                   2023:     if (defined($content{'resource_title'})) {
                   2024:         $restitle = $content{'resource_title'};
                   2025:     } else {
                   2026:         if (defined($content{'baseurl'})) {
                   2027:             $restitle = &Apache::lonnet::gettitle($content{'baseurl'});
                   2028:         }
                   2029:     }
                   2030:     if (defined($content{'baseurl'})) {
                   2031:         $baseurl = &Apache::lonenc::check_encrypt($content{'baseurl'});
                   2032:     }
1.62    ! raeburn  2033:     print STDERR "baseurl is $content{'baseurl'}, title is $content{'resource_title'}, symb is $content{'symb'}, course is $content{'courseid'}\n";  
1.1       albertel 2034:     $r->print('<br /><b>'.&mt('Subject').':</b> '.$content{'subject'}.
                   2035: 	      ($folder ne 'sent'?'<br /><b>'.&mt('From').':</b> '.
                   2036: 	      &Apache::loncommon::aboutmewrapper(
                   2037: 						 &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
                   2038: 						 $content{'sendername'},$content{'senderdomain'}).' ('.
                   2039: 	      $content{'sendername'}.' at '.
                   2040: 	      $content{'senderdomain'}.') ':'<br /><b>'.&mt('To').':</b> '.
                   2041:               $tolist).
1.30      raeburn  2042: 	      ($content{'courseid'}?'<br /><b>'.&mt($crstype).':</b> '.$courseinfo{'description'}.
                   2043: 	       ($content{'coursesec'}?' ('.&mt('Section').': '.$content{'coursesec'}.')':''):'').
1.59      raeburn  2044: 	      '<br /><b>'.&mt('Time').':</b> '.$content{'time'});
                   2045:     if ($baseurl) {
                   2046:         if (defined($content{'courseid'}) && defined($env{'request.course.id'})) {
                   2047:             if ($content{'courseid'} eq $env{'request.course.id'}) {
                   2048:                 my $symblink;
1.62    ! raeburn  2049:                 my $showsymb = &Apache::lonenc::check_decrypt($symb);
        !          2050:                 my $showurl = &Apache::lonenc::check_decrypt($baseurl);
        !          2051:                 my $encrypturl = &Apache::lonnet::EXT('resource.0.encrypturl',
        !          2052:                               $showsymb,$env{'user.domain'},$env{'user.name'});
1.59      raeburn  2053:                 if ($symb) {
1.62    ! raeburn  2054:                     if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
        !          2055:                         $showsymb = &Apache::lonenc::check_encrypt($symb);
        !          2056:                     }
        !          2057:                     $symblink = '?symb='.$showsymb;
        !          2058:                 }
        !          2059:                 if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
        !          2060:                     $showurl = $baseurl;
1.59      raeburn  2061:                 }
1.62    ! raeburn  2062:                 $r->print('<br /><b>'.&mt('Refers to').':</b> <a href="'.$showurl.$symblink.'">'.$restitle.'</a>');
1.59      raeburn  2063:                 $refers_to = 1;
                   2064:             }
                   2065:         }
                   2066:         if (!$refers_to) {
                   2067:             if ($baseurl =~ m-^/enc/-) {
                   2068:                 if (defined($content{'courseid'})) {
1.62    ! raeburn  2069:                     if (!$env{'request.course.id'}) {
        !          2070:                         my $unencurl =
        !          2071:                            &Apache::lonenc::unencrypted($baseurl,
        !          2072:                                                         $content{'courseid'});
        !          2073:                         if ($unencurl ne '') {
        !          2074:                             if (&Apache::lonnet::allowed('bre',$unencurl)) {
        !          2075:                                 $r->print('<br /><b>'.&mt('Refers to').
        !          2076:                                           ':</b> <a href="'.$unencurl.'">'.
        !          2077:                                           $restitle.'</a>');
        !          2078:                             }
1.59      raeburn  2079:                         }
                   2080:                     }
                   2081:                 }
                   2082:             } else {
                   2083:                 if (&Apache::lonnet::allowed('bre',$baseurl)) {
                   2084:                     $r->print('<br /><b>'.&mt('Refers to').
                   2085:                               ':</b> <a href="'.$baseurl.
                   2086:                               '">'.$restitle.'</a>');
                   2087:                 }
                   2088:             }
                   2089:         }
                   2090:     }
                   2091:     $r->print('<p><pre>'.
1.1       albertel 2092: 	      &Apache::lontexconvert::msgtexconverted($content{'message'},1).
                   2093: 	      '</pre><hr />'.&displayresource(%content).'</p>');
1.59      raeburn  2094:     return;
1.1       albertel 2095: }
                   2096: 
                   2097: # =========================================================== Show the citation
                   2098: 
                   2099: sub displayresource {
                   2100:     my %content=@_;
                   2101: #
                   2102: # If the recipient is in the same course that the message was sent from and
                   2103: # has sufficient privileges, show "all details," else show citation
                   2104: #
                   2105:     if (($env{'request.course.id'} eq $content{'courseid'})
                   2106:      && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
1.59      raeburn  2107:         my $symb;
                   2108:         if (defined($content{'symb'})) {
                   2109:             $symb = $content{'symb'};
                   2110:         } else { 
                   2111: 	    $symb=&Apache::lonnet::symbread($content{'baseurl'});
                   2112:         }
1.1       albertel 2113: # Could not get a symb, give up
                   2114: 	unless ($symb) { return $content{'citation'}; }
                   2115: # Have a symb, can render
                   2116: 	return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
                   2117: 	    &Apache::loncommon::get_previous_attempt($symb,
                   2118: 						     $content{'sendername'},
                   2119: 						     $content{'senderdomain'},
                   2120: 						     $content{'courseid'}).
                   2121: 	    '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
                   2122: 	    &Apache::loncommon::get_student_view($symb,
                   2123: 						 $content{'sendername'},
                   2124: 						 $content{'senderdomain'},
                   2125: 						 $content{'courseid'}).
                   2126: 	    '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
                   2127: 	    &Apache::loncommon::get_student_answers($symb,
                   2128: 						    $content{'sendername'},
                   2129: 						    $content{'senderdomain'},
                   2130: 						    $content{'courseid'});
                   2131:     } elsif ($env{'user.adv'}) {
                   2132: 	return $content{'citation'};
                   2133:     }
                   2134:     return '';
                   2135: }
                   2136: 
                   2137: # ================================================================== The Header
                   2138: 
                   2139: sub header {
                   2140:     my ($r,$title,$baseurl)=@_;
                   2141:     
                   2142:     my $extra = &Apache::loncommon::studentbrowser_javascript();
                   2143:     if ($baseurl) {
1.41      albertel 2144: 	$extra .= "<base href=\"".&Apache::lonnet::absolute_url()."/$baseurl\" />";
1.1       albertel 2145:     }
                   2146:     $r->print(&Apache::loncommon::start_page('Communication and Messages',
1.38      raeburn  2147:  					$extra));
1.1       albertel 2148:     $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.38      raeburn  2149:      		(($title?$title:'Communication and Messages')));
1.1       albertel 2150: }
                   2151: 
                   2152: # ---------------------------------------------------------------- Print header
                   2153: 
                   2154: sub printheader {
                   2155:     my ($r,$url,$desc,$title,$baseurl)=@_;
                   2156:     &Apache::lonhtmlcommon::add_breadcrumb
                   2157: 	({href=>$url,
                   2158: 	  text=>$desc});
                   2159:     &header($r,$title,$baseurl);
                   2160: }
                   2161: 
                   2162: # ------------------------------------------------------------ Store the comment
                   2163: 
                   2164: sub storecomment {
                   2165:     my ($r)=@_;
                   2166:     my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
                   2167:     my $cleanmsgtxt='';
1.42      raeburn  2168:     foreach my $line (split(/[\n\r]/,$msgtxt)) {
                   2169: 	unless ($line=~/^\s*(\>|\&gt\;)/) {
                   2170: 	    $cleanmsgtxt.=$line."\n";
1.1       albertel 2171: 	}
                   2172:     }
1.29      www      2173:     my $key=&escape($env{'form.baseurl'}).'___'.time;
1.1       albertel 2174:     &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
                   2175: }
                   2176: 
                   2177: sub storedcommentlisting {
                   2178:     my ($r)=@_;
                   2179:     my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
1.29      www      2180:        '^'.&escape(&escape($env{'form.showcommentbaseurl'})));
1.1       albertel 2181:     $r->print(&Apache::loncommon::start_page('Stored Comment Listing',undef,
                   2182: 					     {'onlybody' => 1}));
                   2183:     if ((keys %msgs)[0]=~/^error\:/) {
                   2184: 	$r->print(&mt('No stored comments yet.'));
                   2185:     } else {
                   2186: 	my $found=0;
1.42      raeburn  2187: 	foreach my $key (sort(keys(%msgs))) {
                   2188: 	    $r->print("\n".$msgs{$key}."<hr />");
1.1       albertel 2189: 	    $found=1;
                   2190: 	}
                   2191: 	unless ($found) {
                   2192: 	    $r->print(&mt('No stored comments yet for this resource.'));
                   2193: 	}
                   2194:     }
                   2195: }
                   2196: 
                   2197: # ---------------------------------------------------------------- Send an email
                   2198: 
                   2199: sub sendoffmail {
                   2200:     my ($r,$folder)=@_;
                   2201:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
                   2202:     my $sendstatus='';
                   2203:     my %specialmsg_status;
                   2204:     my $numspecial = 0;
1.38      raeburn  2205:     my ($cdom,$cnum,$group);
                   2206:     if (exists($env{'form.group'})) {
                   2207:         $group = $env{'form.group'};
                   2208:     }
                   2209:     if (exists($env{'request.course.id'})) {
                   2210:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   2211:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   2212:     }
1.1       albertel 2213:     if ($env{'form.send'}) {
1.53      raeburn  2214:         if (!$env{'form.multiforward'}) { 
                   2215:             if ($group eq '') {
                   2216: 	        &printheader($r,'','Messages being sent.');
                   2217:             } else {
                   2218:                 $r->print(&groupmail_header('sending',$group));
                   2219:             }
1.38      raeburn  2220:         }
1.1       albertel 2221: 	$r->rflush();
                   2222: 	my %content=();
                   2223: 	undef %content;
                   2224: 	if ($env{'form.forwid'}) {
                   2225: 	    my $msgid=$env{'form.forwid'};
                   2226: 	    my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
                   2227: 	    %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
                   2228: 	    &statuschange($msgid,'forwarded',$folder);
                   2229: 	    $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
                   2230: 		$content{'message'};
                   2231: 	}
                   2232: 	if ($env{'form.replyid'}) {
                   2233: 	    my $msgid=$env{'form.replyid'};
                   2234: 	    my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
                   2235: 	    %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
                   2236: 	    &statuschange($msgid,'replied',$folder);
                   2237: 	}
1.13      albertel 2238: 
1.35      albertel 2239: 	my @to =
1.37      raeburn  2240: 	    &Apache::loncommon::get_env_multiple('form.selectedusers_forminput');
1.25      foxr     2241: 	my $mode = $env{'form.sendmode'};
                   2242: 
1.13      albertel 2243: 	my %toaddr;
1.35      albertel 2244: 	if (@to) {
                   2245: 	    foreach my $dest (@to) {
1.27      albertel 2246: 		my ($user,$domain) = split(/:/, $dest);
1.25      foxr     2247: 		if (($user ne '') && ($domain ne '')) {
                   2248: 		    my $address = $user.":".$domain; # How the code below expects it.
                   2249: 		    $toaddr{$address} = '';
                   2250: 		}
                   2251: 	    }
                   2252: 	}
                   2253: 
1.1       albertel 2254: 	if ($env{'form.sendmode'} eq 'group') {
1.25      foxr     2255: 	     foreach my $address (keys(%env)) {
                   2256: 	 	if ($address=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
                   2257: 	 	    $toaddr{$1}='';
                   2258: 	 	}
1.1       albertel 2259: 	    }
                   2260: 	} elsif ($env{'form.sendmode'} eq 'upload') {
1.13      albertel 2261: 	    foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
1.43      raeburn  2262:                 my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/);
1.1       albertel 2263: 		if ($txt) {
1.43      raeburn  2264:                     $rec =~ s/^\s+//;
1.44      raeburn  2265:                     $rec =~ s/\s+$//;
1.1       albertel 2266: 		    $toaddr{$rec}.=$txt."\n";
                   2267: 		}
                   2268: 	    }
                   2269: 	} else {
1.25      foxr     2270: 	    if (($env{'form.recuname'} ne '') && ($env{'form.recdomain'} ne '')) {
                   2271: 		$toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
                   2272: 	    }
1.1       albertel 2273: 	}
                   2274: 	if ($env{'form.additionalrec'}) {
1.42      raeburn  2275: 	    foreach my $rec (split(/\,/,$env{'form.additionalrec'})) {
1.43      raeburn  2276: 		my ($auname,$audom)=split(/:/,$rec);
1.25      foxr     2277: 		if (($auname ne "") && ($audom ne "")) {
                   2278: 		    $toaddr{$auname.':'.$audom}='';
                   2279: 		}
1.1       albertel 2280: 	    }
                   2281: 	}
                   2282: 
                   2283:         my $savemsg;
                   2284:         my $msgtype;
                   2285:         my %sentmessage;
1.7       albertel 2286:         my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'},
                   2287: 							 undef,1);
1.1       albertel 2288:         if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
                   2289:             (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                   2290: 	     || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                   2291: 					 '/'.$env{'request.course.sec'})
                   2292: 	     )) {
                   2293:             $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
                   2294:             $msgtype = 'critical';
                   2295:         } else {
                   2296:             $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
                   2297:         }
                   2298: 	
1.13      albertel 2299: 	foreach my $address (sort(keys(%toaddr))) {
                   2300: 	    my ($recuname,$recdomain)=split(/\:/,$address);
1.1       albertel 2301:             my $msgtxt = $savemsg;
1.13      albertel 2302: 	    if ($toaddr{$address}) { $msgtxt.='<hr />'.$toaddr{$address}; }
1.12      albertel 2303: 	    my @thismsg;
1.60      raeburn  2304: 	    if ($msgtype eq 'critical') {
                   2305: 		$r->print(&mt('Sending critical message').' '.
                   2306:                               $recuname.':'.$recdomain.': ');
1.13      albertel 2307: 		@thismsg=
                   2308: 		    &Apache::lonmsg::user_crit_msg($recuname,$recdomain,
                   2309: 						   $msgsubj,$msgtxt,
                   2310: 						   $env{'form.sendbck'},
                   2311: 						   $env{'form.permanent'},
                   2312: 						   \$sentmessage{$address});
1.1       albertel 2313: 	    } else {
1.14      albertel 2314: 		$r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': ');
1.13      albertel 2315: 		@thismsg=
                   2316: 		    &Apache::lonmsg::user_normal_msg($recuname,$recdomain,
                   2317: 						     $msgsubj,$msgtxt,
                   2318: 						     $content{'citation'},
                   2319: 						     undef,undef,
                   2320: 						     $env{'form.permanent'},
                   2321: 						     \$sentmessage{$address});
1.1       albertel 2322:             }
                   2323: 	    if (($env{'request.course.id'}) && (($msgtype eq 'critical') || 
                   2324:                                          ($env{'form.sendmode'} eq 'group'))) {
1.12      albertel 2325: 	        $specialmsg_status{$recuname.':'.$recdomain} =
                   2326: 		    join(' ',@thismsg);
                   2327: 		foreach my $result (@thismsg) {
1.60      raeburn  2328: 		    if ($result eq 'ok' || $result eq 'con_delayed') {
1.12      albertel 2329: 			$numspecial++;
                   2330: 		    }
                   2331: 		}
1.1       albertel 2332: 	    }
1.12      albertel 2333: 	    $sendstatus.=' '.join(' ',@thismsg);
1.1       albertel 2334: 	}
                   2335:         if (($env{'request.course.id'}) && (($env{'form.sendmode'} eq 'group')
                   2336:                                               || ($msgtype eq 'critical'))) {
                   2337:             my $subj_prefix;
                   2338:             if ($msgtype eq 'critical') {
                   2339:                 $subj_prefix = 'Critical.';
                   2340:             } else {
                   2341:                 $subj_prefix = 'Broadcast.';
                   2342:             }
                   2343:             my ($specialmsgid,$specialresult);
1.29      www      2344:             my $course_str = &escape('['.$cnum.':'.$cdom.']');
1.1       albertel 2345: 
                   2346:             if ($numspecial) {
                   2347:                 $specialresult = &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
                   2348:                     ' '.$course_str,$savemsg,undef,undef,undef,
                   2349:                     undef,undef,\$specialmsgid);
1.29      www      2350:                 $specialmsgid = &unescape($specialmsgid);
1.1       albertel 2351:             }
                   2352:             if ($specialresult eq 'ok') {
                   2353:                 my $record_sent;
1.13      albertel 2354:                 my @recusers;
                   2355:                 my @recudoms;
                   2356:                 my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
1.29      www      2357: 		    split(/\:/,&unescape($specialmsgid));
1.13      albertel 2358: 
1.1       albertel 2359:                 foreach my $recipient (sort(keys(%toaddr))) {
                   2360:                     if ($specialmsg_status{$recipient} eq 'ok') {
                   2361:                         my $usersubj = $subj_prefix.'['.$recipient.']';
                   2362:                         my $usermsgid = 
                   2363: 			    &Apache::lonmsg::buildmsgid($stamp,$usersubj,
                   2364: 							$msgname,$msgdom,
                   2365: 							$msgcount,$context,
                   2366: 							$pid);
                   2367:                         &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
                   2368:                                              ' ['.$recipient.']',$msgsubj,undef,
                   2369:                         undef,undef,undef,$usermsgid,undef,undef,$specialmsgid);
1.13      albertel 2370:                         my ($uname,$udom) = split(/:/,$recipient);
1.1       albertel 2371:                         push(@recusers,$uname);
                   2372:                         push(@recudoms,$udom);
                   2373:                     }
                   2374:                 }
                   2375:                 if (@recusers) {
                   2376:                     my $specialmessage;
1.13      albertel 2377:                     my $sentsubj = 
                   2378: 			$subj_prefix.' ('.$numspecial.' sent) '.$msgsubj;
1.1       albertel 2379:                     $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
                   2380:                     my $sentmsgid = 
                   2381: 			&Apache::lonmsg::buildmsgid($stamp,$sentsubj,$msgname,
                   2382: 						    $msgdom,$msgcount,$context,
                   2383: 						    $pid);
                   2384:                     ($specialmsgid,$specialmessage) = &Apache::lonmsg::packagemsg($msgsubj,$savemsg,
                   2385:                             undef,undef,undef,\@recusers,\@recudoms,$sentmsgid);
                   2386:                     $record_sent = &Apache::lonmsg::store_sent_mail($specialmsgid,$specialmessage);
                   2387:                 }
                   2388:             } else {
                   2389:                 &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');
                   2390:             }
                   2391:         }
                   2392:     } else {
                   2393: 	&printheader($r,'','No messages sent.'); 
                   2394:     }
1.53      raeburn  2395:     if (!$env{'form.multiforward'}) { 
                   2396:         if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
                   2397: 	    $r->print('<br /><span class="LC_success">'.&mt('Completed.').
                   2398:                       '</span>');
                   2399: 	    if ($env{'form.displayedcrit'}) {
                   2400: 	        &discrit($r);
                   2401:             }
                   2402:             if ($group ne '') {
                   2403:                 $r->print(&groupmail_sent($group,$cdom,$cnum)); 
                   2404: 	    } else {
                   2405: 	        &Apache::loncommunicate::menu($r);
                   2406: 	    }
                   2407:         } else {
                   2408: 	    $r->print('<p><span class="LC_error">'.&mt('Could not deliver message').'</span> '.
                   2409: 		  &mt('Please use the browser "Back" button and correct the recipient addresses '."($sendstatus)").'</p>');
1.38      raeburn  2410:         }
1.1       albertel 2411:     }
1.53      raeburn  2412:     return $sendstatus;
1.1       albertel 2413: }
                   2414: 
                   2415: # ===================================================================== Handler
                   2416: 
                   2417: sub handler {
                   2418:     my $r=shift;
                   2419: 
                   2420: # ----------------------------------------------------------- Set document type
                   2421:     
                   2422:     &Apache::loncommon::content_type($r,'text/html');
                   2423:     $r->send_http_header;
                   2424:     
                   2425:     return OK if $r->header_only;
                   2426:     
                   2427: # --------------------------- Get query string for limited number of parameters
                   2428:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   2429:         ['display','replyto','forward','markread','markdel','markunread',
                   2430:          'sendreply','compose','sendmail','critical','recname','recdom',
                   2431:          'recordftf','sortedby','block','folder','startdis','interdis',
1.53      raeburn  2432: 	 'showcommentbaseurl','dismode','group','subject','text','ref',
                   2433:          'msgstatus']);
1.1       albertel 2434:     $sqs='&sortedby='.$env{'form.sortedby'};
                   2435: 
                   2436: # ------------------------------------------------------ They checked for email
                   2437:     unless ($env{'form.block'}) {
                   2438:         &Apache::lonnet::put('email_status',{'recnewemail'=>0});
                   2439:     }
                   2440: 
                   2441: # ----------------------------------------------------------------- Breadcrumbs
                   2442: 
                   2443:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                   2444:     &Apache::lonhtmlcommon::add_breadcrumb
                   2445:         ({href=>"/adm/communicate",
                   2446:           text=>"Communication/Messages",
                   2447:           faq=>12,bug=>'Communication Tools',});
                   2448: 
                   2449: # ------------------------------------------------------------------ Get Folder
                   2450: 
                   2451:     my $folder=$env{'form.folder'};
                   2452:     unless ($folder) { 
                   2453: 	$folder=''; 
                   2454:     } else {
1.29      www      2455: 	$sqs.='&folder='.&escape($folder);
1.1       albertel 2456:     }
                   2457: # ------------------------------------------------------------ Get Display Mode
                   2458: 
                   2459:     my $dismode=$env{'form.dismode'};
                   2460:     unless ($dismode) { 
                   2461: 	$dismode=''; 
                   2462:     } else {
1.48      albertel 2463: 	$sqs.='&amp;dismode='.&escape($dismode);
1.1       albertel 2464:     }
                   2465: 
                   2466: # --------------------------------------------------------------------- Display
1.53      raeburn  2467:     my $msgstatus = $env{'form.msgstatus'};
1.1       albertel 2468:     $startdis=$env{'form.startdis'};
1.53      raeburn  2469:     if ($startdis ne '') {
                   2470:         $startdis--;
                   2471:     }
1.1       albertel 2472:     unless ($startdis) { $startdis=0; }
                   2473: 
                   2474:     if ($env{'form.firstview'}) {
                   2475: 	$startdis=0;
                   2476:     }
                   2477:     if ($env{'form.lastview'}) {
                   2478: 	$startdis=-1;
                   2479:     }
                   2480:     if ($env{'form.prevview'}) {
                   2481: 	$startdis--;
                   2482:     }
                   2483:     if ($env{'form.nextview'}) {
                   2484: 	$startdis++;
                   2485:     }
                   2486:     my $postedstartdis=$startdis+1;
                   2487:     $sqs.='&startdis='.$postedstartdis;
                   2488: 
                   2489: # --------------------------------------------------------------- Render Output
                   2490: 
                   2491:     if ($env{'form.display'}) {
1.53      raeburn  2492: 	&displaymessage($r,$env{'form.display'},$folder,$msgstatus);
1.1       albertel 2493:     } elsif ($env{'form.replyto'}) {
                   2494: 	&compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode);
                   2495:     } elsif ($env{'form.confirm'}) {
                   2496: 	&printheader($r,'','Confirmed Receipt');
1.36      albertel 2497: 	my $replying = 0;
1.42      raeburn  2498: 	foreach my $envkey (keys(%env)) {
                   2499: 	    if ($envkey=~/^form\.rec\_(.*)$/) {
1.1       albertel 2500: 		$r->print('<b>'.&mt('Confirming Receipt').':</b> '.
                   2501: 			  &Apache::lonmsg::user_crit_received($1).'<br>');
                   2502: 	    }
1.42      raeburn  2503: 	    if ($envkey=~/^form\.reprec\_(.*)$/) {
1.1       albertel 2504: 		my $msgid=$1;
                   2505: 		$r->print('<b>'.&mt('Confirming Receipt').':</b> '.
                   2506: 			  &Apache::lonmsg::user_crit_received($msgid).'<br>');
                   2507: 		&compout($r,'','','',$msgid);
1.36      albertel 2508: 		$replying = 1;
1.1       albertel 2509: 	    }
                   2510: 	}
1.36      albertel 2511: 	if (!$replying) {
                   2512: 	    &discrit($r);
                   2513: 	}
1.1       albertel 2514:     } elsif ($env{'form.critical'}) {
                   2515: 	&printheader($r,'','Displaying Critical Messages');
                   2516: 	&discrit($r);
                   2517:     } elsif ($env{'form.forward'}) {
                   2518: 	&compout($r,$env{'form.forward'},undef,undef,undef,$folder);
                   2519:     } elsif ($env{'form.markdel'}) {
                   2520: 	&printheader($r,'','Deleted Message');
1.9       albertel 2521: 	my ($result,$msg) = 
                   2522: 	    &statuschange($env{'form.markdel'},'deleted',$folder);
                   2523: 	if (!$result) {
1.10      albertel 2524: 	    $r->print('<p class="LC_error">'.
                   2525: 		      &mt('Failed to delete the message.').'</p>'.
1.9       albertel 2526: 		      '<p class="LC_error">'.$msg."</p>\n");
                   2527: 	}
1.1       albertel 2528: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  2529: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
                   2530:     } elsif ($env{'form.markedaction'} eq 'markedforward') {
                   2531:         my $total = 0;
                   2532:         my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
                   2533:         foreach my $msgid (@to_forward) {
                   2534:             &statuschange(&unescape($msgid),'forwarded',$folder);
                   2535:             $total ++;
                   2536:         }
                   2537:         if ($total > 0) {
                   2538:             &compout($r,undef,undef,undef,undef,$folder,$dismode,$total);
                   2539:         }
                   2540:     } elsif ($env{'form.markedaction'} eq 'markedread') {
                   2541:         my $total = 0;
                   2542:         my @to_markread = &Apache::loncommon::get_env_multiple('form.delmark');
                   2543:         foreach my $msgid (@to_markread) {
                   2544:             &statuschange(&unescape($msgid),'read',$folder);
                   2545:             $total ++;
                   2546:         }
                   2547:         &printheader($r,'','Marked Messages Read');
                   2548:         $r->print(&mt('Marked [_1] message(s) read',$total).'<p>');
                   2549:         &Apache::loncommunicate::menu($r);
                   2550:         &disall($r,($folder?$folder:$dismode),$msgstatus);
                   2551:     } elsif ($env{'form.markedaction'} eq 'markedunread') {
                   2552:         my $total = 0;
                   2553:         my @to_markunread = &Apache::loncommon::get_env_multiple('form.delmark');
                   2554:         foreach my $msgid (@to_markunread) {
                   2555:             &statuschange(&unescape($msgid),'new',$folder);
                   2556:             $total ++;
                   2557:         }
                   2558:         &printheader($r,'','Marked Messages Unread');
                   2559:         $r->print(&mt('Marked [_1] message(s) unread',$total).'<p>');
                   2560:         &Apache::loncommunicate::menu($r);
                   2561:         &disall($r,($folder?$folder:$dismode),$msgstatus);
                   2562:     } elsif ($env{'form.markedaction'} eq 'markedmove') {
                   2563:         my $destfolder = $env{'form.movetofolder'};
                   2564:         my %gotfolders = &Apache::lonmsg::get_user_folders();
                   2565:         &printheader($r,'','Moved Messages');
                   2566:         if (!defined($gotfolders{$destfolder})) {
                   2567:             $r->print(&mt('Destination folder [_1] is not a valid folder',
                   2568:                       $destfolder));
                   2569:         } else {
                   2570: 	    my ($total,$failed,@failed_msg)=(0,0);
                   2571:             my @to_move = &Apache::loncommon::get_env_multiple('form.delmark');
                   2572:             foreach my $msgid (@to_move) {
                   2573: 	        my ($result,$msg) = &movemsg(&unescape($msgid),$folder,
                   2574: 			                     $env{'form.movetofolder'});
                   2575: 	        if ($result) {
1.9       albertel 2576: 		    $total++;
1.53      raeburn  2577: 	        } else {
1.9       albertel 2578: 		    $failed++;
                   2579: 		    push(@failed_msg,$msg);
1.53      raeburn  2580: 	        }
1.1       albertel 2581: 	    }
1.53      raeburn  2582: 	    if ($failed) {
                   2583: 	        $r->print('<p class="LC_error">
1.10      albertel 2584:                           '.&mt('Failed to move [_1] message(s)',$failed).
                   2585: 		      '</p>');
1.53      raeburn  2586: 	        $r->print('<p class="LC_error">'.
                   2587: 	   	          join("</p>\n<p class=\"LC_error\">",@failed_msg).
                   2588: 		          "</p>\n");
                   2589: 	    }
                   2590: 	    $r->print(&mt('Moved [_1] message(s)',$total).'<p>');
                   2591:         }
1.1       albertel 2592: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  2593: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
                   2594:     } elsif ($env{'form.markedaction'} eq 'markeddel') {
1.9       albertel 2595: 	my ($total,$failed,@failed_msg)=(0,0);
1.53      raeburn  2596:         my @to_delete = &Apache::loncommon::get_env_multiple('form.delmark');
                   2597:         foreach my $msgid (@to_delete) {
                   2598: 	    my ($result,$msg) = &statuschange(&unescape($msgid),'deleted', 
                   2599: 				              $folder);
                   2600: 	    if ($result) {
                   2601: 	        $total++;
                   2602: 	    } else {
                   2603: 	        $failed++;
                   2604: 		push(@failed_msg,$msg);
1.1       albertel 2605: 	    }
                   2606: 	}
                   2607: 	&printheader($r,'','Deleted Messages');
1.9       albertel 2608: 	if ($failed) {
                   2609: 	    $r->print('<p class="LC_error">
1.10      albertel 2610:                           '.&mt('Failed to delete [_1] message(s)',$failed).
                   2611: 		      '</p>');
1.9       albertel 2612: 	    $r->print('<p class="LC_error">'.
                   2613: 		      join("</p>\n<p class=\"LC_error\">",@failed_msg).
                   2614: 		      "</p>\n");
                   2615: 	}
1.10      albertel 2616: 	$r->print(&mt('Deleted [_1] message(s)',$total).'<p>');
1.1       albertel 2617: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  2618: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
1.1       albertel 2619:     } elsif ($env{'form.markunread'}) {
                   2620: 	&printheader($r,'','Marked Message as Unread');
                   2621: 	&statuschange($env{'form.markunread'},'new');
                   2622: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  2623: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
1.1       albertel 2624:     } elsif ($env{'form.compose'}) {
                   2625: 	&compout($r,'','',$env{'form.compose'});
                   2626:     } elsif ($env{'form.recordftf'}) {
                   2627: 	&facetoface($r,$env{'form.recordftf'});
                   2628:     } elsif ($env{'form.block'}) {
                   2629:         &examblock($r,$env{'form.block'});
                   2630:     } elsif ($env{'form.sendmail'}) {
1.53      raeburn  2631:         if ($env{'form.multiforward'}) {
                   2632:             &printheader($r,'','Messages being sent.');
                   2633:             my $fixed_subj = $env{'form.subject'};
                   2634:             my $suffix=&Apache::lonmsg::foldersuffix($folder);
                   2635:             my (%sendresult,%forwardok,%forwardfail,$fwdcount);
                   2636:             my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
                   2637:             foreach my $item (@to_forward) {
                   2638:                 my $msgid=&unescape($item);
                   2639:                 my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
                   2640:                 my %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
                   2641:                 if ($env{'form.showorigsubj'}) {
                   2642:                     $env{'form.subject'} = $fixed_subj.$content{'subject'};
                   2643:                 } else {
                   2644:                     $env{'form.subject'} = '';
                   2645:                 }
                   2646:                 my $uname = $content{'sendername'};
                   2647:                 my $udom = $content{'senderdomain'};
                   2648:                 &statuschange($msgid,'forwarded',$folder);
                   2649:                 if ($env{'form.showorigsender'}) {
                   2650:                     $env{'form.message'} = $env{'form.msgheader'}.' '.
                   2651:                         &Apache::loncommon::plainname($uname,$udom).' ('.
                   2652:                                            $uname.':'.$udom.')';
                   2653:                 }
                   2654:                 $env{'form.message'} .= "\n\n-- Forwarded message --\n\n".
                   2655:                                         $content{'message'};
                   2656:                 $fwdcount ++;
                   2657:                 $r->print($fwdcount.': '); 
                   2658:                 $sendresult{$msgid} = &sendoffmail($r,$folder);
                   2659:                 $r->print('<br />');
                   2660:             }
                   2661:             foreach my $key (keys(%sendresult)) {
                   2662:                 if ($sendresult{$key} =~/^(\s*(?:ok|con_delayed)\s*)*$/) {
                   2663:                     $forwardok{$key} = $sendresult{$key};
                   2664:                 } else {
                   2665:                     $forwardfail{$key} = $sendresult{$key}; 
                   2666:                 }
                   2667:             }
                   2668:             if (keys(%forwardok) > 0) {
                   2669:                 my $count = keys(%forwardok);
                   2670:                 $r->print('<br /><span class="LC_success">'.
                   2671:                           &mt('[quant,_1,message] forwarded.',$count).
                   2672:                           '</span>');
                   2673:             }
                   2674:             if (keys(%forwardfail) > 0) {
                   2675:                 my $count = keys(%forwardfail);
                   2676:                 $r->print('<p><span class="LC_error">'.
                   2677:                           &mt('Could not forward [quant,_1,message].',$count).
                   2678:                           '</span> ');
                   2679:                 foreach my $key (keys(%forwardfail)) {
                   2680:                     $r->print(&mt('Could not deliver forwarded message.').'</span> '.
                   2681:                               &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.').<br /><br />');
                   2682:                 }
                   2683:             }
                   2684:             &Apache::loncommunicate::menu($r);
                   2685:         } else {
                   2686: 	    &sendoffmail($r,$folder);
                   2687:         }
1.1       albertel 2688: 	if ($env{'form.storebasecomment'}) {
                   2689: 	    &storecomment($r);
1.38      raeburn  2690:         }
1.1       albertel 2691: 	if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
1.38      raeburn  2692: 	        &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
1.1       albertel 2693: 				      $env{'course.'.$env{'request.course.id'}.'.domain'},
                   2694: 				      'Course_Announcements',
                   2695: 				      $env{'form.subject'},
                   2696: 				      $env{'form.message'},'/adm/communicate','public');
                   2697: 	}
1.38      raeburn  2698: 	if ((!exists($env{'form.group'})) && (!$env{'form.displayedcrit'})) {
1.53      raeburn  2699: 	    &disall($r,($folder?$folder:$dismode),$msgstatus);
1.36      albertel 2700: 	}
1.1       albertel 2701:     } elsif ($env{'form.newfolder'}) {
                   2702: 	&printheader($r,'','New Folder');
1.46      raeburn  2703:         my $showfolder = $env{'form.newfolder'};
                   2704: 	my ($makeresult,$warning) = &makefolder($env{'form.newfolder'});
                   2705:         if ($makeresult eq 'ok') {
                   2706:             $r->print(&mt('Mail folder "[_1]" created.',$showfolder).'<br />');
                   2707:         } else {
                   2708:             $r->print(&mt('Creation failed.').' '.$makeresult.'<br />'.
                   2709:                       $warning);
                   2710:             $showfolder = $folder;
                   2711:         }
                   2712:         &Apache::loncommunicate::menu($r);
1.53      raeburn  2713: 	&disall($r,$showfolder,$msgstatus);
1.1       albertel 2714:     } elsif ($env{'form.showcommentbaseurl'}) {
                   2715: 	&storedcommentlisting($r);
1.46      raeburn  2716:     } elsif ($env{'form.folderaction'} eq 'delete') {
                   2717:         &printheader($r,'','Deleted Folder');
                   2718:         my $showfolder = '';
                   2719:         my $delresult = &deletefolder($folder);
                   2720:         if ($delresult eq 'ok') {
                   2721:             $r->print(&mt('Mail folder "[_1]" deleted.',$folder).'<br />');
                   2722:         } else {
                   2723:             $r->print(&mt('Deletion failed.').' '.$delresult.'<br />');
                   2724:             $showfolder = $folder;
                   2725:         }
                   2726:         &Apache::loncommunicate::menu($r);
1.53      raeburn  2727:         &disall($r,$showfolder,$msgstatus);
1.46      raeburn  2728:     } elsif ($env{'form.folderaction'} eq 'rename') {
                   2729:         &printheader($r,'','Renamed Folder');
                   2730:         my $showfolder = $env{'form.renamed'};
                   2731:         my $renresult = &renamefolder($folder);
                   2732:         if ($renresult eq 'ok') {
                   2733:             $r->print(&mt('Mail folder "[_1]" renamed "[_2]".',$folder,$showfolder).'<br />');
                   2734:         } else {
                   2735:             $r->print(&mt('Renaming failed.').' '.$renresult.'<br />');
                   2736:             $showfolder = $folder;
                   2737:         }
                   2738:         &Apache::loncommunicate::menu($r);
1.53      raeburn  2739:         &disall($r,$showfolder,$msgstatus);
1.1       albertel 2740:     } else {
                   2741: 	&printheader($r,'','Display All Messages');
1.44      raeburn  2742: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  2743: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
1.1       albertel 2744:     }
                   2745:     $r->print(&Apache::loncommon::end_page());
                   2746:     return OK;
                   2747: }
                   2748: # ================================================= Main program, reset counter
                   2749: 
                   2750: =pod
                   2751: 
                   2752: =back
                   2753: 
                   2754: =cut
                   2755: 
                   2756: 1; 
                   2757: 
                   2758: __END__
                   2759: 

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