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

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

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