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

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

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