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

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

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