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