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

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

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