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