Annotation of loncom/interface/lonmsg.pm, revision 1.36
1.1 www 1: # The LearningOnline Network with CAPA
1.26 albertel 2: # Routines for messaging
3: #
1.36 ! www 4: # $Id: lonmsg.pm,v 1.35 2002/07/22 14:23:29 bowersj2 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;
317: $result.='<hr>From: <b>'.$content{'sendername'}.'@'.
318: $content{'senderdomain'}.'</b> ('.$content{'time'}.
1.34 www 319: ')<br>Subject: '.$content{'subject'}.
1.36 ! www 320: '<br><blockquote>'.
! 321: &Apache::lontexconvert::msgtexconverted($content{'message'}).
! 322: '</blockquote>'.
1.30 matthew 323: '<input type=submit name="rec_'.$_.'" value="Confirm Receipt">'.
324: '<input type=submit name="reprec_'.$_.'" '.
325: 'value="Confirm Receipt and Reply">';
326: }
327: # Check to see if there were any messages.
328: if ($result eq '') {
329: $result = "<h2>You have no critical messages.</h2>";
330: } else {
331: $r->print($header);
332: }
333: $r->print($result);
334: $r->print('<input type=hidden name="displayedcrit" value="true"></form>');
1.12 www 335: }
336:
1.13 www 337: # =============================================================== Compose reply
338:
339: sub comprep {
340: my ($r,$msgid)=@_;
341: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
342: my %content=&unpackagemsg($message{$msgid});
343: my $quotemsg='> '.$content{'message'};
344: $quotemsg=~s/\r/\n/g;
345: $quotemsg=~s/\f/\n/g;
346: $quotemsg=~s/\n+/\n\> /g;
347: my $subject='Re: '.$content{'subject'};
348: my $dispcrit='';
349: if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
1.35 bowersj2 350: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1.13 www 351: $dispcrit=
1.35 bowersj2 352: '<input type=checkbox name=critmsg> Send as critical message ' . $crithelp .
353: '<br>'.
354: '<input type=checkbox name=sendbck> Send as critical message ' .
355: ' and return receipt' . $crithelp . '<p>';
1.13 www 356: }
357: $r->print(<<"ENDREPLY");
358: <form action="/adm/email" method=post>
359: <input type=hidden name=sendreply value="$msgid">
360: Subject: <input type=text size=50 name=subject value="$subject"><p>
1.23 www 361: <textarea name=message cols=64 rows=10 wrap=hard>
1.13 www 362: $quotemsg
363: </textarea><p>
364: $dispcrit
365: <input type=submit value="Send Reply">
366: </form>
367: ENDREPLY
368: }
369:
1.15 www 370: # ======================================================== Display all messages
371:
1.14 www 372: sub disall {
373: my $r=shift;
1.29 www 374: $r->print(<<ENDDISHEADER);
375: <script>
376: function checkall() {
377: for (i=0; i<document.forms.disall.elements.length; i++) {
378: if
379: (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
380: document.forms.disall.elements[i].checked=true;
381: }
382: }
383: }
384:
385: function uncheckall() {
386: for (i=0; i<document.forms.disall.elements.length; i++) {
387: if
388: (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
389: document.forms.disall.elements[i].checked=false;
390: }
391: }
392: }
393: </script>
394: ENDDISHEADER
395: $r->print(
396: '<h1>Display All Messages</h1><form method=post name=disall '.
397: 'action="/adm/email">'.
1.14 www 398: '<table border=2><tr><th colspan=2> </th><th>Date</th>'.
399: '<th>Username</th><th>Domain</th><th>Subject</th><th>Status</th></tr>');
1.27 www 400: foreach (sort split(/\&/,&Apache::lonnet::reply('keys:'.
401: $ENV{'user.domain'}.':'.
402: $ENV{'user.name'}.':nohist_email',
403: $ENV{'user.home'}))) {
1.14 www 404: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
405: &Apache::lonmsg::unpackmsgid($_);
1.33 www 406: unless (($status eq 'deleted') || ($sendtime=~/error/)) {
1.14 www 407: if ($status eq 'new') {
408: $r->print('<tr bgcolor="#FFBB77">');
409: } elsif ($status eq 'read') {
410: $r->print('<tr bgcolor="#BBBB77">');
411: } elsif ($status eq 'replied') {
412: $r->print('<tr bgcolor="#AAAA88">');
413: } else {
414: $r->print('<tr bgcolor="#99BBBB">');
415: }
416: $r->print('<td><a href="/adm/email?display='.$_.
417: '">Open</a></td><td><a href="/adm/email?markdel='.$_.
1.25 www 418: '">Delete</a><input type=checkbox name="delmark_'.$_.'"></td>'.
419: '<td>'.localtime($sendtime).'</td><td>'.
1.14 www 420: $fromname.'</td><td>'.$fromdomain.'</td><td>'.
421: &Apache::lonnet::unescape($shortsubj).'</td><td>'.
422: $status.'</td></tr>');
423: }
1.27 www 424: }
1.25 www 425: $r->print('</table><p>'.
1.29 www 426: '<a href="javascript:checkall()">Check All</a> '.
427: '<a href="javascript:uncheckall()">Uncheck All</a><p>'.
1.25 www 428: '<input type=submit name="markeddel" value="Delete Checked">'.
429: '</form></body></html>');
1.14 www 430: }
431:
1.15 www 432: # ============================================================== Compose output
433:
434: sub compout {
1.17 www 435: my ($r,$forwarding,$broadcast)=@_;
1.15 www 436: my $dispcrit='';
437: my $dissub='';
438: my $dismsg='';
439: my $func='Send New';
440: if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
1.35 bowersj2 441: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1.15 www 442: $dispcrit=
1.35 bowersj2 443: '<input type=checkbox name=critmsg> Send as critical message ' . $crithelp .
444: '<br>'.
445: '<input type=checkbox name=sendbck> Send as critical message ' .
446: ' and return receipt' . $crithelp . '<p>';
1.15 www 447: }
448: if ($forwarding) {
449: $dispcrit.='<input type=hidden name=forwid value="'.
450: $forwarding.'">';
451: $func='Forward';
452: my %message=&Apache::lonnet::get('nohist_email',[$forwarding]);
453: my %content=&unpackagemsg($message{$forwarding});
454:
455: $dissub='Forwarding: '.$content{'subject'};
456: $dismsg='Forwarded message from '.
457: $content{'sendername'}.' at '.$content{'senderdomain'};
458: }
459: my $defdom=$ENV{'user.domain'};
1.22 www 460: $r->print(
1.31 matthew 461: '<form action="/adm/email" name="compemail" method="post"'.
462: ' enctype="multipart/form-data">'."\n".
463: '<input type="hidden" name="sendmail" value="on">'."\n".
464: '<table>');
1.22 www 465: unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
1.31 matthew 466: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
467:
1.17 www 468: $r->print(<<"ENDREC");
1.15 www 469: <table>
470: <tr><td>Username:</td><td><input type=text size=12 name=recuname></td></tr>
471: <tr><td>Domain:</td>
1.31 matthew 472: <td>$domform</td></tr>
1.17 www 473: ENDREC
474: }
1.31 matthew 475: if ($broadcast ne 'upload') {
1.22 www 476: $r->print(<<"ENDCOMP");
1.20 www 477: <tr><td>Additional Recipients<br><tt>username\@domain,username\@domain, ...
478: </tt></td><td>
479: <input type=text size=50 name=additionalrec></td></tr>
1.15 www 480: <tr><td>Subject:</td><td><input type=text size=50 name=subject value="$dissub">
481: </td></tr></table>
1.23 www 482: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
1.15 www 483: </textarea><p>
484: $dispcrit
485: <input type=submit value="$func Mail">
486: ENDCOMP
1.31 matthew 487: } else { # $broadcast is 'upload'
1.22 www 488: $r->print(<<ENDUPLOAD);
489: <input type=hidden name=sendmode value=upload>
490: <h3>Generate messages from a file</h3>
1.31 matthew 491: <p>
1.22 www 492: Subject: <input type=text size=50 name=subject>
1.31 matthew 493: </p>
494: <p>General message text<br />
495: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
496: </textarea></p>
497: <p>
498: The file format for the uploaded portion of the message is:
1.22 www 499: <pre>
500: username1\@domain1: text
501: username2\@domain2: text
1.31 matthew 502: username3\@domain1: text
1.22 www 503: </pre>
1.31 matthew 504: </p>
505: <p>
1.22 www 506: The messages will be assembled from all lines with the respective
1.31 matthew 507: <tt>username\@domain</tt>, and appended to the general message text.</p>
508: <p>
1.22 www 509: <input type=file name=upfile size=20><p>
510: $dispcrit
511: <input type=submit value="Upload and send">
512: ENDUPLOAD
513: }
1.17 www 514: if ($broadcast eq 'group') {
515: &discourse;
516: }
517: $r->print('</form>');
1.15 www 518: }
519:
1.13 www 520: # ===================================================================== Handler
521:
1.5 www 522: sub handler {
523: my $r=shift;
524:
525: # ----------------------------------------------------------- Set document type
526:
527: $r->content_type('text/html');
528: $r->send_http_header;
529:
530: return OK if $r->header_only;
531:
1.6 www 532: # --------------------------- Get query string for limited number of parameters
1.32 matthew 533: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
534: ['display','replyto','forward','markread','markdel','markunread',
535: 'sendreply','compose','sendmail','critical']);
1.6 www 536:
1.5 www 537: # --------------------------------------------------------------- Render Output
538:
539: $r->print('<html><head><title>EMail and Messaging</title></head>');
1.7 www 540: $r->print(
541: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
1.5 www 542: $r->print('<h1>EMail</h1>');
1.6 www 543: if ($ENV{'form.display'}) {
1.7 www 544: my $msgid=$ENV{'form.display'};
545: &statuschange($msgid,'read');
1.8 albertel 546: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7 www 547: my %content=&unpackagemsg($message{$msgid});
548: $r->print('<b>Subject:</b> '.$content{'subject'}.
549: '<br><b>From:</b> '.$content{'sendername'}.' at '.
550: $content{'senderdomain'}.
1.14 www 551: '<br><b>Time:</b> '.$content{'time'}.'<p>'.
552: '<table border=2><tr bgcolor="#FFFFAA"><td>Functions:</td>'.
553: '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).
554: '"><b>Reply</b></a></td>'.
1.15 www 555: '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).
1.14 www 556: '"><b>Forward</b></a></td>'.
1.15 www 557: '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).
558: '"><b>Mark Unread</b></a></td>'.
559: '<td><a href="/adm/email"><b>Display all Messages</b></a></td>'.
1.14 www 560: '</tr></table><p><pre>'.
1.36 ! www 561: &Apache::lontexconvert::msgtexconverted($content{'message'}).
! 562: '</pre><hr>'.$content{'citation'});
1.6 www 563: } elsif ($ENV{'form.replyto'}) {
1.13 www 564: &comprep($r,$ENV{'form.replyto'});
1.7 www 565: } elsif ($ENV{'form.sendreply'}) {
566: my $msgid=$ENV{'form.sendreply'};
1.8 albertel 567: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7 www 568: my %content=&unpackagemsg($message{$msgid});
569: &statuschange($msgid,'replied');
1.24 www 570: if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) &&
1.12 www 571: (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
572: $r->print('Sending critical: '.
573: &user_crit_msg($content{'sendername'},
1.7 www 574: $content{'senderdomain'},
575: $ENV{'form.subject'},
1.24 www 576: $ENV{'form.message'},
577: $ENV{'form.sendbck'}));
1.12 www 578: } else {
579: $r->print('Sending: '.&user_normal_msg($content{'sendername'},
580: $content{'senderdomain'},
581: $ENV{'form.subject'},
582: $ENV{'form.message'}));
583: }
1.14 www 584: if ($ENV{'form.displayedcrit'}) {
585: &discrit($r);
586: } else {
587: &disall($r);
588: }
1.12 www 589: } elsif ($ENV{'form.confirm'}) {
1.28 harris41 590: foreach (keys %ENV) {
1.12 www 591: if ($_=~/^form\.rec\_(.*)$/) {
592: $r->print('<b>Confirming Receipt:</b> '.
593: &user_crit_received($1).'<br>');
1.13 www 594: }
595: if ($_=~/^form\.reprec\_(.*)$/) {
596: my $msgid=$1;
597: $r->print('<b>Confirming Receipt:</b> '.
598: &user_crit_received($msgid).'<br>');
599: &comprep($r,$msgid);
1.12 www 600: }
1.28 harris41 601: }
1.12 www 602: &discrit($r);
603: } elsif ($ENV{'form.critical'}) {
604: &discrit($r);
1.6 www 605: } elsif ($ENV{'form.forward'}) {
1.15 www 606: &compout($r,$ENV{'form.forward'});
1.14 www 607: } elsif ($ENV{'form.markread'}) {
608: } elsif ($ENV{'form.markdel'}) {
609: &statuschange($ENV{'form.markdel'},'deleted');
1.25 www 610: &disall($r);
611: } elsif ($ENV{'form.markeddel'}) {
612: my $total=0;
1.28 harris41 613: foreach (keys %ENV) {
1.25 www 614: if ($_=~/^form\.delmark_(.*)$/) {
615: &statuschange(&Apache::lonnet::unescape($1),'deleted');
616: $total++;
617: }
1.28 harris41 618: }
1.25 www 619: $r->print('Deleted '.$total.' message(s)<p>');
1.14 www 620: &disall($r);
621: } elsif ($ENV{'form.markunread'}) {
1.15 www 622: &statuschange($ENV{'form.markunread'},'new');
623: &disall($r);
1.11 www 624: } elsif ($ENV{'form.compose'}) {
1.17 www 625: &compout($r,'',$ENV{'form.compose'});
1.11 www 626: } elsif ($ENV{'form.sendmail'}) {
1.16 www 627: my %content=();
628: undef %content;
629: if ($ENV{'form.forwid'}) {
630: my $msgid=$ENV{'form.forwid'};
631: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
632: %content=&unpackagemsg($message{$msgid});
633: &statuschange($msgid,'forwarded');
634: $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
635: $content{'message'};
636: }
1.18 www 637: my %toaddr=();
638: undef %toaddr;
639: if ($ENV{'form.sendmode'} eq 'group') {
1.28 harris41 640: foreach (keys %ENV) {
1.19 www 641: if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
1.22 www 642: $toaddr{$1}='';
1.18 www 643: }
1.28 harris41 644: }
1.22 www 645: } elsif ($ENV{'form.sendmode'} eq 'upload') {
1.28 harris41 646: foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) {
1.22 www 647: my ($rec,$txt)=split(/\s*\:\s*/,$_);
648: if ($txt) {
649: $rec=~s/\@/\:/;
650: $toaddr{$rec}.=$txt."\n";
651: }
1.28 harris41 652: }
1.18 www 653: } else {
1.22 www 654: $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
1.20 www 655: }
656: if ($ENV{'form.additionalrec'}) {
1.28 harris41 657: foreach (split(/\,/,$ENV{'form.additionalrec'})) {
1.20 www 658: my ($auname,$audom)=split(/\@/,$_);
1.22 www 659: $toaddr{$auname.':'.$audom}='';
1.28 harris41 660: }
1.18 www 661: }
1.28 harris41 662: foreach (keys %toaddr) {
1.18 www 663: my ($recuname,$recdomain)=split(/\:/,$_);
1.22 www 664: my $msgtxt=$ENV{'form.message'};
665: if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }
1.24 www 666: if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) &&
1.16 www 667: (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
668: $r->print('Sending critical: '.
1.18 www 669: &user_crit_msg($recuname,$recdomain,
1.16 www 670: $ENV{'form.subject'},
1.22 www 671: $msgtxt,
1.24 www 672: $ENV{'form.sendbck'}));
1.16 www 673: } else {
1.18 www 674: $r->print('Sending: '.&user_normal_msg($recuname,$recdomain,
1.16 www 675: $ENV{'form.subject'},
1.22 www 676: $msgtxt,
1.16 www 677: $content{'citation'}));
678: }
1.18 www 679: $r->print('<br>');
1.28 harris41 680: }
1.16 www 681: if ($ENV{'form.displayedcrit'}) {
682: &discrit($r);
683: } else {
684: &disall($r);
685: }
1.6 www 686: } else {
1.14 www 687: &disall($r);
1.6 www 688: }
1.5 www 689: $r->print('</body></html>');
690: return OK;
691:
692: }
1.2 www 693: # ================================================= Main program, reset counter
694:
1.27 www 695: BEGIN {
1.2 www 696: $msgcount=0;
1.1 www 697: }
698:
699: 1;
700: __END__
701:
702:
703:
704:
705:
706:
707:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>