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