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