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