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

1.1       www         1: # The LearningOnline Network with CAPA
1.26      albertel    2: # Routines for messaging
                      3: #
1.57    ! www         4: # $Id: lonmsg.pm,v 1.56 2003/06/23 22:25:14 albertel 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);
1.47      albertel   50: use HTML::TokeParser();
1.5       www        51: use Apache::Constants qw(:common);
1.47      albertel   52: use Apache::loncommon();
                     53: use Apache::lontexconvert();
                     54: use HTML::Entities();
1.53      www        55: use Mail::Send;
1.1       www        56: 
                     57: # ===================================================================== Package
                     58: 
1.3       www        59: sub packagemsg {
1.51      www        60:     my ($subject,$message,$citation,$baseurl,$attachmenturl)=@_;
1.47      albertel   61:     $message =&HTML::Entities::encode($message);
                     62:     $citation=&HTML::Entities::encode($citation);
                     63:     $subject =&HTML::Entities::encode($subject);
1.49      albertel   64:     #remove machine specification
                     65:     $baseurl =~ s|^http://[^/]+/|/|;
                     66:     $baseurl =&HTML::Entities::encode($baseurl);
1.51      www        67:     #remove machine specification
                     68:     $attachmenturl =~ s|^http://[^/]+/|/|;
1.52      www        69:     $attachmenturl =&HTML::Entities::encode($attachmenturl);
1.51      www        70: 
1.2       www        71:     my $now=time;
                     72:     $msgcount++;
1.6       www        73:     my $partsubj=$subject;
                     74:     $partsubj=&Apache::lonnet::escape($partsubj);
                     75:     my $msgid=&Apache::lonnet::escape(
                     76:            $now.':'.$partsubj.':'.$ENV{'user.name'}.':'.
                     77:            $ENV{'user.domain'}.':'.$msgcount.':'.$$);
1.49      albertel   78:     my $result='<sendername>'.$ENV{'user.name'}.'</sendername>'.
1.1       www        79:            '<senderdomain>'.$ENV{'user.domain'}.'</senderdomain>'.
                     80:            '<subject>'.$subject.'</subject>'.
1.2       www        81: 	   '<time>'.localtime($now).'</time>'.
1.1       www        82: 	   '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
                     83:            '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
                     84: 	   '<client>'.$ENV{'REMOTE_ADDR'}.'</client>'.
                     85: 	   '<browsertype>'.$ENV{'browser.type'}.'</browsertype>'.
                     86: 	   '<browseros>'.$ENV{'browser.os'}.'</browseros>'.
                     87: 	   '<browserversion>'.$ENV{'browser.version'}.'</browserversion>'.
                     88:            '<browsermathml>'.$ENV{'browser.mathml'}.'</browsermathml>'.
                     89: 	   '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
                     90: 	   '<courseid>'.$ENV{'request.course.id'}.'</courseid>'.
                     91: 	   '<role>'.$ENV{'request.role'}.'</role>'.
                     92: 	   '<resource>'.$ENV{'request.filename'}.'</resource>'.
1.2       www        93:            '<msgid>'.$msgid.'</msgid>'.
1.49      albertel   94: 	   '<message>'.$message.'</message>';
                     95:     if (defined($citation)) {
                     96: 	$result.='<citation>'.$citation.'</citation>';
                     97:     }
                     98:     if (defined($baseurl)) {
                     99: 	$result.= '<baseurl>'.$baseurl.'</baseurl>';
                    100:     }
1.51      www       101:     if (defined($attachmenturl)) {
1.52      www       102: 	$result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>';
1.51      www       103:     }
1.49      albertel  104:     return $msgid,$result;
1.1       www       105: }
                    106: 
1.2       www       107: # ================================================== Unpack message into a hash
                    108: 
1.3       www       109: sub unpackagemsg {
1.52      www       110:     my ($message,$notoken)=@_;
1.2       www       111:     my %content=();
                    112:     my $parser=HTML::TokeParser->new(\$message);
                    113:     my $token;
                    114:     while ($token=$parser->get_token) {
                    115:        if ($token->[0] eq 'S') {
                    116: 	   my $entry=$token->[1];
                    117:            my $value=$parser->get_text('/'.$entry);
                    118:            $content{$entry}=$value;
                    119:        }
                    120:     }
1.52      www       121:     if ($content{'attachmenturl'}) {
                    122:        my ($fname,$ft)=($content{'attachmenturl'}=~/\/(\w+)\.(\w+)$/);
                    123:        if ($notoken) {
                    124: 	   $content{'message'}.='<p>Attachment: <tt>'.$fname.'.'.$ft.'</tt>';
                    125:        } else {
                    126: 	   $content{'message'}.='<p>Attachment: <a href="'.
                    127: 	       &Apache::lonnet::tokenwrapper($content{'attachmenturl'}).
                    128: 	       '"><tt>'.$fname.'.'.$ft.'</tt></a>';
                    129:        }
                    130:     }
1.2       www       131:     return %content;
                    132: }
                    133: 
1.6       www       134: # ======================================================= Get info out of msgid
                    135: 
                    136: sub unpackmsgid {
1.7       www       137:     my $msgid=&Apache::lonnet::unescape(shift);
1.6       www       138:     my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/,
1.7       www       139:                           &Apache::lonnet::unescape($msgid));
1.8       albertel  140:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
1.6       www       141:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
                    142:     unless ($status{$msgid}) { $status{$msgid}='new'; }
                    143:     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});
                    144: } 
                    145: 
1.53      www       146: 
                    147: sub sendemail {
                    148:     my ($to,$subject,$body)=@_;
                    149:     $body=
                    150:     "*** This is an automatic message generated by the LON-CAPA system.\n".
                    151:     "*** Please do not reply to this address.\n\n".$body;
                    152:     my $msg = new Mail::Send;
                    153:     $msg->to($to);
                    154:     $msg->subject('[LON-CAPA] '.$subject);
                    155:     my $fh = $msg->open('smtp',Server => 'localhost');
                    156:     print $fh $body;
                    157:     $fh->close;
                    158: }
                    159: 
                    160: # ==================================================== Send notification emails
                    161: 
                    162: sub sendnotification {
                    163:     my ($to,$touname,$toudom,$subj,$crit)=@_;
                    164:     my $sender=$ENV{'environment.firstname'}.' '.$ENV{'environment.lastname'};
                    165:     my $critical=($crit?' critical':'');
                    166:     my $url='http://'.
                    167:       $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}.
1.54      www       168:       '/adm/email?username='.$touname.'&domain='.$toudom;
1.53      www       169:     my $body=(<<ENDMSG);
                    170: You received a$critical message from $sender in LON-CAPA. The subject is
                    171: 
                    172:  $subj
                    173: 
                    174: Use
                    175: 
                    176:  $url
                    177: 
                    178: to access this message.
                    179: ENDMSG
                    180:     &sendemail($to,'New'.$critical.' message from '.$sender,$body);
                    181: }
1.40      www       182: # ============================================================= Check for email
                    183: 
                    184: sub newmail {
                    185:     if ((time-$ENV{'user.mailcheck.time'})>300) {
                    186:         my %what=&Apache::lonnet::get('email_status',['recnewemail']);
                    187:         &Apache::lonnet::appenv('user.mailcheck.time'=>time);
                    188:         if ($what{'recnewemail'}>0) { return 1; }
                    189:     }
                    190:     return 0;
                    191: }
                    192: 
1.1       www       193: # =============================== Automated message to the author of a resource
                    194: 
                    195: sub author_res_msg {
                    196:     my ($filename,$message)=@_;
1.2       www       197:     unless ($message) { return 'empty'; }
1.1       www       198:     $filename=&Apache::lonnet::declutter($filename);
                    199:     my ($domain,$author,@dummy)=split(/\//,$filename);
                    200:     my $homeserver=&Apache::lonnet::homeserver($author,$domain);
                    201:     if ($homeserver ne 'no_host') {
                    202:        my $id=unpack("%32C*",$message);
1.2       www       203:        my $msgid;
1.3       www       204:        ($msgid,$message)=&packagemsg($filename,$message);
                    205:        return &Apache::lonnet::reply('put:'.$domain.':'.$author.
                    206:          ':nohist_res_msgs:'.
                    207:           &Apache::lonnet::escape($filename.'_'.$id).'='.
                    208:           &Apache::lonnet::escape($message),$homeserver);
1.1       www       209:     }
1.2       www       210:     return 'no_host';
1.1       www       211: }
                    212: 
                    213: # ================================================== Critical message to a user
                    214: 
1.38      www       215: sub user_crit_msg_raw {
1.24      www       216:     my ($user,$domain,$subject,$message,$sendback)=@_;
1.2       www       217: # Check if allowed missing
                    218:     my $status='';
                    219:     my $msgid='undefined';
                    220:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
                    221:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
                    222:     if ($homeserver ne 'no_host') {
1.3       www       223:        ($msgid,$message)=&packagemsg($subject,$message);
1.24      www       224:        if ($sendback) { $message.='<sendback>true</sendback>'; }
1.4       www       225:        $status=&Apache::lonnet::critical(
                    226:            'put:'.$domain.':'.$user.':critical:'.
                    227:            &Apache::lonnet::escape($msgid).'='.
                    228:            &Apache::lonnet::escape($message),$homeserver);
1.45      www       229:        if ($ENV{'request.course.id'}) {
                    230:           &user_normal_msg_raw(
                    231:             $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
                    232:             $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    233:             'Critical ['.$user.':'.$domain.']',
                    234: 	    $message);
                    235:        }
1.2       www       236:     } else {
                    237:        $status='no_host';
                    238:     }
1.53      www       239: # Notifications
                    240:     my %userenv = &Apache::lonnet::get('environment',['critnotification'],
                    241:                                        $domain,$user);
                    242:     if ($userenv{'critnotification'}) {
                    243:       &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1);
                    244:     }
                    245: # Log this
1.2       www       246:     &Apache::lonnet::logthis(
1.4       www       247:       'Sending critical email '.$msgid.
1.2       www       248:       ', log status: '.
                    249:       &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
                    250:                          $ENV{'user.home'},
                    251:       'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
1.4       www       252:       .$status));
1.2       www       253:     return $status;
                    254: }
                    255: 
1.38      www       256: # New routine that respects "forward" and calls old routine
                    257: 
                    258: sub user_crit_msg {
                    259:     my ($user,$domain,$subject,$message,$sendback)=@_;
                    260:     my $status='';
                    261:     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
                    262:                                        $domain,$user);
                    263:     my $msgforward=$userenv{'msgforward'};
                    264:     if ($msgforward) {
                    265:        foreach (split(/\,/,$msgforward)) {
                    266: 	 my ($forwuser,$forwdomain)=split(/\:/,$_);
                    267:          $status.=
                    268: 	   &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
                    269:                 $sendback).' ';
                    270:        }
                    271:     } else { 
                    272: 	$status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback);
                    273:     }
                    274:     return $status;
                    275: }
                    276: 
1.2       www       277: # =================================================== Critical message received
                    278: 
                    279: sub user_crit_received {
1.12      www       280:     my $msgid=shift;
                    281:     my %message=&Apache::lonnet::get('critical',[$msgid]);
1.52      www       282:     my %contents=&unpackagemsg($message{$msgid},1);
1.24      www       283:     my $status='rec: '.($contents{'sendback'}?
1.5       www       284:      &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
1.4       www       285:                      'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'},
                    286:                      'User '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}.
1.42      www       287:                      ' acknowledged receipt of message'."\n".'   "'.
                    288:                      $contents{'subject'}.'"'."\n".'dated '.
                    289:                      $contents{'time'}.".\n"
                    290:                      ):'no msg req');
1.5       www       291:     $status.=' trans: '.
1.12      www       292:      &Apache::lonnet::put(
                    293:      'nohist_email',{$contents{'msgid'} => $message{$msgid}});
1.5       www       294:     $status.=' del: '.
1.9       albertel  295:      &Apache::lonnet::del('critical',[$contents{'msgid'}]);
1.5       www       296:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
                    297:                          $ENV{'user.home'},'Received critical message '.
                    298:                          $contents{'msgid'}.
                    299:                          ', '.$status);
1.12      www       300:     return $status;
1.2       www       301: }
                    302: 
                    303: # ======================================================== Normal communication
                    304: 
1.38      www       305: sub user_normal_msg_raw {
1.51      www       306:     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_;
1.2       www       307: # Check if allowed missing
                    308:     my $status='';
                    309:     my $msgid='undefined';
                    310:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
                    311:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
                    312:     if ($homeserver ne 'no_host') {
1.51      www       313:        ($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl,
                    314:                                      $attachmenturl);
1.4       www       315:        $status=&Apache::lonnet::critical(
                    316:            'put:'.$domain.':'.$user.':nohist_email:'.
                    317:            &Apache::lonnet::escape($msgid).'='.
                    318:            &Apache::lonnet::escape($message),$homeserver);
1.40      www       319:        &Apache::lonnet::put
                    320:                          ('email_status',{'recnewemail'=>time},$domain,$user);
1.2       www       321:     } else {
                    322:        $status='no_host';
1.53      www       323:     }
                    324: # Notifications
                    325:     my %userenv = &Apache::lonnet::get('environment',['notification'],
                    326:                                        $domain,$user);
                    327:     if ($userenv{'notification'}) {
                    328: 	&sendnotification($userenv{'notification'},$user,$domain,$subject,0);
1.2       www       329:     }
                    330:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
                    331:                          $ENV{'user.home'},
                    332:       'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
                    333:     return $status;
                    334: }
1.38      www       335: 
                    336: # New routine that respects "forward" and calls old routine
                    337: 
                    338: sub user_normal_msg {
1.52      www       339:     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_;
1.38      www       340:     my $status='';
                    341:     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
                    342:                                        $domain,$user);
                    343:     my $msgforward=$userenv{'msgforward'};
                    344:     if ($msgforward) {
                    345:        foreach (split(/\,/,$msgforward)) {
                    346: 	 my ($forwuser,$forwdomain)=split(/\:/,$_);
                    347:          $status.=
                    348: 	  &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
1.52      www       349: 			       $citation,$baseurl,$attachmenturl).' ';
1.38      www       350:        }
                    351:     } else { 
1.49      albertel  352: 	$status=&user_normal_msg_raw($user,$domain,$subject,$message,
1.52      www       353: 				     $citation,$baseurl,$attachmenturl);
1.38      www       354:     }
                    355:     return $status;
                    356: }
                    357: 
1.2       www       358: 
1.7       www       359: # =============================================================== Status Change
                    360: 
                    361: sub statuschange {
                    362:     my ($msgid,$newstatus)=@_;
1.8       albertel  363:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
1.7       www       364:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
                    365:     unless ($status{$msgid}) { $status{$msgid}='new'; }
                    366:     unless (($status{$msgid} eq 'replied') || 
                    367:             ($status{$msgid} eq 'forwarded')) {
1.10      albertel  368: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
1.7       www       369:     }
1.14      www       370:     if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
                    371: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
                    372:     }
1.7       www       373: }
1.14      www       374: 
1.17      www       375: # ======================================================= Display a course list
                    376: 
                    377: sub discourse {
                    378:     my $r=shift;
                    379:     my %courselist=&Apache::lonnet::dump(
                    380:                    'classlist',
                    381: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    382: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    383:     my $now=time;
                    384:     $r->print(<<ENDDISHEADER);
                    385: <input type=hidden name=sendmode value=group>
                    386: <script>
                    387:     function checkall() {
                    388: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
                    389:             if 
                    390:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
                    391: 	      document.forms.compemail.elements[i].checked=true;
                    392:             }
                    393:         }
                    394:     }
                    395: 
1.19      www       396:     function checksec() {
                    397: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
                    398:             if 
                    399:           (document.forms.compemail.elements[i].name.indexOf
                    400:            ('send_to_&&&'+document.forms.compemail.chksec.value)==0) {
                    401: 	      document.forms.compemail.elements[i].checked=true;
                    402:             }
                    403:         }
                    404:     }
                    405: 
1.17      www       406:     function uncheckall() {
                    407: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
                    408:             if 
                    409:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
                    410: 	      document.forms.compemail.elements[i].checked=false;
                    411:             }
                    412:         }
                    413:     }
                    414: </script>
1.19      www       415: <input type=button onClick="checkall()" value="Check for All">&nbsp;
                    416: <input type=button onClick="checksec()" value="Check for Section/Group">
                    417: <input type=text size=5 name=chksec>&nbsp;
1.17      www       418: <input type=button onClick="uncheckall()" value="Check for None">
                    419: <p>
                    420: ENDDISHEADER
1.28      harris41  421:     foreach (sort keys %courselist) {
1.17      www       422:         my ($end,$start)=split(/\:/,$courselist{$_});
                    423:         my $active=1;
                    424:         if (($end) && ($now>$end)) { $active=0; }
                    425:         if ($active) {
                    426:            my ($sname,$sdom)=split(/\:/,$_);
                    427:            my %reply=&Apache::lonnet::get('environment',
                    428:               ['firstname','middlename','lastname','generation'],
                    429:               $sdom,$sname);
1.19      www       430:            my $section=&Apache::lonnet::usection
                    431: 	       ($sdom,$sname,$ENV{'request.course.id'});
                    432:            $r->print(
                    433:         '<br><input type=checkbox name="send_to_&&&'.$section.'&&&_'.$_.'"> '.
1.17      www       434: 		      $reply{'firstname'}.' '. 
                    435:                       $reply{'middlename'}.' '.
                    436:                       $reply{'lastname'}.' '.
                    437:                       $reply{'generation'}.
1.19      www       438:                       ' ('.$_.') '.$section);
1.17      www       439:         } 
1.28      harris41  440:     }
1.17      www       441: }
                    442: 
1.13      www       443: # ==================================================== Display Critical Message
1.5       www       444: 
1.12      www       445: sub discrit {
                    446:     my $r=shift;
1.30      matthew   447:     my $header = '<h1><font color=red>Critical Messages</font></h1>'.
                    448:         '<form action=/adm/email method=post>'.
                    449:         '<input type=hidden name=confirm value=true>';
                    450:     my %what=&Apache::lonnet::dump('critical');
                    451:     my $result = '';
                    452:     foreach (sort keys %what) {
                    453:         my %content=&unpackagemsg($what{$_});
                    454:         next if ($content{'senderdomain'} eq '');
                    455:         $content{'message'}=~s/\n/\<br\>/g;
1.37      www       456:         $result.='<hr>From: <b>'.
                    457: &Apache::loncommon::aboutmewrapper(
                    458:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
                    459: $content{'sendername'}.'@'.
                    460:             $content{'senderdomain'}.') '.$content{'time'}.
                    461:             '<br>Subject: '.$content{'subject'}.
1.36      www       462:             '<br><blockquote>'.
                    463:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
                    464:             '</blockquote>'.
1.30      matthew   465:             '<input type=submit name="rec_'.$_.'" value="Confirm Receipt">'.
                    466:             '<input type=submit name="reprec_'.$_.'" '.
                    467:                   'value="Confirm Receipt and Reply">';
                    468:     }
                    469:     # Check to see if there were any messages.
                    470:     if ($result eq '') {
                    471:         $result = "<h2>You have no critical messages.</h2>";
                    472:     } else {
                    473:         $r->print($header);
                    474:     }
                    475:     $r->print($result);
                    476:     $r->print('<input type=hidden name="displayedcrit" value="true"></form>');
1.12      www       477: }
                    478: 
1.13      www       479: # =============================================================== Compose reply
                    480: 
                    481: sub comprep {
                    482:     my ($r,$msgid)=@_;
                    483:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.52      www       484:       my %content=&unpackagemsg($message{$msgid},1);
1.13      www       485:       my $quotemsg='> '.$content{'message'};
                    486:       $quotemsg=~s/\r/\n/g;
                    487:       $quotemsg=~s/\f/\n/g;
                    488:       $quotemsg=~s/\n+/\n\> /g;
1.57    ! www       489:       my $torepl=&Apache::loncommon::aboutmewrapper(
        !           490:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
        !           491: $content{'sendername'}.'@'.
        !           492:             $content{'senderdomain'}.')';
1.13      www       493:       my $subject='Re: '.$content{'subject'};
                    494:       my $dispcrit='';
                    495:       if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
1.35      bowersj2  496: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1.13      www       497:          $dispcrit=
1.35      bowersj2  498:  '<input type=checkbox name=critmsg> Send as critical message ' . $crithelp . 
                    499:  '<br>'.
                    500:  '<input type=checkbox name=sendbck> Send as critical message ' .
                    501:  ' and return receipt' . $crithelp . '<p>';
1.13      www       502:       }
                    503:       $r->print(<<"ENDREPLY");
                    504: <form action="/adm/email" method=post>
                    505: <input type=hidden name=sendreply value="$msgid">
1.57    ! www       506: To: $torepl<br />
1.13      www       507: Subject: <input type=text size=50 name=subject value="$subject"><p>
1.37      www       508: <textarea name=message cols=84 rows=10 wrap=hard>
1.13      www       509: $quotemsg
                    510: </textarea><p>
                    511: $dispcrit
                    512: <input type=submit value="Send Reply">
                    513: </form>
                    514: ENDREPLY
                    515: }
                    516: 
1.15      www       517: # ======================================================== Display all messages
                    518: 
1.14      www       519: sub disall {
                    520:     my $r=shift;
1.29      www       521:      $r->print(<<ENDDISHEADER);
                    522: <script>
                    523:     function checkall() {
                    524: 	for (i=0; i<document.forms.disall.elements.length; i++) {
                    525:             if 
                    526:           (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
                    527: 	      document.forms.disall.elements[i].checked=true;
                    528:             }
                    529:         }
                    530:     }
                    531: 
                    532:     function uncheckall() {
                    533: 	for (i=0; i<document.forms.disall.elements.length; i++) {
                    534:             if 
                    535:           (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
                    536: 	      document.forms.disall.elements[i].checked=false;
                    537:             }
                    538:         }
                    539:     }
                    540: </script>
                    541: ENDDISHEADER
                    542:    $r->print(
                    543:  '<h1>Display All Messages</h1><form method=post name=disall '.
                    544:  'action="/adm/email">'.
1.14      www       545:      '<table border=2><tr><th colspan=2>&nbsp</th><th>Date</th>'.
                    546:      '<th>Username</th><th>Domain</th><th>Subject</th><th>Status</th></tr>');
1.27      www       547:     foreach (sort split(/\&/,&Apache::lonnet::reply('keys:'.
                    548: 					$ENV{'user.domain'}.':'.
                    549:                                         $ENV{'user.name'}.':nohist_email',
                    550:                                         $ENV{'user.home'}))) {
1.14      www       551:         my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
                    552: 	    &Apache::lonmsg::unpackmsgid($_);
1.39      albertel  553: 	if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
                    554: 	    if ($status eq 'new') {
                    555: 		$r->print('<tr bgcolor="#FFBB77">');
                    556: 	    } elsif ($status eq 'read') {
                    557: 		$r->print('<tr bgcolor="#BBBB77">');
                    558: 	    } elsif ($status eq 'replied') {
                    559: 		$r->print('<tr bgcolor="#AAAA88">');
                    560: 	    } else {
                    561: 		$r->print('<tr bgcolor="#99BBBB">');
                    562: 	    }
                    563: 	    $r->print('<td><a href="/adm/email?display='.$_.
                    564: 		      '">Open</a></td><td><a href="/adm/email?markdel='.$_.
                    565: 		      '">Delete</a><input type=checkbox name="delmark_'.$_.'"></td>'.
                    566: 		      '<td>'.localtime($sendtime).'</td><td>'.
                    567: 		      $fromname.'</td><td>'.$fromdomain.'</td><td>'.
1.14      www       568: 		      &Apache::lonnet::unescape($shortsubj).'</td><td>'.
                    569:                       $status.'</td></tr>');
1.39      albertel  570: 	}
1.27      www       571:     }
1.25      www       572:     $r->print('</table><p>'.
1.29      www       573:               '<a href="javascript:checkall()">Check All</a>&nbsp;'.
                    574:               '<a href="javascript:uncheckall()">Uncheck All</a><p>'.
1.25      www       575:               '<input type=submit name="markeddel" value="Delete Checked">'.
                    576:               '</form></body></html>');
1.14      www       577: }
                    578: 
1.15      www       579: # ============================================================== Compose output
                    580: 
                    581: sub compout {
1.17      www       582:     my ($r,$forwarding,$broadcast)=@_;
1.15      www       583:       my $dispcrit='';
                    584:     my $dissub='';
                    585:     my $dismsg='';
                    586:     my $func='Send New';
                    587:       if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
1.35      bowersj2  588: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1.15      www       589:          $dispcrit=
1.35      bowersj2  590:  '<input type=checkbox name=critmsg> Send as critical message ' . $crithelp . 
                    591:  '<br>'.
                    592:  '<input type=checkbox name=sendbck> Send as critical message ' .
                    593:  ' and return receipt' . $crithelp . '<p>';
1.15      www       594:       }
                    595:     if ($forwarding) {
                    596:        $dispcrit.='<input type=hidden name=forwid value="'.
                    597: 	   $forwarding.'">';
                    598:        $func='Forward';
                    599:       my %message=&Apache::lonnet::get('nohist_email',[$forwarding]);
                    600:       my %content=&unpackagemsg($message{$forwarding});
                    601: 
                    602:        $dissub='Forwarding: '.$content{'subject'};
                    603:        $dismsg='Forwarded message from '.
                    604: 	   $content{'sendername'}.' at '.$content{'senderdomain'};
                    605:     }
                    606:     my $defdom=$ENV{'user.domain'};
1.37      www       607:     if ($ENV{'form.recdom'}) { $defdom=$ENV{'form.recdom'}; }
1.22      www       608:       $r->print(
1.31      matthew   609:                 '<form action="/adm/email"  name="compemail" method="post"'.
                    610:                 ' enctype="multipart/form-data">'."\n".
                    611:                 '<input type="hidden" name="sendmail" value="on">'."\n".
                    612:                 '<table>');
1.22      www       613:     unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
1.31      matthew   614:         my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
1.46      www       615:         my $selectlink=&Apache::loncommon::selectstudent_link
                    616: 	    ('compemail','recuname','recdomain');
1.17      www       617:        $r->print(<<"ENDREC");
1.15      www       618: <table>
1.46      www       619: <tr><td>Username:</td><td><input type=text size=12 name=recuname value="$ENV{'form.recname'}"></td><td rowspan="2">$selectlink</td></tr>
1.15      www       620: <tr><td>Domain:</td>
1.31      matthew   621: <td>$domform</td></tr>
1.17      www       622: ENDREC
                    623:     }
1.55      bowersj2  624:     my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
1.31      matthew   625:     if ($broadcast ne 'upload') {
1.22      www       626:        $r->print(<<"ENDCOMP");
1.20      www       627: <tr><td>Additional Recipients<br><tt>username\@domain,username\@domain, ...
                    628: </tt></td><td>
                    629: <input type=text size=50 name=additionalrec></td></tr>
1.15      www       630: <tr><td>Subject:</td><td><input type=text size=50 name=subject value="$dissub">
                    631: </td></tr></table>
1.55      bowersj2  632: $latexHelp
1.37      www       633: <textarea name=message cols=80 rows=10 wrap=hard>$dismsg
1.15      www       634: </textarea><p>
                    635: $dispcrit
                    636: <input type=submit value="$func Mail">
                    637: ENDCOMP
1.31      matthew   638:     } else { # $broadcast is 'upload'
1.22      www       639: 	$r->print(<<ENDUPLOAD);
                    640: <input type=hidden name=sendmode value=upload>
                    641: <h3>Generate messages from a file</h3>
1.31      matthew   642: <p>
1.22      www       643: Subject: <input type=text size=50 name=subject>
1.31      matthew   644: </p>
                    645: <p>General message text<br />
                    646: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
                    647: </textarea></p>
                    648: <p>
                    649: The file format for the uploaded portion of the message is:
1.22      www       650: <pre>
                    651: username1\@domain1: text
                    652: username2\@domain2: text
1.31      matthew   653: username3\@domain1: text
1.22      www       654: </pre>
1.31      matthew   655: </p>
                    656: <p>
1.22      www       657: The messages will be assembled from all lines with the respective 
1.31      matthew   658: <tt>username\@domain</tt>, and appended to the general message text.</p>
                    659: <p>
1.22      www       660: <input type=file name=upfile size=20><p>
                    661: $dispcrit
                    662: <input type=submit value="Upload and send">
                    663: ENDUPLOAD
                    664:     }
1.17      www       665:     if ($broadcast eq 'group') {
                    666:        &discourse;
                    667:     }
                    668:     $r->print('</form>');
1.15      www       669: }
                    670: 
1.45      www       671: # ---------------------------------------------------- Display all face to face
                    672: 
                    673: sub disfacetoface {
                    674:     my ($r,$user,$domain)=@_;
                    675:     unless ($ENV{'request.course.id'}) { return; }
                    676:     unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
                    677: 	return;
                    678:     }
                    679:     my %records=&Apache::lonnet::dump('nohist_email',
                    680: 			 $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    681: 			 $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
                    682:                          '%255b'.$user.'%253a'.$domain.'%255d');
                    683:     my $result='';
                    684:     foreach (sort keys %records) {
                    685:         my %content=&unpackagemsg($records{$_});
                    686:         next if ($content{'senderdomain'} eq '');
                    687:         $content{'message'}=~s/\n/\<br\>/g;
                    688:         if ($content{'subject'}=~/^Record/) {
                    689: 	    $result.='<h3>Record</h3>';
                    690:         } else {
                    691:             $result.='<h3>Sent Message</h3>';
                    692:             %content=&unpackagemsg($content{'message'});
                    693:             $content{'message'}=
                    694:                 '<b>Subject: '.$content{'subject'}.'</b><br />'.
                    695: 		$content{'message'};
                    696:         }
                    697:         $result.='By: <b>'.
                    698: &Apache::loncommon::aboutmewrapper(
                    699:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
                    700: $content{'sendername'}.'@'.
                    701:             $content{'senderdomain'}.') '.$content{'time'}.
                    702:             '<br><blockquote>'.
                    703:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
                    704: 	      '</blockquote>';
                    705:      }
                    706:     # Check to see if there were any messages.
                    707:     if ($result eq '') {
1.46      www       708:         $r->print("<p><b>No notes, face-to-face discussion records, or critical messages in this course.</b></p>");
1.45      www       709:     } else {
                    710:        $r->print($result);
                    711:     }
                    712: }
                    713: 
1.44      www       714: # ---------------------------------------------------------------- Face to face
                    715: 
                    716: sub facetoface {
                    717:     my ($r,$stage)=@_;
                    718:     unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
                    719: 	return;
                    720:     }
1.46      www       721: # from query string
                    722:     if ($ENV{'form.recname'}) { $ENV{'form.recuname'}=$ENV{'form.recname'}; }
                    723:     if ($ENV{'form.recdom'}) { $ENV{'form.recdomain'}=$ENV{'form.recdom'}; }
                    724: 
1.44      www       725:     my $defdom=$ENV{'user.domain'};
1.46      www       726: # already filled in
1.44      www       727:     if ($ENV{'form.recdomain'}) { $defdom=$ENV{'form.recdomain'}; }
1.46      www       728: # generate output
1.44      www       729:     my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
1.46      www       730:     my $stdbrws = &Apache::loncommon::selectstudent_link
                    731: 	('stdselect','recuname','recdomain');
1.44      www       732:     $r->print(<<"ENDTREC");
1.46      www       733: <h3>User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course</h3>
                    734: <form method="post" action="/adm/email" name="stdselect">
1.44      www       735: <input type="hidden" name="recordftf" value="retrieve" />
                    736: <table>
                    737: <tr><td>Username:</td><td><input type=text size=12 name=recuname value="$ENV{'form.recuname'}"></td>
                    738: <td rowspan="2">
1.46      www       739: $stdbrws
1.44      www       740: <input type="submit" value="Retrieve discussion and message records"></td>
                    741: </tr>
                    742: <tr><td>Domain:</td>
                    743: <td>$domform</td></tr>
                    744: </table>
                    745: </form>
                    746: ENDTREC
                    747:     if (($stage ne 'query') &&
                    748:         ($ENV{'form.recdomain'}) && ($ENV{'form.recuname'})) {
                    749:         chomp($ENV{'form.newrecord'});
                    750:         if ($ENV{'form.newrecord'}) {
1.45      www       751:            &user_normal_msg_raw(
                    752:             $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
                    753:             $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    754:             'Record ['.$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}.']',
                    755: 	    $ENV{'form.newrecord'});
1.44      www       756:         }
1.46      www       757:         $r->print('<h3>'.&Apache::loncommon::plainname($ENV{'form.recuname'},
                    758: 				     $ENV{'form.recdomain'}).'</h3>');
1.45      www       759:         &disfacetoface($r,$ENV{'form.recuname'},$ENV{'form.recdomain'});
1.44      www       760: 	$r->print(<<ENDRHEAD);
                    761: <form method="post" action="/adm/email">
                    762: <input name="recdomain" value="$ENV{'form.recdomain'}" type="hidden" />
                    763: <input name="recuname" value="$ENV{'form.recuname'}" type="hidden" />
                    764: ENDRHEAD
                    765:         $r->print(<<ENDBFORM);
                    766: <hr />New Record (record is visible to course faculty and staff)<br />
                    767: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
1.45      www       768: <br />
                    769: <input type="hidden" name="recordftf" value="post" />
                    770: <input type="submit" value="Post this record" />
1.44      www       771: </form>
                    772: ENDBFORM
                    773:     }
                    774: }
                    775: 
1.13      www       776: # ===================================================================== Handler
                    777: 
1.5       www       778: sub handler {
                    779:     my $r=shift;
                    780: 
                    781: # ----------------------------------------------------------- Set document type
                    782: 
                    783:   $r->content_type('text/html');
                    784:   $r->send_http_header;
                    785: 
                    786:   return OK if $r->header_only;
                    787: 
1.6       www       788: # --------------------------- Get query string for limited number of parameters
1.32      matthew   789:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    790:         ['display','replyto','forward','markread','markdel','markunread',
1.44      www       791:          'sendreply','compose','sendmail','critical','recname','recdom',
                    792:          'recordftf']);
1.6       www       793: 
1.40      www       794: # ------------------------------------------------------ They checked for email
                    795:   &Apache::lonnet::put('email_status',{'recnewemail'=>0});
1.5       www       796: # --------------------------------------------------------------- Render Output
1.49      albertel  797:   if (!$ENV{'form.display'}) {
                    798:       $r->print('<html><head><title>EMail and Messaging</title>'.
                    799: 		&Apache::loncommon::studentbrowser_javascript().'</head>'.
                    800: 		&Apache::loncommon::bodytag('EMail and Messages'));
                    801:   }
1.6       www       802:   if ($ENV{'form.display'}) {
1.7       www       803:       my $msgid=$ENV{'form.display'};
                    804:       &statuschange($msgid,'read');
1.8       albertel  805:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7       www       806:       my %content=&unpackagemsg($message{$msgid});
1.49      albertel  807:       $r->print('<html><head><title>EMail and Messaging</title>');
                    808:       if (defined($content{'baseurl'})) {
                    809: 	  $r->print("<base href=\"http://$ENV{'SERVER_NAME'}/$content{'baseurl'}\" />");
                    810:       }
                    811:       $r->print(&Apache::loncommon::studentbrowser_javascript().
                    812: 		'</head>'.
                    813: 		&Apache::loncommon::bodytag('EMail and Messages'));
1.7       www       814:       $r->print('<b>Subject:</b> '.$content{'subject'}.
1.37      www       815:              '<br><b>From:</b> '.
                    816: &Apache::loncommon::aboutmewrapper(
                    817: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
                    818: $content{'sendername'},$content{'senderdomain'}).' ('.
                    819:                                  $content{'sendername'}.' at '.
                    820:                                  $content{'senderdomain'}.') '.
1.14      www       821:              '<br><b>Time:</b> '.$content{'time'}.'<p>'.
                    822:              '<table border=2><tr bgcolor="#FFFFAA"><td>Functions:</td>'.
                    823:            '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).
                    824:              '"><b>Reply</b></a></td>'.
1.15      www       825:            '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).
1.14      www       826:              '"><b>Forward</b></a></td>'.
1.15      www       827:         '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).
                    828:              '"><b>Mark Unread</b></a></td>'.
1.43      www       829:         '<td><a href="/adm/email?markdel='.&Apache::lonnet::escape($msgid).
                    830:              '"><b>Delete</b></a></td>'.
1.15      www       831:         '<td><a href="/adm/email"><b>Display all Messages</b></a></td>'.
1.14      www       832:              '</tr></table><p><pre>'.
1.36      www       833:              &Apache::lontexconvert::msgtexconverted($content{'message'}).
                    834:              '</pre><hr>'.$content{'citation'});
1.6       www       835:   } elsif ($ENV{'form.replyto'}) {
1.13      www       836:       &comprep($r,$ENV{'form.replyto'});
1.7       www       837:   } elsif ($ENV{'form.sendreply'}) {
                    838:       my $msgid=$ENV{'form.sendreply'};
1.8       albertel  839:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.52      www       840:       my %content=&unpackagemsg($message{$msgid},1);
1.7       www       841:       &statuschange($msgid,'replied');
1.24      www       842:       if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
1.12      www       843:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
                    844:          $r->print('Sending critical: '.
                    845:                 &user_crit_msg($content{'sendername'},
1.7       www       846:                                  $content{'senderdomain'},
1.56      albertel  847:                                  &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
                    848:                                  &Apache::lonfeedback::clear_out_html($ENV{'form.message'}),
1.24      www       849:                                  $ENV{'form.sendbck'}));
1.12      www       850:       } else {
                    851:          $r->print('Sending: '.&user_normal_msg($content{'sendername'},
                    852:                                  $content{'senderdomain'},
1.56      albertel  853:                                  &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
                    854:                                  &Apache::lonfeedback::clear_out_html($ENV{'form.message'})));
1.12      www       855:       }
1.14      www       856:       if ($ENV{'form.displayedcrit'}) {
                    857:           &discrit($r);
                    858:       } else {
                    859: 	  &disall($r);
                    860:       }
1.12      www       861:   } elsif ($ENV{'form.confirm'}) {
1.28      harris41  862:       foreach (keys %ENV) {
1.12      www       863:           if ($_=~/^form\.rec\_(.*)$/) {
                    864: 	      $r->print('<b>Confirming Receipt:</b> '.
                    865:                         &user_crit_received($1).'<br>');
1.13      www       866:           }
                    867:           if ($_=~/^form\.reprec\_(.*)$/) {
                    868:               my $msgid=$1;
                    869: 	      $r->print('<b>Confirming Receipt:</b> '.
                    870:                         &user_crit_received($msgid).'<br>');
                    871:               &comprep($r,$msgid);
1.12      www       872:           }
1.28      harris41  873:       }
1.12      www       874:       &discrit($r);
                    875:   } elsif ($ENV{'form.critical'}) {
                    876:       &discrit($r);
1.6       www       877:   } elsif ($ENV{'form.forward'}) {
1.15      www       878:       &compout($r,$ENV{'form.forward'});
1.14      www       879:   } elsif ($ENV{'form.markread'}) {
                    880:   } elsif ($ENV{'form.markdel'}) {
                    881:       &statuschange($ENV{'form.markdel'},'deleted');
1.25      www       882:       &disall($r);
                    883:   } elsif ($ENV{'form.markeddel'}) {
                    884:       my $total=0;
1.28      harris41  885:       foreach (keys %ENV) {
1.25      www       886:           if ($_=~/^form\.delmark_(.*)$/) {
                    887: 	      &statuschange(&Apache::lonnet::unescape($1),'deleted');
                    888:               $total++;
                    889:           }
1.28      harris41  890:       }
1.25      www       891:       $r->print('Deleted '.$total.' message(s)<p>');
1.14      www       892:       &disall($r);
                    893:   } elsif ($ENV{'form.markunread'}) {
1.15      www       894:       &statuschange($ENV{'form.markunread'},'new');
                    895:       &disall($r);
1.11      www       896:   } elsif ($ENV{'form.compose'}) {
1.17      www       897:       &compout($r,'',$ENV{'form.compose'});
1.44      www       898:   } elsif ($ENV{'form.recordftf'}) {
                    899:       &facetoface($r,$ENV{'form.recordftf'});
1.11      www       900:   } elsif ($ENV{'form.sendmail'}) {
1.16      www       901:       my %content=();
                    902:       undef %content;
                    903:       if ($ENV{'form.forwid'}) {
                    904:         my $msgid=$ENV{'form.forwid'};
                    905:         my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.52      www       906:         %content=&unpackagemsg($message{$msgid},1);
1.16      www       907:         &statuschange($msgid,'forwarded');
                    908:         $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
                    909: 	                       $content{'message'};
                    910:       }
1.18      www       911:       my %toaddr=();
                    912:       undef %toaddr;
                    913:       if ($ENV{'form.sendmode'} eq 'group') {
1.28      harris41  914:           foreach (keys %ENV) {
1.19      www       915: 	      if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
1.22      www       916: 		  $toaddr{$1}='';
1.18      www       917:               }
1.28      harris41  918:           }
1.22      www       919:       } elsif ($ENV{'form.sendmode'} eq 'upload') {
1.28      harris41  920:           foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) {
1.22      www       921:               my ($rec,$txt)=split(/\s*\:\s*/,$_);
                    922:               if ($txt) {
                    923: 		  $rec=~s/\@/\:/;
                    924:                   $toaddr{$rec}.=$txt."\n";
                    925:               }
1.28      harris41  926:           }
1.18      www       927:       } else {
1.22      www       928: 	  $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
1.20      www       929:       }
                    930:       if ($ENV{'form.additionalrec'}) {
1.28      harris41  931: 	  foreach (split(/\,/,$ENV{'form.additionalrec'})) {
1.20      www       932:               my ($auname,$audom)=split(/\@/,$_);
1.22      www       933:               $toaddr{$auname.':'.$audom}='';
1.28      harris41  934:           }
1.18      www       935:       }
1.28      harris41  936:     foreach (keys %toaddr) {
1.18      www       937:       my ($recuname,$recdomain)=split(/\:/,$_);
1.56      albertel  938:       my $msgtxt=&Apache::lonfeedback::clear_out_html($ENV{'form.message'});
1.22      www       939:       if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }    
1.24      www       940:       if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
1.16      www       941:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
                    942:          $r->print('Sending critical: '.
1.18      www       943:                 &user_crit_msg($recuname,$recdomain,
1.56      albertel  944:                &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
1.22      www       945:                                  $msgtxt,
1.24      www       946:                                  $ENV{'form.sendbck'}));
1.16      www       947:       } else {
1.18      www       948:          $r->print('Sending: '.&user_normal_msg($recuname,$recdomain,
1.56      albertel  949:               &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
1.22      www       950:                                  $msgtxt,
1.16      www       951:                                  $content{'citation'}));
                    952:       }
1.18      www       953:       $r->print('<br>');
1.28      harris41  954:     }
1.16      www       955:       if ($ENV{'form.displayedcrit'}) {
                    956:           &discrit($r);
                    957:       } else {
                    958: 	  &disall($r);
                    959:       }
1.6       www       960:   } else {
1.14      www       961:       &disall($r);
1.6       www       962:   }
1.5       www       963:   $r->print('</body></html>');
                    964:   return OK;
                    965: 
                    966: }
1.2       www       967: # ================================================= Main program, reset counter
                    968: 
1.27      www       969: BEGIN {
1.2       www       970:     $msgcount=0;
1.1       www       971: }
                    972: 
                    973: 1;
                    974: __END__
                    975: 
                    976: 
                    977: 
                    978: 
                    979: 
                    980: 
                    981: 

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