File:  [LON-CAPA] / loncom / interface / lonmsg.pm
Revision 1.35: download - view: text, annotated - select for diffs
Mon Jul 22 14:23:29 2002 UTC (21 years, 10 months ago) by bowersj2
Branches: MAIN
CVS tags: HEAD
Checking commit of scripts to make sure I don't get too far out of sync. Added help
links to the message sender describing 'critical message', and several help links in
the course parameters screen. (These will not work until some .tex files are checked
in.)

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

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