File:  [LON-CAPA] / loncom / interface / lonmsgdisplay.pm
Revision 1.52: download - view: text, annotated - select for diffs
Sun Dec 17 15:52:37 2006 UTC (17 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Escape quotes in mail folder names when creating strings for javascript arrays to avoid javascript errors.

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

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