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

1.158     raeburn     1: # The LearningOnline Network with CAPA
1.1       albertel    2: # Routines for messaging display
                      3: #
1.181.2.1! raeburn     4: # $Id: lonmsgdisplay.pm,v 1.181 2015/06/09 21:22:56 damieng 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/';
1.157     raeburn   113: use LONCAPA qw(:DEFAULT :match);
1.1       albertel  114: 
                    115: # Querystring component with sorting type
1.134     raeburn   116: my $sqs='';
                    117: my $startdis='';
1.1       albertel  118: 
                    119: # ============================================================ List all folders
                    120: 
                    121: sub folderlist {
1.53      raeburn   122:     my ($folder,$msgstatus) = @_;
1.181     damieng   123:     my %html_lt = &Apache::lonlocal::texthash(
1.46      raeburn   124:                 actn => 'Action',
                    125:                 fold => 'Folder',
                    126:                 show => 'Show',
1.53      raeburn   127:                 status => 'Message Status',
1.46      raeburn   128:                 go   => 'Go',
1.181     damieng   129: 
                    130:     );
                    131:     &html_escape(\%html_lt);
                    132:     my %js_lt = &Apache::lonlocal::texthash(
1.50      raeburn   133:                 nnff => 'New Name for Folder',
                    134:                 newn => 'New Name',
1.168     raeburn   135:                 fmnb => 'Folder may not be renamed as it is a folder provided by the system.',
                    136:                 asth => 'Requested name already in use for a system-provided or user-defined folder.',
1.50      raeburn   137: 
1.46      raeburn   138:     );
1.181     damieng   139:     &js_escape(\%js_lt);
1.46      raeburn   140: 
1.120     kaisler   141: 	# set se lastvisit for the new mail check in the toplevel menu
                    142: 	&Apache::lonnet::appenv({'user.mailcheck.lastvisit'=>time});
                    143: 
1.46      raeburn   144:     my %actions = &Apache::lonlocal::texthash(
                    145:                                 view => 'View Folder',
                    146:                                 rename => 'Rename Folder',
                    147:                                 delete => 'Delete Folder',
                    148:     );
                    149:     $actions{'select_form_order'} = ['view','rename','delete'];
                    150: 
1.141     bisitz    151:     my %statushash = &Apache::lonlocal::texthash(&get_msgstatus_types());
1.53      raeburn   152: 
                    153:     $statushash{'select_form_order'} = ['','new','read','replied','forwarded'];
                    154: 
1.46      raeburn   155:     my %permfolders = &get_permanent_folders();
                    156:     my $permlist = join("','",sort(keys(%permfolders)));
                    157:     my ($permlistkeys,$permlistvals);
                    158:     foreach my $key (sort(keys(%permfolders))) {
                    159:         $permlistvals .= $permfolders{$key}."','";
                    160:         $permlistkeys .= $key."','";
                    161:     }
                    162:     $permlistvals =~ s/','$//;
                    163:     $permlistkeys =~ s/','$//;
                    164:     my %gotfolders = &Apache::lonmsg::get_user_folders();
                    165:     my %userfolders;
                    166: 
                    167:     foreach my $key (keys(%gotfolders)) {
1.54      albertel  168:         $key =~ s/(['"])/\$1/g; #' stupid emacs
1.46      raeburn   169:         $userfolders{$key} = $key;
                    170:     }
                    171:     my @userorder = sort(keys(%userfolders));
                    172:     my %formhash = (%permfolders,%userfolders);
                    173:     my $folderlist = join("','",@userorder);
                    174:     $folderlist .= "','".$permlistvals;
                    175: 
1.53      raeburn   176:     $formhash{'select_form_order'} = ['','critical',@userorder,'sent','trash'];
1.46      raeburn   177:     my $output = qq|<script type="text/javascript">
1.127     bisitz    178: // <![CDATA[
1.46      raeburn   179: function folder_choice(targetform,caller) {
                    180:     var permfolders_keys = new Array('$permlistkeys');
                    181:     var permfolders_vals = new Array('$permlistvals');
                    182:     var allfolders = new Array('$folderlist');
                    183:     if (caller == 'change') {
                    184:         if (targetform.folderaction.options[targetform.folderaction.selectedIndex].value == 'rename') {
                    185:             for (var i=0; i<permfolders_keys.length; i++) {
                    186:                 if (permfolders_keys[i] == targetform.folder.value) {
1.181     damieng   187:                     alert("'"+permfolders_vals[i]+"' -- $js_lt{'fmnb'}");
1.46      raeburn   188:                     return;
                    189:                 }
                    190:             }
1.181     damieng   191:             var foldername=prompt('$js_lt{'nnff'}','$js_lt{'newn'}');
1.46      raeburn   192:             if (foldername) {
                    193:                 targetform.renamed.value=foldername;
                    194:                 for (var i=0; i<allfolders.length; i++) {
                    195:                     if (allfolders[i] == foldername) {
1.181     damieng   196:                         alert("'"+foldername+"' $js_lt{'asth'}");
1.46      raeburn   197:                         return;
                    198:                     }
                    199:                 }
                    200:                 targetform.submit();
                    201:             }
                    202:         }
                    203:         else {
                    204:             targetform.submit();
                    205:         }
                    206:     }
                    207:     if (caller == 'new') {
                    208:         var newname=targetform.newfolder.value;
                    209:         if (newname) {
                    210:             for (var i=0; i<allfolders.length; i++) {
                    211:                 if (allfolders[i] == newname) {
1.181     damieng   212:                     alert("'"+newname+"' -- $js_lt{'asth'}");
1.46      raeburn   213:                     return;
                    214:                 }
                    215:             }
                    216:             targetform.submit();
                    217:         }
                    218:     }
                    219: }
1.127     bisitz    220: // ]]>
1.46      raeburn   221: </script>|;
1.57      albertel  222:     my %show = ('select_form_order' => [10,20,50,100,200],
                    223: 		map {$_=>$_} (10,20,50,100,200));
1.141     bisitz    224: 
1.46      raeburn   225:     $output .= '
                    226: <form method="post" action="/adm/email" name="folderlist">
1.162     bisitz    227:    <div class="LC_columnSection"><fieldset>
                    228:    <legend>'.&mt('Folder Actions').'</legend>
1.148     bisitz    229:    <table border="0" cellspacing="2" cellpadding="8">
1.46      raeburn   230:     <tr>
1.181     damieng   231:      <td><b>'.$html_lt{'fold'}.'</b><br />'."\n".
1.153     raeburn   232:          &Apache::loncommon::select_form($folder,'folder',\%formhash).'
1.46      raeburn   233:      </td>
1.181     damieng   234:      <td><b>'.$html_lt{'show'}.'</b><br />'."\n".
1.57      albertel  235:          &Apache::loncommon::select_form($env{'form.interdis'},'interdis',
1.153     raeburn   236: 					 \%show).'
1.46      raeburn   237:      </td>
1.181     damieng   238:      <td><b>'.$html_lt{'status'}.'</b><br />'."\n".
1.153     raeburn   239:        &Apache::loncommon::select_form($msgstatus,'msgstatus',\%statushash).'
1.53      raeburn   240:      </td>
1.169     bisitz    241:      <td style="padding-right: 40px;">
1.181     damieng   242:          <b>'.$html_lt{'actn'}.'</b><br />'."\n".'
1.148     bisitz    243:          <span class="LC_nobreak">'.
1.153     raeburn   244:          &Apache::loncommon::select_form('view','folderaction',\%actions).
1.181     damieng   245:          ' <input type="button" value="'.$html_lt{'go'}.
1.148     bisitz    246:          '" onclick="javascript:folder_choice(this.form,'."'change'".');" />
                    247:          </span>
                    248:      </td>
1.169     bisitz    249:      <td style="border-left: 1px solid;padding-left: 40px;">
                    250:          <b>'.&mt('New Folder').'</b><br />'."\n".'
1.148     bisitz    251:          <span class="LC_nobreak">
                    252:          <input type="text" size="15" name="newfolder" value="" />
1.181     damieng   253:          <input type="button" value="'.$html_lt{'go'}.
1.148     bisitz    254:          '" onclick="javascript:folder_choice(this.form,'."'new'".');" />
                    255:          </span>
1.46      raeburn   256:      </td>
                    257:     </tr>
                    258:    </table>
1.162     bisitz    259:    </fieldset></div>
1.148     bisitz    260: '."\n".
1.1       albertel  261:     '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" />'.
1.46      raeburn   262:     '<input type="hidden" name="renamed" value="" />'.
1.53      raeburn   263:         ($folder=~/^critical/?'</form>':'');
1.46      raeburn   264:     return $output;
                    265: }
                    266: 
                    267: sub get_permanent_folders {
1.47      albertel  268:     my %permfolders = 
                    269: 	&Apache::lonlocal::texthash(''         => 'INBOX',
                    270: 				    'trash'    => 'TRASH',
1.173     bisitz    271: 				    'critical' => 'CRITICAL',
                    272: 				    'sent'     => 'SENT MESSAGES',
1.47      albertel  273: 				    );
1.46      raeburn   274:     return %permfolders;
1.1       albertel  275: }
                    276: 
1.53      raeburn   277: sub get_msgstatus_types {
1.141     bisitz    278:     # Don't translate here!
                    279:     my %statushash = (
                    280:         ''          => 'Any',
                    281:         'new'       => 'Unread',
                    282:         'read'      => 'Read',
                    283:         'replied'   => 'Replied to',
                    284:         'forwarded' => 'Forwarded',
1.53      raeburn   285:     );
                    286:     return %statushash;
                    287: }
                    288: 
1.1       albertel  289: sub scrollbuttons {
1.53      raeburn   290:     my ($start,$maxdis,$first,$finish,$total,$msgstatus)=@_;
1.1       albertel  291:     unless ($total>0) { return ''; }
                    292:     $start++; $maxdis++;$first++;$finish++;
1.53      raeburn   293: 
                    294:     my %statushash = &get_msgstatus_types();
                    295:     my $status;
                    296:     if ($msgstatus eq '') {
1.141     bisitz    297:         $status = 'All'; # Don't translate here!
1.53      raeburn   298:     } else {
                    299:         $status = $statushash{$msgstatus};
                    300:     }
1.140     bisitz    301:     my $output = '<b>'.&mt('Page:').'</b> ';
                    302:     if ($maxdis == 1) {
                    303:         # No buttons if only one page is displayed
                    304:         $output .= '1/1';
                    305:     } else {
                    306:         $output .=
                    307:            '<input type="submit" name="firstview" value="|&lt;" />'.
                    308:            '<input type="submit" name="prevview" value="&lt;" />'.
                    309:            ' <input type="text" size="5" name="startdis" value="'.$start.'" onchange="this.form.submit()" /> / '.$maxdis.' '.
                    310:            '<input type="submit" name="nextview" value="&gt;" />'.
                    311:            '<input type="submit" name="lastview" value="&gt;|" />';
                    312:     }
                    313:     $output .=
1.148     bisitz    314:         '<p>'
1.140     bisitz    315:        .'<b>'.&mt($status.' messages:').'</b> '
                    316:        .&mt('showing messages [_1] through [_2] of [_3].',
                    317:             $first,$finish,$total)
1.148     bisitz    318:        .'</p>'
1.140     bisitz    319:        .'</form>';
                    320: 
                    321:     return $output;
1.1       albertel  322: }
                    323: # =============================================================== Status Change
                    324: 
                    325: sub statuschange {
                    326:     my ($msgid,$newstatus,$folder)=@_;
1.3       albertel  327:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
1.1       albertel  328:     my %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
                    329:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
                    330:     unless ($status{$msgid}) { $status{$msgid}='new'; }
                    331:     unless (($status{$msgid} eq 'replied') || 
                    332:             ($status{$msgid} eq 'forwarded')) {
                    333: 	&Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
                    334:     }
                    335:     if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
                    336: 	&Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
                    337:     }
                    338:     if ($newstatus eq 'deleted') {
1.9       albertel  339: 	return &movemsg($msgid,$folder,'trash');
                    340:     }
                    341:     return ;
1.1       albertel  342: }
                    343: 
                    344: # ============================================================= Make new folder
                    345: 
                    346: sub makefolder {
1.46      raeburn   347:     my ($newfolder) = @_;
                    348:     my %permfolders = &get_permanent_folders();
                    349:     my %userfolders = &Apache::lonmsg::get_user_folders();
                    350:     my ($outcome,$warning);
                    351:     if (defined($userfolders{$newfolder})) {
                    352:         return &mt('The folder name: "[_1]" is already in use for an existing folder.',$newfolder);
                    353:     }
                    354:     foreach my $perm (keys(%permfolders)) {
                    355:         if ($permfolders{$perm} eq $newfolder) {
                    356:             return &mt('The folder name: "[_1]" is already used for one of the folders automatically generated by the system.',$newfolder);
                    357:         }
                    358:     } 
                    359:     if (&get_msgfolder_lock() eq 'ok') {
                    360:         my %counter_hash = &Apache::lonnet::get('email_folders',["\0".'idcount']);
                    361:         my $lastcount = $counter_hash{"\0".'idcount'};
                    362:         my $folder_id = $lastcount + 1;
                    363:         while (defined($userfolders{$folder_id})) {
                    364:             $folder_id ++;
                    365:         }
1.47      albertel  366:         my %folderinfo = ( id      => $folder_id,
                    367:                            created => time, );
1.46      raeburn   368:         $outcome =  
1.47      albertel  369: 	    &Apache::lonnet::put('email_folders',{$newfolder => \%folderinfo,
                    370: 						  "\0".'idcount' => $folder_id});
1.46      raeburn   371:         my $releaseresult = &release_msgfolder_lock();
                    372:         if ($releaseresult ne 'ok') {
                    373:             $warning = $releaseresult;
                    374:         }
                    375:     } else {
1.47      albertel  376:         $outcome = 
1.104     raeburn   377: 	    &mt('Error - could not obtain lock on message folders record.');
1.46      raeburn   378:     }
                    379:     return ($outcome,$warning);
1.1       albertel  380: }
                    381: 
1.46      raeburn   382: # ============================================================= Delete folder
                    383: 
                    384: sub deletefolder {
                    385:     my ($folder)=@_;
                    386:     my %permfolders = &get_permanent_folders();
                    387:     if (defined($permfolders{$folder})) {
1.172     bisitz    388:         return &mt('The folder "[_1]" may not be deleted.',$permfolders{$folder}); 
1.46      raeburn   389:     }
                    390:     my %userfolders = &Apache::lonmsg::get_user_folders();
                    391:     if (!defined($userfolders{$folder})) {
1.56      albertel  392:         return &mt('The folder "[_1]" does not exist so deletion is not required.',
1.46      raeburn   393:                    $folder);
                    394:     }
                    395:     # check folder is empty;
                    396:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
                    397:     my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
                    398:     if (@messages > 0) {
1.56      albertel  399:         return &mt('The folder "[_1]" contains messages so it may not be deleted.',$folder).
1.46      raeburn   400:                '<br />'.
                    401:                &mt('Delete or move the messages to a different folder first.');
                    402:     }
                    403:     my $delresult = &Apache::lonnet::del('email_folders',[$folder]);
                    404:     return $delresult;
                    405: }
                    406: 
                    407: sub renamefolder {
                    408:     my ($folder) = @_;
                    409:     my $newname = $env{'form.renamed'};
                    410:     my %permfolders = &get_permanent_folders();
                    411:     if ($env{'form.renamed'} eq '') {
                    412:         return &mt('The folder "[_1]" may not be renamed to "[_2]" as the new name you requested is an invalid name.',$folder,$newname);
                    413:     }
1.73      raeburn   414:     if (defined($permfolders{$folder})) {
                    415:         return &mt('The folder "[_1]" may not be renamed as it is a folder provided by the system.',$folder);
                    416:     }
1.46      raeburn   417:     if (defined($permfolders{$newname})) {
                    418:         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);
                    419:     }
                    420:     my %userfolders = &Apache::lonmsg::get_user_folders();
                    421:     if (defined($userfolders{$newname})) {
                    422:         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);
                    423:     }
                    424:     if (!defined($userfolders{$folder})) {
                    425:         return &mt('The folder "[_1]" could not be renamed to "[_2]" because the folder does not exist.',$folder,$newname);
                    426:     }
                    427:     my %folderinfo;
                    428:     if (ref($userfolders{$folder}) eq 'HASH') {
                    429:         %folderinfo = %{$userfolders{$folder}};
                    430:     } else {
1.47      albertel  431:         %folderinfo = ( id      => $folder,
                    432:                         created => $userfolders{$folder},);
1.46      raeburn   433:     }
                    434:     my $outcome =
                    435:      &Apache::lonnet::put('email_folders',{$newname => \%folderinfo});
                    436:     if ($outcome eq 'ok') {
                    437:         $outcome = &Apache::lonnet::del('email_folders',[$folder]);
                    438:     }
                    439:     return $outcome;
                    440: }
                    441: 
                    442: sub get_msgfolder_lock {
                    443:     # get lock for mail folder counter.
1.47      albertel  444:     my $lockhash = { "\0".'lock_counter' => time, };
1.46      raeburn   445:     my $tries = 0;
                    446:     my $gotlock = &Apache::lonnet::newput('email_folders',$lockhash);
                    447:     while (($gotlock ne 'ok') && $tries <3) {
                    448:         $tries ++;
1.47      albertel  449:         sleep(1);
1.46      raeburn   450:         $gotlock = &Apache::lonnet::newput('email_folders',$lockhash);
                    451:     }
                    452:     return $gotlock;
                    453: }
                    454: 
                    455: sub release_msgfolder_lock {
                    456:     #  remove lock
                    457:     my @del_lock = ("\0".'lock_counter');
                    458:     my $dellockoutcome=&Apache::lonnet::del('email_folders',\@del_lock);
                    459:     if ($dellockoutcome ne 'ok') {
                    460:         return ('<br />'.&mt('Warning: failed to release lock for counter').'<br />');
                    461:     } else {
                    462:         return 'ok';
                    463:     }
                    464: }
                    465: 
                    466: 
1.1       albertel  467: # ======================================================== Move between folders
                    468: 
                    469: sub movemsg {
                    470:     my ($msgid,$srcfolder,$trgfolder)=@_;
                    471:     if ($srcfolder eq 'new') { $srcfolder=''; }
1.3       albertel  472:     my $srcsuffix=&Apache::lonmsg::foldersuffix($srcfolder);
                    473:     my $trgsuffix=&Apache::lonmsg::foldersuffix($trgfolder);
1.9       albertel  474:     if ($srcsuffix eq $trgsuffix) {
                    475: 	return (0,&mt('Message not moved, Attempted to move message to the same folder as it already is in.'));
                    476:     }
1.1       albertel  477: 
                    478: # Copy message
                    479:     my %message=&Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid]);
1.9       albertel  480:     if (!exists($message{$msgid}) || $message{$msgid} eq '') {
1.32      albertel  481: 	if (&Apache::lonnet::error(%message)) {
1.9       albertel  482: 	    return (0,&mt('Message not moved, A network error occurred.'));
                    483: 	} else {
                    484: 	    return (0,&mt('Message not moved as the message is no longer in the source folder.'));
                    485: 	}
                    486:     }
                    487: 
                    488:     my $result =&Apache::lonnet::put('nohist_email'.$trgsuffix,
                    489: 				     {$msgid => $message{$msgid}});
1.32      albertel  490:     if (&Apache::lonnet::error($result)) {
1.9       albertel  491: 	return (0,&mt('Message not moved, A network error occurred.'));
                    492:     }
1.1       albertel  493: 
                    494: # Copy status
                    495:     unless ($trgfolder eq 'trash') {
1.9       albertel  496:        	my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]);
                    497: 	# a non-existant status is the mark of an unread msg
1.32      albertel  498: 	if (&Apache::lonnet::error(%status)) {
1.9       albertel  499: 	    return (0,&mt('Message copied to new folder but status was not, A network error occurred.'));
                    500: 	}
                    501: 	my $result=&Apache::lonnet::put('email_status'.$trgsuffix,
                    502: 					{$msgid => $status{$msgid}});
1.32      albertel  503: 	if (&Apache::lonnet::error($result)) {
1.9       albertel  504: 	    return (0,&mt('Message copied to new folder but status was not, A network error occurred.'));
                    505: 	}
1.1       albertel  506:     }
1.9       albertel  507: 
1.1       albertel  508: # Delete orginals
1.9       albertel  509:     my $result_del_msg = 
                    510: 	&Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]);
                    511:     my $result_del_stat =
                    512: 	&Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]);
1.32      albertel  513:     if (&Apache::lonnet::error($result_del_msg)) {
1.9       albertel  514: 	return (0,&mt('Message copied, but unable to delete the original from the source folder.'));
                    515:     }
1.32      albertel  516:     if (&Apache::lonnet::error($result_del_stat)) {
1.9       albertel  517: 	return (0,&mt('Message copied, but unable to delete the original status from the source folder.'));
                    518:     }
                    519: 
                    520:     return (1);
1.1       albertel  521: }
                    522: 
                    523: # ======================================================= Display a course list
                    524: 
                    525: sub discourse {
1.95      raeburn   526:     my ($statushash) = @_;
                    527:     my ($result,$active,$previous,$future);
1.138     raeburn   528:     my $crstype = &Apache::loncommon::course_type();
1.25      foxr      529:     my ($course_personnel,
                    530: 	$current_members,
                    531: 	$expired_members,
1.28      foxr      532: 	$future_members) = 
                    533: 	    &Apache::lonselstudent::get_people_in_class($env{'request.course.sec'});
1.25      foxr      534:     unshift @$current_members, (@$course_personnel);
                    535:     my %defaultUsers;
1.40      albertel  536:     
1.87      bisitz    537:     my $tmptext;
                    538:     if ($tmptext = &Apache::lonselstudent::render_student_list($current_members,
1.95      raeburn   539:                                                                "activeusers",
1.87      bisitz    540:                                                                "current",
                    541:                                                                \%defaultUsers,
1.95      raeburn   542:                                                                1,"selectedusers",1,'email')
1.87      bisitz    543:        ) {
1.138     raeburn   544:        my $bcc_curr_hdr;
                    545:        if ($crstype eq 'Community') {
                    546:            $bcc_curr_hdr = &mt('Bcc: community participants with current access');
                    547:        } else {
                    548:            $bcc_curr_hdr = &mt('Bcc: course members with current access');
                    549:        }
1.125     bisitz    550:        $result .= '<fieldset id="LC_activeusers"><legend>'
1.138     raeburn   551:                  .$bcc_curr_hdr
1.125     bisitz    552:                  .'</legend>'
1.163     bisitz    553:                  .'<form name="activeusers" action="">';
1.95      raeburn   554:        $result .= $tmptext.'</form></fieldset><br />';
                    555:        if (ref($statushash) eq 'HASH') {
                    556:            $statushash->{'active'} = 1;
                    557:        }
1.87      bisitz    558:     }
                    559:     if ($tmptext = &Apache::lonselstudent::render_student_list($expired_members,
1.95      raeburn   560:                                                                "previoususers",
1.87      bisitz    561:                                                                "expired",
                    562:                                                                \%defaultUsers,
1.95      raeburn   563:                                                                1, "selectedusers",0,'email')
1.87      bisitz    564:        ) {
1.138     raeburn   565:        my $bcc_prev_hdr;
                    566:        if ($crstype eq 'Community') {
                    567:            $bcc_prev_hdr = &mt('Bcc: community participants with expired access');
                    568:        } else {
                    569:            $bcc_prev_hdr = &mt('Bcc: course members with expired access');
                    570:        }
1.125     bisitz    571:        $result .= '<fieldset id="LC_previoususers"><legend>'
1.138     raeburn   572:                  .$bcc_prev_hdr
1.125     bisitz    573:                  .'</legend>'
1.163     bisitz    574:                  .'<form name="previoususers" action="">';
1.95      raeburn   575:        $result .= $tmptext.'</form></fieldset><br />';
                    576:        if (ref($statushash) eq 'HASH') {
                    577:            $statushash->{'previous'} = 1;
                    578:        }
                    579: 
1.87      bisitz    580:     }
                    581:     if ($tmptext = &Apache::lonselstudent::render_student_list($future_members,
1.95      raeburn   582:                                                                "futureusers",
1.87      bisitz    583:                                                                "future",
                    584:                                                                \%defaultUsers,
1.95      raeburn   585:                                                                1, "selectedusers",0,'email')
1.87      bisitz    586:        ) {
1.138     raeburn   587:        my $bcc_future_hdr;
                    588:        if ($crstype eq 'Community') {
                    589:            $bcc_future_hdr = &mt('Bcc: community participants with future access');
                    590:        } else {
                    591:            $bcc_future_hdr = &mt('Bcc: course members with future access');
                    592:        }
                    593: 
1.125     bisitz    594:        $result .= '<fieldset id="LC_futureusers"><legend>'
1.138     raeburn   595:                  .$bcc_future_hdr
1.125     bisitz    596:                  .'</legend>'
1.163     bisitz    597:                  .'<form name="futureusers" action="">';
1.95      raeburn   598:        $result .= $tmptext.'</form></fieldset>';
                    599:        if (ref($statushash) eq 'HASH') {
                    600:            $statushash->{'future'} = 1;
                    601:        }
                    602: 
1.87      bisitz    603:     }
1.25      foxr      604:     return $result;
                    605: }
                    606: 
1.38      raeburn   607: sub disgroup {
1.105     raeburn   608:     my ($r,$cdom,$cnum,$group,$access_status) = @_;
                    609:     my $hasfloat;
1.38      raeburn   610:     #  Needs to be in a course
                    611:     if (!($env{'request.course.fn'})) {
1.105     raeburn   612:         $r->print('<span class="LC_error">'.&mt('Error: you must have a course role selected to be able to send a broadcast message to a group in the course.').'</span>');
                    613:         return;
1.38      raeburn   614:     }
                    615:     if ($cdom eq '' || $cnum eq '') {
1.105     raeburn   616:         $r->print('<span class="LC_error">'.&mt('Error: could not determine domain or number of course').'</span>');
                    617:         return;
1.38      raeburn   618:     }
                    619:     my ($memberinfo,$numitems) =
                    620:                  &Apache::longroup::group_memberlist($cdom,$cnum,$group,{},[]);
                    621:     my @statustypes = ('active');
1.95      raeburn   622:     my $viewgrps = &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
                    623:                    ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
                    624:     my $editgrps = &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
                    625:                    ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.38      raeburn   626:     if ($viewgrps || $editgrps) {
                    627:         push(@statustypes,('future','previous'));
                    628:     }
                    629:     if (keys(%{$memberinfo}) == 0) {
1.105     raeburn   630:         $r->print('<span class="LC_warning">'.
                    631:                   &mt('As this group has no members, there are no recipients to select').
                    632:                   '</span>');
                    633:         return;
1.38      raeburn   634:     } else {
1.105     raeburn   635:         $hasfloat = 1;
1.154     raeburn   636:         $r->print('<div class="LC_left_float">');
1.38      raeburn   637:         my %Sortby = (
                    638:                          active   => {},
                    639:                          previous => {},
                    640:                          future   => {},
                    641:                      );
                    642:         my %lt = &Apache::lonlocal::texthash(
                    643:                                      'name'     => 'Name',
                    644:                                      'usnm'     => 'Username',
                    645:                                      'doma'     => 'Domain',
1.95      raeburn   646:                                      'active'   => 'Broadcast to Active Members',
                    647:                                      'previous' => 'Broadcast (Bcc) to Former Members',
                    648:                                      'future'   => 'Broadcast (Bcc) to Future Members',
1.38      raeburn   649:                                     );
                    650:         foreach my $user (sort(keys(%{$memberinfo}))) {
                    651:             my $status = $$memberinfo{$user}{status};
                    652:             if ($env{'form.'.$status.'.sortby'} eq 'fullname') {
                    653:                 push(@{$Sortby{$status}{$$memberinfo{$user}{fullname}}},$user);
                    654:             } elsif ($env{'form.'.$status.'.sortby'} eq 'username') {
                    655:                 push(@{$Sortby{$status}{$$memberinfo{$user}{uname}}},$user);
                    656:             } elsif ($env{'form.'.$status.'.sortby'} eq 'domain') {
                    657:                 push(@{$Sortby{$status}{$$memberinfo{$user}{udom}}},$user);
                    658:             } else {
                    659:                 push(@{$Sortby{$status}{$$memberinfo{$user}{fullname}}},$user);
                    660:             }
                    661:         }
1.105     raeburn   662:         $r->print(&group_check_uncheck());
1.38      raeburn   663:         foreach my $status (@statustypes)  {
                    664:             if (ref($numitems) eq 'HASH') {
                    665:                 if ((defined($$numitems{$status})) && ($$numitems{$status})) {
1.95      raeburn   666:                     my $formname = $status.'users';
                    667:                     if (ref($access_status) eq 'HASH') {
                    668:                         $access_status->{$status} = $$numitems{$status};
                    669:                     }
1.125     bisitz    670:                     $r->print('<fieldset>'.
                    671:                               '<legend>'.$lt{$status}.'</legend>'.
1.163     bisitz    672:                               '<form name="'.$formname.'" action="">'.
1.105     raeburn   673:                               '<span class="LC_nobreak">'.
                    674:                               '<input type="button" value="'.&mt('Check All').'" '.
                    675:                               'onclick="javascript:toggleAll('."this.form,'check'".')" />'.
                    676:                               '&nbsp;&nbsp;'.
                    677:                               '<input type="button" value="'.&mt('Uncheck All').'" '.
                    678:                               'onclick="javascript:toggleAll('."this.form,'uncheck'".')" />'.
                    679:                               '</span>');
1.95      raeburn   680:                     if ($status eq 'active') {
1.105     raeburn   681:                         $r->print(('&nbsp;'x3).'<select name="groupmail">'.
                    682:                                  '<option value="bcc" selected="selected">'.&mt('Bcc').'</option>'.
                    683:                                  '<option value="cc">'.&mt('Cc').'</option>'.
                    684:                                '</select>');
1.95      raeburn   685:                     }
1.105     raeburn   686:                     $r->print('<br />'.&Apache::loncommon::start_data_table().
1.95      raeburn   687:                                &Apache::loncommon::start_data_table_header_row().
1.105     raeburn   688:                                "<th>$lt{'name'}</th>".
                    689:                                "<th>$lt{'usnm'}</th>".
                    690:                                "<th>$lt{'doma'}</th>".
                    691:                                &Apache::loncommon::end_data_table_header_row());
1.38      raeburn   692:                     foreach my $key (sort(keys(%{$Sortby{$status}}))) {
                    693:                         foreach my $user (@{$Sortby{$status}{$key}}) {
1.105     raeburn   694:                             $r->print(&Apache::loncommon::start_data_table_row().
                    695:                                 '<td><span class="LC_nobreak"><input type="checkbox" '.
1.38      raeburn   696:                                 'name="selectedusers_forminput" value="'.
                    697:                                 $user.':'.$status.'" />'.
1.105     raeburn   698:                                 $$memberinfo{$user}{'fullname'}.'</span></td>'.
1.38      raeburn   699:                                 '<td>'.$$memberinfo{$user}{'uname'}.'</td>'.
                    700:                                 '<td>'.$$memberinfo{$user}{'udom'}.'</td>'.
1.105     raeburn   701:                                 &Apache::loncommon::end_data_table_row());
1.38      raeburn   702:                         }
                    703:                     }
1.105     raeburn   704:                     $r->print(&Apache::loncommon::end_data_table().'</form>'.
1.110     raeburn   705:                               '</fieldset><br />');
1.38      raeburn   706:                 }
                    707:             }
                    708:         }
1.154     raeburn   709:         $r->print('</div>');
1.38      raeburn   710:     }
1.105     raeburn   711:     return $hasfloat;
1.38      raeburn   712: }
                    713: 
                    714: sub group_check_uncheck {
                    715:     my $output = qq|
                    716: <script type="text/javascript">
1.127     bisitz    717: // <![CDATA[
1.95      raeburn   718: function toggleAll(form,action) {
                    719:     if (typeof(form.selectedusers_forminput.length)=="undefined") {
                    720:          if (action == 'check') {
                    721:             form.selectedusers_forminput.checked = true;
                    722:          } else {
                    723:             form.selectedusers_forminput.checked = false;
                    724:         }
                    725:     } else {
                    726:         for (var i=0; i<form.selectedusers_forminput.length; i++) {
1.38      raeburn   727:             if (action == 'check') {
1.95      raeburn   728:                 form.selectedusers_forminput[i].checked = true;
1.38      raeburn   729:             } else {
1.95      raeburn   730:                 form.selectedusers_forminput[i].checked = false;
1.38      raeburn   731:             }
                    732:         }
                    733:     }
                    734: }
1.127     bisitz    735: // ]]>
1.38      raeburn   736: </script>
                    737:     |;
                    738: }
                    739: 
                    740: sub groupmail_header {
                    741:     my ($action,$group,$cdom,$cnum) = @_;
                    742:     my ($description,$refarg);
                    743:     if (!$cdom || !$cnum) {
                    744:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    745:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    746:     }
                    747:     if (exists($env{'form.ref'})) {
                    748:         $refarg = 'ref='.$env{'form.ref'};
                    749:     }
                    750:     if (!$group) {
                    751:         $group = $env{'form.group'};
                    752:     }
                    753:     if ($group eq '') {
                    754:         return  '';
                    755:     } else {
                    756:         my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
                    757:         if (defined($curr_groups{$group})) {
                    758:             my %groupinfo =
                    759:                     &Apache::longroup::get_group_settings($curr_groups{$group});
                    760:             $description = &unescape($groupinfo{'description'});
                    761:         }
                    762:     }
                    763:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    764:     if ($refarg) {
1.138     raeburn   765:         my $brtitle;
                    766:         if (&Apache::loncommon::course_type() eq 'Community') {
                    767:             $brtitle = 'View community groups';  
                    768:         } else {
                    769:             $brtitle = 'View course groups';
                    770:         }  
1.38      raeburn   771:         &Apache::lonhtmlcommon::add_breadcrumb
                    772:             ({href=>"/adm/coursegroups",
                    773:               text=>"Groups",
1.138     raeburn   774:               title=>$brtitle});
1.38      raeburn   775:     }
                    776:     &Apache::lonhtmlcommon::add_breadcrumb
                    777:         ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
                    778:           text=>"Group: $description",
                    779:           title=>"Go to group's home page"},
                    780:          {href=>"/adm/email?compose=group&amp;group=".
                    781:                 "$env{'form.group'}&amp;$refarg",
                    782:           text=>"Send a Message in a Group",
1.99      schafran  783:           title=>"Compose Group Message"},);
1.38      raeburn   784:     if ($action eq 'sending') {
                    785:             &Apache::lonhtmlcommon::add_breadcrumb
1.99      schafran  786:                          ({text=>"Messages being sent.",
1.96      schafran  787:                            title=>"E-mails sent"},);
1.38      raeburn   788:     }
1.99      schafran  789:     my $groupheader = &Apache::loncommon::start_page('Group Message');
1.38      raeburn   790:     $groupheader .= &Apache::lonhtmlcommon::breadcrumbs
                    791:                 ('Group - '.$env{'form.group'}.' Email');
                    792:     return $groupheader;
                    793: }
                    794: 
                    795: sub groupmail_sent {
                    796:     my ($group,$cdom,$cnum) = @_;
                    797:     my $refarg;
                    798:     if (exists($env{'form.ref'})) {
                    799:         $refarg = 'ref='.$env{'form.ref'};
                    800:     }
                    801:     my $output .= '<br /><br /><a href="/adm/email?compose=group&amp;group='.
                    802:                   $group.'&amp;'.$refarg.'">'.
1.99      schafran  803:                   &mt('Send another group message').'</a>'.'&nbsp;&nbsp;&nbsp;'.
1.38      raeburn   804:                   '<a href="/adm/'.$cdom.'/'.$cnum.'/'.$group.'/smppg?'.
                    805:                   $refarg.'">'. &mt('Return to group page').'</a>';
                    806:     return $output;
                    807: }
                    808: 
1.1       albertel  809: # ==================================================== Display Critical Message
                    810: 
                    811: sub discrit {
                    812:     my $r=shift;
1.89      bisitz    813:     my $header = '<h1>'.&mt('Critical Messages').'</h1>'
                    814:                 .'<div class="LC_warning">'
                    815:                 .&mt('Access to other pages will be prevented until you have moved all critical messages to your inbox.')
                    816:                 .'</div><br />'
1.124     bisitz    817:                 .'<form action="/adm/email" method="post">'
1.89      bisitz    818:                 .'<input type="hidden" name="confirm" value="true" />';
1.1       albertel  819:     my %what=&Apache::lonnet::dump('critical');
                    820:     my $result = '';
1.175     musolffc  821:     # Sort by date in descending order
                    822:     foreach my $key (sort{$b <=> $a}(keys(%what))) {    
1.42      raeburn   823:         my %content=&Apache::lonmsg::unpackagemsg($what{$key});
1.1       albertel  824:         next if ($content{'senderdomain'} eq '');
1.157     raeburn   825:         my $description;
                    826:         if ($content{'courseid'} ne '') {
                    827:             if ($content{'courseid'} =~ m{/^$match_domain\_$match_courseid$}) {
                    828:                 my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'},{'one_time' => 1});
                    829:                 if ($courseinfo{'description'} ne '') {
                    830:                     $description = $courseinfo{'description'};
                    831:                 }
                    832:             }
                    833:         }
1.88      bisitz    834:         $result .= &Apache::lonhtmlcommon::start_pick_box()
                    835:                   .&Apache::lonhtmlcommon::row_title(&mt('From'),undef,'LC_oddrow_value')
                    836:                   .'<b>'.&Apache::loncommon::aboutmewrapper(
                    837:                    &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b>'
                    838:                   .' ('.$content{'sendername'}.':'.$content{'senderdomain'}.')'
                    839:                   .&Apache::lonhtmlcommon::row_closure(1)
                    840:                   .&Apache::lonhtmlcommon::row_title(&mt('Date'),undef,'LC_evenrow_value')
                    841:                   .$content{'time'}
                    842:                   .&Apache::lonhtmlcommon::row_closure(1)
                    843:                   .&Apache::lonhtmlcommon::row_title(&mt('Subject'),undef,'LC_oddrow_value')
                    844:                   .$content{'subject'}
1.156     bisitz    845:                   .&Apache::lonhtmlcommon::row_closure(1);
1.157     raeburn   846:         if ($description ne '') {
1.156     bisitz    847:             $result .= &Apache::lonhtmlcommon::row_title(&mt('Course'),undef,'LC_oddrow_value')
1.157     raeburn   848:                       .$description
1.156     bisitz    849:                       .&Apache::lonhtmlcommon::row_closure(1);
                    850:         }
                    851:         $result .= &Apache::lonhtmlcommon::row_title(&mt('Message'),undef,'LC_evenrow_value')
1.88      bisitz    852:                   .'<pre>'.&Apache::lontexconvert::msgtexconverted($content{'message'}).'</pre>'
                    853:                   .&Apache::lonhtmlcommon::row_closure()
                    854:                   .&Apache::lonhtmlcommon::row_title('',undef,'LC_oddrow_value')
                    855:                   .'<div class="LC_warning">';
1.78      raeburn   856:         my ($rec_button,$reprec_button);
                    857:         $rec_button = &mt('Move to Inbox');
                    858:         if (!$content{'noreplies'}) {
                    859:             $reprec_button = &mt('Move to Inbox/Compose reply');
                    860:         }
1.75      raeburn   861:         if ($content{'sendback'}) {
                    862:             $rec_button = &mt('Confirm Receipt');
1.78      raeburn   863:             if (!$content{'noreplies'}) {
                    864:                 $reprec_button = &mt('Confirm Receipt and Reply');
                    865:             }
1.75      raeburn   866:             $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');
                    867:         } else {
1.78      raeburn   868:             $result .= &mt('Access to other pages will be prevented until you have moved the message to your inbox.'); 
1.75      raeburn   869:         }
1.88      bisitz    870:         $result .= '</div>'
                    871:                   .&Apache::lonhtmlcommon::row_closure(1)
                    872:                   .&Apache::lonhtmlcommon::row_title('',undef,'LC_evenrow_value')
                    873:                   .'<input type="submit" name="rec_'.$key.'" value="'.$rec_button.'" />';
1.78      raeburn   874:         if (!$content{'noreplies'}) {
1.88      bisitz    875:             $result .= '<input type="submit" name="reprec_'.$key.'" '
                    876:                       .'value="'.$reprec_button.'" />'
1.78      raeburn   877:         }
1.88      bisitz    878:         $result .= &Apache::lonhtmlcommon::row_closure(1)
                    879:                   .&Apache::lonhtmlcommon::end_pick_box()
                    880:                   .'<br />';
1.1       albertel  881:     }
                    882:     # Check to see if there were any messages.
                    883:     if ($result eq '') {
1.141     bisitz    884:         $result =
                    885:             '<p class="LC_info">'.
                    886:             &mt('You have no critical messages.').
                    887:             '</p>'.
1.162     bisitz    888:             &Apache::lonhtmlcommon::actionbox(
                    889:                 ['<a href="/adm/roles">'.&mt('Select a course').'</a>',
                    890:                  '<a href="/adm/email">'.&mt('Communicate').'</a>']);
1.1       albertel  891:     } else {
                    892:         $r->print($header);
                    893:     }
                    894:     $r->print($result);
                    895:     $r->print('<input type="hidden" name="displayedcrit" value="true" /></form>');
                    896: }
                    897: 
                    898: sub sortedmessages {
1.53      raeburn   899:     my ($blocked,$startblock,$endblock,$numblocked,$folder,$msgstatus) = @_;
1.1       albertel  900:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
                    901:     my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
                    902:     #unpack the varibles and repack into temp for sorting
                    903:     my @temp;
                    904:     my %descriptions;
                    905:     my %status_cache = 
                    906: 	&Apache::lonnet::get('email_status'.&Apache::lonmsg::foldersuffix($folder),\@messages);
1.11      albertel  907: 
                    908:     my $get_received;
                    909:     if ($folder eq 'sent' 
                    910: 	&& ($env{'form.sortedby'} =~ m/^(rev)?(user|domain)$/)) {
                    911: 	$get_received = 1;
                    912:     }
                    913: 
                    914:     foreach my $msgid (@messages) {
1.114     raeburn   915:         next if ($msgid eq '');
1.29      www       916: 	my $esc_msgid=&escape($msgid);
1.59      raeburn   917: 	my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,$processid,$symb,$error) =
1.11      albertel  918: 	    &Apache::lonmsg::unpackmsgid($esc_msgid,$folder,undef,
1.1       albertel  919: 					 \%status_cache);
1.53      raeburn   920:         next if ($msgstatus ne '' && $msgstatus ne $status);
1.1       albertel  921:         my $description = &get_course_desc($fromcid,\%descriptions);
                    922: 	my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
1.11      albertel  923: 		     $esc_msgid,$description);
                    924: 	if ($get_received) {
                    925: 	    my %message = &Apache::lonnet::get('nohist_email'.$suffix,
                    926: 					       [$msgid]);
                    927: 	    my %content = &Apache::lonmsg::unpackagemsg($message{$msgid});
                    928: 	    push(@temp1,$content{'recuser'},$content{'recdomain'});
                    929: 	}
1.1       albertel  930:         # Check whether message was sent during blocking period.
                    931:         if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
1.11      albertel  932:             $$blocked{$msgid} = 'ON';
1.1       albertel  933:             $$numblocked ++;
                    934:         } else { 
                    935:             push @temp ,\@temp1;
                    936:         }
                    937:     }
                    938:     #default sort
                    939:     @temp = sort  {$a->[0] <=> $b->[0]} @temp;    
                    940:     if ($env{'form.sortedby'} eq "date"){
                    941:         @temp = sort  {$a->[0] <=> $b->[0]} @temp;    
                    942:     }
                    943:     if ($env{'form.sortedby'} eq "revdate"){
                    944:     	@temp = sort  {$b->[0] <=> $a->[0]} @temp; 
                    945:     }
                    946:     if ($env{'form.sortedby'} eq "user"){
1.11      albertel  947: 	if ($get_received) {
                    948: 	    @temp = sort  {lc($a->[7][0]) cmp lc($b->[7][0])} @temp;
                    949: 	} else {
                    950: 	    @temp = sort  {lc($a->[2])    cmp lc($b->[2])}    @temp;
                    951: 	}
1.1       albertel  952:     }
                    953:     if ($env{'form.sortedby'} eq "revuser"){
1.11      albertel  954: 	if ($get_received) {
                    955: 	    @temp = sort  {lc($b->[7][0]) cmp lc($a->[7][0])} @temp;
                    956: 	} else {
                    957: 	    @temp = sort  {lc($b->[2])    cmp lc($a->[2])}    @temp;
                    958: 	}
1.1       albertel  959:     }
                    960:     if ($env{'form.sortedby'} eq "domain"){
1.11      albertel  961: 	if ($get_received) {
                    962: 	    @temp = sort  {$a->[8][0] cmp $b->[8][0]} @temp;
                    963: 	} else {
                    964: 	    @temp = sort  {$a->[3]    cmp $b->[3]}    @temp;
                    965: 	}
1.1       albertel  966:     }
                    967:     if ($env{'form.sortedby'} eq "revdomain"){
1.11      albertel  968: 	if ($get_received) {
                    969: 	    @temp = sort  {$b->[8][0] cmp $a->[8][0]} @temp;
                    970: 	} else {
                    971: 	    @temp = sort  {$b->[3]    cmp $a->[3]}    @temp;
                    972: 	}
1.1       albertel  973:     }
                    974:     if ($env{'form.sortedby'} eq "subject"){
                    975:         @temp = sort  {lc($a->[1]) cmp lc($b->[1])} @temp;
                    976:     }
                    977:     if ($env{'form.sortedby'} eq "revsubject"){
                    978:         @temp = sort  {lc($b->[1]) cmp lc($a->[1])} @temp;
                    979:     }
                    980:     if ($env{'form.sortedby'} eq "course"){
                    981:         @temp = sort  {lc($a->[6]) cmp lc($b->[6])} @temp;
                    982:     }
                    983:     if ($env{'form.sortedby'} eq "revcourse"){
                    984:         @temp = sort  {lc($b->[6]) cmp lc($a->[6])} @temp;
                    985:     }
                    986:     if ($env{'form.sortedby'} eq "status"){
                    987:         @temp = sort  {$a->[4] cmp $b->[4]} @temp;
                    988:     }
                    989:     if ($env{'form.sortedby'} eq "revstatus"){
                    990:         @temp = sort  {$b->[4] cmp $a->[4]} @temp;
                    991:     }
                    992:     return @temp;
                    993: }
                    994: 
                    995: sub get_course_desc {
                    996:     my ($fromcid,$descriptions) = @_;
                    997:     my $description;
                    998:     if (!$fromcid) {
                    999:         return $description;
                   1000:     } else {
                   1001:         if (defined($$descriptions{$fromcid})) {
                   1002:             $description = $$descriptions{$fromcid};
                   1003:         } else {
                   1004:             if (defined($env{'course.'.$fromcid.'.description'})) {
                   1005:                 $description = $env{'course.'.$fromcid.'.description'};
                   1006:             } else {
1.157     raeburn  1007:                 if ($fromcid =~ m{/^$match_domain\_$match_courseid$}) {
                   1008:                     my %courseinfo=&Apache::lonnet::coursedescription($fromcid,
                   1009:                                                                       {'one_time' => 1});
                   1010:                     $description = $courseinfo{'description'};
                   1011:                 }
                   1012:             }
                   1013:             if ($description ne '') {
                   1014:                 $$descriptions{$fromcid} = $description;
1.1       albertel 1015:             }
                   1016:         }
                   1017:         return $description;
                   1018:     }
                   1019: }
                   1020: 
                   1021: # ======================================================== Display all messages
                   1022: 
                   1023: sub disall {
1.53      raeburn  1024:     my ($r,$folder,$msgstatus)=@_;
1.81      albertel 1025:     my %saveable = ('msgstatus' => 'scalar',
1.57      albertel 1026: 		    'sortedby'  => 'scalar',
                   1027: 		    'interdis'  => 'scalar',
                   1028: 		    );
                   1029:     &Apache::loncommon::store_settings('user','mail',\%saveable);
                   1030:     &Apache::loncommon::restore_settings('user','mail',\%saveable);
                   1031:     $folder    ||= $env{'form.folder'};
1.175     musolffc 1032:     # Always show critical messages if present
                   1033:     my @what=&Apache::lonnet::dump('critical',$env{'user.domain'},$env{'user.name'});
                   1034:     if ($what[0]) {
                   1035: 	if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
                   1036:             $folder = 'critical';
                   1037:         }
                   1038:     }
1.57      albertel 1039:     $msgstatus ||= $env{'form.msgstatus'};
                   1040:     $env{'form.interdis'} ||= 20;
                   1041: 
1.53      raeburn  1042:     $r->print(&folderlist($folder,$msgstatus));
                   1043:     if ($folder eq 'critical') {
1.1       albertel 1044: 	&discrit($r);
                   1045:     } else {
1.53      raeburn  1046: 	&disfolder($r,$folder,$msgstatus);
1.1       albertel 1047:     }
                   1048: }
                   1049: 
                   1050: # ============================================================ Display a folder
                   1051: 
                   1052: sub disfolder {
1.53      raeburn  1053:     my ($r,$folder,$msgstatus)=@_;
                   1054:     my %statushash = &get_msgstatus_types();
1.1       albertel 1055:     my %blocked = ();
                   1056:     my %setters = ();
                   1057:     my $numblocked = 0;
1.44      raeburn  1058:     my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.181     damieng  1059:     my %js_lt = &Apache::lonlocal::texthash(
1.53      raeburn  1060:                       sede => 'Select a destination folder to which the messages will be moved.',
1.148     bisitz   1061:                       nome => 'No messages have been selected to apply this action to.',
1.53      raeburn  1062:                       chec => 'Check the checkbox for at least one message.',  
                   1063:     );
1.181     damieng  1064:     &js_escape(\%js_lt);
1.64      raeburn  1065:     my $jscript = &Apache::loncommon::check_uncheck_jscript();
1.1       albertel 1066:     $r->print(<<ENDDISHEADER);
1.16      albertel 1067: <script type="text/javascript">
1.127     bisitz   1068: // <![CDATA[
1.64      raeburn  1069:     $jscript
1.1       albertel 1070: 
1.53      raeburn  1071:     function validate_checkedaction() {
                   1072:         document.disall.markedaction.value = document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value;
                   1073:         if (document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value == 'markedmove') {
                   1074:             if (document.disall.movetofolder.options[document.disall.movetofolder.selectedIndex].value == "") {
1.181     damieng  1075:                 alert("$js_lt{'sede'}");
1.53      raeburn  1076:                 return;
                   1077:             } 
                   1078:         }
                   1079:         var checktotal = 0;
1.64      raeburn  1080:         if (document.forms.disall.delmark.length > 0) {
                   1081:             for (var i=0; i<document.forms.disall.delmark.length; i++) {
                   1082:                 if (document.forms.disall.delmark[i].checked) {
                   1083:                     checktotal ++;
                   1084:                 }
                   1085:             }
                   1086:         } else {
                   1087:             if (document.forms.disall.delmark.checked) {
1.53      raeburn  1088:                 checktotal ++;
                   1089:             }
1.64      raeburn  1090:         }   
1.53      raeburn  1091:         if (checktotal == 0) {
1.181     damieng  1092:             alert("$js_lt{'nome'}\\n$js_lt{'chec'}");
1.53      raeburn  1093:             return;
                   1094:         }
                   1095:         document.disall.submit();
                   1096:     }
1.127     bisitz   1097: // ]]>
1.1       albertel 1098: </script>
                   1099: ENDDISHEADER
1.54      albertel 1100: 
1.127     bisitz   1101:     my $fsqs='&amp;folder='.$folder;
1.53      raeburn  1102:     my @temp=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1       albertel 1103:     my $totalnumber=$#temp+1;
1.53      raeburn  1104:     if ($totalnumber < 1) {
1.141     bisitz   1105:         $r->print('<p class="LC_info">');
1.53      raeburn  1106:         if ($msgstatus eq '') {
1.141     bisitz   1107:             $r->print(&mt('There are no messages in this folder.'));
1.53      raeburn  1108:         } elsif ($msgstatus eq 'replied') {
1.141     bisitz   1109:             $r->print(&mt('You have not replied to any messages in this folder.'));
                   1110:         } else {
                   1111:             $r->print(&mt('There are no '.lc($statushash{$msgstatus}).' messages in this folder.'));
1.53      raeburn  1112:         }
1.141     bisitz   1113:         $r->print('</p>');
1.65      raeburn  1114:         if ($numblocked > 0) {
                   1115:             $r->print(&blocked_in_folder($numblocked,$startblock,$endblock,
                   1116:                                          \%setters));
                   1117:         }
1.141     bisitz   1118:         return;
1.1       albertel 1119:     }
1.57      albertel 1120:     my $interdis = $env{'form.interdis'};
1.1       albertel 1121:     my $number=int($totalnumber/$interdis);
1.57      albertel 1122:     if ($totalnumber%$interdis == 0) {
                   1123: 	$number--; 
1.53      raeburn  1124:     }
                   1125: 
1.1       albertel 1126:     if (($startdis<0) || ($startdis>$number)) { $startdis=$number; }
                   1127:     my $firstdis=$interdis*$startdis;
                   1128:     if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; }
                   1129:     my $lastdis=$firstdis+$interdis-1;
                   1130:     if ($lastdis>$#temp) { $lastdis=$#temp; }
1.53      raeburn  1131:     $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber,$msgstatus));
1.1       albertel 1132:     $r->print('<form method="post" name="disall" action="/adm/email">'.
1.149     bisitz   1133: 	      &Apache::loncommon::start_data_table().
                   1134:           &Apache::loncommon::start_data_table_row().
                   1135:           '<th colspan="1">&nbsp;</th><th>');
1.1       albertel 1136:     if ($env{'form.sortedby'} eq "revdate") {
1.134     raeburn  1137: 	$r->print('<a href = "/adm/email?sortedby=date'.$fsqs.'">'.&mt('Date').'</a></th>');
1.1       albertel 1138:     } else {
1.134     raeburn  1139: 	$r->print('<a href = "/adm/email?sortedby=revdate'.$fsqs.'">'.&mt('Date').'</a></th>');
1.1       albertel 1140:     }
                   1141:     $r->print('<th>');
                   1142:     if ($env{'form.sortedby'} eq "revuser") {
1.134     raeburn  1143: 	$r->print('<a href = "/adm/email?sortedby=user'.$fsqs.'">'.&mt('Username').'</a>');
1.1       albertel 1144:     } else {
1.134     raeburn  1145: 	$r->print('<a href = "/adm/email?sortedby=revuser'.$fsqs.'">'.&mt('Username').'</a>');
1.1       albertel 1146:     }
                   1147:     $r->print('</th><th>');
                   1148:     if ($env{'form.sortedby'} eq "revdomain") {
1.134     raeburn  1149: 	$r->print('<a href = "/adm/email?sortedby=domain'.$fsqs.'">'.&mt('Domain').'</a>');
1.1       albertel 1150:     } else {
1.134     raeburn  1151: 	$r->print('<a href = "/adm/email?sortedby=revdomain'.$fsqs.'">'.&mt('Domain').'</a>');
1.1       albertel 1152:     }
                   1153:     $r->print('</th><th>');
                   1154:     if ($env{'form.sortedby'} eq "revsubject") {
1.134     raeburn  1155: 	$r->print('<a href = "/adm/email?sortedby=subject'.$fsqs.'">'.&mt('Subject').'</a>');
1.1       albertel 1156:     } else {
1.134     raeburn  1157:     	$r->print('<a href = "/adm/email?sortedby=revsubject'.$fsqs.'">'.&mt('Subject').'</a>');
1.1       albertel 1158:     }
                   1159:     $r->print('</th><th>');
                   1160:     if ($env{'form.sortedby'} eq "revcourse") {
1.134     raeburn  1161:         $r->print('<a href = "/adm/email?sortedby=course'.$fsqs.'">'.&mt('Course').'</a>');
1.1       albertel 1162:     } else {
1.134     raeburn  1163:         $r->print('<a href = "/adm/email?sortedby=revcourse'.$fsqs.'">'.&mt('Course').'</a>');
1.1       albertel 1164:     }
1.149     bisitz   1165:     $r->print('</th><th colspan="2">');
1.1       albertel 1166:     if ($env{'form.sortedby'} eq "revstatus") {
1.134     raeburn  1167: 	$r->print('<a href = "/adm/email?sortedby=status'.$fsqs.'">'.&mt('Status').'</a></th>');
1.1       albertel 1168:     } else {
1.134     raeburn  1169:      	$r->print('<a href = "/adm/email?sortedby=revstatus'.$fsqs.'">'.&mt('Status').'</a></th>');
1.1       albertel 1170:     }
                   1171:     $r->print("</tr>\n");
1.6       albertel 1172: 
                   1173:     my $suffix = &Apache::lonmsg::foldersuffix($folder);
1.132     raeburn  1174:     my $count = $firstdis;
1.1       albertel 1175:     for (my $n=$firstdis;$n<=$lastdis;$n++) {
1.11      albertel 1176: 	my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,
                   1177: 	    $description,$recv_name,$recv_domain)= 
                   1178: 		@{$temp[$n]};
1.149     bisitz   1179:         if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
                   1180:             my $class_msgstatus = '';
1.114     raeburn  1181:             $count ++;
1.149     bisitz   1182:             if ($status eq 'new') {
                   1183:                 $class_msgstatus = 'LC_mail_new';
                   1184:             } elsif ($status eq 'read') {
                   1185:                 $class_msgstatus = 'LC_mail_read';
                   1186:             } elsif ($status eq 'replied') {
                   1187:                 $class_msgstatus = 'LC_mail_replied'; 
                   1188:             } else {
                   1189:                 $class_msgstatus = 'LC_mail_other';
                   1190:             }
                   1191:             $r->print(&Apache::loncommon::start_data_table_row($class_msgstatus));
1.6       albertel 1192: 	    my ($dis_name,$dis_domain) = ($fromname,$fromdomain);
                   1193: 	    if ($folder eq 'sent') {
1.69      raeburn  1194:                 if (defined($recv_name) && defined($recv_domain)) {
                   1195: 		    if (ref($recv_name) eq 'ARRAY' && 
                   1196:                         ref($recv_domain) eq 'ARRAY') {
                   1197: 		        $dis_name   = join('<br />',@{$recv_name});
                   1198: 		        $dis_domain = join('<br />',@{$recv_domain});
                   1199:                     }
1.11      albertel 1200: 		} else {
1.29      www      1201: 		    my $msg_id  = &unescape($origID);
1.11      albertel 1202: 		    my %message = &Apache::lonnet::get('nohist_email'.$suffix,
                   1203: 						       [$msg_id]);
                   1204: 		    my %content = &Apache::lonmsg::unpackagemsg($message{$msg_id});
1.69      raeburn  1205:                     if (ref($content{'recuser'}) eq 'ARRAY') {
                   1206: 		        $dis_name   = join('<br />',@{$content{'recuser'}});
                   1207:                     }
                   1208:                     if (ref($content{'recdomain'}) eq 'ARRAY') {
                   1209: 		        $dis_domain = join('<br />',@{$content{'recdomain'}});
                   1210:                     }
1.11      albertel 1211: 		}
1.6       albertel 1212: 	    }
1.53      raeburn  1213:             my $localsenttime = &Apache::lonlocal::locallocaltime($sendtime);
1.102     bisitz   1214: 	    $r->print('<td align="right"><span class="LC_nobreak">'.(($status eq 'new')?'<b>':'').
1.53      raeburn  1215:                       $count.'.'.(($status eq 'new')?'</b>':'').'&nbsp;'.
                   1216:                       '<input type="checkbox" name="delmark"'. 
1.102     bisitz   1217:                       ' value="'.$origID.'" /></span></td>');
1.53      raeburn  1218:             foreach my $item ($localsenttime,$dis_name,$dis_domain,$shortsubj) {
                   1219:                 $r->print('<td>'.(($status eq 'new')?'<b>':'').
1.61      raeburn  1220:                           '<a href="/adm/email?display='.$origID.$sqs.'">'.
1.170     bisitz   1221:                           $item.'</a>'.(($status eq 'new')?'</b>':'').'</td>');
1.53      raeburn  1222:             }
1.149     bisitz   1223:             # Description and Status
1.53      raeburn  1224:             my $showstatus;
                   1225:             my %statushash = &get_msgstatus_types();
                   1226:             if ($status eq '') {
                   1227:                 $showstatus = '';
                   1228:             } else {
                   1229:                 $showstatus = $statushash{$status};
                   1230:             }
1.149     bisitz   1231:             $r->print('<td>'.(($status eq 'new')?'<b>':'').$description.
                   1232:                       (($status eq 'new')?'</b>':'').
                   1233:                       '</td>');
                   1234:             $r->print('<td class="'.$class_msgstatus.'">&nbsp;&nbsp;</td>'.
                   1235:                       '<td>'.
                   1236:                       (($status eq 'new')?'<b>':'').&mt($showstatus).
                   1237:                       (($status eq 'new')?'</b>':'').
                   1238:                       '</td>');
                   1239: 
                   1240:             $r->print(&Apache::loncommon::end_data_table_row());
                   1241: 
                   1242:         } elsif ($status eq 'deleted') {
1.1       albertel 1243: # purge
1.149     bisitz   1244:             my ($result,$msg) = 
                   1245:         	&movemsg(&unescape($origID),$folder,'trash');
                   1246:         }
1.1       albertel 1247:     }   
1.149     bisitz   1248:     $r->print(&Apache::loncommon::end_data_table());
                   1249: 
                   1250: 
                   1251:     # Bottom Functions
1.162     bisitz   1252:     $r->print('
                   1253: <div class="LC_columnSection"><fieldset>
                   1254: <legend>'.&mt('Message Actions').'</legend>
                   1255: <table border="0" cellspacing="2" cellpadding="8">
1.53      raeburn  1256:  <tr>
1.162     bisitz   1257:   <td><b>'.&mt('Select Messages').'</b><br />
1.148     bisitz   1258:    <span class="LC_nobreak">
                   1259:    <input type="button" onclick="javascript:checkAll(document.disall.delmark)" value="'.&mt('Check All').'" />'."\n".
                   1260:   ' <input type="button" onclick="javascript:uncheckAll(document.disall.delmark)" value="'.&mt('Uncheck All').'" />'."\n".
                   1261:   '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" />
                   1262:   </span>
                   1263:   </td>'."\n".
                   1264:   '<td><b>'.&mt('Action').'</b><br />'."\n".
1.83      raeburn  1265:   '  <select name="checkedaction">'."\n");
1.53      raeburn  1266: 
1.1       albertel 1267:     if ($folder ne 'trash') {
1.53      raeburn  1268:         $r->print('    <option value="markeddel">'.&mt('Delete').'</option>'."\n");
                   1269:     }
                   1270:     if ($msgstatus ne 'read') {
1.170     bisitz   1271:         $r->print('    <option value="markedread">'.&mt('Mark Read').'</option>'."\n");
1.53      raeburn  1272:     }
                   1273:     if ($msgstatus ne 'unread') {
                   1274:         $r->print('    <option value="markedunread">'.&mt('Mark Unread').'</option>'."\n");
1.1       albertel 1275:     }
1.53      raeburn  1276:     $r->print('   <option value="markedforward">'.&mt('Forward').'</option>'."\n");
1.54      albertel 1277: 
                   1278:     my %gotfolders = &Apache::lonmsg::get_user_folders();
1.53      raeburn  1279:     if (keys(%gotfolders) > 0) {
                   1280:         $r->print('   <option value="markedmove">'.&mt('Move to Folder ->').
                   1281:                   '</option>');
                   1282:     }
                   1283:     $r->print("\n".'</select></td>'."\n");
1.54      albertel 1284: 
1.53      raeburn  1285:     if (keys(%gotfolders) > 0) {
1.162     bisitz   1286:         $r->print('<td><b>'.&mt('Destination folder').'</b><br />');
1.54      albertel 1287: 	my %userfolders;
1.53      raeburn  1288:         foreach my $key (keys(%gotfolders)) {
                   1289:             $userfolders{$key} = $key;
                   1290:         }
                   1291:         $userfolders{''} = "";
1.153     raeburn  1292:         $r->print(&Apache::loncommon::select_form('','movetofolder',\%userfolders).
1.53      raeburn  1293:                   '</td>');
                   1294:     }
1.162     bisitz   1295:     $r->print('<td style="vertical-align:bottom;">'.
1.53      raeburn  1296:               '<input type="button" name="go" value="'.&mt('Go').
                   1297:               '" onclick="javascript:validate_checkedaction()"/></td>'."\n".
1.162     bisitz   1298:               '</tr></table>'."\n".
                   1299:               '</fieldset></div>'."\n"
                   1300:     );
1.1       albertel 1301:     my $postedstartdis=$startdis+1;
1.121     bisitz   1302:     $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 1303:     if ($numblocked > 0) {
1.65      raeburn  1304:         $r->print(&blocked_in_folder($numblocked,$startblock,$endblock,
                   1305:                                      \%setters));
1.1       albertel 1306:     }
                   1307: }
                   1308: 
1.65      raeburn  1309: sub blocked_in_folder {
                   1310:     my ($numblocked,$startblock,$endblock,$setters) = @_;
                   1311:     my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
                   1312:     my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
                   1313:     my $output = '<br /><br />'.
                   1314:                   &mt('[quant,_1,message is, messages are] not viewable because display of LON-CAPA messages sent to you by other students between [_2] and [_3] is currently being blocked because of online exams.',$numblocked,$beginblock,$finishblock);
1.129     kalberla 1315:     #$output .= &Apache::loncommon::build_block_table($startblock,$endblock,
                   1316:     #                                                 $setters);
                   1317:     
1.130     kalberla 1318:     my ($blocked, $blocktext) = &Apache::loncommon::blocking_status("com");
1.131     kalberla 1319:     $output .="<br /><br />".$blocktext;
1.129     kalberla 1320: 
1.65      raeburn  1321:     return $output;
                   1322: }
                   1323: 
1.1       albertel 1324: # ============================================================== Compose output
                   1325: 
                   1326: sub compout {
1.53      raeburn  1327:     my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode,
                   1328:         $multiforward)=@_;
1.1       albertel 1329:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
1.38      raeburn  1330:     my ($cdom,$cnum,$group,$refarg);
                   1331:     if (exists($env{'form.group'})) {
                   1332:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1333:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   1334:         $group = $env{'form.group'};
                   1335:         my $action = 'composing';
                   1336:         $r->print(&groupmail_header($action,$group,$cdom,$cnum));
                   1337:     } elsif ($broadcast eq 'individual') {
1.1       albertel 1338: 	&printheader($r,'/adm/email?compose=individual',
                   1339: 	     'Send a Message');
                   1340:     } elsif ($broadcast) {
                   1341: 	&printheader($r,'/adm/email?compose=group',
                   1342: 	     'Broadcast Message');
                   1343:     } elsif ($forwarding) {
                   1344: 	&Apache::lonhtmlcommon::add_breadcrumb
1.29      www      1345:         ({href=>"/adm/email?display=".&escape($forwarding),
1.1       albertel 1346:           text=>"Display Message"});
1.29      www      1347: 	&printheader($r,'/adm/email?forward='.&escape($forwarding),
1.1       albertel 1348: 	     'Forwarding a Message');
                   1349:     } elsif ($replying) {
                   1350: 	&Apache::lonhtmlcommon::add_breadcrumb
1.29      www      1351:         ({href=>"/adm/email?display=".&escape($replying),
1.1       albertel 1352:           text=>"Display Message"});
1.29      www      1353: 	&printheader($r,'/adm/email?replyto='.&escape($replying),
1.1       albertel 1354: 	     'Replying to a Message');
                   1355:     } elsif ($replycrit) {
                   1356: 	$r->print('<h3>'.&mt('Replying to a Critical Message').'</h3>');
                   1357: 	$replying=$replycrit;
1.53      raeburn  1358:     } elsif ($multiforward) {
                   1359:         &Apache::lonhtmlcommon::add_breadcrumb
                   1360:         ({href=>"/adm/email?folder=".&escape($folder),
1.112     weissno  1361:           text=>"Display All Messages"});
1.53      raeburn  1362:         &printheader($r,'/adm/email?compose=multiforward',
                   1363:              'Forwarding Multiple Messages');
1.70      raeburn  1364:         if ($multiforward > 1) {
1.144     raeburn  1365:             $r->print(&mt('Each of the[_1] [quant,_2,message] [_3]you checked'
1.135     bisitz   1366:                          .' will be forwarded to the recipient(s) you select below.'
1.144     raeburn  1367:                          ,'<b>',$multiforward,'</b>')
1.85      bisitz   1368:                     .'<br />');
1.70      raeburn  1369:         } else {
                   1370:             $r->print(&mt('The message you checked will be forwarded to the recipient(s) you select below.').'<br />');
                   1371:         }
                   1372: 
1.1       albertel 1373:     } else {
                   1374: 	&printheader($r,'/adm/email?compose=upload',
                   1375: 	     'Distribute from Uploaded File');
                   1376:     }
                   1377: 
                   1378:     my $dispcrit='';
                   1379:     my $dissub='';
                   1380:     my $dismsg='';
                   1381:     my $disbase='';
1.86      raeburn  1382:     my $attachrow;
1.94      bisitz   1383:     my $func1='Send'; # do not translate here!
                   1384:     my %func2=( # do not translate here!
                   1385:                'ma'  => 'Message',
                   1386:                'msg' => 'Messages',
                   1387:               );
1.50      raeburn  1388:     my %lt=&Apache::lonlocal::texthash('us'  => 'Username',
                   1389: 				       'do'  => 'Domain',
                   1390: 				       'ad'  => 'Additional Recipients',
1.78      raeburn  1391:                                        'rt'  => 'Reply to',
                   1392:                                        'ar'  => 'Allow replies',
1.50      raeburn  1393: 				       'sb'  => 'Subject',
                   1394: 				       'ca'  => 'Cancel',
                   1395:                                        'gen' => 'Generate messages from a file',
                   1396:                                        'gmt' => 'General message text',
                   1397:                                        'tff' => 'The file format for the uploaded portion of the message is',
                   1398:                                        'uas' => 'Upload and Send',
1.86      raeburn  1399:                                        'atta' => 'Attachment',
1.95      raeburn  1400:                                        'to'   => 'To:',
1.50      raeburn  1401:                                       );
1.86      raeburn  1402:     my %attachmax = (
1.93      bisitz   1403:                      text => &mt('(128 KB max size)'),
1.86      raeburn  1404:                      num  => 131072,
                   1405:                     );
                   1406:     if (!$forwarding && !$multiforward) {
1.95      raeburn  1407:         $attachrow = '<tr><td colspan="3"><b>'.$lt{'atta'}.'</b> '.$attachmax{'text'}.': <input type="file" name="attachment" /></td></tr>';
1.86      raeburn  1408:     }
1.1       albertel 1409:     if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                   1410: 	|| &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                   1411: 				    '/'.$env{'request.course.sec'})) {
1.138     raeburn  1412:          my $crstype = &Apache::loncommon::course_type();
1.1       albertel 1413: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1.138     raeburn  1414:          my $rsstxt;
                   1415:          if (&Apache::loncommon::course_type() eq 'Community') {
                   1416:              $rsstxt = &mt('Include in community RSS newsfeed');
                   1417:          } else {
                   1418:              $rsstxt = &mt('Include in course RSS newsfeed');
                   1419:          }
1.1       albertel 1420:          $dispcrit=
1.95      raeburn  1421:  '<span class="LC_nobreak"><label><input type="checkbox" name="critmsg" /> '.&mt('Send as critical message').'.</label>'.$crithelp.'&nbsp;&nbsp;'.&mt('Require return receipt?').'<label><input type="radio" name="sendbck" value="1" />'.&mt('Yes').'</label>&nbsp;&nbsp;<label><input type="radio" name="sendbck" value="" checked="checked" />'.&mt('No').'</label></span><br />'.
                   1422:  '<label><input type="checkbox" name="permanent" /> '.
1.100     schafran 1423: &mt('Send copy to permanent e-mail address (if known)').'</label><br />'.
1.95      raeburn  1424: '<label><input type="checkbox" name="rsspost" /> '.
1.138     raeburn  1425: 		  $rsstxt.'</label><br />';
1.70      raeburn  1426:     }
1.71      raeburn  1427:     if ($broadcast ne 'group') {
                   1428:         if (&Apache::lonnet::allowed('dff',$env{'request.course.id'}) ||
                   1429:             &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
                   1430:                                      '/'.$env{'request.course.sec'})) {
                   1431: 
1.138     raeburn  1432:             my $rectxt;
                   1433:             if (&Apache::loncommon::course_type() eq 'Community') {
                   1434:                 $rectxt = &mt("Include in community's 'User records' for recipient(s)");
                   1435:             } else {
                   1436:                 $rectxt = &mt("Include in course's 'User records' for recipient(s)");
                   1437:             }
                   1438: 
1.95      raeburn  1439:             $dispcrit.='<label>'.
1.71      raeburn  1440:                        '<input type="checkbox" name="courserecord" value="1" /> '.
1.138     raeburn  1441:                        $rectxt.
1.95      raeburn  1442:                        '</label><br />';
1.71      raeburn  1443:         }
1.70      raeburn  1444:     }
                   1445: 
1.1       albertel 1446:     my %message;
                   1447:     my %content;
1.95      raeburn  1448:     my ($hasfloat,$broadcast_js,$sendmode,$can_grp_broadcast);
1.1       albertel 1449:     my $defdom=$env{'user.domain'};
1.95      raeburn  1450:     if ($broadcast eq 'group') {
                   1451:         my %access_status = (
                   1452:                            active => 0,
                   1453:                            previous => 0,
                   1454:                            future => 0,
                   1455:                       );
                   1456:  
                   1457:         if ($group eq '') {
                   1458:             my $studentsel = &discourse(\%access_status);
                   1459:             if ($studentsel) {
1.154     raeburn  1460:                 $r->print('<div class="LC_left_float">'.$studentsel.'</div>');
1.95      raeburn  1461:                 $hasfloat = 1;
                   1462:             }
                   1463:         } else {
                   1464:             $can_grp_broadcast = &check_group_priv($group);
                   1465:             if ($can_grp_broadcast) {
1.105     raeburn  1466:                 $hasfloat = &disgroup($r,$cdom,$cnum,$group,\%access_status);
1.95      raeburn  1467:             }
                   1468:         }
                   1469:         if ($hasfloat) {
                   1470:             $sendmode = '<input type="hidden" name="sendmode" value="group" />'."\n";
                   1471:             $broadcast_js = qq|
                   1472: <script type="text/javascript">
1.127     bisitz   1473: // <![CDATA[
1.95      raeburn  1474: function courseRecipients() {
                   1475: |;
                   1476:         foreach my $type (keys(%access_status)) {
                   1477:             if ($access_status{$type}) {
                   1478:                 my $formname = $type.'users';
                   1479:                 if ($type eq 'active' && $group ne '') {
                   1480:                     $broadcast_js .= qq|
                   1481:                     document.compemail.groupmail.value = document.$formname.groupmail[document.$formname.groupmail.selectedIndex].value;
                   1482: |;
                   1483:                 }
1.160     golterma 1484:                 #typeof(...forminput.length) returns 'undefined' if only one entry exists
1.95      raeburn  1485:                 $broadcast_js .= qq|
                   1486:     if (typeof(document.$formname.selectedusers_forminput.length)=="undefined") {
1.160     golterma 1487:         if (document.$formname.selectedusers_forminput.checked) {
                   1488:             document.compemail.courserecips.value += '_&&&_'+document.$formname.selectedusers_forminput.value;
                   1489:         }
1.95      raeburn  1490:     } else {
                   1491:         for (var i=0; i<document.$formname.selectedusers_forminput.length; i++) {
                   1492:             if (document.$formname.selectedusers_forminput[i].checked) {
                   1493:                 document.compemail.courserecips.value += '_&&&_'+document.$formname.selectedusers_forminput[i].value;  
                   1494:             }
                   1495:         }
                   1496:     }
                   1497:                 |;
                   1498:             }
                   1499:         }
                   1500:         $broadcast_js .= qq|
                   1501:     return;
                   1502: }
1.127     bisitz   1503: // ]]>
1.95      raeburn  1504: </script>
                   1505: 
                   1506: |;
                   1507:         }
                   1508:     }
1.1       albertel 1509:     if ($forwarding) {
                   1510: 	%message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]);
                   1511: 	%content=&Apache::lonmsg::unpackagemsg($message{$forwarding},$folder);
                   1512: 	$dispcrit.='<input type="hidden" name="forwid" value="'.
                   1513: 	    $forwarding.'" />';
1.94      bisitz   1514: 	$func1='Forward'; # do not translate here!
1.1       albertel 1515: 	
                   1516: 	$dissub=&mt('Forwarding').': '.$content{'subject'};
                   1517: 	$dismsg=&mt('Forwarded message from').' '.
                   1518: 	    $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
                   1519: 	if ($content{'baseurl'}) {
1.29      www      1520: 	    $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1       albertel 1521: 	}
                   1522:     }
                   1523:     if ($replying) {
                   1524: 	%message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
                   1525: 	%content=&Apache::lonmsg::unpackagemsg($message{$replying},$folder);
                   1526: 	$dispcrit.='<input type="hidden" name="replyid" value="'.
                   1527: 	    $replying.'" />';
1.94      bisitz   1528: 	$func1='Send Reply to'; # do not translate here!
1.1       albertel 1529: 	
                   1530: 	$dissub=&mt('Reply').': '.$content{'subject'};       
                   1531: 	$dismsg='> '.$content{'message'};
                   1532: 	$dismsg=~s/\r/\n/g;
                   1533: 	$dismsg=~s/\f/\n/g;
                   1534: 	$dismsg=~s/\n+/\n\> /g;
                   1535: 	if ($content{'baseurl'}) {
1.29      www      1536: 	    $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1       albertel 1537: 	    if ($env{'user.adv'}) {
1.72      albertel 1538: 		$disbase.='<label><input type="checkbox" name="storebasecomment" />'.&mt('Save message for re-use').
1.1       albertel 1539: 		    '</label> <a href="/adm/email?showcommentbaseurl='.
1.29      www      1540: 		    &escape($content{'baseurl'}).'" target="comments">'.
1.1       albertel 1541: 		    &mt('Show re-usable messages').'</a><br />';
                   1542: 	    }
                   1543: 	}
1.73      raeburn  1544:         my $jscript = &Apache::loncommon::check_uncheck_jscript();
                   1545:         $r->print(<<"ENDREPSCRIPT");
                   1546: <script type="text/javascript">
1.127     bisitz   1547: // <![CDATA[
1.73      raeburn  1548: $jscript
1.127     bisitz   1549: // ]]>
1.73      raeburn  1550: </script>
                   1551: ENDREPSCRIPT
1.1       albertel 1552:     }
                   1553:     my $citation=&displayresource(%content);
1.95      raeburn  1554:     my $onsubmit;
1.1       albertel 1555:     if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
1.23      www      1556:     if ($env{'form.text'}) { $dismsg=$env{'form.text'}; }
                   1557:     if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; }
1.95      raeburn  1558:     if ($hasfloat) {
1.154     raeburn  1559:         $r->print($broadcast_js.'<div class="LC_left_float">');
1.95      raeburn  1560:         $onsubmit = ' onsubmit="javascript:courseRecipients();" ';
                   1561:     }
1.23      www      1562:     $r->print(
1.1       albertel 1563:                 '<form action="/adm/email"  name="compemail" method="post"'.
1.95      raeburn  1564:                 ' enctype="multipart/form-data"'.$onsubmit.'>'."\n".
                   1565:                 '<input type="hidden" name="sendmail" value="on" />'."\n".
                   1566:                 '<table>');
                   1567:     if (($broadcast eq 'group') && ($group ne '') && (!$can_grp_broadcast)) {
1.38      raeburn  1568:         $r->print(&recipient_input_row($cdom,%lt));
1.95      raeburn  1569:     }
1.38      raeburn  1570:     if (($broadcast ne 'group') && ($broadcast ne 'upload')) {
1.1       albertel 1571: 	if ($replying) {
1.78      raeburn  1572:             if ($content{'noreplies'}) {
                   1573:                 $r->print('<tr><td>'.&mt('This message was designated by the sender not to allow replies.').'</td></tr></table></form>');
                   1574:                 return;
                   1575:             }
1.95      raeburn  1576:             $r->print('<tr><td colspan="3"><b>'.&mt('Replying to').'</b> ');
1.78      raeburn  1577:             if ($content{'replytoaddr'}) {
                   1578:                 my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
                   1579:                 if ($replytoname ne '' && $replytodom ne '') {
                   1580:                     $r->print(&Apache::loncommon::plainname($replytoname,
                   1581:                                  $replytodom).' ('.$replytoname.':'.
                   1582:                                  $replytodom.')');
                   1583:                     $r->print('<input type="hidden" name="recuname" value="'.
                   1584:                           $replytoname.'" />'.
                   1585:                           '<input type="hidden" name="recdomain" value="'.
                   1586:                           $replytodom.'" /></td></tr>');
                   1587: 
                   1588:                 } else {
                   1589:                     $r->print(&mt('The sender did not designate a reply to address for this message.').'</td></tr></table>');
                   1590:                     return;
                   1591:                 }
                   1592:             } else {
                   1593: 	        $r->print(&Apache::loncommon::aboutmewrapper(
1.1       albertel 1594: 							 &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
1.14      albertel 1595: 		      $content{'sendername'}.':'.
1.78      raeburn  1596: 		      $content{'senderdomain'}.')');
                   1597:                 $r->print('<input type="hidden" name="recuname" value="'.
                   1598: 		          $content{'sendername'}.'" />'.
                   1599: 		          '<input type="hidden" name="recdomain" value="'.
                   1600:                           $content{'senderdomain'}.'" /></td></tr>');
                   1601:             }
1.73      raeburn  1602:             if ($content{'recipid'}) {
1.95      raeburn  1603:                 my %recips;
                   1604:                 &retrieve_recips('replying',\%content,\%recips);
                   1605:                 if (ref($recips{'to'}) eq 'ARRAY') {
                   1606:                     if (@{$recips{'to'}} > 0) {
                   1607:                         my $replyall;
                   1608:                         if (@{$recips{'to'}} > 1) {
                   1609:                             $replyall = qq|
                   1610:  <span class="LC_nobreak">
                   1611:       <input type="button" value="check all"
                   1612:         onclick="javascript:checkAll(document.compemail.replying_to)" />
                   1613:         &nbsp;&nbsp;
                   1614:       <input type="button" value="uncheck all"
                   1615:         onclick="javascript:uncheckAll(document.compemail.replying_to)" />
                   1616:  </span>
                   1617: |;
                   1618:                         }
                   1619:                         my $tolist = join(' ',@{$recips{'to'}});
                   1620:                         $r->print('<tr><td colspan="3"><table><tr><td>'.&mt('[_1]Send reply[_2] to other recipients','<b>','</b>').':<br />'.$replyall.'</td><td>'.$tolist.'</td></tr></table></td></tr>');
                   1621:                     }
                   1622:                 }
                   1623:                 if (ref($recips{'cc'}) eq 'ARRAY') {
                   1624:                     if (@{$recips{'cc'}} > 0) {
                   1625:                         my $replyall;
                   1626:                         if (@{$recips{'cc'}} > 1) {
                   1627:                             $replyall = qq|
1.73      raeburn  1628:  <span class="LC_nobreak">
                   1629:       <input type="button" value="check all"
                   1630:         onclick="javascript:checkAll(document.compemail.replying_cc)" />
                   1631:         &nbsp;&nbsp;
                   1632:       <input type="button" value="uncheck all"
                   1633:         onclick="javascript:uncheckAll(document.compemail.replying_cc)" />
                   1634:  </span>
                   1635: |;
1.95      raeburn  1636:                         }
                   1637:                         my $cclist = join(' ',@{$recips{'cc'}});
                   1638:                         $r->print('<tr><td colspan="3"><table><tr><td>'.&mt('[_1]Cc[_2] to other copied recipients','<b>','</b>').':<br />'.$replyall.'</td><td>'.$cclist.'</td></tr></table></td></tr>');
                   1639:                     }
                   1640:                 }
                   1641:                 if ($content{'group'} ne '') {
                   1642:                     if (&check_group_priv($content{'group'})) {
                   1643:                         if (ref($recips{'group_cc_broadcast'}) eq 'ARRAY') {
                   1644:                             if (@{$recips{'group_cc_broadcast'}} > 0) {
                   1645:                                 my $replyall;
                   1646:                                 if (@{$recips{'group_cc_broadcast'}} > 1) {
                   1647:                                     $replyall = qq|
                   1648:  <span class="LC_nobreak">
                   1649:       <input type="button" value="check all"
                   1650:         onclick="javascript:checkAll(document.compemail.replying_groupcc)" />
                   1651:         &nbsp;&nbsp;
                   1652:       <input type="button" value="uncheck all"
                   1653:         onclick="javascript:uncheckAll(document.compemail.replying_groupcc)" />
                   1654:  </span>
                   1655: |;
                   1656:                                 }
                   1657:                                 my $groupcclist = join(' ',@{$recips{'group_cc_broadcast'}});
                   1658:                                 $r->print('<tr><td colspan="3"><table><tr><td>'.&mt('[_1]Cc[_2] to other copied group members','<b>','</b>').':<br />'.$replyall.'</td><td>'.$groupcclist.'<input type="hidden" name="group" value="'.$content{'group'}.'" /><input type="hidden" name="sendmode" value="group" /><input type="hidden" name="groupmail" value="cc" /></td></tr></table></td></tr>');
                   1659:                             }
                   1660:                         }
                   1661:                     }
1.73      raeburn  1662:                 }
                   1663:             }
1.1       albertel 1664: 	} else {
1.38      raeburn  1665:             $r->print(&recipient_input_row($defdom,%lt));
1.1       albertel 1666:         }
                   1667:     }
1.109     raeburn  1668:     my $latexHelp = &Apache::loncommon::helpLatexCheatsheet(undef,undef,1);
1.154     raeburn  1669:     my $textareaclass;
                   1670:     if (&Apache::lonhtmlcommon::htmlareabrowser()) {
                   1671:         $r->print(&Apache::lonhtmlcommon::htmlareaselectactive());
                   1672:         $textareaclass = 'class="LC_richDefaultOff"';
                   1673:     }
1.53      raeburn  1674:     my $subj_size;
                   1675:     if ($multiforward) {
                   1676:         $r->print(&additional_rec_row(\%lt));
                   1677:         $r->print('<tr><td colspan="2">'.
                   1678:                   &mt('Unless you choose otherwise:').'<ul><li>'.
1.166     raeburn  1679:         &mt("The subject in each forwarded message will be [_1]'Forwarding:'[_2] followed by the original subject.",'<i>','</i>').'</li><li>'.
1.165     bisitz   1680:         &mt("The message itself will begin with a first line: [_1]'Forwarded message from'[_2] followed by the original sender's name.",'<i>','</i>').'</li></ul></td></tr>');
1.94      bisitz   1681:         $func1='Forward'; # do not translate here!
1.53      raeburn  1682:         $dissub = &mt('Forwarding').': ';
                   1683:         $subj_size = '10';
                   1684:         my $extra = '&lt;'.&mt('original subject').'&gt;&nbsp;&nbsp;&nbsp;'.
                   1685:                     '<input type="radio" name="showorigsubj" value="1" checked="checked" />'.&mt('Yes').'&nbsp;<input type="radio" name="showorigsubj" value="0" />'.&mt('No');
                   1686:         $dismsg = &mt('Forwarded message from ').' ';
                   1687:         my $sender = &mt("sender's name");
                   1688:         $r->print(&msg_subject_row($dissub,\%lt,$subj_size,$extra));
                   1689:         $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>
                   1690: </table>
1.95      raeburn  1691: <br /><table>
                   1692: <tr><td align="left">'."\n".
                   1693: $latexHelp."<br />\n".
                   1694: &mt("Any new text to display before the text of the original messages:").'<br />'."\n".
1.154     raeburn  1695: '<textarea name="message" id="message" cols="80" rows="5" wrap="hard" $textareaclass></textarea>');
1.53      raeburn  1696:         my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
                   1697:         foreach my $msg (@to_forward) {
                   1698:             $r->print('<input type="hidden" name="delmark" value="'.$msg.'" />');
                   1699:         }
1.94      bisitz   1700:         $r->print(&submit_button_row($folder,$dismode,&mt($func1.' '.$func2{'msg'}),
1.53      raeburn  1701:                                      \%lt));
                   1702:     } elsif ($broadcast ne 'upload') {
                   1703:         $subj_size = '50';
                   1704:         $r->print(&additional_rec_row(\%lt));
1.78      raeburn  1705:         if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                   1706:             || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                   1707:                                         '/'.$env{'request.course.sec'})) {
                   1708:             $r->print(&reply_to_row(\%lt));
                   1709:         }
1.53      raeburn  1710:         $r->print(&msg_subject_row($dissub,\%lt,$subj_size));
                   1711:         $r->print(<<"ENDCOMP");
1.95      raeburn  1712: $attachrow
                   1713: </table><br />
1.117     bisitz   1714: $latexHelp<br />
1.154     raeburn  1715: <textarea name="message" id="message" cols="80" rows="15" wrap="hard" $textareaclass>$dismsg
                   1716: </textarea>
                   1717: <br />
1.95      raeburn  1718: $sendmode
1.1       albertel 1719: $dispcrit
                   1720: $disbase
                   1721: ENDCOMP
1.97      schafran 1722:         $r->print(&submit_button_row($folder,$dismode,&mt($func1.' '.$func2{'ma'}),
1.95      raeburn  1723:                                      \%lt,$hasfloat,$group));
1.53      raeburn  1724:         $r->print($citation);
1.38      raeburn  1725:         if (exists($env{'form.ref'})) {
                   1726:             $r->print('<input type="hidden" name="ref" value="'.
                   1727:                       $env{'form.ref'}.'" />');
                   1728:         }
                   1729:         if (exists($env{'form.group'})) {
                   1730:             $r->print('<input type="hidden" name="group" value="'.
                   1731:                       $env{'form.group'}.'" />');
                   1732:         }
1.1       albertel 1733:     } else { # $broadcast is 'upload'
1.50      raeburn  1734: 	$r->print(<<ENDBLOCK);
1.1       albertel 1735: <input type="hidden" name="sendmode" value="upload" />
                   1736: <input type="hidden" name="send" value="on" />
1.50      raeburn  1737: <h3>$lt{'gen'}</h3>
1.1       albertel 1738: <p>
                   1739: Subject: <input type="text" size="50" name="subject" />
                   1740: </p>
1.50      raeburn  1741: <p>$lt{'gmt'}:<br />
1.154     raeburn  1742: <textarea name="message" id="message" cols="60" rows="10" wrap="hard" $textareaclass>$dismsg
                   1743: </textarea></p>
1.1       albertel 1744: <p>
1.50      raeburn  1745: $lt{'tff'}:
                   1746: ENDBLOCK
                   1747:        $r->print('
                   1748: <pre>'."\n".
                   1749: &mt('username1:domain1: text')."\n".
                   1750: &mt('username2:domain2: text')."\n".
                   1751: &mt('username3:domain1: text')."\n".
                   1752: '</pre>
1.1       albertel 1753: </p>
                   1754: <p>
1.164     bisitz   1755: '.&mt('The messages will be assembled from all lines with the respective [_1][_2]username:domain[_3], and appended to the general message text.','<br />','<tt>','</tt>'));
1.50      raeburn  1756:         $r->print(<<ENDUPLOAD);
                   1757: </p>
1.1       albertel 1758: <p>
                   1759: <input type="file" name="upfile" size="40" /></p><p>
                   1760: $dispcrit
1.50      raeburn  1761: <input type="submit" value="$lt{'uas'}" /></p>
1.1       albertel 1762: ENDUPLOAD
                   1763:     }
1.36      albertel 1764:     if ($env{'form.displayedcrit'}) {
                   1765: 	$r->print('<input type="hidden" name="displayedcrit" value="true" />');
                   1766:     }
1.95      raeburn  1767:     $r->print('</form>');
                   1768:     if ($hasfloat) {
1.154     raeburn  1769:         $r->print('</div><div class="LC_clear_float_footer"></div>');
1.95      raeburn  1770:     }
                   1771:     $r->print(&generate_preview_form);
                   1772: }
                   1773: 
                   1774: sub check_group_priv {
                   1775:     my ($group) = @_;
                   1776:     my $cid = $env{'request.course.id'};
                   1777:     my $sec = $env{'request.course.sec'};
                   1778:     return if !$cid;
                   1779:     my $can_broadcast = &Apache::lonnet::allowed('sgb',$cid.'/'.$group);
                   1780:     my $viewgrps = &Apache::lonnet::allowed('vcg',$cid.($sec?'/'.$sec:''));
                   1781:     my $editgrps = &Apache::lonnet::allowed('mdg',$cid.($sec?'/'.$sec:''));
                   1782:     if ($viewgrps || $editgrps || $can_broadcast) {
                   1783:         return 1;
                   1784:     }
                   1785:     return;
1.1       albertel 1786: }
                   1787: 
1.38      raeburn  1788: sub recipient_input_row {
                   1789:     my ($dom,%lt) = @_;
                   1790:     my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain');
                   1791:     my $selectlink=
                   1792:       &Apache::loncommon::selectstudent_link('compemail','recuname',
                   1793:                                              'recdomain');
                   1794:     my $output = <<"ENDREC";
1.95      raeburn  1795: <tr><td colspan="3"><span class="LC_nobreak"><b>$lt{'to'}</b> $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  1796: ENDREC
                   1797:     return $output;
                   1798: }
                   1799: 
1.78      raeburn  1800: sub reply_to_row {
                   1801:     my ($lt) = @_;
                   1802:     my $radioyes = &mt('Yes');
                   1803:     my $radiono = &mt('No');
                   1804:     my $output = <<"ENDREP";
1.95      raeburn  1805: <tr><td colspan="3"><span class="LC_nobreak"><b>$lt->{'ar'}</b>:<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>
1.78      raeburn  1806: ENDREP
                   1807:     return $output;
                   1808: }
                   1809: 
1.53      raeburn  1810: sub additional_rec_row {
                   1811:     my ($lt) = @_;
1.73      raeburn  1812:     my $cc = &mt('Cc:');
1.85      bisitz   1813:     my $bcc = &mt('Bcc:');
                   1814:     my $exmpl = &mt('username:domain,username:domain,...'); 
1.53      raeburn  1815:     my $output = <<"ENDADD";
1.125     bisitz   1816: <tr><td colspan="3"><fieldset id="LC_additionalrecips"><legend>$lt->{'ad'} <tt>($exmpl)</tt></legend><table>
1.95      raeburn  1817: <tr><td>&nbsp;</td><td>$lt->{'to'}</td><td><input type="text" size="50" name="additionalrec_to" /></td></tr>
                   1818: <tr><td>&nbsp;</td><td>$cc</td><td><input type="text" size="50" name="additionalrec_cc" /></td></tr> 
1.110     raeburn  1819: <tr><td>&nbsp;</td><td>$bcc</td><td><input type="text" size="50" name="additionalrec_bcc" /></td></tr></table></fieldset></td></tr>
1.53      raeburn  1820: ENDADD
                   1821:     return $output;
                   1822: }
                   1823: 
                   1824: sub submit_button_row {
1.95      raeburn  1825:     my ($folder,$dismode,$sendtext,$lt,$is_crsform,$group) = @_;
                   1826:     my $pre=&mt("Show Preview and Check Spelling");
1.98      schafran 1827:     my $value=&mt('Send');
1.95      raeburn  1828:     my $prevbutton = '<input type="button" name="preview" value="'.$pre.'" onclick="if (typeof(document.compemail.onsubmit)=='."'function'".') {document.compemail.onsubmit();};document.preview.comment.value=document.compemail.message.value;document.preview.subject.value=document.compemail.subject.value;document.preview.submit();" />';
                   1829:     my $output = qq|
1.53      raeburn  1830: <input type="hidden" name="folder" value="$folder" />
1.95      raeburn  1831: <input type="hidden" name="dismode" value="$dismode" />|;
                   1832:     if ($is_crsform) {
                   1833:         $output .= '<input type="hidden" name="courserecips" value="" />'."\n";
                   1834:         if ($group ne '') {
                   1835:             $output .= '<input type="hidden" name="groupmail" value="" />'."\n";
                   1836:         }
                   1837:     }
                   1838:     $output .= qq|
                   1839: <table><tr><td align="left">
1.98      schafran 1840: <input type="submit" name="send" value="$value" title="$sendtext" />
1.95      raeburn  1841: <input type="submit" name="cancel" value="$lt->{'ca'}" />
                   1842: </td><td width="60">&nbsp;</td><td align="right">$prevbutton</td></tr></table>
1.53      raeburn  1843: |;
                   1844:     return $output;
                   1845: }
                   1846: 
                   1847: sub msg_subject_row {
                   1848:     my ($dissub,$lt,$subj_size,$extra) = @_;
1.95      raeburn  1849:     my $output = '<tr><td colspan="3"><b>'.$lt->{'sb'}.'</b>:&nbsp;<input type="text" size="'.
1.53      raeburn  1850:                  $subj_size.'" name="subject" value="'.$dissub.'" />'.$extra.
                   1851:                  '</td></tr>';
                   1852:     return $output;
                   1853: }
                   1854: 
1.95      raeburn  1855: sub generate_preview_form {
                   1856:     my $prevbutton = (<<ENDPREVIEW);
                   1857: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
                   1858: <input type="hidden" name="subject" />
                   1859: <input type="hidden" name="comment" />
                   1860: </form>
                   1861: ENDPREVIEW
                   1862: }
                   1863: 
                   1864: # ---------------------------------------------------- Display all face to face
                   1865: 
1.1       albertel 1866: sub retrieve_instructor_comments {
                   1867:     my ($user,$domain)=@_;
                   1868:     my $target=$env{'form.grade_target'};
                   1869:     if (! $env{'request.course.id'}) { return; }
1.49      albertel 1870:     if (! &Apache::lonnet::allowed('dff',$env{'request.course.id'})
                   1871: 	&& ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1       albertel 1872: 				      '/'.$env{'request.course.sec'})) {
                   1873: 	return;
                   1874:     }
                   1875:     my %records=&Apache::lonnet::dump('nohist_email',
                   1876: 			 $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1877: 			 $env{'course.'.$env{'request.course.id'}.'.num'},
                   1878:                          '%255b'.$user.'%253a'.$domain.'%255d');
                   1879:     my $result='';
1.42      raeburn  1880:     foreach my $key (sort(keys(%records))) {
                   1881:         my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1       albertel 1882:         next if ($content{'senderdomain'} eq '');
                   1883:         next if ($content{'subject'} !~ /^Record/);
                   1884: 	# &Apache::lonfeedback::newline_to_br(\$content{'message'});
                   1885: 	$result.='Recorded by '.
1.14      albertel 1886:             $content{'sendername'}.':'.$content{'senderdomain'}."\n";
1.1       albertel 1887:         $result.=
                   1888:             &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
                   1889:      }
                   1890:     return $result;
                   1891: }
                   1892: 
                   1893: sub disfacetoface {
1.136     amueller 1894:     my ($r,$user,$domain,$target)=@_;
1.145     raeburn  1895:     if ($target eq '') {
                   1896:         $target=$env{'form.grade_target'};
                   1897:     }
1.1       albertel 1898:     unless ($env{'request.course.id'}) { return; }
1.49      albertel 1899:     if  (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
                   1900: 	 && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1       albertel 1901: 				       '/'.$env{'request.course.sec'})) {
1.50      raeburn  1902: 	$r->print(&mt('Not allowed'));
1.1       albertel 1903: 	return;
                   1904:     }
                   1905:     my %records=&Apache::lonnet::dump('nohist_email',
                   1906: 			 $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1907: 			 $env{'course.'.$env{'request.course.id'}.'.num'},
                   1908:                          '%255b'.$user.'%253a'.$domain.'%255d');
1.177     raeburn  1909:     my $result='';
1.42      raeburn  1910:     foreach my $key (sort(keys(%records))) {
                   1911:         my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1       albertel 1912:         next if ($content{'senderdomain'} eq '');
1.139     faziophi 1913:     if (!&Apache::lonfeedback::contains_block_html($content{'message'})) {
                   1914: 		&Apache::lonfeedback::newline_to_br(\$content{'message'});
                   1915: 	}
1.1       albertel 1916:         if ($content{'subject'}=~/^Record/) {
                   1917: 	    $result.='<h3>'.&mt('Record').'</h3>';
                   1918:         } elsif ($content{'subject'}=~/^Broadcast/) {
                   1919:             $result .='<h3>'.&mt('Broadcast Message').'</h3>';
                   1920:             if ($content{'subject'}=~/^Broadcast\./) {
                   1921:                 if (defined($content{'coursemsgid'})) {
1.29      www      1922:                     my $crsmsgid = &escape($content{'coursemsgid'});
1.1       albertel 1923:                     my $broadcast_message = &general_message($crsmsgid);
                   1924:                     $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$broadcast_message;
                   1925:                 } else {
                   1926:                     %content=&Apache::lonmsg::unpackagemsg($content{'message'});
                   1927:                     $content{'message'} =
                   1928:                     '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
                   1929:                     $content{'message'};
                   1930:                 }
1.70      raeburn  1931:             }
                   1932:         } elsif ($content{'subject'}=~/^Archive/) {
                   1933:             $result.='<h3>'.&mt('Archived Message').'</h3>';
                   1934:             if (defined($content{'coursemsgid'})) {
                   1935:                 my $crsmsgid = &escape($content{'coursemsgid'});
                   1936:                 my $archive_message = &general_message($crsmsgid);
                   1937:                 $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$archive_message;
                   1938:             } else {
                   1939:                 %content=&Apache::lonmsg::unpackagemsg($content{'message'});
                   1940:                 $content{'message'} =
1.170     bisitz   1941:                 '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1.70      raeburn  1942:                 $content{'message'};
                   1943:             }
1.1       albertel 1944:         } else {
                   1945:             $result.='<h3>'.&mt('Critical Message').'</h3>';
                   1946:             if (defined($content{'coursemsgid'})) {
1.29      www      1947:                 my $crsmsgid=&escape($content{'coursemsgid'});
1.1       albertel 1948:                 my $critical_message = &general_message($crsmsgid);
                   1949:                 $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$critical_message;
                   1950:             } else {
                   1951:                 %content=&Apache::lonmsg::unpackagemsg($content{'message'});
                   1952:                 $content{'message'}=
                   1953:                 '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
                   1954: 		$content{'message'};
                   1955:             }
                   1956:         }
                   1957:         $result.=&mt('By').': <b>'.
                   1958: &Apache::loncommon::aboutmewrapper(
                   1959:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14      albertel 1960: $content{'sendername'}.':'.
1.1       albertel 1961:             $content{'senderdomain'}.') '.$content{'time'}.
                   1962:             '<br /><pre>'.
                   1963:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
                   1964: 	      '</pre>';
                   1965:      }
                   1966:     # Check to see if there were any messages.
                   1967:     if ($result eq '') {
1.106     riegler  1968:         my $lctype = &mt(lc(&Apache::loncommon::course_type()));
1.1       albertel 1969: 	if ($target ne 'tex') { 
1.174     bisitz   1970: 	    $r->print("<p><b>".&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this '.$lctype.'.')."</b></p>");
1.1       albertel 1971: 	} else {
1.174     bisitz   1972: 	    $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this '.$lctype.'.').'}\\\\');
1.1       albertel 1973: 	}
1.177     raeburn  1974:     } elsif ($target eq 'tex') {
                   1975:         $r->print(&Apache::lonxml::xmlparse($r,$target,$result));
1.1       albertel 1976:     } else {
1.177     raeburn  1977:         $r->print('<div>'.$result.'</div>');
                   1978:     }
1.1       albertel 1979: }
                   1980: 
                   1981: sub general_message {
                   1982:     my ($crsmsgid) = @_;
                   1983:     my %general_content;
                   1984:     if ($crsmsgid) { 
                   1985:         my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid],
                   1986:                            $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1987:                            $env{'course.'.$env{'request.course.id'}.'.num'});
                   1988:         %general_content = &Apache::lonmsg::unpackagemsg($course_content{$crsmsgid});
                   1989:     }
                   1990:     return $general_content{'message'};
                   1991: }
                   1992: 
                   1993: # ---------------------------------------------------------------- Face to face
                   1994: 
                   1995: sub facetoface {
                   1996:     my ($r,$stage)=@_;
1.49      albertel 1997:     if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
                   1998: 	&& ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1       albertel 1999: 				      '/'.$env{'request.course.sec'})) {
1.50      raeburn  2000: 	$r->print(&mt('Not allowed'));
1.1       albertel 2001: 	return;
                   2002:     }
1.33      albertel 2003:     my $crstype = &Apache::loncommon::course_type();
1.128     raeburn  2004:     my $leaders = ($crstype eq 'Community') ? 'coordinators and leaders'
                   2005:                                             : 'faculty and staff';
1.1       albertel 2006:     &printheader($r,
                   2007: 		 '/adm/email?recordftf=query',
1.70      raeburn  2008: 		 "User Notes, Face-to-Face, Critical Messages, Broadcast Messages, Archived Messages");
1.1       albertel 2009: # from query string
                   2010: 
                   2011:     if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
                   2012:     if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
                   2013: 
                   2014:     my $defdom=$env{'user.domain'};
                   2015: # already filled in
                   2016:     if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
                   2017: # generate output
                   2018:     my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
                   2019:     my $stdbrws = &Apache::loncommon::selectstudent_link
                   2020: 	('stdselect','recuname','recdomain');
                   2021:     my %lt=&Apache::lonlocal::texthash('user' => 'Username',
                   2022: 				       'dom' => 'Domain',
1.70      raeburn  2023: 				       'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, Broadcast Messages and Archived Messages in $crstype",
1.1       albertel 2024: 				       'subm' => 'Retrieve discussion and message records',
1.30      raeburn  2025: 				       'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')',
1.1       albertel 2026: 				       'post' => 'Post this Record');
1.123     bisitz   2027: 
                   2028:     $r->print('<h2>'.$lt{'head'}.'</h2>'
                   2029:              .'<form method="post" action="/adm/email" name="stdselect">'
                   2030:              .'<input type="hidden" name="recordftf" value="retrieve" />'
                   2031:              .&Apache::lonhtmlcommon::start_pick_box()
                   2032:              .&Apache::lonhtmlcommon::row_title($lt{'user'})
                   2033:              .'<input type="text" size="12" name="recuname" value="'.$env{'form.recuname'}.'" />'
                   2034:              .' '.$stdbrws
                   2035:              .&Apache::lonhtmlcommon::row_closure()
                   2036:              .&Apache::lonhtmlcommon::row_title($lt{'dom'})
                   2037:              .$domform
                   2038:              .&Apache::lonhtmlcommon::row_closure(1)
                   2039:              .&Apache::lonhtmlcommon::end_pick_box()
                   2040:              .'<br />'
                   2041:              .'<input type="submit" value="'.$lt{'subm'}.'" />'
1.150     raeburn  2042:              .'</form>'
1.123     bisitz   2043:     );
                   2044: 
1.1       albertel 2045:     if (($stage ne 'query') &&
                   2046:         ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
                   2047:         chomp($env{'form.newrecord'});
                   2048:         if ($env{'form.newrecord'}) {
1.31      albertel 2049: 	    &Apache::lonmsg::store_instructor_comment($env{'form.newrecord'},
                   2050: 						      $env{'form.recuname'},
                   2051: 						      $env{'form.recdomain'});
1.1       albertel 2052:         }
1.123     bisitz   2053:         my $aboutmelink=&Apache::loncommon::aboutmewrapper(
                   2054:                             &Apache::loncommon::plainname($env{'form.recuname'}
                   2055:                                                          ,$env{'form.recdomain'})
                   2056:                            ,$env{'form.recuname'},$env{'form.recdomain'});
                   2057:         $r->print('<hr />'
                   2058:                  .'<h2>'
                   2059:                  .&mt('Discussion and message records for [_1] ([_2])'
                   2060:                      ,$aboutmelink
                   2061:                      ,$env{'form.recuname'}.':'.$env{'form.recdomain'})
1.161     bisitz   2062:                  .'</h2>'
1.123     bisitz   2063:        );
1.1       albertel 2064:         &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
                   2065: 	$r->print(<<ENDRHEAD);
                   2066: <form method="post" action="/adm/email">
                   2067: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
                   2068: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
                   2069: ENDRHEAD
                   2070:         $r->print(<<ENDBFORM);
                   2071: <hr />$lt{'newr'}<br />
                   2072: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
                   2073: <br />
                   2074: <input type="hidden" name="recordftf" value="post" />
                   2075: <input type="submit" value="$lt{'post'}" />
                   2076: </form>
                   2077: ENDBFORM
                   2078:     }
                   2079: }
                   2080: 
                   2081: # ----------------------------------------------------------- Display a message
                   2082: 
                   2083: sub displaymessage {
1.53      raeburn  2084:     my ($r,$msgid,$folder,$msgstatus)=@_;
1.1       albertel 2085:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
                   2086:     my %blocked = ();
                   2087:     my %setters = ();
                   2088:     my $numblocked = 0;
1.33      albertel 2089:     my $crstype = &Apache::loncommon::course_type();
1.30      raeburn  2090: 
1.1       albertel 2091: # info to generate "next" and "previous" buttons and check if message is blocked
1.44      raeburn  2092:     my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53      raeburn  2093:     my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1       albertel 2094:     if ( $blocked{$msgid} eq 'ON' ) {
                   2095:         &printheader($r,'/adm/email',&mt('Display a Message'));
1.129     kalberla 2096:         #$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.'));
1.130     kalberla 2097:         my($blocked, $blocktext) = &Apache::loncommon::blocking_status("com");
1.129     kalberla 2098:         $r->print("<br />".$blocktext);
1.1       albertel 2099:         return;
                   2100:     }
1.59      raeburn  2101:     if ($msgstatus eq '') {
                   2102:         &statuschange($msgid,'read',$folder);
                   2103:     }
1.1       albertel 2104:     my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
                   2105:     my %content=&Apache::lonmsg::unpackagemsg($message{$msgid});
                   2106:     my $counter=0;
1.29      www      2107:     my $escmsgid=&escape($msgid);
1.1       albertel 2108:     foreach (@messages) {
                   2109: 	if ($_->[5] eq $escmsgid){
                   2110: 	    last;
                   2111: 	}
                   2112: 	$counter++;
                   2113:     }
1.82      albertel 2114: 
                   2115:     my $see_anonymous;
                   2116:     my $from_student = 0;
                   2117:     if ($env{'request.course.id'} eq $content{'courseid'}) {
                   2118: 	my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   2119: 	my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   2120: 	my $username = $content{'sendername'}.':'.$content{'senderdomain'};
                   2121: 	my %classlist_entry =
                   2122: 	    &Apache::lonnet::get('classlist',[$username],$cdom,$cnum);
                   2123: 	if (exists($classlist_entry{$username})) {
                   2124: 	    $from_student = 1;
                   2125: 	    $see_anonymous = &Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
                   2126: 	}
                   2127:     }
                   2128: 
                   2129: 
1.1       albertel 2130:     my $number_of_messages = scalar(@messages); #subtract 1 for last index
                   2131: # start output
1.29      www      2132:     &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'});
1.101     bisitz   2133: 
                   2134: # Prepare available functions
1.119     bisitz   2135:     my @functionlist;
1.78      raeburn  2136:     if (!$content{'noreplies'}) {
1.119     bisitz   2137:         push(@functionlist,'<a href="/adm/email?replyto='.&escape($msgid).$sqs.'">'
1.101     bisitz   2138:                      .&mt('Reply')
1.119     bisitz   2139:                      .'</a>');
1.101     bisitz   2140:     }
1.119     bisitz   2141:     push(@functionlist,'<a href="/adm/email?forward='.&escape($msgid).$sqs.'">'
1.101     bisitz   2142:                   .&mt('Forward')
1.119     bisitz   2143:                   .'</a>');
                   2144:     push(@functionlist,'<a href="/adm/email?markunread='.&escape($msgid).$sqs.'">'
1.101     bisitz   2145:                   .&mt('Mark Unread')
1.119     bisitz   2146:                   .'</a>');
                   2147:     push(@functionlist,'<a href="/adm/email?markdel='.&escape($msgid).$sqs.'">'
1.101     bisitz   2148:                   .&mt('Delete')
1.119     bisitz   2149:                   .'</a>');
1.162     bisitz   2150: 
                   2151: # Prepare available navigation
                   2152:     my @navigationlist;
1.1       albertel 2153:     if ($counter > 0){
1.162     bisitz   2154:         push(@navigationlist,'<a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.'">'
1.119     bisitz   2155:                           .&mt('Previous')
                   2156:                           .'</a>');
1.1       albertel 2157:     }
                   2158:     if ($counter < $number_of_messages - 1){
1.162     bisitz   2159:         push(@navigationlist,'<a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.'">'
1.119     bisitz   2160:                           .&mt('Next')
                   2161:                           .'</a>');
1.101     bisitz   2162:     }
1.162     bisitz   2163:     push(@navigationlist,'<a href="/adm/email?'.$sqs.'">'
                   2164:                   .&mt('Back to Folder Display')
                   2165:                   .'</a>');
1.101     bisitz   2166: 
                   2167: # Prepare available actions
1.59      raeburn  2168:     my $symb;
                   2169:     if (defined($content{'symb'})) {
                   2170:         $symb = $content{'symb'};
                   2171:     } elsif (defined($content{'baseurl'})) {
                   2172:         $symb=&Apache::lonnet::symbread($content{'baseurl'});
                   2173:     }
1.162     bisitz   2174:     my @actionlist;
1.1       albertel 2175:     if ($env{'user.adv'}) {
1.101     bisitz   2176: 
1.181.2.1! raeburn  2177: 	if (($env{'request.course.id'}) && ($from_student) &&
        !          2178:             (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
1.119     bisitz   2179: 		push(@actionlist,&Apache::loncommon::track_student_link(
1.171     bisitz   2180:                                       'View recent activity'
1.119     bisitz   2181:                                      ,$content{'sendername'}
                   2182:                                      ,$content{'senderdomain'}
                   2183:                                      ,'check'));
1.90      bisitz   2184: 	}
1.1       albertel 2185: 	if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
1.119     bisitz   2186: 	    push(@actionlist,&Apache::loncommon::pprmlink(
                   2187:                                   &mt('Set/Change parameters')
                   2188:                                      ,$content{'sendername'}
                   2189:                                      ,$content{'senderdomain'}
                   2190:                                      ,$symb
                   2191:                                      ,'check'));
1.1       albertel 2192: 	}
                   2193: 	if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
1.119     bisitz   2194: 	    push(@actionlist,&Apache::loncommon::pgrdlink(
                   2195:                                  &mt('Set/Change grades')
                   2196:                                      ,$content{'sendername'}
                   2197:                                      ,$content{'senderdomain'}
                   2198:                                      ,$symb
                   2199:                                      ,'check'));
1.90      bisitz   2200: 	}
1.126     bisitz   2201:     }
                   2202: 
1.162     bisitz   2203: # Print functionlist, navigationlist, and actionlist in page header
1.126     bisitz   2204:         my $functions='<div class="LC_columnSection">';
1.101     bisitz   2205: 
1.126     bisitz   2206:         # Functionlist
                   2207:         $functions.=&Apache::lonhtmlcommon::start_funclist();
                   2208:         foreach my $item (@functionlist) {
                   2209:             $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
                   2210:         }
                   2211:         $functions .= &Apache::lonhtmlcommon::end_funclist();
                   2212: 
1.162     bisitz   2213:         # Navigationlist
                   2214:         $functions.=&Apache::lonhtmlcommon::start_funclist(
                   2215:                     &mt('Navigation'));
                   2216:         foreach my $item (@navigationlist) {
                   2217:             $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
                   2218:         }
                   2219:         $functions .= &Apache::lonhtmlcommon::end_funclist();
                   2220: 
1.126     bisitz   2221:         # Actionlist
1.119     bisitz   2222:         if (@actionlist) {
1.162     bisitz   2223:             $functions.=&Apache::lonhtmlcommon::start_funclist(
                   2224:                             &mt('Currently available actions (will open extra window)'));
1.119     bisitz   2225:             foreach my $item (@actionlist) {
1.126     bisitz   2226:                 $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
1.119     bisitz   2227:             }
1.126     bisitz   2228:             $functions.=&Apache::lonhtmlcommon::end_funclist();
1.90      bisitz   2229:         }
1.126     bisitz   2230: 
                   2231:         $functions.='</div>';
                   2232:         $r->print(&Apache::loncommon::head_subbox($functions));
                   2233: 
1.101     bisitz   2234: 
1.95      raeburn  2235:     my ($tonum,$tolist,$cclist,$bcclist,$groupcclist,%recipients);
                   2236:     if ($content{'recipid'}) {
                   2237:         $tonum = &retrieve_recips('display',\%content,\%recipients);
                   2238:         if (ref($recipients{'cc'}) eq 'ARRAY') {
                   2239:             $cclist = join(', ',@{$recipients{'cc'}});
                   2240:         }
                   2241:         if (ref($recipients{'to'}) eq 'ARRAY') {
                   2242:             $tolist = join(', ',@{$recipients{'to'}});
                   2243:         }
                   2244:         if (ref($recipients{'bcc'}) eq 'ARRAY') {
                   2245:             $bcclist = join(', ',@{$recipients{'bcc'}});
                   2246:         }
                   2247:     }
1.107     raeburn  2248: 
                   2249:     my $broadcast_link;
                   2250:     if (($content{'courseid'}) && ($content{'recipid'} &&
                   2251:         (ref($recipients{'course_broadcast'}) eq 'ARRAY') ||
                   2252:         (ref($recipients{'group_cc_broadcast'}) eq 'ARRAY') ||
                   2253:         (ref($recipients{'group_bcc_broadcast'}) eq 'ARRAY'))) {
                   2254:         $broadcast_link = &recipients_link($r,\%content,\%recipients);
                   2255:     }
                   2256: 
                   2257:     if (((!$tolist) && (!$broadcast_link)) && ref($content{'recuser'}) eq 'ARRAY') {
1.95      raeburn  2258:         my @recipients;
1.73      raeburn  2259:         for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
                   2260:             $recipients[$i] =  &Apache::loncommon::aboutmewrapper(
                   2261:                &Apache::loncommon::plainname($content{'recuser'}[$i],
1.1       albertel 2262:                                       $content{'recdomain'}[$i]),
1.73      raeburn  2263:                   $content{'recuser'}[$i],$content{'recdomain'}[$i]).
1.95      raeburn  2264:            ' ('.$content{'recuser'}[$i].':'.$content{'recdomain'}[$i].') ';
1.73      raeburn  2265:         }
1.95      raeburn  2266:         $tolist = join(', ',@recipients);
1.73      raeburn  2267:     }
1.59      raeburn  2268:     my ($restitle,$baseurl,$refers_to);
                   2269:     if (defined($content{'resource_title'})) {
                   2270:         $restitle = $content{'resource_title'};
                   2271:     } else {
                   2272:         if (defined($content{'baseurl'})) {
                   2273:             $restitle = &Apache::lonnet::gettitle($content{'baseurl'});
                   2274:         }
                   2275:     }
                   2276:     if (defined($content{'baseurl'})) {
                   2277:         $baseurl = &Apache::lonenc::check_encrypt($content{'baseurl'});
                   2278:     }
1.104     raeburn  2279:     $r->print('<div class="LC_clear_float_footer">');
1.82      albertel 2280:     if ($from_student && $see_anonymous ) {
1.104     raeburn  2281: 	$r->print(&Apache::loncommon::student_image_tag($content{'senderdomain'},$content{'sendername'}).'</br>');
1.82      albertel 2282:     }
                   2283: 
1.91      bisitz   2284:     # Display LON-CAPA Message (Start)
                   2285:     # Subject
1.104     raeburn  2286:     $r->print('</div>'
1.91      bisitz   2287:              .&Apache::lonhtmlcommon::start_pick_box()
                   2288:              .&Apache::lonhtmlcommon::row_title(&mt('Subject'))
                   2289:              .$content{'subject'}
                   2290:              .&Apache::lonhtmlcommon::row_closure()
                   2291:     );
1.73      raeburn  2292:     if ($folder eq 'sent') {
1.91      bisitz   2293:         # To
1.107     raeburn  2294:         if ($tolist) {
                   2295:             $r->print(&Apache::lonhtmlcommon::row_title(&mt('To'))
                   2296:                      .$tolist
                   2297:                      .&Apache::lonhtmlcommon::row_closure()
                   2298:             );
                   2299:         }
1.95      raeburn  2300:         if ($cclist) {
                   2301:             $r->print(&Apache::lonhtmlcommon::row_title(&mt('Cc'))
                   2302:                      .$cclist
                   2303:                      .&Apache::lonhtmlcommon::row_closure()
                   2304:             );
                   2305:         }
                   2306:         if ($bcclist) {
                   2307:             $r->print(&Apache::lonhtmlcommon::row_title(&mt('Bcc'))
                   2308:                      .$bcclist
                   2309:                      .&Apache::lonhtmlcommon::row_closure()
                   2310:             );
                   2311:         }
                   2312:         if (($content{'courseid'}) && ($content{'recipid'})) {
                   2313:             my %broadcast_types = 
                   2314:                 &Apache::lonlocal::texthash (
                   2315:                     course_broadcast    => 'Broadcast to', 
                   2316:                     group_cc_broadcast  => 'Cc to group',
                   2317:                     group_bcc_broadcast => 'Bcc to group',
                   2318:                 );                   
                   2319:             foreach my $type (sort(keys(%broadcast_types))) {
                   2320:                 if (ref($recipients{$type}) eq 'ARRAY') {
                   2321:                     my $num = @{$recipients{$type}};
                   2322:                     my $broadcastlist = join(', ',@{$recipients{$type}});
                   2323:                     if ($broadcastlist && $broadcast_link) {
                   2324:                         if ($type eq 'group_cc_broadcast') {
                   2325:                             $groupcclist = $broadcastlist;
                   2326:                         }
                   2327:                         $r->print(&Apache::lonhtmlcommon::row_title(
                   2328:                                             $broadcast_types{$type})
                   2329:                                   .&mt('[quant,_1,recipient]',$num)
                   2330:                                   .' <a href="javascript:showBroadcastList();">['
                   2331:                                   .&mt('Show').']</a>' 
                   2332:                                   .&Apache::lonhtmlcommon::row_closure());
                   2333:                     }
                   2334:                 }
                   2335:             }
                   2336:         }
1.78      raeburn  2337:         if ($content{'replytoaddr'}) {
                   2338:             my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
                   2339:             if ($replytoname ne '' && $replytodom ne '') {
1.91      bisitz   2340:                 $r->print(&Apache::lonhtmlcommon::row_title(&mt('Reply To'))
1.95      raeburn  2341:                          .$replytoname.':'.$replytodom
1.91      bisitz   2342:                          .&Apache::lonhtmlcommon::row_closure()
                   2343:                 );
1.78      raeburn  2344:             }
                   2345:         }
1.73      raeburn  2346:     } else {
1.91      bisitz   2347:         # From, Reply
                   2348:         $r->print(&Apache::lonhtmlcommon::row_title(&mt('From'))
                   2349:                  .&Apache::loncommon::aboutmewrapper(
                   2350:                      &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
                   2351:                                                  $content{'sendername'},$content{'senderdomain'})
                   2352:         );
1.78      raeburn  2353:         if ($content{'noreplies'}) {
1.91      bisitz   2354:             $r->print(' ('.&mt('No replies to sender').')'
                   2355:                      .&Apache::lonhtmlcommon::row_closure()
1.95      raeburn  2356:             );
1.78      raeburn  2357:         } else {
                   2358:             if ($content{'replytoaddr'}) {
                   2359:                 my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
                   2360:                 if ($replytoname ne '' && $replytodom ne '') {
1.91      bisitz   2361:                     $r->print(&Apache::lonhtmlcommon::row_closure()
                   2362:                              .&Apache::lonhtmlcommon::row_title(&mt('Reply To'))
1.95      raeburn  2363:                              .$replytoname.':'.$replytodom
1.91      bisitz   2364:                              .&Apache::lonhtmlcommon::row_closure()
                   2365:                     );
                   2366:                 } else {
                   2367:                     $r->print(&Apache::lonhtmlcommon::row_closure());
1.78      raeburn  2368:                 }
                   2369:             } else {
1.95      raeburn  2370:                 $r->print(' ('.$content{'sendername'}.':'.$content{'senderdomain'}.') '
1.91      bisitz   2371:                          .&Apache::lonhtmlcommon::row_closure()
                   2372:                 );
1.78      raeburn  2373:             }
1.95      raeburn  2374:             if ($tonum && $tolist) {
                   2375:                 $r->print(&Apache::lonhtmlcommon::row_title(&mt('To'))
                   2376:                          .$tolist
                   2377:                          .&Apache::lonhtmlcommon::row_closure()
                   2378:                     );
                   2379:             }
                   2380:             if ($cclist) { 
1.91      bisitz   2381:                 $r->print(&Apache::lonhtmlcommon::row_title(&mt('Cc'))
                   2382:                          .$cclist
                   2383:                          .&Apache::lonhtmlcommon::row_closure()
                   2384:                     );
1.95      raeburn  2385:             }
                   2386:             if ($content{'group'} ne '') {
                   2387:                 if (&check_group_priv($content{'group'})) {
1.155     raeburn  2388:                     if (ref($recipients{'group_cc_broadcast'}) eq 'ARRAY') { 
                   2389:                         $groupcclist = join(', ',@{$recipients{'group_cc_broadcast'}});
                   2390:                         if ($groupcclist) {
                   2391:                             $r->print(&Apache::lonhtmlcommon::row_title(&mt('Group Cc'))
                   2392:                                      .$groupcclist
                   2393:                                      .&Apache::lonhtmlcommon::row_closure()
                   2394:                             );
                   2395:                         }
1.95      raeburn  2396:                     }
                   2397:                 }
1.78      raeburn  2398:             }
1.91      bisitz   2399:         }
1.73      raeburn  2400:     }
1.91      bisitz   2401: 
                   2402:     # Course
1.157     raeburn  2403:     if ($content{'courseid'} ne '') {
                   2404:         if ($content{'courseid'} =~ m{^$match_domain\_$match_courseid$}) {
                   2405:             my %courseinfo;
                   2406:             %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'},
                   2407:                                                            {'one_time' => 1});
                   2408:             my $description = $courseinfo{'description'};
                   2409:             if ($description ne '') {
                   2410:                 $r->print(&Apache::lonhtmlcommon::row_title(&mt($crstype))
                   2411:                          .$description
                   2412:                 );
                   2413:                 if ($content{'coursesec'}) {
                   2414:                     $r->print(' ('.&mt('Section').': '.$content{'coursesec'}.')');
                   2415:                 }
                   2416:                 $r->print(&Apache::lonhtmlcommon::row_closure());
                   2417:             }
1.73      raeburn  2418:         }
                   2419:     }
1.91      bisitz   2420:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Time'))
                   2421:              .$content{'time'}
                   2422:              .&Apache::lonhtmlcommon::row_closure()
                   2423:     );
                   2424: 
                   2425:     # Refers to
1.59      raeburn  2426:     if ($baseurl) {
                   2427:         if (defined($content{'courseid'}) && defined($env{'request.course.id'})) {
                   2428:             if ($content{'courseid'} eq $env{'request.course.id'}) {
                   2429:                 my $symblink;
1.62      raeburn  2430:                 my $showsymb = &Apache::lonenc::check_decrypt($symb);
                   2431:                 my $showurl = &Apache::lonenc::check_decrypt($baseurl);
                   2432:                 my $encrypturl = &Apache::lonnet::EXT('resource.0.encrypturl',
                   2433:                               $showsymb,$env{'user.domain'},$env{'user.name'});
1.59      raeburn  2434:                 if ($symb) {
1.62      raeburn  2435:                     if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
                   2436:                         $showsymb = &Apache::lonenc::check_encrypt($symb);
                   2437:                     }
                   2438:                     $symblink = '?symb='.$showsymb;
                   2439:                 }
                   2440:                 if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
                   2441:                     $showurl = $baseurl;
1.59      raeburn  2442:                 }
1.91      bisitz   2443:                 $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
                   2444:                          .'<a href="'.$showurl.$symblink.'">'.$restitle.'</a>'
                   2445:                          .&Apache::lonhtmlcommon::row_closure()
                   2446:                 );
1.59      raeburn  2447:                 $refers_to = 1;
                   2448:             }
                   2449:         }
                   2450:         if (!$refers_to) {
                   2451:             if ($baseurl =~ m-^/enc/-) {
                   2452:                 if (defined($content{'courseid'})) {
1.62      raeburn  2453:                     if (!$env{'request.course.id'}) {
                   2454:                         my $unencurl =
                   2455:                            &Apache::lonenc::unencrypted($baseurl,
                   2456:                                                         $content{'courseid'});
                   2457:                         if ($unencurl ne '') {
                   2458:                             if (&Apache::lonnet::allowed('bre',$unencurl)) {
1.91      bisitz   2459:                                 $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
                   2460:                                          .'<a href="'.$unencurl.'">'.$restitle.'</a>'
                   2461:                                          .&Apache::lonhtmlcommon::row_closure()
                   2462:                                 );
1.62      raeburn  2463:                             }
1.59      raeburn  2464:                         }
                   2465:                     }
                   2466:                 }
                   2467:             } else {
                   2468:                 if (&Apache::lonnet::allowed('bre',$baseurl)) {
1.91      bisitz   2469:                     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
                   2470:                              .'<a href="'.$baseurl.'">'.$restitle.'</a>'
                   2471:                              .&Apache::lonhtmlcommon::row_closure()
                   2472:                     );
                   2473: 
1.59      raeburn  2474:                 }
                   2475:             }
                   2476:         }
                   2477:     }
1.91      bisitz   2478: 
                   2479:     # Message
                   2480:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Message'))
                   2481:              .'<pre>'
                   2482: 	     .&Apache::lontexconvert::msgtexconverted($content{'message'},1)
                   2483: 	     .'</pre>'
                   2484:     );
                   2485:     if (&displayresource(%content)) {
                   2486:         $r->print(&Apache::lonhtmlcommon::row_closure()
                   2487:                  .&Apache::lonhtmlcommon::row_title(&mt('Resource Details'))
                   2488:                  .&displayresource(%content)
                   2489:         );
                   2490:     } 
1.92      raeburn  2491:     $r->print(&Apache::lonhtmlcommon::row_closure(1).
                   2492:               &Apache::lonhtmlcommon::end_pick_box());
1.91      bisitz   2493:     # Display LON-CAPA Message (End)
1.59      raeburn  2494:     return;
1.1       albertel 2495: }
                   2496: 
1.95      raeburn  2497: sub retrieve_recips {
                   2498:     my ($context,$content,$recips)= @_;
                   2499:     my $tonum = 0;
                   2500:     if (ref($content) eq 'HASH') {
                   2501:         my %reciphash =
                   2502:             &Apache::lonnet::get('nohist_emailrecip',[$content->{'recipid'}],
                   2503:                                  $content->{'senderdomain'},$content->{'sendername'});
                   2504:         my $recipinfo = $reciphash{$content->{'recipid'}};
                   2505:         if (ref($recipinfo) eq 'HASH') {
                   2506:             foreach my $type ('to','cc','course_broadcast','group_cc_broadcast','group_bcc_broadcast') {
                   2507:                 if (ref($recipinfo->{$type}) eq 'HASH') {
                   2508:                     if ($type eq 'to') {
                   2509:                         $tonum = keys(%{$recipinfo->{$type}});
                   2510:                     }
                   2511:                     foreach my $user (sort(keys(%{$recipinfo->{$type}}))) {
                   2512:                         my ($uname,$udom) = split(/:/,$user);
                   2513:                         next if (($context eq 'replying') && ($uname eq $env{'user.name'})
                   2514:                                  && ($udom eq $env{'user.domain'}));
                   2515:                         my $showuser ='<span class="LC_nobreak">';
                   2516:                         if ($context eq 'replying') {
                   2517:                             if (($type eq 'to') || ($type eq 'cc')) { 
                   2518:                                 $showuser = '<label><input type="checkbox" name="replying_'.$type.'" value="'.$user.'" />';
                   2519:                             } elsif ($type eq 'group_cc_broadcast') {
                   2520:                                 $showuser = '<label><input type="checkbox" name="replying_groupcc" value="'.$user.'" />';
                   2521:                             }
                   2522:                         }
                   2523:                         $showuser .= &Apache::loncommon::aboutmewrapper(
                   2524:                                            &Apache::loncommon::plainname($uname,
                   2525:                                            $udom),$uname,$udom);
                   2526: 		        if ($context eq 'replying') {
                   2527: 		            $showuser .='</label>';
                   2528: 		        }
                   2529: 		        $showuser .= '</span>';
                   2530:                         if (ref($recips) eq 'HASH') {
                   2531: 		            push(@{$recips->{$type}},$showuser);
                   2532:                         }
                   2533:                     }
1.73      raeburn  2534:                 }
                   2535:             }
                   2536:         }
                   2537:     }
1.95      raeburn  2538:     return $tonum;
                   2539: }
                   2540: 
                   2541: sub recipients_link {
                   2542:     my ($r,$content,$recipients) = @_;
                   2543:     my ($broadcast_link,$show);
                   2544:     if ((ref($content) eq 'HASH') && (ref($recipients) eq 'HASH')) {
                   2545:         if (ref($recipients->{'course_broadcast'}) eq 'ARRAY') {
                   2546:             if (@{$recipients->{'course_broadcast'}} > 0) {
                   2547:                 $show = 'course';
                   2548:             }
                   2549:         } elsif (ref($recipients->{'group_cc_broadcast'}) eq 'ARRAY') {
                   2550:             if (@{$recipients->{'group_cc_broadcast'}} > 0) {
                   2551:                 $show = 'group_cc';
                   2552:             }
                   2553:         } elsif (ref($recipients->{'group_bcc_broadcast'}) eq 'ARRAY') {
                   2554:             if (@{$recipients->{'group_bcc_broadcast'}} > 0) {
                   2555:                 $show = 'group_bcc';
                   2556:             }
                   2557:         }
                   2558:         if ($show) {
                   2559:             my ($nothing,$height,$width,$start_page,$end_page,$body);
                   2560:             $nothing=&Apache::lonhtmlcommon::javascript_nothing();
                   2561:             $height = 400;
                   2562:             $width = 600;
1.108     raeburn  2563:             $start_page =
                   2564:                 &Apache::loncommon::start_page('Broadcast List', undef,
                   2565:                                                {only_body => 1,
                   2566:                                                 js_ready  => 1,});
                   2567:             $end_page = &Apache::loncommon::end_page({js_ready => 1,});
                   2568:             $body = '<h3>'.&mt("Recipients of broadcast message").'</h3>'.
                   2569:                     &Apache::loncommon::start_data_table();
1.95      raeburn  2570:             my $cell = 0;
                   2571:             $body .= &Apache::loncommon::start_data_table_row();
                   2572:             foreach my $item (@{$recipients->{$show.'_broadcast'}}) {
                   2573:                 $item =~ s/'/\\'/g;
                   2574:                 if (!($cell%2) && $cell > 0) {
                   2575:                     $body .= &Apache::loncommon::end_data_table_row().
                   2576:                              &Apache::loncommon::start_data_table_row();
                   2577:                 }
                   2578:                 $cell ++;
                   2579:                 $body .= '<td>'.$cell.'&nbsp;'.$item.'&nbsp;&nbsp;</td>';
                   2580:             }
                   2581:             if ($cell%2) {
                   2582:                 $body .= '<td>&nbsp;</td>';
                   2583:             }
                   2584:             $body .= &Apache::loncommon::end_data_table_row().
                   2585:                      &Apache::loncommon::end_data_table();
                   2586:             $body =~ s{</}{<\\/}g;
                   2587:             $body =~ s{\n}{}g;
                   2588:             $r->print(<<ENDJS);
                   2589: <script type="text/javascript">
1.127     bisitz   2590: // <![CDATA[
1.95      raeburn  2591: function showBroadcastList() {
                   2592:     var caller = this;
                   2593:     var newWindow = null;
                   2594:     try {
                   2595:         newWindow =  window.open($nothing,"broadcast","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" );
                   2596:     }
                   2597:     catch(error) {
                   2598:         writeWin(caller);
                   2599:         return;
                   2600:     }
                   2601:     if (newWindow) {
                   2602:         caller = newWindow;
                   2603:     }
                   2604:     writeWin(caller);
                   2605:     return;
                   2606: }
                   2607: 
                   2608: function writeWin(caller) {
                   2609:     caller.document.writeln('$start_page $body $end_page');
                   2610:     caller.document.close();
                   2611:     caller.focus();
                   2612: }
1.127     bisitz   2613: // ]]>
1.95      raeburn  2614: </script>
                   2615: 
                   2616: ENDJS
                   2617:             $broadcast_link = 1;
                   2618:         }
                   2619:     }
                   2620:     return $broadcast_link;
1.73      raeburn  2621: }
                   2622: 
1.1       albertel 2623: # =========================================================== Show the citation
                   2624: 
                   2625: sub displayresource {
                   2626:     my %content=@_;
                   2627: #
                   2628: # If the recipient is in the same course that the message was sent from and
                   2629: # has sufficient privileges, show "all details," else show citation
                   2630: #
                   2631:     if (($env{'request.course.id'} eq $content{'courseid'})
                   2632:      && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
1.59      raeburn  2633:         my $symb;
                   2634:         if (defined($content{'symb'})) {
                   2635:             $symb = $content{'symb'};
                   2636:         } else { 
                   2637: 	    $symb=&Apache::lonnet::symbread($content{'baseurl'});
                   2638:         }
1.1       albertel 2639: # Could not get a symb, give up
                   2640: 	unless ($symb) { return $content{'citation'}; }
                   2641: # Have a symb, can render
                   2642: 	return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
                   2643: 	    &Apache::loncommon::get_previous_attempt($symb,
                   2644: 						     $content{'sendername'},
                   2645: 						     $content{'senderdomain'},
                   2646: 						     $content{'courseid'}).
                   2647: 	    '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
                   2648: 	    &Apache::loncommon::get_student_view($symb,
                   2649: 						 $content{'sendername'},
                   2650: 						 $content{'senderdomain'},
                   2651: 						 $content{'courseid'}).
                   2652: 	    '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
                   2653: 	    &Apache::loncommon::get_student_answers($symb,
                   2654: 						    $content{'sendername'},
                   2655: 						    $content{'senderdomain'},
                   2656: 						    $content{'courseid'});
                   2657:     } elsif ($env{'user.adv'}) {
                   2658: 	return $content{'citation'};
                   2659:     }
                   2660:     return '';
                   2661: }
                   2662: 
                   2663: # ================================================================== The Header
                   2664: 
                   2665: sub header {
                   2666:     my ($r,$title,$baseurl)=@_;
                   2667:     my $extra = &Apache::loncommon::studentbrowser_javascript();
                   2668:     if ($baseurl) {
1.41      albertel 2669: 	$extra .= "<base href=\"".&Apache::lonnet::absolute_url()."/$baseurl\" />";
1.1       albertel 2670:     }
1.138     raeburn  2671:     $r->print(&Apache::loncommon::start_page('Messages',
1.38      raeburn  2672:  					$extra));
1.1       albertel 2673:     $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.138     raeburn  2674:      		(($title?$title:'Send and display messages')));
1.1       albertel 2675: }
                   2676: 
                   2677: # ---------------------------------------------------------------- Print header
                   2678: 
                   2679: sub printheader {
                   2680:     my ($r,$url,$desc,$title,$baseurl)=@_;
                   2681:     &Apache::lonhtmlcommon::add_breadcrumb
                   2682: 	({href=>$url,
                   2683: 	  text=>$desc});
                   2684:     &header($r,$title,$baseurl);
                   2685: }
                   2686: 
                   2687: # ------------------------------------------------------------ Store the comment
                   2688: 
                   2689: sub storecomment {
                   2690:     my ($r)=@_;
                   2691:     my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
                   2692:     my $cleanmsgtxt='';
1.42      raeburn  2693:     foreach my $line (split(/[\n\r]/,$msgtxt)) {
                   2694: 	unless ($line=~/^\s*(\>|\&gt\;)/) {
                   2695: 	    $cleanmsgtxt.=$line."\n";
1.1       albertel 2696: 	}
                   2697:     }
1.29      www      2698:     my $key=&escape($env{'form.baseurl'}).'___'.time;
1.1       albertel 2699:     &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
                   2700: }
                   2701: 
                   2702: sub storedcommentlisting {
                   2703:     my ($r)=@_;
                   2704:     my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
1.29      www      2705:        '^'.&escape(&escape($env{'form.showcommentbaseurl'})));
1.72      albertel 2706:     $r->print(&Apache::loncommon::start_page('Saved Comment Listing',undef,
1.1       albertel 2707: 					     {'onlybody' => 1}));
1.178     raeburn  2708:     if ((keys(%msgs))[0]=~/^error\:/) {
1.72      albertel 2709: 	$r->print(&mt('No saved comments yet.'));
1.1       albertel 2710:     } else {
                   2711: 	my $found=0;
1.42      raeburn  2712: 	foreach my $key (sort(keys(%msgs))) {
                   2713: 	    $r->print("\n".$msgs{$key}."<hr />");
1.1       albertel 2714: 	    $found=1;
                   2715: 	}
                   2716: 	unless ($found) {
1.72      albertel 2717: 	    $r->print(&mt('No saved comments yet for this resource.'));
1.1       albertel 2718: 	}
                   2719:     }
                   2720: }
                   2721: 
                   2722: # ---------------------------------------------------------------- Send an email
                   2723: 
                   2724: sub sendoffmail {
                   2725:     my ($r,$folder)=@_;
                   2726:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
                   2727:     my $sendstatus='';
1.71      raeburn  2728:     my %msg_status;
                   2729:     my $numsent = 0;
                   2730:     my $nosentstore = 1;
1.86      raeburn  2731:     my $attachmenturl;
                   2732:     my $now = time;
1.38      raeburn  2733:     my ($cdom,$cnum,$group);
                   2734:     if (exists($env{'form.group'})) {
                   2735:         $group = $env{'form.group'};
                   2736:     }
                   2737:     if (exists($env{'request.course.id'})) {
                   2738:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   2739:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   2740:     }
1.1       albertel 2741:     if ($env{'form.send'}) {
1.53      raeburn  2742:         if (!$env{'form.multiforward'}) { 
                   2743:             if ($group eq '') {
                   2744: 	        &printheader($r,'','Messages being sent.');
                   2745:             } else {
                   2746:                 $r->print(&groupmail_header('sending',$group));
                   2747:             }
1.38      raeburn  2748:         }
1.1       albertel 2749: 	$r->rflush();
                   2750: 	my %content=();
                   2751: 	undef %content;
                   2752: 	if ($env{'form.forwid'}) {
                   2753: 	    my $msgid=$env{'form.forwid'};
                   2754: 	    my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1.86      raeburn  2755: 	    %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1,1);
1.1       albertel 2756: 	    &statuschange($msgid,'forwarded',$folder);
1.86      raeburn  2757:             if ($content{'attachmenturl'} ne '') {
                   2758:                 $attachmenturl = $content{'attachmenturl'};
                   2759:             }
                   2760: 	    $env{'form.message'} .= "\n\n-- Forwarded message --\n\n".
                   2761: 		                    $content{'message'};
1.1       albertel 2762: 	}
                   2763: 	if ($env{'form.replyid'}) {
                   2764: 	    my $msgid=$env{'form.replyid'};
                   2765: 	    my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
                   2766: 	    %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
                   2767: 	    &statuschange($msgid,'replied',$folder);
                   2768: 	}
1.13      albertel 2769: 
1.25      foxr     2770: 	my $mode = $env{'form.sendmode'};
1.95      raeburn  2771: 	my (%toaddr,$tos,$cc,$bcc,$broadcast);
1.25      foxr     2772: 
1.95      raeburn  2773: 	if ($mode eq 'group') {
                   2774:             if (defined($env{'form.courserecips'})) {
                   2775:                 my $courseusers = $env{'form.courserecips'};
                   2776:                 $courseusers =~ s/^_\&\&\&_//;
                   2777:                 my @to = split('_&&&_',$courseusers);
                   2778:                 foreach my $dest (@to) {
                   2779:                     my ($user,$domain) = split(/:/, $dest);
                   2780:                     if (($user ne '') && ($domain ne '')) {
                   2781:                         my $rec = $user.":".$domain;
                   2782:                         $toaddr{$rec} = '';
                   2783:                         $broadcast->{$rec} = '';
                   2784:                     }
                   2785:                 }
                   2786:             }
                   2787: 	} elsif ($mode eq 'upload') {
1.71      raeburn  2788:             $nosentstore = 0;
1.13      albertel 2789: 	    foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
1.43      raeburn  2790:                 my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/);
1.1       albertel 2791: 		if ($txt) {
1.43      raeburn  2792:                     $rec =~ s/^\s+//;
1.44      raeburn  2793:                     $rec =~ s/\s+$//;
1.1       albertel 2794: 		    $toaddr{$rec}.=$txt."\n";
1.95      raeburn  2795:                     $broadcast->{$rec} = '';
1.1       albertel 2796: 		}
                   2797: 	    }
                   2798: 	} else {
1.25      foxr     2799: 	    if (($env{'form.recuname'} ne '') && ($env{'form.recdomain'} ne '')) {
                   2800: 		$toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
1.95      raeburn  2801:                 $tos->{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
1.25      foxr     2802: 	    }
1.1       albertel 2803: 	}
1.95      raeburn  2804:         if ($env{'form.additionalrec_to'}) {
                   2805:             foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_to'})) {
                   2806:                 my ($auname,$audom)=split(/:/,$rec);
                   2807:                 if (($auname ne "") && ($audom ne "")) {
                   2808:                     $toaddr{$auname.':'.$audom}='';
                   2809:                     $tos->{$auname.':'.$audom}='';
                   2810:                 }
                   2811:             }
                   2812:         }
                   2813:         if ($env{'form.replying_to'}) {
                   2814:             my @toreplies =
                   2815:                 &Apache::loncommon::get_env_multiple('form.replying_to');
                   2816:             foreach my $rec (@toreplies) {
                   2817:                 my ($auname,$audom)=split(/:/,$rec);
                   2818:                 if (($auname ne "") && ($audom ne "")) {
                   2819:                     $toaddr{$auname.':'.$audom}='';
                   2820:                     $tos->{$auname.':'.$audom}='';
                   2821:                 }
                   2822:             }
                   2823:         }
1.73      raeburn  2824: 	if ($env{'form.additionalrec_cc'}) {
                   2825: 	    foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_cc'})) {
1.43      raeburn  2826: 		my ($auname,$audom)=split(/:/,$rec);
1.25      foxr     2827: 		if (($auname ne "") && ($audom ne "")) {
1.73      raeburn  2828:                     $toaddr{$auname.':'.$audom}='';
1.95      raeburn  2829:                     if (!defined($tos->{$auname.':'.$audom})) {
                   2830: 		        $cc->{$auname.':'.$audom}='';
                   2831:                     }
1.25      foxr     2832: 		}
1.1       albertel 2833: 	    }
                   2834: 	}
1.95      raeburn  2835:         if ($env{'form.replying_cc'}) {
                   2836:             my @ccreplies =
                   2837:                 &Apache::loncommon::get_env_multiple('form.replying_cc');
                   2838:             foreach my $rec (@ccreplies) {
                   2839:                 my ($auname,$audom)=split(/:/,$rec);
                   2840:                 if (($auname ne "") && ($audom ne "")) {
                   2841:                     $toaddr{$auname.':'.$audom}='';
                   2842:                     if (!defined($tos->{$auname.':'.$audom})) {
                   2843:                         $cc->{$auname.':'.$audom}='';
                   2844:                     }
                   2845:                 }
                   2846:             }
                   2847:         }
                   2848:         if ($env{'form.replying_groupcc'}) {
                   2849:             my @groupreplies =
                   2850:                 &Apache::loncommon::get_env_multiple('form.replying_groupcc');
                   2851:             foreach my $rec (@groupreplies) {
1.73      raeburn  2852:                 my ($auname,$audom)=split(/:/,$rec);
                   2853:                 if (($auname ne "") && ($audom ne "")) {
                   2854:                     $toaddr{$auname.':'.$audom}='';
1.95      raeburn  2855:                     if (!defined($tos->{$auname.':'.$audom})) {
                   2856:                         $broadcast->{$auname.':'.$audom}='';
                   2857:                     }
1.73      raeburn  2858:                 }
                   2859:             }
                   2860:         }
1.95      raeburn  2861:         if ($env{'form.additionalrec_bcc'}) {
                   2862:             foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_bcc'})) {
1.73      raeburn  2863:                 my ($auname,$audom)=split(/:/,$rec);
                   2864:                 if (($auname ne "") && ($audom ne "")) {
                   2865:                     $toaddr{$auname.':'.$audom}='';
1.95      raeburn  2866:                     if ((!defined($tos->{$auname.':'.$audom})) && 
                   2867:                         (!defined($cc->{$auname.':'.$audom}))) {
                   2868:                         $bcc->{$auname.':'.$audom}='';
                   2869:                     }
1.73      raeburn  2870:                 }
                   2871:             }
                   2872:         }
1.1       albertel 2873:         my $savemsg;
                   2874:         my $msgtype;
                   2875:         my %sentmessage;
1.7       albertel 2876:         my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'},
                   2877: 							 undef,1);
1.1       albertel 2878:         if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
                   2879:             (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                   2880: 	     || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                   2881: 					 '/'.$env{'request.course.sec'})
                   2882: 	     )) {
                   2883:             $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
                   2884:             $msgtype = 'critical';
                   2885:         } else {
                   2886:             $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
                   2887:         }
1.73      raeburn  2888:         my %reciphash = (
1.95      raeburn  2889:                            to => $tos,
1.73      raeburn  2890:                            cc => $cc,
                   2891:                            bcc => $bcc,
1.95      raeburn  2892:                         );
                   2893:         if ($mode eq 'group') {
                   2894:             if ($group eq '') {
                   2895:                 $reciphash{'course_broadcast'} = $broadcast;
                   2896:             } else {
                   2897:                 if ($env{'form.groupmail'} eq 'cc') {
                   2898:                     $reciphash{'group_cc_broadcast'} = $broadcast;
                   2899:                 } else {
                   2900:                     $reciphash{'group_bcc_broadcast'} = $broadcast;
                   2901:                 }
                   2902:             }
                   2903:         }
1.73      raeburn  2904:         my ($recipid,$recipstatus) = 
                   2905:             &Apache::lonmsg::store_recipients($msgsubj,$env{'user.name'},
                   2906:                                        $env{'user.domain'},\%reciphash);
                   2907:         if ($recipstatus ne 'ok') {
1.95      raeburn  2908:             &Apache::lonnet::logthis('Failed to store To, Bcc and Cc recipients for '.$env{'user.name'}.':'.$env{'user.domain'});
1.86      raeburn  2909:         }
                   2910:         if ($env{'form.attachment'}) {
                   2911:             if (length($env{'form.attachment'})<131072) {
                   2912:                 $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback/'.$now);
                   2913:             } else {
                   2914:                 $r->print('<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>');
                   2915:             }
                   2916:         } elsif ($env{'form.multiforward'}) {
                   2917:             if ($env{'form.attachmenturl'} ne '') {
                   2918:                 $attachmenturl = $env{'form.attachmenturl'};
                   2919:             }
                   2920:         }
1.71      raeburn  2921:         my @recusers;
                   2922:         my @recudoms;
1.180     raeburn  2923:         my %permresults;
1.13      albertel 2924: 	foreach my $address (sort(keys(%toaddr))) {
                   2925: 	    my ($recuname,$recdomain)=split(/\:/,$address);
1.1       albertel 2926:             my $msgtxt = $savemsg;
1.73      raeburn  2927:             if ($toaddr{$address}) {
1.151     raeburn  2928: 	        $msgtxt.="\n".'<hr />'."\n".$toaddr{$address};
1.73      raeburn  2929:             }
1.12      albertel 2930: 	    my @thismsg;
1.60      raeburn  2931: 	    if ($msgtype eq 'critical') {
                   2932: 		$r->print(&mt('Sending critical message').' '.
                   2933:                               $recuname.':'.$recdomain.': ');
1.13      albertel 2934: 		@thismsg=
                   2935: 		    &Apache::lonmsg::user_crit_msg($recuname,$recdomain,
                   2936: 						   $msgsubj,$msgtxt,
                   2937: 						   $env{'form.sendbck'},
                   2938: 						   $env{'form.permanent'},
1.71      raeburn  2939: 						   \$sentmessage{$address},
1.179     raeburn  2940:                                                    $nosentstore,$recipid,
1.180     raeburn  2941:                                                    $attachmenturl,\%permresults);
1.1       albertel 2942: 	    } else {
1.14      albertel 2943: 		$r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': ');
1.13      albertel 2944: 		@thismsg=
                   2945: 		    &Apache::lonmsg::user_normal_msg($recuname,$recdomain,
                   2946: 						     $msgsubj,$msgtxt,
                   2947: 						     $content{'citation'},
1.86      raeburn  2948: 						     undef,$attachmenturl,
1.13      albertel 2949: 						     $env{'form.permanent'},
1.71      raeburn  2950: 						     \$sentmessage{$address},
                   2951:                                                      undef,undef,undef,
1.180     raeburn  2952:                                                      $nosentstore,$recipid,
                   2953:                                                      \%permresults);
1.71      raeburn  2954:             }
                   2955: 	    $msg_status{$recuname.':'.$recdomain}=join(' ',@thismsg);
                   2956: 	    if ($msg_status{$recuname.':'.$recdomain} =~ /(ok|con_delayed)/) {  
                   2957: 	        $numsent++;
                   2958:                 push(@recusers,$recuname);
                   2959:                 push(@recudoms,$recdomain);
1.180     raeburn  2960:                 if ($1 eq 'ok') {
                   2961:                     $r->print('ok ');
                   2962:                 }
                   2963:                 if ($permresults{$recuname.':'.$recdomain}) {
                   2964:                     $r->print(' (email) ');
                   2965:                 }
1.1       albertel 2966: 	    }
1.12      albertel 2967: 	    $sendstatus.=' '.join(' ',@thismsg);
1.1       albertel 2968: 	}
1.71      raeburn  2969:         my $subj_prefix;
                   2970:         if ($numsent > 0) {
                   2971:             if (($env{'request.course.id'}) && 
1.95      raeburn  2972:                 (($mode eq 'group') ||
1.71      raeburn  2973:                  ($env{'form.courserecord'}) ||
1.95      raeburn  2974:                  ($msgtype eq 'critical')) ||
                   2975:                 ($env{'form.replyid'} && 
                   2976:                  (($content{'courseid'} ne '') && 
                   2977:                   ($mode eq 'group')))) {
1.71      raeburn  2978:                 if ($msgtype eq 'critical') {
                   2979:                     $subj_prefix = 'Critical.';
1.95      raeburn  2980:                 } elsif ($mode eq 'group') {
1.71      raeburn  2981:                     $subj_prefix = 'Broadcast.';
                   2982:                 } else {
                   2983:                     $subj_prefix = 'Archive';
                   2984:                 }
                   2985:                 my ($specialmsgid,$specialresult);
1.95      raeburn  2986:                 my $course_str;
                   2987:                 if ($env{'form.replyid'}) {
                   2988:                     if ($content{'courseid'} ne '') {
                   2989:                         my %crsdesc = 
                   2990:                             &Apache::lonnet::coursedescription($content{'courseid'},
                   2991:                                                                {'one_time' => 1});
                   2992:                         $course_str = &escape('['.$crsdesc{'num'}.':'.$crsdesc{'domain'}.']');
                   2993:                     }
                   2994:                 } elsif ($env{'request.course.id'}) {
                   2995:                     $course_str = &escape('['.$cnum.':'.$cdom.']');
                   2996:                 }
1.71      raeburn  2997:                 $specialresult = 
                   2998:                     &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
                   2999:                         $subj_prefix.' '.$course_str,$savemsg,undef,undef,
1.86      raeburn  3000:                         $attachmenturl,undef,undef,\$specialmsgid,undef,undef,undef,
1.71      raeburn  3001:                         undef,undef,1);
1.29      www      3002:                 $specialmsgid = &unescape($specialmsgid);
1.71      raeburn  3003:                 if ($specialresult eq 'ok') {
                   3004:                     my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
                   3005: 		        split(/\:/,&unescape($specialmsgid));
                   3006: 
                   3007:                     foreach my $recipient (sort(keys(%toaddr))) {
                   3008:                         if ($msg_status{$recipient} =~ /\s*(ok|con_delayed)\s*/) {
                   3009:                             my $usersubj = $subj_prefix.'['.$recipient.']';
                   3010:                             my $usermsgid = 
                   3011: 			        &Apache::lonmsg::buildmsgid($stamp,$usersubj,
                   3012: 							    $msgname,$msgdom,
                   3013: 							    $msgcount,$context,
                   3014: 							    $pid);
                   3015:                             &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
                   3016:                                 $subj_prefix.' ['.$recipient.']',$msgsubj,
1.86      raeburn  3017:                                 undef,undef,$attachmenturl,undef,$usermsgid,undef,
1.71      raeburn  3018:                                 undef,$specialmsgid,undef,undef,undef,1);
                   3019:                         }
                   3020:                     }
1.95      raeburn  3021:                     if (($mode ne 'upload') && (@recusers > 0)) {
1.71      raeburn  3022:                         &Apache::lonmsg::process_sent_mail($msgsubj,
                   3023:                            $subj_prefix,$numsent,$stamp,$msgname,$msgdom,
                   3024:                            $msgcount,$context,$pid,$savemsg,\@recusers,
1.95      raeburn  3025:                            \@recudoms,undef,$attachmenturl,'','','','',$recipid);
1.1       albertel 3026:                     }
1.71      raeburn  3027:                 } else {
1.78      raeburn  3028:                     &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 3029:                 }
                   3030:             } else {
1.71      raeburn  3031:                 my $stamp = time;
                   3032:                 my $msgcount = &Apache::lonmsg::get_uniq();
                   3033:                 my $context = &Apache::lonmsg::get_course_context();
                   3034:                 &Apache::lonmsg::process_sent_mail($msgsubj,$subj_prefix,
                   3035:                        $numsent,$stamp,$env{'user.name'},
                   3036:                        $env{'user.domain'},$msgcount,$context,
1.95      raeburn  3037:                        $$,$savemsg,\@recusers,\@recudoms,undef,$attachmenturl,
                   3038:                        '','','','',$recipid);
1.1       albertel 3039:             }
                   3040:         }
1.143     wenzelju 3041:         if (!$env{'form.multiforward'}) {
1.71      raeburn  3042:             if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
1.143     wenzelju 3043:                 my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Completed.'));
                   3044:                 $message = &Apache::loncommon::confirmwrapper($message);
                   3045:                 $r->print($message);
1.71      raeburn  3046: 	        if ($env{'form.displayedcrit'}) {
                   3047: 	            &discrit($r);
                   3048:                 }
                   3049:                 if ($group ne '') {
                   3050:                     $r->print(&groupmail_sent($group,$cdom,$cnum)); 
                   3051: 	        } else {
                   3052: 	            &Apache::loncommunicate::menu($r);
                   3053: 	        }
                   3054:             } else {
1.143     wenzelju 3055:                 my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Could not deliver message'),1);
1.145     raeburn  3056:                 $message .= '<br />'.&mt('Please use the browser "Back" button and correct the recipient addresses ([_1]).',$sendstatus);
1.143     wenzelju 3057:                 $message = &Apache::loncommon::confirmwrapper($message);
                   3058:                 $r->print($message);
1.53      raeburn  3059:             }
1.38      raeburn  3060:         }
1.152     www      3061:     } else {
                   3062:         &printheader($r,'','Messages cancelled.');
                   3063:         return 'cancelled';
1.1       albertel 3064:     }
1.53      raeburn  3065:     return $sendstatus;
1.1       albertel 3066: }
                   3067: 
                   3068: # ===================================================================== Handler
                   3069: 
                   3070: sub handler {
                   3071:     my $r=shift;
                   3072: 
                   3073: # ----------------------------------------------------------- Set document type
                   3074:     
                   3075:     &Apache::loncommon::content_type($r,'text/html');
                   3076:     $r->send_http_header;
                   3077:     
                   3078:     return OK if $r->header_only;
                   3079:     
                   3080: # --------------------------- Get query string for limited number of parameters
                   3081:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   3082:         ['display','replyto','forward','markread','markdel','markunread',
                   3083:          'sendreply','compose','sendmail','critical','recname','recdom',
1.159     raeburn  3084:          'recordftf','sortedby','folder','startdis','interdis',
1.53      raeburn  3085: 	 'showcommentbaseurl','dismode','group','subject','text','ref',
                   3086:          'msgstatus']);
1.127     bisitz   3087:     $sqs='&amp;sortedby='.$env{'form.sortedby'};
1.1       albertel 3088: 
                   3089: # ------------------------------------------------------ They checked for email
1.159     raeburn  3090:     &Apache::lonnet::put('email_status',{'recnewemail'=>0});
1.1       albertel 3091: 
                   3092: # ----------------------------------------------------------------- Breadcrumbs
                   3093: 
                   3094:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                   3095:     &Apache::lonhtmlcommon::add_breadcrumb
                   3096:         ({href=>"/adm/communicate",
1.138     raeburn  3097:           text=>"Messages",
1.1       albertel 3098:           faq=>12,bug=>'Communication Tools',});
                   3099: 
                   3100: # ------------------------------------------------------------------ Get Folder
                   3101: 
                   3102:     my $folder=$env{'form.folder'};
                   3103:     unless ($folder) { 
                   3104: 	$folder=''; 
                   3105:     } else {
1.127     bisitz   3106: 	$sqs.='&amp;folder='.&escape($folder);
1.1       albertel 3107:     }
                   3108: # ------------------------------------------------------------ Get Display Mode
                   3109: 
                   3110:     my $dismode=$env{'form.dismode'};
                   3111:     unless ($dismode) { 
                   3112: 	$dismode=''; 
                   3113:     } else {
1.48      albertel 3114: 	$sqs.='&amp;dismode='.&escape($dismode);
1.1       albertel 3115:     }
                   3116: 
                   3117: # --------------------------------------------------------------------- Display
1.53      raeburn  3118:     my $msgstatus = $env{'form.msgstatus'};
1.1       albertel 3119:     $startdis=$env{'form.startdis'};
1.53      raeburn  3120:     if ($startdis ne '') {
                   3121:         $startdis--;
                   3122:     }
1.1       albertel 3123:     unless ($startdis) { $startdis=0; }
                   3124: 
                   3125:     if ($env{'form.firstview'}) {
                   3126: 	$startdis=0;
                   3127:     }
                   3128:     if ($env{'form.lastview'}) {
                   3129: 	$startdis=-1;
                   3130:     }
                   3131:     if ($env{'form.prevview'}) {
                   3132: 	$startdis--;
                   3133:     }
                   3134:     if ($env{'form.nextview'}) {
                   3135: 	$startdis++;
                   3136:     }
                   3137:     my $postedstartdis=$startdis+1;
1.127     bisitz   3138:     $sqs.='&amp;startdis='.$postedstartdis;
1.1       albertel 3139: 
                   3140: # --------------------------------------------------------------- Render Output
                   3141: 
                   3142:     if ($env{'form.display'}) {
1.53      raeburn  3143: 	&displaymessage($r,$env{'form.display'},$folder,$msgstatus);
1.1       albertel 3144:     } elsif ($env{'form.replyto'}) {
                   3145: 	&compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode);
                   3146:     } elsif ($env{'form.confirm'}) {
                   3147: 	&printheader($r,'','Confirmed Receipt');
1.36      albertel 3148: 	my $replying = 0;
1.42      raeburn  3149: 	foreach my $envkey (keys(%env)) {
1.75      raeburn  3150: 	    if ($envkey=~/^form\.(rep)?rec\_(.*)$/) {
1.77      raeburn  3151:                 my $repchk = $1;
1.75      raeburn  3152:        		my $msgid = $2;
                   3153: 		$r->print('<b>'.&mt('Confirming Receipt').':</b> ');
                   3154: 		my $result = &Apache::lonmsg::user_crit_received($msgid);
                   3155:                 if ($result =~ /trans:\s+ok/) {
                   3156:                     &statuschange($msgid,'read');
                   3157:                 }
1.76      albertel 3158:                 $r->print($result.'<br />');
1.77      raeburn  3159:                 if ($repchk eq 'rep') {
1.75      raeburn  3160: 		    &compout($r,'','','',$msgid);
                   3161: 		    $replying = 1;
                   3162:                 }
1.1       albertel 3163: 	    }
                   3164: 	}
1.36      albertel 3165: 	if (!$replying) {
                   3166: 	    &discrit($r);
                   3167: 	}
1.1       albertel 3168:     } elsif ($env{'form.critical'}) {
                   3169: 	&printheader($r,'','Displaying Critical Messages');
                   3170: 	&discrit($r);
                   3171:     } elsif ($env{'form.forward'}) {
                   3172: 	&compout($r,$env{'form.forward'},undef,undef,undef,$folder);
                   3173:     } elsif ($env{'form.markdel'}) {
                   3174: 	&printheader($r,'','Deleted Message');
1.9       albertel 3175: 	my ($result,$msg) = 
                   3176: 	    &statuschange($env{'form.markdel'},'deleted',$folder);
                   3177: 	if (!$result) {
1.143     wenzelju 3178:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Failed to delete the message.'),1);
1.147     wenzelju 3179:             $message .= '<p class="LC_error" style="font-size: inherit;">'.$msg.'</p>';
1.143     wenzelju 3180:             $message = &Apache::loncommon::confirmwrapper($message);
                   3181:             $r->print($message);
1.9       albertel 3182: 	}
1.1       albertel 3183: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  3184: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
                   3185:     } elsif ($env{'form.markedaction'} eq 'markedforward') {
                   3186:         my $total = 0;
                   3187:         my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
                   3188:         foreach my $msgid (@to_forward) {
                   3189:             &statuschange(&unescape($msgid),'forwarded',$folder);
                   3190:             $total ++;
                   3191:         }
                   3192:         if ($total > 0) {
                   3193:             &compout($r,undef,undef,undef,undef,$folder,$dismode,$total);
                   3194:         }
                   3195:     } elsif ($env{'form.markedaction'} eq 'markedread') {
                   3196:         my $total = 0;
                   3197:         my @to_markread = &Apache::loncommon::get_env_multiple('form.delmark');
                   3198:         foreach my $msgid (@to_markread) {
                   3199:             &statuschange(&unescape($msgid),'read',$folder);
                   3200:             $total ++;
                   3201:         }
                   3202:         &printheader($r,'','Marked Messages Read');
1.143     wenzelju 3203:         my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Marked [quant,_1,message] read',$total));
                   3204:         $message = &Apache::loncommon::confirmwrapper($message);
                   3205:         $r->print($message);
                   3206:       # $r->print('<p>');
1.53      raeburn  3207:         &Apache::loncommunicate::menu($r);
                   3208:         &disall($r,($folder?$folder:$dismode),$msgstatus);
                   3209:     } elsif ($env{'form.markedaction'} eq 'markedunread') {
                   3210:         my $total = 0;
                   3211:         my @to_markunread = &Apache::loncommon::get_env_multiple('form.delmark');
                   3212:         foreach my $msgid (@to_markunread) {
                   3213:             &statuschange(&unescape($msgid),'new',$folder);
                   3214:             $total ++;
                   3215:         }
                   3216:         &printheader($r,'','Marked Messages Unread');
1.143     wenzelju 3217:         my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Marked [quant,_1,message] unread',$total));
                   3218:         $message = &Apache::loncommon::confirmwrapper($message);
                   3219:         $r->print($message);
                   3220:       # $r->print('<p>');
1.53      raeburn  3221:         &Apache::loncommunicate::menu($r);
                   3222:         &disall($r,($folder?$folder:$dismode),$msgstatus);
                   3223:     } elsif ($env{'form.markedaction'} eq 'markedmove') {
                   3224:         my $destfolder = $env{'form.movetofolder'};
                   3225:         my %gotfolders = &Apache::lonmsg::get_user_folders();
                   3226:         &printheader($r,'','Moved Messages');
                   3227:         if (!defined($gotfolders{$destfolder})) {
                   3228:             $r->print(&mt('Destination folder [_1] is not a valid folder',
1.148     bisitz   3229:                           '<span class="LC_filename">'.$destfolder.'</span>'));
1.53      raeburn  3230:         } else {
                   3231: 	    my ($total,$failed,@failed_msg)=(0,0);
                   3232:             my @to_move = &Apache::loncommon::get_env_multiple('form.delmark');
                   3233:             foreach my $msgid (@to_move) {
                   3234: 	        my ($result,$msg) = &movemsg(&unescape($msgid),$folder,
                   3235: 			                     $env{'form.movetofolder'});
                   3236: 	        if ($result) {
1.9       albertel 3237: 		    $total++;
1.53      raeburn  3238: 	        } else {
1.9       albertel 3239: 		    $failed++;
                   3240: 		    push(@failed_msg,$msg);
1.53      raeburn  3241: 	        }
1.1       albertel 3242: 	    }
1.143     wenzelju 3243:             my $message = '';
                   3244:             if ($failed) {
                   3245:                 $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Failed to move [quant,_1,message]',$failed),1);
1.147     wenzelju 3246:                 $message .= '<p class="LC_error" style="font-size: inherit;">'.
                   3247: 		            join("</p>\n<p class=\"LC_error\" style=\"font-size: inherit;\">",@failed_msg).
1.143     wenzelju 3248: 		            "</p>\n";
                   3249:             }
                   3250:             $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Moved [quant,_1,message]',$total));
                   3251:             $message = &Apache::loncommon::confirmwrapper($message);
                   3252:             $r->print($message);
                   3253:           # $r->print('<p>');
1.53      raeburn  3254:         }
1.1       albertel 3255: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  3256: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
                   3257:     } elsif ($env{'form.markedaction'} eq 'markeddel') {
1.9       albertel 3258: 	my ($total,$failed,@failed_msg)=(0,0);
1.53      raeburn  3259:         my @to_delete = &Apache::loncommon::get_env_multiple('form.delmark');
                   3260:         foreach my $msgid (@to_delete) {
                   3261: 	    my ($result,$msg) = &statuschange(&unescape($msgid),'deleted', 
                   3262: 				              $folder);
                   3263: 	    if ($result) {
                   3264: 	        $total++;
                   3265: 	    } else {
                   3266: 	        $failed++;
                   3267: 		push(@failed_msg,$msg);
1.1       albertel 3268: 	    }
                   3269: 	}
                   3270: 	&printheader($r,'','Deleted Messages');
1.143     wenzelju 3271:         my $message = '';
1.9       albertel 3272: 	if ($failed) {
1.143     wenzelju 3273:             $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Failed to delete [quant,_1,message]',$failed),1);
1.147     wenzelju 3274:             $message .= '<p class="LC_error" style="font-size: inherit;">'.
                   3275: 		      join("</p>\n<p class=\"LC_error\" style=\"font-size: inherit;\">",@failed_msg).
1.143     wenzelju 3276: 		      "</p>\n";
1.9       albertel 3277: 	}
1.143     wenzelju 3278:         $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Deleted [quant,_1,message]',$total));
                   3279:         $message = &Apache::loncommon::confirmwrapper($message);
                   3280:         $r->print($message);
                   3281:       # $r->print('<p>');
1.1       albertel 3282: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  3283: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
1.1       albertel 3284:     } elsif ($env{'form.markunread'}) {
                   3285: 	&printheader($r,'','Marked Message as Unread');
                   3286: 	&statuschange($env{'form.markunread'},'new');
                   3287: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  3288: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
1.1       albertel 3289:     } elsif ($env{'form.compose'}) {
                   3290: 	&compout($r,'','',$env{'form.compose'});
                   3291:     } elsif ($env{'form.recordftf'}) {
                   3292: 	&facetoface($r,$env{'form.recordftf'});
                   3293:     } elsif ($env{'form.sendmail'}) {
1.53      raeburn  3294:         if ($env{'form.multiforward'}) {
                   3295:             &printheader($r,'','Messages being sent.');
                   3296:             my $fixed_subj = $env{'form.subject'};
                   3297:             my $suffix=&Apache::lonmsg::foldersuffix($folder);
                   3298:             my (%sendresult,%forwardok,%forwardfail,$fwdcount);
                   3299:             my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
                   3300:             foreach my $item (@to_forward) {
                   3301:                 my $msgid=&unescape($item);
                   3302:                 my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1.86      raeburn  3303:                 my %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1,1);
1.53      raeburn  3304:                 if ($env{'form.showorigsubj'}) {
                   3305:                     $env{'form.subject'} = $fixed_subj.$content{'subject'};
                   3306:                 } else {
                   3307:                     $env{'form.subject'} = '';
                   3308:                 }
                   3309:                 my $uname = $content{'sendername'};
                   3310:                 my $udom = $content{'senderdomain'};
                   3311:                 &statuschange($msgid,'forwarded',$folder);
                   3312:                 if ($env{'form.showorigsender'}) {
                   3313:                     $env{'form.message'} = $env{'form.msgheader'}.' '.
                   3314:                         &Apache::loncommon::plainname($uname,$udom).' ('.
                   3315:                                            $uname.':'.$udom.')';
                   3316:                 }
1.86      raeburn  3317:                 $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
                   3318:                                       $content{'message'};
                   3319:                 $env{'form.attachmenturl'} = $content{'attachmenturl'};
                   3320:                 $env{'form.multiforwid'} = $item;
1.53      raeburn  3321:                 $fwdcount ++;
                   3322:                 $r->print($fwdcount.': '); 
                   3323:                 $sendresult{$msgid} = &sendoffmail($r,$folder);
                   3324:                 $r->print('<br />');
                   3325:             }
                   3326:             foreach my $key (keys(%sendresult)) {
                   3327:                 if ($sendresult{$key} =~/^(\s*(?:ok|con_delayed)\s*)*$/) {
                   3328:                     $forwardok{$key} = $sendresult{$key};
                   3329:                 } else {
                   3330:                     $forwardfail{$key} = $sendresult{$key}; 
                   3331:                 }
                   3332:             }
                   3333:             if (keys(%forwardok) > 0) {
                   3334:                 my $count = keys(%forwardok);
1.143     wenzelju 3335:                 my $message = &Apache::lonhtmlcommon::confirm_success(&mt('[quant,_1,message] forwarded.',$count));
                   3336:                 $message = &Apache::loncommon::confirmwrapper($message);
                   3337:                 $r->print($message);
1.53      raeburn  3338:             }
                   3339:             if (keys(%forwardfail) > 0) {
                   3340:                 my $count = keys(%forwardfail);
1.143     wenzelju 3341:                 my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Could not forward [quant,_1,message].',$count),1);
1.53      raeburn  3342:                 foreach my $key (keys(%forwardfail)) {
1.145     raeburn  3343:                     $message .= '<br />'.&mt('Could not deliver forwarded message.').'</span> '.
1.143     wenzelju 3344:                                 &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.')';
1.53      raeburn  3345:                 }
1.143     wenzelju 3346:                 $message = &Apache::loncommon::confirmwrapper($message);
                   3347:                 $r->print($message);
1.53      raeburn  3348:             }
                   3349:             &Apache::loncommunicate::menu($r);
                   3350:         } else {
                   3351: 	    &sendoffmail($r,$folder);
                   3352:         }
1.1       albertel 3353: 	if ($env{'form.storebasecomment'}) {
                   3354: 	    &storecomment($r);
1.38      raeburn  3355:         }
1.1       albertel 3356: 	if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
1.38      raeburn  3357: 	        &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
1.1       albertel 3358: 				      $env{'course.'.$env{'request.course.id'}.'.domain'},
                   3359: 				      'Course_Announcements',
                   3360: 				      $env{'form.subject'},
                   3361: 				      $env{'form.message'},'/adm/communicate','public');
                   3362: 	}
1.38      raeburn  3363: 	if ((!exists($env{'form.group'})) && (!$env{'form.displayedcrit'})) {
1.53      raeburn  3364: 	    &disall($r,($folder?$folder:$dismode),$msgstatus);
1.36      albertel 3365: 	}
1.1       albertel 3366:     } elsif ($env{'form.newfolder'}) {
                   3367: 	&printheader($r,'','New Folder');
1.46      raeburn  3368:         my $showfolder = $env{'form.newfolder'};
                   3369: 	my ($makeresult,$warning) = &makefolder($env{'form.newfolder'});
                   3370:         if ($makeresult eq 'ok') {
1.143     wenzelju 3371:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" created.',$showfolder));
                   3372:             $message = &Apache::loncommon::confirmwrapper($message);
                   3373:             $r->print($message);
1.46      raeburn  3374:         } else {
1.143     wenzelju 3375:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Creation failed.').' '.$makeresult.'<br />'.$warning,1);
                   3376:             $message = &Apache::loncommon::confirmwrapper($message);
                   3377:             $r->print($message);
1.46      raeburn  3378:             $showfolder = $folder;
                   3379:         }
                   3380:         &Apache::loncommunicate::menu($r);
1.53      raeburn  3381: 	&disall($r,$showfolder,$msgstatus);
1.1       albertel 3382:     } elsif ($env{'form.showcommentbaseurl'}) {
                   3383: 	&storedcommentlisting($r);
1.46      raeburn  3384:     } elsif ($env{'form.folderaction'} eq 'delete') {
                   3385:         &printheader($r,'','Deleted Folder');
                   3386:         my $showfolder = '';
                   3387:         my $delresult = &deletefolder($folder);
                   3388:         if ($delresult eq 'ok') {
1.143     wenzelju 3389:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" deleted.',$folder));
                   3390:             $message = &Apache::loncommon::confirmwrapper($message);
                   3391:             $r->print($message);
1.65      raeburn  3392:             $env{'form.folder'} = '';
1.46      raeburn  3393:         } else {
1.143     wenzelju 3394:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Deletion failed.').' '.$delresult,1);
                   3395:             $message = &Apache::loncommon::confirmwrapper($message);
                   3396:             $r->print($message);
1.46      raeburn  3397:             $showfolder = $folder;
                   3398:         }
                   3399:         &Apache::loncommunicate::menu($r);
1.53      raeburn  3400:         &disall($r,$showfolder,$msgstatus);
1.46      raeburn  3401:     } elsif ($env{'form.folderaction'} eq 'rename') {
                   3402:         &printheader($r,'','Renamed Folder');
                   3403:         my $showfolder = $env{'form.renamed'};
                   3404:         my $renresult = &renamefolder($folder);
                   3405:         if ($renresult eq 'ok') {
1.143     wenzelju 3406:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" renamed to "[_2]".',$folder,$showfolder));
                   3407:             $message = &Apache::loncommon::confirmwrapper($message);
                   3408:             $r->print($message);
1.46      raeburn  3409:         } else {
1.143     wenzelju 3410:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Renaming failed.').' '.$renresult,1);
                   3411:             $message = &Apache::loncommon::confirmwrapper($message);
                   3412:             $r->print($message);
1.46      raeburn  3413:             $showfolder = $folder;
                   3414:         }
                   3415:         &Apache::loncommunicate::menu($r);
1.53      raeburn  3416:         &disall($r,$showfolder,$msgstatus);
1.1       albertel 3417:     } else {
1.112     weissno  3418: 	&printheader($r,'','Display All Messages');
1.44      raeburn  3419: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  3420: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
1.1       albertel 3421:     }
                   3422:     $r->print(&Apache::loncommon::end_page());
                   3423:     return OK;
                   3424: }
                   3425: # ================================================= Main program, reset counter
                   3426: 
                   3427: =pod
                   3428: 
                   3429: =cut
                   3430: 
                   3431: 1; 
                   3432: 
                   3433: __END__
                   3434: 

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