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

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

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