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