File:  [LON-CAPA] / loncom / interface / lonmsg.pm
Revision 1.28: download - view: text, annotated - select for diffs
Sat Feb 16 19:59:10 2002 UTC (22 years, 3 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
map to foreach

    1: # The LearningOnline Network with CAPA
    2: # Routines for messaging
    3: #
    4: # $Id: lonmsg.pm,v 1.28 2002/02/16 19:59:10 harris41 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 Gerd Kortemeyer
   44: #
   45: package Apache::lonmsg;
   46: 
   47: use strict;
   48: use Apache::lonnet();
   49: use vars qw($msgcount);
   50: use HTML::TokeParser;
   51: use Apache::Constants qw(:common);
   52: 
   53: # ===================================================================== Package
   54: 
   55: sub packagemsg {
   56:     my ($subject,$message,$citation)=@_;
   57:     $message=~s/\</\&lt\;/g;
   58:     $message=~s/\>/\&gt\;/g;
   59:     $citation=~s/\</\&lt\;/g;
   60:     $citation=~s/\>/\&gt\;/g;
   61:     $subject=~s/\</\&lt\;/g;
   62:     $subject=~s/\>/\&gt\;/g;
   63:     my $now=time;
   64:     $msgcount++;
   65:     my $partsubj=$subject;
   66:     $partsubj=&Apache::lonnet::escape($partsubj);
   67:     my $msgid=&Apache::lonnet::escape(
   68:            $now.':'.$partsubj.':'.$ENV{'user.name'}.':'.
   69:            $ENV{'user.domain'}.':'.$msgcount.':'.$$);
   70:     return $msgid,
   71:            '<sendername>'.$ENV{'user.name'}.'</sendername>'.
   72:            '<senderdomain>'.$ENV{'user.domain'}.'</senderdomain>'.
   73:            '<subject>'.$subject.'</subject>'.
   74: 	   '<time>'.localtime($now).'</time>'.
   75: 	   '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
   76:            '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
   77: 	   '<client>'.$ENV{'REMOTE_ADDR'}.'</client>'.
   78: 	   '<browsertype>'.$ENV{'browser.type'}.'</browsertype>'.
   79: 	   '<browseros>'.$ENV{'browser.os'}.'</browseros>'.
   80: 	   '<browserversion>'.$ENV{'browser.version'}.'</browserversion>'.
   81:            '<browsermathml>'.$ENV{'browser.mathml'}.'</browsermathml>'.
   82: 	   '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
   83: 	   '<courseid>'.$ENV{'request.course.id'}.'</courseid>'.
   84: 	   '<role>'.$ENV{'request.role'}.'</role>'.
   85: 	   '<resource>'.$ENV{'request.filename'}.'</resource>'.
   86:            '<msgid>'.$msgid.'</msgid>'.
   87: 	   '<message>'.$message.'</message>'.
   88: 	   '<citation>'.$citation.'</citation>';
   89: }
   90: 
   91: # ================================================== Unpack message into a hash
   92: 
   93: sub unpackagemsg {
   94:     my $message=shift;
   95:     my %content=();
   96:     my $parser=HTML::TokeParser->new(\$message);
   97:     my $token;
   98:     while ($token=$parser->get_token) {
   99:        if ($token->[0] eq 'S') {
  100: 	   my $entry=$token->[1];
  101:            my $value=$parser->get_text('/'.$entry);
  102:            $content{$entry}=$value;
  103:        }
  104:     }
  105:     return %content;
  106: }
  107: 
  108: # ======================================================= Get info out of msgid
  109: 
  110: sub unpackmsgid {
  111:     my $msgid=&Apache::lonnet::unescape(shift);
  112:     my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/,
  113:                           &Apache::lonnet::unescape($msgid));
  114:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
  115:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
  116:     unless ($status{$msgid}) { $status{$msgid}='new'; }
  117:     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});
  118: } 
  119: 
  120: # =============================== Automated message to the author of a resource
  121: 
  122: sub author_res_msg {
  123:     my ($filename,$message)=@_;
  124:     unless ($message) { return 'empty'; }
  125:     $filename=&Apache::lonnet::declutter($filename);
  126:     my ($domain,$author,@dummy)=split(/\//,$filename);
  127:     my $homeserver=&Apache::lonnet::homeserver($author,$domain);
  128:     if ($homeserver ne 'no_host') {
  129:        my $id=unpack("%32C*",$message);
  130:        my $msgid;
  131:        ($msgid,$message)=&packagemsg($filename,$message);
  132:        return &Apache::lonnet::reply('put:'.$domain.':'.$author.
  133:          ':nohist_res_msgs:'.
  134:           &Apache::lonnet::escape($filename.'_'.$id).'='.
  135:           &Apache::lonnet::escape($message),$homeserver);
  136:     }
  137:     return 'no_host';
  138: }
  139: 
  140: # ================================================== Critical message to a user
  141: 
  142: sub user_crit_msg {
  143:     my ($user,$domain,$subject,$message,$sendback)=@_;
  144: # Check if allowed missing
  145:     my $status='';
  146:     my $msgid='undefined';
  147:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
  148:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
  149:     if ($homeserver ne 'no_host') {
  150:        ($msgid,$message)=&packagemsg($subject,$message);
  151:        if ($sendback) { $message.='<sendback>true</sendback>'; }
  152:        $status=&Apache::lonnet::critical(
  153:            'put:'.$domain.':'.$user.':critical:'.
  154:            &Apache::lonnet::escape($msgid).'='.
  155:            &Apache::lonnet::escape($message),$homeserver);
  156:     } else {
  157:        $status='no_host';
  158:     }
  159:     &Apache::lonnet::logthis(
  160:       'Sending critical email '.$msgid.
  161:       ', log status: '.
  162:       &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
  163:                          $ENV{'user.home'},
  164:       'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
  165:       .$status));
  166:     return $status;
  167: }
  168: 
  169: # =================================================== Critical message received
  170: 
  171: sub user_crit_received {
  172:     my $msgid=shift;
  173:     my %message=&Apache::lonnet::get('critical',[$msgid]);
  174:     my %contents=&unpackagemsg($message{$msgid});
  175:     my $status='rec: '.($contents{'sendback'}?
  176:      &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
  177:                      'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'},
  178:                      'User '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}.
  179:                      ' acknowledged receipt of message "'.
  180:                      $contents{'subject'}.'" dated '.$contents{'time'}.".\n\n"
  181:                      .'Message ID: '.$contents{'msgid'}):'no msg req');
  182:     $status.=' trans: '.
  183:      &Apache::lonnet::put(
  184:      'nohist_email',{$contents{'msgid'} => $message{$msgid}});
  185:     $status.=' del: '.
  186:      &Apache::lonnet::del('critical',[$contents{'msgid'}]);
  187:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
  188:                          $ENV{'user.home'},'Received critical message '.
  189:                          $contents{'msgid'}.
  190:                          ', '.$status);
  191:     return $status;
  192: }
  193: 
  194: # ======================================================== Normal communication
  195: 
  196: sub user_normal_msg {
  197:     my ($user,$domain,$subject,$message,$citation)=@_;
  198: # Check if allowed missing
  199:     my $status='';
  200:     my $msgid='undefined';
  201:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
  202:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
  203:     if ($homeserver ne 'no_host') {
  204:        ($msgid,$message)=&packagemsg($subject,$message,$citation);
  205:        $status=&Apache::lonnet::critical(
  206:            'put:'.$domain.':'.$user.':nohist_email:'.
  207:            &Apache::lonnet::escape($msgid).'='.
  208:            &Apache::lonnet::escape($message),$homeserver);
  209:     } else {
  210:        $status='no_host';
  211:     }
  212:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
  213:                          $ENV{'user.home'},
  214:       'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
  215:     return $status;
  216: }
  217: 
  218: # =============================================================== Status Change
  219: 
  220: sub statuschange {
  221:     my ($msgid,$newstatus)=@_;
  222:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
  223:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
  224:     unless ($status{$msgid}) { $status{$msgid}='new'; }
  225:     unless (($status{$msgid} eq 'replied') || 
  226:             ($status{$msgid} eq 'forwarded')) {
  227: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
  228:     }
  229:     if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
  230: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
  231:     }
  232: }
  233: 
  234: # ======================================================= Display a course list
  235: 
  236: sub discourse {
  237:     my $r=shift;
  238:     my %courselist=&Apache::lonnet::dump(
  239:                    'classlist',
  240: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  241: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  242:     my $now=time;
  243:     $r->print(<<ENDDISHEADER);
  244: <input type=hidden name=sendmode value=group>
  245: <script>
  246:     function checkall() {
  247: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
  248:             if 
  249:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
  250: 	      document.forms.compemail.elements[i].checked=true;
  251:             }
  252:         }
  253:     }
  254: 
  255:     function checksec() {
  256: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
  257:             if 
  258:           (document.forms.compemail.elements[i].name.indexOf
  259:            ('send_to_&&&'+document.forms.compemail.chksec.value)==0) {
  260: 	      document.forms.compemail.elements[i].checked=true;
  261:             }
  262:         }
  263:     }
  264: 
  265:     function uncheckall() {
  266: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
  267:             if 
  268:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
  269: 	      document.forms.compemail.elements[i].checked=false;
  270:             }
  271:         }
  272:     }
  273: </script>
  274: <input type=button onClick="checkall()" value="Check for All">&nbsp;
  275: <input type=button onClick="checksec()" value="Check for Section/Group">
  276: <input type=text size=5 name=chksec>&nbsp;
  277: <input type=button onClick="uncheckall()" value="Check for None">
  278: <p>
  279: ENDDISHEADER
  280:     foreach (sort keys %courselist) {
  281:         my ($end,$start)=split(/\:/,$courselist{$_});
  282:         my $active=1;
  283:         if (($end) && ($now>$end)) { $active=0; }
  284:         if ($active) {
  285:            my ($sname,$sdom)=split(/\:/,$_);
  286:            my %reply=&Apache::lonnet::get('environment',
  287:               ['firstname','middlename','lastname','generation'],
  288:               $sdom,$sname);
  289:            my $section=&Apache::lonnet::usection
  290: 	       ($sdom,$sname,$ENV{'request.course.id'});
  291:            $r->print(
  292:         '<br><input type=checkbox name="send_to_&&&'.$section.'&&&_'.$_.'"> '.
  293: 		      $reply{'firstname'}.' '. 
  294:                       $reply{'middlename'}.' '.
  295:                       $reply{'lastname'}.' '.
  296:                       $reply{'generation'}.
  297:                       ' ('.$_.') '.$section);
  298:         } 
  299:     }
  300: }
  301: 
  302: # ==================================================== Display Critical Message
  303: 
  304: sub discrit {
  305:     my $r=shift;
  306:       $r->print('<h1><font color=red>Critical Messages</font></h1>'.
  307:          '<form action=/adm/email method=post>'.
  308:          '<input type=hidden name=confirm value=true>');
  309:       my %what=&Apache::lonnet::dump('critical');
  310:       foreach (sort keys %what) {
  311:           my %content=&unpackagemsg($what{$_});
  312:           $content{'message'}=~s/\n/\<br\>/g;
  313: 	  $r->print('<hr>From: <b>'.$content{'sendername'}.'@'.
  314:                     $content{'senderdomain'}.'</b> ('.$content{'time'}.
  315:                     ')<br><blockquote>'.$content{'message'}.'</blockquote>'.
  316:   '<input type=submit name="rec_'.$_.'" value="Confirm Receipt">'.
  317:  '<input type=submit name="reprec_'.$_.'" value="Confirm Receipt and Reply">');
  318:       }
  319:       $r->print(
  320:           '<input type=hidden name="displayedcrit" value="true"></form>');
  321: }
  322: 
  323: # =============================================================== Compose reply
  324: 
  325: sub comprep {
  326:     my ($r,$msgid)=@_;
  327:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
  328:       my %content=&unpackagemsg($message{$msgid});
  329:       my $quotemsg='> '.$content{'message'};
  330:       $quotemsg=~s/\r/\n/g;
  331:       $quotemsg=~s/\f/\n/g;
  332:       $quotemsg=~s/\n+/\n\> /g;
  333:       my $subject='Re: '.$content{'subject'};
  334:       my $dispcrit='';
  335:       if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
  336:          $dispcrit=
  337:  '<input type=checkbox name=critmsg> Send as critical message<br>'.
  338:  '<input type=checkbox name=sendbck> Send as critical message'.
  339:  ' and return receipt<p>';
  340:       }
  341:       $r->print(<<"ENDREPLY");
  342: <form action="/adm/email" method=post>
  343: <input type=hidden name=sendreply value="$msgid">
  344: Subject: <input type=text size=50 name=subject value="$subject"><p>
  345: <textarea name=message cols=64 rows=10 wrap=hard>
  346: $quotemsg
  347: </textarea><p>
  348: $dispcrit
  349: <input type=submit value="Send Reply">
  350: </form>
  351: ENDREPLY
  352: }
  353: 
  354: # ======================================================== Display all messages
  355: 
  356: sub disall {
  357:     my $r=shift;
  358:     $r->print(
  359:      '<h1>Display All Messages</h1><form method=post action="/adm/email">'.
  360:      '<table border=2><tr><th colspan=2>&nbsp</th><th>Date</th>'.
  361:      '<th>Username</th><th>Domain</th><th>Subject</th><th>Status</th></tr>');
  362:     foreach (sort split(/\&/,&Apache::lonnet::reply('keys:'.
  363: 					$ENV{'user.domain'}.':'.
  364:                                         $ENV{'user.name'}.':nohist_email',
  365:                                         $ENV{'user.home'}))) {
  366:         my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
  367: 	    &Apache::lonmsg::unpackmsgid($_);
  368:        unless ($status eq 'deleted') {
  369:         if ($status eq 'new') {
  370: 	    $r->print('<tr bgcolor="#FFBB77">');
  371:         } elsif ($status eq 'read') {
  372: 	    $r->print('<tr bgcolor="#BBBB77">');
  373:         } elsif ($status eq 'replied') {
  374: 	    $r->print('<tr bgcolor="#AAAA88">');
  375: 	} else {
  376: 	    $r->print('<tr bgcolor="#99BBBB">');
  377:         }
  378:         $r->print('<td><a href="/adm/email?display='.$_.
  379:                   '">Open</a></td><td><a href="/adm/email?markdel='.$_.
  380:                 '">Delete</a><input type=checkbox name="delmark_'.$_.'"></td>'.
  381:                   '<td>'.localtime($sendtime).'</td><td>'.
  382:                   $fromname.'</td><td>'.$fromdomain.'</td><td>'.
  383: 		      &Apache::lonnet::unescape($shortsubj).'</td><td>'.
  384:                       $status.'</td></tr>');
  385:        }
  386:     }
  387:     $r->print('</table><p>'.
  388:               '<input type=submit name="markeddel" value="Delete Checked">'.
  389:               '</form></body></html>');
  390: }
  391: 
  392: # ============================================================== Compose output
  393: 
  394: sub compout {
  395:     my ($r,$forwarding,$broadcast)=@_;
  396:       my $dispcrit='';
  397:     my $dissub='';
  398:     my $dismsg='';
  399:     my $func='Send New';
  400:       if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
  401:          $dispcrit=
  402:  '<input type=checkbox name=critmsg> Send as critical message<br>'.
  403:  '<input type=checkbox name=sendbck> Send as critical message'.
  404:  ' and return receipt<p>';
  405:       }
  406:     if ($forwarding) {
  407:        $dispcrit.='<input type=hidden name=forwid value="'.
  408: 	   $forwarding.'">';
  409:        $func='Forward';
  410:       my %message=&Apache::lonnet::get('nohist_email',[$forwarding]);
  411:       my %content=&unpackagemsg($message{$forwarding});
  412: 
  413:        $dissub='Forwarding: '.$content{'subject'};
  414:        $dismsg='Forwarded message from '.
  415: 	   $content{'sendername'}.' at '.$content{'senderdomain'};
  416:     }
  417:     my $defdom=$ENV{'user.domain'};
  418:       $r->print(
  419:                 '<form action="/adm/email"  name="compemail" method=post'.
  420:                 ' enctype="multipart/form-data">'.
  421:                 '<input type=hidden name=sendmail value=on><table>');
  422:     unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
  423:        $r->print(<<"ENDREC");
  424: <table>
  425: <tr><td>Username:</td><td><input type=text size=12 name=recuname></td></tr>
  426: <tr><td>Domain:</td>
  427: <td><input type=text size=12 name=recdomain value="$defdom"></td></tr>
  428: ENDREC
  429:     }
  430:     unless ($broadcast eq 'upload') {
  431:        $r->print(<<"ENDCOMP");
  432: <tr><td>Additional Recipients<br><tt>username\@domain,username\@domain, ...
  433: </tt></td><td>
  434: <input type=text size=50 name=additionalrec></td></tr>
  435: <tr><td>Subject:</td><td><input type=text size=50 name=subject value="$dissub">
  436: </td></tr></table>
  437: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
  438: </textarea><p>
  439: $dispcrit
  440: <input type=submit value="$func Mail">
  441: ENDCOMP
  442:     }
  443:     if ($broadcast eq 'upload') {
  444: 	$r->print(<<ENDUPLOAD);
  445: <input type=hidden name=sendmode value=upload>
  446: <h3>Generate messages from a file</h3>
  447: Subject: <input type=text size=50 name=subject>
  448: <pre>
  449: username1\@domain1: text
  450: username2\@domain2: text
  451: username1\@domain1: text
  452: </pre>
  453: The messages will be assembled from all lines with the respective 
  454: <tt>username\@domain</tt>, and appended to the general message text.<p>
  455: <input type=file name=upfile size=20><p>
  456: General message text:<p>
  457: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
  458: </textarea><p>
  459: $dispcrit
  460: <input type=submit value="Upload and send">
  461: ENDUPLOAD
  462:     }
  463:     if ($broadcast eq 'group') {
  464:        &discourse;
  465:     }
  466:     $r->print('</form>');
  467: }
  468: 
  469: # ===================================================================== Handler
  470: 
  471: sub handler {
  472:     my $r=shift;
  473: 
  474: # ----------------------------------------------------------- Set document type
  475: 
  476:   $r->content_type('text/html');
  477:   $r->send_http_header;
  478: 
  479:   return OK if $r->header_only;
  480: 
  481: # --------------------------- Get query string for limited number of parameters
  482: 
  483:     foreach (split(/&/,$ENV{'QUERY_STRING'})) {
  484:        my ($name, $value) = split(/=/,$_);
  485:        $value =~ tr/+/ /;
  486:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
  487:        if (($name eq 'display') || ($name eq 'replyto') || 
  488:            ($name eq 'forward') || ($name eq 'markread') ||
  489:            ($name eq 'markdel') || ($name eq 'markunread') ||
  490:            ($name eq 'sendreply') || ($name eq 'compose') ||
  491:            ($name eq 'sendmail') || ($name eq 'critical')) {
  492:            unless ($ENV{'form.'.$name}) {
  493:               $ENV{'form.'.$name}=$value;
  494: 	   }
  495:        }
  496:     }
  497: 
  498: # --------------------------------------------------------------- Render Output
  499:   
  500:   $r->print('<html><head><title>EMail and Messaging</title></head>');
  501:   $r->print(
  502:    '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
  503:   $r->print('<h1>EMail</h1>');
  504:   if ($ENV{'form.display'}) {
  505:       my $msgid=$ENV{'form.display'};
  506:       &statuschange($msgid,'read');
  507:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
  508:       my %content=&unpackagemsg($message{$msgid});
  509:       $r->print('<b>Subject:</b> '.$content{'subject'}.
  510:              '<br><b>From:</b> '.$content{'sendername'}.' at '.
  511:                                  $content{'senderdomain'}.
  512:              '<br><b>Time:</b> '.$content{'time'}.'<p>'.
  513:              '<table border=2><tr bgcolor="#FFFFAA"><td>Functions:</td>'.
  514:            '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).
  515:              '"><b>Reply</b></a></td>'.
  516:            '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).
  517:              '"><b>Forward</b></a></td>'.
  518:         '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).
  519:              '"><b>Mark Unread</b></a></td>'.
  520:         '<td><a href="/adm/email"><b>Display all Messages</b></a></td>'.
  521:              '</tr></table><p><pre>'.
  522:              $content{'message'}.'</pre><hr>'.$content{'citation'});
  523:   } elsif ($ENV{'form.replyto'}) {
  524:       &comprep($r,$ENV{'form.replyto'});
  525:   } elsif ($ENV{'form.sendreply'}) {
  526:       my $msgid=$ENV{'form.sendreply'};
  527:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
  528:       my %content=&unpackagemsg($message{$msgid});
  529:       &statuschange($msgid,'replied');
  530:       if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
  531:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
  532:          $r->print('Sending critical: '.
  533:                 &user_crit_msg($content{'sendername'},
  534:                                  $content{'senderdomain'},
  535:                                  $ENV{'form.subject'},
  536:                                  $ENV{'form.message'},
  537:                                  $ENV{'form.sendbck'}));
  538:       } else {
  539:          $r->print('Sending: '.&user_normal_msg($content{'sendername'},
  540:                                  $content{'senderdomain'},
  541:                                  $ENV{'form.subject'},
  542:                                  $ENV{'form.message'}));
  543:       }
  544:       if ($ENV{'form.displayedcrit'}) {
  545:           &discrit($r);
  546:       } else {
  547: 	  &disall($r);
  548:       }
  549:   } elsif ($ENV{'form.confirm'}) {
  550:       foreach (keys %ENV) {
  551:           if ($_=~/^form\.rec\_(.*)$/) {
  552: 	      $r->print('<b>Confirming Receipt:</b> '.
  553:                         &user_crit_received($1).'<br>');
  554:           }
  555:           if ($_=~/^form\.reprec\_(.*)$/) {
  556:               my $msgid=$1;
  557: 	      $r->print('<b>Confirming Receipt:</b> '.
  558:                         &user_crit_received($msgid).'<br>');
  559:               &comprep($r,$msgid);
  560:           }
  561:       }
  562:       &discrit($r);
  563:   } elsif ($ENV{'form.critical'}) {
  564:       &discrit($r);
  565:   } elsif ($ENV{'form.forward'}) {
  566:       &compout($r,$ENV{'form.forward'});
  567:   } elsif ($ENV{'form.markread'}) {
  568:   } elsif ($ENV{'form.markdel'}) {
  569:       &statuschange($ENV{'form.markdel'},'deleted');
  570:       &disall($r);
  571:   } elsif ($ENV{'form.markeddel'}) {
  572:       my $total=0;
  573:       foreach (keys %ENV) {
  574:           if ($_=~/^form\.delmark_(.*)$/) {
  575: 	      &statuschange(&Apache::lonnet::unescape($1),'deleted');
  576:               $total++;
  577:           }
  578:       }
  579:       $r->print('Deleted '.$total.' message(s)<p>');
  580:       &disall($r);
  581:   } elsif ($ENV{'form.markunread'}) {
  582:       &statuschange($ENV{'form.markunread'},'new');
  583:       &disall($r);
  584:   } elsif ($ENV{'form.compose'}) {
  585:       &compout($r,'',$ENV{'form.compose'});
  586:   } elsif ($ENV{'form.sendmail'}) {
  587:       my %content=();
  588:       undef %content;
  589:       if ($ENV{'form.forwid'}) {
  590:         my $msgid=$ENV{'form.forwid'};
  591:         my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
  592:         %content=&unpackagemsg($message{$msgid});
  593:         &statuschange($msgid,'forwarded');
  594:         $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
  595: 	                       $content{'message'};
  596:       }
  597:       my %toaddr=();
  598:       undef %toaddr;
  599:       if ($ENV{'form.sendmode'} eq 'group') {
  600:           foreach (keys %ENV) {
  601: 	      if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
  602: 		  $toaddr{$1}='';
  603:               }
  604:           }
  605:       } elsif ($ENV{'form.sendmode'} eq 'upload') {
  606:           foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) {
  607:               my ($rec,$txt)=split(/\s*\:\s*/,$_);
  608:               if ($txt) {
  609: 		  $rec=~s/\@/\:/;
  610:                   $toaddr{$rec}.=$txt."\n";
  611:               }
  612:           }
  613:       } else {
  614: 	  $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
  615:       }
  616:       if ($ENV{'form.additionalrec'}) {
  617: 	  foreach (split(/\,/,$ENV{'form.additionalrec'})) {
  618:               my ($auname,$audom)=split(/\@/,$_);
  619:               $toaddr{$auname.':'.$audom}='';
  620:           }
  621:       }
  622:     foreach (keys %toaddr) {
  623:       my ($recuname,$recdomain)=split(/\:/,$_);
  624:       my $msgtxt=$ENV{'form.message'};
  625:       if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }    
  626:       if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
  627:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
  628:          $r->print('Sending critical: '.
  629:                 &user_crit_msg($recuname,$recdomain,
  630:                                  $ENV{'form.subject'},
  631:                                  $msgtxt,
  632:                                  $ENV{'form.sendbck'}));
  633:       } else {
  634:          $r->print('Sending: '.&user_normal_msg($recuname,$recdomain,
  635:                                  $ENV{'form.subject'},
  636:                                  $msgtxt,
  637:                                  $content{'citation'}));
  638:       }
  639:       $r->print('<br>');
  640:     }
  641:       if ($ENV{'form.displayedcrit'}) {
  642:           &discrit($r);
  643:       } else {
  644: 	  &disall($r);
  645:       }
  646:   } else {
  647:       &disall($r);
  648:   }
  649:   $r->print('</body></html>');
  650:   return OK;
  651: 
  652: }
  653: # ================================================= Main program, reset counter
  654: 
  655: BEGIN {
  656:     $msgcount=0;
  657: }
  658: 
  659: 1;
  660: __END__
  661: 
  662: 
  663: 
  664: 
  665: 
  666: 
  667: 

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