1: # The LearningOnline Network with CAPA
2: # Routines for messaging
3: #
4: # $Id: lonmsg.pm,v 1.168 2006/01/05 19:52:52 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:
30: package Apache::lonmsg;
31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::lonmsg: supports internal messaging
37:
38: =head1 SYNOPSIS
39:
40: lonmsg provides routines for sending messages, receiving messages, and
41: a handler to allow users to read, send, and delete messages.
42:
43: =head1 OVERVIEW
44:
45: =head2 Messaging Overview
46:
47: X<messages>LON-CAPA provides an internal messaging system similar to
48: email, but customized for LON-CAPA's usage. LON-CAPA implements its
49: own messaging system, rather then building on top of email, because of
50: the features LON-CAPA messages can offer that conventional e-mail can
51: not:
52:
53: =over 4
54:
55: =item * B<Critical messages>: A message the recipient B<must>
56: acknowlegde receipt of before they are allowed to continue using the
57: system, preventing a user from claiming they never got a message
58:
59: =item * B<Receipts>: LON-CAPA can reliably send reciepts informing the
60: sender that it has been read; again, useful for preventing students
61: from claiming they did not see a message. (While conventional e-mail
62: has some reciept support, it's sporadic, e-mail client-specific, and
63: generally the receiver can opt to not send one, making it useless in
64: this case.)
65:
66: =item * B<Context>: LON-CAPA knows about the sender, such as where
67: they are in a course. When a student mails an instructor asking for
68: help on the problem, the instructor receives not just the student's
69: question, but all submissions the student has made up to that point,
70: the user's rendering of the problem, and the complete view the student
71: saw of the resource, including discussion up to that point. Finally,
72: the instructor is reading all of this inside of LON-CAPA, not their
73: email program, so they have full access to LON-CAPA's grading
74: interface, or other features they may wish to use in response to the
75: student's query.
76:
77: =item * B<Blocking>: LON-CAPA can block display of e-mails that are
78: sent to a student during an online exam. A course coordinator or
79: instructor can set an open and close date/time for scheduled online
80: exams in a course. If a user uses the LON-CAPA internal messaging
81: system to display e-mails during the scheduled blocking event,
82: display of all e-mail sent during the blocking period will be
83: suppressed, and a message of explanation, including details of the
84: currently active blocking periods will be displayed instead. A user
85: who has a course coordinator or instructor role in a course will be
86: unaffected by any blocking periods for the course, unless the user
87: also has a student role in the course, AND has selected the student role.
88:
89: =back
90:
91: Users can ask LON-CAPA to forward messages to conventional e-mail
92: addresses on their B<PREF> screen, but generally, LON-CAPA messages
93: are much more useful than traditional email can be made to be, even
94: with HTML support.
95:
96: Right now, this document will cover just how to send a message, since
97: it is likely you will not need to programmatically read messages,
98: since lonmsg already implements that functionality.
99:
100: The routines used to package messages and unpackage messages are not
101: only used by lonmsg when creating/extracting messages for LON-CAPA's
102: internal messaging system, but also by lonnotify.pm which is available
103: for use by Domain Coordinators to broadcast standard e-mail to specified
104: users in their domain. The XML packaging used in the two cases is very
105: similar. The differences are the use of <recuser>$uname</recuser> and
106: <recdomain>$udom</recdomain> in stored internal messages, compared
107: with <recipient username="$uname:$udom">$email</recipient> in stored
108: Domain Coordinator e-mail for the storage of information about
109: recipients of the message/e-mail.
110:
111: =head1 FUNCTIONS
112:
113: =over 4
114:
115: =cut
116:
117: use strict;
118: use Apache::lonnet;
119: use vars qw($msgcount);
120: use HTML::TokeParser();
121: use Apache::Constants qw(:common);
122: use Apache::loncommon();
123: use Apache::lontexconvert();
124: use HTML::Entities();
125: use Mail::Send;
126: use Apache::lonlocal;
127: use Apache::loncommunicate;
128: use Apache::lonfeedback;
129: use Apache::lonrss();
130:
131: # Querystring component with sorting type
132: my $sqs;
133: my $startdis;
134: my $interdis;
135:
136: # ===================================================================== Package
137:
138: sub packagemsg {
139: my ($subject,$message,$citation,$baseurl,$attachmenturl,
140: $recuser,$recdomain,$msgid,$type)=@_;
141: $message =&HTML::Entities::encode($message,'<>&"');
142: $citation=&HTML::Entities::encode($citation,'<>&"');
143: $subject =&HTML::Entities::encode($subject,'<>&"');
144: #remove machine specification
145: $baseurl =~ s|^http://[^/]+/|/|;
146: $baseurl =&HTML::Entities::encode($baseurl,'<>&"');
147: #remove machine specification
148: $attachmenturl =~ s|^http://[^/]+/|/|;
149: $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
150: my $course_context;
151: if (defined($env{'form.replyid'})) {
152: my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
153: split(/\:/,&Apache::lonnet::unescape($env{'form.replyid'}));
154: $course_context = $origcid;
155: }
156: foreach my $key (keys(%env)) {
157: if ($key=~/^form\.(rep)?rec\_(.*)$/) {
158: my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =
159: split(/\:/,&Apache::lonnet::unescape($2));
160: $course_context = $origcid;
161: last;
162: }
163: }
164: unless(defined($course_context)) {
165: $course_context = $env{'request.course.id'};
166: }
167: my $now=time;
168: $msgcount++;
169: unless(defined($msgid)) {
170: $msgid = &buildmsgid($now,$subject,$env{'user.name'},$env{'user.domain'},
171: $msgcount,$course_context,$$);
172: }
173: my $result='<sendername>'.$env{'user.name'}.'</sendername>'.
174: '<senderdomain>'.$env{'user.domain'}.'</senderdomain>'.
175: '<subject>'.$subject.'</subject>'.
176: '<time>'.&Apache::lonlocal::locallocaltime($now).'</time>'.
177: '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
178: '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
179: '<client>'.$ENV{'REMOTE_ADDR'}.'</client>'.
180: '<browsertype>'.$env{'browser.type'}.'</browsertype>'.
181: '<browseros>'.$env{'browser.os'}.'</browseros>'.
182: '<browserversion>'.$env{'browser.version'}.'</browserversion>'.
183: '<browsermathml>'.$env{'browser.mathml'}.'</browsermathml>'.
184: '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
185: '<courseid>'.$course_context.'</courseid>'.
186: '<coursesec>'.$env{'request.course.sec'}.'</coursesec>'.
187: '<role>'.$env{'request.role'}.'</role>'.
188: '<resource>'.$env{'request.filename'}.'</resource>'.
189: '<msgid>'.$msgid.'</msgid>';
190: if (ref($recuser) eq 'ARRAY') {
191: for (my $i=0; $i<@{$recuser}; $i++) {
192: if ($type eq 'dcmail') {
193: my ($username,$email) = split(/:/,$$recuser[$i]);
194: $username = &Apache::lonnet::unescape($username);
195: $email = &Apache::lonnet::unescape($email);
196: $username = &HTML::Entities::encode($username,'<>&"');
197: $email = &HTML::Entities::encode($email,'<>&"');
198: $result .= '<recipient username="'.$username.'">'.
199: $email.'</recipient>';
200: } else {
201: $result .= '<recuser>'.$$recuser[$i].'</recuser>'.
202: '<recdomain>'.$$recdomain[$i].'</recdomain>';
203: }
204: }
205: } else {
206: $result .= '<recuser>'.$recuser.'</recuser>'.
207: '<recdomain>'.$recdomain.'</recdomain>';
208: }
209: $result .= '<message>'.$message.'</message>';
210: if (defined($citation)) {
211: $result.='<citation>'.$citation.'</citation>';
212: }
213: if (defined($baseurl)) {
214: $result.= '<baseurl>'.$baseurl.'</baseurl>';
215: }
216: if (defined($attachmenturl)) {
217: $result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>';
218: }
219: return $msgid,$result;
220: }
221:
222: # ================================================== Unpack message into a hash
223:
224: sub unpackagemsg {
225: my ($message,$notoken)=@_;
226: my %content=();
227: my $parser=HTML::TokeParser->new(\$message);
228: my $token;
229: while ($token=$parser->get_token) {
230: if ($token->[0] eq 'S') {
231: my $entry=$token->[1];
232: my $value=$parser->get_text('/'.$entry);
233: if (($entry eq 'recuser') || ($entry eq 'recdomain')) {
234: push(@{$content{$entry}},$value);
235: } elsif ($entry eq 'recipient') {
236: my $username = $token->[2]{'username'};
237: $username = &HTML::Entities::decode($username,'<>&"');
238: $content{$entry}{$username} = $value;
239: } else {
240: $content{$entry}=$value;
241: }
242: }
243: }
244: if (!exists($content{'recuser'})) { $content{'recuser'} = []; }
245: if ($content{'attachmenturl'}) {
246: my ($fname)=($content{'attachmenturl'}=~m|/([^/]+)$|);
247: if ($notoken) {
248: $content{'message'}.='<p>'.&mt('Attachment').': <tt>'.$fname.'</tt>';
249: } else {
250: &Apache::lonnet::allowuploaded('/adm/msg',
251: $content{'attachmenturl'});
252: $content{'message'}.='<p>'.&mt('Attachment').
253: ': <a href="'.$content{'attachmenturl'}.'"><tt>'.
254: $fname.'</tt></a>';
255: }
256: }
257: return %content;
258: }
259:
260: # ======================================================= Get info out of msgid
261:
262: sub buildmsgid {
263: my ($now,$subject,$uname,$udom,$msgcount,$course_context,$pid) = @_;
264: $subject=&Apache::lonnet::escape($subject);
265: return(&Apache::lonnet::escape($now.':'.$subject.':'.$uname.':'.
266: $udom.':'.$msgcount.':'.$course_context.':'.$pid));
267: }
268:
269: sub unpackmsgid {
270: my ($msgid,$folder,$skipstatus)=@_;
271: $msgid=&Apache::lonnet::unescape($msgid);
272: my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid,
273: $processid)=split(/\:/,&Apache::lonnet::unescape($msgid));
274: if (!defined($processid)) { $fromcid = ''; }
275: my %status=();
276: unless ($skipstatus) {
277: my $suffix=&foldersuffix($folder);
278: %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
279: if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
280: unless ($status{$msgid}) { $status{$msgid}='new'; }
281: }
282: return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid);
283: }
284:
285:
286: sub sendemail {
287: my ($to,$subject,$body)=@_;
288: $body=
289: "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n".
290: "*** ".&mt('Please do not reply to this address.')."\n\n".$body;
291: my $msg = new Mail::Send;
292: $msg->to($to);
293: $msg->subject('[LON-CAPA] '.$subject);
294: if (my $fh = $msg->open()) {
295: print $fh $body;
296: $fh->close;
297: }
298: }
299:
300: # ==================================================== Send notification emails
301:
302: sub sendnotification {
303: my ($to,$touname,$toudom,$subj,$crit,$text)=@_;
304: my $sender=$env{'environment.firstname'}.' '.$env{'environment.lastname'};
305: unless ($sender=~/\w/) {
306: $sender=$env{'user.name'}.'@'.$env{'user.domain'};
307: }
308: my $critical=($crit?' critical':'');
309: $text=~s/\<\;/\</gs;
310: $text=~s/\>\;/\>/gs;
311: $text=~s/\<\/*[^\>]+\>//gs;
312: my $url='http://'.
313: $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}.
314: '/adm/email?username='.$touname.'&domain='.$toudom;
315: my $body=(<<ENDMSG);
316: You received a$critical message from $sender in LON-CAPA. The subject is
317:
318: $subj
319:
320: === Excerpt ============================================================
321: $text
322: ========================================================================
323:
324: Use
325:
326: $url
327:
328: to access the full message.
329: ENDMSG
330: &sendemail($to,'New'.$critical.' message from '.$sender,$body);
331: }
332: # ============================================================= Check for email
333:
334: sub newmail {
335: if ((time-$env{'user.mailcheck.time'})>300) {
336: my %what=&Apache::lonnet::get('email_status',['recnewemail']);
337: &Apache::lonnet::appenv('user.mailcheck.time'=>time);
338: if ($what{'recnewemail'}>0) { return 1; }
339: }
340: return 0;
341: }
342:
343: # =============================== Automated message to the author of a resource
344:
345: =pod
346:
347: =item * B<author_res_msg($filename, $message)>: Sends message $message to the owner
348: of the resource with the URI $filename.
349:
350: =cut
351:
352: sub author_res_msg {
353: my ($filename,$message)=@_;
354: unless ($message) { return 'empty'; }
355: $filename=&Apache::lonnet::declutter($filename);
356: my ($domain,$author,@dummy)=split(/\//,$filename);
357: my $homeserver=&Apache::lonnet::homeserver($author,$domain);
358: if ($homeserver ne 'no_host') {
359: my $id=unpack("%32C*",$message);
360: my $msgid;
361: ($msgid,$message)=&packagemsg($filename,$message);
362: return &Apache::lonnet::reply('put:'.$domain.':'.$author.
363: ':nohist_res_msgs:'.
364: &Apache::lonnet::escape($filename.'_'.$id).'='.
365: &Apache::lonnet::escape($message),$homeserver);
366: }
367: return 'no_host';
368: }
369:
370: # =========================================== Retrieve author resource messages
371:
372: sub retrieve_author_res_msg {
373: my $url=shift;
374: $url=&Apache::lonnet::declutter($url);
375: my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
376: my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$domain,$author);
377: my $msgs='';
378: foreach (keys %errormsgs) {
379: if ($_=~/^\Q$url\E\_\d+$/) {
380: my %content=&unpackagemsg($errormsgs{$_});
381: $msgs.='<p><img src="/adm/lonMisc/bomb.gif" /><b>'.
382: $content{'time'}.'</b>: '.$content{'message'}.
383: '<br /></p>';
384: }
385: }
386: return $msgs;
387: }
388:
389:
390: # =============================== Delete all author messages related to one URL
391:
392: sub del_url_author_res_msg {
393: my $url=shift;
394: $url=&Apache::lonnet::declutter($url);
395: my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
396: my @delmsgs=();
397: foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
398: if ($_=~/^\Q$url\E\_\d+$/) {
399: push (@delmsgs,$_);
400: }
401: }
402: return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
403: }
404: # =================================== Clear out all author messages in URL path
405:
406: sub clear_author_res_msg {
407: my $url=shift;
408: $url=&Apache::lonnet::declutter($url);
409: my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
410: my @delmsgs=();
411: foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
412: if ($_=~/^\Q$url\E/) {
413: push (@delmsgs,$_);
414: }
415: }
416: return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
417: }
418: # ================= Return hash with URLs for which there is a resource message
419:
420: sub all_url_author_res_msg {
421: my ($author,$domain)=@_;
422: my %returnhash=();
423: foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
424: $_=~/^(.+)\_\d+/;
425: $returnhash{$1}=1;
426: }
427: return %returnhash;
428: }
429:
430: # ================================================== Critical message to a user
431:
432: sub user_crit_msg_raw {
433: my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
434: # Check if allowed missing
435: my $status='';
436: my $msgid='undefined';
437: unless (($message)&&($user)&&($domain)) { $status='empty'; };
438: my $text=$message;
439: my $homeserver=&Apache::lonnet::homeserver($user,$domain);
440: if ($homeserver ne 'no_host') {
441: ($msgid,$message)=&packagemsg($subject,$message);
442: if ($sendback) { $message.='<sendback>true</sendback>'; }
443: $status=&Apache::lonnet::critical(
444: 'put:'.$domain.':'.$user.':critical:'.
445: &Apache::lonnet::escape($msgid).'='.
446: &Apache::lonnet::escape($message),$homeserver);
447: if (defined($sentmessage)) {
448: $$sentmessage = $message;
449: }
450: } else {
451: $status='no_host';
452: }
453: # Notifications
454: my %userenv = &Apache::lonnet::get('environment',['critnotification',
455: 'permanentemail'],
456: $domain,$user);
457: if ($userenv{'critnotification'}) {
458: &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1,
459: $text);
460: }
461: if ($toperm && $userenv{'permanentemail'}) {
462: &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,1,
463: $text);
464: }
465: # Log this
466: &Apache::lonnet::logthis(
467: 'Sending critical email '.$msgid.
468: ', log status: '.
469: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
470: $env{'user.home'},
471: 'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
472: .$status));
473: return $status;
474: }
475:
476: # New routine that respects "forward" and calls old routine
477:
478: =pod
479:
480: =item * B<user_crit_msg($user, $domain, $subject, $message, $sendback)>: Sends
481: a critical message $message to the $user at $domain. If $sendback is true,
482: a reciept will be sent to the current user when $user recieves the message.
483:
484: =cut
485:
486: sub user_crit_msg {
487: my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
488: my $status='';
489: my %userenv = &Apache::lonnet::get('environment',['msgforward'],
490: $domain,$user);
491: my $msgforward=$userenv{'msgforward'};
492: if ($msgforward) {
493: foreach (split(/\,/,$msgforward)) {
494: my ($forwuser,$forwdomain)=split(/\:/,$_);
495: $status.=
496: &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
497: $sendback,$toperm,$sentmessage).' ';
498: }
499: } else {
500: $status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage);
501: }
502: return $status;
503: }
504:
505: # =================================================== Critical message received
506:
507: sub user_crit_received {
508: my $msgid=shift;
509: my %message=&Apache::lonnet::get('critical',[$msgid]);
510: my %contents=&unpackagemsg($message{$msgid},1);
511: my $status='rec: '.($contents{'sendback'}?
512: &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
513: &mt('Receipt').': '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.', '.$contents{'subject'},
514: &mt('User').' '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.
515: ' acknowledged receipt of message'."\n".' "'.
516: $contents{'subject'}.'"'."\n".&mt('dated').' '.
517: $contents{'time'}.".\n"
518: ):'no msg req');
519: $status.=' trans: '.
520: &Apache::lonnet::put(
521: 'nohist_email',{$contents{'msgid'} => $message{$msgid}});
522: $status.=' del: '.
523: &Apache::lonnet::del('critical',[$contents{'msgid'}]);
524: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
525: $env{'user.home'},'Received critical message '.
526: $contents{'msgid'}.
527: ', '.$status);
528: return $status;
529: }
530:
531: # ======================================================== Normal communication
532:
533: sub user_normal_msg_raw {
534: my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
535: $toperm,$currid,$newid,$sentmessage)=@_;
536: # Check if allowed missing
537: my $status='';
538: my $msgid='undefined';
539: my $text=$message;
540: unless (($message)&&($user)&&($domain)) { $status='empty'; };
541: my $homeserver=&Apache::lonnet::homeserver($user,$domain);
542: if ($homeserver ne 'no_host') {
543: ($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl,
544: $attachmenturl,$user,$domain,$currid);
545: # Store in user folder
546: $status=&Apache::lonnet::critical(
547: 'put:'.$domain.':'.$user.':nohist_email:'.
548: &Apache::lonnet::escape($msgid).'='.
549: &Apache::lonnet::escape($message),$homeserver);
550: # Save new message received time
551: &Apache::lonnet::put
552: ('email_status',{'recnewemail'=>time},$domain,$user);
553: # Into sent-mail folder unless a broadcast message or critical message
554: unless (($env{'request.course.id'}) &&
555: (($env{'form.sendmode'} eq 'group') ||
556: (($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
557: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})))) {
558: $status .= &store_sent_mail($msgid,$message);
559: }
560: } else {
561: $status='no_host';
562: }
563: if (defined($newid)) {
564: $$newid = $msgid;
565: }
566: if (defined($sentmessage)) {
567: $$sentmessage = $message;
568: }
569:
570: # Notifications
571: my %userenv = &Apache::lonnet::get('environment',['notification',
572: 'permanentemail'],
573: $domain,$user);
574: if ($userenv{'notification'}) {
575: &sendnotification($userenv{'notification'},$user,$domain,$subject,0,
576: $text);
577: }
578: if ($toperm && $userenv{'permanentemail'}) {
579: &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,0,
580: $text);
581: }
582: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
583: $env{'user.home'},
584: 'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
585: return $status;
586: }
587:
588: # New routine that respects "forward" and calls old routine
589:
590: =pod
591:
592: =item * B<user_normal_msg($user, $domain, $subject, $message,
593: $citation, $baseurl, $attachmenturl)>: Sends a message to the
594: $user at $domain, with subject $subject and message $message.
595:
596: =cut
597:
598: sub user_normal_msg {
599: my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
600: $toperm,$sentmessage)=@_;
601: my $status='';
602: my %userenv = &Apache::lonnet::get('environment',['msgforward'],
603: $domain,$user);
604: my $msgforward=$userenv{'msgforward'};
605: if ($msgforward) {
606: foreach (split(/\,/,$msgforward)) {
607: my ($forwuser,$forwdomain)=split(/\:/,$_);
608: $status.=
609: &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
610: $citation,$baseurl,$attachmenturl,$toperm,undef,undef,$sentmessage).' ';
611: }
612: } else {
613: $status=&user_normal_msg_raw($user,$domain,$subject,$message,
614: $citation,$baseurl,$attachmenturl,$toperm,undef,undef,$sentmessage);
615: }
616: return $status;
617: }
618:
619: sub store_sent_mail {
620: my ($msgid,$message) = @_;
621: my $status =' '.&Apache::lonnet::critical(
622: 'put:'.$env{'user.domain'}.':'.$env{'user.name'}.
623: ':nohist_email_sent:'.
624: &Apache::lonnet::escape($msgid).'='.
625: &Apache::lonnet::escape($message),$env{'user.home'});
626: return $status;
627: }
628:
629: # ============================================================ List all folders
630:
631: sub folderlist {
632: my $folder=shift;
633: my @allfolders=&Apache::lonnet::getkeys('email_folders');
634: if ($allfolders[0]=~/^error:/) { @allfolders=(); }
635: return '<form method="post" action="/adm/email">'.
636: &mt('Folder').': '.
637: &Apache::loncommon::select_form($folder,'folder',
638: ('' => &mt('INBOX'),'trash' => &mt('TRASH'),
639: 'new' => &mt('New Messages Only'),
640: 'critical' => &mt('Critical'),
641: 'sent' => &mt('Sent Messages'),
642: map { $_ => $_ } @allfolders)).
643: ' '.&mt('Show').
644: '<select name="interdis">'.
645: join("\n",map { '<option value="'.$_.'"'.
646: ($_==$interdis?' selected="selected"':'').'>'.$_.'</option>' }
647: (10,20,50,100,200)).'</select>'.
648: '<input type="submit" value="'.&mt('View Folder').'" /><br />'.
649: '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" />'.
650: ($folder=~/^(new|critical)/?'</form>':'');
651: }
652:
653: sub scrollbuttons {
654: my ($start,$maxdis,$first,$finish,$total)=@_;
655: unless ($total>0) { return ''; }
656: $start++; $maxdis++;$first++;$finish++;
657: return
658: &mt('Page').': '.
659: '<input type="submit" name="firstview" value="'.&mt('First').'" />'.
660: '<input type="submit" name="prevview" value="'.&mt('Previous').'" />'.
661: '<input type="text" size="5" name="startdis" value="'.$start.'" onChange="this.form.submit()" /> of '.$maxdis.
662: '<input type="submit" name="nextview" value="'.&mt('Next').'" />'.
663: '<input type="submit" name="lastview" value="'.&mt('Last').'" /><br />'.
664: &mt('Showing messages [_1] through [_2] of [_3]',$first,$finish,$total).'</form>';
665: }
666:
667: # =============================================================== Folder suffix
668:
669: sub foldersuffix {
670: my $folder=shift;
671: unless ($folder) { return ''; }
672: return '_'.&Apache::lonnet::escape($folder);
673: }
674:
675: # =============================================================== Status Change
676:
677: sub statuschange {
678: my ($msgid,$newstatus,$folder)=@_;
679: my $suffix=&foldersuffix($folder);
680: my %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
681: if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
682: unless ($status{$msgid}) { $status{$msgid}='new'; }
683: unless (($status{$msgid} eq 'replied') ||
684: ($status{$msgid} eq 'forwarded')) {
685: &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
686: }
687: if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
688: &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
689: }
690: if ($newstatus eq 'deleted') {
691: &movemsg(&Apache::lonnet::unescape($msgid),$folder,'trash');
692: }
693: }
694:
695: # ============================================================= Make new folder
696:
697: sub makefolder {
698: my ($newfolder)=@_;
699: if (($newfolder eq 'sent')
700: || ($newfolder eq 'critical')
701: || ($newfolder eq 'trash')
702: || ($newfolder eq 'new')) { return; }
703: &Apache::lonnet::put('email_folders',{$newfolder => time});
704: }
705:
706: # ======================================================== Move between folders
707:
708: sub movemsg {
709: my ($msgid,$srcfolder,$trgfolder)=@_;
710: if ($srcfolder eq 'new') { $srcfolder=''; }
711: my $srcsuffix=&foldersuffix($srcfolder);
712: my $trgsuffix=&foldersuffix($trgfolder);
713:
714: # Copy message
715: my %message=&Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid]);
716: &Apache::lonnet::put('nohist_email'.$trgsuffix,{$msgid => $message{$msgid}});
717:
718: # Copy status
719: unless ($trgfolder eq 'trash') {
720: my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]);
721: &Apache::lonnet::put('email_status'.$trgsuffix,{$msgid => $status{$msgid}});
722: }
723: # Delete orginals
724: &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]);
725: &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]);
726: }
727:
728: # ======================================================= Display a course list
729:
730: sub discourse {
731: my $r=shift;
732: my $classlist = &Apache::loncoursedata::get_classlist();
733: my $now=time;
734: my %lt=&Apache::lonlocal::texthash('cfa' => 'Check All',
735: 'cfs' => 'Check Section/Group',
736: 'cfn' => 'Uncheck All');
737: $r->print(<<ENDDISHEADER);
738: <input type="hidden" name="sendmode" value="group" />
739: <script>
740: function checkall() {
741: for (i=0; i<document.forms.compemail.elements.length; i++) {
742: if
743: (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
744: document.forms.compemail.elements[i].checked=true;
745: }
746: }
747: }
748:
749: function checksec() {
750: for (i=0; i<document.forms.compemail.elements.length; i++) {
751: if
752: (document.forms.compemail.elements[i].name.indexOf
753: ('send_to_&&&'+document.forms.compemail.chksec.value)==0) {
754: document.forms.compemail.elements[i].checked=true;
755: }
756: }
757: }
758:
759: function uncheckall() {
760: for (i=0; i<document.forms.compemail.elements.length; i++) {
761: if
762: (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
763: document.forms.compemail.elements[i].checked=false;
764: }
765: }
766: }
767: </script>
768: <input type="button" onClick="checkall()" value="$lt{'cfa'}" />
769: <input type="button" onClick="checksec()" value="$lt{'cfs'}" />
770: <input type="text" size="5" name="chksec" />
771: <input type="button" onClick="uncheckall()" value="$lt{'cfn'}" />
772: <p>
773: ENDDISHEADER
774: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
775: $r->print('<table>');
776: foreach my $role (sort keys %coursepersonnel) {
777: foreach (split(/\,/,$coursepersonnel{$role})) {
778: my ($puname,$pudom)=split(/\:/,$_);
779: $r->print('<tr><td><label>'.
780: '<input type="checkbox" name="send_to_&&&&&&_'.
781: $puname.':'.$pudom.'" /> '.
782: &Apache::loncommon::plainname($puname,$pudom).
783: '</label></td>'.
784: '<td>('.$_.'),</td><td><i>'.$role.'</i></td></tr>');
785: }
786: }
787: $r->print('</table><table>');
788: my $sort = sub {
789: my $aname=lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]);
790: if (!$aname) { $aname=$a; }
791: my $bname=lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]);
792: if (!$bname) { $bname=$b; }
793: return $aname cmp $bname;
794: };
795: foreach my $student (sort $sort (keys(%{$classlist}))) {
796: my $info=$classlist->{$student};
797: my ($sname,$sdom,$status,$fullname,$section) =
798: (@{$info}[&Apache::loncoursedata::CL_SNAME(),
799: &Apache::loncoursedata::CL_SDOM(),
800: &Apache::loncoursedata::CL_STATUS(),
801: &Apache::loncoursedata::CL_FULLNAME(),
802: &Apache::loncoursedata::CL_SECTION()]);
803: next if ($status ne 'Active');
804: next if ($env{'request.course.sec'} &&
805: $section ne $env{'request.course.sec'});
806: my $key = 'send_to_&&&'.$section.'&&&_'.$student;
807: if (! defined($fullname) || $fullname eq '') { $fullname = $sname; }
808: $r->print('<tr><td><label>'.
809: qq{<input type="checkbox" name="$key" />}.(' 'x2).
810: $fullname.'</label></td><td>'.$sname.'@'.$sdom.'</td><td>'.$section.
811: '</td></tr>');
812: }
813: $r->print('</table>');
814: }
815:
816: # ==================================================== Display Critical Message
817:
818: sub discrit {
819: my $r=shift;
820: my $header = '<h1><font color=red>'.&mt('Critical Messages').'</font></h1>'.
821: '<form action="/adm/email" method="POST">'.
822: '<input type="hidden" name="confirm" value="true" />';
823: my %what=&Apache::lonnet::dump('critical');
824: my $result = '';
825: foreach (sort keys %what) {
826: my %content=&unpackagemsg($what{$_});
827: next if ($content{'senderdomain'} eq '');
828: $result.='<hr />'.&mt('From').': <b>'.
829: &Apache::loncommon::aboutmewrapper(
830: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
831: $content{'sendername'}.'@'.
832: $content{'senderdomain'}.') '.$content{'time'}.
833: '<br />'.&mt('Subject').': '.$content{'subject'}.
834: '<br /><pre>'.
835: &Apache::lontexconvert::msgtexconverted($content{'message'}).
836: '</pre><small>'.
837: &mt('You have to confirm that you received this message. After confirmation, this message will be moved to your regular inbox').
838: '</small><br />'.
839: '<input type="submit" name="rec_'.$_.'" value="'.&mt('Confirm Receipt').'" />'.
840: '<input type="submit" name="reprec_'.$_.'" '.
841: 'value="'.&mt('Confirm Receipt and Reply').'" />';
842: }
843: # Check to see if there were any messages.
844: if ($result eq '') {
845: $result = "<h2>".&mt('You have no critical messages.')."</h2>".
846: '<a href="/adm/roles">'.&mt('Select a course').'</a><br />'.
847: '<a href="/adm/email">'.&mt('Communicate').'</a>';
848: } else {
849: $r->print($header);
850: }
851: $r->print($result);
852: $r->print('<input type="hidden" name="displayedcrit" value="true" /></form>');
853: }
854:
855: sub sortedmessages {
856: my ($blocked,$startblock,$endblock,$numblocked,$folder) = @_;
857: my $suffix=&foldersuffix($folder);
858: my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
859: #unpack the varibles and repack into temp for sorting
860: my @temp;
861: my %descriptions;
862: foreach (@messages) {
863: my $msgid=&Apache::lonnet::escape($_);
864: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)=
865: &Apache::lonmsg::unpackmsgid($msgid,$folder);
866: my $description = &get_course_desc($fromcid,\%descriptions);
867: my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
868: $msgid,$description);
869: # Check whether message was sent during blocking period.
870: if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
871: my $escid = &Apache::lonnet::unescape($msgid);
872: $$blocked{$escid} = 'ON';
873: $$numblocked ++;
874: } else {
875: push @temp ,\@temp1;
876: }
877: }
878: #default sort
879: @temp = sort {$a->[0] <=> $b->[0]} @temp;
880: if ($env{'form.sortedby'} eq "date"){
881: @temp = sort {$a->[0] <=> $b->[0]} @temp;
882: }
883: if ($env{'form.sortedby'} eq "revdate"){
884: @temp = sort {$b->[0] <=> $a->[0]} @temp;
885: }
886: if ($env{'form.sortedby'} eq "user"){
887: @temp = sort {lc($a->[2]) cmp lc($b->[2])} @temp;
888: }
889: if ($env{'form.sortedby'} eq "revuser"){
890: @temp = sort {lc($b->[2]) cmp lc($a->[2])} @temp;
891: }
892: if ($env{'form.sortedby'} eq "domain"){
893: @temp = sort {$a->[3] cmp $b->[3]} @temp;
894: }
895: if ($env{'form.sortedby'} eq "revdomain"){
896: @temp = sort {$b->[3] cmp $a->[3]} @temp;
897: }
898: if ($env{'form.sortedby'} eq "subject"){
899: @temp = sort {lc($a->[1]) cmp lc($b->[1])} @temp;
900: }
901: if ($env{'form.sortedby'} eq "revsubject"){
902: @temp = sort {lc($b->[1]) cmp lc($a->[1])} @temp;
903: }
904: if ($env{'form.sortedby'} eq "course"){
905: @temp = sort {lc($a->[6]) cmp lc($b->[6])} @temp;
906: }
907: if ($env{'form.sortedby'} eq "revcourse"){
908: @temp = sort {lc($b->[6]) cmp lc($a->[6])} @temp;
909: }
910: if ($env{'form.sortedby'} eq "status"){
911: @temp = sort {$a->[4] cmp $b->[4]} @temp;
912: }
913: if ($env{'form.sortedby'} eq "revstatus"){
914: @temp = sort {$b->[4] cmp $a->[4]} @temp;
915: }
916: return @temp;
917: }
918:
919: sub get_course_desc {
920: my ($fromcid,$descriptions) = @_;
921: my $description;
922: if (!$fromcid) {
923: return $description;
924: } else {
925: if (defined($$descriptions{$fromcid})) {
926: $description = $$descriptions{$fromcid};
927: } else {
928: if (defined($env{'course.'.$fromcid.'.description'})) {
929: $description = $env{'course.'.$fromcid.'.description'};
930: } else {
931: my %courseinfo=&Apache::lonnet::coursedescription($fromcid); $description = $courseinfo{'description'};
932: $description = $courseinfo{'description'};
933: }
934: $$descriptions{$fromcid} = $description;
935: }
936: return $description;
937: }
938: }
939:
940: # ======================================================== Display new messages
941:
942:
943: sub disnew {
944: my $r=shift;
945: my %lt=&Apache::lonlocal::texthash(
946: 'nm' => 'New Messages',
947: 'su' => 'Subject',
948: 'co' => 'Course',
949: 'da' => 'Date',
950: 'us' => 'Username',
951: 'op' => 'Open',
952: 'do' => 'Domain'
953: );
954: my @msgids = sort split(/\&/,&Apache::lonnet::reply
955: ('keys:'.$env{'user.domain'}.':'.
956: $env{'user.name'}.':nohist_email',
957: $env{'user.home'}));
958: my @newmsgs;
959: my %setters = ();
960: my $startblock = 0;
961: my $endblock = 0;
962: my %blocked = ();
963: my $numblocked = 0;
964: # Check for blocking of display because of scheduled online exams.
965: &blockcheck(\%setters,\$startblock,\$endblock);
966: my %descriptions;
967: foreach (@msgids) {
968: my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
969: &Apache::lonmsg::unpackmsgid($_);
970: if (defined($sendtime) && $sendtime!~/error/) {
971: my $description = &get_course_desc($fromcid,\%descriptions);
972: my $numsendtime = $sendtime;
973: $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
974: if ($status eq 'new') {
975: if ($numsendtime >= $startblock && ($numsendtime <= $endblock && $endblock > 0) ) {
976: $blocked{$_} = 'ON';
977: $numblocked ++;
978: } else {
979: push @newmsgs, {
980: msgid => $_,
981: sendtime => $sendtime,
982: shortsub => &Apache::lonnet::unescape($shortsubj),
983: from => $fromname,
984: fromdom => $fromdom,
985: course => $description
986: }
987: }
988: }
989: }
990: }
991: if ($#newmsgs >= 0) {
992: $r->print(<<TABLEHEAD);
993: <h2>$lt{'nm'}</h2>
994: <table border=2><tr><th> </th>
995: <th>$lt{'da'}</th><th>$lt{'us'}</th><th>$lt{'do'}</th><th>$lt{'su'}</th><th>$lt{'co'}</th></tr>
996: TABLEHEAD
997: foreach my $msg (@newmsgs) {
998: $r->print(<<"ENDLINK");
999: <tr class="new" bgcolor="#FFBB77" onMouseOver="javascript:style.backgroundColor='#DD9955'"
1000: onMouseOut="javascript:style.backgroundColor='#FFBB77'">
1001: <td><a href="/adm/email?dismode=new&display=$msg->{'msgid'}">$lt{'op'}</a></td>
1002: ENDLINK
1003: foreach ('sendtime','from','fromdom','shortsub','course') {
1004: $r->print("<td>$msg->{$_}</td>");
1005: }
1006: $r->print("</td></tr>");
1007: }
1008: $r->print('</table>'.&Apache::loncommon::endbodytag().'</html>');
1009: } elsif ($numblocked == 0) {
1010: $r->print("<h3>".&mt('You have no unread messages')."</h3>");
1011: }
1012: if ($numblocked > 0) {
1013: my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
1014: my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
1015: if ($numblocked == 1) {
1016: $r->print("<h3>".&mt('You have').' '.$numblocked.' '.&mt('blocked unread message').".</h3>");
1017: $r->print(&mt('This message is not viewable because').' ');
1018: } else {
1019: $r->print("<h3>".&mt('You have').' '.$numblocked.' '.&mt('blocked unread messages').".</h3>");
1020: $r->print(&mt('These').' '.$numblocked.' '.&mt('messages are not viewable because '));
1021: }
1022: $r->print(
1023: &mt('display of LON-CAPA messages sent to you by other students between').' '.$beginblock.' '.&mt('and').' '.$finishblock.' '.&mt('is currently being blocked because of online exams').'.');
1024: &build_block_table($r,$startblock,$endblock,\%setters);
1025: }
1026: }
1027:
1028:
1029: # ======================================================== Display all messages
1030:
1031: sub disall {
1032: my ($r,$folder)=@_;
1033: $r->print(&folderlist($folder));
1034: if ($folder eq 'new') {
1035: &disnew($r);
1036: } elsif ($folder eq 'critical') {
1037: &discrit($r);
1038: } else {
1039: &disfolder($r,$folder);
1040: }
1041: }
1042:
1043: # ============================================================ Display a folder
1044:
1045: sub disfolder {
1046: my ($r,$folder)=@_;
1047: my %blocked = ();
1048: my %setters = ();
1049: my $startblock;
1050: my $endblock;
1051: my $numblocked = 0;
1052: &blockcheck(\%setters,\$startblock,\$endblock);
1053: $r->print(<<ENDDISHEADER);
1054: <script>
1055: function checkall() {
1056: for (i=0; i<document.forms.disall.elements.length; i++) {
1057: if
1058: (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
1059: document.forms.disall.elements[i].checked=true;
1060: }
1061: }
1062: }
1063:
1064: function uncheckall() {
1065: for (i=0; i<document.forms.disall.elements.length; i++) {
1066: if
1067: (document.forms.disall.elements[i].name.indexOf('delmark_')==0) {
1068: document.forms.disall.elements[i].checked=false;
1069: }
1070: }
1071: }
1072: </script>
1073: ENDDISHEADER
1074: my $fsqs='&folder='.$folder;
1075: my @temp=sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder);
1076: my $totalnumber=$#temp+1;
1077: unless ($totalnumber>0) {
1078: $r->print('<h2>'.&mt('Empty Folder').'</h2>');
1079: return;
1080: }
1081: unless ($interdis) {
1082: $interdis=20;
1083: }
1084: my $number=int($totalnumber/$interdis);
1085: if (($startdis<0) || ($startdis>$number)) { $startdis=$number; }
1086: my $firstdis=$interdis*$startdis;
1087: if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; }
1088: my $lastdis=$firstdis+$interdis-1;
1089: if ($lastdis>$#temp) { $lastdis=$#temp; }
1090: $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber));
1091: $r->print('<form method="post" name="disall" action="/adm/email">'.
1092: '<table border=2><tr><th colspan="3"> </th><th>');
1093: if ($env{'form.sortedby'} eq "revdate") {
1094: $r->print('<a href = "?sortedby=date'.$fsqs.'">'.&mt('Date').'</a></th>');
1095: } else {
1096: $r->print('<a href = "?sortedby=revdate'.$fsqs.'">'.&mt('Date').'</a></th>');
1097: }
1098: $r->print('<th>');
1099: if ($env{'form.sortedby'} eq "revuser") {
1100: $r->print('<a href = "?sortedby=user'.$fsqs.'">'.&mt('Username').'</a>');
1101: } else {
1102: $r->print('<a href = "?sortedby=revuser'.$fsqs.'">'.&mt('Username').'</a>');
1103: }
1104: $r->print('</th><th>');
1105: if ($env{'form.sortedby'} eq "revdomain") {
1106: $r->print('<a href = "?sortedby=domain'.$fsqs.'">'.&mt('Domain').'</a>');
1107: } else {
1108: $r->print('<a href = "?sortedby=revdomain'.$fsqs.'">'.&mt('Domain').'</a>');
1109: }
1110: $r->print('</th><th>');
1111: if ($env{'form.sortedby'} eq "revsubject") {
1112: $r->print('<a href = "?sortedby=subject'.$fsqs.'">'.&mt('Subject').'</a>');
1113: } else {
1114: $r->print('<a href = "?sortedby=revsubject'.$fsqs.'">'.&mt('Subject').'</a>');
1115: }
1116: $r->print('</th><th>');
1117: if ($env{'form.sortedby'} eq "revcourse") {
1118: $r->print('<a href = "?sortedby=course'.$fsqs.'">'.&mt('Course').'</a>');
1119: } else {
1120: $r->print('<a href = "?sortedby=revcourse'.$fsqs.'">'.&mt('Course').'</a>');
1121: }
1122: $r->print('</th><th>');
1123: if ($env{'form.sortedby'} eq "revstatus") {
1124: $r->print('<a href = "?sortedby=status'.$fsqs.'">'.&mt('Status').'</a></th>');
1125: } else {
1126: $r->print('<a href = "?sortedby=revstatus'.$fsqs.'">'.&mt('Status').'</a></th>');
1127: }
1128: $r->print("</tr>\n");
1129: for (my $n=$firstdis;$n<=$lastdis;$n++) {
1130: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,$description)= @{$temp[$n]};
1131: if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
1132: if ($status eq 'new') {
1133: $r->print('<tr bgcolor="#FFBB77" onMouseOver="javascript:style.backgroundColor=\'#DD9955\'" onMouseOut="javascript:style.backgroundColor=\'#FFBB77\'">');
1134: } elsif ($status eq 'read') {
1135: $r->print('<tr bgcolor="#BBBB77" onMouseOver="javascript:style.backgroundColor=\'#999944\'" onMouseOut="javascript:style.backgroundColor=\'#BBBB77\'">');
1136: } elsif ($status eq 'replied') {
1137: $r->print('<tr bgcolor="#AAAA88" onMouseOver="javascript:style.backgroundColor=\'#888855\'" onMouseOut="javascript:style.backgroundColor=\'#AAAA88\'">');
1138: } else {
1139: $r->print('<tr bgcolor="#99BBBB" onMouseOver="javascript:style.backgroundColor=\'#669999\'" onMouseOut="javascript:style.backgroundColor=\'#99BBBB\'">');
1140: }
1141: $r->print('<td><input type="checkbox" name="delmark_'.$origID.'" /></td><td><a href="/adm/email?display='.$origID.$sqs.
1142: '">'.&mt('Open').'</a></td><td>'.
1143: ($folder ne 'trash'?'<a href="/adm/email?markdel='.$origID.$sqs.
1144: '">'.&mt('Delete'):' ').'</a></td>'.
1145: '<td>'.&Apache::lonlocal::locallocaltime($sendtime).'</td><td>'.
1146: $fromname.'</td><td>'.$fromdomain.'</td><td>'.
1147: &Apache::lonnet::unescape($shortsubj).'</td><td>'.
1148: $description.'</td><td>'.$status.'</td></tr>'."\n");
1149: } elsif ($status eq 'deleted') {
1150: # purge
1151: &movemsg(&Apache::lonnet::unescape($origID),$folder,'trash');
1152: }
1153: }
1154: $r->print("</table>\n<p>".
1155: '<a href="javascript:checkall()">'.&mt('Check All').'</a> '.
1156: '<a href="javascript:uncheckall()">'.&mt('Uncheck All').'</a></p>'.
1157: '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" />');
1158: if ($folder ne 'trash') {
1159: $r->print(
1160: '<p><input type="submit" name="markeddel" value="'.&mt('Delete Checked').'" /></p>');
1161: }
1162: $r->print('<p><input type="submit" name="markedmove" value="'.&mt('Move Checked to Folder').'" />');
1163: my @allfolders=&Apache::lonnet::getkeys('email_folders');
1164: if ($allfolders[0]=~/^error:/) { @allfolders=(); }
1165: $r->print(
1166: &Apache::loncommon::select_form('','movetofolder',
1167: ( map { $_ => $_ } @allfolders))
1168: );
1169: my $postedstartdis=$startdis+1;
1170: $r->print('<input type="hidden" name="folder" value="'.$folder.'" /><input type="hidden" name="startdis" value="'.$postedstartdis.'" /><input type="hidden" name="interdis" value="'.$env{'form.interdis'}.'" /></form>');
1171: if ($numblocked > 0) {
1172: my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
1173: my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
1174: $r->print('<br /><br />'.
1175: $numblocked.' '.&mt('message(s) is/are not viewable because display of LON-CAPA messages sent to you by other students between').' '.$beginblock.' '.&mt('and').' '.$finishblock.' '.&mt('is currently being blocked because of online exams.'));
1176: &build_block_table($r,$startblock,$endblock,\%setters);
1177: }
1178: }
1179:
1180: # ============================================================== Compose output
1181:
1182: sub compout {
1183: my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode)=@_;
1184: my $suffix=&foldersuffix($folder);
1185:
1186: if ($broadcast eq 'individual') {
1187: &printheader($r,'/adm/email?compose=individual',
1188: 'Send a Message');
1189: } elsif ($broadcast) {
1190: &printheader($r,'/adm/email?compose=group',
1191: 'Broadcast Message');
1192: } elsif ($forwarding) {
1193: &Apache::lonhtmlcommon::add_breadcrumb
1194: ({href=>"/adm/email?display=".&Apache::lonnet::escape($forwarding),
1195: text=>"Display Message"});
1196: &printheader($r,'/adm/email?forward='.&Apache::lonnet::escape($forwarding),
1197: 'Forwarding a Message');
1198: } elsif ($replying) {
1199: &Apache::lonhtmlcommon::add_breadcrumb
1200: ({href=>"/adm/email?display=".&Apache::lonnet::escape($replying),
1201: text=>"Display Message"});
1202: &printheader($r,'/adm/email?replyto='.&Apache::lonnet::escape($replying),
1203: 'Replying to a Message');
1204: } elsif ($replycrit) {
1205: $r->print('<h3>'.&mt('Replying to a Critical Message').'</h3>');
1206: $replying=$replycrit;
1207: } else {
1208: &printheader($r,'/adm/email?compose=upload',
1209: 'Distribute from Uploaded File');
1210: }
1211:
1212: my $dispcrit='';
1213: my $dissub='';
1214: my $dismsg='';
1215: my $disbase='';
1216: my $func=&mt('Send New');
1217: my %lt=&Apache::lonlocal::texthash('us' => 'Username',
1218: 'do' => 'Domain',
1219: 'ad' => 'Additional Recipients',
1220: 'sb' => 'Subject',
1221: 'ca' => 'Cancel',
1222: 'ma' => 'Mail');
1223:
1224: if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
1225: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1226: $dispcrit=
1227: '<p><label><input type="checkbox" name="critmsg" /> '.&mt('Send as critical message').'</label> ' . $crithelp .
1228: '</p><p>'.
1229: '<label><input type="checkbox" name="sendbck" /> '.&mt('Send as critical message').' ' .
1230: &mt('and return receipt') . '</label>' . $crithelp .
1231: '</p><p><label><input type="checkbox" name="permanent" /> '.
1232: &mt('Send copy to permanent email address (if known)').'</label></p>'.
1233: '<!-- <p><label><input type="checkbox" name="rsspost" /> '.
1234: &mt('Include in course RSS newsfeed').'</label></p>-->'; }
1235: my %message;
1236: my %content;
1237: my $defdom=$env{'user.domain'};
1238: if ($forwarding) {
1239: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]);
1240: %content=&unpackagemsg($message{$forwarding},$folder);
1241: $dispcrit.='<input type="hidden" name="forwid" value="'.
1242: $forwarding.'" />';
1243: $func=&mt('Forward');
1244:
1245: $dissub=&mt('Forwarding').': '.$content{'subject'};
1246: $dismsg=&mt('Forwarded message from').' '.
1247: $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
1248: if ($content{'baseurl'}) {
1249: $disbase='<input type="hidden" name="baseurl" value="'.&Apache::lonnet::escape($content{'baseurl'}).'" />';
1250: }
1251: }
1252: if ($replying) {
1253: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
1254: %content=&unpackagemsg($message{$replying},$folder);
1255: $dispcrit.='<input type="hidden" name="replyid" value="'.
1256: $replying.'" />';
1257: $func=&mt('Send Reply to');
1258:
1259: $dissub=&mt('Reply').': '.$content{'subject'};
1260: $dismsg='> '.$content{'message'};
1261: $dismsg=~s/\r/\n/g;
1262: $dismsg=~s/\f/\n/g;
1263: $dismsg=~s/\n+/\n\> /g;
1264: if ($content{'baseurl'}) {
1265: $disbase='<input type="hidden" name="baseurl" value="'.&Apache::lonnet::escape($content{'baseurl'}).'" />';
1266: if ($env{'user.adv'}) {
1267: $disbase.='<label><input type="checkbox" name="storebasecomment" />'.&mt('Store message for re-use').
1268: '</label> <a href="/adm/email?showcommentbaseurl='.
1269: &Apache::lonnet::escape($content{'baseurl'}).'" target="comments">'.
1270: &mt('Show re-usable messages').'</a><br />';
1271: }
1272: }
1273: }
1274: my $citation=&displayresource(%content);
1275: if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
1276: $r->print(
1277: '<form action="/adm/email" name="compemail" method="post"'.
1278: ' enctype="multipart/form-data">'."\n".
1279: '<input type="hidden" name="sendmail" value="on" />'."\n".
1280: '<table>');
1281: unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
1282: if ($replying) {
1283: $r->print('<tr><td colspan="2">'.&mt('Replying to').' '.
1284: &Apache::loncommon::aboutmewrapper(
1285: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
1286: $content{'sendername'}.'@'.
1287: $content{'senderdomain'}.')'.
1288: '<input type="hidden" name="recuname" value="'.$content{'sendername'}.'" />'.
1289: '<input type="hidden" name="recdomain" value="'.$content{'senderdomain'}.'" />'.
1290: '</td></tr>');
1291: } else {
1292: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
1293: my $selectlink=&Apache::loncommon::selectstudent_link
1294: ('compemail','recuname','recdomain');
1295: $r->print(<<"ENDREC");
1296: <tr><td>$lt{'us'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recname'}" /></td><td rowspan="2">$selectlink</td></tr>
1297: <tr><td>$lt{'do'}:</td>
1298: <td>$domform</td></tr>
1299: ENDREC
1300: }
1301: }
1302: my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
1303: if ($broadcast ne 'upload') {
1304: $r->print(<<"ENDCOMP");
1305: <tr><td>$lt{'ad'}<br /><tt>username\@domain,username\@domain, ...
1306: </tt></td><td>
1307: <input type="text" size="50" name="additionalrec" /></td></tr>
1308: <tr><td>$lt{'sb'}:</td><td><input type="text" size="50" name="subject" value="$dissub" />
1309: </td></tr></table>
1310: $latexHelp
1311: <textarea name="message" id="message" cols="80" rows="15" wrap="hard">$dismsg
1312: </textarea></p><br />
1313: $dispcrit
1314: $disbase
1315: <input type="hidden" name="folder" value="$folder" />
1316: <input type="hidden" name="dismode" value="$dismode" />
1317: <input type="submit" name="send" value="$func $lt{'ma'}" />
1318: <input type="submit" name="cancel" value="$lt{'ca'}" /><hr />
1319: $citation
1320: ENDCOMP
1321: } else { # $broadcast is 'upload'
1322: $r->print(<<ENDUPLOAD);
1323: <input type="hidden" name="sendmode" value="upload" />
1324: <input type="hidden" name="send" value="on" />
1325: <h3>Generate messages from a file</h3>
1326: <p>
1327: Subject: <input type="text" size="50" name="subject" />
1328: </p>
1329: <p>General message text<br />
1330: <textarea name="message" id="message" cols="60" rows="10" wrap="hard">$dismsg
1331: </textarea></p>
1332: <p>
1333: The file format for the uploaded portion of the message is:
1334: <pre>
1335: username1\@domain1: text
1336: username2\@domain2: text
1337: username3\@domain1: text
1338: </pre>
1339: </p>
1340: <p>
1341: The messages will be assembled from all lines with the respective
1342: <tt>username\@domain</tt>, and appended to the general message text.</p>
1343: <p>
1344: <input type="file" name="upfile" size="40" /></p><p>
1345: $dispcrit
1346: <input type="submit" value="Upload and Send" /></p>
1347: ENDUPLOAD
1348: }
1349: if ($broadcast eq 'group') {
1350: &discourse;
1351: }
1352: $r->print('</form>'.
1353: &Apache::lonfeedback::generate_preview_button('compemail','message').
1354: &Apache::lonhtmlcommon::htmlareaselectactive('message'));
1355: }
1356:
1357: # ---------------------------------------------------- Display all face to face
1358:
1359: sub retrieve_instructor_comments {
1360: my ($user,$domain)=@_;
1361: my $target=$env{'form.grade_target'};
1362: if (! $env{'request.course.id'}) { return; }
1363: if (! &Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
1364: return;
1365: }
1366: my %records=&Apache::lonnet::dump('nohist_email',
1367: $env{'course.'.$env{'request.course.id'}.'.domain'},
1368: $env{'course.'.$env{'request.course.id'}.'.num'},
1369: '%255b'.$user.'%253a'.$domain.'%255d');
1370: my $result='';
1371: foreach (sort(keys(%records))) {
1372: my %content=&unpackagemsg($records{$_});
1373: next if ($content{'senderdomain'} eq '');
1374: next if ($content{'subject'} !~ /^Record/);
1375: # &Apache::lonfeedback::newline_to_br(\$content{'message'});
1376: $result.='Recorded by '.
1377: $content{'sendername'}.'@'.$content{'senderdomain'}."\n";
1378: $result.=
1379: &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
1380: }
1381: return $result;
1382: }
1383:
1384: sub disfacetoface {
1385: my ($r,$user,$domain)=@_;
1386: my $target=$env{'form.grade_target'};
1387: unless ($env{'request.course.id'}) { return; }
1388: unless (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
1389: return;
1390: }
1391: my %records=&Apache::lonnet::dump('nohist_email',
1392: $env{'course.'.$env{'request.course.id'}.'.domain'},
1393: $env{'course.'.$env{'request.course.id'}.'.num'},
1394: '%255b'.$user.'%253a'.$domain.'%255d');
1395: my $result='';
1396: foreach (sort keys %records) {
1397: my %content=&unpackagemsg($records{$_});
1398: next if ($content{'senderdomain'} eq '');
1399: &Apache::lonfeedback::newline_to_br(\$content{'message'});
1400: if ($content{'subject'}=~/^Record/) {
1401: $result.='<h3>'.&mt('Record').'</h3>';
1402: } elsif ($content{'subject'}=~/^Broadcast/) {
1403: $result .='<h3>'.&mt('Broadcast Message').'</h3>';
1404: if ($content{'subject'}=~/^Broadcast\./) {
1405: %content=&unpackagemsg($content{'message'});
1406: $content{'message'}=
1407: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1408: $content{'message'};
1409: }
1410: } else {
1411: $result.='<h3>'.&mt('Critical Message').'</h3>';
1412: %content=&unpackagemsg($content{'message'});
1413: $content{'message'}=
1414: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1415: $content{'message'};
1416: }
1417: $result.=&mt('By').': <b>'.
1418: &Apache::loncommon::aboutmewrapper(
1419: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1420: $content{'sendername'}.'@'.
1421: $content{'senderdomain'}.') '.$content{'time'}.
1422: '<br /><pre>'.
1423: &Apache::lontexconvert::msgtexconverted($content{'message'}).
1424: '</pre>';
1425: }
1426: # Check to see if there were any messages.
1427: if ($result eq '') {
1428: if ($target ne 'tex') {
1429: $r->print("<p><b>".&mt("No notes, face-to-face discussion records, critical messages, or broadcast messages in this course.")."</b></p>");
1430: } else {
1431: $r->print('\textbf{'.&mt("No notes, face-to-face discussion records, critical messages or broadcast messages in this course.").'}\\\\');
1432: }
1433: } else {
1434: $r->print($result);
1435: }
1436: }
1437:
1438: # ---------------------------------------------------------------- Face to face
1439:
1440: sub facetoface {
1441: my ($r,$stage)=@_;
1442: unless (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
1443: return;
1444: }
1445: &printheader($r,
1446: '/adm/email?recordftf=query',
1447: "User Notes, Face-to-Face, Critical Messages, Broadcast Messages");
1448: # from query string
1449:
1450: if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
1451: if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
1452:
1453: my $defdom=$env{'user.domain'};
1454: # already filled in
1455: if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
1456: # generate output
1457: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
1458: my $stdbrws = &Apache::loncommon::selectstudent_link
1459: ('stdselect','recuname','recdomain');
1460: my %lt=&Apache::lonlocal::texthash('user' => 'Username',
1461: 'dom' => 'Domain',
1462: 'head' => 'User Notes, Records of Face-To-Face Discussions, Critical Messages, and Broadcast Messages in Course',
1463: 'subm' => 'Retrieve discussion and message records',
1464: 'newr' => 'New Record (record is visible to course faculty and staff)',
1465: 'post' => 'Post this Record');
1466: $r->print(<<"ENDTREC");
1467: <h3>$lt{'head'}</h3>
1468: <form method="post" action="/adm/email" name="stdselect">
1469: <input type="hidden" name="recordftf" value="retrieve" />
1470: <table>
1471: <tr><td>$lt{'user'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recuname'}" /></td>
1472: <td rowspan="2">
1473: $stdbrws
1474: <input type="submit" value="$lt{'subm'}" /></td>
1475: </tr>
1476: <tr><td>$lt{'dom'}:</td>
1477: <td>$domform</td></tr>
1478: </table>
1479: </form>
1480: ENDTREC
1481: if (($stage ne 'query') &&
1482: ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
1483: chomp($env{'form.newrecord'});
1484: if ($env{'form.newrecord'}) {
1485: my $recordtxt = $env{'form.newrecord'};
1486: &user_normal_msg_raw(
1487: $env{'course.'.$env{'request.course.id'}.'.num'},
1488: $env{'course.'.$env{'request.course.id'}.'.domain'},
1489: &mt('Record').
1490: ' ['.$env{'form.recuname'}.':'.$env{'form.recdomain'}.']',
1491: $recordtxt);
1492: }
1493: $r->print('<h3>'.&Apache::loncommon::plainname($env{'form.recuname'},
1494: $env{'form.recdomain'}).'</h3>');
1495: &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
1496: $r->print(<<ENDRHEAD);
1497: <form method="post" action="/adm/email">
1498: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
1499: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
1500: ENDRHEAD
1501: $r->print(<<ENDBFORM);
1502: <hr />$lt{'newr'}<br />
1503: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
1504: <br />
1505: <input type="hidden" name="recordftf" value="post" />
1506: <input type="submit" value="$lt{'post'}" />
1507: </form>
1508: ENDBFORM
1509: }
1510: }
1511:
1512: # ----------------------------------------------------------- Blocking during exams
1513:
1514: sub examblock {
1515: my ($r,$action) = @_;
1516: unless ($env{'request.course.id'}) { return;}
1517: unless (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) { $r->print('Not allowed'); }
1518: my %lt=&Apache::lonlocal::texthash(
1519: 'comb' => 'Communication Blocking',
1520: 'cbds' => 'Communication blocking during scheduled exams',
1521: 'desc' => 'You can use communication blocking to prevent students enrolled in this course from displaying LON-CAPA messages sent by other students during an online exam. As blocking of communication could potentially interrupt legitimate communication between students who are also both enrolled in a different LON-CAPA course, please be careful that you select the correct start and end times for your scheduled exam when setting or modifying these parameters.',
1522: 'mecb' => 'Modify existing communication blocking periods',
1523: 'ncbc' => 'No communication blocks currently stored'
1524: );
1525:
1526: my %ltext = &Apache::lonlocal::texthash(
1527: 'dura' => 'Duration',
1528: 'setb' => 'Set by',
1529: 'even' => 'Event',
1530: 'actn' => 'Action',
1531: 'star' => 'Start',
1532: 'endd' => 'End'
1533: );
1534:
1535: &printheader($r,'/adm/email?block=display',$lt{'comb'});
1536: $r->print('<h3>'.$lt{'cbds'}.'</h3>');
1537:
1538: if ($action eq 'store') {
1539: &blockstore($r);
1540: }
1541:
1542: $r->print($lt{'desc'}.'<br /><br />
1543: <form name="blockform" method="post" action="/adm/email?block=store">
1544: ');
1545:
1546: $r->print('<h4>'.$lt{'mecb'}.'</h4>');
1547: my %records = ();
1548: my $blockcount = 0;
1549: my $parmcount = 0;
1550: &get_blockdates(\%records,\$blockcount);
1551: if ($blockcount > 0) {
1552: $parmcount = &display_blocker_status($r,\%records,\%ltext);
1553: } else {
1554: $r->print($lt{'ncbc'}.'<br /><br />');
1555: }
1556: &display_addblocker_table($r,$parmcount,\%ltext);
1557: my $endbody=&Apache::loncommon::endbodytag();
1558: $r->print(<<"END");
1559: <br />
1560: <input type="hidden" name="blocktotal" value="$blockcount" />
1561: <input type ="submit" value="Save Changes" />
1562: </form>
1563: $endbody
1564: </html>
1565: END
1566: return;
1567: }
1568:
1569: sub blockstore {
1570: my $r = shift;
1571: my %lt=&Apache::lonlocal::texthash(
1572: 'tfcm' => 'The following changes were made',
1573: 'cbps' => 'communication blocking period(s)',
1574: 'werm' => 'was/were removed',
1575: 'wemo' => 'was/were modified',
1576: 'wead' => 'was/were added',
1577: 'ncwm' => 'No changes were made.'
1578: );
1579: my %adds = ();
1580: my %removals = ();
1581: my %cancels = ();
1582: my $modtotal = 0;
1583: my $canceltotal = 0;
1584: my $addtotal = 0;
1585: my %blocking = ();
1586: $r->print('<h3>'.$lt{'head'}.'</h3>');
1587: foreach (keys %env) {
1588: if ($_ =~ m/^form\.modify_(\w+)$/) {
1589: $adds{$1} = $1;
1590: $removals{$1} = $1;
1591: $modtotal ++;
1592: } elsif ($_ =~ m/^form\.cancel_(\d+)$/) {
1593: $cancels{$1} = $1;
1594: unless ( defined($removals{$1}) ) {
1595: $removals{$1} = $1;
1596: $canceltotal ++;
1597: }
1598: } elsif ($_ =~ m/^form\.add_(\d+)$/) {
1599: $adds{$1} = $1;
1600: $addtotal ++;
1601: }
1602: }
1603:
1604: foreach (keys %removals) {
1605: my $hashkey = $env{'form.key_'.$_};
1606: &Apache::lonnet::del('comm_block',["$hashkey"],
1607: $env{'course.'.$env{'request.course.id'}.'.domain'},
1608: $env{'course.'.$env{'request.course.id'}.'.num'}
1609: );
1610: }
1611: foreach (keys %adds) {
1612: unless ( defined($cancels{$_}) ) {
1613: my ($newstart,$newend) = &get_dates_from_form($_);
1614: my $newkey = $newstart.'____'.$newend;
1615: $blocking{$newkey} = $env{'user.name'}.'@'.$env{'user.domain'}.':'.$env{'form.title_'.$_};
1616: }
1617: }
1618: if ($addtotal + $modtotal > 0) {
1619: &Apache::lonnet::put('comm_block',\%blocking,
1620: $env{'course.'.$env{'request.course.id'}.'.domain'},
1621: $env{'course.'.$env{'request.course.id'}.'.num'}
1622: );
1623: }
1624: my $chgestotal = $canceltotal + $modtotal + $addtotal;
1625: if ($chgestotal > 0) {
1626: $r->print($lt{'tfcm'}.'<ul>');
1627: if ($canceltotal > 0) {
1628: $r->print('<li>'.$canceltotal.' '.$lt{'cbps'},' '.$lt{'werm'}.'</li>');
1629: }
1630: if ($modtotal > 0) {
1631: $r->print('<li>'.$modtotal.' '.$lt{'cbps'},' '.$lt{'wemo'}.'</li>');
1632: }
1633: if ($addtotal > 0) {
1634: $r->print('<li>'.$addtotal.' '.$lt{'cbps'},' '.$lt{'wead'}.'</li>');
1635: }
1636: $r->print('</ul>');
1637: } else {
1638: $r->print($lt{'ncwm'});
1639: }
1640: $r->print('<br />');
1641: return;
1642: }
1643:
1644: sub get_dates_from_form {
1645: my $item = shift;
1646: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
1647: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
1648: return ($startdate,$enddate);
1649: }
1650:
1651: sub get_blockdates {
1652: my ($records,$blockcount) = @_;
1653: $$blockcount = 0;
1654: %{$records} = &Apache::lonnet::dump('comm_block',
1655: $env{'course.'.$env{'request.course.id'}.'.domain'},
1656: $env{'course.'.$env{'request.course.id'}.'.num'}
1657: );
1658: $$blockcount = keys %{$records};
1659:
1660: foreach (keys %{$records}) {
1661: if ($_ eq 'error: 2 tie(GDBM) Failed while attempting dump') {
1662: $$blockcount = 0;
1663: last;
1664: }
1665: }
1666: }
1667:
1668: sub display_blocker_status {
1669: my ($r,$records,$ltext) = @_;
1670: my $parmcount = 0;
1671: my @bgcols = ("#eeeeee","#dddddd");
1672: my $function = &Apache::loncommon::get_users_function();
1673: my $color = &Apache::loncommon::designparm($function.'.tabbg',
1674: $env{'user.domain'});
1675: my %lt = &Apache::lonlocal::texthash(
1676: 'modi' => 'Modify',
1677: 'canc' => 'Cancel',
1678: );
1679: $r->print(<<"END");
1680: <table border="0" cellpadding="0" cellspacing="0">
1681: <tr>
1682: <td width="100%" bgcolor="#000000">
1683: <table width="100%" border="0" cellpadding="1" cellspacing="0">
1684: <tr>
1685: <td width="100%" bgcolor="#000000">
1686: <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
1687: <tr bgcolor="$color">
1688: <td><b>$$ltext{'dura'}</b></td>
1689: <td><b>$$ltext{'setb'}</b></td>
1690: <td><b>$$ltext{'even'}</b></td>
1691: <td><b>$$ltext{'actn'}?</b></td>
1692: </tr>
1693: END
1694: foreach (sort keys %{$records}) {
1695: my $iter = $parmcount%2;
1696: my $onchange = 'onFocus="javascript:window.document.forms['.
1697: "'blockform'].elements['modify_".$parmcount."'].".
1698: 'checked=true;"';
1699: my ($start,$end) = split/____/,$_;
1700: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
1701: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1702: my ($setter,$title) = split/:/,$$records{$_};
1703: my ($setuname,$setudom) = split/@/,$setter;
1704: my $settername = &Apache::loncommon::plainname($setuname,$setudom);
1705: $r->print(<<"END");
1706: <tr bgcolor="$bgcols[$iter]">
1707: <td>$$ltext{'star'}: $startform<br/>$$ltext{'endd'}: $endform</td>
1708: <td>$settername</td>
1709: <td><input type="text" name="title_$parmcount" size="15" value="$title" /><input type="hidden" name="key_$parmcount" value="$_" /></td>
1710: <td><label>$lt{'modi'}? <input type="checkbox" name="modify_$parmcount" /></label><br /><label>$lt{'canc'}? <input type="checkbox" name="cancel_$parmcount" /></label>
1711: </tr>
1712: END
1713: $parmcount ++;
1714: }
1715: $r->print(<<"END");
1716: </table>
1717: </td>
1718: </tr>
1719: </table>
1720: </td>
1721: </tr>
1722: </table>
1723: <br />
1724: <br />
1725: END
1726: return $parmcount;
1727: }
1728:
1729: sub display_addblocker_table {
1730: my ($r,$parmcount,$ltext) = @_;
1731: my $start = time;
1732: my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
1733: my $onchange = 'onFocus="javascript:window.document.forms['.
1734: "'blockform'].elements['add_".$parmcount."'].".
1735: 'checked=true;"';
1736: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
1737: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1738: my $function = &Apache::loncommon::get_users_function();
1739: my $color = &Apache::loncommon::designparm($function.'.tabbg',
1740: $env{'user.domain'});
1741: my %lt = &Apache::lonlocal::texthash(
1742: 'addb' => 'Add block',
1743: 'exam' => 'e.g., Exam 1',
1744: 'addn' => 'Add new communication blocking periods'
1745: );
1746: $r->print(<<"END");
1747: <h4>$lt{'addn'}</h4>
1748: <table border="0" cellpadding="0" cellspacing="0">
1749: <tr>
1750: <td width="100%" bgcolor="#000000">
1751: <table width="100%" border="0" cellpadding="1" cellspacing="0">
1752: <tr>
1753: <td width="100%" bgcolor="#000000">
1754: <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
1755: <tr bgcolor="#CCCCFF">
1756: <td><b>$$ltext{'dura'}</b></td>
1757: <td><b>$$ltext{'even'} $lt{'exam'}</b></td>
1758: <td><b>$$ltext{'actn'}?</b></td>
1759: </tr>
1760: <tr bgcolor="#eeeeee">
1761: <td>$$ltext{'star'}: $startform<br />$$ltext{'endd'}: $endform</td>
1762: <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
1763: <td><label>$lt{'addb'}? <input type="checkbox" name="add_$parmcount" value="1" /></label></td>
1764: </tr>
1765: </table>
1766: </td>
1767: </tr>
1768: </table>
1769: </td>
1770: </tr>
1771: </table>
1772: END
1773: return;
1774: }
1775:
1776: sub blockcheck {
1777: my ($setters,$startblock,$endblock) = @_;
1778: # Retrieve active student roles and active course coordinator/instructor roles
1779: my @livecses = ();
1780: my @staffcses = ();
1781: $$startblock = 0;
1782: $$endblock = 0;
1783: foreach (keys %env) {
1784: if ($_ =~ m-^user\.role\.(st|cc|in)\./(.+)$-) {
1785: my $role = $1;
1786: my $cse = $2;
1787: $cse =~ s|/|_|;
1788: if ($env{$_} =~ m/^(\d*)\.(\d*)$/) {
1789: unless (($2 > 0 && $2 < time) || ($1 > time)) {
1790: if ($role eq 'st') {
1791: push @livecses, $cse;
1792: } else {
1793: unless (grep/^$cse$/,@staffcses) {
1794: push @staffcses, $cse;
1795: }
1796: }
1797: }
1798: }
1799: } elsif ($_ =~ m-user\.role\.cr/(\w+)/(\w+)/([^/]+)\./(.+)$- ) {
1800: my $rolepriv = $env{'user.role..rolesdef_'.$3};
1801: }
1802: }
1803: # Retrieve blocking times and identity of blocker for active courses for students.
1804: if (@livecses > 0) {
1805: foreach my $cse (@livecses) {
1806: my ($cdom,$crs) = split/_/,$cse;
1807: if ( (grep/^$cse$/,@staffcses) && ($env{'request.role'} !~ m-^st\./$cdom/$crs$-) ) {
1808: next;
1809: } else {
1810: %{$$setters{$cse}} = ();
1811: @{$$setters{$cse}{'staff'}} = ();
1812: @{$$setters{$cse}{'times'}} = ();
1813: my %records = &Apache::lonnet::dump('comm_block',$cdom,$crs);
1814: foreach (keys %records) {
1815: if ($_ =~ m/^(\d+)____(\d+)$/) {
1816: if ($1 <= time && $2 >= time) {
1817: my ($staff,$title) = split/:/,$records{$_};
1818: push @{$$setters{$cse}{'staff'}}, $staff;
1819: push @{$$setters{$cse}{'times'}}, $_;
1820: if ( ($$startblock == 0) || ($$startblock > $1) ) {
1821: $$startblock = $1;
1822: }
1823: if ( ($$endblock == 0) || ($$endblock < $2) ) {
1824: $$endblock = $2;
1825: }
1826: }
1827: }
1828: }
1829: }
1830: }
1831: }
1832: }
1833:
1834: sub build_block_table {
1835: my ($r,$startblock,$endblock,$setters) = @_;
1836: my $function = &Apache::loncommon::get_users_function();
1837: my $color = &Apache::loncommon::designparm($function.'.tabbg',
1838: $env{'user.domain'});
1839: my %lt = &Apache::lonlocal::texthash(
1840: 'cacb' => 'Currently active communication blocks',
1841: 'cour' => 'Course',
1842: 'dura' => 'Duration',
1843: 'blse' => 'Block set by'
1844: );
1845: $r->print(<<"END");
1846: <br /<br />$lt{'cacb'}:<br /><br />
1847: <table border="0" cellpadding="0" cellspacing="0">
1848: <tr>
1849: <td width="100%" bgcolor="#000000">
1850: <table width="100%" border="0" cellpadding="1" cellspacing="0">
1851: <tr>
1852: <td width="100%" bgcolor="#000000">
1853: <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
1854: <tr bgcolor="$color">
1855: <td><b>$lt{'cour'}</b></td>
1856: <td><b>$lt{'dura'}</b></td>
1857: <td><b>$lt{'blse'}</b></td>
1858: </tr>
1859: END
1860: foreach (keys %{$setters}) {
1861: my %courseinfo=&Apache::lonnet::coursedescription($_);
1862: for (my $i=0; $i<@{$$setters{$_}{staff}}; $i++) {
1863: my ($uname,$udom) = split/\@/,$$setters{$_}{staff}[$i];
1864: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1865: my ($openblock,$closeblock) = split/____/,$$setters{$_}{times}[$i];
1866: $openblock = &Apache::lonlocal::locallocaltime($openblock);
1867: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
1868: $r->print('<tr><td>'.$courseinfo{'description'}.'</td>'.
1869: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1870: '<td>'.$fullname.' ('.$uname.'@'.$udom.
1871: ')</td></tr>');
1872: }
1873: }
1874: $r->print('</table></td></tr></table></td></tr></table>');
1875: }
1876:
1877: # ----------------------------------------------------------- Display a message
1878:
1879: sub displaymessage {
1880: my ($r,$msgid,$folder)=@_;
1881: my $suffix=&foldersuffix($folder);
1882: my %blocked = ();
1883: my %setters = ();
1884: my $startblock = 0;
1885: my $endblock = 0;
1886: my $numblocked = 0;
1887: # info to generate "next" and "previous" buttons and check if message is blocked
1888: &blockcheck(\%setters,\$startblock,\$endblock);
1889: my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder);
1890: if ( $blocked{$msgid} eq 'ON' ) {
1891: &printheader($r,'/adm/email',&mt('Display a Message'));
1892: $r->print(&mt('You attempted to display a message that is currently blocked because you are enrolled in one or more courses for which there is an ongoing online exam.'));
1893: &build_block_table($r,$startblock,$endblock,\%setters);
1894: return;
1895: }
1896: &statuschange($msgid,'read',$folder);
1897: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1898: my %content=&unpackagemsg($message{$msgid});
1899:
1900: my $counter=0;
1901: $r->print('<pre>');
1902: my $escmsgid=&Apache::lonnet::escape($msgid);
1903: foreach (@messages) {
1904: if ($_->[5] eq $escmsgid){
1905: last;
1906: }
1907: $counter++;
1908: }
1909: $r->print('</pre>');
1910: my $number_of_messages = scalar(@messages); #subtract 1 for last index
1911: # start output
1912: &printheader($r,'/adm/email?display='.&Apache::lonnet::escape($msgid),'Display a Message','',$content{'baseurl'});
1913: my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'});
1914: # Functions
1915: $r->print('<table border="2" width="100%"><tr bgcolor="#FFFFAA"><td>'.&mt('Functions').':</td>'.
1916: '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).$sqs.
1917: '"><b>'.&mt('Reply').'</b></a></td>'.
1918: '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).$sqs.
1919: '"><b>'.&mt('Forward').'</b></a></td>'.
1920: '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).$sqs.
1921: '"><b>'.&mt('Mark Unread').'</b></a></td>'.
1922: '<td><a href="/adm/email?markdel='.&Apache::lonnet::escape($msgid).$sqs.
1923: '"><b>'.&mt('Delete').'</b></a></td>'.
1924: '<td><a href="/adm/email?'.$sqs.
1925: ($env{'form.dismode'} eq 'new'?'&folder=new':'').
1926: '"><b>'.&mt('Back to Folder Display').'</b></a></td>');
1927: if ($counter > 0){
1928: $r->print('<td><a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.
1929: '"><b>'.&mt('Previous').'</b></a></td>');
1930: }
1931: if ($counter < $number_of_messages - 1){
1932: $r->print('<td><a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.
1933: '"><b>'.&mt('Next').'</b></a></td>');
1934: }
1935: $r->print('</tr></table>');
1936: if ($env{'user.adv'}) {
1937: $r->print('<table border="2" width="100%"><tr bgcolor="#FFAAAA"><td>'.&mt('Currently available actions (will open extra window)').':</td>');
1938: my $symb=&Apache::lonnet::symbread($content{'baseurl'});
1939: if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
1940: $r->print('<td><b>'.&Apache::loncommon::track_student_link(&mt('View recent activity'),$content{'sendername'},$content{'senderdomain'},'check').'</b></td>');
1941: }
1942: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
1943: $r->print('<td><b>'.&Apache::loncommon::pprmlink(&mt('Set/Change parameters'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
1944: }
1945: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
1946: $r->print('<td><b>'.&Apache::loncommon::pgrdlink(&mt('Set/Change grades'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
1947: }
1948: $r->print('</tr></table>');
1949: }
1950: my $tolist;
1951: my @recipients = ();
1952: for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
1953: $recipients[$i] = &Apache::loncommon::aboutmewrapper(
1954: &Apache::loncommon::plainname($content{'recuser'}[$i],
1955: $content{'recdomain'}[$i]),
1956: $content{'recuser'}[$i],$content{'recdomain'}[$i]).
1957: ' ('.$content{'recuser'}[$i].' at '.$content{'recdomain'}[$i].') ';
1958: }
1959: $tolist = join(', ',@recipients);
1960: $r->print('<br /><b>'.&mt('Subject').':</b> '.$content{'subject'}.
1961: ($folder ne 'sent'?'<br /><b>'.&mt('From').':</b> '.
1962: &Apache::loncommon::aboutmewrapper(
1963: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
1964: $content{'sendername'},$content{'senderdomain'}).' ('.
1965: $content{'sendername'}.' at '.
1966: $content{'senderdomain'}.') ':'<br /><b>'.&mt('To').':</b> '.
1967: $tolist).
1968: ($content{'courseid'}?'<br /><b>'.&mt('Course').':</b> '.$courseinfo{'description'}.
1969: ($content{'coursesec'}?' ('.&mt('Group/Section').': '.$content{'coursesec'}.')':''):'').
1970: '<br /><b>'.&mt('Time').':</b> '.$content{'time'}.
1971: ($content{'baseurl'}?'<br /><b>'.&mt('Refers to').':</b> <a href="'.$content{'baseurl'}.'">'.
1972: $content{'baseurl'}.' ('.&Apache::lonnet::gettitle($content{'baseurl'}).')</a>':'').
1973: '<p><pre>'.
1974: &Apache::lontexconvert::msgtexconverted($content{'message'},1).
1975: '</pre><hr />'.&displayresource(%content).'</p>');
1976: return;
1977: }
1978:
1979: # =========================================================== Show the citation
1980:
1981: sub displayresource {
1982: my %content=@_;
1983: #
1984: # If the recipient is in the same course that the message was sent from and
1985: # has sufficient privileges, show "all details," else show citation
1986: #
1987: if (($env{'request.course.id'} eq $content{'courseid'})
1988: && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
1989: my $symb=&Apache::lonnet::symbread($content{'baseurl'});
1990: # Could not get a symb, give up
1991: unless ($symb) { return $content{'citation'}; }
1992: # Have a symb, can render
1993: return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
1994: &Apache::loncommon::get_previous_attempt($symb,
1995: $content{'sendername'},
1996: $content{'senderdomain'},
1997: $content{'courseid'}).
1998: '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
1999: &Apache::loncommon::get_student_view($symb,
2000: $content{'sendername'},
2001: $content{'senderdomain'},
2002: $content{'courseid'}).
2003: '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
2004: &Apache::loncommon::get_student_answers($symb,
2005: $content{'sendername'},
2006: $content{'senderdomain'},
2007: $content{'courseid'});
2008: } else {
2009: return $content{'citation'};
2010: }
2011: }
2012:
2013: # ================================================================== The Header
2014:
2015: sub header {
2016: my ($r,$title,$baseurl)=@_;
2017: $r->print(&Apache::lonxml::xmlbegin().
2018: '<head>'.&Apache::lonxml::fontsettings().
2019: '<title>Communication and Messages</title>'.
2020: &Apache::lonhtmlcommon::htmlareaheaders());
2021: if ($baseurl) {
2022: $r->print("<base href=\"http://$ENV{'SERVER_NAME'}/$baseurl\" />");
2023: }
2024: $r->print(&Apache::loncommon::studentbrowser_javascript().'</head>'.
2025: &Apache::loncommon::bodytag('Communication and Messages'));
2026: $r->print(&Apache::lonhtmlcommon::breadcrumbs
2027: (undef,($title?$title:'Communication and Messages')));
2028:
2029: }
2030:
2031: # ---------------------------------------------------------------- Print header
2032:
2033: sub printheader {
2034: my ($r,$url,$desc,$title,$baseurl)=@_;
2035: &Apache::lonhtmlcommon::add_breadcrumb
2036: ({href=>$url,
2037: text=>$desc});
2038: &header($r,$title,$baseurl);
2039: }
2040:
2041: # ------------------------------------------------------------ Store the comment
2042:
2043: sub storecomment {
2044: my ($r)=@_;
2045: my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2046: my $cleanmsgtxt='';
2047: foreach (split(/[\n\r]/,$msgtxt)) {
2048: unless ($_=~/^\s*(\>|\>\;)/) {
2049: $cleanmsgtxt.=$_."\n";
2050: }
2051: }
2052: my $key=&Apache::lonnet::escape($env{'form.baseurl'}).'___'.time;
2053: &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
2054: }
2055:
2056: sub storedcommentlisting {
2057: my ($r)=@_;
2058: my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
2059: '^'.&Apache::lonnet::escape(&Apache::lonnet::escape($env{'form.showcommentbaseurl'})));
2060: $r->print(&Apache::lonxml::xmlbegin().'<head>'.
2061: &Apache::lonxml::fontsettings().'</head><body>');
2062: if ((keys %msgs)[0]=~/^error\:/) {
2063: $r->print(&mt('No stored comments yet.'));
2064: } else {
2065: my $found=0;
2066: foreach (sort keys %msgs) {
2067: $r->print("\n".$msgs{$_}."<hr />");
2068: $found=1;
2069: }
2070: unless ($found) {
2071: $r->print(&mt('No stored comments yet for this resource.'));
2072: }
2073: }
2074: }
2075:
2076: # ---------------------------------------------------------------- Send an email
2077:
2078: sub sendoffmail {
2079: my ($r,$folder)=@_;
2080: my $suffix=&foldersuffix($folder);
2081: my $sendstatus='';
2082: my %specialmsg_status;
2083: my $numspecial = 0;
2084: if ($env{'form.send'}) {
2085: &printheader($r,'','Messages being sent.');
2086: $r->rflush();
2087: my %content=();
2088: undef %content;
2089: if ($env{'form.forwid'}) {
2090: my $msgid=$env{'form.forwid'};
2091: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2092: %content=&unpackagemsg($message{$msgid},1);
2093: &statuschange($msgid,'forwarded',$folder);
2094: $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
2095: $content{'message'};
2096: }
2097: if ($env{'form.replyid'}) {
2098: my $msgid=$env{'form.replyid'};
2099: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2100: %content=&unpackagemsg($message{$msgid},1);
2101: &statuschange($msgid,'replied',$folder);
2102: }
2103: my %toaddr=();
2104: undef %toaddr;
2105: if ($env{'form.sendmode'} eq 'group') {
2106: foreach (keys %env) {
2107: if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
2108: $toaddr{$1}='';
2109: }
2110: }
2111: } elsif ($env{'form.sendmode'} eq 'upload') {
2112: foreach (split(/[\n\r\f]+/,$env{'form.upfile'})) {
2113: my ($rec,$txt)=split(/\s*\:\s*/,$_);
2114: if ($txt) {
2115: $rec=~s/\@/\:/;
2116: $toaddr{$rec}.=$txt."\n";
2117: }
2118: }
2119: } else {
2120: $toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
2121: }
2122: if ($env{'form.additionalrec'}) {
2123: foreach (split(/\,/,$env{'form.additionalrec'})) {
2124: my ($auname,$audom)=split(/\@/,$_);
2125: $toaddr{$auname.':'.$audom}='';
2126: }
2127: }
2128:
2129: my $savemsg;
2130: my $msgtype;
2131: my %sentmessage;
2132: if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
2133: (&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) {
2134: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
2135: $msgtype = 'critical';
2136: } else {
2137: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2138: }
2139:
2140: foreach (keys %toaddr) {
2141: my ($recuname,$recdomain)=split(/\:/,$_);
2142: my $msgtxt = $savemsg;
2143: if ($toaddr{$_}) { $msgtxt.='<hr />'.$toaddr{$_}; }
2144: my $thismsg;
2145: if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
2146: (&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) {
2147: $r->print(&mt('Sending critical message').' '.$recuname.'@'.$recdomain.': ');
2148: $thismsg=&user_crit_msg($recuname,$recdomain,
2149: &Apache::lonfeedback::clear_out_html($env{'form.subject'}),
2150: $msgtxt,
2151: $env{'form.sendbck'},$env{'form.permanent'},\$sentmessage{$_});
2152: } else {
2153: $r->print(&mt('Sending').' '.$recuname.'@'.$recdomain.': ');
2154: $thismsg=&user_normal_msg($recuname,$recdomain,
2155: &Apache::lonfeedback::clear_out_html($env{'form.subject'}),
2156: $msgtxt,
2157: $content{'citation'},undef,undef,$env{'form.permanent'},\$sentmessage{$_});
2158: }
2159: if (($env{'request.course.id'}) && (($msgtype eq 'critical') ||
2160: ($env{'form.sendmode'} eq 'group'))) {
2161: $specialmsg_status{$recuname.':'.$recdomain} = $thismsg;
2162: if ($thismsg eq 'ok') {
2163: $numspecial ++;
2164: }
2165: }
2166: $r->print($thismsg.'<br />');
2167: $sendstatus.=' '.$thismsg;
2168: }
2169: if (($env{'request.course.id'}) && (($env{'form.sendmode'} eq 'group')
2170: || ($msgtype eq 'critical'))) {
2171: my $subj_prefix;
2172: if ($msgtype eq 'critical') {
2173: $subj_prefix = 'Critical.';
2174: } else {
2175: $subj_prefix = 'Broadcast.';
2176: }
2177: my ($specialmsgid,$specialresult);
2178: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2179: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2180: my $course_str = &Apache::lonnet::escape('['.$cnum.':'.$cdom.']');
2181:
2182: if ($numspecial) {
2183: $specialresult = &user_normal_msg_raw($cnum,$cdom,$subj_prefix.
2184: ' '.$course_str,$savemsg,undef,undef,undef,
2185: undef,undef,\$specialmsgid);
2186: $specialmsgid = &Apache::lonnet::unescape($specialmsgid);
2187: }
2188: if ($specialresult eq 'ok') {
2189: my $record_sent;
2190: my @recusers = ();
2191: my @recudoms = ();
2192: my ($stamp,$msgsubj,$msgname,$msgdom,$msgcount,$context,$pid) =
2193: split(/\:/,&Apache::lonnet::unescape($specialmsgid));
2194: foreach my $recipient (sort(keys(%toaddr))) {
2195: if ($specialmsg_status{$recipient} eq 'ok') {
2196: my $usersubj = $subj_prefix.'['.$recipient.']';
2197: my $usermsgid = &buildmsgid($stamp,$usersubj,$msgname,
2198: $msgdom,$msgcount,$context,$pid);
2199: &user_normal_msg_raw($cnum,$cdom,$subj_prefix.
2200: ' ['.$recipient.']',$sentmessage{$recipient},
2201: undef,undef,undef,undef,$usermsgid);
2202: my ($uname,$udom) = split/:/,$recipient;
2203: push(@recusers,$uname);
2204: push(@recudoms,$udom);
2205: }
2206: }
2207: if (@recusers) {
2208: my $specialmessage;
2209: my $sentsubj = $subj_prefix.' ('.$numspecial.' sent) '.
2210: &Apache::lonfeedback::clear_out_html($env{'form.subject'});
2211: $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
2212: my $sentmsgid = &buildmsgid($stamp,$sentsubj,$msgname,
2213: $msgdom,$msgcount,$context,$pid);
2214: ($specialmsgid,$specialmessage) =
2215: &packagemsg(&Apache::lonfeedback::clear_out_html(
2216: $env{'form.subject'}),$savemsg,undef,undef,undef,
2217: \@recusers,\@recudoms,$sentmsgid);
2218: $record_sent = &store_sent_mail($specialmsgid,$specialmessage);
2219: }
2220: } else {
2221: &Apache::lonnet::logthis('Failed to create record of critical message or broadcast in '.$env{'course.'.$env{'request.course.id'}.'.num'}.' at '.$env{'course.'.$env{'request.course.id'}.'.domain'}.' - no msgid generated');
2222: }
2223: }
2224: } else {
2225: &printheader($r,'','No messages sent.');
2226: }
2227: if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
2228: $r->print('<br /><font color="green">'.&mt('Completed.').'</font>');
2229: if ($env{'form.displayedcrit'}) {
2230: &discrit($r);
2231: } else {
2232: &Apache::loncommunicate::menu($r);
2233: }
2234: } else {
2235: $r->print(
2236: '<h2><font color="red">'.&mt('Could not deliver message').'</font></h2>'.
2237: &mt('Please use the browser "Back" button and correct the recipient addresses')
2238: );
2239: }
2240: }
2241:
2242: # ===================================================================== Handler
2243:
2244: sub handler {
2245: my $r=shift;
2246:
2247: # ----------------------------------------------------------- Set document type
2248:
2249: &Apache::loncommon::content_type($r,'text/html');
2250: $r->send_http_header;
2251:
2252: return OK if $r->header_only;
2253:
2254: # --------------------------- Get query string for limited number of parameters
2255: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2256: ['display','replyto','forward','markread','markdel','markunread',
2257: 'sendreply','compose','sendmail','critical','recname','recdom',
2258: 'recordftf','sortedby','block','folder','startdis','interdis',
2259: 'showcommentbaseurl','dismode']);
2260: $sqs='&sortedby='.$env{'form.sortedby'};
2261:
2262: # ------------------------------------------------------ They checked for email
2263: unless ($env{'form.block'}) {
2264: &Apache::lonnet::put('email_status',{'recnewemail'=>0});
2265: }
2266:
2267: # ----------------------------------------------------------------- Breadcrumbs
2268:
2269: &Apache::lonhtmlcommon::clear_breadcrumbs();
2270: &Apache::lonhtmlcommon::add_breadcrumb
2271: ({href=>"/adm/communicate",
2272: text=>"Communication/Messages",
2273: faq=>12,bug=>'Communication Tools',});
2274:
2275: # ------------------------------------------------------------------ Get Folder
2276:
2277: my $folder=$env{'form.folder'};
2278: unless ($folder) {
2279: $folder='';
2280: } else {
2281: $sqs.='&folder='.&Apache::lonnet::escape($folder);
2282: }
2283: # ------------------------------------------------------------ Get Display Mode
2284:
2285: my $dismode=$env{'form.dismode'};
2286: unless ($dismode) {
2287: $dismode='';
2288: } else {
2289: $sqs.='&dismode='.&Apache::lonnet::escape($dismode);
2290: }
2291:
2292: # --------------------------------------------------------------------- Display
2293:
2294: $startdis=$env{'form.startdis'};
2295: $startdis--;
2296: unless ($startdis) { $startdis=0; }
2297:
2298: $interdis=$env{'form.interdis'};
2299: unless ($interdis) { $interdis=20; }
2300: $sqs.='&interdis='.$interdis;
2301:
2302: if ($env{'form.firstview'}) {
2303: $startdis=0;
2304: }
2305: if ($env{'form.lastview'}) {
2306: $startdis=-1;
2307: }
2308: if ($env{'form.prevview'}) {
2309: $startdis--;
2310: }
2311: if ($env{'form.nextview'}) {
2312: $startdis++;
2313: }
2314: my $postedstartdis=$startdis+1;
2315: $sqs.='&startdis='.$postedstartdis;
2316:
2317: # --------------------------------------------------------------- Render Output
2318:
2319: if ($env{'form.display'}) {
2320: &displaymessage($r,$env{'form.display'},$folder);
2321: } elsif ($env{'form.replyto'}) {
2322: &compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode);
2323: } elsif ($env{'form.confirm'}) {
2324: &printheader($r,'','Confirmed Receipt');
2325: foreach (keys %env) {
2326: if ($_=~/^form\.rec\_(.*)$/) {
2327: $r->print('<b>'.&mt('Confirming Receipt').':</b> '.
2328: &user_crit_received($1).'<br>');
2329: }
2330: if ($_=~/^form\.reprec\_(.*)$/) {
2331: my $msgid=$1;
2332: $r->print('<b>'.&mt('Confirming Receipt').':</b> '.
2333: &user_crit_received($msgid).'<br>');
2334: &compout($r,'','','',$msgid);
2335: }
2336: }
2337: &discrit($r);
2338: } elsif ($env{'form.critical'}) {
2339: &printheader($r,'','Displaying Critical Messages');
2340: &discrit($r);
2341: } elsif ($env{'form.forward'}) {
2342: &compout($r,$env{'form.forward'},undef,undef,undef,$folder);
2343: } elsif ($env{'form.markdel'}) {
2344: &printheader($r,'','Deleted Message');
2345: &statuschange($env{'form.markdel'},'deleted',$folder);
2346: &Apache::loncommunicate::menu($r);
2347: &disall($r,($folder?$folder:$dismode));
2348: } elsif ($env{'form.markedmove'}) {
2349: my $total=0;
2350: foreach (keys %env) {
2351: if ($_=~/^form\.delmark_(.*)$/) {
2352: &movemsg(&Apache::lonnet::unescape($1),$folder,
2353: $env{'form.movetofolder'});
2354: $total++;
2355: }
2356: }
2357: &printheader($r,'','Moved Messages');
2358: $r->print('Moved '.$total.' message(s)<p>');
2359: &Apache::loncommunicate::menu($r);
2360: &disall($r,($folder?$folder:$dismode));
2361: } elsif ($env{'form.markeddel'}) {
2362: my $total=0;
2363: foreach (keys %env) {
2364: if ($_=~/^form\.delmark_(.*)$/) {
2365: &statuschange(&Apache::lonnet::unescape($1),'deleted',$folder);
2366: $total++;
2367: }
2368: }
2369: &printheader($r,'','Deleted Messages');
2370: $r->print('Deleted '.$total.' message(s)<p>');
2371: &Apache::loncommunicate::menu($r);
2372: &disall($r,($folder?$folder:$dismode));
2373: } elsif ($env{'form.markunread'}) {
2374: &printheader($r,'','Marked Message as Unread');
2375: &statuschange($env{'form.markunread'},'new');
2376: &Apache::loncommunicate::menu($r);
2377: &disall($r,($folder?$folder:$dismode));
2378: } elsif ($env{'form.compose'}) {
2379: &compout($r,'','',$env{'form.compose'});
2380: } elsif ($env{'form.recordftf'}) {
2381: &facetoface($r,$env{'form.recordftf'});
2382: } elsif ($env{'form.block'}) {
2383: &examblock($r,$env{'form.block'});
2384: } elsif ($env{'form.sendmail'}) {
2385: &sendoffmail($r,$folder);
2386: if ($env{'form.storebasecomment'}) {
2387: &storecomment($r);
2388: }
2389: if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
2390: &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
2391: $env{'course.'.$env{'request.course.id'}.'.domain'},
2392: 'Course_Announcements',
2393: $env{'form.subject'},
2394: $env{'form.message'},'/adm/communicate','public');
2395: }
2396: &disall($r,($folder?$folder:$dismode));
2397: } elsif ($env{'form.newfolder'}) {
2398: &printheader($r,'','New Folder');
2399: &makefolder($env{'form.newfolder'});
2400: &Apache::loncommunicate::menu($r);
2401: &disall($r,$env{'form.newfolder'});
2402: } elsif ($env{'form.showcommentbaseurl'}) {
2403: &storedcommentlisting($r);
2404: } else {
2405: &printheader($r,'','Display All Messages');
2406: &Apache::loncommunicate::menu($r);
2407: &disall($r,($folder?$folder:$dismode));
2408: }
2409: $r->print(&Apache::loncommon::endbodytag().'</html>');
2410: return OK;
2411: }
2412: # ================================================= Main program, reset counter
2413:
2414: BEGIN {
2415: $msgcount=0;
2416: }
2417:
2418: =pod
2419:
2420: =back
2421:
2422: =cut
2423:
2424: 1;
2425:
2426: __END__
2427:
2428:
2429:
2430:
2431:
2432:
2433:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>