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