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