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

1.1       www         1: # The LearningOnline Network with CAPA
1.26      albertel    2: # Routines for messaging
                      3: #
1.44    ! www         4: # $Id: lonmsg.pm,v 1.43 2002/12/23 18:02:44 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.44    ! www       582: # ---------------------------------------------------------------- Face to face
        !           583: 
        !           584: sub facetoface {
        !           585:     my ($r,$stage)=@_;
        !           586:     unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
        !           587: 	return;
        !           588:     }
        !           589:     my $defdom=$ENV{'user.domain'};
        !           590:     if ($ENV{'form.recdomain'}) { $defdom=$ENV{'form.recdomain'}; }
        !           591:     my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
        !           592:     $r->print(<<"ENDTREC");
        !           593: <h2>User Records of Face-To-Face Discussions and Messages in Course</h2>
        !           594: <form method="post" action="/adm/email">
        !           595: <input type="hidden" name="recordftf" value="retrieve" />
        !           596: <table>
        !           597: <tr><td>Username:</td><td><input type=text size=12 name=recuname value="$ENV{'form.recuname'}"></td>
        !           598: <td rowspan="2">
        !           599: <input type="submit" value="Retrieve discussion and message records"></td>
        !           600: </tr>
        !           601: <tr><td>Domain:</td>
        !           602: <td>$domform</td></tr>
        !           603: </table>
        !           604: </form>
        !           605: ENDTREC
        !           606:     if (($stage ne 'query') &&
        !           607:         ($ENV{'form.recdomain'}) && ($ENV{'form.recuname'})) {
        !           608:         chomp($ENV{'form.newrecord'});
        !           609:         if ($ENV{'form.newrecord'}) {
        !           610: 	    my $subject=
        !           611:                'Record ['.$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}.']';
        !           612:         }
        !           613: 	$r->print(<<ENDRHEAD);
        !           614: <form method="post" action="/adm/email">
        !           615: <input name="recdomain" value="$ENV{'form.recdomain'}" type="hidden" />
        !           616: <input name="recuname" value="$ENV{'form.recuname'}" type="hidden" />
        !           617: ENDRHEAD
        !           618:         $r->print(<<ENDBFORM);
        !           619: <hr />New Record (record is visible to course faculty and staff)<br />
        !           620: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
        !           621: </form>
        !           622: ENDBFORM
        !           623:     }
        !           624: }
        !           625: 
1.13      www       626: # ===================================================================== Handler
                    627: 
1.5       www       628: sub handler {
                    629:     my $r=shift;
                    630: 
                    631: # ----------------------------------------------------------- Set document type
                    632: 
                    633:   $r->content_type('text/html');
                    634:   $r->send_http_header;
                    635: 
                    636:   return OK if $r->header_only;
                    637: 
1.6       www       638: # --------------------------- Get query string for limited number of parameters
1.32      matthew   639:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    640:         ['display','replyto','forward','markread','markdel','markunread',
1.44    ! www       641:          'sendreply','compose','sendmail','critical','recname','recdom',
        !           642:          'recordftf']);
1.6       www       643: 
1.40      www       644: # ------------------------------------------------------ They checked for email
                    645:   &Apache::lonnet::put('email_status',{'recnewemail'=>0});
1.5       www       646: # --------------------------------------------------------------- Render Output
                    647:   
1.37      www       648:   $r->print('<html><head><title>EMail and Messaging</title></head>'.
                    649:             &Apache::loncommon::bodytag('EMail and Messages'));
1.6       www       650:   if ($ENV{'form.display'}) {
1.7       www       651:       my $msgid=$ENV{'form.display'};
                    652:       &statuschange($msgid,'read');
1.8       albertel  653:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7       www       654:       my %content=&unpackagemsg($message{$msgid});
                    655:       $r->print('<b>Subject:</b> '.$content{'subject'}.
1.37      www       656:              '<br><b>From:</b> '.
                    657: &Apache::loncommon::aboutmewrapper(
                    658: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
                    659: $content{'sendername'},$content{'senderdomain'}).' ('.
                    660:                                  $content{'sendername'}.' at '.
                    661:                                  $content{'senderdomain'}.') '.
1.14      www       662:              '<br><b>Time:</b> '.$content{'time'}.'<p>'.
                    663:              '<table border=2><tr bgcolor="#FFFFAA"><td>Functions:</td>'.
                    664:            '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).
                    665:              '"><b>Reply</b></a></td>'.
1.15      www       666:            '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).
1.14      www       667:              '"><b>Forward</b></a></td>'.
1.15      www       668:         '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).
                    669:              '"><b>Mark Unread</b></a></td>'.
1.43      www       670:         '<td><a href="/adm/email?markdel='.&Apache::lonnet::escape($msgid).
                    671:              '"><b>Delete</b></a></td>'.
1.15      www       672:         '<td><a href="/adm/email"><b>Display all Messages</b></a></td>'.
1.14      www       673:              '</tr></table><p><pre>'.
1.36      www       674:              &Apache::lontexconvert::msgtexconverted($content{'message'}).
                    675:              '</pre><hr>'.$content{'citation'});
1.6       www       676:   } elsif ($ENV{'form.replyto'}) {
1.13      www       677:       &comprep($r,$ENV{'form.replyto'});
1.7       www       678:   } elsif ($ENV{'form.sendreply'}) {
                    679:       my $msgid=$ENV{'form.sendreply'};
1.8       albertel  680:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7       www       681:       my %content=&unpackagemsg($message{$msgid});
                    682:       &statuschange($msgid,'replied');
1.24      www       683:       if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
1.12      www       684:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
                    685:          $r->print('Sending critical: '.
                    686:                 &user_crit_msg($content{'sendername'},
1.7       www       687:                                  $content{'senderdomain'},
                    688:                                  $ENV{'form.subject'},
1.24      www       689:                                  $ENV{'form.message'},
                    690:                                  $ENV{'form.sendbck'}));
1.12      www       691:       } else {
                    692:          $r->print('Sending: '.&user_normal_msg($content{'sendername'},
                    693:                                  $content{'senderdomain'},
                    694:                                  $ENV{'form.subject'},
                    695:                                  $ENV{'form.message'}));
                    696:       }
1.14      www       697:       if ($ENV{'form.displayedcrit'}) {
                    698:           &discrit($r);
                    699:       } else {
                    700: 	  &disall($r);
                    701:       }
1.12      www       702:   } elsif ($ENV{'form.confirm'}) {
1.28      harris41  703:       foreach (keys %ENV) {
1.12      www       704:           if ($_=~/^form\.rec\_(.*)$/) {
                    705: 	      $r->print('<b>Confirming Receipt:</b> '.
                    706:                         &user_crit_received($1).'<br>');
1.13      www       707:           }
                    708:           if ($_=~/^form\.reprec\_(.*)$/) {
                    709:               my $msgid=$1;
                    710: 	      $r->print('<b>Confirming Receipt:</b> '.
                    711:                         &user_crit_received($msgid).'<br>');
                    712:               &comprep($r,$msgid);
1.12      www       713:           }
1.28      harris41  714:       }
1.12      www       715:       &discrit($r);
                    716:   } elsif ($ENV{'form.critical'}) {
                    717:       &discrit($r);
1.6       www       718:   } elsif ($ENV{'form.forward'}) {
1.15      www       719:       &compout($r,$ENV{'form.forward'});
1.14      www       720:   } elsif ($ENV{'form.markread'}) {
                    721:   } elsif ($ENV{'form.markdel'}) {
                    722:       &statuschange($ENV{'form.markdel'},'deleted');
1.25      www       723:       &disall($r);
                    724:   } elsif ($ENV{'form.markeddel'}) {
                    725:       my $total=0;
1.28      harris41  726:       foreach (keys %ENV) {
1.25      www       727:           if ($_=~/^form\.delmark_(.*)$/) {
                    728: 	      &statuschange(&Apache::lonnet::unescape($1),'deleted');
                    729:               $total++;
                    730:           }
1.28      harris41  731:       }
1.25      www       732:       $r->print('Deleted '.$total.' message(s)<p>');
1.14      www       733:       &disall($r);
                    734:   } elsif ($ENV{'form.markunread'}) {
1.15      www       735:       &statuschange($ENV{'form.markunread'},'new');
                    736:       &disall($r);
1.11      www       737:   } elsif ($ENV{'form.compose'}) {
1.17      www       738:       &compout($r,'',$ENV{'form.compose'});
1.44    ! www       739:   } elsif ($ENV{'form.recordftf'}) {
        !           740:       &facetoface($r,$ENV{'form.recordftf'});
1.11      www       741:   } elsif ($ENV{'form.sendmail'}) {
1.16      www       742:       my %content=();
                    743:       undef %content;
                    744:       if ($ENV{'form.forwid'}) {
                    745:         my $msgid=$ENV{'form.forwid'};
                    746:         my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
                    747:         %content=&unpackagemsg($message{$msgid});
                    748:         &statuschange($msgid,'forwarded');
                    749:         $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
                    750: 	                       $content{'message'};
                    751:       }
1.18      www       752:       my %toaddr=();
                    753:       undef %toaddr;
                    754:       if ($ENV{'form.sendmode'} eq 'group') {
1.28      harris41  755:           foreach (keys %ENV) {
1.19      www       756: 	      if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
1.22      www       757: 		  $toaddr{$1}='';
1.18      www       758:               }
1.28      harris41  759:           }
1.22      www       760:       } elsif ($ENV{'form.sendmode'} eq 'upload') {
1.28      harris41  761:           foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) {
1.22      www       762:               my ($rec,$txt)=split(/\s*\:\s*/,$_);
                    763:               if ($txt) {
                    764: 		  $rec=~s/\@/\:/;
                    765:                   $toaddr{$rec}.=$txt."\n";
                    766:               }
1.28      harris41  767:           }
1.18      www       768:       } else {
1.22      www       769: 	  $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
1.20      www       770:       }
                    771:       if ($ENV{'form.additionalrec'}) {
1.28      harris41  772: 	  foreach (split(/\,/,$ENV{'form.additionalrec'})) {
1.20      www       773:               my ($auname,$audom)=split(/\@/,$_);
1.22      www       774:               $toaddr{$auname.':'.$audom}='';
1.28      harris41  775:           }
1.18      www       776:       }
1.28      harris41  777:     foreach (keys %toaddr) {
1.18      www       778:       my ($recuname,$recdomain)=split(/\:/,$_);
1.22      www       779:       my $msgtxt=$ENV{'form.message'};
                    780:       if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }    
1.24      www       781:       if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
1.16      www       782:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
                    783:          $r->print('Sending critical: '.
1.18      www       784:                 &user_crit_msg($recuname,$recdomain,
1.16      www       785:                                  $ENV{'form.subject'},
1.22      www       786:                                  $msgtxt,
1.24      www       787:                                  $ENV{'form.sendbck'}));
1.16      www       788:       } else {
1.18      www       789:          $r->print('Sending: '.&user_normal_msg($recuname,$recdomain,
1.16      www       790:                                  $ENV{'form.subject'},
1.22      www       791:                                  $msgtxt,
1.16      www       792:                                  $content{'citation'}));
                    793:       }
1.18      www       794:       $r->print('<br>');
1.28      harris41  795:     }
1.16      www       796:       if ($ENV{'form.displayedcrit'}) {
                    797:           &discrit($r);
                    798:       } else {
                    799: 	  &disall($r);
                    800:       }
1.6       www       801:   } else {
1.14      www       802:       &disall($r);
1.6       www       803:   }
1.5       www       804:   $r->print('</body></html>');
                    805:   return OK;
                    806: 
                    807: }
1.2       www       808: # ================================================= Main program, reset counter
                    809: 
1.27      www       810: BEGIN {
1.2       www       811:     $msgcount=0;
1.1       www       812: }
                    813: 
                    814: 1;
                    815: __END__
                    816: 
                    817: 
                    818: 
                    819: 
                    820: 
                    821: 
                    822: 

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