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