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