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