File:  [LON-CAPA] / loncom / interface / lonmsg.pm
Revision 1.67: download - view: text, annotated - select for diffs
Wed Oct 15 18:01:10 2003 UTC (20 years, 8 months ago) by www
Branches: MAIN
CVS tags: HEAD
I was going to work on something else ... anyway, more i18n.

    1: # The LearningOnline Network with CAPA
    2: # Routines for messaging
    3: #
    4: # $Id: lonmsg.pm,v 1.67 2003/10/15 18:01:10 www Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: #
   29: # (Routines to control the menu
   30: #
   31: # (TeX Conversion Module
   32: #
   33: # 05/29/00,05/30 Gerd Kortemeyer)
   34: #
   35: # 10/05 Gerd Kortemeyer)
   36: #
   37: # 10/19,10/20,10/30,
   38: # 02/06/01 Gerd Kortemeyer
   39: # 07/27 Guy Albertelli
   40: # 07/27,07/28,07/30,08/03,08/06,08/08,08/09,08/10,8/13,8/15,
   41: # 10/1,11/5 Gerd Kortemeyer
   42: # YEAR=2002
   43: # 1/1,3/18 Gerd Kortemeyer
   44: #
   45: package Apache::lonmsg;
   46: 
   47: =pod
   48: 
   49: =head1 NAME
   50: 
   51: Apache::lonmsg: supports internal messaging
   52: 
   53: =head1 SYNOPSIS
   54: 
   55: lonmsg provides routines for sending messages, receiving messages, and
   56: a handler to allow users to read, send, and delete messages.
   57: 
   58: =head1 OVERVIEW
   59: 
   60: =head2 Messaging Overview
   61: 
   62: X<messages>LON-CAPA provides an internal messaging system similar to
   63: email, but customized for LON-CAPA's usage. LON-CAPA implements its
   64: own messaging system, rather then building on top of email, because of
   65: the features LON-CAPA messages can offer that conventional e-mail can
   66: not:
   67: 
   68: =over 4
   69: 
   70: =item * B<Critical messages>: A message the recipient B<must>
   71: acknowlegde receipt of before they are allowed to continue using the
   72: system, preventing a user from claiming they never got a message
   73: 
   74: =item * B<Receipts>: LON-CAPA can reliably send reciepts informing the
   75: sender that it has been read; again, useful for preventing students
   76: from claiming they did not see a message. (While conventional e-mail
   77: has some reciept support, it's sporadic, e-mail client-specific, and
   78: generally the receiver can opt to not send one, making it useless in
   79: this case.)
   80: 
   81: =item * B<Context>: LON-CAPA knows about the sender, such as where
   82: they are in a course. When a student mails an instructor asking for
   83: help on the problem, the instructor receives not just the student's
   84: question, but all submissions the student has made up to that point,
   85: the user's rendering of the problem, and the complete view the student
   86: saw of the resource, including discussion up to that point. Finally,
   87: the instructor is reading all of this inside of LON-CAPA, not their
   88: email program, so they have full access to LON-CAPA's grading
   89: interface, or other features they may wish to use in response to the
   90: student's query.
   91: 
   92: =back
   93: 
   94: Users can ask LON-CAPA to forward messages to conventional e-mail
   95: addresses on their B<PREF> screen, but generally, LON-CAPA messages
   96: are much more useful then traditional email can be made to be, even
   97: with HTML support.
   98: 
   99: Right now, this document will cover just how to send a message, since
  100: it is likely you will not need to programmatically read messages,
  101: since lonmsg already implements that functionality.
  102: 
  103: =head1 FUNCTIONS
  104: 
  105: =over 4
  106: 
  107: =cut
  108: 
  109: use strict;
  110: use Apache::lonnet();
  111: use vars qw($msgcount);
  112: use HTML::TokeParser();
  113: use Apache::Constants qw(:common);
  114: use Apache::loncommon();
  115: use Apache::lontexconvert();
  116: use HTML::Entities();
  117: use Mail::Send;
  118: use Apache::lonlocal;
  119: 
  120: # Querystring component with sorting type
  121: my $sqs;
  122: 
  123: # ===================================================================== Package
  124: 
  125: sub packagemsg {
  126:     my ($subject,$message,$citation,$baseurl,$attachmenturl)=@_;
  127:     $message =&HTML::Entities::encode($message);
  128:     $citation=&HTML::Entities::encode($citation);
  129:     $subject =&HTML::Entities::encode($subject);
  130:     #remove machine specification
  131:     $baseurl =~ s|^http://[^/]+/|/|;
  132:     $baseurl =&HTML::Entities::encode($baseurl);
  133:     #remove machine specification
  134:     $attachmenturl =~ s|^http://[^/]+/|/|;
  135:     $attachmenturl =&HTML::Entities::encode($attachmenturl);
  136: 
  137:     my $now=time;
  138:     $msgcount++;
  139:     my $partsubj=$subject;
  140:     $partsubj=&Apache::lonnet::escape($partsubj);
  141:     my $msgid=&Apache::lonnet::escape(
  142:            $now.':'.$partsubj.':'.$ENV{'user.name'}.':'.
  143:            $ENV{'user.domain'}.':'.$msgcount.':'.$$);
  144:     my $result='<sendername>'.$ENV{'user.name'}.'</sendername>'.
  145:            '<senderdomain>'.$ENV{'user.domain'}.'</senderdomain>'.
  146:            '<subject>'.$subject.'</subject>'.
  147: 	   '<time>'.&Apache::lonlocal::locallocaltime($now).'</time>'.
  148: 	   '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
  149:            '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
  150: 	   '<client>'.$ENV{'REMOTE_ADDR'}.'</client>'.
  151: 	   '<browsertype>'.$ENV{'browser.type'}.'</browsertype>'.
  152: 	   '<browseros>'.$ENV{'browser.os'}.'</browseros>'.
  153: 	   '<browserversion>'.$ENV{'browser.version'}.'</browserversion>'.
  154:            '<browsermathml>'.$ENV{'browser.mathml'}.'</browsermathml>'.
  155: 	   '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
  156: 	   '<courseid>'.$ENV{'request.course.id'}.'</courseid>'.
  157: 	   '<role>'.$ENV{'request.role'}.'</role>'.
  158: 	   '<resource>'.$ENV{'request.filename'}.'</resource>'.
  159:            '<msgid>'.$msgid.'</msgid>'.
  160: 	   '<message>'.$message.'</message>';
  161:     if (defined($citation)) {
  162: 	$result.='<citation>'.$citation.'</citation>';
  163:     }
  164:     if (defined($baseurl)) {
  165: 	$result.= '<baseurl>'.$baseurl.'</baseurl>';
  166:     }
  167:     if (defined($attachmenturl)) {
  168: 	$result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>';
  169:     }
  170:     return $msgid,$result;
  171: }
  172: 
  173: # ================================================== Unpack message into a hash
  174: 
  175: sub unpackagemsg {
  176:     my ($message,$notoken)=@_;
  177:     my %content=();
  178:     my $parser=HTML::TokeParser->new(\$message);
  179:     my $token;
  180:     while ($token=$parser->get_token) {
  181:        if ($token->[0] eq 'S') {
  182: 	   my $entry=$token->[1];
  183:            my $value=$parser->get_text('/'.$entry);
  184:            $content{$entry}=$value;
  185:        }
  186:     }
  187:     if ($content{'attachmenturl'}) {
  188:        my ($fname,$ft)=($content{'attachmenturl'}=~/\/(\w+)\.(\w+)$/);
  189:        if ($notoken) {
  190: 	   $content{'message'}.='<p>'.&mt('Attachment').': <tt>'.$fname.'.'.$ft.'</tt>';
  191:        } else {
  192: 	   $content{'message'}.='<p>'.&mt('Attachment').': <a href="'.
  193: 	       &Apache::lonnet::tokenwrapper($content{'attachmenturl'}).
  194: 	       '"><tt>'.$fname.'.'.$ft.'</tt></a>';
  195:        }
  196:     }
  197:     return %content;
  198: }
  199: 
  200: # ======================================================= Get info out of msgid
  201: 
  202: sub unpackmsgid {
  203:     my $msgid=&Apache::lonnet::unescape(shift);
  204:     my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/,
  205:                           &Apache::lonnet::unescape($msgid));
  206:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
  207:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
  208:     unless ($status{$msgid}) { $status{$msgid}='new'; }
  209:     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});
  210: } 
  211: 
  212: 
  213: sub sendemail {
  214:     my ($to,$subject,$body)=@_;
  215:     $body=
  216:     "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n".
  217:     "*** ".&mt('Please do not reply to this address.')."\n\n".$body;
  218:     my $msg = new Mail::Send;
  219:     $msg->to($to);
  220:     $msg->subject('[LON-CAPA] '.$subject);
  221:     my $fh = $msg->open('smtp',Server => 'localhost');
  222:     print $fh $body;
  223:     $fh->close;
  224: }
  225: 
  226: # ==================================================== Send notification emails
  227: 
  228: sub sendnotification {
  229:     my ($to,$touname,$toudom,$subj,$crit)=@_;
  230:     my $sender=$ENV{'environment.firstname'}.' '.$ENV{'environment.lastname'};
  231:     my $critical=($crit?' critical':'');
  232:     my $url='http://'.
  233:       $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}.
  234:       '/adm/email?username='.$touname.'&domain='.$toudom;
  235:     my $body=(<<ENDMSG);
  236: You received a$critical message from $sender in LON-CAPA. The subject is
  237: 
  238:  $subj
  239: 
  240: Use
  241: 
  242:  $url
  243: 
  244: to access this message.
  245: ENDMSG
  246:     &sendemail($to,'New'.$critical.' message from '.$sender,$body);
  247: }
  248: # ============================================================= Check for email
  249: 
  250: sub newmail {
  251:     if ((time-$ENV{'user.mailcheck.time'})>300) {
  252:         my %what=&Apache::lonnet::get('email_status',['recnewemail']);
  253:         &Apache::lonnet::appenv('user.mailcheck.time'=>time);
  254:         if ($what{'recnewemail'}>0) { return 1; }
  255:     }
  256:     return 0;
  257: }
  258: 
  259: # =============================== Automated message to the author of a resource
  260: 
  261: =pod
  262: 
  263: =item * B<author_res_msg($filename, $message)>: Sends message $message to the owner
  264:     of the resource with the URI $filename.
  265: 
  266: =cut
  267: 
  268: sub author_res_msg {
  269:     my ($filename,$message)=@_;
  270:     unless ($message) { return 'empty'; }
  271:     $filename=&Apache::lonnet::declutter($filename);
  272:     my ($domain,$author,@dummy)=split(/\//,$filename);
  273:     my $homeserver=&Apache::lonnet::homeserver($author,$domain);
  274:     if ($homeserver ne 'no_host') {
  275:        my $id=unpack("%32C*",$message);
  276:        my $msgid;
  277:        ($msgid,$message)=&packagemsg($filename,$message);
  278:        return &Apache::lonnet::reply('put:'.$domain.':'.$author.
  279:          ':nohist_res_msgs:'.
  280:           &Apache::lonnet::escape($filename.'_'.$id).'='.
  281:           &Apache::lonnet::escape($message),$homeserver);
  282:     }
  283:     return 'no_host';
  284: }
  285: 
  286: # ================================================== Critical message to a user
  287: 
  288: sub user_crit_msg_raw {
  289:     my ($user,$domain,$subject,$message,$sendback)=@_;
  290: # Check if allowed missing
  291:     my $status='';
  292:     my $msgid='undefined';
  293:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
  294:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
  295:     if ($homeserver ne 'no_host') {
  296:        ($msgid,$message)=&packagemsg($subject,$message);
  297:        if ($sendback) { $message.='<sendback>true</sendback>'; }
  298:        $status=&Apache::lonnet::critical(
  299:            'put:'.$domain.':'.$user.':critical:'.
  300:            &Apache::lonnet::escape($msgid).'='.
  301:            &Apache::lonnet::escape($message),$homeserver);
  302:        if ($ENV{'request.course.id'}) {
  303:           &user_normal_msg_raw(
  304:             $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
  305:             $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  306:             'Critical ['.$user.':'.$domain.']',
  307: 	    $message);
  308:        }
  309:     } else {
  310:        $status='no_host';
  311:     }
  312: # Notifications
  313:     my %userenv = &Apache::lonnet::get('environment',['critnotification'],
  314:                                        $domain,$user);
  315:     if ($userenv{'critnotification'}) {
  316:       &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1);
  317:     }
  318: # Log this
  319:     &Apache::lonnet::logthis(
  320:       'Sending critical email '.$msgid.
  321:       ', log status: '.
  322:       &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
  323:                          $ENV{'user.home'},
  324:       'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
  325:       .$status));
  326:     return $status;
  327: }
  328: 
  329: # New routine that respects "forward" and calls old routine
  330: 
  331: =pod
  332: 
  333: =item * B<user_crit_msg($user, $domain, $subject, $message, $sendback)>: Sends
  334:     a critical message $message to the $user at $domain. If $sendback is true,
  335:     a reciept will be sent to the current user when $user recieves the message.
  336: 
  337: =cut
  338: 
  339: sub user_crit_msg {
  340:     my ($user,$domain,$subject,$message,$sendback)=@_;
  341:     my $status='';
  342:     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
  343:                                        $domain,$user);
  344:     my $msgforward=$userenv{'msgforward'};
  345:     if ($msgforward) {
  346:        foreach (split(/\,/,$msgforward)) {
  347: 	 my ($forwuser,$forwdomain)=split(/\:/,$_);
  348:          $status.=
  349: 	   &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
  350:                 $sendback).' ';
  351:        }
  352:     } else { 
  353: 	$status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback);
  354:     }
  355:     return $status;
  356: }
  357: 
  358: # =================================================== Critical message received
  359: 
  360: sub user_crit_received {
  361:     my $msgid=shift;
  362:     my %message=&Apache::lonnet::get('critical',[$msgid]);
  363:     my %contents=&unpackagemsg($message{$msgid},1);
  364:     my $status='rec: '.($contents{'sendback'}?
  365:      &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
  366:                      &mt('Receipt').': '.$ENV{'user.name'}.' at '.$ENV{'user.domain'},
  367:                      &mt('User').' '.$ENV{'user.name'}.' '.&mt('at').' '.$ENV{'user.domain'}.
  368:                      ' acknowledged receipt of message'."\n".'   "'.
  369:                      $contents{'subject'}.'"'."\n".&mt('dated').' '.
  370:                      $contents{'time'}.".\n"
  371:                      ):'no msg req');
  372:     $status.=' trans: '.
  373:      &Apache::lonnet::put(
  374:      'nohist_email',{$contents{'msgid'} => $message{$msgid}});
  375:     $status.=' del: '.
  376:      &Apache::lonnet::del('critical',[$contents{'msgid'}]);
  377:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
  378:                          $ENV{'user.home'},'Received critical message '.
  379:                          $contents{'msgid'}.
  380:                          ', '.$status);
  381:     return $status;
  382: }
  383: 
  384: # ======================================================== Normal communication
  385: 
  386: sub user_normal_msg_raw {
  387:     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_;
  388: # Check if allowed missing
  389:     my $status='';
  390:     my $msgid='undefined';
  391:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
  392:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
  393:     if ($homeserver ne 'no_host') {
  394:        ($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl,
  395:                                      $attachmenturl);
  396:        $status=&Apache::lonnet::critical(
  397:            'put:'.$domain.':'.$user.':nohist_email:'.
  398:            &Apache::lonnet::escape($msgid).'='.
  399:            &Apache::lonnet::escape($message),$homeserver);
  400:        &Apache::lonnet::put
  401:                          ('email_status',{'recnewemail'=>time},$domain,$user);
  402:     } else {
  403:        $status='no_host';
  404:     }
  405: # Notifications
  406:     my %userenv = &Apache::lonnet::get('environment',['notification'],
  407:                                        $domain,$user);
  408:     if ($userenv{'notification'}) {
  409: 	&sendnotification($userenv{'notification'},$user,$domain,$subject,0);
  410:     }
  411:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
  412:                          $ENV{'user.home'},
  413:       'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
  414:     return $status;
  415: }
  416: 
  417: # New routine that respects "forward" and calls old routine
  418: 
  419: =pod
  420: 
  421: =item * B<user_normal_msg($user, $domain, $subject, $message,
  422:     $citation, $baseurl, $attachmenturl)>: Sends a message to the
  423:     $user at $domain, with subject $subject and message $message.
  424: 
  425: =cut
  426: 
  427: sub user_normal_msg {
  428:     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_;
  429:     my $status='';
  430:     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
  431:                                        $domain,$user);
  432:     my $msgforward=$userenv{'msgforward'};
  433:     if ($msgforward) {
  434:        foreach (split(/\,/,$msgforward)) {
  435: 	 my ($forwuser,$forwdomain)=split(/\:/,$_);
  436:          $status.=
  437: 	  &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
  438: 			       $citation,$baseurl,$attachmenturl).' ';
  439:        }
  440:     } else { 
  441: 	$status=&user_normal_msg_raw($user,$domain,$subject,$message,
  442: 				     $citation,$baseurl,$attachmenturl);
  443:     }
  444:     return $status;
  445: }
  446: 
  447: 
  448: # =============================================================== Status Change
  449: 
  450: sub statuschange {
  451:     my ($msgid,$newstatus)=@_;
  452:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
  453:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
  454:     unless ($status{$msgid}) { $status{$msgid}='new'; }
  455:     unless (($status{$msgid} eq 'replied') || 
  456:             ($status{$msgid} eq 'forwarded')) {
  457: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
  458:     }
  459:     if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
  460: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
  461:     }
  462: }
  463: 
  464: # ======================================================= Display a course list
  465: 
  466: sub discourse {
  467:     my $r=shift;
  468:     my %courselist=&Apache::lonnet::dump(
  469:                    'classlist',
  470: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  471: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  472:     my $now=time;
  473:     my %lt=&Apache::lonlocal::texthash('cfa' => 'Check for All',
  474:             'cfs' => 'Check for Section/Group',
  475:             'cfn' => 'Check for None');
  476:     $r->print(<<ENDDISHEADER);
  477: <input type=hidden name=sendmode value=group>
  478: <script>
  479:     function checkall() {
  480: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
  481:             if 
  482:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
  483: 	      document.forms.compemail.elements[i].checked=true;
  484:             }
  485:         }
  486:     }
  487: 
  488:     function checksec() {
  489: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
  490:             if 
  491:           (document.forms.compemail.elements[i].name.indexOf
  492:            ('send_to_&&&'+document.forms.compemail.chksec.value)==0) {
  493: 	      document.forms.compemail.elements[i].checked=true;
  494:             }
  495:         }
  496:     }
  497: 
  498:     function uncheckall() {
  499: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
  500:             if 
  501:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
  502: 	      document.forms.compemail.elements[i].checked=false;
  503:             }
  504:         }
  505:     }
  506: </script>
  507: <input type=button onClick="checkall()" value="$lt{'cfa'}">&nbsp;
  508: <input type=button onClick="checksec()" value="$lt{'cfs'}">
  509: <input type=text size=5 name=chksec>&nbsp;
  510: <input type=button onClick="uncheckall()" value="$lt{'cfn'}">
  511: <p>
  512: ENDDISHEADER
  513:     my %coursepersonnel=
  514:        &Apache::lonnet::get_course_adv_roles();
  515:     foreach my $role (sort keys %coursepersonnel) {
  516:        foreach (split(/\,/,$coursepersonnel{$role})) {
  517: 	   my ($puname,$pudom)=split(/\:/,$_);
  518: 	   $r->print(
  519:              '<br /><input type="checkbox" name="send_to_&&&&&&_'.
  520:              $puname.':'.$pudom.'" /> '.
  521: 		     &Apache::loncommon::plainname($puname,
  522:                           $pudom).' ('.$_.'), <i>'.$role.'</i>');
  523: 	}
  524:     }
  525: 
  526:     foreach (sort keys %courselist) {
  527:         my ($end,$start)=split(/\:/,$courselist{$_});
  528:         my $active=1;
  529:         if (($end) && ($now>$end)) { $active=0; }
  530:         if ($active) {
  531:            my ($sname,$sdom)=split(/\:/,$_);
  532:            my %reply=&Apache::lonnet::get('environment',
  533:               ['firstname','middlename','lastname','generation'],
  534:               $sdom,$sname);
  535:            my $section=&Apache::lonnet::usection
  536: 	       ($sdom,$sname,$ENV{'request.course.id'});
  537:            $r->print(
  538:         '<br><input type=checkbox name="send_to_&&&'.$section.'&&&_'.$_.'"> '.
  539: 		      $reply{'firstname'}.' '. 
  540:                       $reply{'middlename'}.' '.
  541:                       $reply{'lastname'}.' '.
  542:                       $reply{'generation'}.
  543:                       ' ('.$_.') '.$section);
  544:         } 
  545:     }
  546: }
  547: 
  548: # ==================================================== Display Critical Message
  549: 
  550: sub discrit {
  551:     my $r=shift;
  552:     my $header = '<h1><font color=red>'.&mt('Critical Messages').'</font></h1>'.
  553:         '<form action=/adm/email method=post>'.
  554:         '<input type=hidden name=confirm value=true>';
  555:     my %what=&Apache::lonnet::dump('critical');
  556:     my $result = '';
  557:     foreach (sort keys %what) {
  558:         my %content=&unpackagemsg($what{$_});
  559:         next if ($content{'senderdomain'} eq '');
  560:         $content{'message'}=~s/\n/\<br\>/g;
  561:         $result.='<hr>'.&mt('From').': <b>'.
  562: &Apache::loncommon::aboutmewrapper(
  563:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
  564: $content{'sendername'}.'@'.
  565:             $content{'senderdomain'}.') '.$content{'time'}.
  566:             '<br>'.&mt('Subject').': '.$content{'subject'}.
  567:             '<br><blockquote>'.
  568:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
  569:             '</blockquote>'.
  570:             '<input type=submit name="rec_'.$_.'" value="'.&mt('Confirm Receipt').'">'.
  571:             '<input type=submit name="reprec_'.$_.'" '.
  572:                   'value="'.&mt('Confirm Receipt and Reply').'">';
  573:     }
  574:     # Check to see if there were any messages.
  575:     if ($result eq '') {
  576:         $result = "<h2>".&mt('You have no critical messages.')."</h2>".
  577: 	    '<a href="/adm/roles">'.&mt('Select a course').'</a>';
  578:     } else {
  579:         $r->print($header);
  580:     }
  581:     $r->print($result);
  582:     $r->print('<input type=hidden name="displayedcrit" value="true"></form>');
  583: }
  584: 
  585: # =============================================================== Compose reply
  586: 
  587: sub comprep {
  588:     my ($r,$msgid)=@_;
  589:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
  590:       my %content=&unpackagemsg($message{$msgid},1);
  591:       my $quotemsg='> '.$content{'message'};
  592:       $quotemsg=~s/\r/\n/g;
  593:       $quotemsg=~s/\f/\n/g;
  594:       $quotemsg=~s/\n+/\n\> /g;
  595:       my $torepl=&Apache::loncommon::aboutmewrapper(
  596:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
  597: $content{'sendername'}.'@'.
  598:             $content{'senderdomain'}.')';
  599:       my $subject=&mt('Re').': '.$content{'subject'};
  600:       my $dispcrit='';
  601:       if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
  602: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
  603:          $dispcrit=
  604:  '<input type=checkbox name=critmsg> '.&mt('Send as critical message').' ' . $crithelp . 
  605:  '<br>'.
  606:  '<input type=checkbox name=sendbck> '.&mt('Send as critical message').' ' .
  607:  &mt('and return receipt') . $crithelp . '<p>';
  608:       }
  609:       $r->print(<<"ENDREPLY");
  610: <form action="/adm/email" method=post>
  611: <input type=hidden name=sendreply value="$msgid">
  612: To: $torepl<br />
  613: Subject: <input type=text size=50 name=subject value="$subject"><p>
  614: <textarea name=message cols=84 rows=10 wrap=hard>
  615: $quotemsg
  616: </textarea><p>
  617: $dispcrit
  618: <input type=submit value="Send Reply">
  619: </form>
  620: ENDREPLY
  621: }
  622: 
  623: sub sortedmessages {
  624:     my @messages = &Apache::lonnet::getkeys('nohist_email');
  625:     #unpack the varibles and repack into temp for sorting
  626:     my @temp;
  627:     foreach (@messages) {
  628: 	my $msgid=&Apache::lonnet::escape($_);
  629: 	my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
  630: 	    &Apache::lonmsg::unpackmsgid($msgid);
  631: 	my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
  632: 		     $msgid);
  633: 	push @temp ,\@temp1;
  634:     }
  635:     #default sort
  636:     @temp = sort  {$a->[0] <=> $b->[0]} @temp;    
  637:     if ($ENV{'form.sortedby'} eq "date"){
  638:         @temp = sort  {$a->[0] <=> $b->[0]} @temp;    
  639:     }
  640:     if ($ENV{'form.sortedby'} eq "revdate"){
  641:     	@temp = sort  {$b->[0] <=> $a->[0]} @temp; 
  642:     }
  643:     if ($ENV{'form.sortedby'} eq "user"){
  644: 	@temp = sort  {lc($a->[2]) cmp lc($b->[2])} @temp;
  645:     }
  646:     if ($ENV{'form.sortedby'} eq "revuser"){
  647: 	@temp = sort  {lc($b->[2]) cmp lc($a->[2])} @temp;
  648:     }
  649:     if ($ENV{'form.sortedby'} eq "domain"){
  650:         @temp = sort  {$a->[3] cmp $b->[3]} @temp;
  651:     }
  652:     if ($ENV{'form.sortedby'} eq "revdomain"){
  653:         @temp = sort  {$b->[3] cmp $a->[3]} @temp;
  654:     }
  655:     if ($ENV{'form.sortedby'} eq "subject"){
  656:         @temp = sort  {lc($a->[1]) cmp lc($b->[1])} @temp;
  657:     }
  658:     if ($ENV{'form.sortedby'} eq "revsubject"){
  659:         @temp = sort  {lc($b->[1]) cmp lc($a->[1])} @temp;
  660:     }
  661:     if ($ENV{'form.sortedby'} eq "status"){
  662:         @temp = sort  {$a->[4] cmp $b->[4]} @temp;
  663:     }
  664:     if ($ENV{'form.sortedby'} eq "revstatus"){
  665:         @temp = sort  {$b->[4] cmp $a->[4]} @temp;
  666:     }
  667:     return @temp;
  668: }
  669: 
  670: # ======================================================== Display all messages
  671: 
  672: sub disall {
  673:     my $r=shift;
  674:      $r->print(<<ENDDISHEADER);
  675: <script>
  676:     function checkall() {
  677: 	for (i=0; i<document.forms.disall.elements.length; i++) {
  678:             if 
  679:           (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
  680: 	      document.forms.disall.elements[i].checked=true;
  681:             }
  682:         }
  683:     }
  684: 
  685:     function uncheckall() {
  686: 	for (i=0; i<document.forms.disall.elements.length; i++) {
  687:             if 
  688:           (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
  689: 	      document.forms.disall.elements[i].checked=false;
  690:             }
  691:         }
  692:     }
  693: </script>
  694: ENDDISHEADER
  695:     $r->print('<h1>'.&mt('Display All Messages').'</h1><form method=post name=disall '.
  696: 	      'action="/adm/email">'.
  697: 	      '<table border=2><tr><th colspan=2>&nbsp</th><th>');
  698:     if ($ENV{'form.sortedby'} eq "revdate") {
  699: 	$r->print('<a href = "?sortedby=date">'.&mt('Date').'</a></th>');
  700:     } else {
  701: 	$r->print('<a href = "?sortedby=revdate">'.&mt('Date').'</a></th>');
  702:     }
  703:     $r->print('<th>');
  704:     if ($ENV{'form.sortedby'} eq "revuser") {
  705: 	$r->print('<a href = "?sortedby=user">'.&mt('Username').'</a>');
  706:     } else {
  707: 	$r->print('<a href = "?sortedby=revuser">'.&mt('Username').'</a>');
  708:     }
  709:     $r->print('</th><th>');
  710:     if ($ENV{'form.sortedby'} eq "revdomain") {
  711: 	$r->print('<a href = "?sortedby=domain">'.&mt('Domain').'</a>');
  712:     } else {
  713: 	$r->print('<a href = "?sortedby=revdomain">'.&mt('Domain').'</a>');
  714:     }
  715:     $r->print('</th><th>');
  716:     if ($ENV{'form.sortedby'} eq "revsubject") {
  717: 	$r->print('<a href = "?sortedby=subject">'.&mt('Subject').'</a>');
  718:     } else {
  719:     	$r->print('<a href = "?sortedby=revsubject">'.&mt('Subject').'</a>');
  720:     }
  721:     $r->print('</th><th>');
  722:     if ($ENV{'form.sortedby'} eq "revstatus") {
  723: 	$r->print('<a href = "?sortedby=status">'.&mt('Status').'</th>');
  724:     } else {
  725:      	$r->print('<a href = "?sortedby=revstatus">'.&mt('Status').'</th>');
  726:     }
  727:     $r->print('</tr>');
  728:     my @temp=sortedmessages();
  729:     foreach (@temp){
  730: 	my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID)= @$_;
  731: 	if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
  732: 	    if ($status eq 'new') {
  733: 		$r->print('<tr bgcolor="#FFBB77">');
  734: 	    } elsif ($status eq 'read') {
  735: 		$r->print('<tr bgcolor="#BBBB77">');
  736: 	    } elsif ($status eq 'replied') {
  737: 		$r->print('<tr bgcolor="#AAAA88">'); 
  738: 	    } else {
  739: 		$r->print('<tr bgcolor="#99BBBB">');
  740: 	    }
  741: 	    $r->print('<td><a href="/adm/email?display='.$origID.$sqs. 
  742: 		      '">'.&mt('Open').'</a></td><td><a href="/adm/email?markdel='.$origID.$sqs.
  743: 		      '">'.&mt('Delete').'</a><input type=checkbox name="delmark_'.$origID.'"></td>'.
  744: 		      '<td>'.&Apache::lonlocal::locallocaltime($sendtime).'</td><td>'.
  745: 		      $fromname.'</td><td>'.$fromdomain.'</td><td>'.
  746: 		      &Apache::lonnet::unescape($shortsubj).'</td><td>'.
  747:                       $status.'</td></tr>');
  748: 	}
  749:     }   
  750:     $r->print('</table><p>'.
  751:               '<a href="javascript:checkall()">'.&mt('Check All').'</a>&nbsp;'.
  752:               '<a href="javascript:uncheckall()">'.&mt('Uncheck All').'</a><p>'.
  753: 	      '<input type="hidden" name="sortedby" value="'.$ENV{'form.sortedby'}.'" />'.
  754:               '<input type=submit name="markeddel" value="'.&mt('Delete Checked').'">'.
  755:               '</form></body></html>');
  756: }
  757: 
  758: # ============================================================== Compose output
  759: 
  760: sub compout {
  761:     my ($r,$forwarding,$broadcast)=@_;
  762:       my $dispcrit='';
  763:     my $dissub='';
  764:     my $dismsg='';
  765:     my $func=&mt('Send New');
  766:       if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
  767: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
  768:          $dispcrit=
  769:  '<input type=checkbox name=critmsg> '.&mt('Send as critical message').' ' . $crithelp . 
  770:  '<br>'.
  771:  '<input type=checkbox name=sendbck> '.&mt('Send as critical message').'  ' .
  772:  &mt('and return receipt') . $crithelp . '<p>';
  773:       }
  774:     if ($forwarding) {
  775:        $dispcrit.='<input type=hidden name=forwid value="'.
  776: 	   $forwarding.'">';
  777:        $func=&mt('Forward');
  778:       my %message=&Apache::lonnet::get('nohist_email',[$forwarding]);
  779:       my %content=&unpackagemsg($message{$forwarding});
  780: 
  781:        $dissub=&mt('Forwarding').': '.$content{'subject'};
  782:        $dismsg=&mt('Forwarded message from').' '.
  783: 	   $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
  784:     }
  785:     my $defdom=$ENV{'user.domain'};
  786:     if ($ENV{'form.recdom'}) { $defdom=$ENV{'form.recdom'}; }
  787:       $r->print(
  788:                 '<form action="/adm/email"  name="compemail" method="post"'.
  789:                 ' enctype="multipart/form-data">'."\n".
  790:                 '<input type="hidden" name="sendmail" value="on">'."\n".
  791:                 '<table>');
  792:     unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
  793:         my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
  794:         my $selectlink=&Apache::loncommon::selectstudent_link
  795: 	    ('compemail','recuname','recdomain');
  796:        $r->print(<<"ENDREC");
  797: <table>
  798: <tr><td>Username:</td><td><input type=text size=12 name=recuname value="$ENV{'form.recname'}"></td><td rowspan="2">$selectlink</td></tr>
  799: <tr><td>Domain:</td>
  800: <td>$domform</td></tr>
  801: ENDREC
  802:     }
  803:     my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
  804:     if ($broadcast ne 'upload') {
  805:        $r->print(<<"ENDCOMP");
  806: <tr><td>Additional Recipients<br><tt>username\@domain,username\@domain, ...
  807: </tt></td><td>
  808: <input type=text size=50 name=additionalrec></td></tr>
  809: <tr><td>Subject:</td><td><input type=text size=50 name=subject value="$dissub">
  810: </td></tr></table>
  811: $latexHelp
  812: <textarea name=message cols=80 rows=10 wrap=hard>$dismsg
  813: </textarea><p>
  814: $dispcrit
  815: <input type=submit value="$func Mail">
  816: ENDCOMP
  817:     } else { # $broadcast is 'upload'
  818: 	$r->print(<<ENDUPLOAD);
  819: <input type=hidden name=sendmode value=upload>
  820: <h3>Generate messages from a file</h3>
  821: <p>
  822: Subject: <input type=text size=50 name=subject>
  823: </p>
  824: <p>General message text<br />
  825: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
  826: </textarea></p>
  827: <p>
  828: The file format for the uploaded portion of the message is:
  829: <pre>
  830: username1\@domain1: text
  831: username2\@domain2: text
  832: username3\@domain1: text
  833: </pre>
  834: </p>
  835: <p>
  836: The messages will be assembled from all lines with the respective 
  837: <tt>username\@domain</tt>, and appended to the general message text.</p>
  838: <p>
  839: <input type=file name=upfile size=20><p>
  840: $dispcrit
  841: <input type=submit value="Upload and send">
  842: ENDUPLOAD
  843:     }
  844:     if ($broadcast eq 'group') {
  845:        &discourse;
  846:     }
  847:     $r->print('</form>');
  848: }
  849: 
  850: # ---------------------------------------------------- Display all face to face
  851: 
  852: sub disfacetoface {
  853:     my ($r,$user,$domain)=@_;
  854:     unless ($ENV{'request.course.id'}) { return; }
  855:     unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
  856: 	return;
  857:     }
  858:     my %records=&Apache::lonnet::dump('nohist_email',
  859: 			 $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  860: 			 $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
  861:                          '%255b'.$user.'%253a'.$domain.'%255d');
  862:     my $result='';
  863:     foreach (sort keys %records) {
  864:         my %content=&unpackagemsg($records{$_});
  865:         next if ($content{'senderdomain'} eq '');
  866:         $content{'message'}=~s/\n/\<br\>/g;
  867:         if ($content{'subject'}=~/^Record/) {
  868: 	    $result.='<h3>Record</h3>';
  869:         } else {
  870:             $result.='<h3>Sent Message</h3>';
  871:             %content=&unpackagemsg($content{'message'});
  872:             $content{'message'}=
  873:                 '<b>Subject: '.$content{'subject'}.'</b><br />'.
  874: 		$content{'message'};
  875:         }
  876:         $result.='By: <b>'.
  877: &Apache::loncommon::aboutmewrapper(
  878:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
  879: $content{'sendername'}.'@'.
  880:             $content{'senderdomain'}.') '.$content{'time'}.
  881:             '<br><blockquote>'.
  882:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
  883: 	      '</blockquote>';
  884:      }
  885:     # Check to see if there were any messages.
  886:     if ($result eq '') {
  887:         $r->print("<p><b>No notes, face-to-face discussion records, or critical messages in this course.</b></p>");
  888:     } else {
  889:        $r->print($result);
  890:     }
  891: }
  892: 
  893: # ---------------------------------------------------------------- Face to face
  894: 
  895: sub facetoface {
  896:     my ($r,$stage)=@_;
  897:     unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
  898: 	return;
  899:     }
  900: # from query string
  901:     if ($ENV{'form.recname'}) { $ENV{'form.recuname'}=$ENV{'form.recname'}; }
  902:     if ($ENV{'form.recdom'}) { $ENV{'form.recdomain'}=$ENV{'form.recdom'}; }
  903: 
  904:     my $defdom=$ENV{'user.domain'};
  905: # already filled in
  906:     if ($ENV{'form.recdomain'}) { $defdom=$ENV{'form.recdomain'}; }
  907: # generate output
  908:     my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
  909:     my $stdbrws = &Apache::loncommon::selectstudent_link
  910: 	('stdselect','recuname','recdomain');
  911:     $r->print(<<"ENDTREC");
  912: <h3>User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course</h3>
  913: <form method="post" action="/adm/email" name="stdselect">
  914: <input type="hidden" name="recordftf" value="retrieve" />
  915: <table>
  916: <tr><td>Username:</td><td><input type=text size=12 name=recuname value="$ENV{'form.recuname'}"></td>
  917: <td rowspan="2">
  918: $stdbrws
  919: <input type="submit" value="Retrieve discussion and message records"></td>
  920: </tr>
  921: <tr><td>Domain:</td>
  922: <td>$domform</td></tr>
  923: </table>
  924: </form>
  925: ENDTREC
  926:     if (($stage ne 'query') &&
  927:         ($ENV{'form.recdomain'}) && ($ENV{'form.recuname'})) {
  928:         chomp($ENV{'form.newrecord'});
  929:         if ($ENV{'form.newrecord'}) {
  930:            &user_normal_msg_raw(
  931:             $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
  932:             $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  933:             'Record ['.$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}.']',
  934: 	    $ENV{'form.newrecord'});
  935:         }
  936:         $r->print('<h3>'.&Apache::loncommon::plainname($ENV{'form.recuname'},
  937: 				     $ENV{'form.recdomain'}).'</h3>');
  938:         &disfacetoface($r,$ENV{'form.recuname'},$ENV{'form.recdomain'});
  939: 	$r->print(<<ENDRHEAD);
  940: <form method="post" action="/adm/email">
  941: <input name="recdomain" value="$ENV{'form.recdomain'}" type="hidden" />
  942: <input name="recuname" value="$ENV{'form.recuname'}" type="hidden" />
  943: ENDRHEAD
  944:         $r->print(<<ENDBFORM);
  945: <hr />New Record (record is visible to course faculty and staff)<br />
  946: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
  947: <br />
  948: <input type="hidden" name="recordftf" value="post" />
  949: <input type="submit" value="Post this record" />
  950: </form>
  951: ENDBFORM
  952:     }
  953: }
  954: 
  955: # ===================================================================== Handler
  956: 
  957: sub handler {
  958:     my $r=shift;
  959: 
  960: # ----------------------------------------------------------- Set document type
  961: 
  962:   &Apache::loncommon::content_type($r,'text/html');
  963:   $r->send_http_header;
  964: 
  965:   return OK if $r->header_only;
  966: 
  967: # --------------------------- Get query string for limited number of parameters
  968:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  969:         ['display','replyto','forward','markread','markdel','markunread',
  970:          'sendreply','compose','sendmail','critical','recname','recdom',
  971:          'recordftf','sortedby']);
  972:     $sqs='&sortedby='.$ENV{'form.sortedby'};
  973: # ------------------------------------------------------ They checked for email
  974:   &Apache::lonnet::put('email_status',{'recnewemail'=>0});
  975: # --------------------------------------------------------------- Render Output
  976:   if (!$ENV{'form.display'}) {
  977:       $r->print('<html><head><title>EMail and Messaging</title>'.
  978: 		&Apache::loncommon::studentbrowser_javascript().'</head>'.
  979: 		&Apache::loncommon::bodytag('EMail and Messages'));
  980:   }
  981:   if ($ENV{'form.display'}) {
  982:       my $msgid=$ENV{'form.display'};
  983:       &statuschange($msgid,'read');
  984:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
  985:       my %content=&unpackagemsg($message{$msgid});
  986: # info to generate "next" and "previous" buttons
  987:       my @messages=&sortedmessages();
  988:       my $counter=0;
  989:       $r->print('<pre>');
  990:       my $escmsgid=&Apache::lonnet::escape($msgid);
  991:       foreach (@messages) {
  992:  	  if ($_->[5] eq $escmsgid){
  993:  	      last;
  994:  	  }
  995:  	  $counter++;
  996:       }
  997:       $r->print('</pre>');
  998:       my $number_of_messages = scalar(@messages); #subtract 1 for last index
  999: # start output
 1000:       $r->print('<html><head><title>EMail and Messaging</title>');
 1001:       if (defined($content{'baseurl'})) {
 1002: 	  $r->print("<base href=\"http://$ENV{'SERVER_NAME'}/$content{'baseurl'}\" />");
 1003:       }
 1004:       $r->print(&Apache::loncommon::studentbrowser_javascript().
 1005: 		'</head>'.
 1006: 		&Apache::loncommon::bodytag('EMail and Messages'));
 1007:       $r->print('<b>'.&mt('Subject').':</b> '.$content{'subject'}.
 1008:              '<br><b>'.&mt('From').':</b> '.
 1009: &Apache::loncommon::aboutmewrapper(
 1010: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
 1011: $content{'sendername'},$content{'senderdomain'}).' ('.
 1012:                                  $content{'sendername'}.' at '.
 1013:                                  $content{'senderdomain'}.') '.
 1014:              '<br><b>'.&mt('Time').':</b> '.$content{'time'}.'<p>'.
 1015:              '<table border=2><tr bgcolor="#FFFFAA"><td>'.&mt('Functions').':</td>'.
 1016:            '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).$sqs.
 1017:              '"><b>'.&mt('Reply').'</b></a></td>'.
 1018:            '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).$sqs.
 1019:              '"><b>'.&mt('Forward').'</b></a></td>'.
 1020:         '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).$sqs.
 1021:              '"><b>'.&mt('Mark Unread').'</b></a></td>'.
 1022:         '<td><a href="/adm/email?markdel='.&Apache::lonnet::escape($msgid).$sqs.
 1023:              '"><b>Delete</b></a></td>'.
 1024: 		'<td><a href="/adm/email?sortedby='.$ENV{'form.sortedby'}.
 1025: 		'"><b>'.&mt('Display all Messages').'</b></a></td>');
 1026:       if ($counter > 0){
 1027:  	  $r->print('<td><a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.
 1028:            '"><b>'.&mt('Previous').'</b></a></td>');
 1029:        }
 1030:        if ($counter < $number_of_messages - 1){
 1031:  	  $r->print('<td><a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.
 1032:            '"><b>'.&mt('Next').'</b></a></td>');
 1033:        }
 1034:        $r->print('</tr></table><p><pre>'.
 1035:              &Apache::lontexconvert::msgtexconverted($content{'message'}).
 1036:              '</pre><hr>'.$content{'citation'});
 1037:   } elsif ($ENV{'form.replyto'}) {
 1038:       &comprep($r,$ENV{'form.replyto'});
 1039:   } elsif ($ENV{'form.sendreply'}) {
 1040:       my $msgid=$ENV{'form.sendreply'};
 1041:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
 1042:       my %content=&unpackagemsg($message{$msgid},1);
 1043:       &statuschange($msgid,'replied');
 1044:       if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
 1045:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
 1046:          $r->print(&mt('Sending critical').': '.
 1047:                 &user_crit_msg($content{'sendername'},
 1048:                                  $content{'senderdomain'},
 1049:                                  &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
 1050:                                  &Apache::lonfeedback::clear_out_html($ENV{'form.message'}),
 1051:                                  $ENV{'form.sendbck'}));
 1052:       } else {
 1053:          $r->print(&mt('Sending').': '.&user_normal_msg($content{'sendername'},
 1054:                                  $content{'senderdomain'},
 1055:                                  &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
 1056:                                  &Apache::lonfeedback::clear_out_html($ENV{'form.message'})));
 1057:       }
 1058:       if ($ENV{'form.displayedcrit'}) {
 1059:           &discrit($r);
 1060:       } else {
 1061: 	  &disall($r);
 1062:       }
 1063:   } elsif ($ENV{'form.confirm'}) {
 1064:       foreach (keys %ENV) {
 1065:           if ($_=~/^form\.rec\_(.*)$/) {
 1066: 	      $r->print('<b>Confirming Receipt:</b> '.
 1067:                         &user_crit_received($1).'<br>');
 1068:           }
 1069:           if ($_=~/^form\.reprec\_(.*)$/) {
 1070:               my $msgid=$1;
 1071: 	      $r->print('<b>Confirming Receipt:</b> '.
 1072:                         &user_crit_received($msgid).'<br>');
 1073:               &comprep($r,$msgid);
 1074:           }
 1075:       }
 1076:       &discrit($r);
 1077:   } elsif ($ENV{'form.critical'}) {
 1078:       &discrit($r);
 1079:   } elsif ($ENV{'form.forward'}) {
 1080:       &compout($r,$ENV{'form.forward'});
 1081:   } elsif ($ENV{'form.markread'}) {
 1082:   } elsif ($ENV{'form.markdel'}) {
 1083:       &statuschange($ENV{'form.markdel'},'deleted');
 1084:       &disall($r);
 1085:   } elsif ($ENV{'form.markeddel'}) {
 1086:       my $total=0;
 1087:       foreach (keys %ENV) {
 1088:           if ($_=~/^form\.delmark_(.*)$/) {
 1089: 	      &statuschange(&Apache::lonnet::unescape($1),'deleted');
 1090:               $total++;
 1091:           }
 1092:       }
 1093:       $r->print('Deleted '.$total.' message(s)<p>');
 1094:       &disall($r);
 1095:   } elsif ($ENV{'form.markunread'}) {
 1096:       &statuschange($ENV{'form.markunread'},'new');
 1097:       &disall($r);
 1098:   } elsif ($ENV{'form.compose'}) {
 1099:       &compout($r,'',$ENV{'form.compose'});
 1100:   } elsif ($ENV{'form.recordftf'}) {
 1101:       &facetoface($r,$ENV{'form.recordftf'});
 1102:   } elsif ($ENV{'form.sendmail'}) {
 1103:       my %content=();
 1104:       undef %content;
 1105:       if ($ENV{'form.forwid'}) {
 1106:         my $msgid=$ENV{'form.forwid'};
 1107:         my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
 1108:         %content=&unpackagemsg($message{$msgid},1);
 1109:         &statuschange($msgid,'forwarded');
 1110:         $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
 1111: 	                       $content{'message'};
 1112:       }
 1113:       my %toaddr=();
 1114:       undef %toaddr;
 1115:       if ($ENV{'form.sendmode'} eq 'group') {
 1116:           foreach (keys %ENV) {
 1117: 	      if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
 1118: 		  $toaddr{$1}='';
 1119:               }
 1120:           }
 1121:       } elsif ($ENV{'form.sendmode'} eq 'upload') {
 1122:           foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) {
 1123:               my ($rec,$txt)=split(/\s*\:\s*/,$_);
 1124:               if ($txt) {
 1125: 		  $rec=~s/\@/\:/;
 1126:                   $toaddr{$rec}.=$txt."\n";
 1127:               }
 1128:           }
 1129:       } else {
 1130: 	  $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
 1131:       }
 1132:       if ($ENV{'form.additionalrec'}) {
 1133: 	  foreach (split(/\,/,$ENV{'form.additionalrec'})) {
 1134:               my ($auname,$audom)=split(/\@/,$_);
 1135:               $toaddr{$auname.':'.$audom}='';
 1136:           }
 1137:       }
 1138:     foreach (keys %toaddr) {
 1139:       my ($recuname,$recdomain)=split(/\:/,$_);
 1140:       my $msgtxt=&Apache::lonfeedback::clear_out_html($ENV{'form.message'});
 1141:       if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }    
 1142:       if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
 1143:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
 1144:          $r->print('Sending critical: '.
 1145:                 &user_crit_msg($recuname,$recdomain,
 1146:                &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
 1147:                                  $msgtxt,
 1148:                                  $ENV{'form.sendbck'}));
 1149:       } else {
 1150:          $r->print('Sending: '.&user_normal_msg($recuname,$recdomain,
 1151:               &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
 1152:                                  $msgtxt,
 1153:                                  $content{'citation'}));
 1154:       }
 1155:       $r->print('<br>');
 1156:     }
 1157:       if ($ENV{'form.displayedcrit'}) {
 1158:           &discrit($r);
 1159:       } else {
 1160: 	  &disall($r);
 1161:       }
 1162:   } else {
 1163:       &disall($r);
 1164:   }
 1165:   $r->print('</body></html>');
 1166:   return OK;
 1167: 
 1168: }
 1169: # ================================================= Main program, reset counter
 1170: 
 1171: BEGIN {
 1172:     $msgcount=0;
 1173: }
 1174: 
 1175: =pod
 1176: 
 1177: =back
 1178: 
 1179: =cut
 1180: 
 1181: 1; 
 1182: 
 1183: __END__
 1184: 
 1185: 
 1186: 
 1187: 
 1188: 
 1189: 
 1190: 

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