File:  [LON-CAPA] / loncom / interface / lonmsg.pm
Revision 1.39: download - view: text, annotated - select for diffs
Mon Sep 16 20:06:12 2002 UTC (21 years, 8 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- should be better about silly messages (I keep get this message listed from 1969 that is ne no matter what I do with sending myself messages our trying to delete. With this it at least stops showing up.)

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

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