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