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

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # Routines for messaging display
                      3: #
1.45    ! raeburn     4: # $Id: lonmsgdisplay.pm,v 1.44 2006/11/29 07:46:39 raeburn 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.40      albertel  273:     
                    274:     $result .= '<input type="hidden" name="sendmode" value="group" />'."\n";
1.25      foxr      275: 
1.40      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.38      raeburn   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.39      raeburn   350:                     $result.='<td valign="top">'.
1.38      raeburn   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.39      raeburn   361:                     $result .= "<th>$lt{'name'}</a></th>".
                    362:                                "<th>$lt{'usnm'}</a></th>".
                    363:                                "<th>$lt{'doma'}</a></th>".
1.38      raeburn   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 = '';
1.42      raeburn   489:     foreach my $key (sort(keys(%what))) {
                    490:         my %content=&Apache::lonmsg::unpackagemsg($what{$key});
1.1       albertel  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 />'.
1.42      raeburn   503:             '<input type="submit" name="rec_'.$key.'" value="'.&mt('Confirm Receipt').'" />'.
                    504:             '<input type="submit" name="reprec_'.$key.'" '.
1.1       albertel  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.38      raeburn   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.30      raeburn   643:                                        'co' => 'Course/Group',
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 %blocked = ();
                    653:     my $numblocked = 0;
                    654:     # Check for blocking of display because of scheduled online exams.
1.44      raeburn   655:     my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.1       albertel  656:     my %status_cache = 
                    657: 	&Apache::lonnet::get('email_status',\@msgids);
                    658:     my %descriptions;
1.42      raeburn   659:     foreach my $id (@msgids) {
                    660: 	my $msgid=&escape($id);
1.1       albertel  661:         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
                    662: 	    &Apache::lonmsg::unpackmsgid($msgid,undef,undef,\%status_cache);
                    663:         if (defined($sendtime) && $sendtime!~/error/) {
                    664:             my $description = &get_course_desc($fromcid,\%descriptions);
                    665:             my $numsendtime = $sendtime;
                    666:             $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
                    667:             if ($status eq 'new') {
                    668:                 if ($numsendtime >= $startblock && ($numsendtime <= $endblock && $endblock > 0) ) {
1.42      raeburn   669:                     $blocked{$id} = 'ON';
1.1       albertel  670:                     $numblocked ++;
                    671:                 } else {
                    672:                     push @newmsgs, { 
                    673:                         msgid    => $msgid,
                    674:                         sendtime => $sendtime,
1.8       albertel  675:                         shortsub => $shortsubj,
1.1       albertel  676:                         from     => $fromname,
                    677:                         fromdom  => $fromdom,
                    678:                         course   => $description 
                    679:                         }
                    680:                 }
                    681:             }
                    682:         }
                    683:     }
                    684:     if ($#newmsgs >= 0) {
                    685:         $r->print(<<TABLEHEAD);
                    686: <h2>$lt{'nm'}</h2>
1.4       albertel  687: <table class="LC_mail_list"><tr><th>&nbsp</th>
1.1       albertel  688: <th>$lt{'da'}</th><th>$lt{'us'}</th><th>$lt{'do'}</th><th>$lt{'su'}</th><th>$lt{'co'}</th></tr>
                    689: TABLEHEAD
                    690:         foreach my $msg (@newmsgs) {
                    691:             $r->print(<<"ENDLINK");
1.4       albertel  692: <tr class="LC_mail_new">
1.1       albertel  693: <td><a href="/adm/email?dismode=new&display=$msg->{'msgid'}">$lt{'op'}</a></td>
                    694: ENDLINK
1.42      raeburn   695:             foreach my $item ('sendtime','from','fromdom','shortsub','course') {
                    696:                 $r->print("<td>$msg->{$item}</td>");
1.1       albertel  697:             }
                    698:             $r->print("</td></tr>");
                    699:         }
                    700:         $r->print('</table>');
                    701:     } elsif ($numblocked == 0) {
                    702:         $r->print("<h3>".&mt('You have no unread messages')."</h3>");
                    703:     }
                    704:     if ($numblocked > 0) {
                    705:         my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
                    706:         my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
1.45    ! raeburn   707:         $r->print('<h3>'.&mt('You have [quant,_1,blocked unread message,blocked unread messages].',$numblocked).'</h3>'."\n".
        !           708:                  &mt('[quant,_1,message is,messages are] not viewable because display of LON-CAPA messages sent to you by other students between [_2] and [_3] is currently being blocked because of online exams.',$numblocked,$beginblock,$finishblock).'<br />'."\n".
        !           709:                  &Apache::loncommon::build_block_table($startblock,$endblock,
        !           710:                                                        \%setters));
1.1       albertel  711:     }
                    712: }
                    713: 
                    714: 
                    715: # ======================================================== Display all messages
                    716: 
                    717: sub disall {
                    718:     my ($r,$folder)=@_;
                    719:     $r->print(&folderlist($folder));
                    720:     if ($folder eq 'new') {
                    721: 	&disnew($r);
                    722:     } elsif ($folder eq 'critical') {
                    723: 	&discrit($r);
                    724:     } else {
                    725: 	&disfolder($r,$folder);
                    726:     }
                    727: }
                    728: 
                    729: # ============================================================ Display a folder
                    730: 
                    731: sub disfolder {
                    732:     my ($r,$folder)=@_;
                    733:     my %blocked = ();
                    734:     my %setters = ();
                    735:     my $numblocked = 0;
1.44      raeburn   736:     my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.1       albertel  737:     $r->print(<<ENDDISHEADER);
1.16      albertel  738: <script type="text/javascript">
1.1       albertel  739:     function checkall() {
                    740: 	for (i=0; i<document.forms.disall.elements.length; i++) {
                    741:             if 
                    742:           (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
                    743: 	      document.forms.disall.elements[i].checked=true;
                    744:             }
                    745:         }
                    746:     }
                    747: 
                    748:     function uncheckall() {
                    749: 	for (i=0; i<document.forms.disall.elements.length; i++) {
                    750:             if 
1.30      raeburn   751:           (document.forms.disall.elements[i].name.indexof('delmark_')==0) {
1.1       albertel  752: 	      document.forms.disall.elements[i].checked=false;
                    753:             }
                    754:         }
                    755:     }
                    756: </script>
                    757: ENDDISHEADER
                    758:     my $fsqs='&folder='.$folder;
1.42      raeburn   759:     my @temp=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder);
1.1       albertel  760:     my $totalnumber=$#temp+1;
                    761:     unless ($totalnumber>0) {
                    762: 	$r->print('<h2>'.&mt('Empty Folder').'</h2>');
                    763: 	return;
                    764:     }
                    765:     unless ($interdis) {
                    766: 	$interdis=20;
                    767:     }
                    768:     my $number=int($totalnumber/$interdis);
                    769:     if (($startdis<0) || ($startdis>$number)) { $startdis=$number; }
                    770:     my $firstdis=$interdis*$startdis;
                    771:     if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; }
                    772:     my $lastdis=$firstdis+$interdis-1;
                    773:     if ($lastdis>$#temp) { $lastdis=$#temp; }
                    774:     $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber));
                    775:     $r->print('<form method="post" name="disall" action="/adm/email">'.
1.4       albertel  776: 	      '<table class="LC_mail_list"><tr><th colspan="3">&nbsp</th><th>');
1.1       albertel  777:     if ($env{'form.sortedby'} eq "revdate") {
                    778: 	$r->print('<a href = "?sortedby=date'.$fsqs.'">'.&mt('Date').'</a></th>');
                    779:     } else {
                    780: 	$r->print('<a href = "?sortedby=revdate'.$fsqs.'">'.&mt('Date').'</a></th>');
                    781:     }
                    782:     $r->print('<th>');
                    783:     if ($env{'form.sortedby'} eq "revuser") {
                    784: 	$r->print('<a href = "?sortedby=user'.$fsqs.'">'.&mt('Username').'</a>');
                    785:     } else {
                    786: 	$r->print('<a href = "?sortedby=revuser'.$fsqs.'">'.&mt('Username').'</a>');
                    787:     }
                    788:     $r->print('</th><th>');
                    789:     if ($env{'form.sortedby'} eq "revdomain") {
                    790: 	$r->print('<a href = "?sortedby=domain'.$fsqs.'">'.&mt('Domain').'</a>');
                    791:     } else {
                    792: 	$r->print('<a href = "?sortedby=revdomain'.$fsqs.'">'.&mt('Domain').'</a>');
                    793:     }
                    794:     $r->print('</th><th>');
                    795:     if ($env{'form.sortedby'} eq "revsubject") {
                    796: 	$r->print('<a href = "?sortedby=subject'.$fsqs.'">'.&mt('Subject').'</a>');
                    797:     } else {
                    798:     	$r->print('<a href = "?sortedby=revsubject'.$fsqs.'">'.&mt('Subject').'</a>');
                    799:     }
                    800:     $r->print('</th><th>');
                    801:     if ($env{'form.sortedby'} eq "revcourse") {
1.30      raeburn   802:         $r->print('<a href = "?sortedby=course'.$fsqs.'">'.&mt('Course/Group').'</a>');
1.1       albertel  803:     } else {
1.30      raeburn   804:         $r->print('<a href = "?sortedby=revcourse'.$fsqs.'">'.&mt('Course/Group').'</a>');
1.1       albertel  805:     }
                    806:     $r->print('</th><th>');
                    807:     if ($env{'form.sortedby'} eq "revstatus") {
                    808: 	$r->print('<a href = "?sortedby=status'.$fsqs.'">'.&mt('Status').'</a></th>');
                    809:     } else {
                    810:      	$r->print('<a href = "?sortedby=revstatus'.$fsqs.'">'.&mt('Status').'</a></th>');
                    811:     }
                    812:     $r->print("</tr>\n");
1.6       albertel  813: 
                    814:     my $suffix = &Apache::lonmsg::foldersuffix($folder);
1.1       albertel  815:     for (my $n=$firstdis;$n<=$lastdis;$n++) {
1.11      albertel  816: 	my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,
                    817: 	    $description,$recv_name,$recv_domain)= 
                    818: 		@{$temp[$n]};
1.1       albertel  819: 	if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
                    820: 	    if ($status eq 'new') {
1.4       albertel  821: 		$r->print('<tr class="LC_mail_new">');
1.1       albertel  822: 	    } elsif ($status eq 'read') {
1.4       albertel  823: 		$r->print('<tr class="LC_mail_read">');
1.1       albertel  824: 	    } elsif ($status eq 'replied') {
1.4       albertel  825: 		$r->print('<tr class="LC_mail_replied">'); 
1.1       albertel  826: 	    } else {
1.4       albertel  827: 		$r->print('<tr class="LC_mail_other">');
1.1       albertel  828: 	    }
1.6       albertel  829: 	    my ($dis_name,$dis_domain) = ($fromname,$fromdomain);
                    830: 	    if ($folder eq 'sent') {
1.11      albertel  831: 		if (defined($recv_name) && !defined($recv_domain)) {
                    832: 		    $dis_name   = join('<br />',@{$recv_name});
                    833: 		    $dis_domain = join('<br />',@{$recv_domain});
                    834: 		} else {
1.29      www       835: 		    my $msg_id  = &unescape($origID);
1.11      albertel  836: 		    my %message = &Apache::lonnet::get('nohist_email'.$suffix,
                    837: 						       [$msg_id]);
                    838: 		    my %content = &Apache::lonmsg::unpackagemsg($message{$msg_id});
                    839: 		    $dis_name   = join('<br />',@{$content{'recuser'}});
                    840: 		    $dis_domain = join('<br />',@{$content{'recdomain'}});
                    841: 		}
1.6       albertel  842: 	    }
1.1       albertel  843: 	    $r->print('<td><input type="checkbox" name="delmark_'.$origID.'" /></td><td><a href="/adm/email?display='.$origID.$sqs. 
                    844: 		      '">'.&mt('Open').'</a></td><td>'.
                    845: 		      ($folder ne 'trash'?'<a href="/adm/email?markdel='.$origID.$sqs.
                    846: 		      '">'.&mt('Delete'):'&nbsp').'</a></td>'.
                    847: 		      '<td>'.&Apache::lonlocal::locallocaltime($sendtime).'</td><td>'.
1.6       albertel  848: 		      $dis_name.'</td><td>'.$dis_domain.'</td><td>'.
1.8       albertel  849: 		      $shortsubj.'</td><td>'.
1.1       albertel  850:                       $description.'</td><td>'.$status.'</td></tr>'."\n");
                    851: 	} elsif ($status eq 'deleted') {
                    852: # purge
1.9       albertel  853: 	    my ($result,$msg) = 
1.29      www       854: 		&movemsg(&unescape($origID),$folder,'trash');
1.9       albertel  855: 	    
1.1       albertel  856: 	}
                    857:     }   
                    858:     $r->print("</table>\n<p>".
                    859:   '<a href="javascript:checkall()">'.&mt('Check All').'</a>&nbsp;'.
                    860:   '<a href="javascript:uncheckall()">'.&mt('Uncheck All').'</a></p>'.
                    861:   '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" />');
                    862:     if ($folder ne 'trash') {
                    863: 	$r->print(
                    864: 	      '<p><input type="submit" name="markeddel" value="'.&mt('Delete Checked').'" /></p>');
                    865:     }
                    866:     $r->print('<p><input type="submit" name="markedmove" value="'.&mt('Move Checked to Folder').'" />');
                    867:     my @allfolders=&Apache::lonnet::getkeys('email_folders');
                    868:     if ($allfolders[0]=~/^error:/) { @allfolders=(); }
                    869:     $r->print(
                    870: 	&Apache::loncommon::select_form('','movetofolder',
                    871: 			     ( map { $_ => $_ } @allfolders))
                    872: 	      );
                    873:     my $postedstartdis=$startdis+1;
                    874:     $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>');
                    875:     if ($numblocked > 0) {
                    876:         my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
                    877:         my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
                    878:         $r->print('<br /><br />'.
1.45    ! raeburn   879:                   &mt('[_1,quant,message is, messages are] not viewable because display of LON-CAPA messages sent to you by other students between [_2] and [_3] is currently being blocked because of online exams.',$numblocked,$beginblock,$finishblock));
1.44      raeburn   880:         $r->print(&Apache::loncommon::build_block_table($startblock,$endblock,
                    881:                                                         \%setters));
1.1       albertel  882:     }
                    883: }
                    884: 
                    885: # ============================================================== Compose output
                    886: 
                    887: sub compout {
                    888:     my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode)=@_;
                    889:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
1.38      raeburn   890:     my ($cdom,$cnum,$group,$refarg);
                    891:     if (exists($env{'form.group'})) {
                    892:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    893:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    894:         $group = $env{'form.group'};
                    895:         my $action = 'composing';
                    896:         $r->print(&groupmail_header($action,$group,$cdom,$cnum));
                    897:     } elsif ($broadcast eq 'individual') {
1.1       albertel  898: 	&printheader($r,'/adm/email?compose=individual',
                    899: 	     'Send a Message');
                    900:     } elsif ($broadcast) {
                    901: 	&printheader($r,'/adm/email?compose=group',
                    902: 	     'Broadcast Message');
                    903:     } elsif ($forwarding) {
                    904: 	&Apache::lonhtmlcommon::add_breadcrumb
1.29      www       905:         ({href=>"/adm/email?display=".&escape($forwarding),
1.1       albertel  906:           text=>"Display Message"});
1.29      www       907: 	&printheader($r,'/adm/email?forward='.&escape($forwarding),
1.1       albertel  908: 	     'Forwarding a Message');
                    909:     } elsif ($replying) {
                    910: 	&Apache::lonhtmlcommon::add_breadcrumb
1.29      www       911:         ({href=>"/adm/email?display=".&escape($replying),
1.1       albertel  912:           text=>"Display Message"});
1.29      www       913: 	&printheader($r,'/adm/email?replyto='.&escape($replying),
1.1       albertel  914: 	     'Replying to a Message');
                    915:     } elsif ($replycrit) {
                    916: 	$r->print('<h3>'.&mt('Replying to a Critical Message').'</h3>');
                    917: 	$replying=$replycrit;
                    918:     } else {
                    919: 	&printheader($r,'/adm/email?compose=upload',
                    920: 	     'Distribute from Uploaded File');
                    921:     }
                    922: 
                    923:     my $dispcrit='';
                    924:     my $dissub='';
                    925:     my $dismsg='';
                    926:     my $disbase='';
                    927:     my $func=&mt('Send New');
                    928:     my %lt=&Apache::lonlocal::texthash('us' => 'Username',
                    929: 				       'do' => 'Domain',
                    930: 				       'ad' => 'Additional Recipients',
                    931: 				       'sb' => 'Subject',
                    932: 				       'ca' => 'Cancel',
                    933: 				       'ma' => 'Mail');
                    934: 
                    935:     if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    936: 	|| &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    937: 				    '/'.$env{'request.course.sec'})) {
                    938: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
                    939:          $dispcrit=
                    940:  '<p><label><input type="checkbox" name="critmsg" /> '.&mt('Send as critical message').'</label> ' . $crithelp . 
                    941:  '</p><p>'.
                    942:  '<label><input type="checkbox" name="sendbck" /> '.&mt('Send as critical message').'  ' .
                    943:  &mt('and return receipt') . '</label>' . $crithelp . 
                    944:  '</p><p><label><input type="checkbox" name="permanent" /> '.
                    945: &mt('Send copy to permanent email address (if known)').'</label></p>'.
                    946: '<p><label><input type="checkbox" name="rsspost" /> '.
                    947: 		  &mt('Include in course RSS newsfeed').'</label></p>';
                    948:      }
                    949:     my %message;
                    950:     my %content;
                    951:     my $defdom=$env{'user.domain'};
                    952:     if ($forwarding) {
                    953: 	%message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]);
                    954: 	%content=&Apache::lonmsg::unpackagemsg($message{$forwarding},$folder);
                    955: 	$dispcrit.='<input type="hidden" name="forwid" value="'.
                    956: 	    $forwarding.'" />';
                    957: 	$func=&mt('Forward');
                    958: 	
                    959: 	$dissub=&mt('Forwarding').': '.$content{'subject'};
                    960: 	$dismsg=&mt('Forwarded message from').' '.
                    961: 	    $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
                    962: 	if ($content{'baseurl'}) {
1.29      www       963: 	    $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1       albertel  964: 	}
                    965:     }
                    966:     if ($replying) {
                    967: 	%message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
                    968: 	%content=&Apache::lonmsg::unpackagemsg($message{$replying},$folder);
                    969: 	$dispcrit.='<input type="hidden" name="replyid" value="'.
                    970: 	    $replying.'" />';
                    971: 	$func=&mt('Send Reply to');
                    972: 	
                    973: 	$dissub=&mt('Reply').': '.$content{'subject'};       
                    974: 	$dismsg='> '.$content{'message'};
                    975: 	$dismsg=~s/\r/\n/g;
                    976: 	$dismsg=~s/\f/\n/g;
                    977: 	$dismsg=~s/\n+/\n\> /g;
                    978: 	if ($content{'baseurl'}) {
1.29      www       979: 	    $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1       albertel  980: 	    if ($env{'user.adv'}) {
                    981: 		$disbase.='<label><input type="checkbox" name="storebasecomment" />'.&mt('Store message for re-use').
                    982: 		    '</label> <a href="/adm/email?showcommentbaseurl='.
1.29      www       983: 		    &escape($content{'baseurl'}).'" target="comments">'.
1.1       albertel  984: 		    &mt('Show re-usable messages').'</a><br />';
                    985: 	    }
                    986: 	}
                    987:     }
                    988:     my $citation=&displayresource(%content);
1.38      raeburn   989:     my ($can_grp_broadcast,$viewgrps,$editgrps);
1.1       albertel  990:     if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
1.23      www       991:     if ($env{'form.text'}) { $dismsg=$env{'form.text'}; }
                    992:     if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; }
                    993:     $r->print(
1.1       albertel  994:                 '<form action="/adm/email"  name="compemail" method="post"'.
                    995:                 ' enctype="multipart/form-data">'."\n".
1.38      raeburn   996:                 '<input type="hidden" name="sendmail" value="on" />'."\n");
                    997:     if ($broadcast eq 'group' && $env{'form.group'} ne '') {
                    998:         $can_grp_broadcast = 
                    999:                 &Apache::lonnet::allowed('sgb',$env{'request.course.id'}.'/'.
                   1000:                                          $group);
                   1001:         $viewgrps = 
                   1002:                &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
                   1003:                ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
                   1004:         $editgrps = 
                   1005:                &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
                   1006:                ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
                   1007:         if ($viewgrps || $editgrps || $can_grp_broadcast) {
                   1008:             $r->print(&disgroup($cdom,$cnum,$group,$viewgrps,$editgrps));
                   1009:         }
                   1010:     }
                   1011:     $r->print('<table>');
                   1012:     if (($broadcast eq 'group') && ($group ne '') && 
                   1013:         (!$can_grp_broadcast && !$viewgrps && !$editgrps)) {
                   1014:         $r->print(&recipient_input_row($cdom,%lt));
                   1015:     } 
                   1016:     if (($broadcast ne 'group') && ($broadcast ne 'upload')) {
1.1       albertel 1017: 	if ($replying) {
                   1018: 	    $r->print('<tr><td colspan="2">'.&mt('Replying to').' '.
                   1019: 		      &Apache::loncommon::aboutmewrapper(
                   1020: 							 &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
1.14      albertel 1021: 		      $content{'sendername'}.':'.
1.1       albertel 1022: 		      $content{'senderdomain'}.')'.
                   1023: 		      '<input type="hidden" name="recuname" value="'.$content{'sendername'}.'" />'.
                   1024: 		      '<input type="hidden" name="recdomain" value="'.$content{'senderdomain'}.'" />'.
                   1025: 		      '</td></tr>');
                   1026: 	} else {
1.38      raeburn  1027:             $r->print(&recipient_input_row($defdom,%lt));
1.1       albertel 1028:         }
                   1029:     }
                   1030:     my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
                   1031:     if ($broadcast ne 'upload') {
                   1032:        $r->print(<<"ENDCOMP");
1.43      raeburn  1033: <tr><td>$lt{'ad'}<br /><tt>username:domain,username:domain, ...
1.1       albertel 1034: </tt></td><td>
                   1035: <input type="text" size="50" name="additionalrec" /></td></tr>
                   1036: <tr><td>$lt{'sb'}:</td><td><input type="text" size="50" name="subject" value="$dissub" />
                   1037: </td></tr></table>
                   1038: $latexHelp
                   1039: <textarea name="message" id="message" cols="80" rows="15" wrap="hard">$dismsg
                   1040: </textarea></p><br />
                   1041: $dispcrit
                   1042: $disbase
                   1043: <input type="hidden" name="folder" value="$folder" />
                   1044: <input type="hidden" name="dismode" value="$dismode" />
                   1045: <input type="submit" name="send" value="$func $lt{'ma'}" />
                   1046: <input type="submit" name="cancel" value="$lt{'ca'}" /><hr />
                   1047: $citation
                   1048: ENDCOMP
1.38      raeburn  1049:         if (exists($env{'form.ref'})) {
                   1050:             $r->print('<input type="hidden" name="ref" value="'.
                   1051:                       $env{'form.ref'}.'" />');
                   1052:         }
                   1053:         if (exists($env{'form.group'})) {
                   1054:             $r->print('<input type="hidden" name="group" value="'.
                   1055:                       $env{'form.group'}.'" />');
                   1056:         }
1.1       albertel 1057:     } else { # $broadcast is 'upload'
                   1058: 	$r->print(<<ENDUPLOAD);
                   1059: <input type="hidden" name="sendmode" value="upload" />
                   1060: <input type="hidden" name="send" value="on" />
                   1061: <h3>Generate messages from a file</h3>
                   1062: <p>
                   1063: Subject: <input type="text" size="50" name="subject" />
                   1064: </p>
                   1065: <p>General message text<br />
                   1066: <textarea name="message" id="message" cols="60" rows="10" wrap="hard">$dismsg
                   1067: </textarea></p>
                   1068: <p>
                   1069: The file format for the uploaded portion of the message is:
                   1070: <pre>
1.43      raeburn  1071: username1:domain1: text
                   1072: username2:domain2: text
                   1073: username3:domain1: text
1.1       albertel 1074: </pre>
                   1075: </p>
                   1076: <p>
                   1077: The messages will be assembled from all lines with the respective 
1.43      raeburn  1078: <tt>username:domain</tt>, and appended to the general message text.</p>
1.1       albertel 1079: <p>
                   1080: <input type="file" name="upfile" size="40" /></p><p>
                   1081: $dispcrit
                   1082: <input type="submit" value="Upload and Send" /></p>
                   1083: ENDUPLOAD
                   1084:     }
                   1085:     if ($broadcast eq 'group') {
1.38      raeburn  1086:        if ($group eq '') {
                   1087:            my $studentsel = &discourse();
                   1088:            $r->print($studentsel);
                   1089:        }
1.1       albertel 1090:     }
1.36      albertel 1091:     if ($env{'form.displayedcrit'}) {
                   1092: 	$r->print('<input type="hidden" name="displayedcrit" value="true" />');
                   1093:     }
1.1       albertel 1094:     $r->print('</form>'.
                   1095: 	      &Apache::lonfeedback::generate_preview_button('compemail','message').
                   1096: 	      &Apache::lonhtmlcommon::htmlareaselectactive('message'));
                   1097: }
                   1098: 
                   1099: # ---------------------------------------------------- Display all face to face
                   1100: 
1.38      raeburn  1101: sub recipient_input_row {
                   1102:     my ($dom,%lt) = @_;
                   1103:     my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain');
                   1104:     my $selectlink=
                   1105:       &Apache::loncommon::selectstudent_link('compemail','recuname',
                   1106:                                              'recdomain');
                   1107:     my $output = <<"ENDREC";
                   1108: <tr><td>$lt{'us'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recname'}" /></td><td rowspan="2">$selectlink</td></tr>
                   1109: <tr><td>$lt{'do'}:</td>
                   1110: <td>$domform</td></tr>
                   1111: ENDREC
                   1112:     return $output;
                   1113: }
                   1114: 
1.1       albertel 1115: sub retrieve_instructor_comments {
                   1116:     my ($user,$domain)=@_;
                   1117:     my $target=$env{'form.grade_target'};
                   1118:     if (! $env{'request.course.id'}) { return; }
                   1119:     if (! &Apache::lonnet::allowed('srm',$env{'request.course.id'})
                   1120: 	&& ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                   1121: 				      '/'.$env{'request.course.sec'})) {
                   1122: 	return;
                   1123:     }
                   1124:     my %records=&Apache::lonnet::dump('nohist_email',
                   1125: 			 $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1126: 			 $env{'course.'.$env{'request.course.id'}.'.num'},
                   1127:                          '%255b'.$user.'%253a'.$domain.'%255d');
                   1128:     my $result='';
1.42      raeburn  1129:     foreach my $key (sort(keys(%records))) {
                   1130:         my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1       albertel 1131:         next if ($content{'senderdomain'} eq '');
                   1132:         next if ($content{'subject'} !~ /^Record/);
                   1133: 	# &Apache::lonfeedback::newline_to_br(\$content{'message'});
                   1134: 	$result.='Recorded by '.
1.14      albertel 1135:             $content{'sendername'}.':'.$content{'senderdomain'}."\n";
1.1       albertel 1136:         $result.=
                   1137:             &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
                   1138:      }
                   1139:     return $result;
                   1140: }
                   1141: 
                   1142: sub disfacetoface {
                   1143:     my ($r,$user,$domain)=@_;
                   1144:     my $target=$env{'form.grade_target'};
                   1145:     unless ($env{'request.course.id'}) { return; }
                   1146:     if  (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                   1147: 	 && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                   1148: 				       '/'.$env{'request.course.sec'})) {
                   1149: 	$r->print('Not allowed');
                   1150: 	return;
                   1151:     }
                   1152:     my %records=&Apache::lonnet::dump('nohist_email',
                   1153: 			 $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1154: 			 $env{'course.'.$env{'request.course.id'}.'.num'},
                   1155:                          '%255b'.$user.'%253a'.$domain.'%255d');
                   1156:     my $result='';
1.42      raeburn  1157:     foreach my $key (sort(keys(%records))) {
                   1158:         my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1       albertel 1159:         next if ($content{'senderdomain'} eq '');
                   1160: 	&Apache::lonfeedback::newline_to_br(\$content{'message'});
                   1161:         if ($content{'subject'}=~/^Record/) {
                   1162: 	    $result.='<h3>'.&mt('Record').'</h3>';
                   1163:         } elsif ($content{'subject'}=~/^Broadcast/) {
                   1164:             $result .='<h3>'.&mt('Broadcast Message').'</h3>';
                   1165:             if ($content{'subject'}=~/^Broadcast\./) {
                   1166:                 if (defined($content{'coursemsgid'})) {
1.29      www      1167:                     my $crsmsgid = &escape($content{'coursemsgid'});
1.1       albertel 1168:                     my $broadcast_message = &general_message($crsmsgid);
                   1169:                     $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$broadcast_message;
                   1170:                 } else {
                   1171:                     %content=&Apache::lonmsg::unpackagemsg($content{'message'});
                   1172:                     $content{'message'} =
                   1173:                     '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
                   1174:                     $content{'message'};
                   1175:                 }
                   1176:             }    
                   1177:         } else {
                   1178:             $result.='<h3>'.&mt('Critical Message').'</h3>';
                   1179:             if (defined($content{'coursemsgid'})) {
1.29      www      1180:                 my $crsmsgid=&escape($content{'coursemsgid'});
1.1       albertel 1181:                 my $critical_message = &general_message($crsmsgid);
                   1182:                 $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$critical_message;
                   1183:             } else {
                   1184:                 %content=&Apache::lonmsg::unpackagemsg($content{'message'});
                   1185:                 $content{'message'}=
                   1186:                 '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
                   1187: 		$content{'message'};
                   1188:             }
                   1189:         }
                   1190:         $result.=&mt('By').': <b>'.
                   1191: &Apache::loncommon::aboutmewrapper(
                   1192:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14      albertel 1193: $content{'sendername'}.':'.
1.1       albertel 1194:             $content{'senderdomain'}.') '.$content{'time'}.
                   1195:             '<br /><pre>'.
                   1196:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
                   1197: 	      '</pre>';
                   1198:      }
                   1199:     # Check to see if there were any messages.
                   1200:     if ($result eq '') {
1.33      albertel 1201:         my $lctype = lc(&Apache::loncommon::course_type());
1.1       albertel 1202: 	if ($target ne 'tex') { 
1.30      raeburn  1203: 	    $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 1204: 	} else {
1.30      raeburn  1205: 	    $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this [_1].',$lctype).'}\\\\');
1.1       albertel 1206: 	}
                   1207:     } else {
                   1208:        $r->print($result);
                   1209:     }
                   1210: }
                   1211: 
                   1212: sub general_message {
                   1213:     my ($crsmsgid) = @_;
                   1214:     my %general_content;
                   1215:     if ($crsmsgid) { 
                   1216:         my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid],
                   1217:                            $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1218:                            $env{'course.'.$env{'request.course.id'}.'.num'});
                   1219:         %general_content = &Apache::lonmsg::unpackagemsg($course_content{$crsmsgid});
                   1220:     }
                   1221:     return $general_content{'message'};
                   1222: }
                   1223: 
                   1224: # ---------------------------------------------------------------- Face to face
                   1225: 
                   1226: sub facetoface {
                   1227:     my ($r,$stage)=@_;
                   1228:     if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                   1229: 	&& ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                   1230: 				      '/'.$env{'request.course.sec'})) {
                   1231: 	$r->print('Not allowed');
                   1232: 	return;
                   1233:     }
1.33      albertel 1234:     my $crstype = &Apache::loncommon::course_type();
                   1235:     my $leaders = ($crstype eq 'Group') ? 'coordinators and leaders'
                   1236:                                         : 'faculty and staff';
1.1       albertel 1237:     &printheader($r,
                   1238: 		 '/adm/email?recordftf=query',
                   1239: 		 "User Notes, Face-to-Face, Critical Messages, Broadcast Messages");
                   1240: # from query string
                   1241: 
                   1242:     if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
                   1243:     if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
                   1244: 
                   1245:     my $defdom=$env{'user.domain'};
                   1246: # already filled in
                   1247:     if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
                   1248: # generate output
                   1249:     my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
                   1250:     my $stdbrws = &Apache::loncommon::selectstudent_link
                   1251: 	('stdselect','recuname','recdomain');
                   1252:     my %lt=&Apache::lonlocal::texthash('user' => 'Username',
                   1253: 				       'dom' => 'Domain',
1.30      raeburn  1254: 				       'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, and Broadcast Messages in $crstype",
1.1       albertel 1255: 				       'subm' => 'Retrieve discussion and message records',
1.30      raeburn  1256: 				       'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')',
1.1       albertel 1257: 				       'post' => 'Post this Record');
                   1258:     $r->print(<<"ENDTREC");
                   1259: <h3>$lt{'head'}</h3>
                   1260: <form method="post" action="/adm/email" name="stdselect">
                   1261: <input type="hidden" name="recordftf" value="retrieve" />
                   1262: <table>
                   1263: <tr><td>$lt{'user'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recuname'}" /></td>
                   1264: <td rowspan="2">
                   1265: $stdbrws
                   1266: <input type="submit" value="$lt{'subm'}" /></td>
                   1267: </tr>
                   1268: <tr><td>$lt{'dom'}:</td>
                   1269: <td>$domform</td></tr>
                   1270: </table>
                   1271: </form>
                   1272: ENDTREC
                   1273:     if (($stage ne 'query') &&
                   1274:         ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
                   1275:         chomp($env{'form.newrecord'});
                   1276:         if ($env{'form.newrecord'}) {
1.31      albertel 1277: 	    &Apache::lonmsg::store_instructor_comment($env{'form.newrecord'},
                   1278: 						      $env{'form.recuname'},
                   1279: 						      $env{'form.recdomain'});
1.1       albertel 1280:         }
                   1281:         $r->print('<h3>'.&Apache::loncommon::plainname($env{'form.recuname'},
                   1282: 				     $env{'form.recdomain'}).'</h3>');
                   1283:         &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
                   1284: 	$r->print(<<ENDRHEAD);
                   1285: <form method="post" action="/adm/email">
                   1286: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
                   1287: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
                   1288: ENDRHEAD
                   1289:         $r->print(<<ENDBFORM);
                   1290: <hr />$lt{'newr'}<br />
                   1291: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
                   1292: <br />
                   1293: <input type="hidden" name="recordftf" value="post" />
                   1294: <input type="submit" value="$lt{'post'}" />
                   1295: </form>
                   1296: ENDBFORM
                   1297:     }
                   1298: }
                   1299: 
                   1300: # ----------------------------------------------------------- Blocking during exams
                   1301: 
                   1302: sub examblock {
                   1303:     my ($r,$action) = @_;
                   1304:     unless ($env{'request.course.id'}) { return;}
1.44      raeburn  1305:     if (!&Apache::lonnet::allowed('dcm',$env{'request.course.id'})
                   1306: 	&& ! &Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
1.1       albertel 1307: 				      '/'.$env{'request.course.sec'})) {
                   1308: 	$r->print('Not allowed');
                   1309: 	return;
                   1310:     }
1.34      albertel 1311:     my $usertype = (&Apache::loncommon::course_type() eq 'Group') ? 'members'
1.33      albertel 1312: 	                                                          : 'students';
1.1       albertel 1313:     my %lt=&Apache::lonlocal::texthash(
                   1314:             'comb' => 'Communication Blocking',
                   1315:             'cbds' => 'Communication blocking during scheduled exams',
1.30      raeburn  1316:             '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 1317:              'mecb' => 'Modify existing communication blocking periods',
                   1318:              'ncbc' => 'No communication blocks currently stored'
                   1319:     );
                   1320: 
                   1321:     my %ltext = &Apache::lonlocal::texthash(
                   1322:             'dura' => 'Duration',
                   1323:             'setb' => 'Set by',
                   1324:             'even' => 'Event',
1.44      raeburn  1325:             'blck' => 'Blocked?',
1.1       albertel 1326:             'actn' => 'Action',
                   1327:             'star' => 'Start',
                   1328:             'endd' => 'End'
                   1329:     );
                   1330: 
                   1331:     &printheader($r,'/adm/email?block=display',$lt{'comb'});
                   1332:     $r->print('<h3>'.$lt{'cbds'}.'</h3>');
                   1333: 
                   1334:     if ($action eq 'store') {
                   1335:         &blockstore($r);
                   1336:     }
                   1337: 
                   1338:     $r->print($lt{'desc'}.'<br /><br />
                   1339:                <form name="blockform" method="post" action="/adm/email?block=store">
                   1340:              ');
                   1341: 
                   1342:     $r->print('<h4>'.$lt{'mecb'}.'</h4>');
                   1343:     my %records = ();
                   1344:     my $blockcount = 0;
                   1345:     my $parmcount = 0;
                   1346:     &get_blockdates(\%records,\$blockcount);
                   1347:     if ($blockcount > 0) {
                   1348:         $parmcount = &display_blocker_status($r,\%records,\%ltext);
                   1349:     } else {
                   1350:         $r->print($lt{'ncbc'}.'<br /><br />');
                   1351:     }
                   1352:     &display_addblocker_table($r,$parmcount,\%ltext);
                   1353:     my $end_page=&Apache::loncommon::end_page();
                   1354:     $r->print(<<"END");
                   1355: <br />
                   1356: <input type="hidden" name="blocktotal" value="$blockcount" />
                   1357: <input type ="submit" value="Save Changes" />
                   1358: </form>
                   1359: $end_page
                   1360: END
                   1361:     return;
                   1362: }
                   1363: 
                   1364: sub blockstore {
                   1365:     my $r = shift;
                   1366:     my %lt=&Apache::lonlocal::texthash(
                   1367:             'tfcm' => 'The following changes were made',
                   1368:             'cbps' => 'communication blocking period(s)',
                   1369:             'werm' => 'was/were removed',
                   1370:             'wemo' => 'was/were modified',
                   1371:             'wead' => 'was/were added',
                   1372:             'ncwm' => 'No changes were made.' 
                   1373:     );
                   1374:     my %adds = ();
                   1375:     my %removals = ();
                   1376:     my %cancels = ();
                   1377:     my $modtotal = 0;
                   1378:     my $canceltotal = 0;
                   1379:     my $addtotal = 0;
                   1380:     my %blocking = ();
                   1381:     $r->print('<h3>'.$lt{'head'}.'</h3>');
1.42      raeburn  1382:     foreach my $envkey (keys(%env)) {
1.44      raeburn  1383:         if ($envkey =~ m/^form\.modify_(\d+)$/) {
1.1       albertel 1384:             $adds{$1} = $1;
                   1385:             $removals{$1} = $1;
                   1386:             $modtotal ++;
1.42      raeburn  1387:         } elsif ($envkey =~ m/^form\.cancel_(\d+)$/) {
1.1       albertel 1388:             $cancels{$1} = $1;
                   1389:             unless ( defined($removals{$1}) ) {
                   1390:                 $removals{$1} = $1;
                   1391:                 $canceltotal ++;
                   1392:             }
1.42      raeburn  1393:         } elsif ($envkey =~ m/^form\.add_(\d+)$/) {
1.1       albertel 1394:             $adds{$1} = $1;
                   1395:             $addtotal ++;
1.44      raeburn  1396:         } 
1.1       albertel 1397:     }
                   1398: 
1.42      raeburn  1399:     foreach my $key (keys(%removals)) {
                   1400:         my $hashkey = $env{'form.key_'.$key};
1.1       albertel 1401:         &Apache::lonnet::del('comm_block',["$hashkey"],
                   1402:                          $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1403:                          $env{'course.'.$env{'request.course.id'}.'.num'}
                   1404:                          );
                   1405:     }
1.42      raeburn  1406:     foreach my $key (keys(%adds)) {
                   1407:         unless ( defined($cancels{$key}) ) {
                   1408:             my ($newstart,$newend) = &get_dates_from_form($key);
1.1       albertel 1409:             my $newkey = $newstart.'____'.$newend;
1.44      raeburn  1410:             my $blocktypes = &get_block_choices($key);
                   1411:             $blocking{$newkey} = {
                   1412:                           setter => $env{'user.name'}.':'.$env{'user.domain'},
                   1413:                           event  => &escape($env{'form.title_'.$key}),
                   1414:                           blocks => $blocktypes,
                   1415:                         };
1.1       albertel 1416:         }
                   1417:     }
                   1418:     if ($addtotal + $modtotal > 0) {
                   1419:         &Apache::lonnet::put('comm_block',\%blocking,
                   1420:                      $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1421:                      $env{'course.'.$env{'request.course.id'}.'.num'}
                   1422:                      );
                   1423:     }
                   1424:     my $chgestotal = $canceltotal + $modtotal + $addtotal;
                   1425:     if ($chgestotal > 0) {
                   1426:         $r->print($lt{'tfcm'}.'<ul>');
                   1427:         if ($canceltotal > 0) {
                   1428:             $r->print('<li>'.$canceltotal.' '.$lt{'cbps'},' '.$lt{'werm'}.'</li>');
                   1429:         }
                   1430:         if ($modtotal > 0) {
                   1431:             $r->print('<li>'.$modtotal.' '.$lt{'cbps'},' '.$lt{'wemo'}.'</li>');
                   1432:         }
                   1433:         if ($addtotal > 0) {
                   1434:             $r->print('<li>'.$addtotal.' '.$lt{'cbps'},' '.$lt{'wead'}.'</li>');
                   1435:         }
                   1436:         $r->print('</ul>');
                   1437:     } else {
                   1438:         $r->print($lt{'ncwm'});
                   1439:     }
                   1440:     $r->print('<br />');
                   1441:     return;
                   1442: }
                   1443: 
                   1444: sub get_dates_from_form {
                   1445:     my $item = shift;
                   1446:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
                   1447:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
                   1448:     return ($startdate,$enddate);
                   1449: }
                   1450: 
                   1451: sub get_blockdates {
                   1452:     my ($records,$blockcount) = @_;
                   1453:     $$blockcount = 0;
                   1454:     %{$records} = &Apache::lonnet::dump('comm_block',
                   1455:                          $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1456:                          $env{'course.'.$env{'request.course.id'}.'.num'}
                   1457:                          );
1.15      albertel 1458:     $$blockcount = keys(%{$records});
                   1459: 
                   1460:     if ((keys(%{$records}))[0] =~ /^error: 2 /) {
                   1461: 	$records = {};
                   1462: 	$$blockcount = 0;
1.1       albertel 1463:     }
                   1464: }
                   1465: 
1.44      raeburn  1466: sub get_block_choices {
                   1467:     my $item = shift;
                   1468:     my $blocklist;
                   1469:     my ($typeorder,$types) = &blocktype_text();
                   1470:     foreach my $type (@{$typeorder}) {
                   1471:         if ($env{'form.'.$type.'_'.$item}) {
                   1472:             $blocklist->{$type} = 'on'; 
                   1473:         } else {
                   1474:             $blocklist->{$type} = 'off';
                   1475:         }
                   1476:     }
                   1477:     return $blocklist;
                   1478: }
                   1479: 
1.1       albertel 1480: sub display_blocker_status {
                   1481:     my ($r,$records,$ltext) = @_;
                   1482:     my $parmcount = 0;
1.16      albertel 1483:   
1.1       albertel 1484:     my %lt = &Apache::lonlocal::texthash(
                   1485:         'modi' => 'Modify',
                   1486:         'canc' => 'Cancel',
                   1487:     );
1.44      raeburn  1488:     my ($typeorder,$types) = &blocktype_text();
1.18      albertel 1489:     $r->print(&Apache::loncommon::start_data_table());
1.1       albertel 1490:     $r->print(<<"END");
1.16      albertel 1491:   <tr>
1.44      raeburn  1492:     <th>$ltext->{'dura'}</th>
                   1493:     <th>$ltext->{'setb'}</th>
                   1494:     <th>$ltext->{'even'}</th>
                   1495:     <th>$ltext->{'blck'}</th>
                   1496:     <th>$ltext->{'actn'}?</th>
1.16      albertel 1497:   </tr>
1.1       albertel 1498: END
1.18      albertel 1499:     foreach my $record (sort(keys(%{$records}))) {
1.1       albertel 1500:         my $onchange = 'onFocus="javascript:window.document.forms['.
                   1501:                        "'blockform'].elements['modify_".$parmcount."'].".
                   1502:                        'checked=true;"';
1.18      albertel 1503:         my ($start,$end) = split(/____/,$record);
1.1       albertel 1504:         my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
                   1505:         my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1.15      albertel 1506: 	
1.44      raeburn  1507: 	my ($setuname,$setudom,$title,$blocks) = 
                   1508: 	    &Apache::loncommon::parse_block_record($$records{$record});
1.21      albertel 1509: 	$title = &HTML::Entities::encode($title,'"<>&');
1.44      raeburn  1510:         my $settername = 
                   1511:            &Apache::loncommon::aboutmewrapper(
                   1512:                            &Apache::loncommon::plainname($setuname,$setudom),
                   1513:                            $setuname,$setudom);
1.18      albertel 1514:         $r->print(&Apache::loncommon::start_data_table_row());
1.1       albertel 1515:         $r->print(<<"END");
1.44      raeburn  1516:         <td>$ltext->{'star'}:&nbsp;$startform<br/>$ltext->{'endd'}:&nbsp;&nbsp;$endform</td>
1.1       albertel 1517:         <td>$settername</td>
1.18      albertel 1518:         <td><input type="text" name="title_$parmcount" size="15" value="$title" /><input type="hidden" name="key_$parmcount" value="$record" /></td>
1.44      raeburn  1519:         <td>
                   1520: END
                   1521:         foreach my $block (@{$typeorder}) {
                   1522:             my $blockstatus = '';
                   1523:             if ($blocks->{$block} eq 'on') {
                   1524:                 $blockstatus = 'checked="true"';
                   1525:             }
                   1526:             $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" '.$blockstatus.' value="1" />'.$types->{$block}.'</label><br />');
                   1527:         }
                   1528:         $r->print(<<"END");
                   1529:         </td>      
1.1       albertel 1530:         <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>
                   1531: END
1.18      albertel 1532:         $r->print(&Apache::loncommon::end_data_table_row());
                   1533:         $parmcount++;
1.1       albertel 1534:     }
                   1535:     $r->print(<<"END");
                   1536: </table>
                   1537: <br />
                   1538: <br />
                   1539: END
                   1540:     return $parmcount;
                   1541: }
                   1542: 
                   1543: sub display_addblocker_table {
                   1544:     my ($r,$parmcount,$ltext) = @_;
                   1545:     my $start = time;
                   1546:     my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
                   1547:     my $onchange = 'onFocus="javascript:window.document.forms['.
                   1548:                    "'blockform'].elements['add_".$parmcount."'].".
                   1549:                    'checked=true;"';
                   1550:     my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
                   1551:     my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
                   1552:     my %lt = &Apache::lonlocal::texthash(
                   1553:         'addb' => 'Add block',
                   1554:         'exam' => 'e.g., Exam 1',
                   1555:         'addn' => 'Add new communication blocking periods'
                   1556:     );
1.44      raeburn  1557:     my ($typeorder,$types) = &blocktype_text();
1.1       albertel 1558:     $r->print(<<"END");
                   1559: <h4>$lt{'addn'}</h4> 
1.18      albertel 1560: END
                   1561:     $r->print(&Apache::loncommon::start_data_table());
                   1562:     $r->print(<<"END");
1.16      albertel 1563:    <tr>
1.44      raeburn  1564:      <th>$ltext->{'dura'}</th>
                   1565:      <th>$ltext->{'even'} $lt{'exam'}</th>
                   1566:      <th>$ltext->{'blck'}</th>
                   1567:      <th>$ltext->{'actn'}?</th>
1.16      albertel 1568:    </tr>
1.18      albertel 1569: END
1.44      raeburn  1570:     $r->print(&Apache::loncommon::start_data_table_row());
1.18      albertel 1571:     $r->print(<<"END");
1.44      raeburn  1572:      <td>$ltext->{'star'}:&nbsp;$startform<br />$ltext->{'endd'}:&nbsp;&nbsp;$endform</td>
1.16      albertel 1573:      <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
1.44      raeburn  1574:      <td>
                   1575: END
                   1576:     foreach my $block (@{$typeorder}) {
                   1577:         $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" value="1" />'.$types->{$block}.'</label><br />');
                   1578:      }
                   1579:      $r->print(<<"END");
                   1580:      </td> 
1.16      albertel 1581:      <td><label>$lt{'addb'}?&nbsp;<input type="checkbox" name="add_$parmcount" value="1" /></label></td>
1.1       albertel 1582: END
1.18      albertel 1583:     $r->print(&Apache::loncommon::end_data_table_row());
                   1584:     $r->print(&Apache::loncommon::end_data_table());
1.1       albertel 1585:     return;
                   1586: }
                   1587: 
1.44      raeburn  1588: sub blocktype_text {
                   1589:     my %types = &Apache::lonlocal::texthash(
                   1590:         'com' => 'Messaging',
                   1591:         'chat' => 'Chat',
                   1592:         'boards' => 'Discussion',
                   1593:         'port' => 'Portfolio',
1.45    ! raeburn  1594:         'groups' => 'Groups',
        !          1595:         'blogs' => 'Blogs',
1.18      albertel 1596:     );
1.45    ! raeburn  1597:     my $typeorder = ['com','chat','boards','port','groups','blogs'];
1.44      raeburn  1598:     return ($typeorder,\%types);
1.1       albertel 1599: }
                   1600: 
                   1601: # ----------------------------------------------------------- Display a message
                   1602: 
                   1603: sub displaymessage {
                   1604:     my ($r,$msgid,$folder)=@_;
                   1605:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
                   1606:     my %blocked = ();
                   1607:     my %setters = ();
                   1608:     my $numblocked = 0;
1.33      albertel 1609:     my $crstype = &Apache::loncommon::course_type();
1.30      raeburn  1610: 
1.1       albertel 1611: # info to generate "next" and "previous" buttons and check if message is blocked
1.44      raeburn  1612:     my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.1       albertel 1613:     my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder);
                   1614:     if ( $blocked{$msgid} eq 'ON' ) {
                   1615:         &printheader($r,'/adm/email',&mt('Display a Message'));
                   1616:         $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.'));
                   1617:         &build_block_table($r,$startblock,$endblock,\%setters);
                   1618:         return;
                   1619:     }
                   1620:     &statuschange($msgid,'read',$folder);
                   1621:     my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
                   1622:     my %content=&Apache::lonmsg::unpackagemsg($message{$msgid});
                   1623: 
                   1624:     my $counter=0;
                   1625:     $r->print('<pre>');
1.29      www      1626:     my $escmsgid=&escape($msgid);
1.1       albertel 1627:     foreach (@messages) {
                   1628: 	if ($_->[5] eq $escmsgid){
                   1629: 	    last;
                   1630: 	}
                   1631: 	$counter++;
                   1632:     }
                   1633:     $r->print('</pre>');
                   1634:     my $number_of_messages = scalar(@messages); #subtract 1 for last index
                   1635: # start output
1.29      www      1636:     &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'});
1.1       albertel 1637:     my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'});
                   1638: # Functions
                   1639:     $r->print('<table border="2" width="100%"><tr bgcolor="#FFFFAA"><td>'.&mt('Functions').':</td>'.
1.29      www      1640: 	      '<td><a href="/adm/email?replyto='.&escape($msgid).$sqs.
1.1       albertel 1641: 	      '"><b>'.&mt('Reply').'</b></a></td>'.
1.29      www      1642: 	      '<td><a href="/adm/email?forward='.&escape($msgid).$sqs.
1.1       albertel 1643: 	      '"><b>'.&mt('Forward').'</b></a></td>'.
1.29      www      1644: 	      '<td><a href="/adm/email?markunread='.&escape($msgid).$sqs.
1.1       albertel 1645: 	      '"><b>'.&mt('Mark Unread').'</b></a></td>'.
1.29      www      1646: 	      '<td><a href="/adm/email?markdel='.&escape($msgid).$sqs.
1.1       albertel 1647: 	      '"><b>'.&mt('Delete').'</b></a></td>'.
                   1648: 	      '<td><a href="/adm/email?'.$sqs.
                   1649: 	      ($env{'form.dismode'} eq 'new'?'&folder=new':'').
                   1650: 	      '"><b>'.&mt('Back to Folder Display').'</b></a></td>');
                   1651:     if ($counter > 0){
                   1652: 	$r->print('<td><a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.
                   1653: 		  '"><b>'.&mt('Previous').'</b></a></td>');
                   1654:     }
                   1655:     if ($counter < $number_of_messages - 1){
                   1656: 	$r->print('<td><a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.
                   1657: 		  '"><b>'.&mt('Next').'</b></a></td>');
                   1658:     }
                   1659:     $r->print('</tr></table>');
                   1660:     if ($env{'user.adv'}) {
                   1661: 	$r->print('<table border="2" width="100%"><tr bgcolor="#FFAAAA"><td>'.&mt('Currently available actions (will open extra window)').':</td>');
                   1662: 	my $symb=&Apache::lonnet::symbread($content{'baseurl'});      
                   1663: 	if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
                   1664: 		$r->print('<td><b>'.&Apache::loncommon::track_student_link(&mt('View recent activity'),$content{'sendername'},$content{'senderdomain'},'check').'</b></td>');
                   1665: 	    }
                   1666: 	if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
                   1667: 	    $r->print('<td><b>'.&Apache::loncommon::pprmlink(&mt('Set/Change parameters'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
                   1668: 	}
                   1669: 	if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
                   1670: 	    $r->print('<td><b>'.&Apache::loncommon::pgrdlink(&mt('Set/Change grades'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
                   1671: 	}
                   1672: 	$r->print('</tr></table>');
                   1673:     }
                   1674:     my $tolist;
                   1675:     my @recipients = ();
                   1676:     for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
                   1677:         $recipients[$i] =  &Apache::loncommon::aboutmewrapper(
                   1678:            &Apache::loncommon::plainname($content{'recuser'}[$i],
                   1679:                                       $content{'recdomain'}[$i]),
                   1680:               $content{'recuser'}[$i],$content{'recdomain'}[$i]).
                   1681:        ' ('.$content{'recuser'}[$i].' at '.$content{'recdomain'}[$i].') ';
                   1682:     }
                   1683:     $tolist = join(', ',@recipients);
                   1684:     $r->print('<br /><b>'.&mt('Subject').':</b> '.$content{'subject'}.
                   1685: 	      ($folder ne 'sent'?'<br /><b>'.&mt('From').':</b> '.
                   1686: 	      &Apache::loncommon::aboutmewrapper(
                   1687: 						 &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
                   1688: 						 $content{'sendername'},$content{'senderdomain'}).' ('.
                   1689: 	      $content{'sendername'}.' at '.
                   1690: 	      $content{'senderdomain'}.') ':'<br /><b>'.&mt('To').':</b> '.
                   1691:               $tolist).
1.30      raeburn  1692: 	      ($content{'courseid'}?'<br /><b>'.&mt($crstype).':</b> '.$courseinfo{'description'}.
                   1693: 	       ($content{'coursesec'}?' ('.&mt('Section').': '.$content{'coursesec'}.')':''):'').
1.1       albertel 1694: 	      '<br /><b>'.&mt('Time').':</b> '.$content{'time'}.
                   1695: 	      ($content{'baseurl'}?'<br /><b>'.&mt('Refers to').':</b> <a href="'.$content{'baseurl'}.'">'.
                   1696: 	       $content{'baseurl'}.' ('.&Apache::lonnet::gettitle($content{'baseurl'}).')</a>':'').
                   1697: 	      '<p><pre>'.
                   1698: 	      &Apache::lontexconvert::msgtexconverted($content{'message'},1).
                   1699: 	      '</pre><hr />'.&displayresource(%content).'</p>');
                   1700:     return;   
                   1701: }
                   1702: 
                   1703: # =========================================================== Show the citation
                   1704: 
                   1705: sub displayresource {
                   1706:     my %content=@_;
                   1707: #
                   1708: # If the recipient is in the same course that the message was sent from and
                   1709: # has sufficient privileges, show "all details," else show citation
                   1710: #
                   1711:     if (($env{'request.course.id'} eq $content{'courseid'})
                   1712:      && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
                   1713: 	my $symb=&Apache::lonnet::symbread($content{'baseurl'});
                   1714: # Could not get a symb, give up
                   1715: 	unless ($symb) { return $content{'citation'}; }
                   1716: # Have a symb, can render
                   1717: 	return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
                   1718: 	    &Apache::loncommon::get_previous_attempt($symb,
                   1719: 						     $content{'sendername'},
                   1720: 						     $content{'senderdomain'},
                   1721: 						     $content{'courseid'}).
                   1722: 	    '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
                   1723: 	    &Apache::loncommon::get_student_view($symb,
                   1724: 						 $content{'sendername'},
                   1725: 						 $content{'senderdomain'},
                   1726: 						 $content{'courseid'}).
                   1727: 	    '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
                   1728: 	    &Apache::loncommon::get_student_answers($symb,
                   1729: 						    $content{'sendername'},
                   1730: 						    $content{'senderdomain'},
                   1731: 						    $content{'courseid'});
                   1732:     } elsif ($env{'user.adv'}) {
                   1733: 	return $content{'citation'};
                   1734:     }
                   1735:     return '';
                   1736: }
                   1737: 
                   1738: # ================================================================== The Header
                   1739: 
                   1740: sub header {
                   1741:     my ($r,$title,$baseurl)=@_;
                   1742:     
                   1743:     my $extra = &Apache::loncommon::studentbrowser_javascript();
                   1744:     if ($baseurl) {
1.41      albertel 1745: 	$extra .= "<base href=\"".&Apache::lonnet::absolute_url()."/$baseurl\" />";
1.1       albertel 1746:     }
                   1747:     $r->print(&Apache::loncommon::start_page('Communication and Messages',
1.38      raeburn  1748:  					$extra));
1.1       albertel 1749:     $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.38      raeburn  1750:      		(($title?$title:'Communication and Messages')));
1.1       albertel 1751: }
                   1752: 
                   1753: # ---------------------------------------------------------------- Print header
                   1754: 
                   1755: sub printheader {
                   1756:     my ($r,$url,$desc,$title,$baseurl)=@_;
                   1757:     &Apache::lonhtmlcommon::add_breadcrumb
                   1758: 	({href=>$url,
                   1759: 	  text=>$desc});
                   1760:     &header($r,$title,$baseurl);
                   1761: }
                   1762: 
                   1763: # ------------------------------------------------------------ Store the comment
                   1764: 
                   1765: sub storecomment {
                   1766:     my ($r)=@_;
                   1767:     my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
                   1768:     my $cleanmsgtxt='';
1.42      raeburn  1769:     foreach my $line (split(/[\n\r]/,$msgtxt)) {
                   1770: 	unless ($line=~/^\s*(\>|\&gt\;)/) {
                   1771: 	    $cleanmsgtxt.=$line."\n";
1.1       albertel 1772: 	}
                   1773:     }
1.29      www      1774:     my $key=&escape($env{'form.baseurl'}).'___'.time;
1.1       albertel 1775:     &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
                   1776: }
                   1777: 
                   1778: sub storedcommentlisting {
                   1779:     my ($r)=@_;
                   1780:     my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
1.29      www      1781:        '^'.&escape(&escape($env{'form.showcommentbaseurl'})));
1.1       albertel 1782:     $r->print(&Apache::loncommon::start_page('Stored Comment Listing',undef,
                   1783: 					     {'onlybody' => 1}));
                   1784:     if ((keys %msgs)[0]=~/^error\:/) {
                   1785: 	$r->print(&mt('No stored comments yet.'));
                   1786:     } else {
                   1787: 	my $found=0;
1.42      raeburn  1788: 	foreach my $key (sort(keys(%msgs))) {
                   1789: 	    $r->print("\n".$msgs{$key}."<hr />");
1.1       albertel 1790: 	    $found=1;
                   1791: 	}
                   1792: 	unless ($found) {
                   1793: 	    $r->print(&mt('No stored comments yet for this resource.'));
                   1794: 	}
                   1795:     }
                   1796: }
                   1797: 
                   1798: # ---------------------------------------------------------------- Send an email
                   1799: 
                   1800: sub sendoffmail {
                   1801:     my ($r,$folder)=@_;
                   1802:     my $suffix=&Apache::lonmsg::foldersuffix($folder);
                   1803:     my $sendstatus='';
                   1804:     my %specialmsg_status;
                   1805:     my $numspecial = 0;
1.38      raeburn  1806:     my ($cdom,$cnum,$group);
                   1807:     if (exists($env{'form.group'})) {
                   1808:         $group = $env{'form.group'};
                   1809:     }
                   1810:     if (exists($env{'request.course.id'})) {
                   1811:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   1812:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1813:     }
1.1       albertel 1814:     if ($env{'form.send'}) {
1.38      raeburn  1815:         if ($group eq '') {
                   1816: 	    &printheader($r,'','Messages being sent.');
                   1817:         } else {
                   1818:             $r->print(&groupmail_header('sending',$group));
                   1819:         }
1.1       albertel 1820: 	$r->rflush();
                   1821: 	my %content=();
                   1822: 	undef %content;
                   1823: 	if ($env{'form.forwid'}) {
                   1824: 	    my $msgid=$env{'form.forwid'};
                   1825: 	    my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
                   1826: 	    %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
                   1827: 	    &statuschange($msgid,'forwarded',$folder);
                   1828: 	    $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
                   1829: 		$content{'message'};
                   1830: 	}
                   1831: 	if ($env{'form.replyid'}) {
                   1832: 	    my $msgid=$env{'form.replyid'};
                   1833: 	    my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
                   1834: 	    %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
                   1835: 	    &statuschange($msgid,'replied',$folder);
                   1836: 	}
1.13      albertel 1837: 
1.35      albertel 1838: 	my @to =
1.37      raeburn  1839: 	    &Apache::loncommon::get_env_multiple('form.selectedusers_forminput');
1.25      foxr     1840: 	my $mode = $env{'form.sendmode'};
                   1841: 
1.13      albertel 1842: 	my %toaddr;
1.35      albertel 1843: 	if (@to) {
                   1844: 	    foreach my $dest (@to) {
1.27      albertel 1845: 		my ($user,$domain) = split(/:/, $dest);
1.25      foxr     1846: 		if (($user ne '') && ($domain ne '')) {
                   1847: 		    my $address = $user.":".$domain; # How the code below expects it.
                   1848: 		    $toaddr{$address} = '';
                   1849: 		}
                   1850: 	    }
                   1851: 	}
                   1852: 
1.1       albertel 1853: 	if ($env{'form.sendmode'} eq 'group') {
1.25      foxr     1854: 	     foreach my $address (keys(%env)) {
                   1855: 	 	if ($address=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
                   1856: 	 	    $toaddr{$1}='';
                   1857: 	 	}
1.1       albertel 1858: 	    }
                   1859: 	} elsif ($env{'form.sendmode'} eq 'upload') {
1.13      albertel 1860: 	    foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
1.43      raeburn  1861:                 my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/);
1.1       albertel 1862: 		if ($txt) {
1.43      raeburn  1863:                     $rec =~ s/^\s+//;
1.44      raeburn  1864:                     $rec =~ s/\s+$//;
1.1       albertel 1865: 		    $toaddr{$rec}.=$txt."\n";
                   1866: 		}
                   1867: 	    }
                   1868: 	} else {
1.25      foxr     1869: 	    if (($env{'form.recuname'} ne '') && ($env{'form.recdomain'} ne '')) {
                   1870: 		$toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
                   1871: 	    }
1.1       albertel 1872: 	}
                   1873: 	if ($env{'form.additionalrec'}) {
1.42      raeburn  1874: 	    foreach my $rec (split(/\,/,$env{'form.additionalrec'})) {
1.43      raeburn  1875: 		my ($auname,$audom)=split(/:/,$rec);
1.25      foxr     1876: 		if (($auname ne "") && ($audom ne "")) {
                   1877: 		    $toaddr{$auname.':'.$audom}='';
                   1878: 		}
1.1       albertel 1879: 	    }
                   1880: 	}
                   1881: 
                   1882:         my $savemsg;
                   1883:         my $msgtype;
                   1884:         my %sentmessage;
1.7       albertel 1885:         my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'},
                   1886: 							 undef,1);
1.1       albertel 1887:         if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
                   1888:             (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                   1889: 	     || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                   1890: 					 '/'.$env{'request.course.sec'})
                   1891: 	     )) {
                   1892:             $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
                   1893:             $msgtype = 'critical';
                   1894:         } else {
                   1895:             $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
                   1896:         }
                   1897: 	
1.13      albertel 1898: 	foreach my $address (sort(keys(%toaddr))) {
                   1899: 	    my ($recuname,$recdomain)=split(/\:/,$address);
1.1       albertel 1900:             my $msgtxt = $savemsg;
1.13      albertel 1901: 	    if ($toaddr{$address}) { $msgtxt.='<hr />'.$toaddr{$address}; }
1.12      albertel 1902: 	    my @thismsg;
1.1       albertel 1903: 	    if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) && 
                   1904: 		(&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                   1905: 		 || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                   1906: 					     '/'.$env{'request.course.sec'}))) {
1.13      albertel 1907: 		$r->print(&mt('Sending critical message').' '.$recuname.':'.$recdomain.': ');
                   1908: 		@thismsg=
                   1909: 		    &Apache::lonmsg::user_crit_msg($recuname,$recdomain,
                   1910: 						   $msgsubj,$msgtxt,
                   1911: 						   $env{'form.sendbck'},
                   1912: 						   $env{'form.permanent'},
                   1913: 						   \$sentmessage{$address});
1.1       albertel 1914: 	    } else {
1.14      albertel 1915: 		$r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': ');
1.13      albertel 1916: 		@thismsg=
                   1917: 		    &Apache::lonmsg::user_normal_msg($recuname,$recdomain,
                   1918: 						     $msgsubj,$msgtxt,
                   1919: 						     $content{'citation'},
                   1920: 						     undef,undef,
                   1921: 						     $env{'form.permanent'},
                   1922: 						     \$sentmessage{$address});
1.1       albertel 1923:             }
                   1924: 	    if (($env{'request.course.id'}) && (($msgtype eq 'critical') || 
                   1925:                                          ($env{'form.sendmode'} eq 'group'))) {
1.12      albertel 1926: 	        $specialmsg_status{$recuname.':'.$recdomain} =
                   1927: 		    join(' ',@thismsg);
                   1928: 		foreach my $result (@thismsg) {
                   1929: 		    if ($result eq 'ok') {
                   1930: 			$numspecial++;
                   1931: 		    }
                   1932: 		}
1.1       albertel 1933: 	    }
1.12      albertel 1934: 	    $sendstatus.=' '.join(' ',@thismsg);
1.1       albertel 1935: 	}
                   1936:         if (($env{'request.course.id'}) && (($env{'form.sendmode'} eq 'group')
                   1937:                                               || ($msgtype eq 'critical'))) {
                   1938:             my $subj_prefix;
                   1939:             if ($msgtype eq 'critical') {
                   1940:                 $subj_prefix = 'Critical.';
                   1941:             } else {
                   1942:                 $subj_prefix = 'Broadcast.';
                   1943:             }
                   1944:             my ($specialmsgid,$specialresult);
1.29      www      1945:             my $course_str = &escape('['.$cnum.':'.$cdom.']');
1.1       albertel 1946: 
                   1947:             if ($numspecial) {
                   1948:                 $specialresult = &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
                   1949:                     ' '.$course_str,$savemsg,undef,undef,undef,
                   1950:                     undef,undef,\$specialmsgid);
1.29      www      1951:                 $specialmsgid = &unescape($specialmsgid);
1.1       albertel 1952:             }
                   1953:             if ($specialresult eq 'ok') {
                   1954:                 my $record_sent;
1.13      albertel 1955:                 my @recusers;
                   1956:                 my @recudoms;
                   1957:                 my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
1.29      www      1958: 		    split(/\:/,&unescape($specialmsgid));
1.13      albertel 1959: 
1.1       albertel 1960:                 foreach my $recipient (sort(keys(%toaddr))) {
                   1961:                     if ($specialmsg_status{$recipient} eq 'ok') {
                   1962:                         my $usersubj = $subj_prefix.'['.$recipient.']';
                   1963:                         my $usermsgid = 
                   1964: 			    &Apache::lonmsg::buildmsgid($stamp,$usersubj,
                   1965: 							$msgname,$msgdom,
                   1966: 							$msgcount,$context,
                   1967: 							$pid);
                   1968:                         &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
                   1969:                                              ' ['.$recipient.']',$msgsubj,undef,
                   1970:                         undef,undef,undef,$usermsgid,undef,undef,$specialmsgid);
1.13      albertel 1971:                         my ($uname,$udom) = split(/:/,$recipient);
1.1       albertel 1972:                         push(@recusers,$uname);
                   1973:                         push(@recudoms,$udom);
                   1974:                     }
                   1975:                 }
                   1976:                 if (@recusers) {
                   1977:                     my $specialmessage;
1.13      albertel 1978:                     my $sentsubj = 
                   1979: 			$subj_prefix.' ('.$numspecial.' sent) '.$msgsubj;
1.1       albertel 1980:                     $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
                   1981:                     my $sentmsgid = 
                   1982: 			&Apache::lonmsg::buildmsgid($stamp,$sentsubj,$msgname,
                   1983: 						    $msgdom,$msgcount,$context,
                   1984: 						    $pid);
                   1985:                     ($specialmsgid,$specialmessage) = &Apache::lonmsg::packagemsg($msgsubj,$savemsg,
                   1986:                             undef,undef,undef,\@recusers,\@recudoms,$sentmsgid);
                   1987:                     $record_sent = &Apache::lonmsg::store_sent_mail($specialmsgid,$specialmessage);
                   1988:                 }
                   1989:             } else {
                   1990:                 &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');
                   1991:             }
                   1992:         }
                   1993:     } else {
                   1994: 	&printheader($r,'','No messages sent.'); 
                   1995:     }
                   1996:     if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
1.5       albertel 1997: 	$r->print('<br /><span class="LC_success">'.&mt('Completed.').'</span>');
1.1       albertel 1998: 	if ($env{'form.displayedcrit'}) {
                   1999: 	    &discrit($r);
1.38      raeburn  2000:         }
                   2001:         if ($group ne '') {
                   2002:             $r->print(&groupmail_sent($group,$cdom,$cnum)); 
1.1       albertel 2003: 	} else {
                   2004: 	    &Apache::loncommunicate::menu($r);
                   2005: 	}
                   2006:     } else {
1.5       albertel 2007: 	$r->print('<p><span class="LC_error">'.&mt('Could not deliver message').'</span> '.
1.25      foxr     2008: 		  &mt('Please use the browser "Back" button and correct the recipient addresses '."($sendstatus)").'</p>');
1.1       albertel 2009:     }
                   2010: }
                   2011: 
                   2012: # ===================================================================== Handler
                   2013: 
                   2014: sub handler {
                   2015:     my $r=shift;
                   2016: 
                   2017: # ----------------------------------------------------------- Set document type
                   2018:     
                   2019:     &Apache::loncommon::content_type($r,'text/html');
                   2020:     $r->send_http_header;
                   2021:     
                   2022:     return OK if $r->header_only;
                   2023:     
                   2024: # --------------------------- Get query string for limited number of parameters
                   2025:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   2026:         ['display','replyto','forward','markread','markdel','markunread',
                   2027:          'sendreply','compose','sendmail','critical','recname','recdom',
                   2028:          'recordftf','sortedby','block','folder','startdis','interdis',
1.38      raeburn  2029: 	 'showcommentbaseurl','dismode','group','subject','text','ref']);
1.1       albertel 2030:     $sqs='&sortedby='.$env{'form.sortedby'};
                   2031: 
                   2032: # ------------------------------------------------------ They checked for email
                   2033:     unless ($env{'form.block'}) {
                   2034:         &Apache::lonnet::put('email_status',{'recnewemail'=>0});
                   2035:     }
                   2036: 
                   2037: # ----------------------------------------------------------------- Breadcrumbs
                   2038: 
                   2039:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                   2040:     &Apache::lonhtmlcommon::add_breadcrumb
                   2041:         ({href=>"/adm/communicate",
                   2042:           text=>"Communication/Messages",
                   2043:           faq=>12,bug=>'Communication Tools',});
                   2044: 
                   2045: # ------------------------------------------------------------------ Get Folder
                   2046: 
                   2047:     my $folder=$env{'form.folder'};
                   2048:     unless ($folder) { 
                   2049: 	$folder=''; 
                   2050:     } else {
1.29      www      2051: 	$sqs.='&folder='.&escape($folder);
1.1       albertel 2052:     }
                   2053: # ------------------------------------------------------------ Get Display Mode
                   2054: 
                   2055:     my $dismode=$env{'form.dismode'};
                   2056:     unless ($dismode) { 
                   2057: 	$dismode=''; 
                   2058:     } else {
1.29      www      2059: 	$sqs.='&dismode='.&escape($dismode);
1.1       albertel 2060:     }
                   2061: 
                   2062: # --------------------------------------------------------------------- Display
                   2063: 
                   2064:     $startdis=$env{'form.startdis'};
                   2065:     $startdis--;
                   2066:     unless ($startdis) { $startdis=0; }
                   2067: 
                   2068:     $interdis=$env{'form.interdis'};
                   2069:     unless ($interdis) { $interdis=20; }
                   2070:     $sqs.='&interdis='.$interdis;
                   2071: 
                   2072:     if ($env{'form.firstview'}) {
                   2073: 	$startdis=0;
                   2074:     }
                   2075:     if ($env{'form.lastview'}) {
                   2076: 	$startdis=-1;
                   2077:     }
                   2078:     if ($env{'form.prevview'}) {
                   2079: 	$startdis--;
                   2080:     }
                   2081:     if ($env{'form.nextview'}) {
                   2082: 	$startdis++;
                   2083:     }
                   2084:     my $postedstartdis=$startdis+1;
                   2085:     $sqs.='&startdis='.$postedstartdis;
                   2086: 
                   2087: # --------------------------------------------------------------- Render Output
                   2088: 
                   2089:     if ($env{'form.display'}) {
                   2090: 	&displaymessage($r,$env{'form.display'},$folder);
                   2091:     } elsif ($env{'form.replyto'}) {
                   2092: 	&compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode);
                   2093:     } elsif ($env{'form.confirm'}) {
                   2094: 	&printheader($r,'','Confirmed Receipt');
1.36      albertel 2095: 	my $replying = 0;
1.42      raeburn  2096: 	foreach my $envkey (keys(%env)) {
                   2097: 	    if ($envkey=~/^form\.rec\_(.*)$/) {
1.1       albertel 2098: 		$r->print('<b>'.&mt('Confirming Receipt').':</b> '.
                   2099: 			  &Apache::lonmsg::user_crit_received($1).'<br>');
                   2100: 	    }
1.42      raeburn  2101: 	    if ($envkey=~/^form\.reprec\_(.*)$/) {
1.1       albertel 2102: 		my $msgid=$1;
                   2103: 		$r->print('<b>'.&mt('Confirming Receipt').':</b> '.
                   2104: 			  &Apache::lonmsg::user_crit_received($msgid).'<br>');
                   2105: 		&compout($r,'','','',$msgid);
1.36      albertel 2106: 		$replying = 1;
1.1       albertel 2107: 	    }
                   2108: 	}
1.36      albertel 2109: 	if (!$replying) {
                   2110: 	    &discrit($r);
                   2111: 	}
1.1       albertel 2112:     } elsif ($env{'form.critical'}) {
                   2113: 	&printheader($r,'','Displaying Critical Messages');
                   2114: 	&discrit($r);
                   2115:     } elsif ($env{'form.forward'}) {
                   2116: 	&compout($r,$env{'form.forward'},undef,undef,undef,$folder);
                   2117:     } elsif ($env{'form.markdel'}) {
                   2118: 	&printheader($r,'','Deleted Message');
1.9       albertel 2119: 	my ($result,$msg) = 
                   2120: 	    &statuschange($env{'form.markdel'},'deleted',$folder);
                   2121: 	if (!$result) {
1.10      albertel 2122: 	    $r->print('<p class="LC_error">'.
                   2123: 		      &mt('Failed to delete the message.').'</p>'.
1.9       albertel 2124: 		      '<p class="LC_error">'.$msg."</p>\n");
                   2125: 	}
1.1       albertel 2126: 	&Apache::loncommunicate::menu($r);
                   2127: 	&disall($r,($folder?$folder:$dismode));
                   2128:     } elsif ($env{'form.markedmove'}) {
1.9       albertel 2129: 	my ($total,$failed,@failed_msg)=(0,0);
                   2130: 	foreach my $key (keys(%env)) {
                   2131: 	    if ($key=~/^form\.delmark_(.*)$/) {
                   2132: 		my ($result,$msg) =
1.29      www      2133: 		    &movemsg(&unescape($1),$folder,
1.9       albertel 2134: 			     $env{'form.movetofolder'});
                   2135: 		if ($result) {
                   2136: 		    $total++;
                   2137: 		} else {
                   2138: 		    $failed++;
                   2139: 		    push(@failed_msg,$msg);
                   2140: 		}
1.1       albertel 2141: 	    }
                   2142: 	}
                   2143: 	&printheader($r,'','Moved Messages');
1.9       albertel 2144: 	if ($failed) {
                   2145: 	    $r->print('<p class="LC_error">
1.10      albertel 2146:                           '.&mt('Failed to move [_1] message(s)',$failed).
                   2147: 		      '</p>');
1.9       albertel 2148: 	    $r->print('<p class="LC_error">'.
                   2149: 		      join("</p>\n<p class=\"LC_error\">",@failed_msg).
                   2150: 		      "</p>\n");
                   2151: 	}
1.10      albertel 2152: 	$r->print(&mt('Moved [_1] message(s)',$total).'<p>');
1.1       albertel 2153: 	&Apache::loncommunicate::menu($r);
                   2154: 	&disall($r,($folder?$folder:$dismode));
                   2155:     } elsif ($env{'form.markeddel'}) {
1.9       albertel 2156: 	my ($total,$failed,@failed_msg)=(0,0);
                   2157: 	foreach my $key (keys(%env)) {
                   2158: 	    if ($key=~/^form\.delmark_(.*)$/) {
                   2159: 		my ($result,$msg) = 
1.29      www      2160: 		    &statuschange(&unescape($1),'deleted',
1.9       albertel 2161: 				  $folder);
                   2162: 		if ($result) {
                   2163: 		    $total++;
                   2164: 		} else {
                   2165: 		    $failed++;
                   2166: 		    push(@failed_msg,$msg);
                   2167: 		}
1.1       albertel 2168: 	    }
                   2169: 	}
                   2170: 	&printheader($r,'','Deleted Messages');
1.9       albertel 2171: 	if ($failed) {
                   2172: 	    $r->print('<p class="LC_error">
1.10      albertel 2173:                           '.&mt('Failed to delete [_1] message(s)',$failed).
                   2174: 		      '</p>');
1.9       albertel 2175: 	    $r->print('<p class="LC_error">'.
                   2176: 		      join("</p>\n<p class=\"LC_error\">",@failed_msg).
                   2177: 		      "</p>\n");
                   2178: 	}
1.10      albertel 2179: 	$r->print(&mt('Deleted [_1] message(s)',$total).'<p>');
1.1       albertel 2180: 	&Apache::loncommunicate::menu($r);
                   2181: 	&disall($r,($folder?$folder:$dismode));
                   2182:     } elsif ($env{'form.markunread'}) {
                   2183: 	&printheader($r,'','Marked Message as Unread');
                   2184: 	&statuschange($env{'form.markunread'},'new');
                   2185: 	&Apache::loncommunicate::menu($r);
                   2186: 	&disall($r,($folder?$folder:$dismode));
                   2187:     } elsif ($env{'form.compose'}) {
                   2188: 	&compout($r,'','',$env{'form.compose'});
                   2189:     } elsif ($env{'form.recordftf'}) {
                   2190: 	&facetoface($r,$env{'form.recordftf'});
                   2191:     } elsif ($env{'form.block'}) {
                   2192:         &examblock($r,$env{'form.block'});
                   2193:     } elsif ($env{'form.sendmail'}) {
                   2194: 	&sendoffmail($r,$folder);
                   2195: 	if ($env{'form.storebasecomment'}) {
                   2196: 	    &storecomment($r);
1.38      raeburn  2197:         }
1.1       albertel 2198: 	if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
1.38      raeburn  2199: 	        &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
1.1       albertel 2200: 				      $env{'course.'.$env{'request.course.id'}.'.domain'},
                   2201: 				      'Course_Announcements',
                   2202: 				      $env{'form.subject'},
                   2203: 				      $env{'form.message'},'/adm/communicate','public');
                   2204: 	}
1.38      raeburn  2205: 	if ((!exists($env{'form.group'})) && (!$env{'form.displayedcrit'})) {
1.36      albertel 2206: 	    &disall($r,($folder?$folder:$dismode));
                   2207: 	}
1.1       albertel 2208:     } elsif ($env{'form.newfolder'}) {
                   2209: 	&printheader($r,'','New Folder');
                   2210: 	&makefolder($env{'form.newfolder'});
                   2211: 	&Apache::loncommunicate::menu($r);
                   2212: 	&disall($r,$env{'form.newfolder'});
                   2213:     } elsif ($env{'form.showcommentbaseurl'}) {
                   2214: 	&storedcommentlisting($r);
                   2215:     } else {
                   2216: 	&printheader($r,'','Display All Messages');
1.44      raeburn  2217: 	&Apache::loncommunicate::menu($r);
1.1       albertel 2218: 	&disall($r,($folder?$folder:$dismode));
                   2219:     }
                   2220:     $r->print(&Apache::loncommon::end_page());
                   2221:     return OK;
                   2222: }
                   2223: # ================================================= Main program, reset counter
                   2224: 
                   2225: =pod
                   2226: 
                   2227: =back
                   2228: 
                   2229: =cut
                   2230: 
                   2231: 1; 
                   2232: 
                   2233: __END__
                   2234: 

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