1: # The LearningOnline Network with CAPA
2: # Routines for messaging
3: #
4: # $Id: lonmsg.pm,v 1.70 2003/10/18 16:33:44 www Exp $
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/
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: #
37: # 10/19,10/20,10/30,
38: # 02/06/01 Gerd Kortemeyer
39: # 07/27 Guy Albertelli
40: # 07/27,07/28,07/30,08/03,08/06,08/08,08/09,08/10,8/13,8/15,
41: # 10/1,11/5 Gerd Kortemeyer
42: # YEAR=2002
43: # 1/1,3/18 Gerd Kortemeyer
44: #
45: package Apache::lonmsg;
46:
47: =pod
48:
49: =head1 NAME
50:
51: Apache::lonmsg: supports internal messaging
52:
53: =head1 SYNOPSIS
54:
55: lonmsg provides routines for sending messages, receiving messages, and
56: a handler to allow users to read, send, and delete messages.
57:
58: =head1 OVERVIEW
59:
60: =head2 Messaging Overview
61:
62: X<messages>LON-CAPA provides an internal messaging system similar to
63: email, but customized for LON-CAPA's usage. LON-CAPA implements its
64: own messaging system, rather then building on top of email, because of
65: the features LON-CAPA messages can offer that conventional e-mail can
66: not:
67:
68: =over 4
69:
70: =item * B<Critical messages>: A message the recipient B<must>
71: acknowlegde receipt of before they are allowed to continue using the
72: system, preventing a user from claiming they never got a message
73:
74: =item * B<Receipts>: LON-CAPA can reliably send reciepts informing the
75: sender that it has been read; again, useful for preventing students
76: from claiming they did not see a message. (While conventional e-mail
77: has some reciept support, it's sporadic, e-mail client-specific, and
78: generally the receiver can opt to not send one, making it useless in
79: this case.)
80:
81: =item * B<Context>: LON-CAPA knows about the sender, such as where
82: they are in a course. When a student mails an instructor asking for
83: help on the problem, the instructor receives not just the student's
84: question, but all submissions the student has made up to that point,
85: the user's rendering of the problem, and the complete view the student
86: saw of the resource, including discussion up to that point. Finally,
87: the instructor is reading all of this inside of LON-CAPA, not their
88: email program, so they have full access to LON-CAPA's grading
89: interface, or other features they may wish to use in response to the
90: student's query.
91:
92: =back
93:
94: Users can ask LON-CAPA to forward messages to conventional e-mail
95: addresses on their B<PREF> screen, but generally, LON-CAPA messages
96: are much more useful then traditional email can be made to be, even
97: with HTML support.
98:
99: Right now, this document will cover just how to send a message, since
100: it is likely you will not need to programmatically read messages,
101: since lonmsg already implements that functionality.
102:
103: =head1 FUNCTIONS
104:
105: =over 4
106:
107: =cut
108:
109: use strict;
110: use Apache::lonnet();
111: use vars qw($msgcount);
112: use HTML::TokeParser();
113: use Apache::Constants qw(:common);
114: use Apache::loncommon();
115: use Apache::lontexconvert();
116: use HTML::Entities();
117: use Mail::Send;
118: use Apache::lonlocal;
119:
120: # Querystring component with sorting type
121: my $sqs;
122:
123: # ===================================================================== Package
124:
125: sub packagemsg {
126: my ($subject,$message,$citation,$baseurl,$attachmenturl)=@_;
127: $message =&HTML::Entities::encode($message);
128: $citation=&HTML::Entities::encode($citation);
129: $subject =&HTML::Entities::encode($subject);
130: #remove machine specification
131: $baseurl =~ s|^http://[^/]+/|/|;
132: $baseurl =&HTML::Entities::encode($baseurl);
133: #remove machine specification
134: $attachmenturl =~ s|^http://[^/]+/|/|;
135: $attachmenturl =&HTML::Entities::encode($attachmenturl);
136:
137: my $now=time;
138: $msgcount++;
139: my $partsubj=$subject;
140: $partsubj=&Apache::lonnet::escape($partsubj);
141: my $msgid=&Apache::lonnet::escape(
142: $now.':'.$partsubj.':'.$ENV{'user.name'}.':'.
143: $ENV{'user.domain'}.':'.$msgcount.':'.$$);
144: my $result='<sendername>'.$ENV{'user.name'}.'</sendername>'.
145: '<senderdomain>'.$ENV{'user.domain'}.'</senderdomain>'.
146: '<subject>'.$subject.'</subject>'.
147: '<time>'.&Apache::lonlocal::locallocaltime($now).'</time>'.
148: '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
149: '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
150: '<client>'.$ENV{'REMOTE_ADDR'}.'</client>'.
151: '<browsertype>'.$ENV{'browser.type'}.'</browsertype>'.
152: '<browseros>'.$ENV{'browser.os'}.'</browseros>'.
153: '<browserversion>'.$ENV{'browser.version'}.'</browserversion>'.
154: '<browsermathml>'.$ENV{'browser.mathml'}.'</browsermathml>'.
155: '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
156: '<courseid>'.$ENV{'request.course.id'}.'</courseid>'.
157: '<role>'.$ENV{'request.role'}.'</role>'.
158: '<resource>'.$ENV{'request.filename'}.'</resource>'.
159: '<msgid>'.$msgid.'</msgid>'.
160: '<message>'.$message.'</message>';
161: if (defined($citation)) {
162: $result.='<citation>'.$citation.'</citation>';
163: }
164: if (defined($baseurl)) {
165: $result.= '<baseurl>'.$baseurl.'</baseurl>';
166: }
167: if (defined($attachmenturl)) {
168: $result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>';
169: }
170: return $msgid,$result;
171: }
172:
173: # ================================================== Unpack message into a hash
174:
175: sub unpackagemsg {
176: my ($message,$notoken)=@_;
177: my %content=();
178: my $parser=HTML::TokeParser->new(\$message);
179: my $token;
180: while ($token=$parser->get_token) {
181: if ($token->[0] eq 'S') {
182: my $entry=$token->[1];
183: my $value=$parser->get_text('/'.$entry);
184: $content{$entry}=$value;
185: }
186: }
187: if ($content{'attachmenturl'}) {
188: my ($fname,$ft)=($content{'attachmenturl'}=~/\/(\w+)\.(\w+)$/);
189: if ($notoken) {
190: $content{'message'}.='<p>'.&mt('Attachment').': <tt>'.$fname.'.'.$ft.'</tt>';
191: } else {
192: $content{'message'}.='<p>'.&mt('Attachment').': <a href="'.
193: &Apache::lonnet::tokenwrapper($content{'attachmenturl'}).
194: '"><tt>'.$fname.'.'.$ft.'</tt></a>';
195: }
196: }
197: return %content;
198: }
199:
200: # ======================================================= Get info out of msgid
201:
202: sub unpackmsgid {
203: my $msgid=&Apache::lonnet::unescape(shift);
204: my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/,
205: &Apache::lonnet::unescape($msgid));
206: my %status=&Apache::lonnet::get('email_status',[$msgid]);
207: if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
208: unless ($status{$msgid}) { $status{$msgid}='new'; }
209: return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});
210: }
211:
212:
213: sub sendemail {
214: my ($to,$subject,$body)=@_;
215: $body=
216: "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n".
217: "*** ".&mt('Please do not reply to this address.')."\n\n".$body;
218: my $msg = new Mail::Send;
219: $msg->to($to);
220: $msg->subject('[LON-CAPA] '.$subject);
221: if (my $fh = $msg->open('smtp',Server => 'localhost')) {
222: print $fh $body;
223: $fh->close;
224: }
225: }
226:
227: # ==================================================== Send notification emails
228:
229: sub sendnotification {
230: my ($to,$touname,$toudom,$subj,$crit)=@_;
231: my $sender=$ENV{'environment.firstname'}.' '.$ENV{'environment.lastname'};
232: my $critical=($crit?' critical':'');
233: my $url='http://'.
234: $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}.
235: '/adm/email?username='.$touname.'&domain='.$toudom;
236: my $body=(<<ENDMSG);
237: You received a$critical message from $sender in LON-CAPA. The subject is
238:
239: $subj
240:
241: Use
242:
243: $url
244:
245: to access this message.
246: ENDMSG
247: &sendemail($to,'New'.$critical.' message from '.$sender,$body);
248: }
249: # ============================================================= Check for email
250:
251: sub newmail {
252: if ((time-$ENV{'user.mailcheck.time'})>300) {
253: my %what=&Apache::lonnet::get('email_status',['recnewemail']);
254: &Apache::lonnet::appenv('user.mailcheck.time'=>time);
255: if ($what{'recnewemail'}>0) { return 1; }
256: }
257: return 0;
258: }
259:
260: # =============================== Automated message to the author of a resource
261:
262: =pod
263:
264: =item * B<author_res_msg($filename, $message)>: Sends message $message to the owner
265: of the resource with the URI $filename.
266:
267: =cut
268:
269: sub author_res_msg {
270: my ($filename,$message)=@_;
271: unless ($message) { return 'empty'; }
272: $filename=&Apache::lonnet::declutter($filename);
273: my ($domain,$author,@dummy)=split(/\//,$filename);
274: my $homeserver=&Apache::lonnet::homeserver($author,$domain);
275: if ($homeserver ne 'no_host') {
276: my $id=unpack("%32C*",$message);
277: my $msgid;
278: ($msgid,$message)=&packagemsg($filename,$message);
279: return &Apache::lonnet::reply('put:'.$domain.':'.$author.
280: ':nohist_res_msgs:'.
281: &Apache::lonnet::escape($filename.'_'.$id).'='.
282: &Apache::lonnet::escape($message),$homeserver);
283: }
284: return 'no_host';
285: }
286:
287: # ================================================== Critical message to a user
288:
289: sub user_crit_msg_raw {
290: my ($user,$domain,$subject,$message,$sendback)=@_;
291: # Check if allowed missing
292: my $status='';
293: my $msgid='undefined';
294: unless (($message)&&($user)&&($domain)) { $status='empty'; };
295: my $homeserver=&Apache::lonnet::homeserver($user,$domain);
296: if ($homeserver ne 'no_host') {
297: ($msgid,$message)=&packagemsg($subject,$message);
298: if ($sendback) { $message.='<sendback>true</sendback>'; }
299: $status=&Apache::lonnet::critical(
300: 'put:'.$domain.':'.$user.':critical:'.
301: &Apache::lonnet::escape($msgid).'='.
302: &Apache::lonnet::escape($message),$homeserver);
303: if ($ENV{'request.course.id'}) {
304: &user_normal_msg_raw(
305: $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
306: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
307: 'Critical ['.$user.':'.$domain.']',
308: $message);
309: }
310: } else {
311: $status='no_host';
312: }
313: # Notifications
314: my %userenv = &Apache::lonnet::get('environment',['critnotification'],
315: $domain,$user);
316: if ($userenv{'critnotification'}) {
317: &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1);
318: }
319: # Log this
320: &Apache::lonnet::logthis(
321: 'Sending critical email '.$msgid.
322: ', log status: '.
323: &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
324: $ENV{'user.home'},
325: 'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
326: .$status));
327: return $status;
328: }
329:
330: # New routine that respects "forward" and calls old routine
331:
332: =pod
333:
334: =item * B<user_crit_msg($user, $domain, $subject, $message, $sendback)>: Sends
335: a critical message $message to the $user at $domain. If $sendback is true,
336: a reciept will be sent to the current user when $user recieves the message.
337:
338: =cut
339:
340: sub user_crit_msg {
341: my ($user,$domain,$subject,$message,$sendback)=@_;
342: my $status='';
343: my %userenv = &Apache::lonnet::get('environment',['msgforward'],
344: $domain,$user);
345: my $msgforward=$userenv{'msgforward'};
346: if ($msgforward) {
347: foreach (split(/\,/,$msgforward)) {
348: my ($forwuser,$forwdomain)=split(/\:/,$_);
349: $status.=
350: &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
351: $sendback).' ';
352: }
353: } else {
354: $status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback);
355: }
356: return $status;
357: }
358:
359: # =================================================== Critical message received
360:
361: sub user_crit_received {
362: my $msgid=shift;
363: my %message=&Apache::lonnet::get('critical',[$msgid]);
364: my %contents=&unpackagemsg($message{$msgid},1);
365: my $status='rec: '.($contents{'sendback'}?
366: &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
367: &mt('Receipt').': '.$ENV{'user.name'}.' at '.$ENV{'user.domain'},
368: &mt('User').' '.$ENV{'user.name'}.' '.&mt('at').' '.$ENV{'user.domain'}.
369: ' acknowledged receipt of message'."\n".' "'.
370: $contents{'subject'}.'"'."\n".&mt('dated').' '.
371: $contents{'time'}.".\n"
372: ):'no msg req');
373: $status.=' trans: '.
374: &Apache::lonnet::put(
375: 'nohist_email',{$contents{'msgid'} => $message{$msgid}});
376: $status.=' del: '.
377: &Apache::lonnet::del('critical',[$contents{'msgid'}]);
378: &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
379: $ENV{'user.home'},'Received critical message '.
380: $contents{'msgid'}.
381: ', '.$status);
382: return $status;
383: }
384:
385: # ======================================================== Normal communication
386:
387: sub user_normal_msg_raw {
388: my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_;
389: # Check if allowed missing
390: my $status='';
391: my $msgid='undefined';
392: unless (($message)&&($user)&&($domain)) { $status='empty'; };
393: my $homeserver=&Apache::lonnet::homeserver($user,$domain);
394: if ($homeserver ne 'no_host') {
395: ($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl,
396: $attachmenturl);
397: $status=&Apache::lonnet::critical(
398: 'put:'.$domain.':'.$user.':nohist_email:'.
399: &Apache::lonnet::escape($msgid).'='.
400: &Apache::lonnet::escape($message),$homeserver);
401: &Apache::lonnet::put
402: ('email_status',{'recnewemail'=>time},$domain,$user);
403: } else {
404: $status='no_host';
405: }
406: # Notifications
407: my %userenv = &Apache::lonnet::get('environment',['notification'],
408: $domain,$user);
409: if ($userenv{'notification'}) {
410: &sendnotification($userenv{'notification'},$user,$domain,$subject,0);
411: }
412: &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
413: $ENV{'user.home'},
414: 'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
415: return $status;
416: }
417:
418: # New routine that respects "forward" and calls old routine
419:
420: =pod
421:
422: =item * B<user_normal_msg($user, $domain, $subject, $message,
423: $citation, $baseurl, $attachmenturl)>: Sends a message to the
424: $user at $domain, with subject $subject and message $message.
425:
426: =cut
427:
428: sub user_normal_msg {
429: my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_;
430: my $status='';
431: my %userenv = &Apache::lonnet::get('environment',['msgforward'],
432: $domain,$user);
433: my $msgforward=$userenv{'msgforward'};
434: if ($msgforward) {
435: foreach (split(/\,/,$msgforward)) {
436: my ($forwuser,$forwdomain)=split(/\:/,$_);
437: $status.=
438: &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
439: $citation,$baseurl,$attachmenturl).' ';
440: }
441: } else {
442: $status=&user_normal_msg_raw($user,$domain,$subject,$message,
443: $citation,$baseurl,$attachmenturl);
444: }
445: return $status;
446: }
447:
448:
449: # =============================================================== Status Change
450:
451: sub statuschange {
452: my ($msgid,$newstatus)=@_;
453: my %status=&Apache::lonnet::get('email_status',[$msgid]);
454: if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
455: unless ($status{$msgid}) { $status{$msgid}='new'; }
456: unless (($status{$msgid} eq 'replied') ||
457: ($status{$msgid} eq 'forwarded')) {
458: &Apache::lonnet::put('email_status',{$msgid => $newstatus});
459: }
460: if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
461: &Apache::lonnet::put('email_status',{$msgid => $newstatus});
462: }
463: }
464:
465: # ======================================================= Display a course list
466:
467: sub discourse {
468: my $r=shift;
469: my %courselist=&Apache::lonnet::dump(
470: 'classlist',
471: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
472: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
473: my $now=time;
474: my %lt=&Apache::lonlocal::texthash('cfa' => 'Check for All',
475: 'cfs' => 'Check for Section/Group',
476: 'cfn' => 'Check for None');
477: $r->print(<<ENDDISHEADER);
478: <input type=hidden name=sendmode value=group>
479: <script>
480: function checkall() {
481: for (i=0; i<document.forms.compemail.elements.length; i++) {
482: if
483: (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
484: document.forms.compemail.elements[i].checked=true;
485: }
486: }
487: }
488:
489: function checksec() {
490: for (i=0; i<document.forms.compemail.elements.length; i++) {
491: if
492: (document.forms.compemail.elements[i].name.indexOf
493: ('send_to_&&&'+document.forms.compemail.chksec.value)==0) {
494: document.forms.compemail.elements[i].checked=true;
495: }
496: }
497: }
498:
499: function uncheckall() {
500: for (i=0; i<document.forms.compemail.elements.length; i++) {
501: if
502: (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
503: document.forms.compemail.elements[i].checked=false;
504: }
505: }
506: }
507: </script>
508: <input type=button onClick="checkall()" value="$lt{'cfa'}">
509: <input type=button onClick="checksec()" value="$lt{'cfs'}">
510: <input type=text size=5 name=chksec>
511: <input type=button onClick="uncheckall()" value="$lt{'cfn'}">
512: <p>
513: ENDDISHEADER
514: my %coursepersonnel=
515: &Apache::lonnet::get_course_adv_roles();
516: foreach my $role (sort keys %coursepersonnel) {
517: foreach (split(/\,/,$coursepersonnel{$role})) {
518: my ($puname,$pudom)=split(/\:/,$_);
519: $r->print(
520: '<br /><input type="checkbox" name="send_to_&&&&&&_'.
521: $puname.':'.$pudom.'" /> '.
522: &Apache::loncommon::plainname($puname,
523: $pudom).' ('.$_.'), <i>'.$role.'</i>');
524: }
525: }
526:
527: foreach (sort keys %courselist) {
528: my ($end,$start)=split(/\:/,$courselist{$_});
529: my $active=1;
530: if (($end) && ($now>$end)) { $active=0; }
531: if ($active) {
532: my ($sname,$sdom)=split(/\:/,$_);
533: my %reply=&Apache::lonnet::get('environment',
534: ['firstname','middlename','lastname','generation'],
535: $sdom,$sname);
536: my $section=&Apache::lonnet::usection
537: ($sdom,$sname,$ENV{'request.course.id'});
538: $r->print(
539: '<br><input type=checkbox name="send_to_&&&'.$section.'&&&_'.$_.'"> '.
540: $reply{'firstname'}.' '.
541: $reply{'middlename'}.' '.
542: $reply{'lastname'}.' '.
543: $reply{'generation'}.
544: ' ('.$_.') '.$section);
545: }
546: }
547: }
548:
549: # ==================================================== Display Critical Message
550:
551: sub discrit {
552: my $r=shift;
553: my $header = '<h1><font color=red>'.&mt('Critical Messages').'</font></h1>'.
554: '<form action=/adm/email method=post>'.
555: '<input type=hidden name=confirm value=true>';
556: my %what=&Apache::lonnet::dump('critical');
557: my $result = '';
558: foreach (sort keys %what) {
559: my %content=&unpackagemsg($what{$_});
560: next if ($content{'senderdomain'} eq '');
561: $content{'message'}=~s/\n/\<br\>/g;
562: $result.='<hr>'.&mt('From').': <b>'.
563: &Apache::loncommon::aboutmewrapper(
564: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
565: $content{'sendername'}.'@'.
566: $content{'senderdomain'}.') '.$content{'time'}.
567: '<br>'.&mt('Subject').': '.$content{'subject'}.
568: '<br><blockquote>'.
569: &Apache::lontexconvert::msgtexconverted($content{'message'}).
570: '</blockquote>'.
571: '<input type=submit name="rec_'.$_.'" value="'.&mt('Confirm Receipt').'">'.
572: '<input type=submit name="reprec_'.$_.'" '.
573: 'value="'.&mt('Confirm Receipt and Reply').'">';
574: }
575: # Check to see if there were any messages.
576: if ($result eq '') {
577: $result = "<h2>".&mt('You have no critical messages.')."</h2>".
578: '<a href="/adm/roles">'.&mt('Select a course').'</a>';
579: } else {
580: $r->print($header);
581: }
582: $r->print($result);
583: $r->print('<input type=hidden name="displayedcrit" value="true"></form>');
584: }
585:
586: # =============================================================== Compose reply
587:
588: sub comprep {
589: my ($r,$msgid)=@_;
590: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
591: my %content=&unpackagemsg($message{$msgid},1);
592: my $quotemsg='> '.$content{'message'};
593: $quotemsg=~s/\r/\n/g;
594: $quotemsg=~s/\f/\n/g;
595: $quotemsg=~s/\n+/\n\> /g;
596: my $torepl=&Apache::loncommon::aboutmewrapper(
597: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
598: $content{'sendername'}.'@'.
599: $content{'senderdomain'}.')';
600: my $subject=&mt('Re').': '.$content{'subject'};
601: my $dispcrit='';
602: if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
603: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
604: $dispcrit=
605: '<input type=checkbox name=critmsg> '.&mt('Send as critical message').' ' . $crithelp .
606: '<br>'.
607: '<input type=checkbox name=sendbck> '.&mt('Send as critical message').' ' .
608: &mt('and return receipt') . $crithelp . '<p>';
609: }
610: my %lt=&Apache::lonlocal::texthash(
611: 'to' => 'To',
612: 'sb' => 'Subject',
613: 'sr' => 'Send Reply',
614: 'ca' => 'Cancel'
615: );
616: $r->print(<<"ENDREPLY");
617: <form action="/adm/email" method="post">
618: <input type="hidden" name="sendreply" value="$msgid">
619: $lt{'to'}: $torepl<br />
620: $lt{'sb'}: <input type="text" size=50 name="subject" value="$subject"><p>
621: <textarea name="message" cols="84" rows="10" wrap="hard">
622: $quotemsg
623: </textarea></p><br />
624: $dispcrit
625: <input type="submit" name="send" value="$lt{'sr'}" />
626: <input type="submit" name="cancel" value="$lt{'ca'}"/ >
627: </form>
628: ENDREPLY
629: }
630:
631: sub sortedmessages {
632: my @messages = &Apache::lonnet::getkeys('nohist_email');
633: #unpack the varibles and repack into temp for sorting
634: my @temp;
635: foreach (@messages) {
636: my $msgid=&Apache::lonnet::escape($_);
637: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
638: &Apache::lonmsg::unpackmsgid($msgid);
639: my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
640: $msgid);
641: push @temp ,\@temp1;
642: }
643: #default sort
644: @temp = sort {$a->[0] <=> $b->[0]} @temp;
645: if ($ENV{'form.sortedby'} eq "date"){
646: @temp = sort {$a->[0] <=> $b->[0]} @temp;
647: }
648: if ($ENV{'form.sortedby'} eq "revdate"){
649: @temp = sort {$b->[0] <=> $a->[0]} @temp;
650: }
651: if ($ENV{'form.sortedby'} eq "user"){
652: @temp = sort {lc($a->[2]) cmp lc($b->[2])} @temp;
653: }
654: if ($ENV{'form.sortedby'} eq "revuser"){
655: @temp = sort {lc($b->[2]) cmp lc($a->[2])} @temp;
656: }
657: if ($ENV{'form.sortedby'} eq "domain"){
658: @temp = sort {$a->[3] cmp $b->[3]} @temp;
659: }
660: if ($ENV{'form.sortedby'} eq "revdomain"){
661: @temp = sort {$b->[3] cmp $a->[3]} @temp;
662: }
663: if ($ENV{'form.sortedby'} eq "subject"){
664: @temp = sort {lc($a->[1]) cmp lc($b->[1])} @temp;
665: }
666: if ($ENV{'form.sortedby'} eq "revsubject"){
667: @temp = sort {lc($b->[1]) cmp lc($a->[1])} @temp;
668: }
669: if ($ENV{'form.sortedby'} eq "status"){
670: @temp = sort {$a->[4] cmp $b->[4]} @temp;
671: }
672: if ($ENV{'form.sortedby'} eq "revstatus"){
673: @temp = sort {$b->[4] cmp $a->[4]} @temp;
674: }
675: return @temp;
676: }
677:
678: # ======================================================== Display all messages
679:
680: sub disall {
681: my $r=shift;
682: $r->print(<<ENDDISHEADER);
683: <script>
684: function checkall() {
685: for (i=0; i<document.forms.disall.elements.length; i++) {
686: if
687: (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
688: document.forms.disall.elements[i].checked=true;
689: }
690: }
691: }
692:
693: function uncheckall() {
694: for (i=0; i<document.forms.disall.elements.length; i++) {
695: if
696: (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
697: document.forms.disall.elements[i].checked=false;
698: }
699: }
700: }
701: </script>
702: ENDDISHEADER
703: $r->print('<h1>'.&mt('Display All Messages').'</h1><form method=post name=disall '.
704: 'action="/adm/email">'.
705: '<table border=2><tr><th colspan=2> </th><th>');
706: if ($ENV{'form.sortedby'} eq "revdate") {
707: $r->print('<a href = "?sortedby=date">'.&mt('Date').'</a></th>');
708: } else {
709: $r->print('<a href = "?sortedby=revdate">'.&mt('Date').'</a></th>');
710: }
711: $r->print('<th>');
712: if ($ENV{'form.sortedby'} eq "revuser") {
713: $r->print('<a href = "?sortedby=user">'.&mt('Username').'</a>');
714: } else {
715: $r->print('<a href = "?sortedby=revuser">'.&mt('Username').'</a>');
716: }
717: $r->print('</th><th>');
718: if ($ENV{'form.sortedby'} eq "revdomain") {
719: $r->print('<a href = "?sortedby=domain">'.&mt('Domain').'</a>');
720: } else {
721: $r->print('<a href = "?sortedby=revdomain">'.&mt('Domain').'</a>');
722: }
723: $r->print('</th><th>');
724: if ($ENV{'form.sortedby'} eq "revsubject") {
725: $r->print('<a href = "?sortedby=subject">'.&mt('Subject').'</a>');
726: } else {
727: $r->print('<a href = "?sortedby=revsubject">'.&mt('Subject').'</a>');
728: }
729: $r->print('</th><th>');
730: if ($ENV{'form.sortedby'} eq "revstatus") {
731: $r->print('<a href = "?sortedby=status">'.&mt('Status').'</th>');
732: } else {
733: $r->print('<a href = "?sortedby=revstatus">'.&mt('Status').'</th>');
734: }
735: $r->print('</tr>');
736: my @temp=sortedmessages();
737: foreach (@temp){
738: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID)= @$_;
739: if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
740: if ($status eq 'new') {
741: $r->print('<tr bgcolor="#FFBB77">');
742: } elsif ($status eq 'read') {
743: $r->print('<tr bgcolor="#BBBB77">');
744: } elsif ($status eq 'replied') {
745: $r->print('<tr bgcolor="#AAAA88">');
746: } else {
747: $r->print('<tr bgcolor="#99BBBB">');
748: }
749: $r->print('<td><a href="/adm/email?display='.$origID.$sqs.
750: '">'.&mt('Open').'</a></td><td><a href="/adm/email?markdel='.$origID.$sqs.
751: '">'.&mt('Delete').'</a><input type=checkbox name="delmark_'.$origID.'"></td>'.
752: '<td>'.&Apache::lonlocal::locallocaltime($sendtime).'</td><td>'.
753: $fromname.'</td><td>'.$fromdomain.'</td><td>'.
754: &Apache::lonnet::unescape($shortsubj).'</td><td>'.
755: $status.'</td></tr>');
756: }
757: }
758: $r->print('</table><p>'.
759: '<a href="javascript:checkall()">'.&mt('Check All').'</a> '.
760: '<a href="javascript:uncheckall()">'.&mt('Uncheck All').'</a><p>'.
761: '<input type="hidden" name="sortedby" value="'.$ENV{'form.sortedby'}.'" />'.
762: '<input type=submit name="markeddel" value="'.&mt('Delete Checked').'">'.
763: '</form></body></html>');
764: }
765:
766: # ============================================================== Compose output
767:
768: sub compout {
769: my ($r,$forwarding,$broadcast)=@_;
770: my $dispcrit='';
771: my $dissub='';
772: my $dismsg='';
773: my $func=&mt('Send New');
774: my %lt=&Apache::lonlocal::texthash('us' => 'Username',
775: 'do' => 'Domain',
776: 'ad' => 'Additional Recipients',
777: 'sb' => 'Subject',
778: 'ca' => 'Cancel',
779: 'ma' => 'Mail');
780:
781: if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
782: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
783: $dispcrit=
784: '<input type="checkbox" name="critmsg"> '.&mt('Send as critical message').' ' . $crithelp .
785: '<br>'.
786: '<input type="checkbox" name="sendbck"> '.&mt('Send as critical message').' ' .
787: &mt('and return receipt') . $crithelp . '<p>';
788: }
789: if ($forwarding) {
790: $dispcrit.='<input type="hidden" name="forwid" value="'.
791: $forwarding.'">';
792: $func=&mt('Forward');
793: my %message=&Apache::lonnet::get('nohist_email',[$forwarding]);
794: my %content=&unpackagemsg($message{$forwarding});
795:
796: $dissub=&mt('Forwarding').': '.$content{'subject'};
797: $dismsg=&mt('Forwarded message from').' '.
798: $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
799: }
800: my $defdom=$ENV{'user.domain'};
801: if ($ENV{'form.recdom'}) { $defdom=$ENV{'form.recdom'}; }
802: $r->print(
803: '<form action="/adm/email" name="compemail" method="post"'.
804: ' enctype="multipart/form-data">'."\n".
805: '<input type="hidden" name="sendmail" value="on">'."\n".
806: '<table>');
807: unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
808: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
809: my $selectlink=&Apache::loncommon::selectstudent_link
810: ('compemail','recuname','recdomain');
811: $r->print(<<"ENDREC");
812: <table>
813: <tr><td>$lt{'us'}:</td><td><input type="text" size="12" name="recuname" value="$ENV{'form.recname'}"></td><td rowspan="2">$selectlink</td></tr>
814: <tr><td>$lt{'do'}:</td>
815: <td>$domform</td></tr>
816: ENDREC
817: }
818: my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
819: if ($broadcast ne 'upload') {
820: $r->print(<<"ENDCOMP");
821: <tr><td>$lt{'ad'}<br /><tt>username\@domain,username\@domain, ...
822: </tt></td><td>
823: <input type="text" size="50" name="additionalrec"></td></tr>
824: <tr><td>$lt{'sb'}:</td><td><input type="text" size="50" name="subject" value="$dissub">
825: </td></tr></table>
826: $latexHelp
827: <textarea name="message" cols="80" rows="10" wrap="hard">$dismsg
828: </textarea></p><br />
829: $dispcrit
830: <input type="submit" name="send" value="$func $lt{'ma'}" />
831: <input type="submit" name="cancel" value="$lt{'ca'}" />
832: ENDCOMP
833: } else { # $broadcast is 'upload'
834: $r->print(<<ENDUPLOAD);
835: <input type=hidden name=sendmode value=upload>
836: <h3>Generate messages from a file</h3>
837: <p>
838: Subject: <input type=text size=50 name=subject>
839: </p>
840: <p>General message text<br />
841: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
842: </textarea></p>
843: <p>
844: The file format for the uploaded portion of the message is:
845: <pre>
846: username1\@domain1: text
847: username2\@domain2: text
848: username3\@domain1: text
849: </pre>
850: </p>
851: <p>
852: The messages will be assembled from all lines with the respective
853: <tt>username\@domain</tt>, and appended to the general message text.</p>
854: <p>
855: <input type=file name=upfile size=20><p>
856: $dispcrit
857: <input type=submit value="Upload and send">
858: ENDUPLOAD
859: }
860: if ($broadcast eq 'group') {
861: &discourse;
862: }
863: $r->print('</form>');
864: }
865:
866: # ---------------------------------------------------- Display all face to face
867:
868: sub disfacetoface {
869: my ($r,$user,$domain)=@_;
870: unless ($ENV{'request.course.id'}) { return; }
871: unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
872: return;
873: }
874: my %records=&Apache::lonnet::dump('nohist_email',
875: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
876: $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
877: '%255b'.$user.'%253a'.$domain.'%255d');
878: my $result='';
879: foreach (sort keys %records) {
880: my %content=&unpackagemsg($records{$_});
881: next if ($content{'senderdomain'} eq '');
882: $content{'message'}=~s/\n/\<br\>/g;
883: if ($content{'subject'}=~/^Record/) {
884: $result.='<h3>'.&mt('Record').'</h3>';
885: } else {
886: $result.='<h3>'.&mt('Sent Message').'</h3>';
887: %content=&unpackagemsg($content{'message'});
888: $content{'message'}=
889: '<b>Subject: '.$content{'subject'}.'</b><br />'.
890: $content{'message'};
891: }
892: $result.=&mt('By').': <b>'.
893: &Apache::loncommon::aboutmewrapper(
894: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
895: $content{'sendername'}.'@'.
896: $content{'senderdomain'}.') '.$content{'time'}.
897: '<br><blockquote>'.
898: &Apache::lontexconvert::msgtexconverted($content{'message'}).
899: '</blockquote>';
900: }
901: # Check to see if there were any messages.
902: if ($result eq '') {
903: $r->print("<p><b>No notes, face-to-face discussion records, or critical messages in this course.</b></p>");
904: } else {
905: $r->print($result);
906: }
907: }
908:
909: # ---------------------------------------------------------------- Face to face
910:
911: sub facetoface {
912: my ($r,$stage)=@_;
913: unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
914: return;
915: }
916: # from query string
917: if ($ENV{'form.recname'}) { $ENV{'form.recuname'}=$ENV{'form.recname'}; }
918: if ($ENV{'form.recdom'}) { $ENV{'form.recdomain'}=$ENV{'form.recdom'}; }
919:
920: my $defdom=$ENV{'user.domain'};
921: # already filled in
922: if ($ENV{'form.recdomain'}) { $defdom=$ENV{'form.recdomain'}; }
923: # generate output
924: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
925: my $stdbrws = &Apache::loncommon::selectstudent_link
926: ('stdselect','recuname','recdomain');
927: $r->print(<<"ENDTREC");
928: <h3>User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course</h3>
929: <form method="post" action="/adm/email" name="stdselect">
930: <input type="hidden" name="recordftf" value="retrieve" />
931: <table>
932: <tr><td>Username:</td><td><input type=text size=12 name=recuname value="$ENV{'form.recuname'}"></td>
933: <td rowspan="2">
934: $stdbrws
935: <input type="submit" value="Retrieve discussion and message records"></td>
936: </tr>
937: <tr><td>Domain:</td>
938: <td>$domform</td></tr>
939: </table>
940: </form>
941: ENDTREC
942: if (($stage ne 'query') &&
943: ($ENV{'form.recdomain'}) && ($ENV{'form.recuname'})) {
944: chomp($ENV{'form.newrecord'});
945: if ($ENV{'form.newrecord'}) {
946: &user_normal_msg_raw(
947: $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
948: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
949: 'Record ['.$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}.']',
950: $ENV{'form.newrecord'});
951: }
952: $r->print('<h3>'.&Apache::loncommon::plainname($ENV{'form.recuname'},
953: $ENV{'form.recdomain'}).'</h3>');
954: &disfacetoface($r,$ENV{'form.recuname'},$ENV{'form.recdomain'});
955: $r->print(<<ENDRHEAD);
956: <form method="post" action="/adm/email">
957: <input name="recdomain" value="$ENV{'form.recdomain'}" type="hidden" />
958: <input name="recuname" value="$ENV{'form.recuname'}" type="hidden" />
959: ENDRHEAD
960: $r->print(<<ENDBFORM);
961: <hr />New Record (record is visible to course faculty and staff)<br />
962: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
963: <br />
964: <input type="hidden" name="recordftf" value="post" />
965: <input type="submit" value="Post this record" />
966: </form>
967: ENDBFORM
968: }
969: }
970:
971: # ===================================================================== Handler
972:
973: sub handler {
974: my $r=shift;
975:
976: # ----------------------------------------------------------- Set document type
977:
978: &Apache::loncommon::content_type($r,'text/html');
979: $r->send_http_header;
980:
981: return OK if $r->header_only;
982:
983: # --------------------------- Get query string for limited number of parameters
984: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
985: ['display','replyto','forward','markread','markdel','markunread',
986: 'sendreply','compose','sendmail','critical','recname','recdom',
987: 'recordftf','sortedby']);
988: $sqs='&sortedby='.$ENV{'form.sortedby'};
989: # ------------------------------------------------------ They checked for email
990: &Apache::lonnet::put('email_status',{'recnewemail'=>0});
991: # --------------------------------------------------------------- Render Output
992: if (!$ENV{'form.display'}) {
993: $r->print('<html><head><title>EMail and Messaging</title>'.
994: &Apache::loncommon::studentbrowser_javascript().'</head>'.
995: &Apache::loncommon::bodytag('EMail and Messages'));
996: }
997: if ($ENV{'form.display'}) {
998: my $msgid=$ENV{'form.display'};
999: &statuschange($msgid,'read');
1000: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1001: my %content=&unpackagemsg($message{$msgid});
1002: # info to generate "next" and "previous" buttons
1003: my @messages=&sortedmessages();
1004: my $counter=0;
1005: $r->print('<pre>');
1006: my $escmsgid=&Apache::lonnet::escape($msgid);
1007: foreach (@messages) {
1008: if ($_->[5] eq $escmsgid){
1009: last;
1010: }
1011: $counter++;
1012: }
1013: $r->print('</pre>');
1014: my $number_of_messages = scalar(@messages); #subtract 1 for last index
1015: # start output
1016: $r->print('<html><head><title>EMail and Messaging</title>');
1017: if (defined($content{'baseurl'})) {
1018: $r->print("<base href=\"http://$ENV{'SERVER_NAME'}/$content{'baseurl'}\" />");
1019: }
1020: $r->print(&Apache::loncommon::studentbrowser_javascript().
1021: '</head>'.
1022: &Apache::loncommon::bodytag('EMail and Messages'));
1023: $r->print('<b>'.&mt('Subject').':</b> '.$content{'subject'}.
1024: '<br><b>'.&mt('From').':</b> '.
1025: &Apache::loncommon::aboutmewrapper(
1026: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
1027: $content{'sendername'},$content{'senderdomain'}).' ('.
1028: $content{'sendername'}.' at '.
1029: $content{'senderdomain'}.') '.
1030: '<br><b>'.&mt('Time').':</b> '.$content{'time'}.'<p>'.
1031: '<table border=2><tr bgcolor="#FFFFAA"><td>'.&mt('Functions').':</td>'.
1032: '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).$sqs.
1033: '"><b>'.&mt('Reply').'</b></a></td>'.
1034: '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).$sqs.
1035: '"><b>'.&mt('Forward').'</b></a></td>'.
1036: '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).$sqs.
1037: '"><b>'.&mt('Mark Unread').'</b></a></td>'.
1038: '<td><a href="/adm/email?markdel='.&Apache::lonnet::escape($msgid).$sqs.
1039: '"><b>Delete</b></a></td>'.
1040: '<td><a href="/adm/email?sortedby='.$ENV{'form.sortedby'}.
1041: '"><b>'.&mt('Display all Messages').'</b></a></td>');
1042: if ($counter > 0){
1043: $r->print('<td><a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.
1044: '"><b>'.&mt('Previous').'</b></a></td>');
1045: }
1046: if ($counter < $number_of_messages - 1){
1047: $r->print('<td><a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.
1048: '"><b>'.&mt('Next').'</b></a></td>');
1049: }
1050: $r->print('</tr></table><p><pre>'.
1051: &Apache::lontexconvert::msgtexconverted($content{'message'}).
1052: '</pre><hr>'.$content{'citation'});
1053: } elsif ($ENV{'form.replyto'}) {
1054: &comprep($r,$ENV{'form.replyto'});
1055: } elsif ($ENV{'form.sendreply'}) {
1056: if ($ENV{'form.send'}) {
1057: my $msgid=$ENV{'form.sendreply'};
1058: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1059: my %content=&unpackagemsg($message{$msgid},1);
1060: &statuschange($msgid,'replied');
1061: if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) &&
1062: (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
1063: $r->print(&mt('Sending critical message').': '.
1064: &user_crit_msg($content{'sendername'},
1065: $content{'senderdomain'},
1066: &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
1067: &Apache::lonfeedback::clear_out_html($ENV{'form.message'}),
1068: $ENV{'form.sendbck'}));
1069: } else {
1070: $r->print(&mt('Sending').': '.&user_normal_msg($content{'sendername'},
1071: $content{'senderdomain'},
1072: &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
1073: &Apache::lonfeedback::clear_out_html($ENV{'form.message'})));
1074: }
1075: }
1076: if ($ENV{'form.displayedcrit'}) {
1077: &discrit($r);
1078: } else {
1079: &disall($r);
1080: }
1081: } elsif ($ENV{'form.confirm'}) {
1082: foreach (keys %ENV) {
1083: if ($_=~/^form\.rec\_(.*)$/) {
1084: $r->print('<b>Confirming Receipt:</b> '.
1085: &user_crit_received($1).'<br>');
1086: }
1087: if ($_=~/^form\.reprec\_(.*)$/) {
1088: my $msgid=$1;
1089: $r->print('<b>Confirming Receipt:</b> '.
1090: &user_crit_received($msgid).'<br>');
1091: &comprep($r,$msgid);
1092: }
1093: }
1094: &discrit($r);
1095: } elsif ($ENV{'form.critical'}) {
1096: &discrit($r);
1097: } elsif ($ENV{'form.forward'}) {
1098: &compout($r,$ENV{'form.forward'});
1099: } elsif ($ENV{'form.markread'}) {
1100: } elsif ($ENV{'form.markdel'}) {
1101: &statuschange($ENV{'form.markdel'},'deleted');
1102: &disall($r);
1103: } elsif ($ENV{'form.markeddel'}) {
1104: my $total=0;
1105: foreach (keys %ENV) {
1106: if ($_=~/^form\.delmark_(.*)$/) {
1107: &statuschange(&Apache::lonnet::unescape($1),'deleted');
1108: $total++;
1109: }
1110: }
1111: $r->print('Deleted '.$total.' message(s)<p>');
1112: &disall($r);
1113: } elsif ($ENV{'form.markunread'}) {
1114: &statuschange($ENV{'form.markunread'},'new');
1115: &disall($r);
1116: } elsif ($ENV{'form.compose'}) {
1117: &compout($r,'',$ENV{'form.compose'});
1118: } elsif ($ENV{'form.recordftf'}) {
1119: &facetoface($r,$ENV{'form.recordftf'});
1120: } elsif ($ENV{'form.sendmail'}) {
1121: my $sendstatus='';
1122: if ($ENV{'form.send'}) {
1123: my %content=();
1124: undef %content;
1125: if ($ENV{'form.forwid'}) {
1126: my $msgid=$ENV{'form.forwid'};
1127: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1128: %content=&unpackagemsg($message{$msgid},1);
1129: &statuschange($msgid,'forwarded');
1130: $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
1131: $content{'message'};
1132: }
1133: my %toaddr=();
1134: undef %toaddr;
1135: if ($ENV{'form.sendmode'} eq 'group') {
1136: foreach (keys %ENV) {
1137: if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
1138: $toaddr{$1}='';
1139: }
1140: }
1141: } elsif ($ENV{'form.sendmode'} eq 'upload') {
1142: foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) {
1143: my ($rec,$txt)=split(/\s*\:\s*/,$_);
1144: if ($txt) {
1145: $rec=~s/\@/\:/;
1146: $toaddr{$rec}.=$txt."\n";
1147: }
1148: }
1149: } else {
1150: $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
1151: }
1152: if ($ENV{'form.additionalrec'}) {
1153: foreach (split(/\,/,$ENV{'form.additionalrec'})) {
1154: my ($auname,$audom)=split(/\@/,$_);
1155: $toaddr{$auname.':'.$audom}='';
1156: }
1157: }
1158: foreach (keys %toaddr) {
1159: my ($recuname,$recdomain)=split(/\:/,$_);
1160: my $msgtxt=&Apache::lonfeedback::clear_out_html($ENV{'form.message'});
1161: if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }
1162: if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) &&
1163: (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
1164: $r->print(&mt('Sending critical message').' ...');
1165: $sendstatus.=' '.&user_crit_msg($recuname,$recdomain,
1166: &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
1167: $msgtxt,
1168: $ENV{'form.sendbck'});
1169: } else {
1170: $r->print(&mt('Sending').' ...');
1171: $sendstatus.=' '.&user_normal_msg($recuname,$recdomain,
1172: &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
1173: $msgtxt,
1174: $content{'citation'});
1175: }
1176: $r->print('<br />');
1177: }
1178: }
1179: if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
1180: if ($ENV{'form.displayedcrit'}) {
1181: &discrit($r);
1182: } else {
1183: &disall($r);
1184: }
1185: } else {
1186: $r->print(
1187: '<h2><font color="red">'.&mt('Could not deliver message').'</font></h2>'.
1188: &mt('Please use the browser "Back" button and correct the recipient addresses')
1189: );
1190: }
1191: } else {
1192: &disall($r);
1193: }
1194: $r->print('</body></html>');
1195: return OK;
1196:
1197: }
1198: # ================================================= Main program, reset counter
1199:
1200: BEGIN {
1201: $msgcount=0;
1202: }
1203:
1204: =pod
1205:
1206: =back
1207:
1208: =cut
1209:
1210: 1;
1211:
1212: __END__
1213:
1214:
1215:
1216:
1217:
1218:
1219:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>