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

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

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