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

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

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