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