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