File:  [LON-CAPA] / loncom / interface / lonmsg.pm
Revision 1.50: download - view: text, annotated - select for diffs
Mon Mar 17 17:02:38 2003 UTC (21 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
-removing baseurl testing logsthises

    1: # The LearningOnline Network with CAPA
    2: # Routines for messaging
    3: #
    4: # $Id: lonmsg.pm,v 1.50 2003/03/17 17:02:38 albertel Exp $
    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/
   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: #
   37: # 10/19,10/20,10/30,
   38: # 02/06/01 Gerd Kortemeyer
   39: # 07/27 Guy Albertelli
   40: # 07/27,07/28,07/30,08/03,08/06,08/08,08/09,08/10,8/13,8/15,
   41: # 10/1,11/5 Gerd Kortemeyer
   42: # YEAR=2002
   43: # 1/1,3/18 Gerd Kortemeyer
   44: #
   45: package Apache::lonmsg;
   46: 
   47: use strict;
   48: use Apache::lonnet();
   49: use vars qw($msgcount);
   50: use HTML::TokeParser();
   51: use Apache::Constants qw(:common);
   52: use Apache::loncommon();
   53: use Apache::lontexconvert();
   54: use HTML::Entities();
   55: 
   56: # ===================================================================== Package
   57: 
   58: sub packagemsg {
   59:     my ($subject,$message,$citation,$baseurl)=@_;
   60:     $message =&HTML::Entities::encode($message);
   61:     $citation=&HTML::Entities::encode($citation);
   62:     $subject =&HTML::Entities::encode($subject);
   63:     #remove machine specification
   64:     $baseurl =~ s|^http://[^/]+/|/|;
   65:     $baseurl =&HTML::Entities::encode($baseurl);
   66:     my $now=time;
   67:     $msgcount++;
   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.':'.$$);
   73:     my $result='<sendername>'.$ENV{'user.name'}.'</sendername>'.
   74:            '<senderdomain>'.$ENV{'user.domain'}.'</senderdomain>'.
   75:            '<subject>'.$subject.'</subject>'.
   76: 	   '<time>'.localtime($now).'</time>'.
   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>'.
   88:            '<msgid>'.$msgid.'</msgid>'.
   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;
   97: }
   98: 
   99: # ================================================== Unpack message into a hash
  100: 
  101: sub unpackagemsg {
  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: 
  116: # ======================================================= Get info out of msgid
  117: 
  118: sub unpackmsgid {
  119:     my $msgid=&Apache::lonnet::unescape(shift);
  120:     my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/,
  121:                           &Apache::lonnet::unescape($msgid));
  122:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
  123:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
  124:     unless ($status{$msgid}) { $status{$msgid}='new'; }
  125:     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});
  126: } 
  127: 
  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: 
  139: # =============================== Automated message to the author of a resource
  140: 
  141: sub author_res_msg {
  142:     my ($filename,$message)=@_;
  143:     unless ($message) { return 'empty'; }
  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);
  149:        my $msgid;
  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);
  155:     }
  156:     return 'no_host';
  157: }
  158: 
  159: # ================================================== Critical message to a user
  160: 
  161: sub user_crit_msg_raw {
  162:     my ($user,$domain,$subject,$message,$sendback)=@_;
  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') {
  169:        ($msgid,$message)=&packagemsg($subject,$message);
  170:        if ($sendback) { $message.='<sendback>true</sendback>'; }
  171:        $status=&Apache::lonnet::critical(
  172:            'put:'.$domain.':'.$user.':critical:'.
  173:            &Apache::lonnet::escape($msgid).'='.
  174:            &Apache::lonnet::escape($message),$homeserver);
  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:        }
  182:     } else {
  183:        $status='no_host';
  184:     }
  185:     &Apache::lonnet::logthis(
  186:       'Sending critical email '.$msgid.
  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: '
  191:       .$status));
  192:     return $status;
  193: }
  194: 
  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: 
  216: # =================================================== Critical message received
  217: 
  218: sub user_crit_received {
  219:     my $msgid=shift;
  220:     my %message=&Apache::lonnet::get('critical',[$msgid]);
  221:     my %contents=&unpackagemsg($message{$msgid});
  222:     my $status='rec: '.($contents{'sendback'}?
  223:      &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
  224:                      'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'},
  225:                      'User '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}.
  226:                      ' acknowledged receipt of message'."\n".'   "'.
  227:                      $contents{'subject'}.'"'."\n".'dated '.
  228:                      $contents{'time'}.".\n"
  229:                      ):'no msg req');
  230:     $status.=' trans: '.
  231:      &Apache::lonnet::put(
  232:      'nohist_email',{$contents{'msgid'} => $message{$msgid}});
  233:     $status.=' del: '.
  234:      &Apache::lonnet::del('critical',[$contents{'msgid'}]);
  235:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
  236:                          $ENV{'user.home'},'Received critical message '.
  237:                          $contents{'msgid'}.
  238:                          ', '.$status);
  239:     return $status;
  240: }
  241: 
  242: # ======================================================== Normal communication
  243: 
  244: sub user_normal_msg_raw {
  245:     my ($user,$domain,$subject,$message,$citation,$baseurl)=@_;
  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') {
  252:        ($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl);
  253:        $status=&Apache::lonnet::critical(
  254:            'put:'.$domain.':'.$user.':nohist_email:'.
  255:            &Apache::lonnet::escape($msgid).'='.
  256:            &Apache::lonnet::escape($message),$homeserver);
  257:        &Apache::lonnet::put
  258:                          ('email_status',{'recnewemail'=>time},$domain,$user);
  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: }
  267: 
  268: # New routine that respects "forward" and calls old routine
  269: 
  270: sub user_normal_msg {
  271:     my ($user,$domain,$subject,$message,$citation,$baseurl)=@_;
  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,
  281: 			       $citation,$baseurl).' ';
  282:        }
  283:     } else { 
  284: 	$status=&user_normal_msg_raw($user,$domain,$subject,$message,
  285: 				     $citation,$baseurl);
  286:     }
  287:     return $status;
  288: }
  289: 
  290: 
  291: # =============================================================== Status Change
  292: 
  293: sub statuschange {
  294:     my ($msgid,$newstatus)=@_;
  295:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
  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')) {
  300: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
  301:     }
  302:     if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
  303: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
  304:     }
  305: }
  306: 
  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: 
  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: 
  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>
  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;
  350: <input type=button onClick="uncheckall()" value="Check for None">
  351: <p>
  352: ENDDISHEADER
  353:     foreach (sort keys %courselist) {
  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);
  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.'&&&_'.$_.'"> '.
  366: 		      $reply{'firstname'}.' '. 
  367:                       $reply{'middlename'}.' '.
  368:                       $reply{'lastname'}.' '.
  369:                       $reply{'generation'}.
  370:                       ' ('.$_.') '.$section);
  371:         } 
  372:     }
  373: }
  374: 
  375: # ==================================================== Display Critical Message
  376: 
  377: sub discrit {
  378:     my $r=shift;
  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;
  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'}.
  394:             '<br><blockquote>'.
  395:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
  396:             '</blockquote>'.
  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>');
  409: }
  410: 
  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'})) {
  424: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
  425:          $dispcrit=
  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>';
  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>
  435: <textarea name=message cols=84 rows=10 wrap=hard>
  436: $quotemsg
  437: </textarea><p>
  438: $dispcrit
  439: <input type=submit value="Send Reply">
  440: </form>
  441: ENDREPLY
  442: }
  443: 
  444: # ======================================================== Display all messages
  445: 
  446: sub disall {
  447:     my $r=shift;
  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">'.
  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>');
  474:     foreach (sort split(/\&/,&Apache::lonnet::reply('keys:'.
  475: 					$ENV{'user.domain'}.':'.
  476:                                         $ENV{'user.name'}.':nohist_email',
  477:                                         $ENV{'user.home'}))) {
  478:         my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
  479: 	    &Apache::lonmsg::unpackmsgid($_);
  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>'.
  495: 		      &Apache::lonnet::unescape($shortsubj).'</td><td>'.
  496:                       $status.'</td></tr>');
  497: 	}
  498:     }
  499:     $r->print('</table><p>'.
  500:               '<a href="javascript:checkall()">Check All</a>&nbsp;'.
  501:               '<a href="javascript:uncheckall()">Uncheck All</a><p>'.
  502:               '<input type=submit name="markeddel" value="Delete Checked">'.
  503:               '</form></body></html>');
  504: }
  505: 
  506: # ============================================================== Compose output
  507: 
  508: sub compout {
  509:     my ($r,$forwarding,$broadcast)=@_;
  510:       my $dispcrit='';
  511:     my $dissub='';
  512:     my $dismsg='';
  513:     my $func='Send New';
  514:       if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
  515: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
  516:          $dispcrit=
  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>';
  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'};
  534:     if ($ENV{'form.recdom'}) { $defdom=$ENV{'form.recdom'}; }
  535:       $r->print(
  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>');
  540:     unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
  541:         my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
  542:         my $selectlink=&Apache::loncommon::selectstudent_link
  543: 	    ('compemail','recuname','recdomain');
  544:        $r->print(<<"ENDREC");
  545: <table>
  546: <tr><td>Username:</td><td><input type=text size=12 name=recuname value="$ENV{'form.recname'}"></td><td rowspan="2">$selectlink</td></tr>
  547: <tr><td>Domain:</td>
  548: <td>$domform</td></tr>
  549: ENDREC
  550:     }
  551:     if ($broadcast ne 'upload') {
  552:        $r->print(<<"ENDCOMP");
  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>
  556: <tr><td>Subject:</td><td><input type=text size=50 name=subject value="$dissub">
  557: </td></tr></table>
  558: <textarea name=message cols=80 rows=10 wrap=hard>$dismsg
  559: </textarea><p>
  560: $dispcrit
  561: <input type=submit value="$func Mail">
  562: ENDCOMP
  563:     } else { # $broadcast is 'upload'
  564: 	$r->print(<<ENDUPLOAD);
  565: <input type=hidden name=sendmode value=upload>
  566: <h3>Generate messages from a file</h3>
  567: <p>
  568: Subject: <input type=text size=50 name=subject>
  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:
  575: <pre>
  576: username1\@domain1: text
  577: username2\@domain2: text
  578: username3\@domain1: text
  579: </pre>
  580: </p>
  581: <p>
  582: The messages will be assembled from all lines with the respective 
  583: <tt>username\@domain</tt>, and appended to the general message text.</p>
  584: <p>
  585: <input type=file name=upfile size=20><p>
  586: $dispcrit
  587: <input type=submit value="Upload and send">
  588: ENDUPLOAD
  589:     }
  590:     if ($broadcast eq 'group') {
  591:        &discourse;
  592:     }
  593:     $r->print('</form>');
  594: }
  595: 
  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 '') {
  633:         $r->print("<p><b>No notes, face-to-face discussion records, or critical messages in this course.</b></p>");
  634:     } else {
  635:        $r->print($result);
  636:     }
  637: }
  638: 
  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:     }
  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: 
  650:     my $defdom=$ENV{'user.domain'};
  651: # already filled in
  652:     if ($ENV{'form.recdomain'}) { $defdom=$ENV{'form.recdomain'}; }
  653: # generate output
  654:     my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
  655:     my $stdbrws = &Apache::loncommon::selectstudent_link
  656: 	('stdselect','recuname','recdomain');
  657:     $r->print(<<"ENDTREC");
  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">
  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">
  664: $stdbrws
  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'}) {
  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'});
  681:         }
  682:         $r->print('<h3>'.&Apache::loncommon::plainname($ENV{'form.recuname'},
  683: 				     $ENV{'form.recdomain'}).'</h3>');
  684:         &disfacetoface($r,$ENV{'form.recuname'},$ENV{'form.recdomain'});
  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>
  693: <br />
  694: <input type="hidden" name="recordftf" value="post" />
  695: <input type="submit" value="Post this record" />
  696: </form>
  697: ENDBFORM
  698:     }
  699: }
  700: 
  701: # ===================================================================== Handler
  702: 
  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: 
  713: # --------------------------- Get query string for limited number of parameters
  714:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  715:         ['display','replyto','forward','markread','markdel','markunread',
  716:          'sendreply','compose','sendmail','critical','recname','recdom',
  717:          'recordftf']);
  718: 
  719: # ------------------------------------------------------ They checked for email
  720:   &Apache::lonnet::put('email_status',{'recnewemail'=>0});
  721: # --------------------------------------------------------------- Render Output
  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:   }
  727:   if ($ENV{'form.display'}) {
  728:       my $msgid=$ENV{'form.display'};
  729:       &statuschange($msgid,'read');
  730:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
  731:       my %content=&unpackagemsg($message{$msgid});
  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'));
  739:       $r->print('<b>Subject:</b> '.$content{'subject'}.
  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'}.') '.
  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>'.
  750:            '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).
  751:              '"><b>Forward</b></a></td>'.
  752:         '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).
  753:              '"><b>Mark Unread</b></a></td>'.
  754:         '<td><a href="/adm/email?markdel='.&Apache::lonnet::escape($msgid).
  755:              '"><b>Delete</b></a></td>'.
  756:         '<td><a href="/adm/email"><b>Display all Messages</b></a></td>'.
  757:              '</tr></table><p><pre>'.
  758:              &Apache::lontexconvert::msgtexconverted($content{'message'}).
  759:              '</pre><hr>'.$content{'citation'});
  760:   } elsif ($ENV{'form.replyto'}) {
  761:       &comprep($r,$ENV{'form.replyto'});
  762:   } elsif ($ENV{'form.sendreply'}) {
  763:       my $msgid=$ENV{'form.sendreply'};
  764:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
  765:       my %content=&unpackagemsg($message{$msgid});
  766:       &statuschange($msgid,'replied');
  767:       if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
  768:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
  769:          $r->print('Sending critical: '.
  770:                 &user_crit_msg($content{'sendername'},
  771:                                  $content{'senderdomain'},
  772:                                  $ENV{'form.subject'},
  773:                                  $ENV{'form.message'},
  774:                                  $ENV{'form.sendbck'}));
  775:       } else {
  776:          $r->print('Sending: '.&user_normal_msg($content{'sendername'},
  777:                                  $content{'senderdomain'},
  778:                                  $ENV{'form.subject'},
  779:                                  $ENV{'form.message'}));
  780:       }
  781:       if ($ENV{'form.displayedcrit'}) {
  782:           &discrit($r);
  783:       } else {
  784: 	  &disall($r);
  785:       }
  786:   } elsif ($ENV{'form.confirm'}) {
  787:       foreach (keys %ENV) {
  788:           if ($_=~/^form\.rec\_(.*)$/) {
  789: 	      $r->print('<b>Confirming Receipt:</b> '.
  790:                         &user_crit_received($1).'<br>');
  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);
  797:           }
  798:       }
  799:       &discrit($r);
  800:   } elsif ($ENV{'form.critical'}) {
  801:       &discrit($r);
  802:   } elsif ($ENV{'form.forward'}) {
  803:       &compout($r,$ENV{'form.forward'});
  804:   } elsif ($ENV{'form.markread'}) {
  805:   } elsif ($ENV{'form.markdel'}) {
  806:       &statuschange($ENV{'form.markdel'},'deleted');
  807:       &disall($r);
  808:   } elsif ($ENV{'form.markeddel'}) {
  809:       my $total=0;
  810:       foreach (keys %ENV) {
  811:           if ($_=~/^form\.delmark_(.*)$/) {
  812: 	      &statuschange(&Apache::lonnet::unescape($1),'deleted');
  813:               $total++;
  814:           }
  815:       }
  816:       $r->print('Deleted '.$total.' message(s)<p>');
  817:       &disall($r);
  818:   } elsif ($ENV{'form.markunread'}) {
  819:       &statuschange($ENV{'form.markunread'},'new');
  820:       &disall($r);
  821:   } elsif ($ENV{'form.compose'}) {
  822:       &compout($r,'',$ENV{'form.compose'});
  823:   } elsif ($ENV{'form.recordftf'}) {
  824:       &facetoface($r,$ENV{'form.recordftf'});
  825:   } elsif ($ENV{'form.sendmail'}) {
  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:       }
  836:       my %toaddr=();
  837:       undef %toaddr;
  838:       if ($ENV{'form.sendmode'} eq 'group') {
  839:           foreach (keys %ENV) {
  840: 	      if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
  841: 		  $toaddr{$1}='';
  842:               }
  843:           }
  844:       } elsif ($ENV{'form.sendmode'} eq 'upload') {
  845:           foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) {
  846:               my ($rec,$txt)=split(/\s*\:\s*/,$_);
  847:               if ($txt) {
  848: 		  $rec=~s/\@/\:/;
  849:                   $toaddr{$rec}.=$txt."\n";
  850:               }
  851:           }
  852:       } else {
  853: 	  $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
  854:       }
  855:       if ($ENV{'form.additionalrec'}) {
  856: 	  foreach (split(/\,/,$ENV{'form.additionalrec'})) {
  857:               my ($auname,$audom)=split(/\@/,$_);
  858:               $toaddr{$auname.':'.$audom}='';
  859:           }
  860:       }
  861:     foreach (keys %toaddr) {
  862:       my ($recuname,$recdomain)=split(/\:/,$_);
  863:       my $msgtxt=$ENV{'form.message'};
  864:       if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }    
  865:       if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
  866:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
  867:          $r->print('Sending critical: '.
  868:                 &user_crit_msg($recuname,$recdomain,
  869:                                  $ENV{'form.subject'},
  870:                                  $msgtxt,
  871:                                  $ENV{'form.sendbck'}));
  872:       } else {
  873:          $r->print('Sending: '.&user_normal_msg($recuname,$recdomain,
  874:                                  $ENV{'form.subject'},
  875:                                  $msgtxt,
  876:                                  $content{'citation'}));
  877:       }
  878:       $r->print('<br>');
  879:     }
  880:       if ($ENV{'form.displayedcrit'}) {
  881:           &discrit($r);
  882:       } else {
  883: 	  &disall($r);
  884:       }
  885:   } else {
  886:       &disall($r);
  887:   }
  888:   $r->print('</body></html>');
  889:   return OK;
  890: 
  891: }
  892: # ================================================= Main program, reset counter
  893: 
  894: BEGIN {
  895:     $msgcount=0;
  896: }
  897: 
  898: 1;
  899: __END__
  900: 
  901: 
  902: 
  903: 
  904: 
  905: 
  906: 

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