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