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

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

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