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