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