Annotation of loncom/interface/lonmsg.pm, revision 1.53
1.1 www 1: # The LearningOnline Network with CAPA
1.26 albertel 2: # Routines for messaging
3: #
1.53 ! www 4: # $Id: lonmsg.pm,v 1.52 2003/03/31 16:34:08 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:
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)}.
! 168: '/adm/login&username='.$touname.'&domain='.$toudom;
! 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.31 matthew 619: if ($broadcast ne 'upload') {
1.22 www 620: $r->print(<<"ENDCOMP");
1.20 www 621: <tr><td>Additional Recipients<br><tt>username\@domain,username\@domain, ...
622: </tt></td><td>
623: <input type=text size=50 name=additionalrec></td></tr>
1.15 www 624: <tr><td>Subject:</td><td><input type=text size=50 name=subject value="$dissub">
625: </td></tr></table>
1.37 www 626: <textarea name=message cols=80 rows=10 wrap=hard>$dismsg
1.15 www 627: </textarea><p>
628: $dispcrit
629: <input type=submit value="$func Mail">
630: ENDCOMP
1.31 matthew 631: } else { # $broadcast is 'upload'
1.22 www 632: $r->print(<<ENDUPLOAD);
633: <input type=hidden name=sendmode value=upload>
634: <h3>Generate messages from a file</h3>
1.31 matthew 635: <p>
1.22 www 636: Subject: <input type=text size=50 name=subject>
1.31 matthew 637: </p>
638: <p>General message text<br />
639: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
640: </textarea></p>
641: <p>
642: The file format for the uploaded portion of the message is:
1.22 www 643: <pre>
644: username1\@domain1: text
645: username2\@domain2: text
1.31 matthew 646: username3\@domain1: text
1.22 www 647: </pre>
1.31 matthew 648: </p>
649: <p>
1.22 www 650: The messages will be assembled from all lines with the respective
1.31 matthew 651: <tt>username\@domain</tt>, and appended to the general message text.</p>
652: <p>
1.22 www 653: <input type=file name=upfile size=20><p>
654: $dispcrit
655: <input type=submit value="Upload and send">
656: ENDUPLOAD
657: }
1.17 www 658: if ($broadcast eq 'group') {
659: &discourse;
660: }
661: $r->print('</form>');
1.15 www 662: }
663:
1.45 www 664: # ---------------------------------------------------- Display all face to face
665:
666: sub disfacetoface {
667: my ($r,$user,$domain)=@_;
668: unless ($ENV{'request.course.id'}) { return; }
669: unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
670: return;
671: }
672: my %records=&Apache::lonnet::dump('nohist_email',
673: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
674: $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
675: '%255b'.$user.'%253a'.$domain.'%255d');
676: my $result='';
677: foreach (sort keys %records) {
678: my %content=&unpackagemsg($records{$_});
679: next if ($content{'senderdomain'} eq '');
680: $content{'message'}=~s/\n/\<br\>/g;
681: if ($content{'subject'}=~/^Record/) {
682: $result.='<h3>Record</h3>';
683: } else {
684: $result.='<h3>Sent Message</h3>';
685: %content=&unpackagemsg($content{'message'});
686: $content{'message'}=
687: '<b>Subject: '.$content{'subject'}.'</b><br />'.
688: $content{'message'};
689: }
690: $result.='By: <b>'.
691: &Apache::loncommon::aboutmewrapper(
692: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
693: $content{'sendername'}.'@'.
694: $content{'senderdomain'}.') '.$content{'time'}.
695: '<br><blockquote>'.
696: &Apache::lontexconvert::msgtexconverted($content{'message'}).
697: '</blockquote>';
698: }
699: # Check to see if there were any messages.
700: if ($result eq '') {
1.46 www 701: $r->print("<p><b>No notes, face-to-face discussion records, or critical messages in this course.</b></p>");
1.45 www 702: } else {
703: $r->print($result);
704: }
705: }
706:
1.44 www 707: # ---------------------------------------------------------------- Face to face
708:
709: sub facetoface {
710: my ($r,$stage)=@_;
711: unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
712: return;
713: }
1.46 www 714: # from query string
715: if ($ENV{'form.recname'}) { $ENV{'form.recuname'}=$ENV{'form.recname'}; }
716: if ($ENV{'form.recdom'}) { $ENV{'form.recdomain'}=$ENV{'form.recdom'}; }
717:
1.44 www 718: my $defdom=$ENV{'user.domain'};
1.46 www 719: # already filled in
1.44 www 720: if ($ENV{'form.recdomain'}) { $defdom=$ENV{'form.recdomain'}; }
1.46 www 721: # generate output
1.44 www 722: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
1.46 www 723: my $stdbrws = &Apache::loncommon::selectstudent_link
724: ('stdselect','recuname','recdomain');
1.44 www 725: $r->print(<<"ENDTREC");
1.46 www 726: <h3>User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course</h3>
727: <form method="post" action="/adm/email" name="stdselect">
1.44 www 728: <input type="hidden" name="recordftf" value="retrieve" />
729: <table>
730: <tr><td>Username:</td><td><input type=text size=12 name=recuname value="$ENV{'form.recuname'}"></td>
731: <td rowspan="2">
1.46 www 732: $stdbrws
1.44 www 733: <input type="submit" value="Retrieve discussion and message records"></td>
734: </tr>
735: <tr><td>Domain:</td>
736: <td>$domform</td></tr>
737: </table>
738: </form>
739: ENDTREC
740: if (($stage ne 'query') &&
741: ($ENV{'form.recdomain'}) && ($ENV{'form.recuname'})) {
742: chomp($ENV{'form.newrecord'});
743: if ($ENV{'form.newrecord'}) {
1.45 www 744: &user_normal_msg_raw(
745: $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
746: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
747: 'Record ['.$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}.']',
748: $ENV{'form.newrecord'});
1.44 www 749: }
1.46 www 750: $r->print('<h3>'.&Apache::loncommon::plainname($ENV{'form.recuname'},
751: $ENV{'form.recdomain'}).'</h3>');
1.45 www 752: &disfacetoface($r,$ENV{'form.recuname'},$ENV{'form.recdomain'});
1.44 www 753: $r->print(<<ENDRHEAD);
754: <form method="post" action="/adm/email">
755: <input name="recdomain" value="$ENV{'form.recdomain'}" type="hidden" />
756: <input name="recuname" value="$ENV{'form.recuname'}" type="hidden" />
757: ENDRHEAD
758: $r->print(<<ENDBFORM);
759: <hr />New Record (record is visible to course faculty and staff)<br />
760: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
1.45 www 761: <br />
762: <input type="hidden" name="recordftf" value="post" />
763: <input type="submit" value="Post this record" />
1.44 www 764: </form>
765: ENDBFORM
766: }
767: }
768:
1.13 www 769: # ===================================================================== Handler
770:
1.5 www 771: sub handler {
772: my $r=shift;
773:
774: # ----------------------------------------------------------- Set document type
775:
776: $r->content_type('text/html');
777: $r->send_http_header;
778:
779: return OK if $r->header_only;
780:
1.6 www 781: # --------------------------- Get query string for limited number of parameters
1.32 matthew 782: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
783: ['display','replyto','forward','markread','markdel','markunread',
1.44 www 784: 'sendreply','compose','sendmail','critical','recname','recdom',
785: 'recordftf']);
1.6 www 786:
1.40 www 787: # ------------------------------------------------------ They checked for email
788: &Apache::lonnet::put('email_status',{'recnewemail'=>0});
1.5 www 789: # --------------------------------------------------------------- Render Output
1.49 albertel 790: if (!$ENV{'form.display'}) {
791: $r->print('<html><head><title>EMail and Messaging</title>'.
792: &Apache::loncommon::studentbrowser_javascript().'</head>'.
793: &Apache::loncommon::bodytag('EMail and Messages'));
794: }
1.6 www 795: if ($ENV{'form.display'}) {
1.7 www 796: my $msgid=$ENV{'form.display'};
797: &statuschange($msgid,'read');
1.8 albertel 798: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7 www 799: my %content=&unpackagemsg($message{$msgid});
1.49 albertel 800: $r->print('<html><head><title>EMail and Messaging</title>');
801: if (defined($content{'baseurl'})) {
802: $r->print("<base href=\"http://$ENV{'SERVER_NAME'}/$content{'baseurl'}\" />");
803: }
804: $r->print(&Apache::loncommon::studentbrowser_javascript().
805: '</head>'.
806: &Apache::loncommon::bodytag('EMail and Messages'));
1.7 www 807: $r->print('<b>Subject:</b> '.$content{'subject'}.
1.37 www 808: '<br><b>From:</b> '.
809: &Apache::loncommon::aboutmewrapper(
810: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
811: $content{'sendername'},$content{'senderdomain'}).' ('.
812: $content{'sendername'}.' at '.
813: $content{'senderdomain'}.') '.
1.14 www 814: '<br><b>Time:</b> '.$content{'time'}.'<p>'.
815: '<table border=2><tr bgcolor="#FFFFAA"><td>Functions:</td>'.
816: '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).
817: '"><b>Reply</b></a></td>'.
1.15 www 818: '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).
1.14 www 819: '"><b>Forward</b></a></td>'.
1.15 www 820: '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).
821: '"><b>Mark Unread</b></a></td>'.
1.43 www 822: '<td><a href="/adm/email?markdel='.&Apache::lonnet::escape($msgid).
823: '"><b>Delete</b></a></td>'.
1.15 www 824: '<td><a href="/adm/email"><b>Display all Messages</b></a></td>'.
1.14 www 825: '</tr></table><p><pre>'.
1.36 www 826: &Apache::lontexconvert::msgtexconverted($content{'message'}).
827: '</pre><hr>'.$content{'citation'});
1.6 www 828: } elsif ($ENV{'form.replyto'}) {
1.13 www 829: &comprep($r,$ENV{'form.replyto'});
1.7 www 830: } elsif ($ENV{'form.sendreply'}) {
831: my $msgid=$ENV{'form.sendreply'};
1.8 albertel 832: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.52 www 833: my %content=&unpackagemsg($message{$msgid},1);
1.7 www 834: &statuschange($msgid,'replied');
1.24 www 835: if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) &&
1.12 www 836: (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
837: $r->print('Sending critical: '.
838: &user_crit_msg($content{'sendername'},
1.7 www 839: $content{'senderdomain'},
840: $ENV{'form.subject'},
1.24 www 841: $ENV{'form.message'},
842: $ENV{'form.sendbck'}));
1.12 www 843: } else {
844: $r->print('Sending: '.&user_normal_msg($content{'sendername'},
845: $content{'senderdomain'},
846: $ENV{'form.subject'},
847: $ENV{'form.message'}));
848: }
1.14 www 849: if ($ENV{'form.displayedcrit'}) {
850: &discrit($r);
851: } else {
852: &disall($r);
853: }
1.12 www 854: } elsif ($ENV{'form.confirm'}) {
1.28 harris41 855: foreach (keys %ENV) {
1.12 www 856: if ($_=~/^form\.rec\_(.*)$/) {
857: $r->print('<b>Confirming Receipt:</b> '.
858: &user_crit_received($1).'<br>');
1.13 www 859: }
860: if ($_=~/^form\.reprec\_(.*)$/) {
861: my $msgid=$1;
862: $r->print('<b>Confirming Receipt:</b> '.
863: &user_crit_received($msgid).'<br>');
864: &comprep($r,$msgid);
1.12 www 865: }
1.28 harris41 866: }
1.12 www 867: &discrit($r);
868: } elsif ($ENV{'form.critical'}) {
869: &discrit($r);
1.6 www 870: } elsif ($ENV{'form.forward'}) {
1.15 www 871: &compout($r,$ENV{'form.forward'});
1.14 www 872: } elsif ($ENV{'form.markread'}) {
873: } elsif ($ENV{'form.markdel'}) {
874: &statuschange($ENV{'form.markdel'},'deleted');
1.25 www 875: &disall($r);
876: } elsif ($ENV{'form.markeddel'}) {
877: my $total=0;
1.28 harris41 878: foreach (keys %ENV) {
1.25 www 879: if ($_=~/^form\.delmark_(.*)$/) {
880: &statuschange(&Apache::lonnet::unescape($1),'deleted');
881: $total++;
882: }
1.28 harris41 883: }
1.25 www 884: $r->print('Deleted '.$total.' message(s)<p>');
1.14 www 885: &disall($r);
886: } elsif ($ENV{'form.markunread'}) {
1.15 www 887: &statuschange($ENV{'form.markunread'},'new');
888: &disall($r);
1.11 www 889: } elsif ($ENV{'form.compose'}) {
1.17 www 890: &compout($r,'',$ENV{'form.compose'});
1.44 www 891: } elsif ($ENV{'form.recordftf'}) {
892: &facetoface($r,$ENV{'form.recordftf'});
1.11 www 893: } elsif ($ENV{'form.sendmail'}) {
1.16 www 894: my %content=();
895: undef %content;
896: if ($ENV{'form.forwid'}) {
897: my $msgid=$ENV{'form.forwid'};
898: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.52 www 899: %content=&unpackagemsg($message{$msgid},1);
1.16 www 900: &statuschange($msgid,'forwarded');
901: $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
902: $content{'message'};
903: }
1.18 www 904: my %toaddr=();
905: undef %toaddr;
906: if ($ENV{'form.sendmode'} eq 'group') {
1.28 harris41 907: foreach (keys %ENV) {
1.19 www 908: if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
1.22 www 909: $toaddr{$1}='';
1.18 www 910: }
1.28 harris41 911: }
1.22 www 912: } elsif ($ENV{'form.sendmode'} eq 'upload') {
1.28 harris41 913: foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) {
1.22 www 914: my ($rec,$txt)=split(/\s*\:\s*/,$_);
915: if ($txt) {
916: $rec=~s/\@/\:/;
917: $toaddr{$rec}.=$txt."\n";
918: }
1.28 harris41 919: }
1.18 www 920: } else {
1.22 www 921: $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
1.20 www 922: }
923: if ($ENV{'form.additionalrec'}) {
1.28 harris41 924: foreach (split(/\,/,$ENV{'form.additionalrec'})) {
1.20 www 925: my ($auname,$audom)=split(/\@/,$_);
1.22 www 926: $toaddr{$auname.':'.$audom}='';
1.28 harris41 927: }
1.18 www 928: }
1.28 harris41 929: foreach (keys %toaddr) {
1.18 www 930: my ($recuname,$recdomain)=split(/\:/,$_);
1.22 www 931: my $msgtxt=$ENV{'form.message'};
932: if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }
1.24 www 933: if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) &&
1.16 www 934: (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
935: $r->print('Sending critical: '.
1.18 www 936: &user_crit_msg($recuname,$recdomain,
1.16 www 937: $ENV{'form.subject'},
1.22 www 938: $msgtxt,
1.24 www 939: $ENV{'form.sendbck'}));
1.16 www 940: } else {
1.18 www 941: $r->print('Sending: '.&user_normal_msg($recuname,$recdomain,
1.16 www 942: $ENV{'form.subject'},
1.22 www 943: $msgtxt,
1.16 www 944: $content{'citation'}));
945: }
1.18 www 946: $r->print('<br>');
1.28 harris41 947: }
1.16 www 948: if ($ENV{'form.displayedcrit'}) {
949: &discrit($r);
950: } else {
951: &disall($r);
952: }
1.6 www 953: } else {
1.14 www 954: &disall($r);
1.6 www 955: }
1.5 www 956: $r->print('</body></html>');
957: return OK;
958:
959: }
1.2 www 960: # ================================================= Main program, reset counter
961:
1.27 www 962: BEGIN {
1.2 www 963: $msgcount=0;
1.1 www 964: }
965:
966: 1;
967: __END__
968:
969:
970:
971:
972:
973:
974:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>