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

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

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