Annotation of loncom/interface/lonmsgdisplay.pm, revision 1.32
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # Routines for messaging display
3: #
1.32 ! albertel 4: # $Id: lonmsgdisplay.pm,v 1.31 2006/06/12 22:55:23 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.30 raeburn 456: 'co' => 'Course/Group',
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.30 raeburn 625: $r->print('<a href = "?sortedby=course'.$fsqs.'">'.&mt('Course/Group').'</a>');
1.1 albertel 626: } else {
1.30 raeburn 627: $r->print('<a href = "?sortedby=revcourse'.$fsqs.'">'.&mt('Course/Group').'</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: }
886: $r->print('</form>'.
887: &Apache::lonfeedback::generate_preview_button('compemail','message').
888: &Apache::lonhtmlcommon::htmlareaselectactive('message'));
889: }
890:
891: # ---------------------------------------------------- Display all face to face
892:
893: sub retrieve_instructor_comments {
894: my ($user,$domain)=@_;
895: my $target=$env{'form.grade_target'};
896: if (! $env{'request.course.id'}) { return; }
897: if (! &Apache::lonnet::allowed('srm',$env{'request.course.id'})
898: && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
899: '/'.$env{'request.course.sec'})) {
900: return;
901: }
902: my %records=&Apache::lonnet::dump('nohist_email',
903: $env{'course.'.$env{'request.course.id'}.'.domain'},
904: $env{'course.'.$env{'request.course.id'}.'.num'},
905: '%255b'.$user.'%253a'.$domain.'%255d');
906: my $result='';
907: foreach (sort(keys(%records))) {
908: my %content=&Apache::lonmsg::unpackagemsg($records{$_});
909: next if ($content{'senderdomain'} eq '');
910: next if ($content{'subject'} !~ /^Record/);
911: # &Apache::lonfeedback::newline_to_br(\$content{'message'});
912: $result.='Recorded by '.
1.14 albertel 913: $content{'sendername'}.':'.$content{'senderdomain'}."\n";
1.1 albertel 914: $result.=
915: &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
916: }
917: return $result;
918: }
919:
920: sub disfacetoface {
921: my ($r,$user,$domain)=@_;
922: my $target=$env{'form.grade_target'};
923: unless ($env{'request.course.id'}) { return; }
924: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
925: && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
926: '/'.$env{'request.course.sec'})) {
927: $r->print('Not allowed');
928: return;
929: }
930: my %records=&Apache::lonnet::dump('nohist_email',
931: $env{'course.'.$env{'request.course.id'}.'.domain'},
932: $env{'course.'.$env{'request.course.id'}.'.num'},
933: '%255b'.$user.'%253a'.$domain.'%255d');
934: my $result='';
935: foreach (sort keys %records) {
936: my %content=&Apache::lonmsg::unpackagemsg($records{$_});
937: next if ($content{'senderdomain'} eq '');
938: &Apache::lonfeedback::newline_to_br(\$content{'message'});
939: if ($content{'subject'}=~/^Record/) {
940: $result.='<h3>'.&mt('Record').'</h3>';
941: } elsif ($content{'subject'}=~/^Broadcast/) {
942: $result .='<h3>'.&mt('Broadcast Message').'</h3>';
943: if ($content{'subject'}=~/^Broadcast\./) {
944: if (defined($content{'coursemsgid'})) {
1.29 www 945: my $crsmsgid = &escape($content{'coursemsgid'});
1.1 albertel 946: my $broadcast_message = &general_message($crsmsgid);
947: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$broadcast_message;
948: } else {
949: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
950: $content{'message'} =
951: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
952: $content{'message'};
953: }
954: }
955: } else {
956: $result.='<h3>'.&mt('Critical Message').'</h3>';
957: if (defined($content{'coursemsgid'})) {
1.29 www 958: my $crsmsgid=&escape($content{'coursemsgid'});
1.1 albertel 959: my $critical_message = &general_message($crsmsgid);
960: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$critical_message;
961: } else {
962: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
963: $content{'message'}=
964: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
965: $content{'message'};
966: }
967: }
968: $result.=&mt('By').': <b>'.
969: &Apache::loncommon::aboutmewrapper(
970: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14 albertel 971: $content{'sendername'}.':'.
1.1 albertel 972: $content{'senderdomain'}.') '.$content{'time'}.
973: '<br /><pre>'.
974: &Apache::lontexconvert::msgtexconverted($content{'message'}).
975: '</pre>';
976: }
977: # Check to see if there were any messages.
978: if ($result eq '') {
1.30 raeburn 979: my $lctype = 'course';
980: if (defined($env{'course.'.$env{'request.course.id'}.'.type'})) {
981: $lctype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
982: }
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.30 raeburn 1015: my $crstype = 'Course';
1016: my $leaders = 'faculty and staff';
1017: if (defined($env{'course.'.$env{'request.course.id'}.'.type'})) {
1018: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
1019: $leaders = 'coordinators and leaders';
1020: }
1.1 albertel 1021: &printheader($r,
1022: '/adm/email?recordftf=query',
1023: "User Notes, Face-to-Face, Critical Messages, Broadcast Messages");
1024: # from query string
1025:
1026: if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
1027: if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
1028:
1029: my $defdom=$env{'user.domain'};
1030: # already filled in
1031: if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
1032: # generate output
1033: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
1034: my $stdbrws = &Apache::loncommon::selectstudent_link
1035: ('stdselect','recuname','recdomain');
1036: my %lt=&Apache::lonlocal::texthash('user' => 'Username',
1037: 'dom' => 'Domain',
1.30 raeburn 1038: 'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, and Broadcast Messages in $crstype",
1.1 albertel 1039: 'subm' => 'Retrieve discussion and message records',
1.30 raeburn 1040: 'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')',
1.1 albertel 1041: 'post' => 'Post this Record');
1042: $r->print(<<"ENDTREC");
1043: <h3>$lt{'head'}</h3>
1044: <form method="post" action="/adm/email" name="stdselect">
1045: <input type="hidden" name="recordftf" value="retrieve" />
1046: <table>
1047: <tr><td>$lt{'user'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recuname'}" /></td>
1048: <td rowspan="2">
1049: $stdbrws
1050: <input type="submit" value="$lt{'subm'}" /></td>
1051: </tr>
1052: <tr><td>$lt{'dom'}:</td>
1053: <td>$domform</td></tr>
1054: </table>
1055: </form>
1056: ENDTREC
1057: if (($stage ne 'query') &&
1058: ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
1059: chomp($env{'form.newrecord'});
1060: if ($env{'form.newrecord'}) {
1.31 albertel 1061: &Apache::lonmsg::store_instructor_comment($env{'form.newrecord'},
1062: $env{'form.recuname'},
1063: $env{'form.recdomain'});
1.1 albertel 1064: }
1065: $r->print('<h3>'.&Apache::loncommon::plainname($env{'form.recuname'},
1066: $env{'form.recdomain'}).'</h3>');
1067: &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
1068: $r->print(<<ENDRHEAD);
1069: <form method="post" action="/adm/email">
1070: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
1071: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
1072: ENDRHEAD
1073: $r->print(<<ENDBFORM);
1074: <hr />$lt{'newr'}<br />
1075: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
1076: <br />
1077: <input type="hidden" name="recordftf" value="post" />
1078: <input type="submit" value="$lt{'post'}" />
1079: </form>
1080: ENDBFORM
1081: }
1082: }
1083:
1084: # ----------------------------------------------------------- Blocking during exams
1085:
1086: sub examblock {
1087: my ($r,$action) = @_;
1088: unless ($env{'request.course.id'}) { return;}
1089: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
1090: && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
1091: '/'.$env{'request.course.sec'})) {
1092: $r->print('Not allowed');
1093: return;
1094: }
1.30 raeburn 1095: my $usertype = 'students';
1096: if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Group') {
1097: $usertype = 'members';
1098: }
1.1 albertel 1099: my %lt=&Apache::lonlocal::texthash(
1100: 'comb' => 'Communication Blocking',
1101: 'cbds' => 'Communication blocking during scheduled exams',
1.30 raeburn 1102: '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 1103: 'mecb' => 'Modify existing communication blocking periods',
1104: 'ncbc' => 'No communication blocks currently stored'
1105: );
1106:
1107: my %ltext = &Apache::lonlocal::texthash(
1108: 'dura' => 'Duration',
1109: 'setb' => 'Set by',
1110: 'even' => 'Event',
1111: 'actn' => 'Action',
1112: 'star' => 'Start',
1113: 'endd' => 'End'
1114: );
1115:
1116: &printheader($r,'/adm/email?block=display',$lt{'comb'});
1117: $r->print('<h3>'.$lt{'cbds'}.'</h3>');
1118:
1119: if ($action eq 'store') {
1120: &blockstore($r);
1121: }
1122:
1123: $r->print($lt{'desc'}.'<br /><br />
1124: <form name="blockform" method="post" action="/adm/email?block=store">
1125: ');
1126:
1127: $r->print('<h4>'.$lt{'mecb'}.'</h4>');
1128: my %records = ();
1129: my $blockcount = 0;
1130: my $parmcount = 0;
1131: &get_blockdates(\%records,\$blockcount);
1132: if ($blockcount > 0) {
1133: $parmcount = &display_blocker_status($r,\%records,\%ltext);
1134: } else {
1135: $r->print($lt{'ncbc'}.'<br /><br />');
1136: }
1137: &display_addblocker_table($r,$parmcount,\%ltext);
1138: my $end_page=&Apache::loncommon::end_page();
1139: $r->print(<<"END");
1140: <br />
1141: <input type="hidden" name="blocktotal" value="$blockcount" />
1142: <input type ="submit" value="Save Changes" />
1143: </form>
1144: $end_page
1145: END
1146: return;
1147: }
1148:
1149: sub blockstore {
1150: my $r = shift;
1151: my %lt=&Apache::lonlocal::texthash(
1152: 'tfcm' => 'The following changes were made',
1153: 'cbps' => 'communication blocking period(s)',
1154: 'werm' => 'was/were removed',
1155: 'wemo' => 'was/were modified',
1156: 'wead' => 'was/were added',
1157: 'ncwm' => 'No changes were made.'
1158: );
1159: my %adds = ();
1160: my %removals = ();
1161: my %cancels = ();
1162: my $modtotal = 0;
1163: my $canceltotal = 0;
1164: my $addtotal = 0;
1165: my %blocking = ();
1166: $r->print('<h3>'.$lt{'head'}.'</h3>');
1167: foreach (keys %env) {
1168: if ($_ =~ m/^form\.modify_(\w+)$/) {
1169: $adds{$1} = $1;
1170: $removals{$1} = $1;
1171: $modtotal ++;
1172: } elsif ($_ =~ m/^form\.cancel_(\d+)$/) {
1173: $cancels{$1} = $1;
1174: unless ( defined($removals{$1}) ) {
1175: $removals{$1} = $1;
1176: $canceltotal ++;
1177: }
1178: } elsif ($_ =~ m/^form\.add_(\d+)$/) {
1179: $adds{$1} = $1;
1180: $addtotal ++;
1181: }
1182: }
1183:
1184: foreach (keys %removals) {
1185: my $hashkey = $env{'form.key_'.$_};
1186: &Apache::lonnet::del('comm_block',["$hashkey"],
1187: $env{'course.'.$env{'request.course.id'}.'.domain'},
1188: $env{'course.'.$env{'request.course.id'}.'.num'}
1189: );
1190: }
1191: foreach (keys %adds) {
1192: unless ( defined($cancels{$_}) ) {
1193: my ($newstart,$newend) = &get_dates_from_form($_);
1194: my $newkey = $newstart.'____'.$newend;
1.14 albertel 1195: $blocking{$newkey} = $env{'user.name'}.':'.$env{'user.domain'}.':'.$env{'form.title_'.$_};
1.1 albertel 1196: }
1197: }
1198: if ($addtotal + $modtotal > 0) {
1199: &Apache::lonnet::put('comm_block',\%blocking,
1200: $env{'course.'.$env{'request.course.id'}.'.domain'},
1201: $env{'course.'.$env{'request.course.id'}.'.num'}
1202: );
1203: }
1204: my $chgestotal = $canceltotal + $modtotal + $addtotal;
1205: if ($chgestotal > 0) {
1206: $r->print($lt{'tfcm'}.'<ul>');
1207: if ($canceltotal > 0) {
1208: $r->print('<li>'.$canceltotal.' '.$lt{'cbps'},' '.$lt{'werm'}.'</li>');
1209: }
1210: if ($modtotal > 0) {
1211: $r->print('<li>'.$modtotal.' '.$lt{'cbps'},' '.$lt{'wemo'}.'</li>');
1212: }
1213: if ($addtotal > 0) {
1214: $r->print('<li>'.$addtotal.' '.$lt{'cbps'},' '.$lt{'wead'}.'</li>');
1215: }
1216: $r->print('</ul>');
1217: } else {
1218: $r->print($lt{'ncwm'});
1219: }
1220: $r->print('<br />');
1221: return;
1222: }
1223:
1224: sub get_dates_from_form {
1225: my $item = shift;
1226: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
1227: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
1228: return ($startdate,$enddate);
1229: }
1230:
1231: sub get_blockdates {
1232: my ($records,$blockcount) = @_;
1233: $$blockcount = 0;
1234: %{$records} = &Apache::lonnet::dump('comm_block',
1235: $env{'course.'.$env{'request.course.id'}.'.domain'},
1236: $env{'course.'.$env{'request.course.id'}.'.num'}
1237: );
1.15 albertel 1238: $$blockcount = keys(%{$records});
1239:
1240: if ((keys(%{$records}))[0] =~ /^error: 2 /) {
1241: $records = {};
1242: $$blockcount = 0;
1.1 albertel 1243: }
1244: }
1245:
1246: sub display_blocker_status {
1247: my ($r,$records,$ltext) = @_;
1248: my $parmcount = 0;
1.16 albertel 1249:
1.1 albertel 1250: my %lt = &Apache::lonlocal::texthash(
1251: 'modi' => 'Modify',
1252: 'canc' => 'Cancel',
1253: );
1.18 albertel 1254: $r->print(&Apache::loncommon::start_data_table());
1.1 albertel 1255: $r->print(<<"END");
1.16 albertel 1256: <tr>
1257: <th>$$ltext{'dura'}</th>
1258: <th>$$ltext{'setb'}</th>
1259: <th>$$ltext{'even'}</th>
1260: <th>$$ltext{'actn'}?</th>
1261: </tr>
1.1 albertel 1262: END
1.18 albertel 1263: foreach my $record (sort(keys(%{$records}))) {
1.1 albertel 1264: my $onchange = 'onFocus="javascript:window.document.forms['.
1265: "'blockform'].elements['modify_".$parmcount."'].".
1266: 'checked=true;"';
1.18 albertel 1267: my ($start,$end) = split(/____/,$record);
1.1 albertel 1268: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
1269: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1.15 albertel 1270:
1.18 albertel 1271: my ($setuname,$setudom,$title) =
1272: &parse_block_record($$records{$record});
1.21 albertel 1273: $title = &HTML::Entities::encode($title,'"<>&');
1.1 albertel 1274: my $settername = &Apache::loncommon::plainname($setuname,$setudom);
1.18 albertel 1275: $r->print(&Apache::loncommon::start_data_table_row());
1.1 albertel 1276: $r->print(<<"END");
1277: <td>$$ltext{'star'}: $startform<br/>$$ltext{'endd'}: $endform</td>
1278: <td>$settername</td>
1.18 albertel 1279: <td><input type="text" name="title_$parmcount" size="15" value="$title" /><input type="hidden" name="key_$parmcount" value="$record" /></td>
1.1 albertel 1280: <td><label>$lt{'modi'}? <input type="checkbox" name="modify_$parmcount" /></label><br /><label>$lt{'canc'}? <input type="checkbox" name="cancel_$parmcount" /></label>
1281: END
1.18 albertel 1282: $r->print(&Apache::loncommon::end_data_table_row());
1283: $parmcount++;
1.1 albertel 1284: }
1285: $r->print(<<"END");
1286: </table>
1287: <br />
1288: <br />
1289: END
1290: return $parmcount;
1291: }
1292:
1.15 albertel 1293: sub parse_block_record {
1294: my ($record) = @_;
1295: my ($setuname,$setudom,$title);
1296: my @data = split(/:/,$record,3);
1297: if (scalar(@data) eq 2) {
1298: $title = $data[1];
1299: ($setuname,$setudom) = split(/@/,$data[0]);
1300: } else {
1301: ($setuname,$setudom,$title) = @data;
1302: }
1303: return ($setuname,$setudom,$title);
1304: }
1305:
1.1 albertel 1306: sub display_addblocker_table {
1307: my ($r,$parmcount,$ltext) = @_;
1308: my $start = time;
1309: my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
1310: my $onchange = 'onFocus="javascript:window.document.forms['.
1311: "'blockform'].elements['add_".$parmcount."'].".
1312: 'checked=true;"';
1313: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
1314: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1315: my %lt = &Apache::lonlocal::texthash(
1316: 'addb' => 'Add block',
1317: 'exam' => 'e.g., Exam 1',
1318: 'addn' => 'Add new communication blocking periods'
1319: );
1320: $r->print(<<"END");
1321: <h4>$lt{'addn'}</h4>
1.18 albertel 1322: END
1323: $r->print(&Apache::loncommon::start_data_table());
1324: $r->print(<<"END");
1.16 albertel 1325: <tr>
1326: <th>$$ltext{'dura'}</th>
1327: <th>$$ltext{'even'} $lt{'exam'}</th>
1328: <th>$$ltext{'actn'}?</th>
1329: </tr>
1.18 albertel 1330: END
1331: $r->print(&Apache::loncommon::start_data_table_row());
1332: $r->print(<<"END");
1.16 albertel 1333: <td>$$ltext{'star'}: $startform<br />$$ltext{'endd'}: $endform</td>
1334: <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
1335: <td><label>$lt{'addb'}? <input type="checkbox" name="add_$parmcount" value="1" /></label></td>
1.1 albertel 1336: END
1.18 albertel 1337: $r->print(&Apache::loncommon::end_data_table_row());
1338: $r->print(&Apache::loncommon::end_data_table());
1.1 albertel 1339: return;
1340: }
1341:
1342: sub blockcheck {
1343: my ($setters,$startblock,$endblock) = @_;
1344: # Retrieve active student roles and active course coordinator/instructor roles
1.15 albertel 1345: my %live_courses =
1346: map { $_ => 1} &Apache::loncommon::findallcourses();
1347: # FIXME should really probe for apriv, but ::allowed can only probe the
1348: # currently active role
1349: my %staff_of =
1350: map { $_ => 1} &Apache::loncommon::findallcourses(['cc','in']);
1351:
1352: # Retrieve blocking times and identity of blocker for active courses
1353: # for students.
1354: return if (!%live_courses);
1355:
1356: foreach my $course (keys(%live_courses)) {
1.19 albertel 1357: my $cdom = $env{'course.'.$course.'.domain'};
1358: my $cnum = $env{'course.'.$course.'.num'};
1.15 albertel 1359:
1360: # if they are a staff member and are currently not playing student
1361: next if ( $staff_of{$course}
1362: && ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
1363:
1364: $setters->{$course} = {};
1365: $setters->{$course}{'staff'} = [];
1366: $setters->{$course}{'times'} = [];
1367: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
1368: foreach my $record (keys %records) {
1369: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
1370: if ($start <= time && $end >= time) {
1371: my ($staff_name,$staff_dom,$title) =
1372: &parse_block_record($records{$record});
1373: push(@{$$setters{$course}{'staff'}}, [$staff_name,$staff_dom]);
1374: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1375: if ( ($$startblock == 0) || ($$startblock > $1) ) {
1376: $$startblock = $1;
1377: }
1378: if ( ($$endblock == 0) || ($$endblock < $2) ) {
1379: $$endblock = $2;
1380: }
1381: }
1382: }
1.1 albertel 1383: }
1384: }
1385:
1386: sub build_block_table {
1387: my ($r,$startblock,$endblock,$setters) = @_;
1388: my %lt = &Apache::lonlocal::texthash(
1389: 'cacb' => 'Currently active communication blocks',
1.30 raeburn 1390: 'cour' => 'Course/Group',
1.1 albertel 1391: 'dura' => 'Duration',
1392: 'blse' => 'Block set by'
1.18 albertel 1393: );
1394: $r->print(<<"END");
1395: <br /><br />$lt{'cacb'}:<br /><br />
1396: END
1397: $r->print(&Apache::loncommon::start_data_table());
1.1 albertel 1398: $r->print(<<"END");
1.16 albertel 1399: <tr>
1400: <th>$lt{'cour'}</th>
1401: <th>$lt{'dura'}</th>
1402: <th>$lt{'blse'}</th>
1403: </tr>
1.1 albertel 1404: END
1.18 albertel 1405: foreach my $course (keys(%{$setters})) {
1406: my %courseinfo=&Apache::lonnet::coursedescription($course);
1407: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
1408: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.1 albertel 1409: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1.18 albertel 1410: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
1.1 albertel 1411: $openblock = &Apache::lonlocal::locallocaltime($openblock);
1412: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
1.18 albertel 1413: $r->print(&Apache::loncommon::start_data_table_row().
1414: '<td>'.$courseinfo{'description'}.'</td>'.
1.1 albertel 1415: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.14 albertel 1416: '<td>'.$fullname.' ('.$uname.':'.$udom.
1.18 albertel 1417: ')</td>'.
1418: &Apache::loncommon::end_data_table_row());
1.1 albertel 1419: }
1420: }
1.18 albertel 1421: $r->print(&Apache::loncommon::end_data_table());
1.1 albertel 1422: }
1423:
1424: # ----------------------------------------------------------- Display a message
1425:
1426: sub displaymessage {
1427: my ($r,$msgid,$folder)=@_;
1428: my $suffix=&Apache::lonmsg::foldersuffix($folder);
1429: my %blocked = ();
1430: my %setters = ();
1431: my $startblock = 0;
1432: my $endblock = 0;
1433: my $numblocked = 0;
1.30 raeburn 1434: my $crstype = 'Course';
1435: if (defined($env{'course.'.$env{'request.course.id'}.'.type'})) {
1436: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
1437: }
1438:
1.1 albertel 1439: # info to generate "next" and "previous" buttons and check if message is blocked
1440: &blockcheck(\%setters,\$startblock,\$endblock);
1441: my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder);
1442: if ( $blocked{$msgid} eq 'ON' ) {
1443: &printheader($r,'/adm/email',&mt('Display a Message'));
1444: $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.'));
1445: &build_block_table($r,$startblock,$endblock,\%setters);
1446: return;
1447: }
1448: &statuschange($msgid,'read',$folder);
1449: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1450: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid});
1451:
1452: my $counter=0;
1453: $r->print('<pre>');
1.29 www 1454: my $escmsgid=&escape($msgid);
1.1 albertel 1455: foreach (@messages) {
1456: if ($_->[5] eq $escmsgid){
1457: last;
1458: }
1459: $counter++;
1460: }
1461: $r->print('</pre>');
1462: my $number_of_messages = scalar(@messages); #subtract 1 for last index
1463: # start output
1.29 www 1464: &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'});
1.1 albertel 1465: my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'});
1466: # Functions
1467: $r->print('<table border="2" width="100%"><tr bgcolor="#FFFFAA"><td>'.&mt('Functions').':</td>'.
1.29 www 1468: '<td><a href="/adm/email?replyto='.&escape($msgid).$sqs.
1.1 albertel 1469: '"><b>'.&mt('Reply').'</b></a></td>'.
1.29 www 1470: '<td><a href="/adm/email?forward='.&escape($msgid).$sqs.
1.1 albertel 1471: '"><b>'.&mt('Forward').'</b></a></td>'.
1.29 www 1472: '<td><a href="/adm/email?markunread='.&escape($msgid).$sqs.
1.1 albertel 1473: '"><b>'.&mt('Mark Unread').'</b></a></td>'.
1.29 www 1474: '<td><a href="/adm/email?markdel='.&escape($msgid).$sqs.
1.1 albertel 1475: '"><b>'.&mt('Delete').'</b></a></td>'.
1476: '<td><a href="/adm/email?'.$sqs.
1477: ($env{'form.dismode'} eq 'new'?'&folder=new':'').
1478: '"><b>'.&mt('Back to Folder Display').'</b></a></td>');
1479: if ($counter > 0){
1480: $r->print('<td><a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.
1481: '"><b>'.&mt('Previous').'</b></a></td>');
1482: }
1483: if ($counter < $number_of_messages - 1){
1484: $r->print('<td><a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.
1485: '"><b>'.&mt('Next').'</b></a></td>');
1486: }
1487: $r->print('</tr></table>');
1488: if ($env{'user.adv'}) {
1489: $r->print('<table border="2" width="100%"><tr bgcolor="#FFAAAA"><td>'.&mt('Currently available actions (will open extra window)').':</td>');
1490: my $symb=&Apache::lonnet::symbread($content{'baseurl'});
1491: if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
1492: $r->print('<td><b>'.&Apache::loncommon::track_student_link(&mt('View recent activity'),$content{'sendername'},$content{'senderdomain'},'check').'</b></td>');
1493: }
1494: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
1495: $r->print('<td><b>'.&Apache::loncommon::pprmlink(&mt('Set/Change parameters'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
1496: }
1497: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
1498: $r->print('<td><b>'.&Apache::loncommon::pgrdlink(&mt('Set/Change grades'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
1499: }
1500: $r->print('</tr></table>');
1501: }
1502: my $tolist;
1503: my @recipients = ();
1504: for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
1505: $recipients[$i] = &Apache::loncommon::aboutmewrapper(
1506: &Apache::loncommon::plainname($content{'recuser'}[$i],
1507: $content{'recdomain'}[$i]),
1508: $content{'recuser'}[$i],$content{'recdomain'}[$i]).
1509: ' ('.$content{'recuser'}[$i].' at '.$content{'recdomain'}[$i].') ';
1510: }
1511: $tolist = join(', ',@recipients);
1512: $r->print('<br /><b>'.&mt('Subject').':</b> '.$content{'subject'}.
1513: ($folder ne 'sent'?'<br /><b>'.&mt('From').':</b> '.
1514: &Apache::loncommon::aboutmewrapper(
1515: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
1516: $content{'sendername'},$content{'senderdomain'}).' ('.
1517: $content{'sendername'}.' at '.
1518: $content{'senderdomain'}.') ':'<br /><b>'.&mt('To').':</b> '.
1519: $tolist).
1.30 raeburn 1520: ($content{'courseid'}?'<br /><b>'.&mt($crstype).':</b> '.$courseinfo{'description'}.
1521: ($content{'coursesec'}?' ('.&mt('Section').': '.$content{'coursesec'}.')':''):'').
1.1 albertel 1522: '<br /><b>'.&mt('Time').':</b> '.$content{'time'}.
1523: ($content{'baseurl'}?'<br /><b>'.&mt('Refers to').':</b> <a href="'.$content{'baseurl'}.'">'.
1524: $content{'baseurl'}.' ('.&Apache::lonnet::gettitle($content{'baseurl'}).')</a>':'').
1525: '<p><pre>'.
1526: &Apache::lontexconvert::msgtexconverted($content{'message'},1).
1527: '</pre><hr />'.&displayresource(%content).'</p>');
1528: return;
1529: }
1530:
1531: # =========================================================== Show the citation
1532:
1533: sub displayresource {
1534: my %content=@_;
1535: #
1536: # If the recipient is in the same course that the message was sent from and
1537: # has sufficient privileges, show "all details," else show citation
1538: #
1539: if (($env{'request.course.id'} eq $content{'courseid'})
1540: && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
1541: my $symb=&Apache::lonnet::symbread($content{'baseurl'});
1542: # Could not get a symb, give up
1543: unless ($symb) { return $content{'citation'}; }
1544: # Have a symb, can render
1545: return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
1546: &Apache::loncommon::get_previous_attempt($symb,
1547: $content{'sendername'},
1548: $content{'senderdomain'},
1549: $content{'courseid'}).
1550: '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
1551: &Apache::loncommon::get_student_view($symb,
1552: $content{'sendername'},
1553: $content{'senderdomain'},
1554: $content{'courseid'}).
1555: '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
1556: &Apache::loncommon::get_student_answers($symb,
1557: $content{'sendername'},
1558: $content{'senderdomain'},
1559: $content{'courseid'});
1560: } elsif ($env{'user.adv'}) {
1561: return $content{'citation'};
1562: }
1563: return '';
1564: }
1565:
1566: # ================================================================== The Header
1567:
1568: sub header {
1569: my ($r,$title,$baseurl)=@_;
1570:
1571: my $extra = &Apache::loncommon::studentbrowser_javascript();
1572: if ($baseurl) {
1573: $extra .= "<base href=\"http://$ENV{'SERVER_NAME'}/$baseurl\" />";
1574: }
1575: $r->print(&Apache::loncommon::start_page('Communication and Messages',
1576: $extra));
1577: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.22 albertel 1578: (($title?$title:'Communication and Messages')));
1.1 albertel 1579:
1580: }
1581:
1582: # ---------------------------------------------------------------- Print header
1583:
1584: sub printheader {
1585: my ($r,$url,$desc,$title,$baseurl)=@_;
1586: &Apache::lonhtmlcommon::add_breadcrumb
1587: ({href=>$url,
1588: text=>$desc});
1589: &header($r,$title,$baseurl);
1590: }
1591:
1592: # ------------------------------------------------------------ Store the comment
1593:
1594: sub storecomment {
1595: my ($r)=@_;
1596: my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
1597: my $cleanmsgtxt='';
1598: foreach (split(/[\n\r]/,$msgtxt)) {
1599: unless ($_=~/^\s*(\>|\>\;)/) {
1600: $cleanmsgtxt.=$_."\n";
1601: }
1602: }
1.29 www 1603: my $key=&escape($env{'form.baseurl'}).'___'.time;
1.1 albertel 1604: &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
1605: }
1606:
1607: sub storedcommentlisting {
1608: my ($r)=@_;
1609: my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
1.29 www 1610: '^'.&escape(&escape($env{'form.showcommentbaseurl'})));
1.1 albertel 1611: $r->print(&Apache::loncommon::start_page('Stored Comment Listing',undef,
1612: {'onlybody' => 1}));
1613: if ((keys %msgs)[0]=~/^error\:/) {
1614: $r->print(&mt('No stored comments yet.'));
1615: } else {
1616: my $found=0;
1617: foreach (sort keys %msgs) {
1618: $r->print("\n".$msgs{$_}."<hr />");
1619: $found=1;
1620: }
1621: unless ($found) {
1622: $r->print(&mt('No stored comments yet for this resource.'));
1623: }
1624: }
1625: }
1626:
1627: # ---------------------------------------------------------------- Send an email
1628:
1629: sub sendoffmail {
1630: my ($r,$folder)=@_;
1631: my $suffix=&Apache::lonmsg::foldersuffix($folder);
1632: my $sendstatus='';
1633: my %specialmsg_status;
1634: my $numspecial = 0;
1635: if ($env{'form.send'}) {
1636: &printheader($r,'','Messages being sent.');
1637: $r->rflush();
1638: my %content=();
1639: undef %content;
1640: if ($env{'form.forwid'}) {
1641: my $msgid=$env{'form.forwid'};
1642: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1643: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
1644: &statuschange($msgid,'forwarded',$folder);
1645: $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
1646: $content{'message'};
1647: }
1648: if ($env{'form.replyid'}) {
1649: my $msgid=$env{'form.replyid'};
1650: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1651: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
1652: &statuschange($msgid,'replied',$folder);
1653: }
1.13 albertel 1654:
1.25 foxr 1655: my $to = $env{'form.selectedusers.forminput'};
1656: my $mode = $env{'form.sendmode'};
1657:
1.13 albertel 1658: my %toaddr;
1.25 foxr 1659: if ($to) {
1660: foreach my $dest (@$to) {
1.27 albertel 1661: my ($user,$domain) = split(/:/, $dest);
1.25 foxr 1662: if (($user ne '') && ($domain ne '')) {
1663: my $address = $user.":".$domain; # How the code below expects it.
1664: $toaddr{$address} = '';
1665: }
1666: }
1667: }
1668:
1.1 albertel 1669: if ($env{'form.sendmode'} eq 'group') {
1.25 foxr 1670: foreach my $address (keys(%env)) {
1671: if ($address=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
1672: $toaddr{$1}='';
1673: }
1.1 albertel 1674: }
1675: } elsif ($env{'form.sendmode'} eq 'upload') {
1.13 albertel 1676: foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
1677: my ($rec,$txt)=split(/\s*\:\s*/,$line);
1.1 albertel 1678: if ($txt) {
1679: $rec=~s/\@/\:/;
1680: $toaddr{$rec}.=$txt."\n";
1681: }
1682: }
1683: } else {
1.25 foxr 1684: if (($env{'form.recuname'} ne '') && ($env{'form.recdomain'} ne '')) {
1685: $toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
1686: }
1.1 albertel 1687: }
1688: if ($env{'form.additionalrec'}) {
1689: foreach (split(/\,/,$env{'form.additionalrec'})) {
1690: my ($auname,$audom)=split(/\@/,$_);
1.25 foxr 1691: if (($auname ne "") && ($audom ne "")) {
1692: $toaddr{$auname.':'.$audom}='';
1693: }
1.1 albertel 1694: }
1695: }
1696:
1697: my $savemsg;
1698: my $msgtype;
1699: my %sentmessage;
1.7 albertel 1700: my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'},
1701: undef,1);
1.1 albertel 1702: if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
1703: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
1704: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
1705: '/'.$env{'request.course.sec'})
1706: )) {
1707: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
1708: $msgtype = 'critical';
1709: } else {
1710: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
1711: }
1712:
1.13 albertel 1713: foreach my $address (sort(keys(%toaddr))) {
1714: my ($recuname,$recdomain)=split(/\:/,$address);
1.1 albertel 1715: my $msgtxt = $savemsg;
1.13 albertel 1716: if ($toaddr{$address}) { $msgtxt.='<hr />'.$toaddr{$address}; }
1.12 albertel 1717: my @thismsg;
1.1 albertel 1718: if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
1719: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
1720: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
1721: '/'.$env{'request.course.sec'}))) {
1.13 albertel 1722: $r->print(&mt('Sending critical message').' '.$recuname.':'.$recdomain.': ');
1723: @thismsg=
1724: &Apache::lonmsg::user_crit_msg($recuname,$recdomain,
1725: $msgsubj,$msgtxt,
1726: $env{'form.sendbck'},
1727: $env{'form.permanent'},
1728: \$sentmessage{$address});
1.1 albertel 1729: } else {
1.14 albertel 1730: $r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': ');
1.13 albertel 1731: @thismsg=
1732: &Apache::lonmsg::user_normal_msg($recuname,$recdomain,
1733: $msgsubj,$msgtxt,
1734: $content{'citation'},
1735: undef,undef,
1736: $env{'form.permanent'},
1737: \$sentmessage{$address});
1.1 albertel 1738: }
1739: if (($env{'request.course.id'}) && (($msgtype eq 'critical') ||
1740: ($env{'form.sendmode'} eq 'group'))) {
1.12 albertel 1741: $specialmsg_status{$recuname.':'.$recdomain} =
1742: join(' ',@thismsg);
1743: foreach my $result (@thismsg) {
1744: if ($result eq 'ok') {
1745: $numspecial++;
1746: }
1747: }
1.1 albertel 1748: }
1.12 albertel 1749: $sendstatus.=' '.join(' ',@thismsg);
1.1 albertel 1750: }
1751: if (($env{'request.course.id'}) && (($env{'form.sendmode'} eq 'group')
1752: || ($msgtype eq 'critical'))) {
1753: my $subj_prefix;
1754: if ($msgtype eq 'critical') {
1755: $subj_prefix = 'Critical.';
1756: } else {
1757: $subj_prefix = 'Broadcast.';
1758: }
1759: my ($specialmsgid,$specialresult);
1760: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1761: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.29 www 1762: my $course_str = &escape('['.$cnum.':'.$cdom.']');
1.1 albertel 1763:
1764: if ($numspecial) {
1765: $specialresult = &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
1766: ' '.$course_str,$savemsg,undef,undef,undef,
1767: undef,undef,\$specialmsgid);
1.29 www 1768: $specialmsgid = &unescape($specialmsgid);
1.1 albertel 1769: }
1770: if ($specialresult eq 'ok') {
1771: my $record_sent;
1.13 albertel 1772: my @recusers;
1773: my @recudoms;
1774: my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
1.29 www 1775: split(/\:/,&unescape($specialmsgid));
1.13 albertel 1776:
1.1 albertel 1777: foreach my $recipient (sort(keys(%toaddr))) {
1778: if ($specialmsg_status{$recipient} eq 'ok') {
1779: my $usersubj = $subj_prefix.'['.$recipient.']';
1780: my $usermsgid =
1781: &Apache::lonmsg::buildmsgid($stamp,$usersubj,
1782: $msgname,$msgdom,
1783: $msgcount,$context,
1784: $pid);
1785: &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
1786: ' ['.$recipient.']',$msgsubj,undef,
1787: undef,undef,undef,$usermsgid,undef,undef,$specialmsgid);
1.13 albertel 1788: my ($uname,$udom) = split(/:/,$recipient);
1.1 albertel 1789: push(@recusers,$uname);
1790: push(@recudoms,$udom);
1791: }
1792: }
1793: if (@recusers) {
1794: my $specialmessage;
1.13 albertel 1795: my $sentsubj =
1796: $subj_prefix.' ('.$numspecial.' sent) '.$msgsubj;
1.1 albertel 1797: $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
1798: my $sentmsgid =
1799: &Apache::lonmsg::buildmsgid($stamp,$sentsubj,$msgname,
1800: $msgdom,$msgcount,$context,
1801: $pid);
1802: ($specialmsgid,$specialmessage) = &Apache::lonmsg::packagemsg($msgsubj,$savemsg,
1803: undef,undef,undef,\@recusers,\@recudoms,$sentmsgid);
1804: $record_sent = &Apache::lonmsg::store_sent_mail($specialmsgid,$specialmessage);
1805: }
1806: } else {
1807: &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');
1808: }
1809: }
1810: } else {
1811: &printheader($r,'','No messages sent.');
1812: }
1813: if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
1.5 albertel 1814: $r->print('<br /><span class="LC_success">'.&mt('Completed.').'</span>');
1.1 albertel 1815: if ($env{'form.displayedcrit'}) {
1816: &discrit($r);
1817: } else {
1818: &Apache::loncommunicate::menu($r);
1819: }
1820: } else {
1.5 albertel 1821: $r->print('<p><span class="LC_error">'.&mt('Could not deliver message').'</span> '.
1.25 foxr 1822: &mt('Please use the browser "Back" button and correct the recipient addresses '."($sendstatus)").'</p>');
1.1 albertel 1823: }
1824: }
1825:
1826: # ===================================================================== Handler
1827:
1828: sub handler {
1829: my $r=shift;
1830:
1831: # ----------------------------------------------------------- Set document type
1832:
1833: &Apache::loncommon::content_type($r,'text/html');
1834: $r->send_http_header;
1835:
1836: return OK if $r->header_only;
1837:
1838: # --------------------------- Get query string for limited number of parameters
1839: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1840: ['display','replyto','forward','markread','markdel','markunread',
1841: 'sendreply','compose','sendmail','critical','recname','recdom',
1842: 'recordftf','sortedby','block','folder','startdis','interdis',
1.23 www 1843: 'showcommentbaseurl','dismode','group','subject','text']);
1.1 albertel 1844: $sqs='&sortedby='.$env{'form.sortedby'};
1845:
1846: # ------------------------------------------------------ They checked for email
1847: unless ($env{'form.block'}) {
1848: &Apache::lonnet::put('email_status',{'recnewemail'=>0});
1849: }
1850:
1851: # ----------------------------------------------------------------- Breadcrumbs
1852:
1853: &Apache::lonhtmlcommon::clear_breadcrumbs();
1854: &Apache::lonhtmlcommon::add_breadcrumb
1855: ({href=>"/adm/communicate",
1856: text=>"Communication/Messages",
1857: faq=>12,bug=>'Communication Tools',});
1858:
1859: # ------------------------------------------------------------------ Get Folder
1860:
1861: my $folder=$env{'form.folder'};
1862: unless ($folder) {
1863: $folder='';
1864: } else {
1.29 www 1865: $sqs.='&folder='.&escape($folder);
1.1 albertel 1866: }
1867: # ------------------------------------------------------------ Get Display Mode
1868:
1869: my $dismode=$env{'form.dismode'};
1870: unless ($dismode) {
1871: $dismode='';
1872: } else {
1.29 www 1873: $sqs.='&dismode='.&escape($dismode);
1.1 albertel 1874: }
1875:
1876: # --------------------------------------------------------------------- Display
1877:
1878: $startdis=$env{'form.startdis'};
1879: $startdis--;
1880: unless ($startdis) { $startdis=0; }
1881:
1882: $interdis=$env{'form.interdis'};
1883: unless ($interdis) { $interdis=20; }
1884: $sqs.='&interdis='.$interdis;
1885:
1886: if ($env{'form.firstview'}) {
1887: $startdis=0;
1888: }
1889: if ($env{'form.lastview'}) {
1890: $startdis=-1;
1891: }
1892: if ($env{'form.prevview'}) {
1893: $startdis--;
1894: }
1895: if ($env{'form.nextview'}) {
1896: $startdis++;
1897: }
1898: my $postedstartdis=$startdis+1;
1899: $sqs.='&startdis='.$postedstartdis;
1900:
1901: # --------------------------------------------------------------- Render Output
1902:
1903: if ($env{'form.display'}) {
1904: &displaymessage($r,$env{'form.display'},$folder);
1905: } elsif ($env{'form.replyto'}) {
1906: &compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode);
1907: } elsif ($env{'form.confirm'}) {
1908: &printheader($r,'','Confirmed Receipt');
1909: foreach (keys %env) {
1910: if ($_=~/^form\.rec\_(.*)$/) {
1911: $r->print('<b>'.&mt('Confirming Receipt').':</b> '.
1912: &Apache::lonmsg::user_crit_received($1).'<br>');
1913: }
1914: if ($_=~/^form\.reprec\_(.*)$/) {
1915: my $msgid=$1;
1916: $r->print('<b>'.&mt('Confirming Receipt').':</b> '.
1917: &Apache::lonmsg::user_crit_received($msgid).'<br>');
1918: &compout($r,'','','',$msgid);
1919: }
1920: }
1921: &discrit($r);
1922: } elsif ($env{'form.critical'}) {
1923: &printheader($r,'','Displaying Critical Messages');
1924: &discrit($r);
1925: } elsif ($env{'form.forward'}) {
1926: &compout($r,$env{'form.forward'},undef,undef,undef,$folder);
1927: } elsif ($env{'form.markdel'}) {
1928: &printheader($r,'','Deleted Message');
1.9 albertel 1929: my ($result,$msg) =
1930: &statuschange($env{'form.markdel'},'deleted',$folder);
1931: if (!$result) {
1.10 albertel 1932: $r->print('<p class="LC_error">'.
1933: &mt('Failed to delete the message.').'</p>'.
1.9 albertel 1934: '<p class="LC_error">'.$msg."</p>\n");
1935: }
1.1 albertel 1936: &Apache::loncommunicate::menu($r);
1937: &disall($r,($folder?$folder:$dismode));
1938: } elsif ($env{'form.markedmove'}) {
1.9 albertel 1939: my ($total,$failed,@failed_msg)=(0,0);
1940: foreach my $key (keys(%env)) {
1941: if ($key=~/^form\.delmark_(.*)$/) {
1942: my ($result,$msg) =
1.29 www 1943: &movemsg(&unescape($1),$folder,
1.9 albertel 1944: $env{'form.movetofolder'});
1945: if ($result) {
1946: $total++;
1947: } else {
1948: $failed++;
1949: push(@failed_msg,$msg);
1950: }
1.1 albertel 1951: }
1952: }
1953: &printheader($r,'','Moved Messages');
1.9 albertel 1954: if ($failed) {
1955: $r->print('<p class="LC_error">
1.10 albertel 1956: '.&mt('Failed to move [_1] message(s)',$failed).
1957: '</p>');
1.9 albertel 1958: $r->print('<p class="LC_error">'.
1959: join("</p>\n<p class=\"LC_error\">",@failed_msg).
1960: "</p>\n");
1961: }
1.10 albertel 1962: $r->print(&mt('Moved [_1] message(s)',$total).'<p>');
1.1 albertel 1963: &Apache::loncommunicate::menu($r);
1964: &disall($r,($folder?$folder:$dismode));
1965: } elsif ($env{'form.markeddel'}) {
1.9 albertel 1966: my ($total,$failed,@failed_msg)=(0,0);
1967: foreach my $key (keys(%env)) {
1968: if ($key=~/^form\.delmark_(.*)$/) {
1969: my ($result,$msg) =
1.29 www 1970: &statuschange(&unescape($1),'deleted',
1.9 albertel 1971: $folder);
1972: if ($result) {
1973: $total++;
1974: } else {
1975: $failed++;
1976: push(@failed_msg,$msg);
1977: }
1.1 albertel 1978: }
1979: }
1980: &printheader($r,'','Deleted Messages');
1.9 albertel 1981: if ($failed) {
1982: $r->print('<p class="LC_error">
1.10 albertel 1983: '.&mt('Failed to delete [_1] message(s)',$failed).
1984: '</p>');
1.9 albertel 1985: $r->print('<p class="LC_error">'.
1986: join("</p>\n<p class=\"LC_error\">",@failed_msg).
1987: "</p>\n");
1988: }
1.10 albertel 1989: $r->print(&mt('Deleted [_1] message(s)',$total).'<p>');
1.1 albertel 1990: &Apache::loncommunicate::menu($r);
1991: &disall($r,($folder?$folder:$dismode));
1992: } elsif ($env{'form.markunread'}) {
1993: &printheader($r,'','Marked Message as Unread');
1994: &statuschange($env{'form.markunread'},'new');
1995: &Apache::loncommunicate::menu($r);
1996: &disall($r,($folder?$folder:$dismode));
1997: } elsif ($env{'form.compose'}) {
1998: &compout($r,'','',$env{'form.compose'});
1999: } elsif ($env{'form.recordftf'}) {
2000: &facetoface($r,$env{'form.recordftf'});
2001: } elsif ($env{'form.block'}) {
2002: &examblock($r,$env{'form.block'});
2003: } elsif ($env{'form.sendmail'}) {
2004: &sendoffmail($r,$folder);
2005: if ($env{'form.storebasecomment'}) {
2006: &storecomment($r);
2007: }
2008: if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
2009: &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
2010: $env{'course.'.$env{'request.course.id'}.'.domain'},
2011: 'Course_Announcements',
2012: $env{'form.subject'},
2013: $env{'form.message'},'/adm/communicate','public');
2014: }
2015: &disall($r,($folder?$folder:$dismode));
2016: } elsif ($env{'form.newfolder'}) {
2017: &printheader($r,'','New Folder');
2018: &makefolder($env{'form.newfolder'});
2019: &Apache::loncommunicate::menu($r);
2020: &disall($r,$env{'form.newfolder'});
2021: } elsif ($env{'form.showcommentbaseurl'}) {
2022: &storedcommentlisting($r);
2023: } else {
2024: &printheader($r,'','Display All Messages');
2025: &Apache::loncommunicate::menu($r);
2026: &disall($r,($folder?$folder:$dismode));
2027: }
2028: $r->print(&Apache::loncommon::end_page());
2029: return OK;
2030: }
2031: # ================================================= Main program, reset counter
2032:
2033: =pod
2034:
2035: =back
2036:
2037: =cut
2038:
2039: 1;
2040:
2041: __END__
2042:
2043:
2044:
2045:
2046:
2047:
2048:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>