File:  [LON-CAPA] / loncom / interface / lonmsg.pm
Revision 1.44: download - view: text, annotated - select for diffs
Fri Dec 27 14:59:42 2002 UTC (21 years, 5 months ago) by www
Branches: MAIN
CVS tags: HEAD
Toward bug #274 - recording of face-to-face discussion (look-up of all student
communication)

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

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