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