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