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