Annotation of loncom/interface/lonmsg.pm, revision 1.153

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

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