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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: #
                      3: # Routines for messaging
                      4: #
                      5: # (Routines to control the menu
                      6: #
                      7: # (TeX Conversion Module
                      8: #
                      9: # 05/29/00,05/30 Gerd Kortemeyer)
                     10: #
                     11: # 10/05 Gerd Kortemeyer)
                     12: #
1.6       www        13: # 10/19,10/20,10/30,
                     14: # 02/06/01 Gerd Kortemeyer
1.11      www        15: # 07/27 Guy Albertelli
1.23    ! www        16: # 07/27,07/28,07/30,08/03,08/06,08/08,08/09,08/10,8/13,8/15,
        !            17: # 10/1 Gerd Kortemeyer
1.1       www        18: 
                     19: package Apache::lonmsg;
                     20: 
                     21: use strict;
                     22: use Apache::lonnet();
1.2       www        23: use vars qw($msgcount);
                     24: use HTML::TokeParser;
1.5       www        25: use Apache::Constants qw(:common);
1.1       www        26: 
                     27: # ===================================================================== Package
                     28: 
1.3       www        29: sub packagemsg {
1.7       www        30:     my ($subject,$message,$citation)=@_;
1.1       www        31:     $message=~s/\</\&lt\;/g;
                     32:     $message=~s/\>/\&gt\;/g;
1.7       www        33:     $citation=~s/\</\&lt\;/g;
                     34:     $citation=~s/\>/\&gt\;/g;
1.1       www        35:     $subject=~s/\</\&lt\;/g;
                     36:     $subject=~s/\>/\&gt\;/g;
1.2       www        37:     my $now=time;
                     38:     $msgcount++;
1.6       www        39:     my $partsubj=$subject;
                     40:     $partsubj=&Apache::lonnet::escape($partsubj);
                     41:     $partsubj=substr($partsubj,0,50);
                     42:     my $msgid=&Apache::lonnet::escape(
                     43:            $now.':'.$partsubj.':'.$ENV{'user.name'}.':'.
                     44:            $ENV{'user.domain'}.':'.$msgcount.':'.$$);
1.2       www        45:     return $msgid,
                     46:            '<sendername>'.$ENV{'user.name'}.'</sendername>'.
1.1       www        47:            '<senderdomain>'.$ENV{'user.domain'}.'</senderdomain>'.
                     48:            '<subject>'.$subject.'</subject>'.
1.2       www        49: 	   '<time>'.localtime($now).'</time>'.
1.1       www        50: 	   '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
                     51:            '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
                     52: 	   '<client>'.$ENV{'REMOTE_ADDR'}.'</client>'.
                     53: 	   '<browsertype>'.$ENV{'browser.type'}.'</browsertype>'.
                     54: 	   '<browseros>'.$ENV{'browser.os'}.'</browseros>'.
                     55: 	   '<browserversion>'.$ENV{'browser.version'}.'</browserversion>'.
                     56:            '<browsermathml>'.$ENV{'browser.mathml'}.'</browsermathml>'.
                     57: 	   '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
                     58: 	   '<courseid>'.$ENV{'request.course.id'}.'</courseid>'.
                     59: 	   '<role>'.$ENV{'request.role'}.'</role>'.
                     60: 	   '<resource>'.$ENV{'request.filename'}.'</resource>'.
1.2       www        61:            '<msgid>'.$msgid.'</msgid>'.
1.7       www        62: 	   '<message>'.$message.'</message>'.
                     63: 	   '<citation>'.$citation.'</citation>';
1.1       www        64: }
                     65: 
1.2       www        66: # ================================================== Unpack message into a hash
                     67: 
1.3       www        68: sub unpackagemsg {
1.2       www        69:     my $message=shift;
                     70:     my %content=();
                     71:     my $parser=HTML::TokeParser->new(\$message);
                     72:     my $token;
                     73:     while ($token=$parser->get_token) {
                     74:        if ($token->[0] eq 'S') {
                     75: 	   my $entry=$token->[1];
                     76:            my $value=$parser->get_text('/'.$entry);
                     77:            $content{$entry}=$value;
                     78:        }
                     79:     }
                     80:     return %content;
                     81: }
                     82: 
1.6       www        83: # ======================================================= Get info out of msgid
                     84: 
                     85: sub unpackmsgid {
1.7       www        86:     my $msgid=&Apache::lonnet::unescape(shift);
1.6       www        87:     my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/,
1.7       www        88:                           &Apache::lonnet::unescape($msgid));
1.8       albertel   89:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
1.6       www        90:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
                     91:     unless ($status{$msgid}) { $status{$msgid}='new'; }
                     92:     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});
                     93: } 
                     94: 
1.1       www        95: # =============================== Automated message to the author of a resource
                     96: 
                     97: sub author_res_msg {
                     98:     my ($filename,$message)=@_;
1.2       www        99:     unless ($message) { return 'empty'; }
1.1       www       100:     $filename=&Apache::lonnet::declutter($filename);
                    101:     my ($domain,$author,@dummy)=split(/\//,$filename);
                    102:     my $homeserver=&Apache::lonnet::homeserver($author,$domain);
                    103:     if ($homeserver ne 'no_host') {
                    104:        my $id=unpack("%32C*",$message);
1.2       www       105:        my $msgid;
1.3       www       106:        ($msgid,$message)=&packagemsg($filename,$message);
                    107:        return &Apache::lonnet::reply('put:'.$domain.':'.$author.
                    108:          ':nohist_res_msgs:'.
                    109:           &Apache::lonnet::escape($filename.'_'.$id).'='.
                    110:           &Apache::lonnet::escape($message),$homeserver);
1.1       www       111:     }
1.2       www       112:     return 'no_host';
1.1       www       113: }
                    114: 
                    115: # ================================================== Critical message to a user
                    116: 
                    117: sub user_crit_msg {
                    118:     my ($user,$domain,$subject,$message)=@_;
1.2       www       119: # Check if allowed missing
                    120:     my $status='';
                    121:     my $msgid='undefined';
                    122:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
                    123:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
                    124:     if ($homeserver ne 'no_host') {
1.3       www       125:        ($msgid,$message)=&packagemsg($subject,$message);
1.4       www       126:        $status=&Apache::lonnet::critical(
                    127:            'put:'.$domain.':'.$user.':critical:'.
                    128:            &Apache::lonnet::escape($msgid).'='.
                    129:            &Apache::lonnet::escape($message),$homeserver);
1.2       www       130:     } else {
                    131:        $status='no_host';
                    132:     }
                    133:     &Apache::lonnet::logthis(
1.4       www       134:       'Sending critical email '.$msgid.
1.2       www       135:       ', log status: '.
                    136:       &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
                    137:                          $ENV{'user.home'},
                    138:       'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
1.4       www       139:       .$status));
1.2       www       140:     return $status;
                    141: }
                    142: 
                    143: # =================================================== Critical message received
                    144: 
                    145: sub user_crit_received {
1.12      www       146:     my $msgid=shift;
                    147:     my %message=&Apache::lonnet::get('critical',[$msgid]);
                    148:     my %contents=&unpackagemsg($message{$msgid});
1.5       www       149:     my $status='rec: '.
                    150:      &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
1.4       www       151:                      'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'},
                    152:                      'User '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}.
                    153:                      ' acknowledged receipt of message "'.
                    154:                      $contents{'subject'}.'" dated '.$contents{'time'}.".\n\n"
                    155:                      .'Message ID: '.$contents{'msgid'});
1.5       www       156:     $status.=' trans: '.
1.12      www       157:      &Apache::lonnet::put(
                    158:      'nohist_email',{$contents{'msgid'} => $message{$msgid}});
1.5       www       159:     $status.=' del: '.
1.9       albertel  160:      &Apache::lonnet::del('critical',[$contents{'msgid'}]);
1.5       www       161:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
                    162:                          $ENV{'user.home'},'Received critical message '.
                    163:                          $contents{'msgid'}.
                    164:                          ', '.$status);
1.12      www       165:     return $status;
1.2       www       166: }
                    167: 
                    168: # ======================================================== Normal communication
                    169: 
                    170: sub user_normal_msg {
1.7       www       171:     my ($user,$domain,$subject,$message,$citation)=@_;
1.2       www       172: # Check if allowed missing
                    173:     my $status='';
                    174:     my $msgid='undefined';
                    175:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
                    176:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
                    177:     if ($homeserver ne 'no_host') {
1.7       www       178:        ($msgid,$message)=&packagemsg($subject,$message,$citation);
1.4       www       179:        $status=&Apache::lonnet::critical(
                    180:            'put:'.$domain.':'.$user.':nohist_email:'.
                    181:            &Apache::lonnet::escape($msgid).'='.
                    182:            &Apache::lonnet::escape($message),$homeserver);
1.2       www       183:     } else {
                    184:        $status='no_host';
                    185:     }
                    186:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
                    187:                          $ENV{'user.home'},
                    188:       'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
                    189:     return $status;
                    190: }
                    191: 
1.7       www       192: # =============================================================== Status Change
                    193: 
                    194: sub statuschange {
                    195:     my ($msgid,$newstatus)=@_;
1.8       albertel  196:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
1.7       www       197:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
                    198:     unless ($status{$msgid}) { $status{$msgid}='new'; }
                    199:     unless (($status{$msgid} eq 'replied') || 
                    200:             ($status{$msgid} eq 'forwarded')) {
1.10      albertel  201: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
1.7       www       202:     }
1.14      www       203:     if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
                    204: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
                    205:     }
1.7       www       206: }
1.14      www       207: 
1.17      www       208: # ======================================================= Display a course list
                    209: 
                    210: sub discourse {
                    211:     my $r=shift;
                    212:     my %courselist=&Apache::lonnet::dump(
                    213:                    'classlist',
                    214: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    215: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    216:     my $now=time;
                    217:     $r->print(<<ENDDISHEADER);
                    218: <input type=hidden name=sendmode value=group>
                    219: <script>
                    220:     function checkall() {
                    221: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
                    222:             if 
                    223:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
                    224: 	      document.forms.compemail.elements[i].checked=true;
                    225:             }
                    226:         }
                    227:     }
                    228: 
1.19      www       229:     function checksec() {
                    230: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
                    231:             if 
                    232:           (document.forms.compemail.elements[i].name.indexOf
                    233:            ('send_to_&&&'+document.forms.compemail.chksec.value)==0) {
                    234: 	      document.forms.compemail.elements[i].checked=true;
                    235:             }
                    236:         }
                    237:     }
                    238: 
1.17      www       239:     function uncheckall() {
                    240: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
                    241:             if 
                    242:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
                    243: 	      document.forms.compemail.elements[i].checked=false;
                    244:             }
                    245:         }
                    246:     }
                    247: </script>
1.19      www       248: <input type=button onClick="checkall()" value="Check for All">&nbsp;
                    249: <input type=button onClick="checksec()" value="Check for Section/Group">
                    250: <input type=text size=5 name=chksec>&nbsp;
1.17      www       251: <input type=button onClick="uncheckall()" value="Check for None">
                    252: <p>
                    253: ENDDISHEADER
                    254:     map {
                    255:         my ($end,$start)=split(/\:/,$courselist{$_});
                    256:         my $active=1;
                    257:         if (($end) && ($now>$end)) { $active=0; }
                    258:         if ($active) {
                    259:            my ($sname,$sdom)=split(/\:/,$_);
                    260:            my %reply=&Apache::lonnet::get('environment',
                    261:               ['firstname','middlename','lastname','generation'],
                    262:               $sdom,$sname);
1.19      www       263:            my $section=&Apache::lonnet::usection
                    264: 	       ($sdom,$sname,$ENV{'request.course.id'});
                    265:            $r->print(
                    266:         '<br><input type=checkbox name="send_to_&&&'.$section.'&&&_'.$_.'"> '.
1.17      www       267: 		      $reply{'firstname'}.' '. 
                    268:                       $reply{'middlename'}.' '.
                    269:                       $reply{'lastname'}.' '.
                    270:                       $reply{'generation'}.
1.19      www       271:                       ' ('.$_.') '.$section);
1.17      www       272:         } 
                    273:     } sort keys %courselist;
                    274: }
                    275: 
1.13      www       276: # ==================================================== Display Critical Message
1.5       www       277: 
1.12      www       278: sub discrit {
                    279:     my $r=shift;
                    280:       $r->print('<h1><font color=red>Critical Messages</font></h1>'.
                    281:          '<form action=/adm/email method=post>'.
                    282:          '<input type=hidden name=confirm value=true>');
                    283:       my %what=&Apache::lonnet::dump('critical');
                    284:       map {
                    285:           my %content=&unpackagemsg($what{$_});
                    286:           $content{'message'}=~s/\n/\<br\>/g;
                    287: 	  $r->print('<hr>From: <b>'.$content{'sendername'}.'@'.
                    288:                     $content{'senderdomain'}.'</b> ('.$content{'time'}.
                    289:                     ')<br><blockquote>'.$content{'message'}.'</blockquote>'.
1.13      www       290:   '<input type=submit name="rec_'.$_.'" value="Confirm Receipt">'.
                    291:  '<input type=submit name="reprec_'.$_.'" value="Confirm Receipt and Reply">');
1.12      www       292:       } sort keys %what;
1.16      www       293:       $r->print(
                    294:           '<input type=hidden name="displayedcrit" value="true"></form>');
1.12      www       295: }
                    296: 
1.13      www       297: # =============================================================== Compose reply
                    298: 
                    299: sub comprep {
                    300:     my ($r,$msgid)=@_;
                    301:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
                    302:       my %content=&unpackagemsg($message{$msgid});
                    303:       my $quotemsg='> '.$content{'message'};
                    304:       $quotemsg=~s/\r/\n/g;
                    305:       $quotemsg=~s/\f/\n/g;
                    306:       $quotemsg=~s/\n+/\n\> /g;
                    307:       my $subject='Re: '.$content{'subject'};
                    308:       my $dispcrit='';
                    309:       if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
                    310:          $dispcrit=
                    311: 	     '<input type=checkbox name=critmsg> Send as critical message<p>';
                    312:       }
                    313:       $r->print(<<"ENDREPLY");
                    314: <form action="/adm/email" method=post>
                    315: <input type=hidden name=sendreply value="$msgid">
                    316: Subject: <input type=text size=50 name=subject value="$subject"><p>
1.23    ! www       317: <textarea name=message cols=64 rows=10 wrap=hard>
1.13      www       318: $quotemsg
                    319: </textarea><p>
                    320: $dispcrit
                    321: <input type=submit value="Send Reply">
                    322: </form>
                    323: ENDREPLY
                    324: }
                    325: 
1.15      www       326: # ======================================================== Display all messages
                    327: 
1.14      www       328: sub disall {
                    329:     my $r=shift;
                    330:     $r->print('<h1>Display All Messages</h1>'.
                    331:      '<table border=2><tr><th colspan=2>&nbsp</th><th>Date</th>'.
                    332:      '<th>Username</th><th>Domain</th><th>Subject</th><th>Status</th></tr>');
                    333:     map {
                    334:         my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
                    335: 	    &Apache::lonmsg::unpackmsgid($_);
                    336:        unless ($status eq 'deleted') {
                    337:         if ($status eq 'new') {
                    338: 	    $r->print('<tr bgcolor="#FFBB77">');
                    339:         } elsif ($status eq 'read') {
                    340: 	    $r->print('<tr bgcolor="#BBBB77">');
                    341:         } elsif ($status eq 'replied') {
                    342: 	    $r->print('<tr bgcolor="#AAAA88">');
                    343: 	} else {
                    344: 	    $r->print('<tr bgcolor="#99BBBB">');
                    345:         }
                    346:         $r->print('<td><a href="/adm/email?display='.$_.
                    347:                   '">Open</a></td><td><a href="/adm/email?markdel='.$_.
                    348:                   '">Delete</a></td><td>'.localtime($sendtime).'</td><td>'.
                    349:                   $fromname.'</td><td>'.$fromdomain.'</td><td>'.
                    350: 		      &Apache::lonnet::unescape($shortsubj).'</td><td>'.
                    351:                       $status.'</td></tr>');
                    352:        }
                    353:     } sort split(/\&/,&Apache::lonnet::reply('keys:'.
                    354: 					$ENV{'user.domain'}.':'.
                    355:                                         $ENV{'user.name'}.':nohist_email',
                    356:                                         $ENV{'user.home'}));
                    357:     $r->print('</table></body></html>');
                    358: }
                    359: 
1.15      www       360: # ============================================================== Compose output
                    361: 
                    362: sub compout {
1.17      www       363:     my ($r,$forwarding,$broadcast)=@_;
1.15      www       364:       my $dispcrit='';
                    365:     my $dissub='';
                    366:     my $dismsg='';
                    367:     my $func='Send New';
                    368:       if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
                    369:          $dispcrit=
                    370: 	     '<input type=checkbox name=critmsg> Send as critical message<p>';
                    371:       }
                    372:     if ($forwarding) {
                    373:        $dispcrit.='<input type=hidden name=forwid value="'.
                    374: 	   $forwarding.'">';
                    375:        $func='Forward';
                    376:       my %message=&Apache::lonnet::get('nohist_email',[$forwarding]);
                    377:       my %content=&unpackagemsg($message{$forwarding});
                    378: 
                    379:        $dissub='Forwarding: '.$content{'subject'};
                    380:        $dismsg='Forwarded message from '.
                    381: 	   $content{'sendername'}.' at '.$content{'senderdomain'};
                    382:     }
                    383:     my $defdom=$ENV{'user.domain'};
1.22      www       384:       $r->print(
                    385:                 '<form action="/adm/email"  name="compemail" method=post'.
                    386:                 ' enctype="multipart/form-data">'.
1.17      www       387:                 '<input type=hidden name=sendmail value=on><table>');
1.22      www       388:     unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
1.17      www       389:        $r->print(<<"ENDREC");
1.15      www       390: <table>
                    391: <tr><td>Username:</td><td><input type=text size=12 name=recuname></td></tr>
                    392: <tr><td>Domain:</td>
                    393: <td><input type=text size=12 name=recdomain value="$defdom"></td></tr>
1.17      www       394: ENDREC
                    395:     }
1.22      www       396:     unless ($broadcast eq 'upload') {
                    397:        $r->print(<<"ENDCOMP");
1.20      www       398: <tr><td>Additional Recipients<br><tt>username\@domain,username\@domain, ...
                    399: </tt></td><td>
                    400: <input type=text size=50 name=additionalrec></td></tr>
1.15      www       401: <tr><td>Subject:</td><td><input type=text size=50 name=subject value="$dissub">
                    402: </td></tr></table>
1.23    ! www       403: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
1.15      www       404: </textarea><p>
                    405: $dispcrit
                    406: <input type=submit value="$func Mail">
                    407: ENDCOMP
1.22      www       408:     }
                    409:     if ($broadcast eq 'upload') {
                    410: 	$r->print(<<ENDUPLOAD);
                    411: <input type=hidden name=sendmode value=upload>
                    412: <h3>Generate messages from a file</h3>
                    413: Subject: <input type=text size=50 name=subject>
                    414: <pre>
                    415: username1\@domain1: text
                    416: username2\@domain2: text
                    417: username1\@domain1: text
                    418: </pre>
                    419: The messages will be assembled from all lines with the respective 
                    420: <tt>username\@domain</tt>, and appended to the general message text.<p>
                    421: <input type=file name=upfile size=20><p>
                    422: General message text:<p>
1.23    ! www       423: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
1.22      www       424: </textarea><p>
                    425: $dispcrit
                    426: <input type=submit value="Upload and send">
                    427: ENDUPLOAD
                    428:     }
1.17      www       429:     if ($broadcast eq 'group') {
                    430:        &discourse;
                    431:     }
                    432:     $r->print('</form>');
1.15      www       433: }
                    434: 
1.13      www       435: # ===================================================================== Handler
                    436: 
1.5       www       437: sub handler {
                    438:     my $r=shift;
                    439: 
                    440: # ----------------------------------------------------------- Set document type
                    441: 
                    442:   $r->content_type('text/html');
                    443:   $r->send_http_header;
                    444: 
                    445:   return OK if $r->header_only;
                    446: 
1.6       www       447: # --------------------------- Get query string for limited number of parameters
                    448: 
                    449:     map {
                    450:        my ($name, $value) = split(/=/,$_);
                    451:        $value =~ tr/+/ /;
                    452:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                    453:        if (($name eq 'display') || ($name eq 'replyto') || 
1.14      www       454:            ($name eq 'forward') || ($name eq 'markread') ||
                    455:            ($name eq 'markdel') || ($name eq 'markunread') ||
1.12      www       456:            ($name eq 'sendreply') || ($name eq 'compose') ||
                    457:            ($name eq 'sendmail') || ($name eq 'critical')) {
1.6       www       458:            unless ($ENV{'form.'.$name}) {
                    459:               $ENV{'form.'.$name}=$value;
                    460: 	   }
                    461:        }
                    462:     } (split(/&/,$ENV{'QUERY_STRING'}));
                    463: 
1.5       www       464: # --------------------------------------------------------------- Render Output
                    465:   
                    466:   $r->print('<html><head><title>EMail and Messaging</title></head>');
1.7       www       467:   $r->print(
                    468:    '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
1.5       www       469:   $r->print('<h1>EMail</h1>');
1.6       www       470:   if ($ENV{'form.display'}) {
1.7       www       471:       my $msgid=$ENV{'form.display'};
                    472:       &statuschange($msgid,'read');
1.8       albertel  473:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7       www       474:       my %content=&unpackagemsg($message{$msgid});
                    475:       $r->print('<b>Subject:</b> '.$content{'subject'}.
                    476:              '<br><b>From:</b> '.$content{'sendername'}.' at '.
                    477:                                  $content{'senderdomain'}.
1.14      www       478:              '<br><b>Time:</b> '.$content{'time'}.'<p>'.
                    479:              '<table border=2><tr bgcolor="#FFFFAA"><td>Functions:</td>'.
                    480:            '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).
                    481:              '"><b>Reply</b></a></td>'.
1.15      www       482:            '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).
1.14      www       483:              '"><b>Forward</b></a></td>'.
1.15      www       484:         '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).
                    485:              '"><b>Mark Unread</b></a></td>'.
                    486:         '<td><a href="/adm/email"><b>Display all Messages</b></a></td>'.
1.14      www       487:              '</tr></table><p><pre>'.
1.7       www       488:              $content{'message'}.'</pre><hr>'.$content{'citation'});
1.6       www       489:   } elsif ($ENV{'form.replyto'}) {
1.13      www       490:       &comprep($r,$ENV{'form.replyto'});
1.7       www       491:   } elsif ($ENV{'form.sendreply'}) {
                    492:       my $msgid=$ENV{'form.sendreply'};
1.8       albertel  493:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7       www       494:       my %content=&unpackagemsg($message{$msgid});
                    495:       &statuschange($msgid,'replied');
1.12      www       496:       if (($ENV{'form.critmsg'}) && 
                    497:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
                    498:          $r->print('Sending critical: '.
                    499:                 &user_crit_msg($content{'sendername'},
1.7       www       500:                                  $content{'senderdomain'},
                    501:                                  $ENV{'form.subject'},
                    502:                                  $ENV{'form.message'}));
1.12      www       503:       } else {
                    504:          $r->print('Sending: '.&user_normal_msg($content{'sendername'},
                    505:                                  $content{'senderdomain'},
                    506:                                  $ENV{'form.subject'},
                    507:                                  $ENV{'form.message'}));
                    508:       }
1.14      www       509:       if ($ENV{'form.displayedcrit'}) {
                    510:           &discrit($r);
                    511:       } else {
                    512: 	  &disall($r);
                    513:       }
1.12      www       514:   } elsif ($ENV{'form.confirm'}) {
                    515:       map {
                    516:           if ($_=~/^form\.rec\_(.*)$/) {
                    517: 	      $r->print('<b>Confirming Receipt:</b> '.
                    518:                         &user_crit_received($1).'<br>');
1.13      www       519:           }
                    520:           if ($_=~/^form\.reprec\_(.*)$/) {
                    521:               my $msgid=$1;
                    522: 	      $r->print('<b>Confirming Receipt:</b> '.
                    523:                         &user_crit_received($msgid).'<br>');
                    524:               &comprep($r,$msgid);
1.12      www       525:           }
                    526:       } keys %ENV;
                    527:       &discrit($r);
                    528:   } elsif ($ENV{'form.critical'}) {
                    529:       &discrit($r);
1.6       www       530:   } elsif ($ENV{'form.forward'}) {
1.15      www       531:       &compout($r,$ENV{'form.forward'});
1.14      www       532:   } elsif ($ENV{'form.markread'}) {
                    533:   } elsif ($ENV{'form.markdel'}) {
                    534:       &statuschange($ENV{'form.markdel'},'deleted');
                    535:       &disall($r);
                    536:   } elsif ($ENV{'form.markunread'}) {
1.15      www       537:       &statuschange($ENV{'form.markunread'},'new');
                    538:       &disall($r);
1.11      www       539:   } elsif ($ENV{'form.compose'}) {
1.17      www       540:       &compout($r,'',$ENV{'form.compose'});
1.11      www       541:   } elsif ($ENV{'form.sendmail'}) {
1.16      www       542:       my %content=();
                    543:       undef %content;
                    544:       if ($ENV{'form.forwid'}) {
                    545:         my $msgid=$ENV{'form.forwid'};
                    546:         my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
                    547:         %content=&unpackagemsg($message{$msgid});
                    548:         &statuschange($msgid,'forwarded');
                    549:         $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
                    550: 	                       $content{'message'};
                    551:       }
1.18      www       552:       my %toaddr=();
                    553:       undef %toaddr;
                    554:       if ($ENV{'form.sendmode'} eq 'group') {
                    555:           map {
1.19      www       556: 	      if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
1.22      www       557: 		  $toaddr{$1}='';
1.18      www       558:               }
                    559:           } keys %ENV;
1.22      www       560:       } elsif ($ENV{'form.sendmode'} eq 'upload') {
                    561:           map {
                    562:               my ($rec,$txt)=split(/\s*\:\s*/,$_);
                    563:               if ($txt) {
                    564: 		  $rec=~s/\@/\:/;
                    565:                   $toaddr{$rec}.=$txt."\n";
                    566:               }
                    567:           } split(/[\n\r\f]+/,$ENV{'form.upfile'});
1.18      www       568:       } else {
1.22      www       569: 	  $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
1.20      www       570:       }
                    571:       if ($ENV{'form.additionalrec'}) {
                    572: 	  map {
                    573:               my ($auname,$audom)=split(/\@/,$_);
1.22      www       574:               $toaddr{$auname.':'.$audom}='';
1.20      www       575:           } split(/\,/,$ENV{'form.additionalrec'});
1.18      www       576:       }
                    577:     map {
                    578:       my ($recuname,$recdomain)=split(/\:/,$_);
1.22      www       579:       my $msgtxt=$ENV{'form.message'};
                    580:       if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }    
1.16      www       581:       if (($ENV{'form.critmsg'}) && 
                    582:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
                    583:          $r->print('Sending critical: '.
1.18      www       584:                 &user_crit_msg($recuname,$recdomain,
1.16      www       585:                                  $ENV{'form.subject'},
1.22      www       586:                                  $msgtxt,
1.16      www       587:                                  $content{'citation'}));
                    588:       } else {
1.18      www       589:          $r->print('Sending: '.&user_normal_msg($recuname,$recdomain,
1.16      www       590:                                  $ENV{'form.subject'},
1.22      www       591:                                  $msgtxt,
1.16      www       592:                                  $content{'citation'}));
                    593:       }
1.18      www       594:       $r->print('<br>');
                    595:     } keys %toaddr;
1.16      www       596:       if ($ENV{'form.displayedcrit'}) {
                    597:           &discrit($r);
                    598:       } else {
                    599: 	  &disall($r);
                    600:       }
1.6       www       601:   } else {
1.14      www       602:       &disall($r);
1.6       www       603:   }
1.5       www       604:   $r->print('</body></html>');
                    605:   return OK;
                    606: 
                    607: }
1.2       www       608: # ================================================= Main program, reset counter
                    609: 
                    610: sub BEGIN {
                    611:     $msgcount=0;
1.1       www       612: }
                    613: 
                    614: 1;
                    615: __END__
                    616: 
                    617: 
                    618: 
                    619: 
                    620: 
                    621: 
                    622: 

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