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

1.158     raeburn     1: # The LearningOnline Network with CAPA
1.1       albertel    2: # Routines for messaging display
                      3: #
1.182   ! musolffc    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.182   ! musolffc 1403:                      text => &mt('(1 MB max size)'),
        !          1404:                      num  => 1048576,
1.86      raeburn  1405:                     );
                   1406:     if (!$forwarding && !$multiforward) {
1.182   ! musolffc 1407:         $attachrow = '<tr><td colspan="3"><b>'.$lt{'atta'}.'</b> '.$attachmax{'text'}
        !          1408:             .': <input type="file" name="attachment" class="flUpload" multiple />'
        !          1409:             .'</td></tr>'
        !          1410:             .'<input type="hidden" id="free_space" value="'.$attachmax{'num'}.'" />';
1.86      raeburn  1411:     }
1.1       albertel 1412:     if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                   1413: 	|| &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                   1414: 				    '/'.$env{'request.course.sec'})) {
1.138     raeburn  1415:          my $crstype = &Apache::loncommon::course_type();
1.1       albertel 1416: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1.138     raeburn  1417:          my $rsstxt;
                   1418:          if (&Apache::loncommon::course_type() eq 'Community') {
                   1419:              $rsstxt = &mt('Include in community RSS newsfeed');
                   1420:          } else {
                   1421:              $rsstxt = &mt('Include in course RSS newsfeed');
                   1422:          }
1.1       albertel 1423:          $dispcrit=
1.95      raeburn  1424:  '<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 />'.
                   1425:  '<label><input type="checkbox" name="permanent" /> '.
1.100     schafran 1426: &mt('Send copy to permanent e-mail address (if known)').'</label><br />'.
1.95      raeburn  1427: '<label><input type="checkbox" name="rsspost" /> '.
1.138     raeburn  1428: 		  $rsstxt.'</label><br />';
1.70      raeburn  1429:     }
1.71      raeburn  1430:     if ($broadcast ne 'group') {
                   1431:         if (&Apache::lonnet::allowed('dff',$env{'request.course.id'}) ||
                   1432:             &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
                   1433:                                      '/'.$env{'request.course.sec'})) {
                   1434: 
1.138     raeburn  1435:             my $rectxt;
                   1436:             if (&Apache::loncommon::course_type() eq 'Community') {
                   1437:                 $rectxt = &mt("Include in community's 'User records' for recipient(s)");
                   1438:             } else {
                   1439:                 $rectxt = &mt("Include in course's 'User records' for recipient(s)");
                   1440:             }
                   1441: 
1.95      raeburn  1442:             $dispcrit.='<label>'.
1.71      raeburn  1443:                        '<input type="checkbox" name="courserecord" value="1" /> '.
1.138     raeburn  1444:                        $rectxt.
1.95      raeburn  1445:                        '</label><br />';
1.71      raeburn  1446:         }
1.70      raeburn  1447:     }
                   1448: 
1.1       albertel 1449:     my %message;
                   1450:     my %content;
1.95      raeburn  1451:     my ($hasfloat,$broadcast_js,$sendmode,$can_grp_broadcast);
1.1       albertel 1452:     my $defdom=$env{'user.domain'};
1.95      raeburn  1453:     if ($broadcast eq 'group') {
                   1454:         my %access_status = (
                   1455:                            active => 0,
                   1456:                            previous => 0,
                   1457:                            future => 0,
                   1458:                       );
                   1459:  
                   1460:         if ($group eq '') {
                   1461:             my $studentsel = &discourse(\%access_status);
                   1462:             if ($studentsel) {
1.154     raeburn  1463:                 $r->print('<div class="LC_left_float">'.$studentsel.'</div>');
1.95      raeburn  1464:                 $hasfloat = 1;
                   1465:             }
                   1466:         } else {
                   1467:             $can_grp_broadcast = &check_group_priv($group);
                   1468:             if ($can_grp_broadcast) {
1.105     raeburn  1469:                 $hasfloat = &disgroup($r,$cdom,$cnum,$group,\%access_status);
1.95      raeburn  1470:             }
                   1471:         }
                   1472:         if ($hasfloat) {
                   1473:             $sendmode = '<input type="hidden" name="sendmode" value="group" />'."\n";
                   1474:             $broadcast_js = qq|
                   1475: <script type="text/javascript">
1.127     bisitz   1476: // <![CDATA[
1.95      raeburn  1477: function courseRecipients() {
                   1478: |;
                   1479:         foreach my $type (keys(%access_status)) {
                   1480:             if ($access_status{$type}) {
                   1481:                 my $formname = $type.'users';
                   1482:                 if ($type eq 'active' && $group ne '') {
                   1483:                     $broadcast_js .= qq|
                   1484:                     document.compemail.groupmail.value = document.$formname.groupmail[document.$formname.groupmail.selectedIndex].value;
                   1485: |;
                   1486:                 }
1.160     golterma 1487:                 #typeof(...forminput.length) returns 'undefined' if only one entry exists
1.95      raeburn  1488:                 $broadcast_js .= qq|
                   1489:     if (typeof(document.$formname.selectedusers_forminput.length)=="undefined") {
1.160     golterma 1490:         if (document.$formname.selectedusers_forminput.checked) {
                   1491:             document.compemail.courserecips.value += '_&&&_'+document.$formname.selectedusers_forminput.value;
                   1492:         }
1.95      raeburn  1493:     } else {
                   1494:         for (var i=0; i<document.$formname.selectedusers_forminput.length; i++) {
                   1495:             if (document.$formname.selectedusers_forminput[i].checked) {
                   1496:                 document.compemail.courserecips.value += '_&&&_'+document.$formname.selectedusers_forminput[i].value;  
                   1497:             }
                   1498:         }
                   1499:     }
                   1500:                 |;
                   1501:             }
                   1502:         }
                   1503:         $broadcast_js .= qq|
                   1504:     return;
                   1505: }
1.127     bisitz   1506: // ]]>
1.95      raeburn  1507: </script>
                   1508: 
                   1509: |;
                   1510:         }
                   1511:     }
1.1       albertel 1512:     if ($forwarding) {
                   1513: 	%message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]);
                   1514: 	%content=&Apache::lonmsg::unpackagemsg($message{$forwarding},$folder);
                   1515: 	$dispcrit.='<input type="hidden" name="forwid" value="'.
                   1516: 	    $forwarding.'" />';
1.94      bisitz   1517: 	$func1='Forward'; # do not translate here!
1.1       albertel 1518: 	
                   1519: 	$dissub=&mt('Forwarding').': '.$content{'subject'};
                   1520: 	$dismsg=&mt('Forwarded message from').' '.
                   1521: 	    $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
                   1522: 	if ($content{'baseurl'}) {
1.29      www      1523: 	    $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1       albertel 1524: 	}
                   1525:     }
                   1526:     if ($replying) {
                   1527: 	%message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
                   1528: 	%content=&Apache::lonmsg::unpackagemsg($message{$replying},$folder);
                   1529: 	$dispcrit.='<input type="hidden" name="replyid" value="'.
                   1530: 	    $replying.'" />';
1.94      bisitz   1531: 	$func1='Send Reply to'; # do not translate here!
1.1       albertel 1532: 	
                   1533: 	$dissub=&mt('Reply').': '.$content{'subject'};       
                   1534: 	$dismsg='> '.$content{'message'};
                   1535: 	$dismsg=~s/\r/\n/g;
                   1536: 	$dismsg=~s/\f/\n/g;
                   1537: 	$dismsg=~s/\n+/\n\> /g;
                   1538: 	if ($content{'baseurl'}) {
1.29      www      1539: 	    $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1       albertel 1540: 	    if ($env{'user.adv'}) {
1.72      albertel 1541: 		$disbase.='<label><input type="checkbox" name="storebasecomment" />'.&mt('Save message for re-use').
1.1       albertel 1542: 		    '</label> <a href="/adm/email?showcommentbaseurl='.
1.29      www      1543: 		    &escape($content{'baseurl'}).'" target="comments">'.
1.1       albertel 1544: 		    &mt('Show re-usable messages').'</a><br />';
                   1545: 	    }
                   1546: 	}
1.73      raeburn  1547:         my $jscript = &Apache::loncommon::check_uncheck_jscript();
                   1548:         $r->print(<<"ENDREPSCRIPT");
                   1549: <script type="text/javascript">
1.127     bisitz   1550: // <![CDATA[
1.73      raeburn  1551: $jscript
1.127     bisitz   1552: // ]]>
1.73      raeburn  1553: </script>
                   1554: ENDREPSCRIPT
1.1       albertel 1555:     }
                   1556:     my $citation=&displayresource(%content);
1.95      raeburn  1557:     my $onsubmit;
1.1       albertel 1558:     if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
1.23      www      1559:     if ($env{'form.text'}) { $dismsg=$env{'form.text'}; }
                   1560:     if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; }
1.95      raeburn  1561:     if ($hasfloat) {
1.154     raeburn  1562:         $r->print($broadcast_js.'<div class="LC_left_float">');
1.95      raeburn  1563:         $onsubmit = ' onsubmit="javascript:courseRecipients();" ';
                   1564:     }
1.23      www      1565:     $r->print(
1.1       albertel 1566:                 '<form action="/adm/email"  name="compemail" method="post"'.
1.95      raeburn  1567:                 ' enctype="multipart/form-data"'.$onsubmit.'>'."\n".
                   1568:                 '<input type="hidden" name="sendmail" value="on" />'."\n".
                   1569:                 '<table>');
                   1570:     if (($broadcast eq 'group') && ($group ne '') && (!$can_grp_broadcast)) {
1.38      raeburn  1571:         $r->print(&recipient_input_row($cdom,%lt));
1.95      raeburn  1572:     }
1.38      raeburn  1573:     if (($broadcast ne 'group') && ($broadcast ne 'upload')) {
1.1       albertel 1574: 	if ($replying) {
1.78      raeburn  1575:             if ($content{'noreplies'}) {
                   1576:                 $r->print('<tr><td>'.&mt('This message was designated by the sender not to allow replies.').'</td></tr></table></form>');
                   1577:                 return;
                   1578:             }
1.95      raeburn  1579:             $r->print('<tr><td colspan="3"><b>'.&mt('Replying to').'</b> ');
1.78      raeburn  1580:             if ($content{'replytoaddr'}) {
                   1581:                 my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
                   1582:                 if ($replytoname ne '' && $replytodom ne '') {
                   1583:                     $r->print(&Apache::loncommon::plainname($replytoname,
                   1584:                                  $replytodom).' ('.$replytoname.':'.
                   1585:                                  $replytodom.')');
                   1586:                     $r->print('<input type="hidden" name="recuname" value="'.
                   1587:                           $replytoname.'" />'.
                   1588:                           '<input type="hidden" name="recdomain" value="'.
                   1589:                           $replytodom.'" /></td></tr>');
                   1590: 
                   1591:                 } else {
                   1592:                     $r->print(&mt('The sender did not designate a reply to address for this message.').'</td></tr></table>');
                   1593:                     return;
                   1594:                 }
                   1595:             } else {
                   1596: 	        $r->print(&Apache::loncommon::aboutmewrapper(
1.1       albertel 1597: 							 &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
1.14      albertel 1598: 		      $content{'sendername'}.':'.
1.78      raeburn  1599: 		      $content{'senderdomain'}.')');
                   1600:                 $r->print('<input type="hidden" name="recuname" value="'.
                   1601: 		          $content{'sendername'}.'" />'.
                   1602: 		          '<input type="hidden" name="recdomain" value="'.
                   1603:                           $content{'senderdomain'}.'" /></td></tr>');
                   1604:             }
1.73      raeburn  1605:             if ($content{'recipid'}) {
1.95      raeburn  1606:                 my %recips;
                   1607:                 &retrieve_recips('replying',\%content,\%recips);
                   1608:                 if (ref($recips{'to'}) eq 'ARRAY') {
                   1609:                     if (@{$recips{'to'}} > 0) {
                   1610:                         my $replyall;
                   1611:                         if (@{$recips{'to'}} > 1) {
                   1612:                             $replyall = qq|
                   1613:  <span class="LC_nobreak">
                   1614:       <input type="button" value="check all"
                   1615:         onclick="javascript:checkAll(document.compemail.replying_to)" />
                   1616:         &nbsp;&nbsp;
                   1617:       <input type="button" value="uncheck all"
                   1618:         onclick="javascript:uncheckAll(document.compemail.replying_to)" />
                   1619:  </span>
                   1620: |;
                   1621:                         }
                   1622:                         my $tolist = join(' ',@{$recips{'to'}});
                   1623:                         $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>');
                   1624:                     }
                   1625:                 }
                   1626:                 if (ref($recips{'cc'}) eq 'ARRAY') {
                   1627:                     if (@{$recips{'cc'}} > 0) {
                   1628:                         my $replyall;
                   1629:                         if (@{$recips{'cc'}} > 1) {
                   1630:                             $replyall = qq|
1.73      raeburn  1631:  <span class="LC_nobreak">
                   1632:       <input type="button" value="check all"
                   1633:         onclick="javascript:checkAll(document.compemail.replying_cc)" />
                   1634:         &nbsp;&nbsp;
                   1635:       <input type="button" value="uncheck all"
                   1636:         onclick="javascript:uncheckAll(document.compemail.replying_cc)" />
                   1637:  </span>
                   1638: |;
1.95      raeburn  1639:                         }
                   1640:                         my $cclist = join(' ',@{$recips{'cc'}});
                   1641:                         $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>');
                   1642:                     }
                   1643:                 }
                   1644:                 if ($content{'group'} ne '') {
                   1645:                     if (&check_group_priv($content{'group'})) {
                   1646:                         if (ref($recips{'group_cc_broadcast'}) eq 'ARRAY') {
                   1647:                             if (@{$recips{'group_cc_broadcast'}} > 0) {
                   1648:                                 my $replyall;
                   1649:                                 if (@{$recips{'group_cc_broadcast'}} > 1) {
                   1650:                                     $replyall = qq|
                   1651:  <span class="LC_nobreak">
                   1652:       <input type="button" value="check all"
                   1653:         onclick="javascript:checkAll(document.compemail.replying_groupcc)" />
                   1654:         &nbsp;&nbsp;
                   1655:       <input type="button" value="uncheck all"
                   1656:         onclick="javascript:uncheckAll(document.compemail.replying_groupcc)" />
                   1657:  </span>
                   1658: |;
                   1659:                                 }
                   1660:                                 my $groupcclist = join(' ',@{$recips{'group_cc_broadcast'}});
                   1661:                                 $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>');
                   1662:                             }
                   1663:                         }
                   1664:                     }
1.73      raeburn  1665:                 }
                   1666:             }
1.1       albertel 1667: 	} else {
1.38      raeburn  1668:             $r->print(&recipient_input_row($defdom,%lt));
1.1       albertel 1669:         }
                   1670:     }
1.109     raeburn  1671:     my $latexHelp = &Apache::loncommon::helpLatexCheatsheet(undef,undef,1);
1.154     raeburn  1672:     my $textareaclass;
                   1673:     if (&Apache::lonhtmlcommon::htmlareabrowser()) {
                   1674:         $r->print(&Apache::lonhtmlcommon::htmlareaselectactive());
                   1675:         $textareaclass = 'class="LC_richDefaultOff"';
                   1676:     }
1.53      raeburn  1677:     my $subj_size;
                   1678:     if ($multiforward) {
                   1679:         $r->print(&additional_rec_row(\%lt));
                   1680:         $r->print('<tr><td colspan="2">'.
                   1681:                   &mt('Unless you choose otherwise:').'<ul><li>'.
1.166     raeburn  1682:         &mt("The subject in each forwarded message will be [_1]'Forwarding:'[_2] followed by the original subject.",'<i>','</i>').'</li><li>'.
1.165     bisitz   1683:         &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   1684:         $func1='Forward'; # do not translate here!
1.53      raeburn  1685:         $dissub = &mt('Forwarding').': ';
                   1686:         $subj_size = '10';
                   1687:         my $extra = '&lt;'.&mt('original subject').'&gt;&nbsp;&nbsp;&nbsp;'.
                   1688:                     '<input type="radio" name="showorigsubj" value="1" checked="checked" />'.&mt('Yes').'&nbsp;<input type="radio" name="showorigsubj" value="0" />'.&mt('No');
                   1689:         $dismsg = &mt('Forwarded message from ').' ';
                   1690:         my $sender = &mt("sender's name");
                   1691:         $r->print(&msg_subject_row($dissub,\%lt,$subj_size,$extra));
                   1692:         $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>
                   1693: </table>
1.95      raeburn  1694: <br /><table>
                   1695: <tr><td align="left">'."\n".
                   1696: $latexHelp."<br />\n".
                   1697: &mt("Any new text to display before the text of the original messages:").'<br />'."\n".
1.154     raeburn  1698: '<textarea name="message" id="message" cols="80" rows="5" wrap="hard" $textareaclass></textarea>');
1.53      raeburn  1699:         my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
                   1700:         foreach my $msg (@to_forward) {
                   1701:             $r->print('<input type="hidden" name="delmark" value="'.$msg.'" />');
                   1702:         }
1.94      bisitz   1703:         $r->print(&submit_button_row($folder,$dismode,&mt($func1.' '.$func2{'msg'}),
1.53      raeburn  1704:                                      \%lt));
                   1705:     } elsif ($broadcast ne 'upload') {
                   1706:         $subj_size = '50';
                   1707:         $r->print(&additional_rec_row(\%lt));
1.78      raeburn  1708:         if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                   1709:             || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                   1710:                                         '/'.$env{'request.course.sec'})) {
                   1711:             $r->print(&reply_to_row(\%lt));
                   1712:         }
1.53      raeburn  1713:         $r->print(&msg_subject_row($dissub,\%lt,$subj_size));
                   1714:         $r->print(<<"ENDCOMP");
1.95      raeburn  1715: $attachrow
                   1716: </table><br />
1.117     bisitz   1717: $latexHelp<br />
1.154     raeburn  1718: <textarea name="message" id="message" cols="80" rows="15" wrap="hard" $textareaclass>$dismsg
                   1719: </textarea>
                   1720: <br />
1.95      raeburn  1721: $sendmode
1.1       albertel 1722: $dispcrit
                   1723: $disbase
                   1724: ENDCOMP
1.97      schafran 1725:         $r->print(&submit_button_row($folder,$dismode,&mt($func1.' '.$func2{'ma'}),
1.95      raeburn  1726:                                      \%lt,$hasfloat,$group));
1.53      raeburn  1727:         $r->print($citation);
1.38      raeburn  1728:         if (exists($env{'form.ref'})) {
                   1729:             $r->print('<input type="hidden" name="ref" value="'.
                   1730:                       $env{'form.ref'}.'" />');
                   1731:         }
                   1732:         if (exists($env{'form.group'})) {
                   1733:             $r->print('<input type="hidden" name="group" value="'.
                   1734:                       $env{'form.group'}.'" />');
                   1735:         }
1.1       albertel 1736:     } else { # $broadcast is 'upload'
1.50      raeburn  1737: 	$r->print(<<ENDBLOCK);
1.1       albertel 1738: <input type="hidden" name="sendmode" value="upload" />
                   1739: <input type="hidden" name="send" value="on" />
1.50      raeburn  1740: <h3>$lt{'gen'}</h3>
1.1       albertel 1741: <p>
                   1742: Subject: <input type="text" size="50" name="subject" />
                   1743: </p>
1.50      raeburn  1744: <p>$lt{'gmt'}:<br />
1.154     raeburn  1745: <textarea name="message" id="message" cols="60" rows="10" wrap="hard" $textareaclass>$dismsg
                   1746: </textarea></p>
1.1       albertel 1747: <p>
1.50      raeburn  1748: $lt{'tff'}:
                   1749: ENDBLOCK
                   1750:        $r->print('
                   1751: <pre>'."\n".
                   1752: &mt('username1:domain1: text')."\n".
                   1753: &mt('username2:domain2: text')."\n".
                   1754: &mt('username3:domain1: text')."\n".
                   1755: '</pre>
1.1       albertel 1756: </p>
                   1757: <p>
1.164     bisitz   1758: '.&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  1759:         $r->print(<<ENDUPLOAD);
                   1760: </p>
1.1       albertel 1761: <p>
                   1762: <input type="file" name="upfile" size="40" /></p><p>
                   1763: $dispcrit
1.50      raeburn  1764: <input type="submit" value="$lt{'uas'}" /></p>
1.1       albertel 1765: ENDUPLOAD
                   1766:     }
1.36      albertel 1767:     if ($env{'form.displayedcrit'}) {
                   1768: 	$r->print('<input type="hidden" name="displayedcrit" value="true" />');
                   1769:     }
1.95      raeburn  1770:     $r->print('</form>');
                   1771:     if ($hasfloat) {
1.154     raeburn  1772:         $r->print('</div><div class="LC_clear_float_footer"></div>');
1.95      raeburn  1773:     }
                   1774:     $r->print(&generate_preview_form);
                   1775: }
                   1776: 
                   1777: sub check_group_priv {
                   1778:     my ($group) = @_;
                   1779:     my $cid = $env{'request.course.id'};
                   1780:     my $sec = $env{'request.course.sec'};
                   1781:     return if !$cid;
                   1782:     my $can_broadcast = &Apache::lonnet::allowed('sgb',$cid.'/'.$group);
                   1783:     my $viewgrps = &Apache::lonnet::allowed('vcg',$cid.($sec?'/'.$sec:''));
                   1784:     my $editgrps = &Apache::lonnet::allowed('mdg',$cid.($sec?'/'.$sec:''));
                   1785:     if ($viewgrps || $editgrps || $can_broadcast) {
                   1786:         return 1;
                   1787:     }
                   1788:     return;
1.1       albertel 1789: }
                   1790: 
1.38      raeburn  1791: sub recipient_input_row {
                   1792:     my ($dom,%lt) = @_;
                   1793:     my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain');
                   1794:     my $selectlink=
                   1795:       &Apache::loncommon::selectstudent_link('compemail','recuname',
                   1796:                                              'recdomain');
                   1797:     my $output = <<"ENDREC";
1.95      raeburn  1798: <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  1799: ENDREC
                   1800:     return $output;
                   1801: }
                   1802: 
1.78      raeburn  1803: sub reply_to_row {
                   1804:     my ($lt) = @_;
                   1805:     my $radioyes = &mt('Yes');
                   1806:     my $radiono = &mt('No');
                   1807:     my $output = <<"ENDREP";
1.95      raeburn  1808: <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  1809: ENDREP
                   1810:     return $output;
                   1811: }
                   1812: 
1.53      raeburn  1813: sub additional_rec_row {
                   1814:     my ($lt) = @_;
1.73      raeburn  1815:     my $cc = &mt('Cc:');
1.85      bisitz   1816:     my $bcc = &mt('Bcc:');
                   1817:     my $exmpl = &mt('username:domain,username:domain,...'); 
1.53      raeburn  1818:     my $output = <<"ENDADD";
1.125     bisitz   1819: <tr><td colspan="3"><fieldset id="LC_additionalrecips"><legend>$lt->{'ad'} <tt>($exmpl)</tt></legend><table>
1.95      raeburn  1820: <tr><td>&nbsp;</td><td>$lt->{'to'}</td><td><input type="text" size="50" name="additionalrec_to" /></td></tr>
                   1821: <tr><td>&nbsp;</td><td>$cc</td><td><input type="text" size="50" name="additionalrec_cc" /></td></tr> 
1.110     raeburn  1822: <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  1823: ENDADD
                   1824:     return $output;
                   1825: }
                   1826: 
                   1827: sub submit_button_row {
1.95      raeburn  1828:     my ($folder,$dismode,$sendtext,$lt,$is_crsform,$group) = @_;
                   1829:     my $pre=&mt("Show Preview and Check Spelling");
1.98      schafran 1830:     my $value=&mt('Send');
1.95      raeburn  1831:     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();" />';
                   1832:     my $output = qq|
1.53      raeburn  1833: <input type="hidden" name="folder" value="$folder" />
1.95      raeburn  1834: <input type="hidden" name="dismode" value="$dismode" />|;
                   1835:     if ($is_crsform) {
                   1836:         $output .= '<input type="hidden" name="courserecips" value="" />'."\n";
                   1837:         if ($group ne '') {
                   1838:             $output .= '<input type="hidden" name="groupmail" value="" />'."\n";
                   1839:         }
                   1840:     }
                   1841:     $output .= qq|
                   1842: <table><tr><td align="left">
1.98      schafran 1843: <input type="submit" name="send" value="$value" title="$sendtext" />
1.95      raeburn  1844: <input type="submit" name="cancel" value="$lt->{'ca'}" />
                   1845: </td><td width="60">&nbsp;</td><td align="right">$prevbutton</td></tr></table>
1.53      raeburn  1846: |;
                   1847:     return $output;
                   1848: }
                   1849: 
                   1850: sub msg_subject_row {
                   1851:     my ($dissub,$lt,$subj_size,$extra) = @_;
1.95      raeburn  1852:     my $output = '<tr><td colspan="3"><b>'.$lt->{'sb'}.'</b>:&nbsp;<input type="text" size="'.
1.53      raeburn  1853:                  $subj_size.'" name="subject" value="'.$dissub.'" />'.$extra.
                   1854:                  '</td></tr>';
                   1855:     return $output;
                   1856: }
                   1857: 
1.95      raeburn  1858: sub generate_preview_form {
                   1859:     my $prevbutton = (<<ENDPREVIEW);
                   1860: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
                   1861: <input type="hidden" name="subject" />
                   1862: <input type="hidden" name="comment" />
                   1863: </form>
                   1864: ENDPREVIEW
                   1865: }
                   1866: 
                   1867: # ---------------------------------------------------- Display all face to face
                   1868: 
1.1       albertel 1869: sub retrieve_instructor_comments {
                   1870:     my ($user,$domain)=@_;
                   1871:     my $target=$env{'form.grade_target'};
                   1872:     if (! $env{'request.course.id'}) { return; }
1.49      albertel 1873:     if (! &Apache::lonnet::allowed('dff',$env{'request.course.id'})
                   1874: 	&& ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1       albertel 1875: 				      '/'.$env{'request.course.sec'})) {
                   1876: 	return;
                   1877:     }
                   1878:     my %records=&Apache::lonnet::dump('nohist_email',
                   1879: 			 $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1880: 			 $env{'course.'.$env{'request.course.id'}.'.num'},
                   1881:                          '%255b'.$user.'%253a'.$domain.'%255d');
                   1882:     my $result='';
1.42      raeburn  1883:     foreach my $key (sort(keys(%records))) {
                   1884:         my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1       albertel 1885:         next if ($content{'senderdomain'} eq '');
                   1886:         next if ($content{'subject'} !~ /^Record/);
                   1887: 	# &Apache::lonfeedback::newline_to_br(\$content{'message'});
                   1888: 	$result.='Recorded by '.
1.14      albertel 1889:             $content{'sendername'}.':'.$content{'senderdomain'}."\n";
1.1       albertel 1890:         $result.=
                   1891:             &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
                   1892:      }
                   1893:     return $result;
                   1894: }
                   1895: 
                   1896: sub disfacetoface {
1.136     amueller 1897:     my ($r,$user,$domain,$target)=@_;
1.145     raeburn  1898:     if ($target eq '') {
                   1899:         $target=$env{'form.grade_target'};
                   1900:     }
1.1       albertel 1901:     unless ($env{'request.course.id'}) { return; }
1.49      albertel 1902:     if  (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
                   1903: 	 && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1       albertel 1904: 				       '/'.$env{'request.course.sec'})) {
1.50      raeburn  1905: 	$r->print(&mt('Not allowed'));
1.1       albertel 1906: 	return;
                   1907:     }
                   1908:     my %records=&Apache::lonnet::dump('nohist_email',
                   1909: 			 $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1910: 			 $env{'course.'.$env{'request.course.id'}.'.num'},
                   1911:                          '%255b'.$user.'%253a'.$domain.'%255d');
1.177     raeburn  1912:     my $result='';
1.42      raeburn  1913:     foreach my $key (sort(keys(%records))) {
                   1914:         my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1       albertel 1915:         next if ($content{'senderdomain'} eq '');
1.139     faziophi 1916:     if (!&Apache::lonfeedback::contains_block_html($content{'message'})) {
                   1917: 		&Apache::lonfeedback::newline_to_br(\$content{'message'});
                   1918: 	}
1.1       albertel 1919:         if ($content{'subject'}=~/^Record/) {
                   1920: 	    $result.='<h3>'.&mt('Record').'</h3>';
                   1921:         } elsif ($content{'subject'}=~/^Broadcast/) {
                   1922:             $result .='<h3>'.&mt('Broadcast Message').'</h3>';
                   1923:             if ($content{'subject'}=~/^Broadcast\./) {
                   1924:                 if (defined($content{'coursemsgid'})) {
1.29      www      1925:                     my $crsmsgid = &escape($content{'coursemsgid'});
1.1       albertel 1926:                     my $broadcast_message = &general_message($crsmsgid);
                   1927:                     $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$broadcast_message;
                   1928:                 } else {
                   1929:                     %content=&Apache::lonmsg::unpackagemsg($content{'message'});
                   1930:                     $content{'message'} =
                   1931:                     '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
                   1932:                     $content{'message'};
                   1933:                 }
1.70      raeburn  1934:             }
                   1935:         } elsif ($content{'subject'}=~/^Archive/) {
                   1936:             $result.='<h3>'.&mt('Archived Message').'</h3>';
                   1937:             if (defined($content{'coursemsgid'})) {
                   1938:                 my $crsmsgid = &escape($content{'coursemsgid'});
                   1939:                 my $archive_message = &general_message($crsmsgid);
                   1940:                 $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$archive_message;
                   1941:             } else {
                   1942:                 %content=&Apache::lonmsg::unpackagemsg($content{'message'});
                   1943:                 $content{'message'} =
1.170     bisitz   1944:                 '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1.70      raeburn  1945:                 $content{'message'};
                   1946:             }
1.1       albertel 1947:         } else {
                   1948:             $result.='<h3>'.&mt('Critical Message').'</h3>';
                   1949:             if (defined($content{'coursemsgid'})) {
1.29      www      1950:                 my $crsmsgid=&escape($content{'coursemsgid'});
1.1       albertel 1951:                 my $critical_message = &general_message($crsmsgid);
                   1952:                 $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$critical_message;
                   1953:             } else {
                   1954:                 %content=&Apache::lonmsg::unpackagemsg($content{'message'});
                   1955:                 $content{'message'}=
                   1956:                 '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
                   1957: 		$content{'message'};
                   1958:             }
                   1959:         }
                   1960:         $result.=&mt('By').': <b>'.
                   1961: &Apache::loncommon::aboutmewrapper(
                   1962:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14      albertel 1963: $content{'sendername'}.':'.
1.1       albertel 1964:             $content{'senderdomain'}.') '.$content{'time'}.
                   1965:             '<br /><pre>'.
                   1966:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
                   1967: 	      '</pre>';
                   1968:      }
                   1969:     # Check to see if there were any messages.
                   1970:     if ($result eq '') {
1.106     riegler  1971:         my $lctype = &mt(lc(&Apache::loncommon::course_type()));
1.1       albertel 1972: 	if ($target ne 'tex') { 
1.174     bisitz   1973: 	    $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 1974: 	} else {
1.174     bisitz   1975: 	    $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this '.$lctype.'.').'}\\\\');
1.1       albertel 1976: 	}
1.177     raeburn  1977:     } elsif ($target eq 'tex') {
                   1978:         $r->print(&Apache::lonxml::xmlparse($r,$target,$result));
1.1       albertel 1979:     } else {
1.177     raeburn  1980:         $r->print('<div>'.$result.'</div>');
                   1981:     }
1.1       albertel 1982: }
                   1983: 
                   1984: sub general_message {
                   1985:     my ($crsmsgid) = @_;
                   1986:     my %general_content;
                   1987:     if ($crsmsgid) { 
                   1988:         my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid],
                   1989:                            $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1990:                            $env{'course.'.$env{'request.course.id'}.'.num'});
                   1991:         %general_content = &Apache::lonmsg::unpackagemsg($course_content{$crsmsgid});
                   1992:     }
                   1993:     return $general_content{'message'};
                   1994: }
                   1995: 
                   1996: # ---------------------------------------------------------------- Face to face
                   1997: 
                   1998: sub facetoface {
                   1999:     my ($r,$stage)=@_;
1.49      albertel 2000:     if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
                   2001: 	&& ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1       albertel 2002: 				      '/'.$env{'request.course.sec'})) {
1.50      raeburn  2003: 	$r->print(&mt('Not allowed'));
1.1       albertel 2004: 	return;
                   2005:     }
1.33      albertel 2006:     my $crstype = &Apache::loncommon::course_type();
1.128     raeburn  2007:     my $leaders = ($crstype eq 'Community') ? 'coordinators and leaders'
                   2008:                                             : 'faculty and staff';
1.1       albertel 2009:     &printheader($r,
                   2010: 		 '/adm/email?recordftf=query',
1.70      raeburn  2011: 		 "User Notes, Face-to-Face, Critical Messages, Broadcast Messages, Archived Messages");
1.1       albertel 2012: # from query string
                   2013: 
                   2014:     if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
                   2015:     if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
                   2016: 
                   2017:     my $defdom=$env{'user.domain'};
                   2018: # already filled in
                   2019:     if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
                   2020: # generate output
                   2021:     my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
                   2022:     my $stdbrws = &Apache::loncommon::selectstudent_link
                   2023: 	('stdselect','recuname','recdomain');
                   2024:     my %lt=&Apache::lonlocal::texthash('user' => 'Username',
                   2025: 				       'dom' => 'Domain',
1.70      raeburn  2026: 				       'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, Broadcast Messages and Archived Messages in $crstype",
1.1       albertel 2027: 				       'subm' => 'Retrieve discussion and message records',
1.30      raeburn  2028: 				       'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')',
1.1       albertel 2029: 				       'post' => 'Post this Record');
1.123     bisitz   2030: 
                   2031:     $r->print('<h2>'.$lt{'head'}.'</h2>'
                   2032:              .'<form method="post" action="/adm/email" name="stdselect">'
                   2033:              .'<input type="hidden" name="recordftf" value="retrieve" />'
                   2034:              .&Apache::lonhtmlcommon::start_pick_box()
                   2035:              .&Apache::lonhtmlcommon::row_title($lt{'user'})
                   2036:              .'<input type="text" size="12" name="recuname" value="'.$env{'form.recuname'}.'" />'
                   2037:              .' '.$stdbrws
                   2038:              .&Apache::lonhtmlcommon::row_closure()
                   2039:              .&Apache::lonhtmlcommon::row_title($lt{'dom'})
                   2040:              .$domform
                   2041:              .&Apache::lonhtmlcommon::row_closure(1)
                   2042:              .&Apache::lonhtmlcommon::end_pick_box()
                   2043:              .'<br />'
                   2044:              .'<input type="submit" value="'.$lt{'subm'}.'" />'
1.150     raeburn  2045:              .'</form>'
1.123     bisitz   2046:     );
                   2047: 
1.1       albertel 2048:     if (($stage ne 'query') &&
                   2049:         ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
                   2050:         chomp($env{'form.newrecord'});
                   2051:         if ($env{'form.newrecord'}) {
1.31      albertel 2052: 	    &Apache::lonmsg::store_instructor_comment($env{'form.newrecord'},
                   2053: 						      $env{'form.recuname'},
                   2054: 						      $env{'form.recdomain'});
1.1       albertel 2055:         }
1.123     bisitz   2056:         my $aboutmelink=&Apache::loncommon::aboutmewrapper(
                   2057:                             &Apache::loncommon::plainname($env{'form.recuname'}
                   2058:                                                          ,$env{'form.recdomain'})
                   2059:                            ,$env{'form.recuname'},$env{'form.recdomain'});
                   2060:         $r->print('<hr />'
                   2061:                  .'<h2>'
                   2062:                  .&mt('Discussion and message records for [_1] ([_2])'
                   2063:                      ,$aboutmelink
                   2064:                      ,$env{'form.recuname'}.':'.$env{'form.recdomain'})
1.161     bisitz   2065:                  .'</h2>'
1.123     bisitz   2066:        );
1.1       albertel 2067:         &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
                   2068: 	$r->print(<<ENDRHEAD);
                   2069: <form method="post" action="/adm/email">
                   2070: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
                   2071: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
                   2072: ENDRHEAD
                   2073:         $r->print(<<ENDBFORM);
                   2074: <hr />$lt{'newr'}<br />
                   2075: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
                   2076: <br />
                   2077: <input type="hidden" name="recordftf" value="post" />
                   2078: <input type="submit" value="$lt{'post'}" />
                   2079: </form>
                   2080: ENDBFORM
                   2081:     }
                   2082: }
                   2083: 
                   2084: # ----------------------------------------------------------- Display a message
                   2085: 
                   2086: sub displaymessage {
1.53      raeburn  2087:     my ($r,$msgid,$folder,$msgstatus)=@_;
1.1       albertel 2088:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
                   2089:     my %blocked = ();
                   2090:     my %setters = ();
                   2091:     my $numblocked = 0;
1.33      albertel 2092:     my $crstype = &Apache::loncommon::course_type();
1.30      raeburn  2093: 
1.1       albertel 2094: # info to generate "next" and "previous" buttons and check if message is blocked
1.44      raeburn  2095:     my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53      raeburn  2096:     my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1       albertel 2097:     if ( $blocked{$msgid} eq 'ON' ) {
                   2098:         &printheader($r,'/adm/email',&mt('Display a Message'));
1.129     kalberla 2099:         #$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 2100:         my($blocked, $blocktext) = &Apache::loncommon::blocking_status("com");
1.129     kalberla 2101:         $r->print("<br />".$blocktext);
1.1       albertel 2102:         return;
                   2103:     }
1.59      raeburn  2104:     if ($msgstatus eq '') {
                   2105:         &statuschange($msgid,'read',$folder);
                   2106:     }
1.1       albertel 2107:     my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
                   2108:     my %content=&Apache::lonmsg::unpackagemsg($message{$msgid});
                   2109:     my $counter=0;
1.29      www      2110:     my $escmsgid=&escape($msgid);
1.1       albertel 2111:     foreach (@messages) {
                   2112: 	if ($_->[5] eq $escmsgid){
                   2113: 	    last;
                   2114: 	}
                   2115: 	$counter++;
                   2116:     }
1.82      albertel 2117: 
                   2118:     my $see_anonymous;
                   2119:     my $from_student = 0;
                   2120:     if ($env{'request.course.id'} eq $content{'courseid'}) {
                   2121: 	my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   2122: 	my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   2123: 	my $username = $content{'sendername'}.':'.$content{'senderdomain'};
                   2124: 	my %classlist_entry =
                   2125: 	    &Apache::lonnet::get('classlist',[$username],$cdom,$cnum);
                   2126: 	if (exists($classlist_entry{$username})) {
                   2127: 	    $from_student = 1;
                   2128: 	    $see_anonymous = &Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
                   2129: 	}
                   2130:     }
                   2131: 
                   2132: 
1.1       albertel 2133:     my $number_of_messages = scalar(@messages); #subtract 1 for last index
                   2134: # start output
1.29      www      2135:     &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'});
1.101     bisitz   2136: 
                   2137: # Prepare available functions
1.119     bisitz   2138:     my @functionlist;
1.78      raeburn  2139:     if (!$content{'noreplies'}) {
1.119     bisitz   2140:         push(@functionlist,'<a href="/adm/email?replyto='.&escape($msgid).$sqs.'">'
1.101     bisitz   2141:                      .&mt('Reply')
1.119     bisitz   2142:                      .'</a>');
1.101     bisitz   2143:     }
1.119     bisitz   2144:     push(@functionlist,'<a href="/adm/email?forward='.&escape($msgid).$sqs.'">'
1.101     bisitz   2145:                   .&mt('Forward')
1.119     bisitz   2146:                   .'</a>');
                   2147:     push(@functionlist,'<a href="/adm/email?markunread='.&escape($msgid).$sqs.'">'
1.101     bisitz   2148:                   .&mt('Mark Unread')
1.119     bisitz   2149:                   .'</a>');
                   2150:     push(@functionlist,'<a href="/adm/email?markdel='.&escape($msgid).$sqs.'">'
1.101     bisitz   2151:                   .&mt('Delete')
1.119     bisitz   2152:                   .'</a>');
1.162     bisitz   2153: 
                   2154: # Prepare available navigation
                   2155:     my @navigationlist;
1.1       albertel 2156:     if ($counter > 0){
1.162     bisitz   2157:         push(@navigationlist,'<a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.'">'
1.119     bisitz   2158:                           .&mt('Previous')
                   2159:                           .'</a>');
1.1       albertel 2160:     }
                   2161:     if ($counter < $number_of_messages - 1){
1.162     bisitz   2162:         push(@navigationlist,'<a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.'">'
1.119     bisitz   2163:                           .&mt('Next')
                   2164:                           .'</a>');
1.101     bisitz   2165:     }
1.162     bisitz   2166:     push(@navigationlist,'<a href="/adm/email?'.$sqs.'">'
                   2167:                   .&mt('Back to Folder Display')
                   2168:                   .'</a>');
1.101     bisitz   2169: 
                   2170: # Prepare available actions
1.59      raeburn  2171:     my $symb;
                   2172:     if (defined($content{'symb'})) {
                   2173:         $symb = $content{'symb'};
                   2174:     } elsif (defined($content{'baseurl'})) {
                   2175:         $symb=&Apache::lonnet::symbread($content{'baseurl'});
                   2176:     }
1.162     bisitz   2177:     my @actionlist;
1.1       albertel 2178:     if ($env{'user.adv'}) {
1.101     bisitz   2179: 
1.1       albertel 2180: 	if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
1.119     bisitz   2181: 		push(@actionlist,&Apache::loncommon::track_student_link(
1.171     bisitz   2182:                                       'View recent activity'
1.119     bisitz   2183:                                      ,$content{'sendername'}
                   2184:                                      ,$content{'senderdomain'}
                   2185:                                      ,'check'));
1.90      bisitz   2186: 	}
1.1       albertel 2187: 	if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
1.119     bisitz   2188: 	    push(@actionlist,&Apache::loncommon::pprmlink(
                   2189:                                   &mt('Set/Change parameters')
                   2190:                                      ,$content{'sendername'}
                   2191:                                      ,$content{'senderdomain'}
                   2192:                                      ,$symb
                   2193:                                      ,'check'));
1.1       albertel 2194: 	}
                   2195: 	if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
1.119     bisitz   2196: 	    push(@actionlist,&Apache::loncommon::pgrdlink(
                   2197:                                  &mt('Set/Change grades')
                   2198:                                      ,$content{'sendername'}
                   2199:                                      ,$content{'senderdomain'}
                   2200:                                      ,$symb
                   2201:                                      ,'check'));
1.90      bisitz   2202: 	}
1.126     bisitz   2203:     }
                   2204: 
1.162     bisitz   2205: # Print functionlist, navigationlist, and actionlist in page header
1.126     bisitz   2206:         my $functions='<div class="LC_columnSection">';
1.101     bisitz   2207: 
1.126     bisitz   2208:         # Functionlist
                   2209:         $functions.=&Apache::lonhtmlcommon::start_funclist();
                   2210:         foreach my $item (@functionlist) {
                   2211:             $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
                   2212:         }
                   2213:         $functions .= &Apache::lonhtmlcommon::end_funclist();
                   2214: 
1.162     bisitz   2215:         # Navigationlist
                   2216:         $functions.=&Apache::lonhtmlcommon::start_funclist(
                   2217:                     &mt('Navigation'));
                   2218:         foreach my $item (@navigationlist) {
                   2219:             $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
                   2220:         }
                   2221:         $functions .= &Apache::lonhtmlcommon::end_funclist();
                   2222: 
1.126     bisitz   2223:         # Actionlist
1.119     bisitz   2224:         if (@actionlist) {
1.162     bisitz   2225:             $functions.=&Apache::lonhtmlcommon::start_funclist(
                   2226:                             &mt('Currently available actions (will open extra window)'));
1.119     bisitz   2227:             foreach my $item (@actionlist) {
1.126     bisitz   2228:                 $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
1.119     bisitz   2229:             }
1.126     bisitz   2230:             $functions.=&Apache::lonhtmlcommon::end_funclist();
1.90      bisitz   2231:         }
1.126     bisitz   2232: 
                   2233:         $functions.='</div>';
                   2234:         $r->print(&Apache::loncommon::head_subbox($functions));
                   2235: 
1.101     bisitz   2236: 
1.95      raeburn  2237:     my ($tonum,$tolist,$cclist,$bcclist,$groupcclist,%recipients);
                   2238:     if ($content{'recipid'}) {
                   2239:         $tonum = &retrieve_recips('display',\%content,\%recipients);
                   2240:         if (ref($recipients{'cc'}) eq 'ARRAY') {
                   2241:             $cclist = join(', ',@{$recipients{'cc'}});
                   2242:         }
                   2243:         if (ref($recipients{'to'}) eq 'ARRAY') {
                   2244:             $tolist = join(', ',@{$recipients{'to'}});
                   2245:         }
                   2246:         if (ref($recipients{'bcc'}) eq 'ARRAY') {
                   2247:             $bcclist = join(', ',@{$recipients{'bcc'}});
                   2248:         }
                   2249:     }
1.107     raeburn  2250: 
                   2251:     my $broadcast_link;
                   2252:     if (($content{'courseid'}) && ($content{'recipid'} &&
                   2253:         (ref($recipients{'course_broadcast'}) eq 'ARRAY') ||
                   2254:         (ref($recipients{'group_cc_broadcast'}) eq 'ARRAY') ||
                   2255:         (ref($recipients{'group_bcc_broadcast'}) eq 'ARRAY'))) {
                   2256:         $broadcast_link = &recipients_link($r,\%content,\%recipients);
                   2257:     }
                   2258: 
                   2259:     if (((!$tolist) && (!$broadcast_link)) && ref($content{'recuser'}) eq 'ARRAY') {
1.95      raeburn  2260:         my @recipients;
1.73      raeburn  2261:         for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
                   2262:             $recipients[$i] =  &Apache::loncommon::aboutmewrapper(
                   2263:                &Apache::loncommon::plainname($content{'recuser'}[$i],
1.1       albertel 2264:                                       $content{'recdomain'}[$i]),
1.73      raeburn  2265:                   $content{'recuser'}[$i],$content{'recdomain'}[$i]).
1.95      raeburn  2266:            ' ('.$content{'recuser'}[$i].':'.$content{'recdomain'}[$i].') ';
1.73      raeburn  2267:         }
1.95      raeburn  2268:         $tolist = join(', ',@recipients);
1.73      raeburn  2269:     }
1.59      raeburn  2270:     my ($restitle,$baseurl,$refers_to);
                   2271:     if (defined($content{'resource_title'})) {
                   2272:         $restitle = $content{'resource_title'};
                   2273:     } else {
                   2274:         if (defined($content{'baseurl'})) {
                   2275:             $restitle = &Apache::lonnet::gettitle($content{'baseurl'});
                   2276:         }
                   2277:     }
                   2278:     if (defined($content{'baseurl'})) {
                   2279:         $baseurl = &Apache::lonenc::check_encrypt($content{'baseurl'});
                   2280:     }
1.104     raeburn  2281:     $r->print('<div class="LC_clear_float_footer">');
1.82      albertel 2282:     if ($from_student && $see_anonymous ) {
1.104     raeburn  2283: 	$r->print(&Apache::loncommon::student_image_tag($content{'senderdomain'},$content{'sendername'}).'</br>');
1.82      albertel 2284:     }
                   2285: 
1.91      bisitz   2286:     # Display LON-CAPA Message (Start)
                   2287:     # Subject
1.104     raeburn  2288:     $r->print('</div>'
1.91      bisitz   2289:              .&Apache::lonhtmlcommon::start_pick_box()
                   2290:              .&Apache::lonhtmlcommon::row_title(&mt('Subject'))
                   2291:              .$content{'subject'}
                   2292:              .&Apache::lonhtmlcommon::row_closure()
                   2293:     );
1.73      raeburn  2294:     if ($folder eq 'sent') {
1.91      bisitz   2295:         # To
1.107     raeburn  2296:         if ($tolist) {
                   2297:             $r->print(&Apache::lonhtmlcommon::row_title(&mt('To'))
                   2298:                      .$tolist
                   2299:                      .&Apache::lonhtmlcommon::row_closure()
                   2300:             );
                   2301:         }
1.95      raeburn  2302:         if ($cclist) {
                   2303:             $r->print(&Apache::lonhtmlcommon::row_title(&mt('Cc'))
                   2304:                      .$cclist
                   2305:                      .&Apache::lonhtmlcommon::row_closure()
                   2306:             );
                   2307:         }
                   2308:         if ($bcclist) {
                   2309:             $r->print(&Apache::lonhtmlcommon::row_title(&mt('Bcc'))
                   2310:                      .$bcclist
                   2311:                      .&Apache::lonhtmlcommon::row_closure()
                   2312:             );
                   2313:         }
                   2314:         if (($content{'courseid'}) && ($content{'recipid'})) {
                   2315:             my %broadcast_types = 
                   2316:                 &Apache::lonlocal::texthash (
                   2317:                     course_broadcast    => 'Broadcast to', 
                   2318:                     group_cc_broadcast  => 'Cc to group',
                   2319:                     group_bcc_broadcast => 'Bcc to group',
                   2320:                 );                   
                   2321:             foreach my $type (sort(keys(%broadcast_types))) {
                   2322:                 if (ref($recipients{$type}) eq 'ARRAY') {
                   2323:                     my $num = @{$recipients{$type}};
                   2324:                     my $broadcastlist = join(', ',@{$recipients{$type}});
                   2325:                     if ($broadcastlist && $broadcast_link) {
                   2326:                         if ($type eq 'group_cc_broadcast') {
                   2327:                             $groupcclist = $broadcastlist;
                   2328:                         }
                   2329:                         $r->print(&Apache::lonhtmlcommon::row_title(
                   2330:                                             $broadcast_types{$type})
                   2331:                                   .&mt('[quant,_1,recipient]',$num)
                   2332:                                   .' <a href="javascript:showBroadcastList();">['
                   2333:                                   .&mt('Show').']</a>' 
                   2334:                                   .&Apache::lonhtmlcommon::row_closure());
                   2335:                     }
                   2336:                 }
                   2337:             }
                   2338:         }
1.78      raeburn  2339:         if ($content{'replytoaddr'}) {
                   2340:             my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
                   2341:             if ($replytoname ne '' && $replytodom ne '') {
1.91      bisitz   2342:                 $r->print(&Apache::lonhtmlcommon::row_title(&mt('Reply To'))
1.95      raeburn  2343:                          .$replytoname.':'.$replytodom
1.91      bisitz   2344:                          .&Apache::lonhtmlcommon::row_closure()
                   2345:                 );
1.78      raeburn  2346:             }
                   2347:         }
1.73      raeburn  2348:     } else {
1.91      bisitz   2349:         # From, Reply
                   2350:         $r->print(&Apache::lonhtmlcommon::row_title(&mt('From'))
                   2351:                  .&Apache::loncommon::aboutmewrapper(
                   2352:                      &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
                   2353:                                                  $content{'sendername'},$content{'senderdomain'})
                   2354:         );
1.78      raeburn  2355:         if ($content{'noreplies'}) {
1.91      bisitz   2356:             $r->print(' ('.&mt('No replies to sender').')'
                   2357:                      .&Apache::lonhtmlcommon::row_closure()
1.95      raeburn  2358:             );
1.78      raeburn  2359:         } else {
                   2360:             if ($content{'replytoaddr'}) {
                   2361:                 my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
                   2362:                 if ($replytoname ne '' && $replytodom ne '') {
1.91      bisitz   2363:                     $r->print(&Apache::lonhtmlcommon::row_closure()
                   2364:                              .&Apache::lonhtmlcommon::row_title(&mt('Reply To'))
1.95      raeburn  2365:                              .$replytoname.':'.$replytodom
1.91      bisitz   2366:                              .&Apache::lonhtmlcommon::row_closure()
                   2367:                     );
                   2368:                 } else {
                   2369:                     $r->print(&Apache::lonhtmlcommon::row_closure());
1.78      raeburn  2370:                 }
                   2371:             } else {
1.95      raeburn  2372:                 $r->print(' ('.$content{'sendername'}.':'.$content{'senderdomain'}.') '
1.91      bisitz   2373:                          .&Apache::lonhtmlcommon::row_closure()
                   2374:                 );
1.78      raeburn  2375:             }
1.95      raeburn  2376:             if ($tonum && $tolist) {
                   2377:                 $r->print(&Apache::lonhtmlcommon::row_title(&mt('To'))
                   2378:                          .$tolist
                   2379:                          .&Apache::lonhtmlcommon::row_closure()
                   2380:                     );
                   2381:             }
                   2382:             if ($cclist) { 
1.91      bisitz   2383:                 $r->print(&Apache::lonhtmlcommon::row_title(&mt('Cc'))
                   2384:                          .$cclist
                   2385:                          .&Apache::lonhtmlcommon::row_closure()
                   2386:                     );
1.95      raeburn  2387:             }
                   2388:             if ($content{'group'} ne '') {
                   2389:                 if (&check_group_priv($content{'group'})) {
1.155     raeburn  2390:                     if (ref($recipients{'group_cc_broadcast'}) eq 'ARRAY') { 
                   2391:                         $groupcclist = join(', ',@{$recipients{'group_cc_broadcast'}});
                   2392:                         if ($groupcclist) {
                   2393:                             $r->print(&Apache::lonhtmlcommon::row_title(&mt('Group Cc'))
                   2394:                                      .$groupcclist
                   2395:                                      .&Apache::lonhtmlcommon::row_closure()
                   2396:                             );
                   2397:                         }
1.95      raeburn  2398:                     }
                   2399:                 }
1.78      raeburn  2400:             }
1.91      bisitz   2401:         }
1.73      raeburn  2402:     }
1.91      bisitz   2403: 
                   2404:     # Course
1.157     raeburn  2405:     if ($content{'courseid'} ne '') {
                   2406:         if ($content{'courseid'} =~ m{^$match_domain\_$match_courseid$}) {
                   2407:             my %courseinfo;
                   2408:             %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'},
                   2409:                                                            {'one_time' => 1});
                   2410:             my $description = $courseinfo{'description'};
                   2411:             if ($description ne '') {
                   2412:                 $r->print(&Apache::lonhtmlcommon::row_title(&mt($crstype))
                   2413:                          .$description
                   2414:                 );
                   2415:                 if ($content{'coursesec'}) {
                   2416:                     $r->print(' ('.&mt('Section').': '.$content{'coursesec'}.')');
                   2417:                 }
                   2418:                 $r->print(&Apache::lonhtmlcommon::row_closure());
                   2419:             }
1.73      raeburn  2420:         }
                   2421:     }
1.91      bisitz   2422:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Time'))
                   2423:              .$content{'time'}
                   2424:              .&Apache::lonhtmlcommon::row_closure()
                   2425:     );
                   2426: 
                   2427:     # Refers to
1.59      raeburn  2428:     if ($baseurl) {
                   2429:         if (defined($content{'courseid'}) && defined($env{'request.course.id'})) {
                   2430:             if ($content{'courseid'} eq $env{'request.course.id'}) {
                   2431:                 my $symblink;
1.62      raeburn  2432:                 my $showsymb = &Apache::lonenc::check_decrypt($symb);
                   2433:                 my $showurl = &Apache::lonenc::check_decrypt($baseurl);
                   2434:                 my $encrypturl = &Apache::lonnet::EXT('resource.0.encrypturl',
                   2435:                               $showsymb,$env{'user.domain'},$env{'user.name'});
1.59      raeburn  2436:                 if ($symb) {
1.62      raeburn  2437:                     if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
                   2438:                         $showsymb = &Apache::lonenc::check_encrypt($symb);
                   2439:                     }
                   2440:                     $symblink = '?symb='.$showsymb;
                   2441:                 }
                   2442:                 if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
                   2443:                     $showurl = $baseurl;
1.59      raeburn  2444:                 }
1.91      bisitz   2445:                 $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
                   2446:                          .'<a href="'.$showurl.$symblink.'">'.$restitle.'</a>'
                   2447:                          .&Apache::lonhtmlcommon::row_closure()
                   2448:                 );
1.59      raeburn  2449:                 $refers_to = 1;
                   2450:             }
                   2451:         }
                   2452:         if (!$refers_to) {
                   2453:             if ($baseurl =~ m-^/enc/-) {
                   2454:                 if (defined($content{'courseid'})) {
1.62      raeburn  2455:                     if (!$env{'request.course.id'}) {
                   2456:                         my $unencurl =
                   2457:                            &Apache::lonenc::unencrypted($baseurl,
                   2458:                                                         $content{'courseid'});
                   2459:                         if ($unencurl ne '') {
                   2460:                             if (&Apache::lonnet::allowed('bre',$unencurl)) {
1.91      bisitz   2461:                                 $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
                   2462:                                          .'<a href="'.$unencurl.'">'.$restitle.'</a>'
                   2463:                                          .&Apache::lonhtmlcommon::row_closure()
                   2464:                                 );
1.62      raeburn  2465:                             }
1.59      raeburn  2466:                         }
                   2467:                     }
                   2468:                 }
                   2469:             } else {
                   2470:                 if (&Apache::lonnet::allowed('bre',$baseurl)) {
1.91      bisitz   2471:                     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
                   2472:                              .'<a href="'.$baseurl.'">'.$restitle.'</a>'
                   2473:                              .&Apache::lonhtmlcommon::row_closure()
                   2474:                     );
                   2475: 
1.59      raeburn  2476:                 }
                   2477:             }
                   2478:         }
                   2479:     }
1.91      bisitz   2480: 
                   2481:     # Message
                   2482:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Message'))
                   2483:              .'<pre>'
                   2484: 	     .&Apache::lontexconvert::msgtexconverted($content{'message'},1)
                   2485: 	     .'</pre>'
                   2486:     );
                   2487:     if (&displayresource(%content)) {
                   2488:         $r->print(&Apache::lonhtmlcommon::row_closure()
                   2489:                  .&Apache::lonhtmlcommon::row_title(&mt('Resource Details'))
                   2490:                  .&displayresource(%content)
                   2491:         );
                   2492:     } 
1.92      raeburn  2493:     $r->print(&Apache::lonhtmlcommon::row_closure(1).
                   2494:               &Apache::lonhtmlcommon::end_pick_box());
1.91      bisitz   2495:     # Display LON-CAPA Message (End)
1.59      raeburn  2496:     return;
1.1       albertel 2497: }
                   2498: 
1.95      raeburn  2499: sub retrieve_recips {
                   2500:     my ($context,$content,$recips)= @_;
                   2501:     my $tonum = 0;
                   2502:     if (ref($content) eq 'HASH') {
                   2503:         my %reciphash =
                   2504:             &Apache::lonnet::get('nohist_emailrecip',[$content->{'recipid'}],
                   2505:                                  $content->{'senderdomain'},$content->{'sendername'});
                   2506:         my $recipinfo = $reciphash{$content->{'recipid'}};
                   2507:         if (ref($recipinfo) eq 'HASH') {
                   2508:             foreach my $type ('to','cc','course_broadcast','group_cc_broadcast','group_bcc_broadcast') {
                   2509:                 if (ref($recipinfo->{$type}) eq 'HASH') {
                   2510:                     if ($type eq 'to') {
                   2511:                         $tonum = keys(%{$recipinfo->{$type}});
                   2512:                     }
                   2513:                     foreach my $user (sort(keys(%{$recipinfo->{$type}}))) {
                   2514:                         my ($uname,$udom) = split(/:/,$user);
                   2515:                         next if (($context eq 'replying') && ($uname eq $env{'user.name'})
                   2516:                                  && ($udom eq $env{'user.domain'}));
                   2517:                         my $showuser ='<span class="LC_nobreak">';
                   2518:                         if ($context eq 'replying') {
                   2519:                             if (($type eq 'to') || ($type eq 'cc')) { 
                   2520:                                 $showuser = '<label><input type="checkbox" name="replying_'.$type.'" value="'.$user.'" />';
                   2521:                             } elsif ($type eq 'group_cc_broadcast') {
                   2522:                                 $showuser = '<label><input type="checkbox" name="replying_groupcc" value="'.$user.'" />';
                   2523:                             }
                   2524:                         }
                   2525:                         $showuser .= &Apache::loncommon::aboutmewrapper(
                   2526:                                            &Apache::loncommon::plainname($uname,
                   2527:                                            $udom),$uname,$udom);
                   2528: 		        if ($context eq 'replying') {
                   2529: 		            $showuser .='</label>';
                   2530: 		        }
                   2531: 		        $showuser .= '</span>';
                   2532:                         if (ref($recips) eq 'HASH') {
                   2533: 		            push(@{$recips->{$type}},$showuser);
                   2534:                         }
                   2535:                     }
1.73      raeburn  2536:                 }
                   2537:             }
                   2538:         }
                   2539:     }
1.95      raeburn  2540:     return $tonum;
                   2541: }
                   2542: 
                   2543: sub recipients_link {
                   2544:     my ($r,$content,$recipients) = @_;
                   2545:     my ($broadcast_link,$show);
                   2546:     if ((ref($content) eq 'HASH') && (ref($recipients) eq 'HASH')) {
                   2547:         if (ref($recipients->{'course_broadcast'}) eq 'ARRAY') {
                   2548:             if (@{$recipients->{'course_broadcast'}} > 0) {
                   2549:                 $show = 'course';
                   2550:             }
                   2551:         } elsif (ref($recipients->{'group_cc_broadcast'}) eq 'ARRAY') {
                   2552:             if (@{$recipients->{'group_cc_broadcast'}} > 0) {
                   2553:                 $show = 'group_cc';
                   2554:             }
                   2555:         } elsif (ref($recipients->{'group_bcc_broadcast'}) eq 'ARRAY') {
                   2556:             if (@{$recipients->{'group_bcc_broadcast'}} > 0) {
                   2557:                 $show = 'group_bcc';
                   2558:             }
                   2559:         }
                   2560:         if ($show) {
                   2561:             my ($nothing,$height,$width,$start_page,$end_page,$body);
                   2562:             $nothing=&Apache::lonhtmlcommon::javascript_nothing();
                   2563:             $height = 400;
                   2564:             $width = 600;
1.108     raeburn  2565:             $start_page =
                   2566:                 &Apache::loncommon::start_page('Broadcast List', undef,
                   2567:                                                {only_body => 1,
                   2568:                                                 js_ready  => 1,});
                   2569:             $end_page = &Apache::loncommon::end_page({js_ready => 1,});
                   2570:             $body = '<h3>'.&mt("Recipients of broadcast message").'</h3>'.
                   2571:                     &Apache::loncommon::start_data_table();
1.95      raeburn  2572:             my $cell = 0;
                   2573:             $body .= &Apache::loncommon::start_data_table_row();
                   2574:             foreach my $item (@{$recipients->{$show.'_broadcast'}}) {
                   2575:                 $item =~ s/'/\\'/g;
                   2576:                 if (!($cell%2) && $cell > 0) {
                   2577:                     $body .= &Apache::loncommon::end_data_table_row().
                   2578:                              &Apache::loncommon::start_data_table_row();
                   2579:                 }
                   2580:                 $cell ++;
                   2581:                 $body .= '<td>'.$cell.'&nbsp;'.$item.'&nbsp;&nbsp;</td>';
                   2582:             }
                   2583:             if ($cell%2) {
                   2584:                 $body .= '<td>&nbsp;</td>';
                   2585:             }
                   2586:             $body .= &Apache::loncommon::end_data_table_row().
                   2587:                      &Apache::loncommon::end_data_table();
                   2588:             $body =~ s{</}{<\\/}g;
                   2589:             $body =~ s{\n}{}g;
                   2590:             $r->print(<<ENDJS);
                   2591: <script type="text/javascript">
1.127     bisitz   2592: // <![CDATA[
1.95      raeburn  2593: function showBroadcastList() {
                   2594:     var caller = this;
                   2595:     var newWindow = null;
                   2596:     try {
                   2597:         newWindow =  window.open($nothing,"broadcast","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" );
                   2598:     }
                   2599:     catch(error) {
                   2600:         writeWin(caller);
                   2601:         return;
                   2602:     }
                   2603:     if (newWindow) {
                   2604:         caller = newWindow;
                   2605:     }
                   2606:     writeWin(caller);
                   2607:     return;
                   2608: }
                   2609: 
                   2610: function writeWin(caller) {
                   2611:     caller.document.writeln('$start_page $body $end_page');
                   2612:     caller.document.close();
                   2613:     caller.focus();
                   2614: }
1.127     bisitz   2615: // ]]>
1.95      raeburn  2616: </script>
                   2617: 
                   2618: ENDJS
                   2619:             $broadcast_link = 1;
                   2620:         }
                   2621:     }
                   2622:     return $broadcast_link;
1.73      raeburn  2623: }
                   2624: 
1.1       albertel 2625: # =========================================================== Show the citation
                   2626: 
                   2627: sub displayresource {
                   2628:     my %content=@_;
                   2629: #
                   2630: # If the recipient is in the same course that the message was sent from and
                   2631: # has sufficient privileges, show "all details," else show citation
                   2632: #
                   2633:     if (($env{'request.course.id'} eq $content{'courseid'})
                   2634:      && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
1.59      raeburn  2635:         my $symb;
                   2636:         if (defined($content{'symb'})) {
                   2637:             $symb = $content{'symb'};
                   2638:         } else { 
                   2639: 	    $symb=&Apache::lonnet::symbread($content{'baseurl'});
                   2640:         }
1.1       albertel 2641: # Could not get a symb, give up
                   2642: 	unless ($symb) { return $content{'citation'}; }
                   2643: # Have a symb, can render
                   2644: 	return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
                   2645: 	    &Apache::loncommon::get_previous_attempt($symb,
                   2646: 						     $content{'sendername'},
                   2647: 						     $content{'senderdomain'},
                   2648: 						     $content{'courseid'}).
                   2649: 	    '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
                   2650: 	    &Apache::loncommon::get_student_view($symb,
                   2651: 						 $content{'sendername'},
                   2652: 						 $content{'senderdomain'},
                   2653: 						 $content{'courseid'}).
                   2654: 	    '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
                   2655: 	    &Apache::loncommon::get_student_answers($symb,
                   2656: 						    $content{'sendername'},
                   2657: 						    $content{'senderdomain'},
                   2658: 						    $content{'courseid'});
                   2659:     } elsif ($env{'user.adv'}) {
                   2660: 	return $content{'citation'};
                   2661:     }
                   2662:     return '';
                   2663: }
                   2664: 
                   2665: # ================================================================== The Header
                   2666: 
                   2667: sub header {
                   2668:     my ($r,$title,$baseurl)=@_;
                   2669:     my $extra = &Apache::loncommon::studentbrowser_javascript();
                   2670:     if ($baseurl) {
1.41      albertel 2671: 	$extra .= "<base href=\"".&Apache::lonnet::absolute_url()."/$baseurl\" />";
1.1       albertel 2672:     }
1.182   ! musolffc 2673:     $extra .= '<script type="text/javascript"
        !          2674:                 src="/res/adm/includes/file_upload.js"></script>';
1.138     raeburn  2675:     $r->print(&Apache::loncommon::start_page('Messages',
1.38      raeburn  2676:  					$extra));
1.1       albertel 2677:     $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.138     raeburn  2678:      		(($title?$title:'Send and display messages')));
1.1       albertel 2679: }
                   2680: 
                   2681: # ---------------------------------------------------------------- Print header
                   2682: 
                   2683: sub printheader {
                   2684:     my ($r,$url,$desc,$title,$baseurl)=@_;
                   2685:     &Apache::lonhtmlcommon::add_breadcrumb
                   2686: 	({href=>$url,
                   2687: 	  text=>$desc});
                   2688:     &header($r,$title,$baseurl);
                   2689: }
                   2690: 
                   2691: # ------------------------------------------------------------ Store the comment
                   2692: 
                   2693: sub storecomment {
                   2694:     my ($r)=@_;
                   2695:     my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
                   2696:     my $cleanmsgtxt='';
1.42      raeburn  2697:     foreach my $line (split(/[\n\r]/,$msgtxt)) {
                   2698: 	unless ($line=~/^\s*(\>|\&gt\;)/) {
                   2699: 	    $cleanmsgtxt.=$line."\n";
1.1       albertel 2700: 	}
                   2701:     }
1.29      www      2702:     my $key=&escape($env{'form.baseurl'}).'___'.time;
1.1       albertel 2703:     &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
                   2704: }
                   2705: 
                   2706: sub storedcommentlisting {
                   2707:     my ($r)=@_;
                   2708:     my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
1.29      www      2709:        '^'.&escape(&escape($env{'form.showcommentbaseurl'})));
1.72      albertel 2710:     $r->print(&Apache::loncommon::start_page('Saved Comment Listing',undef,
1.1       albertel 2711: 					     {'onlybody' => 1}));
1.178     raeburn  2712:     if ((keys(%msgs))[0]=~/^error\:/) {
1.72      albertel 2713: 	$r->print(&mt('No saved comments yet.'));
1.1       albertel 2714:     } else {
                   2715: 	my $found=0;
1.42      raeburn  2716: 	foreach my $key (sort(keys(%msgs))) {
                   2717: 	    $r->print("\n".$msgs{$key}."<hr />");
1.1       albertel 2718: 	    $found=1;
                   2719: 	}
                   2720: 	unless ($found) {
1.72      albertel 2721: 	    $r->print(&mt('No saved comments yet for this resource.'));
1.1       albertel 2722: 	}
                   2723:     }
                   2724: }
                   2725: 
                   2726: # ---------------------------------------------------------------- Send an email
                   2727: 
                   2728: sub sendoffmail {
                   2729:     my ($r,$folder)=@_;
                   2730:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
                   2731:     my $sendstatus='';
1.71      raeburn  2732:     my %msg_status;
                   2733:     my $numsent = 0;
                   2734:     my $nosentstore = 1;
1.86      raeburn  2735:     my $attachmenturl;
                   2736:     my $now = time;
1.38      raeburn  2737:     my ($cdom,$cnum,$group);
                   2738:     if (exists($env{'form.group'})) {
                   2739:         $group = $env{'form.group'};
                   2740:     }
                   2741:     if (exists($env{'request.course.id'})) {
                   2742:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   2743:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   2744:     }
1.1       albertel 2745:     if ($env{'form.send'}) {
1.53      raeburn  2746:         if (!$env{'form.multiforward'}) { 
                   2747:             if ($group eq '') {
                   2748: 	        &printheader($r,'','Messages being sent.');
                   2749:             } else {
                   2750:                 $r->print(&groupmail_header('sending',$group));
                   2751:             }
1.38      raeburn  2752:         }
1.1       albertel 2753: 	$r->rflush();
                   2754: 	my %content=();
                   2755: 	undef %content;
                   2756: 	if ($env{'form.forwid'}) {
                   2757: 	    my $msgid=$env{'form.forwid'};
                   2758: 	    my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1.86      raeburn  2759: 	    %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1,1);
1.1       albertel 2760: 	    &statuschange($msgid,'forwarded',$folder);
1.86      raeburn  2761:             if ($content{'attachmenturl'} ne '') {
                   2762:                 $attachmenturl = $content{'attachmenturl'};
                   2763:             }
                   2764: 	    $env{'form.message'} .= "\n\n-- Forwarded message --\n\n".
                   2765: 		                    $content{'message'};
1.1       albertel 2766: 	}
                   2767: 	if ($env{'form.replyid'}) {
                   2768: 	    my $msgid=$env{'form.replyid'};
                   2769: 	    my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
                   2770: 	    %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
                   2771: 	    &statuschange($msgid,'replied',$folder);
                   2772: 	}
1.13      albertel 2773: 
1.25      foxr     2774: 	my $mode = $env{'form.sendmode'};
1.95      raeburn  2775: 	my (%toaddr,$tos,$cc,$bcc,$broadcast);
1.25      foxr     2776: 
1.95      raeburn  2777: 	if ($mode eq 'group') {
                   2778:             if (defined($env{'form.courserecips'})) {
                   2779:                 my $courseusers = $env{'form.courserecips'};
                   2780:                 $courseusers =~ s/^_\&\&\&_//;
                   2781:                 my @to = split('_&&&_',$courseusers);
                   2782:                 foreach my $dest (@to) {
                   2783:                     my ($user,$domain) = split(/:/, $dest);
                   2784:                     if (($user ne '') && ($domain ne '')) {
                   2785:                         my $rec = $user.":".$domain;
                   2786:                         $toaddr{$rec} = '';
                   2787:                         $broadcast->{$rec} = '';
                   2788:                     }
                   2789:                 }
                   2790:             }
                   2791: 	} elsif ($mode eq 'upload') {
1.71      raeburn  2792:             $nosentstore = 0;
1.13      albertel 2793: 	    foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
1.43      raeburn  2794:                 my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/);
1.1       albertel 2795: 		if ($txt) {
1.43      raeburn  2796:                     $rec =~ s/^\s+//;
1.44      raeburn  2797:                     $rec =~ s/\s+$//;
1.1       albertel 2798: 		    $toaddr{$rec}.=$txt."\n";
1.95      raeburn  2799:                     $broadcast->{$rec} = '';
1.1       albertel 2800: 		}
                   2801: 	    }
                   2802: 	} else {
1.25      foxr     2803: 	    if (($env{'form.recuname'} ne '') && ($env{'form.recdomain'} ne '')) {
                   2804: 		$toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
1.95      raeburn  2805:                 $tos->{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
1.25      foxr     2806: 	    }
1.1       albertel 2807: 	}
1.95      raeburn  2808:         if ($env{'form.additionalrec_to'}) {
                   2809:             foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_to'})) {
                   2810:                 my ($auname,$audom)=split(/:/,$rec);
                   2811:                 if (($auname ne "") && ($audom ne "")) {
                   2812:                     $toaddr{$auname.':'.$audom}='';
                   2813:                     $tos->{$auname.':'.$audom}='';
                   2814:                 }
                   2815:             }
                   2816:         }
                   2817:         if ($env{'form.replying_to'}) {
                   2818:             my @toreplies =
                   2819:                 &Apache::loncommon::get_env_multiple('form.replying_to');
                   2820:             foreach my $rec (@toreplies) {
                   2821:                 my ($auname,$audom)=split(/:/,$rec);
                   2822:                 if (($auname ne "") && ($audom ne "")) {
                   2823:                     $toaddr{$auname.':'.$audom}='';
                   2824:                     $tos->{$auname.':'.$audom}='';
                   2825:                 }
                   2826:             }
                   2827:         }
1.73      raeburn  2828: 	if ($env{'form.additionalrec_cc'}) {
                   2829: 	    foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_cc'})) {
1.43      raeburn  2830: 		my ($auname,$audom)=split(/:/,$rec);
1.25      foxr     2831: 		if (($auname ne "") && ($audom ne "")) {
1.73      raeburn  2832:                     $toaddr{$auname.':'.$audom}='';
1.95      raeburn  2833:                     if (!defined($tos->{$auname.':'.$audom})) {
                   2834: 		        $cc->{$auname.':'.$audom}='';
                   2835:                     }
1.25      foxr     2836: 		}
1.1       albertel 2837: 	    }
                   2838: 	}
1.95      raeburn  2839:         if ($env{'form.replying_cc'}) {
                   2840:             my @ccreplies =
                   2841:                 &Apache::loncommon::get_env_multiple('form.replying_cc');
                   2842:             foreach my $rec (@ccreplies) {
                   2843:                 my ($auname,$audom)=split(/:/,$rec);
                   2844:                 if (($auname ne "") && ($audom ne "")) {
                   2845:                     $toaddr{$auname.':'.$audom}='';
                   2846:                     if (!defined($tos->{$auname.':'.$audom})) {
                   2847:                         $cc->{$auname.':'.$audom}='';
                   2848:                     }
                   2849:                 }
                   2850:             }
                   2851:         }
                   2852:         if ($env{'form.replying_groupcc'}) {
                   2853:             my @groupreplies =
                   2854:                 &Apache::loncommon::get_env_multiple('form.replying_groupcc');
                   2855:             foreach my $rec (@groupreplies) {
1.73      raeburn  2856:                 my ($auname,$audom)=split(/:/,$rec);
                   2857:                 if (($auname ne "") && ($audom ne "")) {
                   2858:                     $toaddr{$auname.':'.$audom}='';
1.95      raeburn  2859:                     if (!defined($tos->{$auname.':'.$audom})) {
                   2860:                         $broadcast->{$auname.':'.$audom}='';
                   2861:                     }
1.73      raeburn  2862:                 }
                   2863:             }
                   2864:         }
1.95      raeburn  2865:         if ($env{'form.additionalrec_bcc'}) {
                   2866:             foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_bcc'})) {
1.73      raeburn  2867:                 my ($auname,$audom)=split(/:/,$rec);
                   2868:                 if (($auname ne "") && ($audom ne "")) {
                   2869:                     $toaddr{$auname.':'.$audom}='';
1.95      raeburn  2870:                     if ((!defined($tos->{$auname.':'.$audom})) && 
                   2871:                         (!defined($cc->{$auname.':'.$audom}))) {
                   2872:                         $bcc->{$auname.':'.$audom}='';
                   2873:                     }
1.73      raeburn  2874:                 }
                   2875:             }
                   2876:         }
1.1       albertel 2877:         my $savemsg;
                   2878:         my $msgtype;
                   2879:         my %sentmessage;
1.7       albertel 2880:         my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'},
                   2881: 							 undef,1);
1.1       albertel 2882:         if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
                   2883:             (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                   2884: 	     || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                   2885: 					 '/'.$env{'request.course.sec'})
                   2886: 	     )) {
                   2887:             $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
                   2888:             $msgtype = 'critical';
                   2889:         } else {
                   2890:             $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
                   2891:         }
1.73      raeburn  2892:         my %reciphash = (
1.95      raeburn  2893:                            to => $tos,
1.73      raeburn  2894:                            cc => $cc,
                   2895:                            bcc => $bcc,
1.95      raeburn  2896:                         );
                   2897:         if ($mode eq 'group') {
                   2898:             if ($group eq '') {
                   2899:                 $reciphash{'course_broadcast'} = $broadcast;
                   2900:             } else {
                   2901:                 if ($env{'form.groupmail'} eq 'cc') {
                   2902:                     $reciphash{'group_cc_broadcast'} = $broadcast;
                   2903:                 } else {
                   2904:                     $reciphash{'group_bcc_broadcast'} = $broadcast;
                   2905:                 }
                   2906:             }
                   2907:         }
1.73      raeburn  2908:         my ($recipid,$recipstatus) = 
                   2909:             &Apache::lonmsg::store_recipients($msgsubj,$env{'user.name'},
                   2910:                                        $env{'user.domain'},\%reciphash);
                   2911:         if ($recipstatus ne 'ok') {
1.95      raeburn  2912:             &Apache::lonnet::logthis('Failed to store To, Bcc and Cc recipients for '.$env{'user.name'}.':'.$env{'user.domain'});
1.86      raeburn  2913:         }
                   2914:         if ($env{'form.attachment'}) {
                   2915:             if (length($env{'form.attachment'})<131072) {
                   2916:                 $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback/'.$now);
                   2917:             } else {
                   2918:                 $r->print('<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>');
                   2919:             }
                   2920:         } elsif ($env{'form.multiforward'}) {
                   2921:             if ($env{'form.attachmenturl'} ne '') {
                   2922:                 $attachmenturl = $env{'form.attachmenturl'};
                   2923:             }
                   2924:         }
1.71      raeburn  2925:         my @recusers;
                   2926:         my @recudoms;
1.180     raeburn  2927:         my %permresults;
1.13      albertel 2928: 	foreach my $address (sort(keys(%toaddr))) {
                   2929: 	    my ($recuname,$recdomain)=split(/\:/,$address);
1.1       albertel 2930:             my $msgtxt = $savemsg;
1.73      raeburn  2931:             if ($toaddr{$address}) {
1.151     raeburn  2932: 	        $msgtxt.="\n".'<hr />'."\n".$toaddr{$address};
1.73      raeburn  2933:             }
1.12      albertel 2934: 	    my @thismsg;
1.60      raeburn  2935: 	    if ($msgtype eq 'critical') {
                   2936: 		$r->print(&mt('Sending critical message').' '.
                   2937:                               $recuname.':'.$recdomain.': ');
1.13      albertel 2938: 		@thismsg=
                   2939: 		    &Apache::lonmsg::user_crit_msg($recuname,$recdomain,
                   2940: 						   $msgsubj,$msgtxt,
                   2941: 						   $env{'form.sendbck'},
                   2942: 						   $env{'form.permanent'},
1.71      raeburn  2943: 						   \$sentmessage{$address},
1.179     raeburn  2944:                                                    $nosentstore,$recipid,
1.180     raeburn  2945:                                                    $attachmenturl,\%permresults);
1.1       albertel 2946: 	    } else {
1.14      albertel 2947: 		$r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': ');
1.13      albertel 2948: 		@thismsg=
                   2949: 		    &Apache::lonmsg::user_normal_msg($recuname,$recdomain,
                   2950: 						     $msgsubj,$msgtxt,
                   2951: 						     $content{'citation'},
1.86      raeburn  2952: 						     undef,$attachmenturl,
1.13      albertel 2953: 						     $env{'form.permanent'},
1.71      raeburn  2954: 						     \$sentmessage{$address},
                   2955:                                                      undef,undef,undef,
1.180     raeburn  2956:                                                      $nosentstore,$recipid,
                   2957:                                                      \%permresults);
1.71      raeburn  2958:             }
                   2959: 	    $msg_status{$recuname.':'.$recdomain}=join(' ',@thismsg);
                   2960: 	    if ($msg_status{$recuname.':'.$recdomain} =~ /(ok|con_delayed)/) {  
                   2961: 	        $numsent++;
                   2962:                 push(@recusers,$recuname);
                   2963:                 push(@recudoms,$recdomain);
1.180     raeburn  2964:                 if ($1 eq 'ok') {
                   2965:                     $r->print('ok ');
                   2966:                 }
                   2967:                 if ($permresults{$recuname.':'.$recdomain}) {
                   2968:                     $r->print(' (email) ');
                   2969:                 }
1.1       albertel 2970: 	    }
1.12      albertel 2971: 	    $sendstatus.=' '.join(' ',@thismsg);
1.1       albertel 2972: 	}
1.71      raeburn  2973:         my $subj_prefix;
                   2974:         if ($numsent > 0) {
                   2975:             if (($env{'request.course.id'}) && 
1.95      raeburn  2976:                 (($mode eq 'group') ||
1.71      raeburn  2977:                  ($env{'form.courserecord'}) ||
1.95      raeburn  2978:                  ($msgtype eq 'critical')) ||
                   2979:                 ($env{'form.replyid'} && 
                   2980:                  (($content{'courseid'} ne '') && 
                   2981:                   ($mode eq 'group')))) {
1.71      raeburn  2982:                 if ($msgtype eq 'critical') {
                   2983:                     $subj_prefix = 'Critical.';
1.95      raeburn  2984:                 } elsif ($mode eq 'group') {
1.71      raeburn  2985:                     $subj_prefix = 'Broadcast.';
                   2986:                 } else {
                   2987:                     $subj_prefix = 'Archive';
                   2988:                 }
                   2989:                 my ($specialmsgid,$specialresult);
1.95      raeburn  2990:                 my $course_str;
                   2991:                 if ($env{'form.replyid'}) {
                   2992:                     if ($content{'courseid'} ne '') {
                   2993:                         my %crsdesc = 
                   2994:                             &Apache::lonnet::coursedescription($content{'courseid'},
                   2995:                                                                {'one_time' => 1});
                   2996:                         $course_str = &escape('['.$crsdesc{'num'}.':'.$crsdesc{'domain'}.']');
                   2997:                     }
                   2998:                 } elsif ($env{'request.course.id'}) {
                   2999:                     $course_str = &escape('['.$cnum.':'.$cdom.']');
                   3000:                 }
1.71      raeburn  3001:                 $specialresult = 
                   3002:                     &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
                   3003:                         $subj_prefix.' '.$course_str,$savemsg,undef,undef,
1.86      raeburn  3004:                         $attachmenturl,undef,undef,\$specialmsgid,undef,undef,undef,
1.71      raeburn  3005:                         undef,undef,1);
1.29      www      3006:                 $specialmsgid = &unescape($specialmsgid);
1.71      raeburn  3007:                 if ($specialresult eq 'ok') {
                   3008:                     my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
                   3009: 		        split(/\:/,&unescape($specialmsgid));
                   3010: 
                   3011:                     foreach my $recipient (sort(keys(%toaddr))) {
                   3012:                         if ($msg_status{$recipient} =~ /\s*(ok|con_delayed)\s*/) {
                   3013:                             my $usersubj = $subj_prefix.'['.$recipient.']';
                   3014:                             my $usermsgid = 
                   3015: 			        &Apache::lonmsg::buildmsgid($stamp,$usersubj,
                   3016: 							    $msgname,$msgdom,
                   3017: 							    $msgcount,$context,
                   3018: 							    $pid);
                   3019:                             &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
                   3020:                                 $subj_prefix.' ['.$recipient.']',$msgsubj,
1.86      raeburn  3021:                                 undef,undef,$attachmenturl,undef,$usermsgid,undef,
1.71      raeburn  3022:                                 undef,$specialmsgid,undef,undef,undef,1);
                   3023:                         }
                   3024:                     }
1.95      raeburn  3025:                     if (($mode ne 'upload') && (@recusers > 0)) {
1.71      raeburn  3026:                         &Apache::lonmsg::process_sent_mail($msgsubj,
                   3027:                            $subj_prefix,$numsent,$stamp,$msgname,$msgdom,
                   3028:                            $msgcount,$context,$pid,$savemsg,\@recusers,
1.95      raeburn  3029:                            \@recudoms,undef,$attachmenturl,'','','','',$recipid);
1.1       albertel 3030:                     }
1.71      raeburn  3031:                 } else {
1.78      raeburn  3032:                     &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 3033:                 }
                   3034:             } else {
1.71      raeburn  3035:                 my $stamp = time;
                   3036:                 my $msgcount = &Apache::lonmsg::get_uniq();
                   3037:                 my $context = &Apache::lonmsg::get_course_context();
                   3038:                 &Apache::lonmsg::process_sent_mail($msgsubj,$subj_prefix,
                   3039:                        $numsent,$stamp,$env{'user.name'},
                   3040:                        $env{'user.domain'},$msgcount,$context,
1.95      raeburn  3041:                        $$,$savemsg,\@recusers,\@recudoms,undef,$attachmenturl,
                   3042:                        '','','','',$recipid);
1.1       albertel 3043:             }
                   3044:         }
1.143     wenzelju 3045:         if (!$env{'form.multiforward'}) {
1.71      raeburn  3046:             if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
1.143     wenzelju 3047:                 my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Completed.'));
                   3048:                 $message = &Apache::loncommon::confirmwrapper($message);
                   3049:                 $r->print($message);
1.71      raeburn  3050: 	        if ($env{'form.displayedcrit'}) {
                   3051: 	            &discrit($r);
                   3052:                 }
                   3053:                 if ($group ne '') {
                   3054:                     $r->print(&groupmail_sent($group,$cdom,$cnum)); 
                   3055: 	        } else {
                   3056: 	            &Apache::loncommunicate::menu($r);
                   3057: 	        }
                   3058:             } else {
1.143     wenzelju 3059:                 my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Could not deliver message'),1);
1.145     raeburn  3060:                 $message .= '<br />'.&mt('Please use the browser "Back" button and correct the recipient addresses ([_1]).',$sendstatus);
1.143     wenzelju 3061:                 $message = &Apache::loncommon::confirmwrapper($message);
                   3062:                 $r->print($message);
1.53      raeburn  3063:             }
1.38      raeburn  3064:         }
1.152     www      3065:     } else {
                   3066:         &printheader($r,'','Messages cancelled.');
                   3067:         return 'cancelled';
1.1       albertel 3068:     }
1.53      raeburn  3069:     return $sendstatus;
1.1       albertel 3070: }
                   3071: 
                   3072: # ===================================================================== Handler
                   3073: 
                   3074: sub handler {
                   3075:     my $r=shift;
                   3076: 
                   3077: # ----------------------------------------------------------- Set document type
                   3078:     
                   3079:     &Apache::loncommon::content_type($r,'text/html');
                   3080:     $r->send_http_header;
                   3081:     
                   3082:     return OK if $r->header_only;
                   3083:     
                   3084: # --------------------------- Get query string for limited number of parameters
                   3085:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   3086:         ['display','replyto','forward','markread','markdel','markunread',
                   3087:          'sendreply','compose','sendmail','critical','recname','recdom',
1.159     raeburn  3088:          'recordftf','sortedby','folder','startdis','interdis',
1.53      raeburn  3089: 	 'showcommentbaseurl','dismode','group','subject','text','ref',
                   3090:          'msgstatus']);
1.127     bisitz   3091:     $sqs='&amp;sortedby='.$env{'form.sortedby'};
1.1       albertel 3092: 
                   3093: # ------------------------------------------------------ They checked for email
1.159     raeburn  3094:     &Apache::lonnet::put('email_status',{'recnewemail'=>0});
1.1       albertel 3095: 
                   3096: # ----------------------------------------------------------------- Breadcrumbs
                   3097: 
                   3098:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                   3099:     &Apache::lonhtmlcommon::add_breadcrumb
                   3100:         ({href=>"/adm/communicate",
1.138     raeburn  3101:           text=>"Messages",
1.1       albertel 3102:           faq=>12,bug=>'Communication Tools',});
                   3103: 
                   3104: # ------------------------------------------------------------------ Get Folder
                   3105: 
                   3106:     my $folder=$env{'form.folder'};
                   3107:     unless ($folder) { 
                   3108: 	$folder=''; 
                   3109:     } else {
1.127     bisitz   3110: 	$sqs.='&amp;folder='.&escape($folder);
1.1       albertel 3111:     }
                   3112: # ------------------------------------------------------------ Get Display Mode
                   3113: 
                   3114:     my $dismode=$env{'form.dismode'};
                   3115:     unless ($dismode) { 
                   3116: 	$dismode=''; 
                   3117:     } else {
1.48      albertel 3118: 	$sqs.='&amp;dismode='.&escape($dismode);
1.1       albertel 3119:     }
                   3120: 
                   3121: # --------------------------------------------------------------------- Display
1.53      raeburn  3122:     my $msgstatus = $env{'form.msgstatus'};
1.1       albertel 3123:     $startdis=$env{'form.startdis'};
1.53      raeburn  3124:     if ($startdis ne '') {
                   3125:         $startdis--;
                   3126:     }
1.1       albertel 3127:     unless ($startdis) { $startdis=0; }
                   3128: 
                   3129:     if ($env{'form.firstview'}) {
                   3130: 	$startdis=0;
                   3131:     }
                   3132:     if ($env{'form.lastview'}) {
                   3133: 	$startdis=-1;
                   3134:     }
                   3135:     if ($env{'form.prevview'}) {
                   3136: 	$startdis--;
                   3137:     }
                   3138:     if ($env{'form.nextview'}) {
                   3139: 	$startdis++;
                   3140:     }
                   3141:     my $postedstartdis=$startdis+1;
1.127     bisitz   3142:     $sqs.='&amp;startdis='.$postedstartdis;
1.1       albertel 3143: 
                   3144: # --------------------------------------------------------------- Render Output
                   3145: 
                   3146:     if ($env{'form.display'}) {
1.53      raeburn  3147: 	&displaymessage($r,$env{'form.display'},$folder,$msgstatus);
1.1       albertel 3148:     } elsif ($env{'form.replyto'}) {
                   3149: 	&compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode);
                   3150:     } elsif ($env{'form.confirm'}) {
                   3151: 	&printheader($r,'','Confirmed Receipt');
1.36      albertel 3152: 	my $replying = 0;
1.42      raeburn  3153: 	foreach my $envkey (keys(%env)) {
1.75      raeburn  3154: 	    if ($envkey=~/^form\.(rep)?rec\_(.*)$/) {
1.77      raeburn  3155:                 my $repchk = $1;
1.75      raeburn  3156:        		my $msgid = $2;
                   3157: 		$r->print('<b>'.&mt('Confirming Receipt').':</b> ');
                   3158: 		my $result = &Apache::lonmsg::user_crit_received($msgid);
                   3159:                 if ($result =~ /trans:\s+ok/) {
                   3160:                     &statuschange($msgid,'read');
                   3161:                 }
1.76      albertel 3162:                 $r->print($result.'<br />');
1.77      raeburn  3163:                 if ($repchk eq 'rep') {
1.75      raeburn  3164: 		    &compout($r,'','','',$msgid);
                   3165: 		    $replying = 1;
                   3166:                 }
1.1       albertel 3167: 	    }
                   3168: 	}
1.36      albertel 3169: 	if (!$replying) {
                   3170: 	    &discrit($r);
                   3171: 	}
1.1       albertel 3172:     } elsif ($env{'form.critical'}) {
                   3173: 	&printheader($r,'','Displaying Critical Messages');
                   3174: 	&discrit($r);
                   3175:     } elsif ($env{'form.forward'}) {
                   3176: 	&compout($r,$env{'form.forward'},undef,undef,undef,$folder);
                   3177:     } elsif ($env{'form.markdel'}) {
                   3178: 	&printheader($r,'','Deleted Message');
1.9       albertel 3179: 	my ($result,$msg) = 
                   3180: 	    &statuschange($env{'form.markdel'},'deleted',$folder);
                   3181: 	if (!$result) {
1.143     wenzelju 3182:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Failed to delete the message.'),1);
1.147     wenzelju 3183:             $message .= '<p class="LC_error" style="font-size: inherit;">'.$msg.'</p>';
1.143     wenzelju 3184:             $message = &Apache::loncommon::confirmwrapper($message);
                   3185:             $r->print($message);
1.9       albertel 3186: 	}
1.1       albertel 3187: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  3188: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
                   3189:     } elsif ($env{'form.markedaction'} eq 'markedforward') {
                   3190:         my $total = 0;
                   3191:         my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
                   3192:         foreach my $msgid (@to_forward) {
                   3193:             &statuschange(&unescape($msgid),'forwarded',$folder);
                   3194:             $total ++;
                   3195:         }
                   3196:         if ($total > 0) {
                   3197:             &compout($r,undef,undef,undef,undef,$folder,$dismode,$total);
                   3198:         }
                   3199:     } elsif ($env{'form.markedaction'} eq 'markedread') {
                   3200:         my $total = 0;
                   3201:         my @to_markread = &Apache::loncommon::get_env_multiple('form.delmark');
                   3202:         foreach my $msgid (@to_markread) {
                   3203:             &statuschange(&unescape($msgid),'read',$folder);
                   3204:             $total ++;
                   3205:         }
                   3206:         &printheader($r,'','Marked Messages Read');
1.143     wenzelju 3207:         my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Marked [quant,_1,message] read',$total));
                   3208:         $message = &Apache::loncommon::confirmwrapper($message);
                   3209:         $r->print($message);
                   3210:       # $r->print('<p>');
1.53      raeburn  3211:         &Apache::loncommunicate::menu($r);
                   3212:         &disall($r,($folder?$folder:$dismode),$msgstatus);
                   3213:     } elsif ($env{'form.markedaction'} eq 'markedunread') {
                   3214:         my $total = 0;
                   3215:         my @to_markunread = &Apache::loncommon::get_env_multiple('form.delmark');
                   3216:         foreach my $msgid (@to_markunread) {
                   3217:             &statuschange(&unescape($msgid),'new',$folder);
                   3218:             $total ++;
                   3219:         }
                   3220:         &printheader($r,'','Marked Messages Unread');
1.143     wenzelju 3221:         my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Marked [quant,_1,message] unread',$total));
                   3222:         $message = &Apache::loncommon::confirmwrapper($message);
                   3223:         $r->print($message);
                   3224:       # $r->print('<p>');
1.53      raeburn  3225:         &Apache::loncommunicate::menu($r);
                   3226:         &disall($r,($folder?$folder:$dismode),$msgstatus);
                   3227:     } elsif ($env{'form.markedaction'} eq 'markedmove') {
                   3228:         my $destfolder = $env{'form.movetofolder'};
                   3229:         my %gotfolders = &Apache::lonmsg::get_user_folders();
                   3230:         &printheader($r,'','Moved Messages');
                   3231:         if (!defined($gotfolders{$destfolder})) {
                   3232:             $r->print(&mt('Destination folder [_1] is not a valid folder',
1.148     bisitz   3233:                           '<span class="LC_filename">'.$destfolder.'</span>'));
1.53      raeburn  3234:         } else {
                   3235: 	    my ($total,$failed,@failed_msg)=(0,0);
                   3236:             my @to_move = &Apache::loncommon::get_env_multiple('form.delmark');
                   3237:             foreach my $msgid (@to_move) {
                   3238: 	        my ($result,$msg) = &movemsg(&unescape($msgid),$folder,
                   3239: 			                     $env{'form.movetofolder'});
                   3240: 	        if ($result) {
1.9       albertel 3241: 		    $total++;
1.53      raeburn  3242: 	        } else {
1.9       albertel 3243: 		    $failed++;
                   3244: 		    push(@failed_msg,$msg);
1.53      raeburn  3245: 	        }
1.1       albertel 3246: 	    }
1.143     wenzelju 3247:             my $message = '';
                   3248:             if ($failed) {
                   3249:                 $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Failed to move [quant,_1,message]',$failed),1);
1.147     wenzelju 3250:                 $message .= '<p class="LC_error" style="font-size: inherit;">'.
                   3251: 		            join("</p>\n<p class=\"LC_error\" style=\"font-size: inherit;\">",@failed_msg).
1.143     wenzelju 3252: 		            "</p>\n";
                   3253:             }
                   3254:             $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Moved [quant,_1,message]',$total));
                   3255:             $message = &Apache::loncommon::confirmwrapper($message);
                   3256:             $r->print($message);
                   3257:           # $r->print('<p>');
1.53      raeburn  3258:         }
1.1       albertel 3259: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  3260: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
                   3261:     } elsif ($env{'form.markedaction'} eq 'markeddel') {
1.9       albertel 3262: 	my ($total,$failed,@failed_msg)=(0,0);
1.53      raeburn  3263:         my @to_delete = &Apache::loncommon::get_env_multiple('form.delmark');
                   3264:         foreach my $msgid (@to_delete) {
                   3265: 	    my ($result,$msg) = &statuschange(&unescape($msgid),'deleted', 
                   3266: 				              $folder);
                   3267: 	    if ($result) {
                   3268: 	        $total++;
                   3269: 	    } else {
                   3270: 	        $failed++;
                   3271: 		push(@failed_msg,$msg);
1.1       albertel 3272: 	    }
                   3273: 	}
                   3274: 	&printheader($r,'','Deleted Messages');
1.143     wenzelju 3275:         my $message = '';
1.9       albertel 3276: 	if ($failed) {
1.143     wenzelju 3277:             $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Failed to delete [quant,_1,message]',$failed),1);
1.147     wenzelju 3278:             $message .= '<p class="LC_error" style="font-size: inherit;">'.
                   3279: 		      join("</p>\n<p class=\"LC_error\" style=\"font-size: inherit;\">",@failed_msg).
1.143     wenzelju 3280: 		      "</p>\n";
1.9       albertel 3281: 	}
1.143     wenzelju 3282:         $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Deleted [quant,_1,message]',$total));
                   3283:         $message = &Apache::loncommon::confirmwrapper($message);
                   3284:         $r->print($message);
                   3285:       # $r->print('<p>');
1.1       albertel 3286: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  3287: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
1.1       albertel 3288:     } elsif ($env{'form.markunread'}) {
                   3289: 	&printheader($r,'','Marked Message as Unread');
                   3290: 	&statuschange($env{'form.markunread'},'new');
                   3291: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  3292: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
1.1       albertel 3293:     } elsif ($env{'form.compose'}) {
                   3294: 	&compout($r,'','',$env{'form.compose'});
                   3295:     } elsif ($env{'form.recordftf'}) {
                   3296: 	&facetoface($r,$env{'form.recordftf'});
                   3297:     } elsif ($env{'form.sendmail'}) {
1.53      raeburn  3298:         if ($env{'form.multiforward'}) {
                   3299:             &printheader($r,'','Messages being sent.');
                   3300:             my $fixed_subj = $env{'form.subject'};
                   3301:             my $suffix=&Apache::lonmsg::foldersuffix($folder);
                   3302:             my (%sendresult,%forwardok,%forwardfail,$fwdcount);
                   3303:             my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
                   3304:             foreach my $item (@to_forward) {
                   3305:                 my $msgid=&unescape($item);
                   3306:                 my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1.86      raeburn  3307:                 my %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1,1);
1.53      raeburn  3308:                 if ($env{'form.showorigsubj'}) {
                   3309:                     $env{'form.subject'} = $fixed_subj.$content{'subject'};
                   3310:                 } else {
                   3311:                     $env{'form.subject'} = '';
                   3312:                 }
                   3313:                 my $uname = $content{'sendername'};
                   3314:                 my $udom = $content{'senderdomain'};
                   3315:                 &statuschange($msgid,'forwarded',$folder);
                   3316:                 if ($env{'form.showorigsender'}) {
                   3317:                     $env{'form.message'} = $env{'form.msgheader'}.' '.
                   3318:                         &Apache::loncommon::plainname($uname,$udom).' ('.
                   3319:                                            $uname.':'.$udom.')';
                   3320:                 }
1.86      raeburn  3321:                 $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
                   3322:                                       $content{'message'};
                   3323:                 $env{'form.attachmenturl'} = $content{'attachmenturl'};
                   3324:                 $env{'form.multiforwid'} = $item;
1.53      raeburn  3325:                 $fwdcount ++;
                   3326:                 $r->print($fwdcount.': '); 
                   3327:                 $sendresult{$msgid} = &sendoffmail($r,$folder);
                   3328:                 $r->print('<br />');
                   3329:             }
                   3330:             foreach my $key (keys(%sendresult)) {
                   3331:                 if ($sendresult{$key} =~/^(\s*(?:ok|con_delayed)\s*)*$/) {
                   3332:                     $forwardok{$key} = $sendresult{$key};
                   3333:                 } else {
                   3334:                     $forwardfail{$key} = $sendresult{$key}; 
                   3335:                 }
                   3336:             }
                   3337:             if (keys(%forwardok) > 0) {
                   3338:                 my $count = keys(%forwardok);
1.143     wenzelju 3339:                 my $message = &Apache::lonhtmlcommon::confirm_success(&mt('[quant,_1,message] forwarded.',$count));
                   3340:                 $message = &Apache::loncommon::confirmwrapper($message);
                   3341:                 $r->print($message);
1.53      raeburn  3342:             }
                   3343:             if (keys(%forwardfail) > 0) {
                   3344:                 my $count = keys(%forwardfail);
1.143     wenzelju 3345:                 my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Could not forward [quant,_1,message].',$count),1);
1.53      raeburn  3346:                 foreach my $key (keys(%forwardfail)) {
1.145     raeburn  3347:                     $message .= '<br />'.&mt('Could not deliver forwarded message.').'</span> '.
1.143     wenzelju 3348:                                 &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.')';
1.53      raeburn  3349:                 }
1.143     wenzelju 3350:                 $message = &Apache::loncommon::confirmwrapper($message);
                   3351:                 $r->print($message);
1.53      raeburn  3352:             }
                   3353:             &Apache::loncommunicate::menu($r);
                   3354:         } else {
                   3355: 	    &sendoffmail($r,$folder);
                   3356:         }
1.1       albertel 3357: 	if ($env{'form.storebasecomment'}) {
                   3358: 	    &storecomment($r);
1.38      raeburn  3359:         }
1.1       albertel 3360: 	if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
1.38      raeburn  3361: 	        &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
1.1       albertel 3362: 				      $env{'course.'.$env{'request.course.id'}.'.domain'},
                   3363: 				      'Course_Announcements',
                   3364: 				      $env{'form.subject'},
                   3365: 				      $env{'form.message'},'/adm/communicate','public');
                   3366: 	}
1.38      raeburn  3367: 	if ((!exists($env{'form.group'})) && (!$env{'form.displayedcrit'})) {
1.53      raeburn  3368: 	    &disall($r,($folder?$folder:$dismode),$msgstatus);
1.36      albertel 3369: 	}
1.1       albertel 3370:     } elsif ($env{'form.newfolder'}) {
                   3371: 	&printheader($r,'','New Folder');
1.46      raeburn  3372:         my $showfolder = $env{'form.newfolder'};
                   3373: 	my ($makeresult,$warning) = &makefolder($env{'form.newfolder'});
                   3374:         if ($makeresult eq 'ok') {
1.143     wenzelju 3375:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" created.',$showfolder));
                   3376:             $message = &Apache::loncommon::confirmwrapper($message);
                   3377:             $r->print($message);
1.46      raeburn  3378:         } else {
1.143     wenzelju 3379:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Creation failed.').' '.$makeresult.'<br />'.$warning,1);
                   3380:             $message = &Apache::loncommon::confirmwrapper($message);
                   3381:             $r->print($message);
1.46      raeburn  3382:             $showfolder = $folder;
                   3383:         }
                   3384:         &Apache::loncommunicate::menu($r);
1.53      raeburn  3385: 	&disall($r,$showfolder,$msgstatus);
1.1       albertel 3386:     } elsif ($env{'form.showcommentbaseurl'}) {
                   3387: 	&storedcommentlisting($r);
1.46      raeburn  3388:     } elsif ($env{'form.folderaction'} eq 'delete') {
                   3389:         &printheader($r,'','Deleted Folder');
                   3390:         my $showfolder = '';
                   3391:         my $delresult = &deletefolder($folder);
                   3392:         if ($delresult eq 'ok') {
1.143     wenzelju 3393:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" deleted.',$folder));
                   3394:             $message = &Apache::loncommon::confirmwrapper($message);
                   3395:             $r->print($message);
1.65      raeburn  3396:             $env{'form.folder'} = '';
1.46      raeburn  3397:         } else {
1.143     wenzelju 3398:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Deletion failed.').' '.$delresult,1);
                   3399:             $message = &Apache::loncommon::confirmwrapper($message);
                   3400:             $r->print($message);
1.46      raeburn  3401:             $showfolder = $folder;
                   3402:         }
                   3403:         &Apache::loncommunicate::menu($r);
1.53      raeburn  3404:         &disall($r,$showfolder,$msgstatus);
1.46      raeburn  3405:     } elsif ($env{'form.folderaction'} eq 'rename') {
                   3406:         &printheader($r,'','Renamed Folder');
                   3407:         my $showfolder = $env{'form.renamed'};
                   3408:         my $renresult = &renamefolder($folder);
                   3409:         if ($renresult eq 'ok') {
1.143     wenzelju 3410:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" renamed to "[_2]".',$folder,$showfolder));
                   3411:             $message = &Apache::loncommon::confirmwrapper($message);
                   3412:             $r->print($message);
1.46      raeburn  3413:         } else {
1.143     wenzelju 3414:             my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Renaming failed.').' '.$renresult,1);
                   3415:             $message = &Apache::loncommon::confirmwrapper($message);
                   3416:             $r->print($message);
1.46      raeburn  3417:             $showfolder = $folder;
                   3418:         }
                   3419:         &Apache::loncommunicate::menu($r);
1.53      raeburn  3420:         &disall($r,$showfolder,$msgstatus);
1.1       albertel 3421:     } else {
1.112     weissno  3422: 	&printheader($r,'','Display All Messages');
1.44      raeburn  3423: 	&Apache::loncommunicate::menu($r);
1.53      raeburn  3424: 	&disall($r,($folder?$folder:$dismode),$msgstatus);
1.1       albertel 3425:     }
                   3426:     $r->print(&Apache::loncommon::end_page());
                   3427:     return OK;
                   3428: }
                   3429: # ================================================= Main program, reset counter
                   3430: 
                   3431: =pod
                   3432: 
                   3433: =cut
                   3434: 
                   3435: 1; 
                   3436: 
                   3437: __END__
                   3438: 

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