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