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