File:  [LON-CAPA] / loncom / interface / lonmsg.pm
Revision 1.75: download - view: text, annotated - select for diffs
Tue Dec 30 22:19:18 2003 UTC (20 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #2444: show bombs in construction space.

    1: # The LearningOnline Network with CAPA
    2: # Routines for messaging
    3: #
    4: # $Id: lonmsg.pm,v 1.75 2003/12/30 22:19:18 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: 
   30: package Apache::lonmsg;
   31: 
   32: =pod
   33: 
   34: =head1 NAME
   35: 
   36: Apache::lonmsg: supports internal messaging
   37: 
   38: =head1 SYNOPSIS
   39: 
   40: lonmsg provides routines for sending messages, receiving messages, and
   41: a handler to allow users to read, send, and delete messages.
   42: 
   43: =head1 OVERVIEW
   44: 
   45: =head2 Messaging Overview
   46: 
   47: X<messages>LON-CAPA provides an internal messaging system similar to
   48: email, but customized for LON-CAPA's usage. LON-CAPA implements its
   49: own messaging system, rather then building on top of email, because of
   50: the features LON-CAPA messages can offer that conventional e-mail can
   51: not:
   52: 
   53: =over 4
   54: 
   55: =item * B<Critical messages>: A message the recipient B<must>
   56: acknowlegde receipt of before they are allowed to continue using the
   57: system, preventing a user from claiming they never got a message
   58: 
   59: =item * B<Receipts>: LON-CAPA can reliably send reciepts informing the
   60: sender that it has been read; again, useful for preventing students
   61: from claiming they did not see a message. (While conventional e-mail
   62: has some reciept support, it's sporadic, e-mail client-specific, and
   63: generally the receiver can opt to not send one, making it useless in
   64: this case.)
   65: 
   66: =item * B<Context>: LON-CAPA knows about the sender, such as where
   67: they are in a course. When a student mails an instructor asking for
   68: help on the problem, the instructor receives not just the student's
   69: question, but all submissions the student has made up to that point,
   70: the user's rendering of the problem, and the complete view the student
   71: saw of the resource, including discussion up to that point. Finally,
   72: the instructor is reading all of this inside of LON-CAPA, not their
   73: email program, so they have full access to LON-CAPA's grading
   74: interface, or other features they may wish to use in response to the
   75: student's query.
   76: 
   77: =back
   78: 
   79: Users can ask LON-CAPA to forward messages to conventional e-mail
   80: addresses on their B<PREF> screen, but generally, LON-CAPA messages
   81: are much more useful then traditional email can be made to be, even
   82: with HTML support.
   83: 
   84: Right now, this document will cover just how to send a message, since
   85: it is likely you will not need to programmatically read messages,
   86: since lonmsg already implements that functionality.
   87: 
   88: =head1 FUNCTIONS
   89: 
   90: =over 4
   91: 
   92: =cut
   93: 
   94: use strict;
   95: use Apache::lonnet();
   96: use vars qw($msgcount);
   97: use HTML::TokeParser();
   98: use Apache::Constants qw(:common);
   99: use Apache::loncommon();
  100: use Apache::lontexconvert();
  101: use HTML::Entities();
  102: use Mail::Send;
  103: use Apache::lonlocal;
  104: 
  105: # Querystring component with sorting type
  106: my $sqs;
  107: 
  108: # ===================================================================== Package
  109: 
  110: sub packagemsg {
  111:     my ($subject,$message,$citation,$baseurl,$attachmenturl)=@_;
  112:     $message =&HTML::Entities::encode($message);
  113:     $citation=&HTML::Entities::encode($citation);
  114:     $subject =&HTML::Entities::encode($subject);
  115:     #remove machine specification
  116:     $baseurl =~ s|^http://[^/]+/|/|;
  117:     $baseurl =&HTML::Entities::encode($baseurl);
  118:     #remove machine specification
  119:     $attachmenturl =~ s|^http://[^/]+/|/|;
  120:     $attachmenturl =&HTML::Entities::encode($attachmenturl);
  121: 
  122:     my $now=time;
  123:     $msgcount++;
  124:     my $partsubj=$subject;
  125:     $partsubj=&Apache::lonnet::escape($partsubj);
  126:     my $msgid=&Apache::lonnet::escape(
  127:            $now.':'.$partsubj.':'.$ENV{'user.name'}.':'.
  128:            $ENV{'user.domain'}.':'.$msgcount.':'.$$);
  129:     my $result='<sendername>'.$ENV{'user.name'}.'</sendername>'.
  130:            '<senderdomain>'.$ENV{'user.domain'}.'</senderdomain>'.
  131:            '<subject>'.$subject.'</subject>'.
  132: 	   '<time>'.&Apache::lonlocal::locallocaltime($now).'</time>'.
  133: 	   '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
  134:            '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
  135: 	   '<client>'.$ENV{'REMOTE_ADDR'}.'</client>'.
  136: 	   '<browsertype>'.$ENV{'browser.type'}.'</browsertype>'.
  137: 	   '<browseros>'.$ENV{'browser.os'}.'</browseros>'.
  138: 	   '<browserversion>'.$ENV{'browser.version'}.'</browserversion>'.
  139:            '<browsermathml>'.$ENV{'browser.mathml'}.'</browsermathml>'.
  140: 	   '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
  141: 	   '<courseid>'.$ENV{'request.course.id'}.'</courseid>'.
  142: 	   '<role>'.$ENV{'request.role'}.'</role>'.
  143: 	   '<resource>'.$ENV{'request.filename'}.'</resource>'.
  144:            '<msgid>'.$msgid.'</msgid>'.
  145: 	   '<message>'.$message.'</message>';
  146:     if (defined($citation)) {
  147: 	$result.='<citation>'.$citation.'</citation>';
  148:     }
  149:     if (defined($baseurl)) {
  150: 	$result.= '<baseurl>'.$baseurl.'</baseurl>';
  151:     }
  152:     if (defined($attachmenturl)) {
  153: 	$result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>';
  154:     }
  155:     return $msgid,$result;
  156: }
  157: 
  158: # ================================================== Unpack message into a hash
  159: 
  160: sub unpackagemsg {
  161:     my ($message,$notoken)=@_;
  162:     my %content=();
  163:     my $parser=HTML::TokeParser->new(\$message);
  164:     my $token;
  165:     while ($token=$parser->get_token) {
  166:        if ($token->[0] eq 'S') {
  167: 	   my $entry=$token->[1];
  168:            my $value=$parser->get_text('/'.$entry);
  169:            $content{$entry}=$value;
  170:        }
  171:     }
  172:     if ($content{'attachmenturl'}) {
  173:        my ($fname,$ft)=($content{'attachmenturl'}=~/\/(\w+)\.(\w+)$/);
  174:        if ($notoken) {
  175: 	   $content{'message'}.='<p>'.&mt('Attachment').': <tt>'.$fname.'.'.$ft.'</tt>';
  176:        } else {
  177: 	   $content{'message'}.='<p>'.&mt('Attachment').': <a href="'.
  178: 	       &Apache::lonnet::tokenwrapper($content{'attachmenturl'}).
  179: 	       '"><tt>'.$fname.'.'.$ft.'</tt></a>';
  180:        }
  181:     }
  182:     return %content;
  183: }
  184: 
  185: # ======================================================= Get info out of msgid
  186: 
  187: sub unpackmsgid {
  188:     my $msgid=&Apache::lonnet::unescape(shift);
  189:     my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/,
  190:                           &Apache::lonnet::unescape($msgid));
  191:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
  192:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
  193:     unless ($status{$msgid}) { $status{$msgid}='new'; }
  194:     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});
  195: } 
  196: 
  197: 
  198: sub sendemail {
  199:     my ($to,$subject,$body)=@_;
  200:     $body=
  201:     "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n".
  202:     "*** ".&mt('Please do not reply to this address.')."\n\n".$body;
  203:     my $msg = new Mail::Send;
  204:     $msg->to($to);
  205:     $msg->subject('[LON-CAPA] '.$subject);
  206:     if (my $fh = $msg->open('smtp',Server => 'localhost')) {
  207: 	print $fh $body;
  208: 	$fh->close;
  209:     }
  210: }
  211: 
  212: # ==================================================== Send notification emails
  213: 
  214: sub sendnotification {
  215:     my ($to,$touname,$toudom,$subj,$crit)=@_;
  216:     my $sender=$ENV{'environment.firstname'}.' '.$ENV{'environment.lastname'};
  217:     my $critical=($crit?' critical':'');
  218:     my $url='http://'.
  219:       $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}.
  220:       '/adm/email?username='.$touname.'&domain='.$toudom;
  221:     my $body=(<<ENDMSG);
  222: You received a$critical message from $sender in LON-CAPA. The subject is
  223: 
  224:  $subj
  225: 
  226: Use
  227: 
  228:  $url
  229: 
  230: to access this message.
  231: ENDMSG
  232:     &sendemail($to,'New'.$critical.' message from '.$sender,$body);
  233: }
  234: # ============================================================= Check for email
  235: 
  236: sub newmail {
  237:     if ((time-$ENV{'user.mailcheck.time'})>300) {
  238:         my %what=&Apache::lonnet::get('email_status',['recnewemail']);
  239:         &Apache::lonnet::appenv('user.mailcheck.time'=>time);
  240:         if ($what{'recnewemail'}>0) { return 1; }
  241:     }
  242:     return 0;
  243: }
  244: 
  245: # =============================== Automated message to the author of a resource
  246: 
  247: =pod
  248: 
  249: =item * B<author_res_msg($filename, $message)>: Sends message $message to the owner
  250:     of the resource with the URI $filename.
  251: 
  252: =cut
  253: 
  254: sub author_res_msg {
  255:     my ($filename,$message)=@_;
  256:     unless ($message) { return 'empty'; }
  257:     $filename=&Apache::lonnet::declutter($filename);
  258:     my ($domain,$author,@dummy)=split(/\//,$filename);
  259:     my $homeserver=&Apache::lonnet::homeserver($author,$domain);
  260:     if ($homeserver ne 'no_host') {
  261:        my $id=unpack("%32C*",$message);
  262:        my $msgid;
  263:        ($msgid,$message)=&packagemsg($filename,$message);
  264:        return &Apache::lonnet::reply('put:'.$domain.':'.$author.
  265:          ':nohist_res_msgs:'.
  266:           &Apache::lonnet::escape($filename.'_'.$id).'='.
  267:           &Apache::lonnet::escape($message),$homeserver);
  268:     }
  269:     return 'no_host';
  270: }
  271: 
  272: # =========================================== Retrieve author resource messages
  273: 
  274: sub retrieve_author_res_msg {
  275:     my $url=shift;
  276:     $url=&Apache::lonnet::declutter($url);
  277:     my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
  278:     my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$1,$2);
  279:     my $msgs='';
  280:     foreach (keys %errormsgs) {
  281: 	if ($_=~/^\Q$url\E\_\d+$/) {
  282: 	    my %content=&unpackagemsg($errormsgs{$_});
  283: 	    $msgs.='<p><img src="/adm/lonMisc/bomb.gif" /><b>'.
  284: 		$content{'time'}.'</b>: '.$content{'message'}.
  285: 		'<br /></p>';
  286: 	}
  287:     } 
  288:     return $msgs;     
  289: }
  290: 
  291: 
  292: # =============================== Delete all author messages related to one URL
  293: 
  294: sub del_url_author_res_msg {
  295:     my $url=shift;
  296:     $url=&Apache::lonnet::declutter($url);
  297: }
  298: 
  299: # ================= Return hash with URLs for which there is a resource message
  300: 
  301: sub all_url_author_res_msg {
  302:     my ($author,$domain)=@_;
  303:     my %returnhash=();
  304:     foreach (&Apache::lonnet::getkeys('nohist_res_msgs')) {
  305: 	$_=~/^(.+)\_\d+/;
  306: 	$returnhash{$1}=1;
  307:     }
  308:     return %returnhash;
  309: }
  310: 
  311: # ================================================== Critical message to a user
  312: 
  313: sub user_crit_msg_raw {
  314:     my ($user,$domain,$subject,$message,$sendback)=@_;
  315: # Check if allowed missing
  316:     my $status='';
  317:     my $msgid='undefined';
  318:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
  319:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
  320:     if ($homeserver ne 'no_host') {
  321:        ($msgid,$message)=&packagemsg($subject,$message);
  322:        if ($sendback) { $message.='<sendback>true</sendback>'; }
  323:        $status=&Apache::lonnet::critical(
  324:            'put:'.$domain.':'.$user.':critical:'.
  325:            &Apache::lonnet::escape($msgid).'='.
  326:            &Apache::lonnet::escape($message),$homeserver);
  327:        if ($ENV{'request.course.id'}) {
  328:           &user_normal_msg_raw(
  329:             $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
  330:             $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  331:             'Critical ['.$user.':'.$domain.']',
  332: 	    $message);
  333:        }
  334:     } else {
  335:        $status='no_host';
  336:     }
  337: # Notifications
  338:     my %userenv = &Apache::lonnet::get('environment',['critnotification'],
  339:                                        $domain,$user);
  340:     if ($userenv{'critnotification'}) {
  341:       &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1);
  342:     }
  343: # Log this
  344:     &Apache::lonnet::logthis(
  345:       'Sending critical email '.$msgid.
  346:       ', log status: '.
  347:       &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
  348:                          $ENV{'user.home'},
  349:       'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
  350:       .$status));
  351:     return $status;
  352: }
  353: 
  354: # New routine that respects "forward" and calls old routine
  355: 
  356: =pod
  357: 
  358: =item * B<user_crit_msg($user, $domain, $subject, $message, $sendback)>: Sends
  359:     a critical message $message to the $user at $domain. If $sendback is true,
  360:     a reciept will be sent to the current user when $user recieves the message.
  361: 
  362: =cut
  363: 
  364: sub user_crit_msg {
  365:     my ($user,$domain,$subject,$message,$sendback)=@_;
  366:     my $status='';
  367:     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
  368:                                        $domain,$user);
  369:     my $msgforward=$userenv{'msgforward'};
  370:     if ($msgforward) {
  371:        foreach (split(/\,/,$msgforward)) {
  372: 	 my ($forwuser,$forwdomain)=split(/\:/,$_);
  373:          $status.=
  374: 	   &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
  375:                 $sendback).' ';
  376:        }
  377:     } else { 
  378: 	$status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback);
  379:     }
  380:     return $status;
  381: }
  382: 
  383: # =================================================== Critical message received
  384: 
  385: sub user_crit_received {
  386:     my $msgid=shift;
  387:     my %message=&Apache::lonnet::get('critical',[$msgid]);
  388:     my %contents=&unpackagemsg($message{$msgid},1);
  389:     my $status='rec: '.($contents{'sendback'}?
  390:      &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
  391:                      &mt('Receipt').': '.$ENV{'user.name'}.' at '.$ENV{'user.domain'},
  392:                      &mt('User').' '.$ENV{'user.name'}.' '.&mt('at').' '.$ENV{'user.domain'}.
  393:                      ' acknowledged receipt of message'."\n".'   "'.
  394:                      $contents{'subject'}.'"'."\n".&mt('dated').' '.
  395:                      $contents{'time'}.".\n"
  396:                      ):'no msg req');
  397:     $status.=' trans: '.
  398:      &Apache::lonnet::put(
  399:      'nohist_email',{$contents{'msgid'} => $message{$msgid}});
  400:     $status.=' del: '.
  401:      &Apache::lonnet::del('critical',[$contents{'msgid'}]);
  402:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
  403:                          $ENV{'user.home'},'Received critical message '.
  404:                          $contents{'msgid'}.
  405:                          ', '.$status);
  406:     return $status;
  407: }
  408: 
  409: # ======================================================== Normal communication
  410: 
  411: sub user_normal_msg_raw {
  412:     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_;
  413: # Check if allowed missing
  414:     my $status='';
  415:     my $msgid='undefined';
  416:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
  417:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
  418:     if ($homeserver ne 'no_host') {
  419:        ($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl,
  420:                                      $attachmenturl);
  421:        $status=&Apache::lonnet::critical(
  422:            'put:'.$domain.':'.$user.':nohist_email:'.
  423:            &Apache::lonnet::escape($msgid).'='.
  424:            &Apache::lonnet::escape($message),$homeserver);
  425:        &Apache::lonnet::put
  426:                          ('email_status',{'recnewemail'=>time},$domain,$user);
  427:     } else {
  428:        $status='no_host';
  429:     }
  430: # Notifications
  431:     my %userenv = &Apache::lonnet::get('environment',['notification'],
  432:                                        $domain,$user);
  433:     if ($userenv{'notification'}) {
  434: 	&sendnotification($userenv{'notification'},$user,$domain,$subject,0);
  435:     }
  436:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
  437:                          $ENV{'user.home'},
  438:       'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
  439:     return $status;
  440: }
  441: 
  442: # New routine that respects "forward" and calls old routine
  443: 
  444: =pod
  445: 
  446: =item * B<user_normal_msg($user, $domain, $subject, $message,
  447:     $citation, $baseurl, $attachmenturl)>: Sends a message to the
  448:     $user at $domain, with subject $subject and message $message.
  449: 
  450: =cut
  451: 
  452: sub user_normal_msg {
  453:     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_;
  454:     my $status='';
  455:     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
  456:                                        $domain,$user);
  457:     my $msgforward=$userenv{'msgforward'};
  458:     if ($msgforward) {
  459:        foreach (split(/\,/,$msgforward)) {
  460: 	 my ($forwuser,$forwdomain)=split(/\:/,$_);
  461:          $status.=
  462: 	  &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
  463: 			       $citation,$baseurl,$attachmenturl).' ';
  464:        }
  465:     } else { 
  466: 	$status=&user_normal_msg_raw($user,$domain,$subject,$message,
  467: 				     $citation,$baseurl,$attachmenturl);
  468:     }
  469:     return $status;
  470: }
  471: 
  472: 
  473: # =============================================================== Status Change
  474: 
  475: sub statuschange {
  476:     my ($msgid,$newstatus)=@_;
  477:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
  478:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
  479:     unless ($status{$msgid}) { $status{$msgid}='new'; }
  480:     unless (($status{$msgid} eq 'replied') || 
  481:             ($status{$msgid} eq 'forwarded')) {
  482: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
  483:     }
  484:     if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
  485: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
  486:     }
  487: }
  488: 
  489: # ======================================================= Display a course list
  490: 
  491: sub discourse {
  492:     my $r=shift;
  493:     my %courselist=&Apache::lonnet::dump(
  494:                    'classlist',
  495: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  496: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  497:     my $now=time;
  498:     my %lt=&Apache::lonlocal::texthash('cfa' => 'Check for All',
  499:             'cfs' => 'Check for Section/Group',
  500:             'cfn' => 'Check for None');
  501:     $r->print(<<ENDDISHEADER);
  502: <input type=hidden name=sendmode value=group>
  503: <script>
  504:     function checkall() {
  505: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
  506:             if 
  507:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
  508: 	      document.forms.compemail.elements[i].checked=true;
  509:             }
  510:         }
  511:     }
  512: 
  513:     function checksec() {
  514: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
  515:             if 
  516:           (document.forms.compemail.elements[i].name.indexOf
  517:            ('send_to_&&&'+document.forms.compemail.chksec.value)==0) {
  518: 	      document.forms.compemail.elements[i].checked=true;
  519:             }
  520:         }
  521:     }
  522: 
  523:     function uncheckall() {
  524: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
  525:             if 
  526:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
  527: 	      document.forms.compemail.elements[i].checked=false;
  528:             }
  529:         }
  530:     }
  531: </script>
  532: <input type=button onClick="checkall()" value="$lt{'cfa'}">&nbsp;
  533: <input type=button onClick="checksec()" value="$lt{'cfs'}">
  534: <input type=text size=5 name=chksec>&nbsp;
  535: <input type=button onClick="uncheckall()" value="$lt{'cfn'}">
  536: <p>
  537: ENDDISHEADER
  538:     my %coursepersonnel=
  539:        &Apache::lonnet::get_course_adv_roles();
  540:     foreach my $role (sort keys %coursepersonnel) {
  541:        foreach (split(/\,/,$coursepersonnel{$role})) {
  542: 	   my ($puname,$pudom)=split(/\:/,$_);
  543: 	   $r->print(
  544:              '<br /><input type="checkbox" name="send_to_&&&&&&_'.
  545:              $puname.':'.$pudom.'" /> '.
  546: 		     &Apache::loncommon::plainname($puname,
  547:                           $pudom).' ('.$_.'), <i>'.$role.'</i>');
  548: 	}
  549:     }
  550: 
  551:     foreach (sort keys %courselist) {
  552:         my ($end,$start)=split(/\:/,$courselist{$_});
  553:         my $active=1;
  554:         if (($end) && ($now>$end)) { $active=0; }
  555:         if ($active) {
  556:            my ($sname,$sdom)=split(/\:/,$_);
  557:            my %reply=&Apache::lonnet::get('environment',
  558:               ['firstname','middlename','lastname','generation'],
  559:               $sdom,$sname);
  560:            my $section=&Apache::lonnet::usection
  561: 	       ($sdom,$sname,$ENV{'request.course.id'});
  562:            $r->print(
  563:         '<br><input type=checkbox name="send_to_&&&'.$section.'&&&_'.$_.'"> '.
  564: 		      $reply{'firstname'}.' '. 
  565:                       $reply{'middlename'}.' '.
  566:                       $reply{'lastname'}.' '.
  567:                       $reply{'generation'}.
  568:                       ' ('.$_.') '.$section);
  569:         } 
  570:     }
  571: }
  572: 
  573: # ==================================================== Display Critical Message
  574: 
  575: sub discrit {
  576:     my $r=shift;
  577:     my $header = '<h1><font color=red>'.&mt('Critical Messages').'</font></h1>'.
  578:         '<form action=/adm/email method=post>'.
  579:         '<input type=hidden name=confirm value=true>';
  580:     my %what=&Apache::lonnet::dump('critical');
  581:     my $result = '';
  582:     foreach (sort keys %what) {
  583:         my %content=&unpackagemsg($what{$_});
  584:         next if ($content{'senderdomain'} eq '');
  585:         $content{'message'}=~s/\n/\<br\>/g;
  586:         $result.='<hr>'.&mt('From').': <b>'.
  587: &Apache::loncommon::aboutmewrapper(
  588:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
  589: $content{'sendername'}.'@'.
  590:             $content{'senderdomain'}.') '.$content{'time'}.
  591:             '<br>'.&mt('Subject').': '.$content{'subject'}.
  592:             '<br><blockquote>'.
  593:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
  594:             '</blockquote>'.
  595:             '<input type=submit name="rec_'.$_.'" value="'.&mt('Confirm Receipt').'">'.
  596:             '<input type=submit name="reprec_'.$_.'" '.
  597:                   'value="'.&mt('Confirm Receipt and Reply').'">';
  598:     }
  599:     # Check to see if there were any messages.
  600:     if ($result eq '') {
  601:         $result = "<h2>".&mt('You have no critical messages.')."</h2>".
  602: 	    '<a href="/adm/roles">'.&mt('Select a course').'</a>';
  603:     } else {
  604:         $r->print($header);
  605:     }
  606:     $r->print($result);
  607:     $r->print('<input type=hidden name="displayedcrit" value="true"></form>');
  608: }
  609: 
  610: # =============================================================== Compose reply
  611: 
  612: sub comprep {
  613:     my ($r,$msgid)=@_;
  614:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
  615:       my %content=&unpackagemsg($message{$msgid},1);
  616:       my $quotemsg='> '.$content{'message'};
  617:       $quotemsg=~s/\r/\n/g;
  618:       $quotemsg=~s/\f/\n/g;
  619:       $quotemsg=~s/\n+/\n\> /g;
  620:       my $torepl=&Apache::loncommon::aboutmewrapper(
  621:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
  622: $content{'sendername'}.'@'.
  623:             $content{'senderdomain'}.')';
  624:       my $subject=&mt('Re').': '.$content{'subject'};
  625:       my $dispcrit='';
  626:       if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
  627: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
  628:          $dispcrit=
  629:  '<input type=checkbox name=critmsg> '.&mt('Send as critical message').' ' . $crithelp . 
  630:  '<br>'.
  631:  '<input type=checkbox name=sendbck> '.&mt('Send as critical message').' ' .
  632:  &mt('and return receipt') . $crithelp . '<p>';
  633:       }
  634:     my %lt=&Apache::lonlocal::texthash(
  635: 				   'to' => 'To',
  636: 				   'sb' => 'Subject',
  637: 				   'sr' => 'Send Reply',
  638: 				   'ca' => 'Cancel'
  639: 				   );
  640:       $r->print(<<"ENDREPLY");
  641: <form action="/adm/email" method="post">
  642: <input type="hidden" name="sendreply" value="$msgid">
  643: $lt{'to'}: $torepl<br />
  644: $lt{'sb'}: <input type="text" size=50 name="subject" value="$subject"><p>
  645: <textarea name="message" cols="84" rows="10" wrap="hard">
  646: $quotemsg
  647: </textarea></p><br />
  648: $dispcrit
  649: <input type="submit" name="send" value="$lt{'sr'}" />
  650: <input type="submit" name="cancel" value="$lt{'ca'}"/ >
  651: </form>
  652: ENDREPLY
  653: }
  654: 
  655: sub sortedmessages {
  656:     my @messages = &Apache::lonnet::getkeys('nohist_email');
  657:     #unpack the varibles and repack into temp for sorting
  658:     my @temp;
  659:     foreach (@messages) {
  660: 	my $msgid=&Apache::lonnet::escape($_);
  661: 	my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
  662: 	    &Apache::lonmsg::unpackmsgid($msgid);
  663: 	my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
  664: 		     $msgid);
  665: 	push @temp ,\@temp1;
  666:     }
  667:     #default sort
  668:     @temp = sort  {$a->[0] <=> $b->[0]} @temp;    
  669:     if ($ENV{'form.sortedby'} eq "date"){
  670:         @temp = sort  {$a->[0] <=> $b->[0]} @temp;    
  671:     }
  672:     if ($ENV{'form.sortedby'} eq "revdate"){
  673:     	@temp = sort  {$b->[0] <=> $a->[0]} @temp; 
  674:     }
  675:     if ($ENV{'form.sortedby'} eq "user"){
  676: 	@temp = sort  {lc($a->[2]) cmp lc($b->[2])} @temp;
  677:     }
  678:     if ($ENV{'form.sortedby'} eq "revuser"){
  679: 	@temp = sort  {lc($b->[2]) cmp lc($a->[2])} @temp;
  680:     }
  681:     if ($ENV{'form.sortedby'} eq "domain"){
  682:         @temp = sort  {$a->[3] cmp $b->[3]} @temp;
  683:     }
  684:     if ($ENV{'form.sortedby'} eq "revdomain"){
  685:         @temp = sort  {$b->[3] cmp $a->[3]} @temp;
  686:     }
  687:     if ($ENV{'form.sortedby'} eq "subject"){
  688:         @temp = sort  {lc($a->[1]) cmp lc($b->[1])} @temp;
  689:     }
  690:     if ($ENV{'form.sortedby'} eq "revsubject"){
  691:         @temp = sort  {lc($b->[1]) cmp lc($a->[1])} @temp;
  692:     }
  693:     if ($ENV{'form.sortedby'} eq "status"){
  694:         @temp = sort  {$a->[4] cmp $b->[4]} @temp;
  695:     }
  696:     if ($ENV{'form.sortedby'} eq "revstatus"){
  697:         @temp = sort  {$b->[4] cmp $a->[4]} @temp;
  698:     }
  699:     return @temp;
  700: }
  701: 
  702: # ======================================================== Display all messages
  703: 
  704: sub disall {
  705:     my $r=shift;
  706:      $r->print(<<ENDDISHEADER);
  707: <script>
  708:     function checkall() {
  709: 	for (i=0; i<document.forms.disall.elements.length; i++) {
  710:             if 
  711:           (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
  712: 	      document.forms.disall.elements[i].checked=true;
  713:             }
  714:         }
  715:     }
  716: 
  717:     function uncheckall() {
  718: 	for (i=0; i<document.forms.disall.elements.length; i++) {
  719:             if 
  720:           (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
  721: 	      document.forms.disall.elements[i].checked=false;
  722:             }
  723:         }
  724:     }
  725: </script>
  726: ENDDISHEADER
  727:     $r->print('<h1>'.&mt('Display All Messages').'</h1><form method=post name=disall '.
  728: 	      'action="/adm/email">'.
  729: 	      '<table border=2><tr><th colspan=2>&nbsp</th><th>');
  730:     if ($ENV{'form.sortedby'} eq "revdate") {
  731: 	$r->print('<a href = "?sortedby=date">'.&mt('Date').'</a></th>');
  732:     } else {
  733: 	$r->print('<a href = "?sortedby=revdate">'.&mt('Date').'</a></th>');
  734:     }
  735:     $r->print('<th>');
  736:     if ($ENV{'form.sortedby'} eq "revuser") {
  737: 	$r->print('<a href = "?sortedby=user">'.&mt('Username').'</a>');
  738:     } else {
  739: 	$r->print('<a href = "?sortedby=revuser">'.&mt('Username').'</a>');
  740:     }
  741:     $r->print('</th><th>');
  742:     if ($ENV{'form.sortedby'} eq "revdomain") {
  743: 	$r->print('<a href = "?sortedby=domain">'.&mt('Domain').'</a>');
  744:     } else {
  745: 	$r->print('<a href = "?sortedby=revdomain">'.&mt('Domain').'</a>');
  746:     }
  747:     $r->print('</th><th>');
  748:     if ($ENV{'form.sortedby'} eq "revsubject") {
  749: 	$r->print('<a href = "?sortedby=subject">'.&mt('Subject').'</a>');
  750:     } else {
  751:     	$r->print('<a href = "?sortedby=revsubject">'.&mt('Subject').'</a>');
  752:     }
  753:     $r->print('</th><th>');
  754:     if ($ENV{'form.sortedby'} eq "revstatus") {
  755: 	$r->print('<a href = "?sortedby=status">'.&mt('Status').'</th>');
  756:     } else {
  757:      	$r->print('<a href = "?sortedby=revstatus">'.&mt('Status').'</th>');
  758:     }
  759:     $r->print('</tr>');
  760:     my @temp=sortedmessages();
  761:     foreach (@temp){
  762: 	my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID)= @$_;
  763: 	if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
  764: 	    if ($status eq 'new') {
  765: 		$r->print('<tr bgcolor="#FFBB77">');
  766: 	    } elsif ($status eq 'read') {
  767: 		$r->print('<tr bgcolor="#BBBB77">');
  768: 	    } elsif ($status eq 'replied') {
  769: 		$r->print('<tr bgcolor="#AAAA88">'); 
  770: 	    } else {
  771: 		$r->print('<tr bgcolor="#99BBBB">');
  772: 	    }
  773: 	    $r->print('<td><a href="/adm/email?display='.$origID.$sqs. 
  774: 		      '">'.&mt('Open').'</a></td><td><a href="/adm/email?markdel='.$origID.$sqs.
  775: 		      '">'.&mt('Delete').'</a><input type=checkbox name="delmark_'.$origID.'"></td>'.
  776: 		      '<td>'.&Apache::lonlocal::locallocaltime($sendtime).'</td><td>'.
  777: 		      $fromname.'</td><td>'.$fromdomain.'</td><td>'.
  778: 		      &Apache::lonnet::unescape($shortsubj).'</td><td>'.
  779:                       $status.'</td></tr>');
  780: 	}
  781:     }   
  782:     $r->print('</table><p>'.
  783:               '<a href="javascript:checkall()">'.&mt('Check All').'</a>&nbsp;'.
  784:               '<a href="javascript:uncheckall()">'.&mt('Uncheck All').'</a><p>'.
  785: 	      '<input type="hidden" name="sortedby" value="'.$ENV{'form.sortedby'}.'" />'.
  786:               '<input type=submit name="markeddel" value="'.&mt('Delete Checked').'">'.
  787:               '</form></body></html>');
  788: }
  789: 
  790: # ============================================================== Compose output
  791: 
  792: sub compout {
  793:     my ($r,$forwarding,$broadcast)=@_;
  794:       my $dispcrit='';
  795:     my $dissub='';
  796:     my $dismsg='';
  797:     my $func=&mt('Send New');
  798:     my %lt=&Apache::lonlocal::texthash('us' => 'Username',
  799: 				       'do' => 'Domain',
  800: 				       'ad' => 'Additional Recipients',
  801: 				       'sb' => 'Subject',
  802: 				       'ca' => 'Cancel',
  803: 				       'ma' => 'Mail');
  804: 
  805:     if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
  806: 	 my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
  807:          $dispcrit=
  808:  '<input type="checkbox" name="critmsg"> '.&mt('Send as critical message').' ' . $crithelp . 
  809:  '<br>'.
  810:  '<input type="checkbox" name="sendbck"> '.&mt('Send as critical message').'  ' .
  811:  &mt('and return receipt') . $crithelp . '<p>';
  812:       }
  813:     if ($forwarding) {
  814:        $dispcrit.='<input type="hidden" name="forwid" value="'.
  815: 	   $forwarding.'">';
  816:        $func=&mt('Forward');
  817:       my %message=&Apache::lonnet::get('nohist_email',[$forwarding]);
  818:       my %content=&unpackagemsg($message{$forwarding});
  819: 
  820:        $dissub=&mt('Forwarding').': '.$content{'subject'};
  821:        $dismsg=&mt('Forwarded message from').' '.
  822: 	   $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
  823:     }
  824:     my $defdom=$ENV{'user.domain'};
  825:     if ($ENV{'form.recdom'}) { $defdom=$ENV{'form.recdom'}; }
  826:       $r->print(
  827:                 '<form action="/adm/email"  name="compemail" method="post"'.
  828:                 ' enctype="multipart/form-data">'."\n".
  829:                 '<input type="hidden" name="sendmail" value="on">'."\n".
  830:                 '<table>');
  831:     unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
  832:         my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
  833:         my $selectlink=&Apache::loncommon::selectstudent_link
  834: 	    ('compemail','recuname','recdomain');
  835:        $r->print(<<"ENDREC");
  836: <table>
  837: <tr><td>$lt{'us'}:</td><td><input type="text" size="12" name="recuname" value="$ENV{'form.recname'}"></td><td rowspan="2">$selectlink</td></tr>
  838: <tr><td>$lt{'do'}:</td>
  839: <td>$domform</td></tr>
  840: ENDREC
  841:     }
  842:     my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
  843:     if ($broadcast ne 'upload') {
  844:        $r->print(<<"ENDCOMP");
  845: <tr><td>$lt{'ad'}<br /><tt>username\@domain,username\@domain, ...
  846: </tt></td><td>
  847: <input type="text" size="50" name="additionalrec"></td></tr>
  848: <tr><td>$lt{'sb'}:</td><td><input type="text" size="50" name="subject" value="$dissub">
  849: </td></tr></table>
  850: $latexHelp
  851: <textarea name="message" cols="80" rows="10" wrap="hard">$dismsg
  852: </textarea></p><br />
  853: $dispcrit
  854: <input type="submit" name="send" value="$func $lt{'ma'}" />
  855: <input type="submit" name="cancel" value="$lt{'ca'}" />
  856: ENDCOMP
  857:     } else { # $broadcast is 'upload'
  858: 	$r->print(<<ENDUPLOAD);
  859: <input type=hidden name=sendmode value=upload>
  860: <h3>Generate messages from a file</h3>
  861: <p>
  862: Subject: <input type=text size=50 name=subject>
  863: </p>
  864: <p>General message text<br />
  865: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
  866: </textarea></p>
  867: <p>
  868: The file format for the uploaded portion of the message is:
  869: <pre>
  870: username1\@domain1: text
  871: username2\@domain2: text
  872: username3\@domain1: text
  873: </pre>
  874: </p>
  875: <p>
  876: The messages will be assembled from all lines with the respective 
  877: <tt>username\@domain</tt>, and appended to the general message text.</p>
  878: <p>
  879: <input type=file name=upfile size=20><p>
  880: $dispcrit
  881: <input type=submit value="Upload and send">
  882: ENDUPLOAD
  883:     }
  884:     if ($broadcast eq 'group') {
  885:        &discourse;
  886:     }
  887:     $r->print('</form>');
  888: }
  889: 
  890: # ---------------------------------------------------- Display all face to face
  891: 
  892: sub disfacetoface {
  893:     my ($r,$user,$domain)=@_;
  894:     unless ($ENV{'request.course.id'}) { return; }
  895:     unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
  896: 	return;
  897:     }
  898:     my %records=&Apache::lonnet::dump('nohist_email',
  899: 			 $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  900: 			 $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
  901:                          '%255b'.$user.'%253a'.$domain.'%255d');
  902:     my $result='';
  903:     foreach (sort keys %records) {
  904:         my %content=&unpackagemsg($records{$_});
  905:         next if ($content{'senderdomain'} eq '');
  906:         $content{'message'}=~s/\n/\<br\>/g;
  907:         if ($content{'subject'}=~/^Record/) {
  908: 	    $result.='<h3>'.&mt('Record').'</h3>';
  909:         } else {
  910:             $result.='<h3>'.&mt('Sent Message').'</h3>';
  911:             %content=&unpackagemsg($content{'message'});
  912:             $content{'message'}=
  913:                 '<b>Subject: '.$content{'subject'}.'</b><br />'.
  914: 		$content{'message'};
  915:         }
  916:         $result.=&mt('By').': <b>'.
  917: &Apache::loncommon::aboutmewrapper(
  918:  &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
  919: $content{'sendername'}.'@'.
  920:             $content{'senderdomain'}.') '.$content{'time'}.
  921:             '<br><blockquote>'.
  922:               &Apache::lontexconvert::msgtexconverted($content{'message'}).
  923: 	      '</blockquote>';
  924:      }
  925:     # Check to see if there were any messages.
  926:     if ($result eq '') {
  927:         $r->print("<p><b>No notes, face-to-face discussion records, or critical messages in this course.</b></p>");
  928:     } else {
  929:        $r->print($result);
  930:     }
  931: }
  932: 
  933: # ---------------------------------------------------------------- Face to face
  934: 
  935: sub facetoface {
  936:     my ($r,$stage)=@_;
  937:     unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
  938: 	return;
  939:     }
  940: # from query string
  941:     if ($ENV{'form.recname'}) { $ENV{'form.recuname'}=$ENV{'form.recname'}; }
  942:     if ($ENV{'form.recdom'}) { $ENV{'form.recdomain'}=$ENV{'form.recdom'}; }
  943: 
  944:     my $defdom=$ENV{'user.domain'};
  945: # already filled in
  946:     if ($ENV{'form.recdomain'}) { $defdom=$ENV{'form.recdomain'}; }
  947: # generate output
  948:     my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
  949:     my $stdbrws = &Apache::loncommon::selectstudent_link
  950: 	('stdselect','recuname','recdomain');
  951:     $r->print(<<"ENDTREC");
  952: <h3>User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course</h3>
  953: <form method="post" action="/adm/email" name="stdselect">
  954: <input type="hidden" name="recordftf" value="retrieve" />
  955: <table>
  956: <tr><td>Username:</td><td><input type=text size=12 name=recuname value="$ENV{'form.recuname'}"></td>
  957: <td rowspan="2">
  958: $stdbrws
  959: <input type="submit" value="Retrieve discussion and message records"></td>
  960: </tr>
  961: <tr><td>Domain:</td>
  962: <td>$domform</td></tr>
  963: </table>
  964: </form>
  965: ENDTREC
  966:     if (($stage ne 'query') &&
  967:         ($ENV{'form.recdomain'}) && ($ENV{'form.recuname'})) {
  968:         chomp($ENV{'form.newrecord'});
  969:         if ($ENV{'form.newrecord'}) {
  970:            &user_normal_msg_raw(
  971:             $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
  972:             $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  973:             'Record ['.$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}.']',
  974: 	    $ENV{'form.newrecord'});
  975:         }
  976:         $r->print('<h3>'.&Apache::loncommon::plainname($ENV{'form.recuname'},
  977: 				     $ENV{'form.recdomain'}).'</h3>');
  978:         &disfacetoface($r,$ENV{'form.recuname'},$ENV{'form.recdomain'});
  979: 	$r->print(<<ENDRHEAD);
  980: <form method="post" action="/adm/email">
  981: <input name="recdomain" value="$ENV{'form.recdomain'}" type="hidden" />
  982: <input name="recuname" value="$ENV{'form.recuname'}" type="hidden" />
  983: ENDRHEAD
  984:         $r->print(<<ENDBFORM);
  985: <hr />New Record (record is visible to course faculty and staff)<br />
  986: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
  987: <br />
  988: <input type="hidden" name="recordftf" value="post" />
  989: <input type="submit" value="Post this record" />
  990: </form>
  991: ENDBFORM
  992:     }
  993: }
  994: 
  995: # ===================================================================== Handler
  996: 
  997: sub handler {
  998:     my $r=shift;
  999: 
 1000: # ----------------------------------------------------------- Set document type
 1001: 
 1002:   &Apache::loncommon::content_type($r,'text/html');
 1003:   $r->send_http_header;
 1004: 
 1005:   return OK if $r->header_only;
 1006: 
 1007: # --------------------------- Get query string for limited number of parameters
 1008:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 1009:         ['display','replyto','forward','markread','markdel','markunread',
 1010:          'sendreply','compose','sendmail','critical','recname','recdom',
 1011:          'recordftf','sortedby']);
 1012:     $sqs='&sortedby='.$ENV{'form.sortedby'};
 1013: # ------------------------------------------------------ They checked for email
 1014:   &Apache::lonnet::put('email_status',{'recnewemail'=>0});
 1015: # --------------------------------------------------------------- Render Output
 1016:   if (!$ENV{'form.display'}) {
 1017:       $r->print('<html><head><title>EMail and Messaging</title>'.
 1018: 		&Apache::loncommon::studentbrowser_javascript().'</head>'.
 1019: 		&Apache::loncommon::bodytag('EMail and Messages'));
 1020:   }
 1021:   if ($ENV{'form.display'}) {
 1022:       my $msgid=$ENV{'form.display'};
 1023:       &statuschange($msgid,'read');
 1024:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
 1025:       my %content=&unpackagemsg($message{$msgid});
 1026: # info to generate "next" and "previous" buttons
 1027:       my @messages=&sortedmessages();
 1028:       my $counter=0;
 1029:       $r->print('<pre>');
 1030:       my $escmsgid=&Apache::lonnet::escape($msgid);
 1031:       foreach (@messages) {
 1032:  	  if ($_->[5] eq $escmsgid){
 1033:  	      last;
 1034:  	  }
 1035:  	  $counter++;
 1036:       }
 1037:       $r->print('</pre>');
 1038:       my $number_of_messages = scalar(@messages); #subtract 1 for last index
 1039: # start output
 1040:       $r->print('<html><head><title>EMail and Messaging</title>');
 1041:       if (defined($content{'baseurl'})) {
 1042: 	  $r->print("<base href=\"http://$ENV{'SERVER_NAME'}/$content{'baseurl'}\" />");
 1043:       }
 1044:       $r->print(&Apache::loncommon::studentbrowser_javascript().
 1045: 		'</head>'.
 1046: 		&Apache::loncommon::bodytag('EMail and Messages'));
 1047:       $r->print('<b>'.&mt('Subject').':</b> '.$content{'subject'}.
 1048:              '<br><b>'.&mt('From').':</b> '.
 1049: &Apache::loncommon::aboutmewrapper(
 1050: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
 1051: $content{'sendername'},$content{'senderdomain'}).' ('.
 1052:                                  $content{'sendername'}.' at '.
 1053:                                  $content{'senderdomain'}.') '.
 1054:              '<br><b>'.&mt('Time').':</b> '.$content{'time'}.'<p>'.
 1055:              '<table border=2><tr bgcolor="#FFFFAA"><td>'.&mt('Functions').':</td>'.
 1056:            '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).$sqs.
 1057:              '"><b>'.&mt('Reply').'</b></a></td>'.
 1058:            '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).$sqs.
 1059:              '"><b>'.&mt('Forward').'</b></a></td>'.
 1060:         '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).$sqs.
 1061:              '"><b>'.&mt('Mark Unread').'</b></a></td>'.
 1062:         '<td><a href="/adm/email?markdel='.&Apache::lonnet::escape($msgid).$sqs.
 1063:              '"><b>Delete</b></a></td>'.
 1064: 		'<td><a href="/adm/email?sortedby='.$ENV{'form.sortedby'}.
 1065: 		'"><b>'.&mt('Display all Messages').'</b></a></td>');
 1066:       if ($counter > 0){
 1067:  	  $r->print('<td><a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.
 1068:            '"><b>'.&mt('Previous').'</b></a></td>');
 1069:        }
 1070:        if ($counter < $number_of_messages - 1){
 1071:  	  $r->print('<td><a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.
 1072:            '"><b>'.&mt('Next').'</b></a></td>');
 1073:        }
 1074:        $r->print('</tr></table><p><pre>'.
 1075:              &Apache::lontexconvert::msgtexconverted($content{'message'}).
 1076:              '</pre><hr>'.$content{'citation'});
 1077:   } elsif ($ENV{'form.replyto'}) {
 1078:       &comprep($r,$ENV{'form.replyto'});
 1079:   } elsif ($ENV{'form.sendreply'}) {
 1080:       if ($ENV{'form.send'}) {
 1081: 	  my $msgid=$ENV{'form.sendreply'};
 1082: 	  my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
 1083: 	  my %content=&unpackagemsg($message{$msgid},1);
 1084: 	  &statuschange($msgid,'replied');
 1085: 	  if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
 1086: 	      (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
 1087: 	      $r->print(&mt('Sending critical message').': '.
 1088: 			&user_crit_msg($content{'sendername'},
 1089: 				       $content{'senderdomain'},
 1090: 				       &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
 1091: 				       &Apache::lonfeedback::clear_out_html($ENV{'form.message'}),
 1092: 				       $ENV{'form.sendbck'}));
 1093: 	  } else {
 1094: 	      $r->print(&mt('Sending').': '.&user_normal_msg($content{'sendername'},
 1095: 							     $content{'senderdomain'},
 1096: 							     &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
 1097: 							     &Apache::lonfeedback::clear_out_html($ENV{'form.message'})));
 1098: 	  }
 1099:       }
 1100:       if ($ENV{'form.displayedcrit'}) {
 1101:           &discrit($r);
 1102:       } else {
 1103: 	  &disall($r);
 1104:       }
 1105:   } elsif ($ENV{'form.confirm'}) {
 1106:       foreach (keys %ENV) {
 1107:           if ($_=~/^form\.rec\_(.*)$/) {
 1108: 	      $r->print('<b>Confirming Receipt:</b> '.
 1109:                         &user_crit_received($1).'<br>');
 1110:           }
 1111:           if ($_=~/^form\.reprec\_(.*)$/) {
 1112:               my $msgid=$1;
 1113: 	      $r->print('<b>Confirming Receipt:</b> '.
 1114:                         &user_crit_received($msgid).'<br>');
 1115:               &comprep($r,$msgid);
 1116:           }
 1117:       }
 1118:       &discrit($r);
 1119:   } elsif ($ENV{'form.critical'}) {
 1120:       &discrit($r);
 1121:   } elsif ($ENV{'form.forward'}) {
 1122:       &compout($r,$ENV{'form.forward'});
 1123:   } elsif ($ENV{'form.markread'}) {
 1124:   } elsif ($ENV{'form.markdel'}) {
 1125:       &statuschange($ENV{'form.markdel'},'deleted');
 1126:       &disall($r);
 1127:   } elsif ($ENV{'form.markeddel'}) {
 1128:       my $total=0;
 1129:       foreach (keys %ENV) {
 1130:           if ($_=~/^form\.delmark_(.*)$/) {
 1131: 	      &statuschange(&Apache::lonnet::unescape($1),'deleted');
 1132:               $total++;
 1133:           }
 1134:       }
 1135:       $r->print('Deleted '.$total.' message(s)<p>');
 1136:       &disall($r);
 1137:   } elsif ($ENV{'form.markunread'}) {
 1138:       &statuschange($ENV{'form.markunread'},'new');
 1139:       &disall($r);
 1140:   } elsif ($ENV{'form.compose'}) {
 1141:       &compout($r,'',$ENV{'form.compose'});
 1142:   } elsif ($ENV{'form.recordftf'}) {
 1143:       &facetoface($r,$ENV{'form.recordftf'});
 1144:   } elsif ($ENV{'form.sendmail'}) {
 1145:       my $sendstatus='';
 1146:       if ($ENV{'form.send'}) {
 1147: 	  my %content=();
 1148: 	  undef %content;
 1149: 	  if ($ENV{'form.forwid'}) {
 1150: 	      my $msgid=$ENV{'form.forwid'};
 1151: 	      my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
 1152: 	      %content=&unpackagemsg($message{$msgid},1);
 1153: 	      &statuschange($msgid,'forwarded');
 1154: 	      $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
 1155: 		  $content{'message'};
 1156: 	  }
 1157: 	  my %toaddr=();
 1158: 	  undef %toaddr;
 1159: 	  if ($ENV{'form.sendmode'} eq 'group') {
 1160: 	      foreach (keys %ENV) {
 1161: 		  if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
 1162: 		      $toaddr{$1}='';
 1163: 		  }
 1164: 	      }
 1165: 	  } elsif ($ENV{'form.sendmode'} eq 'upload') {
 1166: 	      foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) {
 1167: 		  my ($rec,$txt)=split(/\s*\:\s*/,$_);
 1168: 		  if ($txt) {
 1169: 		      $rec=~s/\@/\:/;
 1170: 		      $toaddr{$rec}.=$txt."\n";
 1171: 		  }
 1172: 	      }
 1173: 	  } else {
 1174: 	      $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
 1175: 	  }
 1176: 	  if ($ENV{'form.additionalrec'}) {
 1177: 	      foreach (split(/\,/,$ENV{'form.additionalrec'})) {
 1178: 		  my ($auname,$audom)=split(/\@/,$_);
 1179: 		  $toaddr{$auname.':'.$audom}='';
 1180: 	      }
 1181: 	  }
 1182: 	  foreach (keys %toaddr) {
 1183: 	      my ($recuname,$recdomain)=split(/\:/,$_);
 1184: 	      my $msgtxt=&Apache::lonfeedback::clear_out_html($ENV{'form.message'});
 1185: 	      if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }    
 1186: 	      if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
 1187: 		  (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
 1188: 		  $r->print(&mt('Sending critical message').' ...');
 1189:                   $sendstatus.=' '.&user_crit_msg($recuname,$recdomain,
 1190: 					   &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
 1191: 					   $msgtxt,
 1192: 					   $ENV{'form.sendbck'});
 1193: 	      } else {
 1194: 		  $r->print(&mt('Sending').' ...');
 1195:                   $sendstatus.=' '.&user_normal_msg($recuname,$recdomain,
 1196: 				                         &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
 1197: 							 $msgtxt,
 1198: 							 $content{'citation'});
 1199: 	      }
 1200: 	      $r->print('<br />');
 1201: 	  }
 1202:       }
 1203:       if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
 1204: 	  if ($ENV{'form.displayedcrit'}) {
 1205: 	      &discrit($r);
 1206: 	  } else {
 1207: 	      &disall($r);
 1208: 	  }
 1209:       } else {
 1210: 	  $r->print(
 1211:   '<h2><font color="red">'.&mt('Could not deliver message').'</font></h2>'.
 1212:   &mt('Please use the browser "Back" button and correct the recipient addresses')
 1213: 		    );
 1214:       }
 1215:   } else {
 1216:       &disall($r);
 1217:   }
 1218:   $r->print('</body></html>');
 1219:   return OK;
 1220: 
 1221: }
 1222: # ================================================= Main program, reset counter
 1223: 
 1224: BEGIN {
 1225:     $msgcount=0;
 1226: }
 1227: 
 1228: =pod
 1229: 
 1230: =back
 1231: 
 1232: =cut
 1233: 
 1234: 1; 
 1235: 
 1236: __END__
 1237: 
 1238: 
 1239: 
 1240: 
 1241: 
 1242: 
 1243: 

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