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