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