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

1.1       www         1: # The LearningOnline Network with CAPA
1.26      albertel    2: # Routines for messaging
                      3: #
1.39    ! albertel    4: # $Id: lonmsg.pm,v 1.38 2002/09/07 13:57:26 www Exp $
1.26      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
1.1       www        27: #
                     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: #
1.6       www        37: # 10/19,10/20,10/30,
                     38: # 02/06/01 Gerd Kortemeyer
1.11      www        39: # 07/27 Guy Albertelli
1.23      www        40: # 07/27,07/28,07/30,08/03,08/06,08/08,08/09,08/10,8/13,8/15,
1.24      www        41: # 10/1,11/5 Gerd Kortemeyer
1.27      www        42: # YEAR=2002
1.29      www        43: # 1/1,3/18 Gerd Kortemeyer
1.27      www        44: #
1.1       www        45: package Apache::lonmsg;
                     46: 
                     47: use strict;
                     48: use Apache::lonnet();
1.2       www        49: use vars qw($msgcount);
                     50: use HTML::TokeParser;
1.5       www        51: use Apache::Constants qw(:common);
1.35      bowersj2   52: use Apache::loncommon;
1.36      www        53: use Apache::lontexconvert;
1.1       www        54: 
                     55: # ===================================================================== Package
                     56: 
1.3       www        57: sub packagemsg {
1.7       www        58:     my ($subject,$message,$citation)=@_;
1.1       www        59:     $message=~s/\</\&lt\;/g;
                     60:     $message=~s/\>/\&gt\;/g;
1.7       www        61:     $citation=~s/\</\&lt\;/g;
                     62:     $citation=~s/\>/\&gt\;/g;
1.1       www        63:     $subject=~s/\</\&lt\;/g;
                     64:     $subject=~s/\>/\&gt\;/g;
1.2       www        65:     my $now=time;
                     66:     $msgcount++;
1.6       www        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.':'.$$);
1.2       www        72:     return $msgid,
                     73:            '<sendername>'.$ENV{'user.name'}.'</sendername>'.
1.1       www        74:            '<senderdomain>'.$ENV{'user.domain'}.'</senderdomain>'.
                     75:            '<subject>'.$subject.'</subject>'.
1.2       www        76: 	   '<time>'.localtime($now).'</time>'.
1.1       www        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>'.
1.2       www        88:            '<msgid>'.$msgid.'</msgid>'.
1.7       www        89: 	   '<message>'.$message.'</message>'.
                     90: 	   '<citation>'.$citation.'</citation>';
1.1       www        91: }
                     92: 
1.2       www        93: # ================================================== Unpack message into a hash
                     94: 
1.3       www        95: sub unpackagemsg {
1.2       www        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: 
1.6       www       110: # ======================================================= Get info out of msgid
                    111: 
                    112: sub unpackmsgid {
1.7       www       113:     my $msgid=&Apache::lonnet::unescape(shift);
1.6       www       114:     my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/,
1.7       www       115:                           &Apache::lonnet::unescape($msgid));
1.8       albertel  116:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
1.6       www       117:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
                    118:     unless ($status{$msgid}) { $status{$msgid}='new'; }
                    119:     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});
                    120: } 
                    121: 
1.1       www       122: # =============================== Automated message to the author of a resource
                    123: 
                    124: sub author_res_msg {
                    125:     my ($filename,$message)=@_;
1.2       www       126:     unless ($message) { return 'empty'; }
1.1       www       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);
1.2       www       132:        my $msgid;
1.3       www       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);
1.1       www       138:     }
1.2       www       139:     return 'no_host';
1.1       www       140: }
                    141: 
                    142: # ================================================== Critical message to a user
                    143: 
1.38      www       144: sub user_crit_msg_raw {
1.24      www       145:     my ($user,$domain,$subject,$message,$sendback)=@_;
1.2       www       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') {
1.3       www       152:        ($msgid,$message)=&packagemsg($subject,$message);
1.24      www       153:        if ($sendback) { $message.='<sendback>true</sendback>'; }
1.4       www       154:        $status=&Apache::lonnet::critical(
                    155:            'put:'.$domain.':'.$user.':critical:'.
                    156:            &Apache::lonnet::escape($msgid).'='.
                    157:            &Apache::lonnet::escape($message),$homeserver);
1.2       www       158:     } else {
                    159:        $status='no_host';
                    160:     }
                    161:     &Apache::lonnet::logthis(
1.4       www       162:       'Sending critical email '.$msgid.
1.2       www       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: '
1.4       www       167:       .$status));
1.2       www       168:     return $status;
                    169: }
                    170: 
1.38      www       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: 
1.2       www       192: # =================================================== Critical message received
                    193: 
                    194: sub user_crit_received {
1.12      www       195:     my $msgid=shift;
                    196:     my %message=&Apache::lonnet::get('critical',[$msgid]);
                    197:     my %contents=&unpackagemsg($message{$msgid});
1.24      www       198:     my $status='rec: '.($contents{'sendback'}?
1.5       www       199:      &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
1.4       www       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"
1.24      www       204:                      .'Message ID: '.$contents{'msgid'}):'no msg req');
1.5       www       205:     $status.=' trans: '.
1.12      www       206:      &Apache::lonnet::put(
                    207:      'nohist_email',{$contents{'msgid'} => $message{$msgid}});
1.5       www       208:     $status.=' del: '.
1.9       albertel  209:      &Apache::lonnet::del('critical',[$contents{'msgid'}]);
1.5       www       210:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
                    211:                          $ENV{'user.home'},'Received critical message '.
                    212:                          $contents{'msgid'}.
                    213:                          ', '.$status);
1.12      www       214:     return $status;
1.2       www       215: }
                    216: 
                    217: # ======================================================== Normal communication
                    218: 
1.38      www       219: sub user_normal_msg_raw {
1.7       www       220:     my ($user,$domain,$subject,$message,$citation)=@_;
1.2       www       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') {
1.7       www       227:        ($msgid,$message)=&packagemsg($subject,$message,$citation);
1.4       www       228:        $status=&Apache::lonnet::critical(
                    229:            'put:'.$domain.':'.$user.':nohist_email:'.
                    230:            &Apache::lonnet::escape($msgid).'='.
                    231:            &Apache::lonnet::escape($message),$homeserver);
1.2       www       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: }
1.38      www       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: 
1.2       www       263: 
1.7       www       264: # =============================================================== Status Change
                    265: 
                    266: sub statuschange {
                    267:     my ($msgid,$newstatus)=@_;
1.8       albertel  268:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
1.7       www       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')) {
1.10      albertel  273: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
1.7       www       274:     }
1.14      www       275:     if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
                    276: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
                    277:     }
1.7       www       278: }
1.14      www       279: 
1.17      www       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: 
1.19      www       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: 
1.17      www       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>
1.19      www       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;
1.17      www       323: <input type=button onClick="uncheckall()" value="Check for None">
                    324: <p>
                    325: ENDDISHEADER
1.28      harris41  326:     foreach (sort keys %courselist) {
1.17      www       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);
1.19      www       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.'&&&_'.$_.'"> '.
1.17      www       339: 		      $reply{'firstname'}.' '. 
                    340:                       $reply{'middlename'}.' '.
                    341:                       $reply{'lastname'}.' '.
                    342:                       $reply{'generation'}.
1.19      www       343:                       ' ('.$_.') '.$section);
1.17      www       344:         } 
1.28      harris41  345:     }
1.17      www       346: }
                    347: 
1.13      www       348: # ==================================================== Display Critical Message
1.5       www       349: 
1.12      www       350: sub discrit {
                    351:     my $r=shift;
1.30      matthew   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;
1.37      www       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'}.
1.36      www       367:             '<br><blockquote>'.
                    368:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
                    369:             '</blockquote>'.
1.30      matthew   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>');
1.12      www       382: }
                    383: 
1.13      www       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'})) {
1.35      bowersj2  397: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1.13      www       398:          $dispcrit=
1.35      bowersj2  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>';
1.13      www       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>
1.37      www       408: <textarea name=message cols=84 rows=10 wrap=hard>
1.13      www       409: $quotemsg
                    410: </textarea><p>
                    411: $dispcrit
                    412: <input type=submit value="Send Reply">
                    413: </form>
                    414: ENDREPLY
                    415: }
                    416: 
1.15      www       417: # ======================================================== Display all messages
                    418: 
1.14      www       419: sub disall {
                    420:     my $r=shift;
1.29      www       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">'.
1.14      www       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>');
1.27      www       447:     foreach (sort split(/\&/,&Apache::lonnet::reply('keys:'.
                    448: 					$ENV{'user.domain'}.':'.
                    449:                                         $ENV{'user.name'}.':nohist_email',
                    450:                                         $ENV{'user.home'}))) {
1.14      www       451:         my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
                    452: 	    &Apache::lonmsg::unpackmsgid($_);
1.39    ! albertel  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>'.
1.14      www       468: 		      &Apache::lonnet::unescape($shortsubj).'</td><td>'.
                    469:                       $status.'</td></tr>');
1.39    ! albertel  470: 	}
1.27      www       471:     }
1.25      www       472:     $r->print('</table><p>'.
1.29      www       473:               '<a href="javascript:checkall()">Check All</a>&nbsp;'.
                    474:               '<a href="javascript:uncheckall()">Uncheck All</a><p>'.
1.25      www       475:               '<input type=submit name="markeddel" value="Delete Checked">'.
                    476:               '</form></body></html>');
1.14      www       477: }
                    478: 
1.15      www       479: # ============================================================== Compose output
                    480: 
                    481: sub compout {
1.17      www       482:     my ($r,$forwarding,$broadcast)=@_;
1.15      www       483:       my $dispcrit='';
                    484:     my $dissub='';
                    485:     my $dismsg='';
                    486:     my $func='Send New';
                    487:       if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
1.35      bowersj2  488: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1.15      www       489:          $dispcrit=
1.35      bowersj2  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>';
1.15      www       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'};
1.37      www       507:     if ($ENV{'form.recdom'}) { $defdom=$ENV{'form.recdom'}; }
1.22      www       508:       $r->print(
1.31      matthew   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>');
1.22      www       513:     unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
1.31      matthew   514:         my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
                    515: 
1.17      www       516:        $r->print(<<"ENDREC");
1.15      www       517: <table>
1.37      www       518: <tr><td>Username:</td><td><input type=text size=12 name=recuname value="$ENV{'form.recname'}"></td></tr>
1.15      www       519: <tr><td>Domain:</td>
1.31      matthew   520: <td>$domform</td></tr>
1.17      www       521: ENDREC
                    522:     }
1.31      matthew   523:     if ($broadcast ne 'upload') {
1.22      www       524:        $r->print(<<"ENDCOMP");
1.20      www       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>
1.15      www       528: <tr><td>Subject:</td><td><input type=text size=50 name=subject value="$dissub">
                    529: </td></tr></table>
1.37      www       530: <textarea name=message cols=80 rows=10 wrap=hard>$dismsg
1.15      www       531: </textarea><p>
                    532: $dispcrit
                    533: <input type=submit value="$func Mail">
                    534: ENDCOMP
1.31      matthew   535:     } else { # $broadcast is 'upload'
1.22      www       536: 	$r->print(<<ENDUPLOAD);
                    537: <input type=hidden name=sendmode value=upload>
                    538: <h3>Generate messages from a file</h3>
1.31      matthew   539: <p>
1.22      www       540: Subject: <input type=text size=50 name=subject>
1.31      matthew   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:
1.22      www       547: <pre>
                    548: username1\@domain1: text
                    549: username2\@domain2: text
1.31      matthew   550: username3\@domain1: text
1.22      www       551: </pre>
1.31      matthew   552: </p>
                    553: <p>
1.22      www       554: The messages will be assembled from all lines with the respective 
1.31      matthew   555: <tt>username\@domain</tt>, and appended to the general message text.</p>
                    556: <p>
1.22      www       557: <input type=file name=upfile size=20><p>
                    558: $dispcrit
                    559: <input type=submit value="Upload and send">
                    560: ENDUPLOAD
                    561:     }
1.17      www       562:     if ($broadcast eq 'group') {
                    563:        &discourse;
                    564:     }
                    565:     $r->print('</form>');
1.15      www       566: }
                    567: 
1.13      www       568: # ===================================================================== Handler
                    569: 
1.5       www       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: 
1.6       www       580: # --------------------------- Get query string for limited number of parameters
1.32      matthew   581:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    582:         ['display','replyto','forward','markread','markdel','markunread',
1.37      www       583:          'sendreply','compose','sendmail','critical','recname','recdom']);
1.6       www       584: 
1.5       www       585: # --------------------------------------------------------------- Render Output
                    586:   
1.37      www       587:   $r->print('<html><head><title>EMail and Messaging</title></head>'.
                    588:             &Apache::loncommon::bodytag('EMail and Messages'));
1.6       www       589:   if ($ENV{'form.display'}) {
1.7       www       590:       my $msgid=$ENV{'form.display'};
                    591:       &statuschange($msgid,'read');
1.8       albertel  592:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7       www       593:       my %content=&unpackagemsg($message{$msgid});
                    594:       $r->print('<b>Subject:</b> '.$content{'subject'}.
1.37      www       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'}.') '.
1.14      www       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>'.
1.15      www       605:            '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).
1.14      www       606:              '"><b>Forward</b></a></td>'.
1.15      www       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>'.
1.14      www       610:              '</tr></table><p><pre>'.
1.36      www       611:              &Apache::lontexconvert::msgtexconverted($content{'message'}).
                    612:              '</pre><hr>'.$content{'citation'});
1.6       www       613:   } elsif ($ENV{'form.replyto'}) {
1.13      www       614:       &comprep($r,$ENV{'form.replyto'});
1.7       www       615:   } elsif ($ENV{'form.sendreply'}) {
                    616:       my $msgid=$ENV{'form.sendreply'};
1.8       albertel  617:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7       www       618:       my %content=&unpackagemsg($message{$msgid});
                    619:       &statuschange($msgid,'replied');
1.24      www       620:       if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
1.12      www       621:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
                    622:          $r->print('Sending critical: '.
                    623:                 &user_crit_msg($content{'sendername'},
1.7       www       624:                                  $content{'senderdomain'},
                    625:                                  $ENV{'form.subject'},
1.24      www       626:                                  $ENV{'form.message'},
                    627:                                  $ENV{'form.sendbck'}));
1.12      www       628:       } else {
                    629:          $r->print('Sending: '.&user_normal_msg($content{'sendername'},
                    630:                                  $content{'senderdomain'},
                    631:                                  $ENV{'form.subject'},
                    632:                                  $ENV{'form.message'}));
                    633:       }
1.14      www       634:       if ($ENV{'form.displayedcrit'}) {
                    635:           &discrit($r);
                    636:       } else {
                    637: 	  &disall($r);
                    638:       }
1.12      www       639:   } elsif ($ENV{'form.confirm'}) {
1.28      harris41  640:       foreach (keys %ENV) {
1.12      www       641:           if ($_=~/^form\.rec\_(.*)$/) {
                    642: 	      $r->print('<b>Confirming Receipt:</b> '.
                    643:                         &user_crit_received($1).'<br>');
1.13      www       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);
1.12      www       650:           }
1.28      harris41  651:       }
1.12      www       652:       &discrit($r);
                    653:   } elsif ($ENV{'form.critical'}) {
                    654:       &discrit($r);
1.6       www       655:   } elsif ($ENV{'form.forward'}) {
1.15      www       656:       &compout($r,$ENV{'form.forward'});
1.14      www       657:   } elsif ($ENV{'form.markread'}) {
                    658:   } elsif ($ENV{'form.markdel'}) {
                    659:       &statuschange($ENV{'form.markdel'},'deleted');
1.25      www       660:       &disall($r);
                    661:   } elsif ($ENV{'form.markeddel'}) {
                    662:       my $total=0;
1.28      harris41  663:       foreach (keys %ENV) {
1.25      www       664:           if ($_=~/^form\.delmark_(.*)$/) {
                    665: 	      &statuschange(&Apache::lonnet::unescape($1),'deleted');
                    666:               $total++;
                    667:           }
1.28      harris41  668:       }
1.25      www       669:       $r->print('Deleted '.$total.' message(s)<p>');
1.14      www       670:       &disall($r);
                    671:   } elsif ($ENV{'form.markunread'}) {
1.15      www       672:       &statuschange($ENV{'form.markunread'},'new');
                    673:       &disall($r);
1.11      www       674:   } elsif ($ENV{'form.compose'}) {
1.17      www       675:       &compout($r,'',$ENV{'form.compose'});
1.11      www       676:   } elsif ($ENV{'form.sendmail'}) {
1.16      www       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:       }
1.18      www       687:       my %toaddr=();
                    688:       undef %toaddr;
                    689:       if ($ENV{'form.sendmode'} eq 'group') {
1.28      harris41  690:           foreach (keys %ENV) {
1.19      www       691: 	      if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
1.22      www       692: 		  $toaddr{$1}='';
1.18      www       693:               }
1.28      harris41  694:           }
1.22      www       695:       } elsif ($ENV{'form.sendmode'} eq 'upload') {
1.28      harris41  696:           foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) {
1.22      www       697:               my ($rec,$txt)=split(/\s*\:\s*/,$_);
                    698:               if ($txt) {
                    699: 		  $rec=~s/\@/\:/;
                    700:                   $toaddr{$rec}.=$txt."\n";
                    701:               }
1.28      harris41  702:           }
1.18      www       703:       } else {
1.22      www       704: 	  $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
1.20      www       705:       }
                    706:       if ($ENV{'form.additionalrec'}) {
1.28      harris41  707: 	  foreach (split(/\,/,$ENV{'form.additionalrec'})) {
1.20      www       708:               my ($auname,$audom)=split(/\@/,$_);
1.22      www       709:               $toaddr{$auname.':'.$audom}='';
1.28      harris41  710:           }
1.18      www       711:       }
1.28      harris41  712:     foreach (keys %toaddr) {
1.18      www       713:       my ($recuname,$recdomain)=split(/\:/,$_);
1.22      www       714:       my $msgtxt=$ENV{'form.message'};
                    715:       if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }    
1.24      www       716:       if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
1.16      www       717:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
                    718:          $r->print('Sending critical: '.
1.18      www       719:                 &user_crit_msg($recuname,$recdomain,
1.16      www       720:                                  $ENV{'form.subject'},
1.22      www       721:                                  $msgtxt,
1.24      www       722:                                  $ENV{'form.sendbck'}));
1.16      www       723:       } else {
1.18      www       724:          $r->print('Sending: '.&user_normal_msg($recuname,$recdomain,
1.16      www       725:                                  $ENV{'form.subject'},
1.22      www       726:                                  $msgtxt,
1.16      www       727:                                  $content{'citation'}));
                    728:       }
1.18      www       729:       $r->print('<br>');
1.28      harris41  730:     }
1.16      www       731:       if ($ENV{'form.displayedcrit'}) {
                    732:           &discrit($r);
                    733:       } else {
                    734: 	  &disall($r);
                    735:       }
1.6       www       736:   } else {
1.14      www       737:       &disall($r);
1.6       www       738:   }
1.5       www       739:   $r->print('</body></html>');
                    740:   return OK;
                    741: 
                    742: }
1.2       www       743: # ================================================= Main program, reset counter
                    744: 
1.27      www       745: BEGIN {
1.2       www       746:     $msgcount=0;
1.1       www       747: }
                    748: 
                    749: 1;
                    750: __END__
                    751: 
                    752: 
                    753: 
                    754: 
                    755: 
                    756: 
                    757: 

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