Annotation of loncom/interface/lonmsg.pm, revision 1.37
1.1 www 1: # The LearningOnline Network with CAPA
1.26 albertel 2: # Routines for messaging
3: #
1.37 ! www 4: # $Id: lonmsg.pm,v 1.36 2002/07/29 22:17:05 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/\</\<\;/g;
60: $message=~s/\>/\>\;/g;
1.7 www 61: $citation=~s/\</\<\;/g;
62: $citation=~s/\>/\>\;/g;
1.1 www 63: $subject=~s/\</\<\;/g;
64: $subject=~s/\>/\>\;/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.1 www 122: # =============================== Automated message to the author of a resource
123:
124: sub author_res_msg {
125: my ($filename,$message)=@_;
1.2 www 126: unless ($message) { return 'empty'; }
1.1 www 127: $filename=&Apache::lonnet::declutter($filename);
128: my ($domain,$author,@dummy)=split(/\//,$filename);
129: my $homeserver=&Apache::lonnet::homeserver($author,$domain);
130: if ($homeserver ne 'no_host') {
131: my $id=unpack("%32C*",$message);
1.2 www 132: my $msgid;
1.3 www 133: ($msgid,$message)=&packagemsg($filename,$message);
134: return &Apache::lonnet::reply('put:'.$domain.':'.$author.
135: ':nohist_res_msgs:'.
136: &Apache::lonnet::escape($filename.'_'.$id).'='.
137: &Apache::lonnet::escape($message),$homeserver);
1.1 www 138: }
1.2 www 139: return 'no_host';
1.1 www 140: }
141:
142: # ================================================== Critical message to a user
143:
144: sub user_crit_msg {
1.24 www 145: my ($user,$domain,$subject,$message,$sendback)=@_;
1.2 www 146: # Check if allowed missing
147: my $status='';
148: my $msgid='undefined';
149: unless (($message)&&($user)&&($domain)) { $status='empty'; };
150: my $homeserver=&Apache::lonnet::homeserver($user,$domain);
151: if ($homeserver ne 'no_host') {
1.3 www 152: ($msgid,$message)=&packagemsg($subject,$message);
1.24 www 153: if ($sendback) { $message.='<sendback>true</sendback>'; }
1.4 www 154: $status=&Apache::lonnet::critical(
155: 'put:'.$domain.':'.$user.':critical:'.
156: &Apache::lonnet::escape($msgid).'='.
157: &Apache::lonnet::escape($message),$homeserver);
1.2 www 158: } else {
159: $status='no_host';
160: }
161: &Apache::lonnet::logthis(
1.4 www 162: 'Sending critical email '.$msgid.
1.2 www 163: ', log status: '.
164: &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
165: $ENV{'user.home'},
166: 'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
1.4 www 167: .$status));
1.2 www 168: return $status;
169: }
170:
171: # =================================================== Critical message received
172:
173: sub user_crit_received {
1.12 www 174: my $msgid=shift;
175: my %message=&Apache::lonnet::get('critical',[$msgid]);
176: my %contents=&unpackagemsg($message{$msgid});
1.24 www 177: my $status='rec: '.($contents{'sendback'}?
1.5 www 178: &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
1.4 www 179: 'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'},
180: 'User '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}.
181: ' acknowledged receipt of message "'.
182: $contents{'subject'}.'" dated '.$contents{'time'}.".\n\n"
1.24 www 183: .'Message ID: '.$contents{'msgid'}):'no msg req');
1.5 www 184: $status.=' trans: '.
1.12 www 185: &Apache::lonnet::put(
186: 'nohist_email',{$contents{'msgid'} => $message{$msgid}});
1.5 www 187: $status.=' del: '.
1.9 albertel 188: &Apache::lonnet::del('critical',[$contents{'msgid'}]);
1.5 www 189: &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
190: $ENV{'user.home'},'Received critical message '.
191: $contents{'msgid'}.
192: ', '.$status);
1.12 www 193: return $status;
1.2 www 194: }
195:
196: # ======================================================== Normal communication
197:
198: sub user_normal_msg {
1.7 www 199: my ($user,$domain,$subject,$message,$citation)=@_;
1.2 www 200: # Check if allowed missing
201: my $status='';
202: my $msgid='undefined';
203: unless (($message)&&($user)&&($domain)) { $status='empty'; };
204: my $homeserver=&Apache::lonnet::homeserver($user,$domain);
205: if ($homeserver ne 'no_host') {
1.7 www 206: ($msgid,$message)=&packagemsg($subject,$message,$citation);
1.4 www 207: $status=&Apache::lonnet::critical(
208: 'put:'.$domain.':'.$user.':nohist_email:'.
209: &Apache::lonnet::escape($msgid).'='.
210: &Apache::lonnet::escape($message),$homeserver);
1.2 www 211: } else {
212: $status='no_host';
213: }
214: &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
215: $ENV{'user.home'},
216: 'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
217: return $status;
218: }
219:
1.7 www 220: # =============================================================== Status Change
221:
222: sub statuschange {
223: my ($msgid,$newstatus)=@_;
1.8 albertel 224: my %status=&Apache::lonnet::get('email_status',[$msgid]);
1.7 www 225: if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
226: unless ($status{$msgid}) { $status{$msgid}='new'; }
227: unless (($status{$msgid} eq 'replied') ||
228: ($status{$msgid} eq 'forwarded')) {
1.10 albertel 229: &Apache::lonnet::put('email_status',{$msgid => $newstatus});
1.7 www 230: }
1.14 www 231: if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
232: &Apache::lonnet::put('email_status',{$msgid => $newstatus});
233: }
1.7 www 234: }
1.14 www 235:
1.17 www 236: # ======================================================= Display a course list
237:
238: sub discourse {
239: my $r=shift;
240: my %courselist=&Apache::lonnet::dump(
241: 'classlist',
242: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
243: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
244: my $now=time;
245: $r->print(<<ENDDISHEADER);
246: <input type=hidden name=sendmode value=group>
247: <script>
248: function checkall() {
249: for (i=0; i<document.forms.compemail.elements.length; i++) {
250: if
251: (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
252: document.forms.compemail.elements[i].checked=true;
253: }
254: }
255: }
256:
1.19 www 257: function checksec() {
258: for (i=0; i<document.forms.compemail.elements.length; i++) {
259: if
260: (document.forms.compemail.elements[i].name.indexOf
261: ('send_to_&&&'+document.forms.compemail.chksec.value)==0) {
262: document.forms.compemail.elements[i].checked=true;
263: }
264: }
265: }
266:
1.17 www 267: function uncheckall() {
268: for (i=0; i<document.forms.compemail.elements.length; i++) {
269: if
270: (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
271: document.forms.compemail.elements[i].checked=false;
272: }
273: }
274: }
275: </script>
1.19 www 276: <input type=button onClick="checkall()" value="Check for All">
277: <input type=button onClick="checksec()" value="Check for Section/Group">
278: <input type=text size=5 name=chksec>
1.17 www 279: <input type=button onClick="uncheckall()" value="Check for None">
280: <p>
281: ENDDISHEADER
1.28 harris41 282: foreach (sort keys %courselist) {
1.17 www 283: my ($end,$start)=split(/\:/,$courselist{$_});
284: my $active=1;
285: if (($end) && ($now>$end)) { $active=0; }
286: if ($active) {
287: my ($sname,$sdom)=split(/\:/,$_);
288: my %reply=&Apache::lonnet::get('environment',
289: ['firstname','middlename','lastname','generation'],
290: $sdom,$sname);
1.19 www 291: my $section=&Apache::lonnet::usection
292: ($sdom,$sname,$ENV{'request.course.id'});
293: $r->print(
294: '<br><input type=checkbox name="send_to_&&&'.$section.'&&&_'.$_.'"> '.
1.17 www 295: $reply{'firstname'}.' '.
296: $reply{'middlename'}.' '.
297: $reply{'lastname'}.' '.
298: $reply{'generation'}.
1.19 www 299: ' ('.$_.') '.$section);
1.17 www 300: }
1.28 harris41 301: }
1.17 www 302: }
303:
1.13 www 304: # ==================================================== Display Critical Message
1.5 www 305:
1.12 www 306: sub discrit {
307: my $r=shift;
1.30 matthew 308: my $header = '<h1><font color=red>Critical Messages</font></h1>'.
309: '<form action=/adm/email method=post>'.
310: '<input type=hidden name=confirm value=true>';
311: my %what=&Apache::lonnet::dump('critical');
312: my $result = '';
313: foreach (sort keys %what) {
314: my %content=&unpackagemsg($what{$_});
315: next if ($content{'senderdomain'} eq '');
316: $content{'message'}=~s/\n/\<br\>/g;
1.37 ! www 317: $result.='<hr>From: <b>'.
! 318: &Apache::loncommon::aboutmewrapper(
! 319: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
! 320: $content{'sendername'}.'@'.
! 321: $content{'senderdomain'}.') '.$content{'time'}.
! 322: '<br>Subject: '.$content{'subject'}.
1.36 www 323: '<br><blockquote>'.
324: &Apache::lontexconvert::msgtexconverted($content{'message'}).
325: '</blockquote>'.
1.30 matthew 326: '<input type=submit name="rec_'.$_.'" value="Confirm Receipt">'.
327: '<input type=submit name="reprec_'.$_.'" '.
328: 'value="Confirm Receipt and Reply">';
329: }
330: # Check to see if there were any messages.
331: if ($result eq '') {
332: $result = "<h2>You have no critical messages.</h2>";
333: } else {
334: $r->print($header);
335: }
336: $r->print($result);
337: $r->print('<input type=hidden name="displayedcrit" value="true"></form>');
1.12 www 338: }
339:
1.13 www 340: # =============================================================== Compose reply
341:
342: sub comprep {
343: my ($r,$msgid)=@_;
344: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
345: my %content=&unpackagemsg($message{$msgid});
346: my $quotemsg='> '.$content{'message'};
347: $quotemsg=~s/\r/\n/g;
348: $quotemsg=~s/\f/\n/g;
349: $quotemsg=~s/\n+/\n\> /g;
350: my $subject='Re: '.$content{'subject'};
351: my $dispcrit='';
352: if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
1.35 bowersj2 353: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1.13 www 354: $dispcrit=
1.35 bowersj2 355: '<input type=checkbox name=critmsg> Send as critical message ' . $crithelp .
356: '<br>'.
357: '<input type=checkbox name=sendbck> Send as critical message ' .
358: ' and return receipt' . $crithelp . '<p>';
1.13 www 359: }
360: $r->print(<<"ENDREPLY");
361: <form action="/adm/email" method=post>
362: <input type=hidden name=sendreply value="$msgid">
363: Subject: <input type=text size=50 name=subject value="$subject"><p>
1.37 ! www 364: <textarea name=message cols=84 rows=10 wrap=hard>
1.13 www 365: $quotemsg
366: </textarea><p>
367: $dispcrit
368: <input type=submit value="Send Reply">
369: </form>
370: ENDREPLY
371: }
372:
1.15 www 373: # ======================================================== Display all messages
374:
1.14 www 375: sub disall {
376: my $r=shift;
1.29 www 377: $r->print(<<ENDDISHEADER);
378: <script>
379: function checkall() {
380: for (i=0; i<document.forms.disall.elements.length; i++) {
381: if
382: (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
383: document.forms.disall.elements[i].checked=true;
384: }
385: }
386: }
387:
388: function uncheckall() {
389: for (i=0; i<document.forms.disall.elements.length; i++) {
390: if
391: (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
392: document.forms.disall.elements[i].checked=false;
393: }
394: }
395: }
396: </script>
397: ENDDISHEADER
398: $r->print(
399: '<h1>Display All Messages</h1><form method=post name=disall '.
400: 'action="/adm/email">'.
1.14 www 401: '<table border=2><tr><th colspan=2> </th><th>Date</th>'.
402: '<th>Username</th><th>Domain</th><th>Subject</th><th>Status</th></tr>');
1.27 www 403: foreach (sort split(/\&/,&Apache::lonnet::reply('keys:'.
404: $ENV{'user.domain'}.':'.
405: $ENV{'user.name'}.':nohist_email',
406: $ENV{'user.home'}))) {
1.14 www 407: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
408: &Apache::lonmsg::unpackmsgid($_);
1.33 www 409: unless (($status eq 'deleted') || ($sendtime=~/error/)) {
1.14 www 410: if ($status eq 'new') {
411: $r->print('<tr bgcolor="#FFBB77">');
412: } elsif ($status eq 'read') {
413: $r->print('<tr bgcolor="#BBBB77">');
414: } elsif ($status eq 'replied') {
415: $r->print('<tr bgcolor="#AAAA88">');
416: } else {
417: $r->print('<tr bgcolor="#99BBBB">');
418: }
419: $r->print('<td><a href="/adm/email?display='.$_.
420: '">Open</a></td><td><a href="/adm/email?markdel='.$_.
1.25 www 421: '">Delete</a><input type=checkbox name="delmark_'.$_.'"></td>'.
422: '<td>'.localtime($sendtime).'</td><td>'.
1.14 www 423: $fromname.'</td><td>'.$fromdomain.'</td><td>'.
424: &Apache::lonnet::unescape($shortsubj).'</td><td>'.
425: $status.'</td></tr>');
426: }
1.27 www 427: }
1.25 www 428: $r->print('</table><p>'.
1.29 www 429: '<a href="javascript:checkall()">Check All</a> '.
430: '<a href="javascript:uncheckall()">Uncheck All</a><p>'.
1.25 www 431: '<input type=submit name="markeddel" value="Delete Checked">'.
432: '</form></body></html>');
1.14 www 433: }
434:
1.15 www 435: # ============================================================== Compose output
436:
437: sub compout {
1.17 www 438: my ($r,$forwarding,$broadcast)=@_;
1.15 www 439: my $dispcrit='';
440: my $dissub='';
441: my $dismsg='';
442: my $func='Send New';
443: if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
1.35 bowersj2 444: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1.15 www 445: $dispcrit=
1.35 bowersj2 446: '<input type=checkbox name=critmsg> Send as critical message ' . $crithelp .
447: '<br>'.
448: '<input type=checkbox name=sendbck> Send as critical message ' .
449: ' and return receipt' . $crithelp . '<p>';
1.15 www 450: }
451: if ($forwarding) {
452: $dispcrit.='<input type=hidden name=forwid value="'.
453: $forwarding.'">';
454: $func='Forward';
455: my %message=&Apache::lonnet::get('nohist_email',[$forwarding]);
456: my %content=&unpackagemsg($message{$forwarding});
457:
458: $dissub='Forwarding: '.$content{'subject'};
459: $dismsg='Forwarded message from '.
460: $content{'sendername'}.' at '.$content{'senderdomain'};
461: }
462: my $defdom=$ENV{'user.domain'};
1.37 ! www 463: if ($ENV{'form.recdom'}) { $defdom=$ENV{'form.recdom'}; }
1.22 www 464: $r->print(
1.31 matthew 465: '<form action="/adm/email" name="compemail" method="post"'.
466: ' enctype="multipart/form-data">'."\n".
467: '<input type="hidden" name="sendmail" value="on">'."\n".
468: '<table>');
1.22 www 469: unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
1.31 matthew 470: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
471:
1.17 www 472: $r->print(<<"ENDREC");
1.15 www 473: <table>
1.37 ! www 474: <tr><td>Username:</td><td><input type=text size=12 name=recuname value="$ENV{'form.recname'}"></td></tr>
1.15 www 475: <tr><td>Domain:</td>
1.31 matthew 476: <td>$domform</td></tr>
1.17 www 477: ENDREC
478: }
1.31 matthew 479: if ($broadcast ne 'upload') {
1.22 www 480: $r->print(<<"ENDCOMP");
1.20 www 481: <tr><td>Additional Recipients<br><tt>username\@domain,username\@domain, ...
482: </tt></td><td>
483: <input type=text size=50 name=additionalrec></td></tr>
1.15 www 484: <tr><td>Subject:</td><td><input type=text size=50 name=subject value="$dissub">
485: </td></tr></table>
1.37 ! www 486: <textarea name=message cols=80 rows=10 wrap=hard>$dismsg
1.15 www 487: </textarea><p>
488: $dispcrit
489: <input type=submit value="$func Mail">
490: ENDCOMP
1.31 matthew 491: } else { # $broadcast is 'upload'
1.22 www 492: $r->print(<<ENDUPLOAD);
493: <input type=hidden name=sendmode value=upload>
494: <h3>Generate messages from a file</h3>
1.31 matthew 495: <p>
1.22 www 496: Subject: <input type=text size=50 name=subject>
1.31 matthew 497: </p>
498: <p>General message text<br />
499: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
500: </textarea></p>
501: <p>
502: The file format for the uploaded portion of the message is:
1.22 www 503: <pre>
504: username1\@domain1: text
505: username2\@domain2: text
1.31 matthew 506: username3\@domain1: text
1.22 www 507: </pre>
1.31 matthew 508: </p>
509: <p>
1.22 www 510: The messages will be assembled from all lines with the respective
1.31 matthew 511: <tt>username\@domain</tt>, and appended to the general message text.</p>
512: <p>
1.22 www 513: <input type=file name=upfile size=20><p>
514: $dispcrit
515: <input type=submit value="Upload and send">
516: ENDUPLOAD
517: }
1.17 www 518: if ($broadcast eq 'group') {
519: &discourse;
520: }
521: $r->print('</form>');
1.15 www 522: }
523:
1.13 www 524: # ===================================================================== Handler
525:
1.5 www 526: sub handler {
527: my $r=shift;
528:
529: # ----------------------------------------------------------- Set document type
530:
531: $r->content_type('text/html');
532: $r->send_http_header;
533:
534: return OK if $r->header_only;
535:
1.6 www 536: # --------------------------- Get query string for limited number of parameters
1.32 matthew 537: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
538: ['display','replyto','forward','markread','markdel','markunread',
1.37 ! www 539: 'sendreply','compose','sendmail','critical','recname','recdom']);
1.6 www 540:
1.5 www 541: # --------------------------------------------------------------- Render Output
542:
1.37 ! www 543: $r->print('<html><head><title>EMail and Messaging</title></head>'.
! 544: &Apache::loncommon::bodytag('EMail and Messages'));
1.6 www 545: if ($ENV{'form.display'}) {
1.7 www 546: my $msgid=$ENV{'form.display'};
547: &statuschange($msgid,'read');
1.8 albertel 548: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7 www 549: my %content=&unpackagemsg($message{$msgid});
550: $r->print('<b>Subject:</b> '.$content{'subject'}.
1.37 ! www 551: '<br><b>From:</b> '.
! 552: &Apache::loncommon::aboutmewrapper(
! 553: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
! 554: $content{'sendername'},$content{'senderdomain'}).' ('.
! 555: $content{'sendername'}.' at '.
! 556: $content{'senderdomain'}.') '.
1.14 www 557: '<br><b>Time:</b> '.$content{'time'}.'<p>'.
558: '<table border=2><tr bgcolor="#FFFFAA"><td>Functions:</td>'.
559: '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).
560: '"><b>Reply</b></a></td>'.
1.15 www 561: '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).
1.14 www 562: '"><b>Forward</b></a></td>'.
1.15 www 563: '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).
564: '"><b>Mark Unread</b></a></td>'.
565: '<td><a href="/adm/email"><b>Display all Messages</b></a></td>'.
1.14 www 566: '</tr></table><p><pre>'.
1.36 www 567: &Apache::lontexconvert::msgtexconverted($content{'message'}).
568: '</pre><hr>'.$content{'citation'});
1.6 www 569: } elsif ($ENV{'form.replyto'}) {
1.13 www 570: &comprep($r,$ENV{'form.replyto'});
1.7 www 571: } elsif ($ENV{'form.sendreply'}) {
572: my $msgid=$ENV{'form.sendreply'};
1.8 albertel 573: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7 www 574: my %content=&unpackagemsg($message{$msgid});
575: &statuschange($msgid,'replied');
1.24 www 576: if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) &&
1.12 www 577: (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
578: $r->print('Sending critical: '.
579: &user_crit_msg($content{'sendername'},
1.7 www 580: $content{'senderdomain'},
581: $ENV{'form.subject'},
1.24 www 582: $ENV{'form.message'},
583: $ENV{'form.sendbck'}));
1.12 www 584: } else {
585: $r->print('Sending: '.&user_normal_msg($content{'sendername'},
586: $content{'senderdomain'},
587: $ENV{'form.subject'},
588: $ENV{'form.message'}));
589: }
1.14 www 590: if ($ENV{'form.displayedcrit'}) {
591: &discrit($r);
592: } else {
593: &disall($r);
594: }
1.12 www 595: } elsif ($ENV{'form.confirm'}) {
1.28 harris41 596: foreach (keys %ENV) {
1.12 www 597: if ($_=~/^form\.rec\_(.*)$/) {
598: $r->print('<b>Confirming Receipt:</b> '.
599: &user_crit_received($1).'<br>');
1.13 www 600: }
601: if ($_=~/^form\.reprec\_(.*)$/) {
602: my $msgid=$1;
603: $r->print('<b>Confirming Receipt:</b> '.
604: &user_crit_received($msgid).'<br>');
605: &comprep($r,$msgid);
1.12 www 606: }
1.28 harris41 607: }
1.12 www 608: &discrit($r);
609: } elsif ($ENV{'form.critical'}) {
610: &discrit($r);
1.6 www 611: } elsif ($ENV{'form.forward'}) {
1.15 www 612: &compout($r,$ENV{'form.forward'});
1.14 www 613: } elsif ($ENV{'form.markread'}) {
614: } elsif ($ENV{'form.markdel'}) {
615: &statuschange($ENV{'form.markdel'},'deleted');
1.25 www 616: &disall($r);
617: } elsif ($ENV{'form.markeddel'}) {
618: my $total=0;
1.28 harris41 619: foreach (keys %ENV) {
1.25 www 620: if ($_=~/^form\.delmark_(.*)$/) {
621: &statuschange(&Apache::lonnet::unescape($1),'deleted');
622: $total++;
623: }
1.28 harris41 624: }
1.25 www 625: $r->print('Deleted '.$total.' message(s)<p>');
1.14 www 626: &disall($r);
627: } elsif ($ENV{'form.markunread'}) {
1.15 www 628: &statuschange($ENV{'form.markunread'},'new');
629: &disall($r);
1.11 www 630: } elsif ($ENV{'form.compose'}) {
1.17 www 631: &compout($r,'',$ENV{'form.compose'});
1.11 www 632: } elsif ($ENV{'form.sendmail'}) {
1.16 www 633: my %content=();
634: undef %content;
635: if ($ENV{'form.forwid'}) {
636: my $msgid=$ENV{'form.forwid'};
637: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
638: %content=&unpackagemsg($message{$msgid});
639: &statuschange($msgid,'forwarded');
640: $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
641: $content{'message'};
642: }
1.18 www 643: my %toaddr=();
644: undef %toaddr;
645: if ($ENV{'form.sendmode'} eq 'group') {
1.28 harris41 646: foreach (keys %ENV) {
1.19 www 647: if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
1.22 www 648: $toaddr{$1}='';
1.18 www 649: }
1.28 harris41 650: }
1.22 www 651: } elsif ($ENV{'form.sendmode'} eq 'upload') {
1.28 harris41 652: foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) {
1.22 www 653: my ($rec,$txt)=split(/\s*\:\s*/,$_);
654: if ($txt) {
655: $rec=~s/\@/\:/;
656: $toaddr{$rec}.=$txt."\n";
657: }
1.28 harris41 658: }
1.18 www 659: } else {
1.22 www 660: $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
1.20 www 661: }
662: if ($ENV{'form.additionalrec'}) {
1.28 harris41 663: foreach (split(/\,/,$ENV{'form.additionalrec'})) {
1.20 www 664: my ($auname,$audom)=split(/\@/,$_);
1.22 www 665: $toaddr{$auname.':'.$audom}='';
1.28 harris41 666: }
1.18 www 667: }
1.28 harris41 668: foreach (keys %toaddr) {
1.18 www 669: my ($recuname,$recdomain)=split(/\:/,$_);
1.22 www 670: my $msgtxt=$ENV{'form.message'};
671: if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }
1.24 www 672: if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) &&
1.16 www 673: (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
674: $r->print('Sending critical: '.
1.18 www 675: &user_crit_msg($recuname,$recdomain,
1.16 www 676: $ENV{'form.subject'},
1.22 www 677: $msgtxt,
1.24 www 678: $ENV{'form.sendbck'}));
1.16 www 679: } else {
1.18 www 680: $r->print('Sending: '.&user_normal_msg($recuname,$recdomain,
1.16 www 681: $ENV{'form.subject'},
1.22 www 682: $msgtxt,
1.16 www 683: $content{'citation'}));
684: }
1.18 www 685: $r->print('<br>');
1.28 harris41 686: }
1.16 www 687: if ($ENV{'form.displayedcrit'}) {
688: &discrit($r);
689: } else {
690: &disall($r);
691: }
1.6 www 692: } else {
1.14 www 693: &disall($r);
1.6 www 694: }
1.5 www 695: $r->print('</body></html>');
696: return OK;
697:
698: }
1.2 www 699: # ================================================= Main program, reset counter
700:
1.27 www 701: BEGIN {
1.2 www 702: $msgcount=0;
1.1 www 703: }
704:
705: 1;
706: __END__
707:
708:
709:
710:
711:
712:
713:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>