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