Annotation of loncom/interface/lonmsgdisplay.pm, revision 1.63
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # Routines for messaging display
3: #
1.63 ! raeburn 4: # $Id: lonmsgdisplay.pm,v 1.62 2007/01/04 16:54:07 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;
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:
1.50 raeburn 77: =item * B<Blocking>: LON-CAPA can block selected communication
78: features for students during an online exam. A course coordinator or
1.1 albertel 79: instructor can set an open and close date/time for scheduled online
80: exams in a course. If a user uses the LON-CAPA internal messaging
81: system to display e-mails during the scheduled blocking event,
82: display of all e-mail sent during the blocking period will be
83: suppressed, and a message of explanation, including details of the
84: currently active blocking periods will be displayed instead. A user
85: who has a course coordinator or instructor role in a course will be
86: unaffected by any blocking periods for the course, unless the user
87: also has a student role in the course, AND has selected the student role.
88:
89: =back
90:
91: Users can ask LON-CAPA to forward messages to conventional e-mail
92: addresses on their B<PREF> screen, but generally, LON-CAPA messages
93: are much more useful than traditional email can be made to be, even
94: with HTML support.
95:
96: Right now, this document will cover just how to send a message, since
97: it is likely you will not need to programmatically read messages,
98: since lonmsg already implements that functionality.
99:
100: The routines used to package messages and unpackage messages are not
101: only used by lonmsg when creating/extracting messages for LON-CAPA's
102: internal messaging system, but also by lonnotify.pm which is available
103: for use by Domain Coordinators to broadcast standard e-mail to specified
104: users in their domain. The XML packaging used in the two cases is very
105: similar. The differences are the use of <recuser>$uname</recuser> and
106: <recdomain>$udom</recdomain> in stored internal messages, compared
107: with <recipient username="$uname:$udom">$email</recipient> in stored
108: Domain Coordinator e-mail for the storage of information about
109: recipients of the message/e-mail.
110:
111: =head1 FUNCTIONS
112:
113: =over 4
114:
115: =cut
116:
117: use strict;
118: use Apache::lonnet;
119: use HTML::TokeParser();
120: use Apache::Constants qw(:common);
121: use Apache::loncommon();
122: use Apache::lontexconvert();
123: use HTML::Entities();
124: use Apache::lonlocal;
125: use Apache::loncommunicate;
126: use Apache::lonfeedback;
127: use Apache::lonrss();
1.27 albertel 128: use Apache::lonselstudent();
1.29 www 129: use lib '/home/httpd/lib/perl/';
130: use LONCAPA;
1.1 albertel 131:
132: # Querystring component with sorting type
133: my $sqs;
134: my $startdis;
135:
136: # ============================================================ List all folders
137:
138: sub folderlist {
1.53 raeburn 139: my ($folder,$msgstatus) = @_;
1.46 raeburn 140: my %lt = &Apache::lonlocal::texthash(
141: actn => 'Action',
142: fold => 'Folder',
143: show => 'Show',
1.53 raeburn 144: status => 'Message Status',
1.46 raeburn 145: go => 'Go',
1.50 raeburn 146: nnff => 'New Name for Folder',
147: newn => 'New Name',
148: thfm => 'The folder may not be renamed',
149: fmnb => 'folder may not be renamed as it is a folder provided by the system.',
150: asth => 'as this name is already in use for a system-provided or user-defined folder.',
151: the => 'The',
152: tnfm => 'The new folder may not be named',
153:
1.46 raeburn 154: );
155:
156: my %actions = &Apache::lonlocal::texthash(
157: view => 'View Folder',
158: rename => 'Rename Folder',
159: delete => 'Delete Folder',
160: );
161: $actions{'select_form_order'} = ['view','rename','delete'];
162:
1.53 raeburn 163: my %statushash = &get_msgstatus_types();
164:
165: $statushash{'select_form_order'} = ['','new','read','replied','forwarded'];
166:
1.46 raeburn 167: my %permfolders = &get_permanent_folders();
168: my $permlist = join("','",sort(keys(%permfolders)));
169: my ($permlistkeys,$permlistvals);
170: foreach my $key (sort(keys(%permfolders))) {
171: $permlistvals .= $permfolders{$key}."','";
172: $permlistkeys .= $key."','";
173: }
174: $permlistvals =~ s/','$//;
175: $permlistkeys =~ s/','$//;
176: my %gotfolders = &Apache::lonmsg::get_user_folders();
177: my %userfolders;
178:
179: foreach my $key (keys(%gotfolders)) {
1.54 albertel 180: $key =~ s/(['"])/\$1/g; #' stupid emacs
1.46 raeburn 181: $userfolders{$key} = $key;
182: }
183: my @userorder = sort(keys(%userfolders));
184: my %formhash = (%permfolders,%userfolders);
185: my $folderlist = join("','",@userorder);
186: $folderlist .= "','".$permlistvals;
187:
1.53 raeburn 188: $formhash{'select_form_order'} = ['','critical',@userorder,'sent','trash'];
1.46 raeburn 189: my $output = qq|<script type="text/javascript">
190: function folder_choice(targetform,caller) {
191: var permfolders_keys = new Array('$permlistkeys');
192: var permfolders_vals = new Array('$permlistvals');
193: var allfolders = new Array('$folderlist');
194: if (caller == 'change') {
195: if (targetform.folderaction.options[targetform.folderaction.selectedIndex].value == 'rename') {
196: for (var i=0; i<permfolders_keys.length; i++) {
197: if (permfolders_keys[i] == targetform.folder.value) {
1.50 raeburn 198: alert("$lt{'the'} '"+permfolders_vals[i]+"' $lt{'fmnb'}");
1.46 raeburn 199: return;
200: }
201: }
1.50 raeburn 202: var foldername=prompt('$lt{'nnff'}','$lt{'newn'}');
1.46 raeburn 203: if (foldername) {
204: targetform.renamed.value=foldername;
205: for (var i=0; i<allfolders.length; i++) {
206: if (allfolders[i] == foldername) {
1.50 raeburn 207: alert("$lt{'thfm'} '"+foldername+"' $lt{'asth'}");
1.46 raeburn 208: return;
209: }
210: }
211: targetform.submit();
212: }
213: }
214: else {
215: targetform.submit();
216: }
217: }
218: if (caller == 'new') {
219: var newname=targetform.newfolder.value;
220: if (newname) {
221: for (var i=0; i<allfolders.length; i++) {
222: if (allfolders[i] == newname) {
1.50 raeburn 223: alert("$lt{'tnfm'} '"+newname+"' $lt{'asth'}");
1.46 raeburn 224: return;
225: }
226: }
227: targetform.submit();
228: }
229: }
230: }
231: </script>|;
1.57 albertel 232: my %show = ('select_form_order' => [10,20,50,100,200],
233: map {$_=>$_} (10,20,50,100,200));
234:
235:
1.46 raeburn 236: $output .= '
237: <form method="post" action="/adm/email" name="folderlist">
238: <table border="0" cellspacing="2" cellpadding="2">
239: <tr>
240: <td align="left">
241: <table border="0" cellspacing="2" cellpadding="2">
242: <tr>
243: <td align="center"><b>'.$lt{'fold'}.'</b><br />'."\n".
1.47 albertel 244: &Apache::loncommon::select_form($folder,'folder',%formhash).'
1.46 raeburn 245: </td>
1.57 albertel 246: <td align="center"><b>'.$lt{'show'}.'</b><br />'."\n".
247: &Apache::loncommon::select_form($env{'form.interdis'},'interdis',
248: %show).'
1.46 raeburn 249: </td>
1.53 raeburn 250: <td align="center"><b>'.$lt{'status'}.'</b><br />'."\n".
251: &Apache::loncommon::select_form($msgstatus,'msgstatus',%statushash).'
252: </td>
1.46 raeburn 253: <td align="center"><b>'.$lt{'actn'}.'</b><br />'.
1.47 albertel 254: &Apache::loncommon::select_form('view','folderaction',%actions).'
1.46 raeburn 255: </td><td><br />'.
256: '<input type="button" value="'.$lt{'go'}.'" onClick="javascript:folder_choice(this.form,'."'change'".');" />
257: </td>
258: </tr>
259: </table>
260: </td><td> </td><td> </td><td> </td><td> </td>
261: <td align="right">
262: <table><tr><td><br />
263: <input type="button" value="'.&mt('Make New Folder').
264: '" onClick="javascript:folder_choice(this.form,'."'new'".');" /></td>'.
1.48 albertel 265: '<td align="center"><b>'.&mt('New Folder').'</b><br />'.
1.46 raeburn 266: '<input type="text" size="15" name="newfolder" value="" />
267: </td></tr></table>
268: </td>
269: </tr>
270: </table>'."\n".
1.1 albertel 271: '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" />'.
1.46 raeburn 272: '<input type="hidden" name="renamed" value="" />'.
1.53 raeburn 273: ($folder=~/^critical/?'</form>':'');
1.46 raeburn 274: return $output;
275: }
276:
277: sub get_permanent_folders {
1.47 albertel 278: my %permfolders =
279: &Apache::lonlocal::texthash('' => 'INBOX',
280: 'trash' => 'TRASH',
281: 'critical' => 'Critical',
282: 'sent' => 'Sent Messages',
283: );
1.46 raeburn 284: return %permfolders;
1.1 albertel 285: }
286:
1.53 raeburn 287: sub get_msgstatus_types {
288: my %statushash = &Apache::lonlocal::texthash(
289: '' => 'Any',
290: new => 'Unread',
291: read => 'Read',
292: replied => 'Replied to',
293: forwarded => 'Forwarded',
294: );
295: return %statushash;
296: }
297:
1.1 albertel 298: sub scrollbuttons {
1.53 raeburn 299: my ($start,$maxdis,$first,$finish,$total,$msgstatus)=@_;
1.1 albertel 300: unless ($total>0) { return ''; }
301: $start++; $maxdis++;$first++;$finish++;
1.53 raeburn 302:
303: my %statushash = &get_msgstatus_types();
304: my $status;
305: if ($msgstatus eq '') {
306: $status = &mt('All');
307: } else {
308: $status = $statushash{$msgstatus};
309: }
1.1 albertel 310: return
1.53 raeburn 311: '<b>'.&mt('Page').'</b>: '.
1.1 albertel 312: '<input type="submit" name="firstview" value="'.&mt('First').'" />'.
313: '<input type="submit" name="prevview" value="'.&mt('Previous').'" />'.
314: '<input type="text" size="5" name="startdis" value="'.$start.'" onChange="this.form.submit()" /> of '.$maxdis.
315: '<input type="submit" name="nextview" value="'.&mt('Next').'" />'.
316: '<input type="submit" name="lastview" value="'.&mt('Last').'" /><br />'.
1.53 raeburn 317: &mt('<b>[_1] messages</b>: showing messages [_2] through [_3] of [_4].',$status,$first,$finish,$total).'</form>';
1.1 albertel 318: }
319: # =============================================================== Status Change
320:
321: sub statuschange {
322: my ($msgid,$newstatus,$folder)=@_;
1.3 albertel 323: my $suffix=&Apache::lonmsg::foldersuffix($folder);
1.1 albertel 324: my %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
325: if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
326: unless ($status{$msgid}) { $status{$msgid}='new'; }
327: unless (($status{$msgid} eq 'replied') ||
328: ($status{$msgid} eq 'forwarded')) {
329: &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
330: }
331: if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
332: &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
333: }
334: if ($newstatus eq 'deleted') {
1.9 albertel 335: return &movemsg($msgid,$folder,'trash');
336: }
337: return ;
1.1 albertel 338: }
339:
340: # ============================================================= Make new folder
341:
342: sub makefolder {
1.46 raeburn 343: my ($newfolder) = @_;
344: my %permfolders = &get_permanent_folders();
345: my %userfolders = &Apache::lonmsg::get_user_folders();
346: my ($outcome,$warning);
347: if (defined($userfolders{$newfolder})) {
348: return &mt('The folder name: "[_1]" is already in use for an existing folder.',$newfolder);
349: }
350: foreach my $perm (keys(%permfolders)) {
351: if ($permfolders{$perm} eq $newfolder) {
352: return &mt('The folder name: "[_1]" is already used for one of the folders automatically generated by the system.',$newfolder);
353: }
354: }
355: if (&get_msgfolder_lock() eq 'ok') {
356: my %counter_hash = &Apache::lonnet::get('email_folders',["\0".'idcount']);
357: my $lastcount = $counter_hash{"\0".'idcount'};
358: my $folder_id = $lastcount + 1;
359: while (defined($userfolders{$folder_id})) {
360: $folder_id ++;
361: }
1.47 albertel 362: my %folderinfo = ( id => $folder_id,
363: created => time, );
1.46 raeburn 364: $outcome =
1.47 albertel 365: &Apache::lonnet::put('email_folders',{$newfolder => \%folderinfo,
366: "\0".'idcount' => $folder_id});
1.46 raeburn 367: my $releaseresult = &release_msgfolder_lock();
368: if ($releaseresult ne 'ok') {
369: $warning = $releaseresult;
370: }
371: } else {
1.47 albertel 372: $outcome =
373: &mt('Error - could not obtain lock on email folders record.');
1.46 raeburn 374: }
375: return ($outcome,$warning);
1.1 albertel 376: }
377:
1.46 raeburn 378: # ============================================================= Delete folder
379:
380: sub deletefolder {
381: my ($folder)=@_;
382: my %permfolders = &get_permanent_folders();
383: if (defined($permfolders{$folder})) {
1.56 albertel 384: return &mt('The folder "[_1]" may not be deleted',$folder);
1.46 raeburn 385: }
386: my %userfolders = &Apache::lonmsg::get_user_folders();
387: if (!defined($userfolders{$folder})) {
1.56 albertel 388: return &mt('The folder "[_1]" does not exist so deletion is not required.',
1.46 raeburn 389: $folder);
390: }
391: # check folder is empty;
392: my $suffix=&Apache::lonmsg::foldersuffix($folder);
393: my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
394: if (@messages > 0) {
1.56 albertel 395: return &mt('The folder "[_1]" contains messages so it may not be deleted.',$folder).
1.46 raeburn 396: '<br />'.
397: &mt('Delete or move the messages to a different folder first.');
398: }
399: my $delresult = &Apache::lonnet::del('email_folders',[$folder]);
400: return $delresult;
401: }
402:
403: sub renamefolder {
404: my ($folder) = @_;
405: my $newname = $env{'form.renamed'};
406: my %permfolders = &get_permanent_folders();
407: if ($env{'form.renamed'} eq '') {
408: return &mt('The folder "[_1]" may not be renamed to "[_2]" as the new name you requested is an invalid name.',$folder,$newname);
409: }
410: if (defined($permfolders{$newname})) {
411: return &mt('The folder "[_1]" may not be renamed to "[_2]" as the new name you requested is reserved for folders provided automatically by the system.',$folder,$newname);
412: }
413: my %userfolders = &Apache::lonmsg::get_user_folders();
414: if (defined($userfolders{$newname})) {
415: return &mt('The folder "[_1]" may not be renamed to "[_2]" because the new name you requested is already being used for an existing folder.',$folder,$newname);
416: }
417: if (!defined($userfolders{$folder})) {
418: return &mt('The folder "[_1]" could not be renamed to "[_2]" because the folder does not exist.',$folder,$newname);
419: }
420: my %folderinfo;
421: if (ref($userfolders{$folder}) eq 'HASH') {
422: %folderinfo = %{$userfolders{$folder}};
423: } else {
1.47 albertel 424: %folderinfo = ( id => $folder,
425: created => $userfolders{$folder},);
1.46 raeburn 426: }
427: my $outcome =
428: &Apache::lonnet::put('email_folders',{$newname => \%folderinfo});
429: if ($outcome eq 'ok') {
430: $outcome = &Apache::lonnet::del('email_folders',[$folder]);
431: }
432: return $outcome;
433: }
434:
435: sub get_msgfolder_lock {
436: # get lock for mail folder counter.
1.47 albertel 437: my $lockhash = { "\0".'lock_counter' => time, };
1.46 raeburn 438: my $tries = 0;
439: my $gotlock = &Apache::lonnet::newput('email_folders',$lockhash);
440: while (($gotlock ne 'ok') && $tries <3) {
441: $tries ++;
1.47 albertel 442: sleep(1);
1.46 raeburn 443: $gotlock = &Apache::lonnet::newput('email_folders',$lockhash);
444: }
445: return $gotlock;
446: }
447:
448: sub release_msgfolder_lock {
449: # remove lock
450: my @del_lock = ("\0".'lock_counter');
451: my $dellockoutcome=&Apache::lonnet::del('email_folders',\@del_lock);
452: if ($dellockoutcome ne 'ok') {
453: return ('<br />'.&mt('Warning: failed to release lock for counter').'<br />');
454: } else {
455: return 'ok';
456: }
457: }
458:
459:
1.1 albertel 460: # ======================================================== Move between folders
461:
462: sub movemsg {
463: my ($msgid,$srcfolder,$trgfolder)=@_;
464: if ($srcfolder eq 'new') { $srcfolder=''; }
1.3 albertel 465: my $srcsuffix=&Apache::lonmsg::foldersuffix($srcfolder);
466: my $trgsuffix=&Apache::lonmsg::foldersuffix($trgfolder);
1.9 albertel 467: if ($srcsuffix eq $trgsuffix) {
468: return (0,&mt('Message not moved, Attempted to move message to the same folder as it already is in.'));
469: }
1.1 albertel 470:
471: # Copy message
472: my %message=&Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid]);
1.9 albertel 473: if (!exists($message{$msgid}) || $message{$msgid} eq '') {
1.32 albertel 474: if (&Apache::lonnet::error(%message)) {
1.9 albertel 475: return (0,&mt('Message not moved, A network error occurred.'));
476: } else {
477: return (0,&mt('Message not moved as the message is no longer in the source folder.'));
478: }
479: }
480:
481: my $result =&Apache::lonnet::put('nohist_email'.$trgsuffix,
482: {$msgid => $message{$msgid}});
1.32 albertel 483: if (&Apache::lonnet::error($result)) {
1.9 albertel 484: return (0,&mt('Message not moved, A network error occurred.'));
485: }
1.1 albertel 486:
487: # Copy status
488: unless ($trgfolder eq 'trash') {
1.9 albertel 489: my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]);
490: # a non-existant status is the mark of an unread msg
1.32 albertel 491: if (&Apache::lonnet::error(%status)) {
1.9 albertel 492: return (0,&mt('Message copied to new folder but status was not, A network error occurred.'));
493: }
494: my $result=&Apache::lonnet::put('email_status'.$trgsuffix,
495: {$msgid => $status{$msgid}});
1.32 albertel 496: if (&Apache::lonnet::error($result)) {
1.9 albertel 497: return (0,&mt('Message copied to new folder but status was not, A network error occurred.'));
498: }
1.1 albertel 499: }
1.9 albertel 500:
1.1 albertel 501: # Delete orginals
1.9 albertel 502: my $result_del_msg =
503: &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]);
504: my $result_del_stat =
505: &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]);
1.32 albertel 506: if (&Apache::lonnet::error($result_del_msg)) {
1.9 albertel 507: return (0,&mt('Message copied, but unable to delete the original from the source folder.'));
508: }
1.32 albertel 509: if (&Apache::lonnet::error($result_del_stat)) {
1.9 albertel 510: return (0,&mt('Message copied, but unable to delete the original status from the source folder.'));
511: }
512:
513: return (1);
1.1 albertel 514: }
515:
516: # ======================================================= Display a course list
517:
518: sub discourse {
1.25 foxr 519: my $result;
520: my ($course_personnel,
521: $current_members,
522: $expired_members,
1.28 foxr 523: $future_members) =
524: &Apache::lonselstudent::get_people_in_class($env{'request.course.sec'});
1.25 foxr 525: unshift @$current_members, (@$course_personnel);
526: my %defaultUsers;
1.40 albertel 527:
528: $result .= '<input type="hidden" name="sendmode" value="group" />'."\n";
1.25 foxr 529:
1.40 albertel 530: $result .= &Apache::lonselstudent::render_student_list($current_members,
531: "compemail",
532: "current",
533: \%defaultUsers,
534: 1,"selectedusers",1);
1.25 foxr 535:
1.28 foxr 536: $result .= &Apache::lonselstudent::render_student_list($expired_members,
537: "compemail",
538: "expired",
539: \%defaultUsers,
540: 1, "selectedusers",0);
541: $result .= &Apache::lonselstudent::render_student_list($future_members,
542: "compemail",
543: "future",
544: \%defaultUsers,
545: 1, "selectedusers", 0);
1.25 foxr 546: return $result;
547: }
548:
1.38 raeburn 549: sub disgroup {
550: my ($cdom,$cnum,$group,$viewgrps,$editgrps) = @_;
551: my $result;
552: # Needs to be in a course
553: if (!($env{'request.course.fn'})) {
554: $result = &mt('Error: you must have a course role selected to be able to send a broadcast message to a group in the course.');
555: return $result;
556: }
557: if ($cdom eq '' || $cnum eq '') {
558: $result = &mt('Error: could not determine domain or number of course');
559: return $result;
560: }
561: my ($memberinfo,$numitems) =
562: &Apache::longroup::group_memberlist($cdom,$cnum,$group,{},[]);
563: my @statustypes = ('active');
564: if ($viewgrps || $editgrps) {
565: push(@statustypes,('future','previous'));
566: }
567: if (keys(%{$memberinfo}) == 0) {
568: $result = &mt('As this group has no members, there are no '.
569: 'recipients to select.');
570: return $result;
571: } else {
572: $result = &mt('Select message recipients from the group members listed below.<br />');
573: my %Sortby = (
574: active => {},
575: previous => {},
576: future => {},
577: );
578: my %lt = &Apache::lonlocal::texthash(
579: 'name' => 'Name',
580: 'usnm' => 'Username',
581: 'doma' => 'Domain',
582: 'active' => 'Active Members',
583: 'previous' => 'Former Members',
584: 'future' => 'Future Members',
585: );
586: foreach my $user (sort(keys(%{$memberinfo}))) {
587: my $status = $$memberinfo{$user}{status};
588: if ($env{'form.'.$status.'.sortby'} eq 'fullname') {
589: push(@{$Sortby{$status}{$$memberinfo{$user}{fullname}}},$user);
590: } elsif ($env{'form.'.$status.'.sortby'} eq 'username') {
591: push(@{$Sortby{$status}{$$memberinfo{$user}{uname}}},$user);
592: } elsif ($env{'form.'.$status.'.sortby'} eq 'domain') {
593: push(@{$Sortby{$status}{$$memberinfo{$user}{udom}}},$user);
594: } else {
595: push(@{$Sortby{$status}{$$memberinfo{$user}{fullname}}},$user);
596: }
597: }
598: $result .= &group_check_uncheck();
599: $result .= '<table border="0" cellspacing="8" cellpadding="2">'.
600: '<tr>';
601: foreach my $status (@statustypes) {
602: if (ref($numitems) eq 'HASH') {
603: if ((defined($$numitems{$status})) && ($$numitems{$status})) {
1.39 raeburn 604: $result.='<td valign="top">'.
1.38 raeburn 605: '<fieldset><legend><b>'.$lt{$status}.
606: '</b></legend><nobr>'.
1.50 raeburn 607: '<input type="button" value="'.&mt('Check All').'" '.
1.38 raeburn 608: 'onclick="javascript:toggleAll('."'".$status."','check'".')" />'.
609: ' '.
1.50 raeburn 610: '<input type="button" value="'.&mt('Uncheck All').'" '.
1.38 raeburn 611: 'onclick="javascript:toggleAll('."'".$status."','uncheck'".')" />'.
612: '</nobr></fieldset><br />'.
613: &Apache::loncommon::start_data_table().
614: &Apache::loncommon::start_data_table_header_row();
1.39 raeburn 615: $result .= "<th>$lt{'name'}</a></th>".
616: "<th>$lt{'usnm'}</a></th>".
617: "<th>$lt{'doma'}</a></th>".
1.38 raeburn 618: &Apache::loncommon::end_data_table_header_row();
619: foreach my $key (sort(keys(%{$Sortby{$status}}))) {
620: foreach my $user (@{$Sortby{$status}{$key}}) {
621: $result .=
622: &Apache::loncommon::start_data_table_row().
623: '<td><input type="checkbox" '.
624: 'name="selectedusers_forminput" value="'.
625: $user.':'.$status.'" />'.
626: $$memberinfo{$user}{'fullname'}.'</td>'.
627: '<td>'.$$memberinfo{$user}{'uname'}.'</td>'.
628: '<td>'.$$memberinfo{$user}{'udom'}.'</td>'.
629: &Apache::loncommon::end_data_table_row();
630: }
631: }
632: $result .= &Apache::loncommon::end_data_table();
633: }
634: }
635: $result .= '</td><td> </td>';
636: }
637: $result .= '</tr></table>';
638: }
639: return $result;
640: }
641:
642: sub group_check_uncheck {
643: my $output = qq|
644: <script type="text/javascript">
645: function toggleAll(caller,action) {
646: var pattern = new RegExp(":"+caller+"\$");
647: if (typeof(document.compemail.selectedusers_forminput.length)=="undefined") {
648: if (document.compemail.selectedusers_forminput.value.match(pattern)) {
649: if (action == 'check') {
650: document.groupmail.selectedusers_forminput.checked = true;
651: } else {
652: document.groupmail.selectedusers_forminput.checked = false;
653: }
654: }
655: } else {
656: for (var i=0; i<document.compemail.selectedusers_forminput.length; i++) {
657: if (document.compemail.selectedusers_forminput[i].value.match(pattern)) {
658: if (action == 'check') {
659: document.compemail.selectedusers_forminput[i].checked = true;
660: } else {
661: document.compemail.selectedusers_forminput[i].checked = false;
662: }
663: }
664: }
665: }
666: }
667: </script>
668: |;
669: }
670:
671: sub groupmail_header {
672: my ($action,$group,$cdom,$cnum) = @_;
673: my ($description,$refarg);
674: if (!$cdom || !$cnum) {
675: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
676: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
677: }
678: if (exists($env{'form.ref'})) {
679: $refarg = 'ref='.$env{'form.ref'};
680: }
681: if (!$group) {
682: $group = $env{'form.group'};
683: }
684: if ($group eq '') {
685: return '';
686: } else {
687: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
688: if (defined($curr_groups{$group})) {
689: my %groupinfo =
690: &Apache::longroup::get_group_settings($curr_groups{$group});
691: $description = &unescape($groupinfo{'description'});
692: }
693: }
694: &Apache::lonhtmlcommon::clear_breadcrumbs();
695: if ($refarg) {
696: &Apache::lonhtmlcommon::add_breadcrumb
697: ({href=>"/adm/coursegroups",
698: text=>"Groups",
699: title=>"View course groups"});
700: }
701: &Apache::lonhtmlcommon::add_breadcrumb
702: ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
703: text=>"Group: $description",
704: title=>"Go to group's home page"},
705: {href=>"/adm/email?compose=group&group=".
706: "$env{'form.group'}&$refarg",
707: text=>"Send a Message in a Group",
708: title=>"Compose Group Email Message"},);
709: if ($action eq 'sending') {
710: &Apache::lonhtmlcommon::add_breadcrumb
711: ({text=>"Messages being sent.",
712: title=>"Messages sent"},);
713: }
714: my $groupheader = &Apache::loncommon::start_page('Group Email');
715: $groupheader .= &Apache::lonhtmlcommon::breadcrumbs
716: ('Group - '.$env{'form.group'}.' Email');
717: return $groupheader;
718: }
719:
720: sub groupmail_sent {
721: my ($group,$cdom,$cnum) = @_;
722: my $refarg;
723: if (exists($env{'form.ref'})) {
724: $refarg = 'ref='.$env{'form.ref'};
725: }
726: my $output .= '<br /><br /><a href="/adm/email?compose=group&group='.
727: $group.'&'.$refarg.'">'.
728: &mt('Send another group email').'</a>'.' '.
729: '<a href="/adm/'.$cdom.'/'.$cnum.'/'.$group.'/smppg?'.
730: $refarg.'">'. &mt('Return to group page').'</a>';
731: return $output;
732: }
733:
1.1 albertel 734: # ==================================================== Display Critical Message
735:
736: sub discrit {
737: my $r=shift;
1.5 albertel 738: my $header = '<h1><font color="red">'.&mt('Critical Messages').'</font></h1>'.
1.1 albertel 739: '<form action="/adm/email" method="POST">'.
740: '<input type="hidden" name="confirm" value="true" />';
741: my %what=&Apache::lonnet::dump('critical');
742: my $result = '';
1.42 raeburn 743: foreach my $key (sort(keys(%what))) {
744: my %content=&Apache::lonmsg::unpackagemsg($what{$key});
1.1 albertel 745: next if ($content{'senderdomain'} eq '');
746: $result.='<hr />'.&mt('From').': <b>'.
747: &Apache::loncommon::aboutmewrapper(
748: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14 albertel 749: $content{'sendername'}.':'.
1.1 albertel 750: $content{'senderdomain'}.') '.$content{'time'}.
751: '<br />'.&mt('Subject').': '.$content{'subject'}.
752: '<br /><pre>'.
753: &Apache::lontexconvert::msgtexconverted($content{'message'}).
754: '</pre><small>'.
755: &mt('You have to confirm that you received this message. After confirmation, this message will be moved to your regular inbox').
756: '</small><br />'.
1.42 raeburn 757: '<input type="submit" name="rec_'.$key.'" value="'.&mt('Confirm Receipt').'" />'.
758: '<input type="submit" name="reprec_'.$key.'" '.
1.1 albertel 759: 'value="'.&mt('Confirm Receipt and Reply').'" />';
760: }
761: # Check to see if there were any messages.
762: if ($result eq '') {
763: $result = "<h2>".&mt('You have no critical messages.')."</h2>".
1.38 raeburn 764: '<a href="/adm/roles">'.&mt('Select a course').'</a><br />'.
1.1 albertel 765: '<a href="/adm/email">'.&mt('Communicate').'</a>';
766: } else {
767: $r->print($header);
768: }
769: $r->print($result);
770: $r->print('<input type="hidden" name="displayedcrit" value="true" /></form>');
771: }
772:
773: sub sortedmessages {
1.53 raeburn 774: my ($blocked,$startblock,$endblock,$numblocked,$folder,$msgstatus) = @_;
1.1 albertel 775: my $suffix=&Apache::lonmsg::foldersuffix($folder);
776: my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
777: #unpack the varibles and repack into temp for sorting
778: my @temp;
779: my %descriptions;
780: my %status_cache =
781: &Apache::lonnet::get('email_status'.&Apache::lonmsg::foldersuffix($folder),\@messages);
1.11 albertel 782:
783: my $get_received;
784: if ($folder eq 'sent'
785: && ($env{'form.sortedby'} =~ m/^(rev)?(user|domain)$/)) {
786: $get_received = 1;
787: }
788:
789: foreach my $msgid (@messages) {
1.29 www 790: my $esc_msgid=&escape($msgid);
1.59 raeburn 791: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,$processid,$symb,$error) =
1.11 albertel 792: &Apache::lonmsg::unpackmsgid($esc_msgid,$folder,undef,
1.1 albertel 793: \%status_cache);
1.53 raeburn 794: next if ($msgstatus ne '' && $msgstatus ne $status);
1.1 albertel 795: my $description = &get_course_desc($fromcid,\%descriptions);
796: my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
1.11 albertel 797: $esc_msgid,$description);
798: if ($get_received) {
799: my %message = &Apache::lonnet::get('nohist_email'.$suffix,
800: [$msgid]);
801: my %content = &Apache::lonmsg::unpackagemsg($message{$msgid});
802: push(@temp1,$content{'recuser'},$content{'recdomain'});
803: }
1.1 albertel 804: # Check whether message was sent during blocking period.
805: if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
1.11 albertel 806: $$blocked{$msgid} = 'ON';
1.1 albertel 807: $$numblocked ++;
808: } else {
809: push @temp ,\@temp1;
810: }
811: }
812: #default sort
813: @temp = sort {$a->[0] <=> $b->[0]} @temp;
814: if ($env{'form.sortedby'} eq "date"){
815: @temp = sort {$a->[0] <=> $b->[0]} @temp;
816: }
817: if ($env{'form.sortedby'} eq "revdate"){
818: @temp = sort {$b->[0] <=> $a->[0]} @temp;
819: }
820: if ($env{'form.sortedby'} eq "user"){
1.11 albertel 821: if ($get_received) {
822: @temp = sort {lc($a->[7][0]) cmp lc($b->[7][0])} @temp;
823: } else {
824: @temp = sort {lc($a->[2]) cmp lc($b->[2])} @temp;
825: }
1.1 albertel 826: }
827: if ($env{'form.sortedby'} eq "revuser"){
1.11 albertel 828: if ($get_received) {
829: @temp = sort {lc($b->[7][0]) cmp lc($a->[7][0])} @temp;
830: } else {
831: @temp = sort {lc($b->[2]) cmp lc($a->[2])} @temp;
832: }
1.1 albertel 833: }
834: if ($env{'form.sortedby'} eq "domain"){
1.11 albertel 835: if ($get_received) {
836: @temp = sort {$a->[8][0] cmp $b->[8][0]} @temp;
837: } else {
838: @temp = sort {$a->[3] cmp $b->[3]} @temp;
839: }
1.1 albertel 840: }
841: if ($env{'form.sortedby'} eq "revdomain"){
1.11 albertel 842: if ($get_received) {
843: @temp = sort {$b->[8][0] cmp $a->[8][0]} @temp;
844: } else {
845: @temp = sort {$b->[3] cmp $a->[3]} @temp;
846: }
1.1 albertel 847: }
848: if ($env{'form.sortedby'} eq "subject"){
849: @temp = sort {lc($a->[1]) cmp lc($b->[1])} @temp;
850: }
851: if ($env{'form.sortedby'} eq "revsubject"){
852: @temp = sort {lc($b->[1]) cmp lc($a->[1])} @temp;
853: }
854: if ($env{'form.sortedby'} eq "course"){
855: @temp = sort {lc($a->[6]) cmp lc($b->[6])} @temp;
856: }
857: if ($env{'form.sortedby'} eq "revcourse"){
858: @temp = sort {lc($b->[6]) cmp lc($a->[6])} @temp;
859: }
860: if ($env{'form.sortedby'} eq "status"){
861: @temp = sort {$a->[4] cmp $b->[4]} @temp;
862: }
863: if ($env{'form.sortedby'} eq "revstatus"){
864: @temp = sort {$b->[4] cmp $a->[4]} @temp;
865: }
866: return @temp;
867: }
868:
869: sub get_course_desc {
870: my ($fromcid,$descriptions) = @_;
871: my $description;
872: if (!$fromcid) {
873: return $description;
874: } else {
875: if (defined($$descriptions{$fromcid})) {
876: $description = $$descriptions{$fromcid};
877: } else {
878: if (defined($env{'course.'.$fromcid.'.description'})) {
879: $description = $env{'course.'.$fromcid.'.description'};
880: } else {
1.48 albertel 881: my %courseinfo=&Apache::lonnet::coursedescription($fromcid);
1.1 albertel 882: $description = $courseinfo{'description'};
883: }
884: $$descriptions{$fromcid} = $description;
885: }
886: return $description;
887: }
888: }
889:
890: # ======================================================== Display all messages
891:
892: sub disall {
1.53 raeburn 893: my ($r,$folder,$msgstatus)=@_;
1.57 albertel 894: my %saveable = ('folder' => 'scalar',
895: 'msgstatus' => 'scalar',
896: 'sortedby' => 'scalar',
897: 'interdis' => 'scalar',
898: );
899: &Apache::loncommon::store_settings('user','mail',\%saveable);
900: &Apache::loncommon::restore_settings('user','mail',\%saveable);
901: $folder ||= $env{'form.folder'};
902: $msgstatus ||= $env{'form.msgstatus'};
903: $env{'form.interdis'} ||= 20;
904:
1.53 raeburn 905: $r->print(&folderlist($folder,$msgstatus));
906: if ($folder eq 'critical') {
1.1 albertel 907: &discrit($r);
908: } else {
1.53 raeburn 909: &disfolder($r,$folder,$msgstatus);
1.1 albertel 910: }
911: }
912:
913: # ============================================================ Display a folder
914:
915: sub disfolder {
1.53 raeburn 916: my ($r,$folder,$msgstatus)=@_;
917: my %statushash = &get_msgstatus_types();
1.1 albertel 918: my %blocked = ();
919: my %setters = ();
920: my $numblocked = 0;
1.44 raeburn 921: my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53 raeburn 922: my %lt = &Apache::lonlocal::texthash(
923: sede => 'Select a destination folder to which the messages will be moved.',
924: nome => 'No messages have been selected to apply ths action to.',
925: chec => 'Check the checkbox for at least one message.',
926: );
1.1 albertel 927: $r->print(<<ENDDISHEADER);
1.16 albertel 928: <script type="text/javascript">
1.1 albertel 929: function checkall() {
1.53 raeburn 930: for (i=0; i<document.forms.disall.delmark.length; i++) {
931: document.forms.disall.delmark[i].checked=true;
1.1 albertel 932: }
933: }
934:
935: function uncheckall() {
1.53 raeburn 936: for (i=0; i<document.forms.disall.delmark.length; i++) {
937: document.forms.disall.delmark[i].checked=false;
938: }
939: }
940: function checkfoldermove() {
941: if (document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value == 'markedmove') {
942: if (document.disall.movetofolder.options[document.disall.movetofolder.selectedIndex].value == "") {
943: alert("$lt{'sede'}");
944: return;
1.1 albertel 945: }
946: }
1.53 raeburn 947: return;
1.1 albertel 948: }
1.53 raeburn 949:
950: function validate_checkedaction() {
951: document.disall.markedaction.value = document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value;
952: if (document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value == 'markedmove') {
953: if (document.disall.movetofolder.options[document.disall.movetofolder.selectedIndex].value == "") {
954: alert("$lt{'sede'}");
955: return;
956: }
957: }
958: var checktotal = 0;
959: for (var i=0; i<document.forms.disall.delmark.length; i++) {
960: if (document.forms.disall.delmark[i].checked) {
961: checktotal ++;
962: }
963: }
964: if (checktotal == 0) {
965: alert("$lt{'nome'}\\n$lt{'chec'}");
966: return;
967: }
968: document.disall.submit();
969: }
970:
1.1 albertel 971: </script>
972: ENDDISHEADER
1.54 albertel 973:
1.1 albertel 974: my $fsqs='&folder='.$folder;
1.53 raeburn 975: my @temp=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1 albertel 976: my $totalnumber=$#temp+1;
1.53 raeburn 977: if ($totalnumber < 1) {
978: if ($msgstatus eq '') {
979: $r->print('<h2>'.&mt('Empty Folder').'</h2>');
980: } elsif ($msgstatus eq 'replied') {
981: $r->print('<h2>'.&mt('You have not replied to any messages in this folder.').'</h2>');
982: } else {
1.55 albertel 983: $r->print('<h2>'.&mt('There are no '.lc($statushash{$msgstatus}).' messages in this folder.').'</h2>');
1.53 raeburn 984: }
1.1 albertel 985: return;
986: }
1.57 albertel 987: my $interdis = $env{'form.interdis'};
1.1 albertel 988: my $number=int($totalnumber/$interdis);
1.57 albertel 989: if ($totalnumber%$interdis == 0) {
990: $number--;
1.53 raeburn 991: }
992:
1.1 albertel 993: if (($startdis<0) || ($startdis>$number)) { $startdis=$number; }
994: my $firstdis=$interdis*$startdis;
995: if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; }
996: my $lastdis=$firstdis+$interdis-1;
997: if ($lastdis>$#temp) { $lastdis=$#temp; }
1.53 raeburn 998: $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber,$msgstatus));
1.1 albertel 999: $r->print('<form method="post" name="disall" action="/adm/email">'.
1.53 raeburn 1000: '<table class="LC_mail_list"><tr><th colspan="1"> </th><th>');
1.1 albertel 1001: if ($env{'form.sortedby'} eq "revdate") {
1002: $r->print('<a href = "?sortedby=date'.$fsqs.'">'.&mt('Date').'</a></th>');
1003: } else {
1004: $r->print('<a href = "?sortedby=revdate'.$fsqs.'">'.&mt('Date').'</a></th>');
1005: }
1006: $r->print('<th>');
1007: if ($env{'form.sortedby'} eq "revuser") {
1008: $r->print('<a href = "?sortedby=user'.$fsqs.'">'.&mt('Username').'</a>');
1009: } else {
1010: $r->print('<a href = "?sortedby=revuser'.$fsqs.'">'.&mt('Username').'</a>');
1011: }
1012: $r->print('</th><th>');
1013: if ($env{'form.sortedby'} eq "revdomain") {
1014: $r->print('<a href = "?sortedby=domain'.$fsqs.'">'.&mt('Domain').'</a>');
1015: } else {
1016: $r->print('<a href = "?sortedby=revdomain'.$fsqs.'">'.&mt('Domain').'</a>');
1017: }
1018: $r->print('</th><th>');
1019: if ($env{'form.sortedby'} eq "revsubject") {
1020: $r->print('<a href = "?sortedby=subject'.$fsqs.'">'.&mt('Subject').'</a>');
1021: } else {
1022: $r->print('<a href = "?sortedby=revsubject'.$fsqs.'">'.&mt('Subject').'</a>');
1023: }
1024: $r->print('</th><th>');
1025: if ($env{'form.sortedby'} eq "revcourse") {
1.46 raeburn 1026: $r->print('<a href = "?sortedby=course'.$fsqs.'">'.&mt('Course').'</a>');
1.1 albertel 1027: } else {
1.46 raeburn 1028: $r->print('<a href = "?sortedby=revcourse'.$fsqs.'">'.&mt('Course').'</a>');
1.1 albertel 1029: }
1030: $r->print('</th><th>');
1031: if ($env{'form.sortedby'} eq "revstatus") {
1032: $r->print('<a href = "?sortedby=status'.$fsqs.'">'.&mt('Status').'</a></th>');
1033: } else {
1034: $r->print('<a href = "?sortedby=revstatus'.$fsqs.'">'.&mt('Status').'</a></th>');
1035: }
1036: $r->print("</tr>\n");
1.6 albertel 1037:
1038: my $suffix = &Apache::lonmsg::foldersuffix($folder);
1.1 albertel 1039: for (my $n=$firstdis;$n<=$lastdis;$n++) {
1.11 albertel 1040: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,
1041: $description,$recv_name,$recv_domain)=
1042: @{$temp[$n]};
1.1 albertel 1043: if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
1044: if ($status eq 'new') {
1.4 albertel 1045: $r->print('<tr class="LC_mail_new">');
1.1 albertel 1046: } elsif ($status eq 'read') {
1.4 albertel 1047: $r->print('<tr class="LC_mail_read">');
1.1 albertel 1048: } elsif ($status eq 'replied') {
1.4 albertel 1049: $r->print('<tr class="LC_mail_replied">');
1.1 albertel 1050: } else {
1.4 albertel 1051: $r->print('<tr class="LC_mail_other">');
1.1 albertel 1052: }
1.6 albertel 1053: my ($dis_name,$dis_domain) = ($fromname,$fromdomain);
1054: if ($folder eq 'sent') {
1.11 albertel 1055: if (defined($recv_name) && !defined($recv_domain)) {
1056: $dis_name = join('<br />',@{$recv_name});
1057: $dis_domain = join('<br />',@{$recv_domain});
1058: } else {
1.29 www 1059: my $msg_id = &unescape($origID);
1.11 albertel 1060: my %message = &Apache::lonnet::get('nohist_email'.$suffix,
1061: [$msg_id]);
1062: my %content = &Apache::lonmsg::unpackagemsg($message{$msg_id});
1063: $dis_name = join('<br />',@{$content{'recuser'}});
1064: $dis_domain = join('<br />',@{$content{'recdomain'}});
1065: }
1.6 albertel 1066: }
1.53 raeburn 1067: my $localsenttime = &Apache::lonlocal::locallocaltime($sendtime);
1068: my $count = $n +1;
1069: $r->print('<td align="right"><nobr>'.(($status eq 'new')?'<b>':'').
1070: $count.'.'.(($status eq 'new')?'</b>':'').' '.
1071: '<input type="checkbox" name="delmark"'.
1072: ' value="'.$origID.'" /></nobr></td>');
1073: foreach my $item ($localsenttime,$dis_name,$dis_domain,$shortsubj) {
1074: $r->print('<td>'.(($status eq 'new')?'<b>':'').
1.61 raeburn 1075: '<a href="/adm/email?display='.$origID.$sqs.'">'.
1.53 raeburn 1076: $item.(($status eq 'new')?'</b>':'').'</td>');
1077: }
1078: my $showstatus;
1079: my %statushash = &get_msgstatus_types();
1080: if ($status eq '') {
1081: $showstatus = '';
1082: } else {
1083: $showstatus = $statushash{$status};
1084: }
1085: $r->print('<td>'.(($status eq 'new')?'<b>':'').$description.
1086: (($status eq 'new')?'</b>':'').'</td><td>'.
1087: (($status eq 'new')?'<b>':'').$showstatus.
1088: (($status eq 'new')?'</b>':'').'</td></tr>'."\n");
1.1 albertel 1089: } elsif ($status eq 'deleted') {
1090: # purge
1.9 albertel 1091: my ($result,$msg) =
1.29 www 1092: &movemsg(&unescape($origID),$folder,'trash');
1.9 albertel 1093:
1.1 albertel 1094: }
1095: }
1.53 raeburn 1096: $r->print("</table>\n");
1097: $r->print('<table border="0" cellspacing="2" cellpadding="2">
1098: <tr>
1099: <td>'.
1100: '<input type="button" onclick="javascript:checkall()" value="'.&mt('Check All').'" /><br />'."\n".
1101: '<input type="button" onclick="javascript:uncheckall()" value="'.&mt('Uncheck All').'" />'."\n".
1102: '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" /></td><td> </td>'."\n".
1103: '<td align="center"><b>'.&mt('Action').'</b><br />'."\n".
1104: ' <select name="checkedaction" onchange="javascript:checkfoldermove()">'."\n");
1105:
1.1 albertel 1106: if ($folder ne 'trash') {
1.53 raeburn 1107: $r->print(' <option value="markeddel">'.&mt('Delete').'</option>'."\n");
1108: }
1109: if ($msgstatus ne 'read') {
1110: $r->print(' <option value="markedread">'.&mt('Mark Read').'</option>."\n"');
1111: }
1112: if ($msgstatus ne 'unread') {
1113: $r->print(' <option value="markedunread">'.&mt('Mark Unread').'</option>'."\n");
1.1 albertel 1114: }
1.53 raeburn 1115: $r->print(' <option value="markedforward">'.&mt('Forward').'</option>'."\n");
1.54 albertel 1116:
1117: my %gotfolders = &Apache::lonmsg::get_user_folders();
1.53 raeburn 1118: if (keys(%gotfolders) > 0) {
1119: $r->print(' <option value="markedmove">'.&mt('Move to Folder ->').
1120: '</option>');
1121: }
1122: $r->print("\n".'</select></td>'."\n");
1.54 albertel 1123:
1.53 raeburn 1124: if (keys(%gotfolders) > 0) {
1125: $r->print('<td align="center"><b>'.&mt('Destination folder').'<b><br />');
1.54 albertel 1126: my %userfolders;
1.53 raeburn 1127: foreach my $key (keys(%gotfolders)) {
1128: $userfolders{$key} = $key;
1129: }
1130: $userfolders{''} = "";
1131: $r->print(&Apache::loncommon::select_form('','movetofolder',%userfolders).
1132: '</td>');
1133: }
1134: $r->print('<td> </td><td> '.
1135: '<input type="button" name="go" value="'.&mt('Go').
1136: '" onclick="javascript:validate_checkedaction()"/></td>'."\n".
1137: '</tr></table>');
1.1 albertel 1138: my $postedstartdis=$startdis+1;
1.53 raeburn 1139: $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'}.'" /><input type="hidden" name="msgstatus" value="'.$msgstatus.'" ><input type="hidden" name="markedaction" value="" /></form>');
1.1 albertel 1140: if ($numblocked > 0) {
1141: my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
1142: my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
1143: $r->print('<br /><br />'.
1.51 raeburn 1144: &mt('[quant,_1,message is, messages are] not viewable because display of LON-CAPA messages sent to you by other students between [_2] and [_3] is currently being blocked because of online exams.',$numblocked,$beginblock,$finishblock));
1.44 raeburn 1145: $r->print(&Apache::loncommon::build_block_table($startblock,$endblock,
1146: \%setters));
1.1 albertel 1147: }
1148: }
1149:
1150: # ============================================================== Compose output
1151:
1152: sub compout {
1.53 raeburn 1153: my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode,
1154: $multiforward)=@_;
1.1 albertel 1155: my $suffix=&Apache::lonmsg::foldersuffix($folder);
1.38 raeburn 1156: my ($cdom,$cnum,$group,$refarg);
1157: if (exists($env{'form.group'})) {
1158: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1159: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1160: $group = $env{'form.group'};
1161: my $action = 'composing';
1162: $r->print(&groupmail_header($action,$group,$cdom,$cnum));
1163: } elsif ($broadcast eq 'individual') {
1.1 albertel 1164: &printheader($r,'/adm/email?compose=individual',
1165: 'Send a Message');
1166: } elsif ($broadcast) {
1167: &printheader($r,'/adm/email?compose=group',
1168: 'Broadcast Message');
1169: } elsif ($forwarding) {
1170: &Apache::lonhtmlcommon::add_breadcrumb
1.29 www 1171: ({href=>"/adm/email?display=".&escape($forwarding),
1.1 albertel 1172: text=>"Display Message"});
1.29 www 1173: &printheader($r,'/adm/email?forward='.&escape($forwarding),
1.1 albertel 1174: 'Forwarding a Message');
1175: } elsif ($replying) {
1176: &Apache::lonhtmlcommon::add_breadcrumb
1.29 www 1177: ({href=>"/adm/email?display=".&escape($replying),
1.1 albertel 1178: text=>"Display Message"});
1.29 www 1179: &printheader($r,'/adm/email?replyto='.&escape($replying),
1.1 albertel 1180: 'Replying to a Message');
1181: } elsif ($replycrit) {
1182: $r->print('<h3>'.&mt('Replying to a Critical Message').'</h3>');
1183: $replying=$replycrit;
1.53 raeburn 1184: } elsif ($multiforward) {
1185: &Apache::lonhtmlcommon::add_breadcrumb
1186: ({href=>"/adm/email?folder=".&escape($folder),
1187: text=>"Display All Messages"});
1188: &printheader($r,'/adm/email?compose=multiforward',
1189: 'Forwarding Multiple Messages');
1190: $r->print(&mt('Each of the <b>[quant,_1,message]</b> you checked will be forwarded to the recipient(s) you select below.',$multiforward).'<br />');
1.1 albertel 1191: } else {
1192: &printheader($r,'/adm/email?compose=upload',
1193: 'Distribute from Uploaded File');
1194: }
1195:
1196: my $dispcrit='';
1197: my $dissub='';
1198: my $dismsg='';
1199: my $disbase='';
1200: my $func=&mt('Send New');
1.50 raeburn 1201: my %lt=&Apache::lonlocal::texthash('us' => 'Username',
1202: 'do' => 'Domain',
1203: 'ad' => 'Additional Recipients',
1204: 'sb' => 'Subject',
1205: 'ca' => 'Cancel',
1206: 'ma' => 'Mail',
1.53 raeburn 1207: 'msg' => 'Messages',
1.50 raeburn 1208: 'gen' => 'Generate messages from a file',
1209: 'gmt' => 'General message text',
1210: 'tff' => 'The file format for the uploaded portion of the message is',
1211: 'uas' => 'Upload and Send',
1212: );
1.1 albertel 1213: if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
1214: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
1215: '/'.$env{'request.course.sec'})) {
1216: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1217: $dispcrit=
1218: '<p><label><input type="checkbox" name="critmsg" /> '.&mt('Send as critical message').'</label> ' . $crithelp .
1219: '</p><p>'.
1220: '<label><input type="checkbox" name="sendbck" /> '.&mt('Send as critical message').' ' .
1221: &mt('and return receipt') . '</label>' . $crithelp .
1222: '</p><p><label><input type="checkbox" name="permanent" /> '.
1223: &mt('Send copy to permanent email address (if known)').'</label></p>'.
1224: '<p><label><input type="checkbox" name="rsspost" /> '.
1225: &mt('Include in course RSS newsfeed').'</label></p>';
1226: }
1227: my %message;
1228: my %content;
1229: my $defdom=$env{'user.domain'};
1230: if ($forwarding) {
1231: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]);
1232: %content=&Apache::lonmsg::unpackagemsg($message{$forwarding},$folder);
1233: $dispcrit.='<input type="hidden" name="forwid" value="'.
1234: $forwarding.'" />';
1235: $func=&mt('Forward');
1236:
1237: $dissub=&mt('Forwarding').': '.$content{'subject'};
1238: $dismsg=&mt('Forwarded message from').' '.
1239: $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
1240: if ($content{'baseurl'}) {
1.29 www 1241: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1 albertel 1242: }
1243: }
1244: if ($replying) {
1245: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
1246: %content=&Apache::lonmsg::unpackagemsg($message{$replying},$folder);
1247: $dispcrit.='<input type="hidden" name="replyid" value="'.
1248: $replying.'" />';
1249: $func=&mt('Send Reply to');
1250:
1251: $dissub=&mt('Reply').': '.$content{'subject'};
1252: $dismsg='> '.$content{'message'};
1253: $dismsg=~s/\r/\n/g;
1254: $dismsg=~s/\f/\n/g;
1255: $dismsg=~s/\n+/\n\> /g;
1256: if ($content{'baseurl'}) {
1.29 www 1257: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1 albertel 1258: if ($env{'user.adv'}) {
1259: $disbase.='<label><input type="checkbox" name="storebasecomment" />'.&mt('Store message for re-use').
1260: '</label> <a href="/adm/email?showcommentbaseurl='.
1.29 www 1261: &escape($content{'baseurl'}).'" target="comments">'.
1.1 albertel 1262: &mt('Show re-usable messages').'</a><br />';
1263: }
1264: }
1265: }
1266: my $citation=&displayresource(%content);
1.38 raeburn 1267: my ($can_grp_broadcast,$viewgrps,$editgrps);
1.1 albertel 1268: if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
1.23 www 1269: if ($env{'form.text'}) { $dismsg=$env{'form.text'}; }
1270: if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; }
1271: $r->print(
1.1 albertel 1272: '<form action="/adm/email" name="compemail" method="post"'.
1273: ' enctype="multipart/form-data">'."\n".
1.38 raeburn 1274: '<input type="hidden" name="sendmail" value="on" />'."\n");
1275: if ($broadcast eq 'group' && $env{'form.group'} ne '') {
1276: $can_grp_broadcast =
1277: &Apache::lonnet::allowed('sgb',$env{'request.course.id'}.'/'.
1278: $group);
1279: $viewgrps =
1280: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
1281: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1282: $editgrps =
1283: &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
1284: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1285: if ($viewgrps || $editgrps || $can_grp_broadcast) {
1286: $r->print(&disgroup($cdom,$cnum,$group,$viewgrps,$editgrps));
1287: }
1288: }
1289: $r->print('<table>');
1290: if (($broadcast eq 'group') && ($group ne '') &&
1291: (!$can_grp_broadcast && !$viewgrps && !$editgrps)) {
1292: $r->print(&recipient_input_row($cdom,%lt));
1293: }
1294: if (($broadcast ne 'group') && ($broadcast ne 'upload')) {
1.1 albertel 1295: if ($replying) {
1296: $r->print('<tr><td colspan="2">'.&mt('Replying to').' '.
1297: &Apache::loncommon::aboutmewrapper(
1298: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
1.14 albertel 1299: $content{'sendername'}.':'.
1.1 albertel 1300: $content{'senderdomain'}.')'.
1301: '<input type="hidden" name="recuname" value="'.$content{'sendername'}.'" />'.
1302: '<input type="hidden" name="recdomain" value="'.$content{'senderdomain'}.'" />'.
1303: '</td></tr>');
1304: } else {
1.38 raeburn 1305: $r->print(&recipient_input_row($defdom,%lt));
1.1 albertel 1306: }
1307: }
1308: my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
1.53 raeburn 1309: my $subj_size;
1310: if ($multiforward) {
1311: $r->print(&additional_rec_row(\%lt));
1312: $r->print('<tr><td colspan="2">'.
1313: &mt('Unless you choose otherwise:').'<ul><li>'.
1314: &mt("The subject in each forwarded message will be <i>'Forwarding:'</i> followed by the original subject.").'</li><li>'.
1315: &mt("The message itself will begin with a first line: <i>'Forwarded message from'</i> followed by the original sender's name.").'</li></ul></td></tr>');
1316: $func=&mt('Forward');
1317: $dissub = &mt('Forwarding').': ';
1318: $subj_size = '10';
1319: my $extra = '<'.&mt('original subject').'> '.
1320: '<input type="radio" name="showorigsubj" value="1" checked="checked" />'.&mt('Yes').' <input type="radio" name="showorigsubj" value="0" />'.&mt('No');
1321: $dismsg = &mt('Forwarded message from ').' ';
1322: my $sender = &mt("sender's name");
1323: $r->print(&msg_subject_row($dissub,\%lt,$subj_size,$extra));
1324: $r->print('<tr><td>'.&mt('Message begins with:').'</td><td><input type="text" name="msgheader" value="'.$dismsg.'" /> '.$sender.' <input type="radio" name="showorigsender" value="1" checked="checked" />'.&mt('Yes').' <input type="radio" name="showorigsender" value="0" />'.&mt('No').'<input type="hidden" name="multiforward" value="'.$multiforward.'" /></td></tr>
1325: </table>
1326: <br />'.
1327: $latexHelp.
1328: &mt("Any new text to display before the text of the original messages:").'<br />
1329: <textarea name="message" id="message" cols="80" rows="5" wrap="hard">
1330: </textarea></p><br />');
1331: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
1332: foreach my $msg (@to_forward) {
1333: $r->print('<input type="hidden" name="delmark" value="'.$msg.'" />');
1334: }
1335: $r->print(&submit_button_row($folder,$dismode,$func.' '.$lt{'msg'},
1336: \%lt));
1337: } elsif ($broadcast ne 'upload') {
1338: $subj_size = '50';
1339: $r->print(&additional_rec_row(\%lt));
1340: $r->print(&msg_subject_row($dissub,\%lt,$subj_size));
1341: $r->print(<<"ENDCOMP");
1342: </table>
1.1 albertel 1343: $latexHelp
1344: <textarea name="message" id="message" cols="80" rows="15" wrap="hard">$dismsg
1345: </textarea></p><br />
1346: $dispcrit
1347: $disbase
1348: ENDCOMP
1.53 raeburn 1349: $r->print(&submit_button_row($folder,$dismode,$func.' '.$lt{'ma'},
1350: \%lt));
1351: $r->print($citation);
1.38 raeburn 1352: if (exists($env{'form.ref'})) {
1353: $r->print('<input type="hidden" name="ref" value="'.
1354: $env{'form.ref'}.'" />');
1355: }
1356: if (exists($env{'form.group'})) {
1357: $r->print('<input type="hidden" name="group" value="'.
1358: $env{'form.group'}.'" />');
1359: }
1.1 albertel 1360: } else { # $broadcast is 'upload'
1.50 raeburn 1361: $r->print(<<ENDBLOCK);
1.1 albertel 1362: <input type="hidden" name="sendmode" value="upload" />
1363: <input type="hidden" name="send" value="on" />
1.50 raeburn 1364: <h3>$lt{'gen'}</h3>
1.1 albertel 1365: <p>
1366: Subject: <input type="text" size="50" name="subject" />
1367: </p>
1.50 raeburn 1368: <p>$lt{'gmt'}:<br />
1.1 albertel 1369: <textarea name="message" id="message" cols="60" rows="10" wrap="hard">$dismsg
1370: </textarea></p>
1371: <p>
1.50 raeburn 1372: $lt{'tff'}:
1373: ENDBLOCK
1374: $r->print('
1375: <pre>'."\n".
1376: &mt('username1:domain1: text')."\n".
1377: &mt('username2:domain2: text')."\n".
1378: &mt('username3:domain1: text')."\n".
1379: '</pre>
1.1 albertel 1380: </p>
1381: <p>
1.50 raeburn 1382: '.&mt('The messages will be assembled from all lines with the respective'."\n".'<tt>username:domain</tt>, and appended to the general message text.'));
1383: $r->print(<<ENDUPLOAD);
1384: </p>
1.1 albertel 1385: <p>
1386: <input type="file" name="upfile" size="40" /></p><p>
1387: $dispcrit
1.50 raeburn 1388: <input type="submit" value="$lt{'uas'}" /></p>
1.1 albertel 1389: ENDUPLOAD
1390: }
1391: if ($broadcast eq 'group') {
1.38 raeburn 1392: if ($group eq '') {
1393: my $studentsel = &discourse();
1394: $r->print($studentsel);
1395: }
1.1 albertel 1396: }
1.36 albertel 1397: if ($env{'form.displayedcrit'}) {
1398: $r->print('<input type="hidden" name="displayedcrit" value="true" />');
1399: }
1.1 albertel 1400: $r->print('</form>'.
1401: &Apache::lonfeedback::generate_preview_button('compemail','message').
1402: &Apache::lonhtmlcommon::htmlareaselectactive('message'));
1403: }
1404:
1405: # ---------------------------------------------------- Display all face to face
1406:
1.38 raeburn 1407: sub recipient_input_row {
1408: my ($dom,%lt) = @_;
1409: my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain');
1410: my $selectlink=
1411: &Apache::loncommon::selectstudent_link('compemail','recuname',
1412: 'recdomain');
1413: my $output = <<"ENDREC";
1414: <tr><td>$lt{'us'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recname'}" /></td><td rowspan="2">$selectlink</td></tr>
1415: <tr><td>$lt{'do'}:</td>
1416: <td>$domform</td></tr>
1417: ENDREC
1418: return $output;
1419: }
1420:
1.53 raeburn 1421: sub additional_rec_row {
1422: my ($lt) = @_;
1423: my $output = <<"ENDADD";
1424: <tr><td>$lt->{'ad'}:<br /><tt>username:domain,username:domain, ...
1425: </tt></td><td>
1426: <input type="text" size="50" name="additionalrec" /></td></tr>
1427: ENDADD
1428: return $output;
1429: }
1430:
1431: sub submit_button_row {
1432: my ($folder,$dismode,$sendtext,$lt) = @_;
1433: my $output = qq|
1434: <input type="hidden" name="folder" value="$folder" />
1435: <input type="hidden" name="dismode" value="$dismode" />
1436: <input type="submit" name="send" value="$sendtext" />
1437: <input type="submit" name="cancel" value="$lt->{'ca'}" /><hr />
1438: |;
1439: return $output;
1440: }
1441:
1442: sub msg_subject_row {
1443: my ($dissub,$lt,$subj_size,$extra) = @_;
1444: my $output = '<tr><td>'.$lt->{'sb'}.':</td><td><input type="text" size="'.
1445: $subj_size.'" name="subject" value="'.$dissub.'" />'.$extra.
1446: '</td></tr>';
1447: return $output;
1448: }
1449:
1.1 albertel 1450: sub retrieve_instructor_comments {
1451: my ($user,$domain)=@_;
1452: my $target=$env{'form.grade_target'};
1453: if (! $env{'request.course.id'}) { return; }
1.49 albertel 1454: if (! &Apache::lonnet::allowed('dff',$env{'request.course.id'})
1455: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1456: '/'.$env{'request.course.sec'})) {
1457: return;
1458: }
1459: my %records=&Apache::lonnet::dump('nohist_email',
1460: $env{'course.'.$env{'request.course.id'}.'.domain'},
1461: $env{'course.'.$env{'request.course.id'}.'.num'},
1462: '%255b'.$user.'%253a'.$domain.'%255d');
1463: my $result='';
1.42 raeburn 1464: foreach my $key (sort(keys(%records))) {
1465: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1 albertel 1466: next if ($content{'senderdomain'} eq '');
1467: next if ($content{'subject'} !~ /^Record/);
1468: # &Apache::lonfeedback::newline_to_br(\$content{'message'});
1469: $result.='Recorded by '.
1.14 albertel 1470: $content{'sendername'}.':'.$content{'senderdomain'}."\n";
1.1 albertel 1471: $result.=
1472: &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
1473: }
1474: return $result;
1475: }
1476:
1477: sub disfacetoface {
1478: my ($r,$user,$domain)=@_;
1479: my $target=$env{'form.grade_target'};
1480: unless ($env{'request.course.id'}) { return; }
1.49 albertel 1481: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
1482: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1483: '/'.$env{'request.course.sec'})) {
1.50 raeburn 1484: $r->print(&mt('Not allowed'));
1.1 albertel 1485: return;
1486: }
1487: my %records=&Apache::lonnet::dump('nohist_email',
1488: $env{'course.'.$env{'request.course.id'}.'.domain'},
1489: $env{'course.'.$env{'request.course.id'}.'.num'},
1490: '%255b'.$user.'%253a'.$domain.'%255d');
1491: my $result='';
1.42 raeburn 1492: foreach my $key (sort(keys(%records))) {
1493: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1 albertel 1494: next if ($content{'senderdomain'} eq '');
1495: &Apache::lonfeedback::newline_to_br(\$content{'message'});
1496: if ($content{'subject'}=~/^Record/) {
1497: $result.='<h3>'.&mt('Record').'</h3>';
1498: } elsif ($content{'subject'}=~/^Broadcast/) {
1499: $result .='<h3>'.&mt('Broadcast Message').'</h3>';
1500: if ($content{'subject'}=~/^Broadcast\./) {
1501: if (defined($content{'coursemsgid'})) {
1.29 www 1502: my $crsmsgid = &escape($content{'coursemsgid'});
1.1 albertel 1503: my $broadcast_message = &general_message($crsmsgid);
1504: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$broadcast_message;
1505: } else {
1506: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1507: $content{'message'} =
1508: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1509: $content{'message'};
1510: }
1511: }
1512: } else {
1513: $result.='<h3>'.&mt('Critical Message').'</h3>';
1514: if (defined($content{'coursemsgid'})) {
1.29 www 1515: my $crsmsgid=&escape($content{'coursemsgid'});
1.1 albertel 1516: my $critical_message = &general_message($crsmsgid);
1517: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$critical_message;
1518: } else {
1519: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1520: $content{'message'}=
1521: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1522: $content{'message'};
1523: }
1524: }
1525: $result.=&mt('By').': <b>'.
1526: &Apache::loncommon::aboutmewrapper(
1527: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14 albertel 1528: $content{'sendername'}.':'.
1.1 albertel 1529: $content{'senderdomain'}.') '.$content{'time'}.
1530: '<br /><pre>'.
1531: &Apache::lontexconvert::msgtexconverted($content{'message'}).
1532: '</pre>';
1533: }
1534: # Check to see if there were any messages.
1535: if ($result eq '') {
1.33 albertel 1536: my $lctype = lc(&Apache::loncommon::course_type());
1.1 albertel 1537: if ($target ne 'tex') {
1.30 raeburn 1538: $r->print("<p><b>".&mt('No notes, face-to-face discussion records, critical messages, or broadcast messages in this [_1].',$lctype)."</b></p>");
1.1 albertel 1539: } else {
1.30 raeburn 1540: $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this [_1].',$lctype).'}\\\\');
1.1 albertel 1541: }
1542: } else {
1543: $r->print($result);
1544: }
1545: }
1546:
1547: sub general_message {
1548: my ($crsmsgid) = @_;
1549: my %general_content;
1550: if ($crsmsgid) {
1551: my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid],
1552: $env{'course.'.$env{'request.course.id'}.'.domain'},
1553: $env{'course.'.$env{'request.course.id'}.'.num'});
1554: %general_content = &Apache::lonmsg::unpackagemsg($course_content{$crsmsgid});
1555: }
1556: return $general_content{'message'};
1557: }
1558:
1559: # ---------------------------------------------------------------- Face to face
1560:
1561: sub facetoface {
1562: my ($r,$stage)=@_;
1.49 albertel 1563: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
1564: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1565: '/'.$env{'request.course.sec'})) {
1.50 raeburn 1566: $r->print(&mt('Not allowed'));
1.1 albertel 1567: return;
1568: }
1.33 albertel 1569: my $crstype = &Apache::loncommon::course_type();
1570: my $leaders = ($crstype eq 'Group') ? 'coordinators and leaders'
1571: : 'faculty and staff';
1.1 albertel 1572: &printheader($r,
1573: '/adm/email?recordftf=query',
1574: "User Notes, Face-to-Face, Critical Messages, Broadcast Messages");
1575: # from query string
1576:
1577: if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
1578: if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
1579:
1580: my $defdom=$env{'user.domain'};
1581: # already filled in
1582: if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
1583: # generate output
1584: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
1585: my $stdbrws = &Apache::loncommon::selectstudent_link
1586: ('stdselect','recuname','recdomain');
1587: my %lt=&Apache::lonlocal::texthash('user' => 'Username',
1588: 'dom' => 'Domain',
1.30 raeburn 1589: 'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, and Broadcast Messages in $crstype",
1.1 albertel 1590: 'subm' => 'Retrieve discussion and message records',
1.30 raeburn 1591: 'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')',
1.1 albertel 1592: 'post' => 'Post this Record');
1593: $r->print(<<"ENDTREC");
1594: <h3>$lt{'head'}</h3>
1595: <form method="post" action="/adm/email" name="stdselect">
1596: <input type="hidden" name="recordftf" value="retrieve" />
1597: <table>
1598: <tr><td>$lt{'user'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recuname'}" /></td>
1599: <td rowspan="2">
1600: $stdbrws
1601: <input type="submit" value="$lt{'subm'}" /></td>
1602: </tr>
1603: <tr><td>$lt{'dom'}:</td>
1604: <td>$domform</td></tr>
1605: </table>
1606: </form>
1607: ENDTREC
1608: if (($stage ne 'query') &&
1609: ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
1610: chomp($env{'form.newrecord'});
1611: if ($env{'form.newrecord'}) {
1.31 albertel 1612: &Apache::lonmsg::store_instructor_comment($env{'form.newrecord'},
1613: $env{'form.recuname'},
1614: $env{'form.recdomain'});
1.1 albertel 1615: }
1616: $r->print('<h3>'.&Apache::loncommon::plainname($env{'form.recuname'},
1617: $env{'form.recdomain'}).'</h3>');
1618: &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
1619: $r->print(<<ENDRHEAD);
1620: <form method="post" action="/adm/email">
1621: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
1622: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
1623: ENDRHEAD
1624: $r->print(<<ENDBFORM);
1625: <hr />$lt{'newr'}<br />
1626: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
1627: <br />
1628: <input type="hidden" name="recordftf" value="post" />
1629: <input type="submit" value="$lt{'post'}" />
1630: </form>
1631: ENDBFORM
1632: }
1633: }
1634:
1635: # ----------------------------------------------------------- Blocking during exams
1636:
1637: sub examblock {
1638: my ($r,$action) = @_;
1639: unless ($env{'request.course.id'}) { return;}
1.44 raeburn 1640: if (!&Apache::lonnet::allowed('dcm',$env{'request.course.id'})
1641: && ! &Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
1.1 albertel 1642: '/'.$env{'request.course.sec'})) {
1643: $r->print('Not allowed');
1644: return;
1645: }
1.34 albertel 1646: my $usertype = (&Apache::loncommon::course_type() eq 'Group') ? 'members'
1.33 albertel 1647: : 'students';
1.1 albertel 1648: my %lt=&Apache::lonlocal::texthash(
1649: 'comb' => 'Communication Blocking',
1650: 'cbds' => 'Communication blocking during scheduled exams',
1.30 raeburn 1651: 'desc' => "You can use communication blocking to prevent $usertype enrolled in this course from displaying LON-CAPA messages sent by other $usertype during an online exam. As blocking of communication could potentially interrupt legitimate communication between $usertype who are also both enrolled in a different LON-CAPA course, please be careful that you select the correct start and end times for your scheduled exam when setting or modifying these parameters.",
1.1 albertel 1652: 'mecb' => 'Modify existing communication blocking periods',
1.50 raeburn 1653: 'ncbc' => 'No communication blocks currently stored',
1654: 'stor' => 'Store',
1.1 albertel 1655: );
1656:
1657: my %ltext = &Apache::lonlocal::texthash(
1658: 'dura' => 'Duration',
1659: 'setb' => 'Set by',
1660: 'even' => 'Event',
1.44 raeburn 1661: 'blck' => 'Blocked?',
1.1 albertel 1662: 'actn' => 'Action',
1663: 'star' => 'Start',
1664: 'endd' => 'End'
1665: );
1666:
1667: &printheader($r,'/adm/email?block=display',$lt{'comb'});
1668: $r->print('<h3>'.$lt{'cbds'}.'</h3>');
1669:
1670: if ($action eq 'store') {
1671: &blockstore($r);
1672: }
1673:
1674: $r->print($lt{'desc'}.'<br /><br />
1675: <form name="blockform" method="post" action="/adm/email?block=store">
1676: ');
1677:
1678: $r->print('<h4>'.$lt{'mecb'}.'</h4>');
1679: my %records = ();
1680: my $blockcount = 0;
1681: my $parmcount = 0;
1682: &get_blockdates(\%records,\$blockcount);
1683: if ($blockcount > 0) {
1684: $parmcount = &display_blocker_status($r,\%records,\%ltext);
1685: } else {
1686: $r->print($lt{'ncbc'}.'<br /><br />');
1687: }
1688: &display_addblocker_table($r,$parmcount,\%ltext);
1689: my $end_page=&Apache::loncommon::end_page();
1690: $r->print(<<"END");
1691: <br />
1692: <input type="hidden" name="blocktotal" value="$blockcount" />
1.50 raeburn 1693: <input type ="submit" value="$lt{'stor'}" />
1.1 albertel 1694: </form>
1695: $end_page
1696: END
1697: return;
1698: }
1699:
1700: sub blockstore {
1701: my $r = shift;
1702: my %lt=&Apache::lonlocal::texthash(
1703: 'tfcm' => 'The following changes were made',
1704: 'ncwm' => 'No changes were made.'
1705: );
1706: my %adds = ();
1707: my %removals = ();
1708: my %cancels = ();
1709: my $modtotal = 0;
1710: my $canceltotal = 0;
1711: my $addtotal = 0;
1712: my %blocking = ();
1713: $r->print('<h3>'.$lt{'head'}.'</h3>');
1.42 raeburn 1714: foreach my $envkey (keys(%env)) {
1.44 raeburn 1715: if ($envkey =~ m/^form\.modify_(\d+)$/) {
1.1 albertel 1716: $adds{$1} = $1;
1717: $removals{$1} = $1;
1718: $modtotal ++;
1.42 raeburn 1719: } elsif ($envkey =~ m/^form\.cancel_(\d+)$/) {
1.1 albertel 1720: $cancels{$1} = $1;
1721: unless ( defined($removals{$1}) ) {
1722: $removals{$1} = $1;
1723: $canceltotal ++;
1724: }
1.42 raeburn 1725: } elsif ($envkey =~ m/^form\.add_(\d+)$/) {
1.1 albertel 1726: $adds{$1} = $1;
1727: $addtotal ++;
1.44 raeburn 1728: }
1.1 albertel 1729: }
1730:
1.42 raeburn 1731: foreach my $key (keys(%removals)) {
1732: my $hashkey = $env{'form.key_'.$key};
1.1 albertel 1733: &Apache::lonnet::del('comm_block',["$hashkey"],
1734: $env{'course.'.$env{'request.course.id'}.'.domain'},
1735: $env{'course.'.$env{'request.course.id'}.'.num'}
1736: );
1737: }
1.42 raeburn 1738: foreach my $key (keys(%adds)) {
1739: unless ( defined($cancels{$key}) ) {
1740: my ($newstart,$newend) = &get_dates_from_form($key);
1.1 albertel 1741: my $newkey = $newstart.'____'.$newend;
1.44 raeburn 1742: my $blocktypes = &get_block_choices($key);
1743: $blocking{$newkey} = {
1744: setter => $env{'user.name'}.':'.$env{'user.domain'},
1745: event => &escape($env{'form.title_'.$key}),
1746: blocks => $blocktypes,
1747: };
1.1 albertel 1748: }
1749: }
1750: if ($addtotal + $modtotal > 0) {
1751: &Apache::lonnet::put('comm_block',\%blocking,
1752: $env{'course.'.$env{'request.course.id'}.'.domain'},
1753: $env{'course.'.$env{'request.course.id'}.'.num'}
1754: );
1755: }
1756: my $chgestotal = $canceltotal + $modtotal + $addtotal;
1757: if ($chgestotal > 0) {
1758: $r->print($lt{'tfcm'}.'<ul>');
1759: if ($canceltotal > 0) {
1.50 raeburn 1760: $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] removed.',$canceltotal).'</li>');
1.1 albertel 1761: }
1762: if ($modtotal > 0) {
1.50 raeburn 1763: $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] modified.',$modtotal).'</li>');
1.1 albertel 1764: }
1765: if ($addtotal > 0) {
1.50 raeburn 1766: $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] added.',$addtotal).'</li>');
1.1 albertel 1767: }
1768: $r->print('</ul>');
1769: } else {
1770: $r->print($lt{'ncwm'});
1771: }
1772: $r->print('<br />');
1773: return;
1774: }
1775:
1776: sub get_dates_from_form {
1777: my $item = shift;
1778: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
1779: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
1780: return ($startdate,$enddate);
1781: }
1782:
1783: sub get_blockdates {
1784: my ($records,$blockcount) = @_;
1785: $$blockcount = 0;
1786: %{$records} = &Apache::lonnet::dump('comm_block',
1787: $env{'course.'.$env{'request.course.id'}.'.domain'},
1788: $env{'course.'.$env{'request.course.id'}.'.num'}
1789: );
1.15 albertel 1790: $$blockcount = keys(%{$records});
1791:
1792: if ((keys(%{$records}))[0] =~ /^error: 2 /) {
1793: $records = {};
1794: $$blockcount = 0;
1.1 albertel 1795: }
1796: }
1797:
1.44 raeburn 1798: sub get_block_choices {
1799: my $item = shift;
1800: my $blocklist;
1801: my ($typeorder,$types) = &blocktype_text();
1802: foreach my $type (@{$typeorder}) {
1803: if ($env{'form.'.$type.'_'.$item}) {
1804: $blocklist->{$type} = 'on';
1805: } else {
1806: $blocklist->{$type} = 'off';
1807: }
1808: }
1809: return $blocklist;
1810: }
1811:
1.1 albertel 1812: sub display_blocker_status {
1813: my ($r,$records,$ltext) = @_;
1814: my $parmcount = 0;
1.16 albertel 1815:
1.1 albertel 1816: my %lt = &Apache::lonlocal::texthash(
1817: 'modi' => 'Modify',
1818: 'canc' => 'Cancel',
1819: );
1.44 raeburn 1820: my ($typeorder,$types) = &blocktype_text();
1.18 albertel 1821: $r->print(&Apache::loncommon::start_data_table());
1.1 albertel 1822: $r->print(<<"END");
1.16 albertel 1823: <tr>
1.44 raeburn 1824: <th>$ltext->{'dura'}</th>
1825: <th>$ltext->{'setb'}</th>
1826: <th>$ltext->{'even'}</th>
1827: <th>$ltext->{'blck'}</th>
1828: <th>$ltext->{'actn'}?</th>
1.16 albertel 1829: </tr>
1.1 albertel 1830: END
1.18 albertel 1831: foreach my $record (sort(keys(%{$records}))) {
1.1 albertel 1832: my $onchange = 'onFocus="javascript:window.document.forms['.
1833: "'blockform'].elements['modify_".$parmcount."'].".
1834: 'checked=true;"';
1.18 albertel 1835: my ($start,$end) = split(/____/,$record);
1.1 albertel 1836: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
1837: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1.15 albertel 1838:
1.44 raeburn 1839: my ($setuname,$setudom,$title,$blocks) =
1840: &Apache::loncommon::parse_block_record($$records{$record});
1.21 albertel 1841: $title = &HTML::Entities::encode($title,'"<>&');
1.44 raeburn 1842: my $settername =
1843: &Apache::loncommon::aboutmewrapper(
1844: &Apache::loncommon::plainname($setuname,$setudom),
1845: $setuname,$setudom);
1.18 albertel 1846: $r->print(&Apache::loncommon::start_data_table_row());
1.1 albertel 1847: $r->print(<<"END");
1.44 raeburn 1848: <td>$ltext->{'star'}: $startform<br/>$ltext->{'endd'}: $endform</td>
1.1 albertel 1849: <td>$settername</td>
1.18 albertel 1850: <td><input type="text" name="title_$parmcount" size="15" value="$title" /><input type="hidden" name="key_$parmcount" value="$record" /></td>
1.44 raeburn 1851: <td>
1852: END
1853: foreach my $block (@{$typeorder}) {
1854: my $blockstatus = '';
1855: if ($blocks->{$block} eq 'on') {
1856: $blockstatus = 'checked="true"';
1857: }
1858: $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" '.$blockstatus.' value="1" />'.$types->{$block}.'</label><br />');
1859: }
1860: $r->print(<<"END");
1861: </td>
1.1 albertel 1862: <td><label>$lt{'modi'}? <input type="checkbox" name="modify_$parmcount" /></label><br /><label>$lt{'canc'}? <input type="checkbox" name="cancel_$parmcount" /></label>
1863: END
1.18 albertel 1864: $r->print(&Apache::loncommon::end_data_table_row());
1865: $parmcount++;
1.1 albertel 1866: }
1867: $r->print(<<"END");
1868: </table>
1869: <br />
1870: <br />
1871: END
1872: return $parmcount;
1873: }
1874:
1875: sub display_addblocker_table {
1876: my ($r,$parmcount,$ltext) = @_;
1877: my $start = time;
1878: my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
1879: my $onchange = 'onFocus="javascript:window.document.forms['.
1880: "'blockform'].elements['add_".$parmcount."'].".
1881: 'checked=true;"';
1882: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
1883: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1884: my %lt = &Apache::lonlocal::texthash(
1885: 'addb' => 'Add block',
1886: 'exam' => 'e.g., Exam 1',
1887: 'addn' => 'Add new communication blocking periods'
1888: );
1.44 raeburn 1889: my ($typeorder,$types) = &blocktype_text();
1.1 albertel 1890: $r->print(<<"END");
1891: <h4>$lt{'addn'}</h4>
1.18 albertel 1892: END
1893: $r->print(&Apache::loncommon::start_data_table());
1894: $r->print(<<"END");
1.16 albertel 1895: <tr>
1.44 raeburn 1896: <th>$ltext->{'dura'}</th>
1897: <th>$ltext->{'even'} $lt{'exam'}</th>
1898: <th>$ltext->{'blck'}</th>
1899: <th>$ltext->{'actn'}?</th>
1.16 albertel 1900: </tr>
1.18 albertel 1901: END
1.44 raeburn 1902: $r->print(&Apache::loncommon::start_data_table_row());
1.18 albertel 1903: $r->print(<<"END");
1.44 raeburn 1904: <td>$ltext->{'star'}: $startform<br />$ltext->{'endd'}: $endform</td>
1.16 albertel 1905: <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
1.44 raeburn 1906: <td>
1907: END
1908: foreach my $block (@{$typeorder}) {
1909: $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" value="1" />'.$types->{$block}.'</label><br />');
1910: }
1911: $r->print(<<"END");
1912: </td>
1.16 albertel 1913: <td><label>$lt{'addb'}? <input type="checkbox" name="add_$parmcount" value="1" /></label></td>
1.1 albertel 1914: END
1.18 albertel 1915: $r->print(&Apache::loncommon::end_data_table_row());
1916: $r->print(&Apache::loncommon::end_data_table());
1.1 albertel 1917: return;
1918: }
1919:
1.44 raeburn 1920: sub blocktype_text {
1921: my %types = &Apache::lonlocal::texthash(
1922: 'com' => 'Messaging',
1923: 'chat' => 'Chat',
1924: 'boards' => 'Discussion',
1925: 'port' => 'Portfolio',
1.45 raeburn 1926: 'groups' => 'Groups',
1927: 'blogs' => 'Blogs',
1.18 albertel 1928: );
1.45 raeburn 1929: my $typeorder = ['com','chat','boards','port','groups','blogs'];
1.44 raeburn 1930: return ($typeorder,\%types);
1.1 albertel 1931: }
1932:
1933: # ----------------------------------------------------------- Display a message
1934:
1935: sub displaymessage {
1.53 raeburn 1936: my ($r,$msgid,$folder,$msgstatus)=@_;
1.1 albertel 1937: my $suffix=&Apache::lonmsg::foldersuffix($folder);
1938: my %blocked = ();
1939: my %setters = ();
1940: my $numblocked = 0;
1.33 albertel 1941: my $crstype = &Apache::loncommon::course_type();
1.30 raeburn 1942:
1.1 albertel 1943: # info to generate "next" and "previous" buttons and check if message is blocked
1.44 raeburn 1944: my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53 raeburn 1945: my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1 albertel 1946: if ( $blocked{$msgid} eq 'ON' ) {
1947: &printheader($r,'/adm/email',&mt('Display a Message'));
1948: $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.'));
1949: &build_block_table($r,$startblock,$endblock,\%setters);
1950: return;
1951: }
1.59 raeburn 1952: if ($msgstatus eq '') {
1953: &statuschange($msgid,'read',$folder);
1954: }
1.1 albertel 1955: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1956: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid});
1957:
1958: my $counter=0;
1959: $r->print('<pre>');
1.29 www 1960: my $escmsgid=&escape($msgid);
1.1 albertel 1961: foreach (@messages) {
1962: if ($_->[5] eq $escmsgid){
1963: last;
1964: }
1965: $counter++;
1966: }
1967: $r->print('</pre>');
1968: my $number_of_messages = scalar(@messages); #subtract 1 for last index
1969: # start output
1.29 www 1970: &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'});
1.1 albertel 1971: my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'});
1972: # Functions
1973: $r->print('<table border="2" width="100%"><tr bgcolor="#FFFFAA"><td>'.&mt('Functions').':</td>'.
1.29 www 1974: '<td><a href="/adm/email?replyto='.&escape($msgid).$sqs.
1.1 albertel 1975: '"><b>'.&mt('Reply').'</b></a></td>'.
1.29 www 1976: '<td><a href="/adm/email?forward='.&escape($msgid).$sqs.
1.1 albertel 1977: '"><b>'.&mt('Forward').'</b></a></td>'.
1.29 www 1978: '<td><a href="/adm/email?markunread='.&escape($msgid).$sqs.
1.1 albertel 1979: '"><b>'.&mt('Mark Unread').'</b></a></td>'.
1.29 www 1980: '<td><a href="/adm/email?markdel='.&escape($msgid).$sqs.
1.1 albertel 1981: '"><b>'.&mt('Delete').'</b></a></td>'.
1982: '<td><a href="/adm/email?'.$sqs.
1983: '"><b>'.&mt('Back to Folder Display').'</b></a></td>');
1984: if ($counter > 0){
1985: $r->print('<td><a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.
1986: '"><b>'.&mt('Previous').'</b></a></td>');
1987: }
1988: if ($counter < $number_of_messages - 1){
1989: $r->print('<td><a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.
1990: '"><b>'.&mt('Next').'</b></a></td>');
1991: }
1992: $r->print('</tr></table>');
1.59 raeburn 1993: my $symb;
1994: if (defined($content{'symb'})) {
1995: $symb = $content{'symb'};
1996: } elsif (defined($content{'baseurl'})) {
1997: $symb=&Apache::lonnet::symbread($content{'baseurl'});
1998: }
1.1 albertel 1999: if ($env{'user.adv'}) {
2000: $r->print('<table border="2" width="100%"><tr bgcolor="#FFAAAA"><td>'.&mt('Currently available actions (will open extra window)').':</td>');
2001: if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
2002: $r->print('<td><b>'.&Apache::loncommon::track_student_link(&mt('View recent activity'),$content{'sendername'},$content{'senderdomain'},'check').'</b></td>');
2003: }
2004: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
2005: $r->print('<td><b>'.&Apache::loncommon::pprmlink(&mt('Set/Change parameters'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
2006: }
2007: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
2008: $r->print('<td><b>'.&Apache::loncommon::pgrdlink(&mt('Set/Change grades'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
2009: }
2010: $r->print('</tr></table>');
2011: }
2012: my $tolist;
2013: my @recipients = ();
2014: for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
2015: $recipients[$i] = &Apache::loncommon::aboutmewrapper(
2016: &Apache::loncommon::plainname($content{'recuser'}[$i],
2017: $content{'recdomain'}[$i]),
2018: $content{'recuser'}[$i],$content{'recdomain'}[$i]).
2019: ' ('.$content{'recuser'}[$i].' at '.$content{'recdomain'}[$i].') ';
2020: }
2021: $tolist = join(', ',@recipients);
1.59 raeburn 2022: my ($restitle,$baseurl,$refers_to);
2023: if (defined($content{'resource_title'})) {
2024: $restitle = $content{'resource_title'};
2025: } else {
2026: if (defined($content{'baseurl'})) {
2027: $restitle = &Apache::lonnet::gettitle($content{'baseurl'});
2028: }
2029: }
2030: if (defined($content{'baseurl'})) {
2031: $baseurl = &Apache::lonenc::check_encrypt($content{'baseurl'});
2032: }
1.1 albertel 2033: $r->print('<br /><b>'.&mt('Subject').':</b> '.$content{'subject'}.
2034: ($folder ne 'sent'?'<br /><b>'.&mt('From').':</b> '.
2035: &Apache::loncommon::aboutmewrapper(
2036: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
2037: $content{'sendername'},$content{'senderdomain'}).' ('.
2038: $content{'sendername'}.' at '.
2039: $content{'senderdomain'}.') ':'<br /><b>'.&mt('To').':</b> '.
2040: $tolist).
1.30 raeburn 2041: ($content{'courseid'}?'<br /><b>'.&mt($crstype).':</b> '.$courseinfo{'description'}.
2042: ($content{'coursesec'}?' ('.&mt('Section').': '.$content{'coursesec'}.')':''):'').
1.59 raeburn 2043: '<br /><b>'.&mt('Time').':</b> '.$content{'time'});
2044: if ($baseurl) {
2045: if (defined($content{'courseid'}) && defined($env{'request.course.id'})) {
2046: if ($content{'courseid'} eq $env{'request.course.id'}) {
2047: my $symblink;
1.62 raeburn 2048: my $showsymb = &Apache::lonenc::check_decrypt($symb);
2049: my $showurl = &Apache::lonenc::check_decrypt($baseurl);
2050: my $encrypturl = &Apache::lonnet::EXT('resource.0.encrypturl',
2051: $showsymb,$env{'user.domain'},$env{'user.name'});
1.59 raeburn 2052: if ($symb) {
1.62 raeburn 2053: if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
2054: $showsymb = &Apache::lonenc::check_encrypt($symb);
2055: }
2056: $symblink = '?symb='.$showsymb;
2057: }
2058: if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
2059: $showurl = $baseurl;
1.59 raeburn 2060: }
1.62 raeburn 2061: $r->print('<br /><b>'.&mt('Refers to').':</b> <a href="'.$showurl.$symblink.'">'.$restitle.'</a>');
1.59 raeburn 2062: $refers_to = 1;
2063: }
2064: }
2065: if (!$refers_to) {
2066: if ($baseurl =~ m-^/enc/-) {
2067: if (defined($content{'courseid'})) {
1.62 raeburn 2068: if (!$env{'request.course.id'}) {
2069: my $unencurl =
2070: &Apache::lonenc::unencrypted($baseurl,
2071: $content{'courseid'});
2072: if ($unencurl ne '') {
2073: if (&Apache::lonnet::allowed('bre',$unencurl)) {
2074: $r->print('<br /><b>'.&mt('Refers to').
2075: ':</b> <a href="'.$unencurl.'">'.
2076: $restitle.'</a>');
2077: }
1.59 raeburn 2078: }
2079: }
2080: }
2081: } else {
2082: if (&Apache::lonnet::allowed('bre',$baseurl)) {
2083: $r->print('<br /><b>'.&mt('Refers to').
2084: ':</b> <a href="'.$baseurl.
2085: '">'.$restitle.'</a>');
2086: }
2087: }
2088: }
2089: }
2090: $r->print('<p><pre>'.
1.1 albertel 2091: &Apache::lontexconvert::msgtexconverted($content{'message'},1).
2092: '</pre><hr />'.&displayresource(%content).'</p>');
1.59 raeburn 2093: return;
1.1 albertel 2094: }
2095:
2096: # =========================================================== Show the citation
2097:
2098: sub displayresource {
2099: my %content=@_;
2100: #
2101: # If the recipient is in the same course that the message was sent from and
2102: # has sufficient privileges, show "all details," else show citation
2103: #
2104: if (($env{'request.course.id'} eq $content{'courseid'})
2105: && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
1.59 raeburn 2106: my $symb;
2107: if (defined($content{'symb'})) {
2108: $symb = $content{'symb'};
2109: } else {
2110: $symb=&Apache::lonnet::symbread($content{'baseurl'});
2111: }
1.1 albertel 2112: # Could not get a symb, give up
2113: unless ($symb) { return $content{'citation'}; }
2114: # Have a symb, can render
2115: return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
2116: &Apache::loncommon::get_previous_attempt($symb,
2117: $content{'sendername'},
2118: $content{'senderdomain'},
2119: $content{'courseid'}).
2120: '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
2121: &Apache::loncommon::get_student_view($symb,
2122: $content{'sendername'},
2123: $content{'senderdomain'},
2124: $content{'courseid'}).
2125: '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
2126: &Apache::loncommon::get_student_answers($symb,
2127: $content{'sendername'},
2128: $content{'senderdomain'},
2129: $content{'courseid'});
2130: } elsif ($env{'user.adv'}) {
2131: return $content{'citation'};
2132: }
2133: return '';
2134: }
2135:
2136: # ================================================================== The Header
2137:
2138: sub header {
2139: my ($r,$title,$baseurl)=@_;
2140:
2141: my $extra = &Apache::loncommon::studentbrowser_javascript();
2142: if ($baseurl) {
1.41 albertel 2143: $extra .= "<base href=\"".&Apache::lonnet::absolute_url()."/$baseurl\" />";
1.1 albertel 2144: }
2145: $r->print(&Apache::loncommon::start_page('Communication and Messages',
1.38 raeburn 2146: $extra));
1.1 albertel 2147: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.38 raeburn 2148: (($title?$title:'Communication and Messages')));
1.1 albertel 2149: }
2150:
2151: # ---------------------------------------------------------------- Print header
2152:
2153: sub printheader {
2154: my ($r,$url,$desc,$title,$baseurl)=@_;
2155: &Apache::lonhtmlcommon::add_breadcrumb
2156: ({href=>$url,
2157: text=>$desc});
2158: &header($r,$title,$baseurl);
2159: }
2160:
2161: # ------------------------------------------------------------ Store the comment
2162:
2163: sub storecomment {
2164: my ($r)=@_;
2165: my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2166: my $cleanmsgtxt='';
1.42 raeburn 2167: foreach my $line (split(/[\n\r]/,$msgtxt)) {
2168: unless ($line=~/^\s*(\>|\>\;)/) {
2169: $cleanmsgtxt.=$line."\n";
1.1 albertel 2170: }
2171: }
1.29 www 2172: my $key=&escape($env{'form.baseurl'}).'___'.time;
1.1 albertel 2173: &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
2174: }
2175:
2176: sub storedcommentlisting {
2177: my ($r)=@_;
2178: my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
1.29 www 2179: '^'.&escape(&escape($env{'form.showcommentbaseurl'})));
1.1 albertel 2180: $r->print(&Apache::loncommon::start_page('Stored Comment Listing',undef,
2181: {'onlybody' => 1}));
2182: if ((keys %msgs)[0]=~/^error\:/) {
2183: $r->print(&mt('No stored comments yet.'));
2184: } else {
2185: my $found=0;
1.42 raeburn 2186: foreach my $key (sort(keys(%msgs))) {
2187: $r->print("\n".$msgs{$key}."<hr />");
1.1 albertel 2188: $found=1;
2189: }
2190: unless ($found) {
2191: $r->print(&mt('No stored comments yet for this resource.'));
2192: }
2193: }
2194: }
2195:
2196: # ---------------------------------------------------------------- Send an email
2197:
2198: sub sendoffmail {
2199: my ($r,$folder)=@_;
2200: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2201: my $sendstatus='';
2202: my %specialmsg_status;
2203: my $numspecial = 0;
1.38 raeburn 2204: my ($cdom,$cnum,$group);
2205: if (exists($env{'form.group'})) {
2206: $group = $env{'form.group'};
2207: }
2208: if (exists($env{'request.course.id'})) {
2209: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2210: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2211: }
1.1 albertel 2212: if ($env{'form.send'}) {
1.53 raeburn 2213: if (!$env{'form.multiforward'}) {
2214: if ($group eq '') {
2215: &printheader($r,'','Messages being sent.');
2216: } else {
2217: $r->print(&groupmail_header('sending',$group));
2218: }
1.38 raeburn 2219: }
1.1 albertel 2220: $r->rflush();
2221: my %content=();
2222: undef %content;
2223: if ($env{'form.forwid'}) {
2224: my $msgid=$env{'form.forwid'};
2225: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2226: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2227: &statuschange($msgid,'forwarded',$folder);
2228: $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
2229: $content{'message'};
2230: }
2231: if ($env{'form.replyid'}) {
2232: my $msgid=$env{'form.replyid'};
2233: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2234: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2235: &statuschange($msgid,'replied',$folder);
2236: }
1.13 albertel 2237:
1.35 albertel 2238: my @to =
1.37 raeburn 2239: &Apache::loncommon::get_env_multiple('form.selectedusers_forminput');
1.25 foxr 2240: my $mode = $env{'form.sendmode'};
2241:
1.13 albertel 2242: my %toaddr;
1.35 albertel 2243: if (@to) {
2244: foreach my $dest (@to) {
1.27 albertel 2245: my ($user,$domain) = split(/:/, $dest);
1.25 foxr 2246: if (($user ne '') && ($domain ne '')) {
2247: my $address = $user.":".$domain; # How the code below expects it.
2248: $toaddr{$address} = '';
2249: }
2250: }
2251: }
2252:
1.1 albertel 2253: if ($env{'form.sendmode'} eq 'group') {
1.25 foxr 2254: foreach my $address (keys(%env)) {
2255: if ($address=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
2256: $toaddr{$1}='';
2257: }
1.1 albertel 2258: }
2259: } elsif ($env{'form.sendmode'} eq 'upload') {
1.13 albertel 2260: foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
1.43 raeburn 2261: my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/);
1.1 albertel 2262: if ($txt) {
1.43 raeburn 2263: $rec =~ s/^\s+//;
1.44 raeburn 2264: $rec =~ s/\s+$//;
1.1 albertel 2265: $toaddr{$rec}.=$txt."\n";
2266: }
2267: }
2268: } else {
1.25 foxr 2269: if (($env{'form.recuname'} ne '') && ($env{'form.recdomain'} ne '')) {
2270: $toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
2271: }
1.1 albertel 2272: }
2273: if ($env{'form.additionalrec'}) {
1.42 raeburn 2274: foreach my $rec (split(/\,/,$env{'form.additionalrec'})) {
1.43 raeburn 2275: my ($auname,$audom)=split(/:/,$rec);
1.25 foxr 2276: if (($auname ne "") && ($audom ne "")) {
2277: $toaddr{$auname.':'.$audom}='';
2278: }
1.1 albertel 2279: }
2280: }
2281:
2282: my $savemsg;
2283: my $msgtype;
2284: my %sentmessage;
1.7 albertel 2285: my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'},
2286: undef,1);
1.1 albertel 2287: if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
2288: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
2289: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
2290: '/'.$env{'request.course.sec'})
2291: )) {
2292: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
2293: $msgtype = 'critical';
2294: } else {
2295: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2296: }
2297:
1.13 albertel 2298: foreach my $address (sort(keys(%toaddr))) {
2299: my ($recuname,$recdomain)=split(/\:/,$address);
1.1 albertel 2300: my $msgtxt = $savemsg;
1.13 albertel 2301: if ($toaddr{$address}) { $msgtxt.='<hr />'.$toaddr{$address}; }
1.12 albertel 2302: my @thismsg;
1.60 raeburn 2303: if ($msgtype eq 'critical') {
2304: $r->print(&mt('Sending critical message').' '.
2305: $recuname.':'.$recdomain.': ');
1.13 albertel 2306: @thismsg=
2307: &Apache::lonmsg::user_crit_msg($recuname,$recdomain,
2308: $msgsubj,$msgtxt,
2309: $env{'form.sendbck'},
2310: $env{'form.permanent'},
2311: \$sentmessage{$address});
1.1 albertel 2312: } else {
1.14 albertel 2313: $r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': ');
1.13 albertel 2314: @thismsg=
2315: &Apache::lonmsg::user_normal_msg($recuname,$recdomain,
2316: $msgsubj,$msgtxt,
2317: $content{'citation'},
2318: undef,undef,
2319: $env{'form.permanent'},
2320: \$sentmessage{$address});
1.1 albertel 2321: }
2322: if (($env{'request.course.id'}) && (($msgtype eq 'critical') ||
2323: ($env{'form.sendmode'} eq 'group'))) {
1.12 albertel 2324: $specialmsg_status{$recuname.':'.$recdomain} =
2325: join(' ',@thismsg);
2326: foreach my $result (@thismsg) {
1.60 raeburn 2327: if ($result eq 'ok' || $result eq 'con_delayed') {
1.12 albertel 2328: $numspecial++;
2329: }
2330: }
1.1 albertel 2331: }
1.12 albertel 2332: $sendstatus.=' '.join(' ',@thismsg);
1.1 albertel 2333: }
2334: if (($env{'request.course.id'}) && (($env{'form.sendmode'} eq 'group')
2335: || ($msgtype eq 'critical'))) {
2336: my $subj_prefix;
2337: if ($msgtype eq 'critical') {
2338: $subj_prefix = 'Critical.';
2339: } else {
2340: $subj_prefix = 'Broadcast.';
2341: }
2342: my ($specialmsgid,$specialresult);
1.29 www 2343: my $course_str = &escape('['.$cnum.':'.$cdom.']');
1.1 albertel 2344:
2345: if ($numspecial) {
2346: $specialresult = &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
2347: ' '.$course_str,$savemsg,undef,undef,undef,
2348: undef,undef,\$specialmsgid);
1.29 www 2349: $specialmsgid = &unescape($specialmsgid);
1.1 albertel 2350: }
2351: if ($specialresult eq 'ok') {
2352: my $record_sent;
1.13 albertel 2353: my @recusers;
2354: my @recudoms;
2355: my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
1.29 www 2356: split(/\:/,&unescape($specialmsgid));
1.13 albertel 2357:
1.1 albertel 2358: foreach my $recipient (sort(keys(%toaddr))) {
2359: if ($specialmsg_status{$recipient} eq 'ok') {
2360: my $usersubj = $subj_prefix.'['.$recipient.']';
2361: my $usermsgid =
2362: &Apache::lonmsg::buildmsgid($stamp,$usersubj,
2363: $msgname,$msgdom,
2364: $msgcount,$context,
2365: $pid);
2366: &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
2367: ' ['.$recipient.']',$msgsubj,undef,
2368: undef,undef,undef,$usermsgid,undef,undef,$specialmsgid);
1.13 albertel 2369: my ($uname,$udom) = split(/:/,$recipient);
1.1 albertel 2370: push(@recusers,$uname);
2371: push(@recudoms,$udom);
2372: }
2373: }
2374: if (@recusers) {
2375: my $specialmessage;
1.13 albertel 2376: my $sentsubj =
2377: $subj_prefix.' ('.$numspecial.' sent) '.$msgsubj;
1.1 albertel 2378: $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
2379: my $sentmsgid =
2380: &Apache::lonmsg::buildmsgid($stamp,$sentsubj,$msgname,
2381: $msgdom,$msgcount,$context,
2382: $pid);
2383: ($specialmsgid,$specialmessage) = &Apache::lonmsg::packagemsg($msgsubj,$savemsg,
2384: undef,undef,undef,\@recusers,\@recudoms,$sentmsgid);
2385: $record_sent = &Apache::lonmsg::store_sent_mail($specialmsgid,$specialmessage);
2386: }
2387: } else {
2388: &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');
2389: }
2390: }
2391: } else {
2392: &printheader($r,'','No messages sent.');
2393: }
1.53 raeburn 2394: if (!$env{'form.multiforward'}) {
2395: if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
2396: $r->print('<br /><span class="LC_success">'.&mt('Completed.').
2397: '</span>');
2398: if ($env{'form.displayedcrit'}) {
2399: &discrit($r);
2400: }
2401: if ($group ne '') {
2402: $r->print(&groupmail_sent($group,$cdom,$cnum));
2403: } else {
2404: &Apache::loncommunicate::menu($r);
2405: }
2406: } else {
2407: $r->print('<p><span class="LC_error">'.&mt('Could not deliver message').'</span> '.
2408: &mt('Please use the browser "Back" button and correct the recipient addresses '."($sendstatus)").'</p>');
1.38 raeburn 2409: }
1.1 albertel 2410: }
1.53 raeburn 2411: return $sendstatus;
1.1 albertel 2412: }
2413:
2414: # ===================================================================== Handler
2415:
2416: sub handler {
2417: my $r=shift;
2418:
2419: # ----------------------------------------------------------- Set document type
2420:
2421: &Apache::loncommon::content_type($r,'text/html');
2422: $r->send_http_header;
2423:
2424: return OK if $r->header_only;
2425:
2426: # --------------------------- Get query string for limited number of parameters
2427: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2428: ['display','replyto','forward','markread','markdel','markunread',
2429: 'sendreply','compose','sendmail','critical','recname','recdom',
2430: 'recordftf','sortedby','block','folder','startdis','interdis',
1.53 raeburn 2431: 'showcommentbaseurl','dismode','group','subject','text','ref',
2432: 'msgstatus']);
1.1 albertel 2433: $sqs='&sortedby='.$env{'form.sortedby'};
2434:
2435: # ------------------------------------------------------ They checked for email
2436: unless ($env{'form.block'}) {
2437: &Apache::lonnet::put('email_status',{'recnewemail'=>0});
2438: }
2439:
2440: # ----------------------------------------------------------------- Breadcrumbs
2441:
2442: &Apache::lonhtmlcommon::clear_breadcrumbs();
2443: &Apache::lonhtmlcommon::add_breadcrumb
2444: ({href=>"/adm/communicate",
2445: text=>"Communication/Messages",
2446: faq=>12,bug=>'Communication Tools',});
2447:
2448: # ------------------------------------------------------------------ Get Folder
2449:
2450: my $folder=$env{'form.folder'};
2451: unless ($folder) {
2452: $folder='';
2453: } else {
1.29 www 2454: $sqs.='&folder='.&escape($folder);
1.1 albertel 2455: }
2456: # ------------------------------------------------------------ Get Display Mode
2457:
2458: my $dismode=$env{'form.dismode'};
2459: unless ($dismode) {
2460: $dismode='';
2461: } else {
1.48 albertel 2462: $sqs.='&dismode='.&escape($dismode);
1.1 albertel 2463: }
2464:
2465: # --------------------------------------------------------------------- Display
1.53 raeburn 2466: my $msgstatus = $env{'form.msgstatus'};
1.1 albertel 2467: $startdis=$env{'form.startdis'};
1.53 raeburn 2468: if ($startdis ne '') {
2469: $startdis--;
2470: }
1.1 albertel 2471: unless ($startdis) { $startdis=0; }
2472:
2473: if ($env{'form.firstview'}) {
2474: $startdis=0;
2475: }
2476: if ($env{'form.lastview'}) {
2477: $startdis=-1;
2478: }
2479: if ($env{'form.prevview'}) {
2480: $startdis--;
2481: }
2482: if ($env{'form.nextview'}) {
2483: $startdis++;
2484: }
2485: my $postedstartdis=$startdis+1;
2486: $sqs.='&startdis='.$postedstartdis;
2487:
2488: # --------------------------------------------------------------- Render Output
2489:
2490: if ($env{'form.display'}) {
1.53 raeburn 2491: &displaymessage($r,$env{'form.display'},$folder,$msgstatus);
1.1 albertel 2492: } elsif ($env{'form.replyto'}) {
2493: &compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode);
2494: } elsif ($env{'form.confirm'}) {
2495: &printheader($r,'','Confirmed Receipt');
1.36 albertel 2496: my $replying = 0;
1.42 raeburn 2497: foreach my $envkey (keys(%env)) {
2498: if ($envkey=~/^form\.rec\_(.*)$/) {
1.1 albertel 2499: $r->print('<b>'.&mt('Confirming Receipt').':</b> '.
2500: &Apache::lonmsg::user_crit_received($1).'<br>');
2501: }
1.42 raeburn 2502: if ($envkey=~/^form\.reprec\_(.*)$/) {
1.1 albertel 2503: my $msgid=$1;
2504: $r->print('<b>'.&mt('Confirming Receipt').':</b> '.
2505: &Apache::lonmsg::user_crit_received($msgid).'<br>');
2506: &compout($r,'','','',$msgid);
1.36 albertel 2507: $replying = 1;
1.1 albertel 2508: }
2509: }
1.36 albertel 2510: if (!$replying) {
2511: &discrit($r);
2512: }
1.1 albertel 2513: } elsif ($env{'form.critical'}) {
2514: &printheader($r,'','Displaying Critical Messages');
2515: &discrit($r);
2516: } elsif ($env{'form.forward'}) {
2517: &compout($r,$env{'form.forward'},undef,undef,undef,$folder);
2518: } elsif ($env{'form.markdel'}) {
2519: &printheader($r,'','Deleted Message');
1.9 albertel 2520: my ($result,$msg) =
2521: &statuschange($env{'form.markdel'},'deleted',$folder);
2522: if (!$result) {
1.10 albertel 2523: $r->print('<p class="LC_error">'.
2524: &mt('Failed to delete the message.').'</p>'.
1.9 albertel 2525: '<p class="LC_error">'.$msg."</p>\n");
2526: }
1.1 albertel 2527: &Apache::loncommunicate::menu($r);
1.53 raeburn 2528: &disall($r,($folder?$folder:$dismode),$msgstatus);
2529: } elsif ($env{'form.markedaction'} eq 'markedforward') {
2530: my $total = 0;
2531: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
2532: foreach my $msgid (@to_forward) {
2533: &statuschange(&unescape($msgid),'forwarded',$folder);
2534: $total ++;
2535: }
2536: if ($total > 0) {
2537: &compout($r,undef,undef,undef,undef,$folder,$dismode,$total);
2538: }
2539: } elsif ($env{'form.markedaction'} eq 'markedread') {
2540: my $total = 0;
2541: my @to_markread = &Apache::loncommon::get_env_multiple('form.delmark');
2542: foreach my $msgid (@to_markread) {
2543: &statuschange(&unescape($msgid),'read',$folder);
2544: $total ++;
2545: }
2546: &printheader($r,'','Marked Messages Read');
2547: $r->print(&mt('Marked [_1] message(s) read',$total).'<p>');
2548: &Apache::loncommunicate::menu($r);
2549: &disall($r,($folder?$folder:$dismode),$msgstatus);
2550: } elsif ($env{'form.markedaction'} eq 'markedunread') {
2551: my $total = 0;
2552: my @to_markunread = &Apache::loncommon::get_env_multiple('form.delmark');
2553: foreach my $msgid (@to_markunread) {
2554: &statuschange(&unescape($msgid),'new',$folder);
2555: $total ++;
2556: }
2557: &printheader($r,'','Marked Messages Unread');
2558: $r->print(&mt('Marked [_1] message(s) unread',$total).'<p>');
2559: &Apache::loncommunicate::menu($r);
2560: &disall($r,($folder?$folder:$dismode),$msgstatus);
2561: } elsif ($env{'form.markedaction'} eq 'markedmove') {
2562: my $destfolder = $env{'form.movetofolder'};
2563: my %gotfolders = &Apache::lonmsg::get_user_folders();
2564: &printheader($r,'','Moved Messages');
2565: if (!defined($gotfolders{$destfolder})) {
2566: $r->print(&mt('Destination folder [_1] is not a valid folder',
2567: $destfolder));
2568: } else {
2569: my ($total,$failed,@failed_msg)=(0,0);
2570: my @to_move = &Apache::loncommon::get_env_multiple('form.delmark');
2571: foreach my $msgid (@to_move) {
2572: my ($result,$msg) = &movemsg(&unescape($msgid),$folder,
2573: $env{'form.movetofolder'});
2574: if ($result) {
1.9 albertel 2575: $total++;
1.53 raeburn 2576: } else {
1.9 albertel 2577: $failed++;
2578: push(@failed_msg,$msg);
1.53 raeburn 2579: }
1.1 albertel 2580: }
1.53 raeburn 2581: if ($failed) {
2582: $r->print('<p class="LC_error">
1.10 albertel 2583: '.&mt('Failed to move [_1] message(s)',$failed).
2584: '</p>');
1.53 raeburn 2585: $r->print('<p class="LC_error">'.
2586: join("</p>\n<p class=\"LC_error\">",@failed_msg).
2587: "</p>\n");
2588: }
2589: $r->print(&mt('Moved [_1] message(s)',$total).'<p>');
2590: }
1.1 albertel 2591: &Apache::loncommunicate::menu($r);
1.53 raeburn 2592: &disall($r,($folder?$folder:$dismode),$msgstatus);
2593: } elsif ($env{'form.markedaction'} eq 'markeddel') {
1.9 albertel 2594: my ($total,$failed,@failed_msg)=(0,0);
1.53 raeburn 2595: my @to_delete = &Apache::loncommon::get_env_multiple('form.delmark');
2596: foreach my $msgid (@to_delete) {
2597: my ($result,$msg) = &statuschange(&unescape($msgid),'deleted',
2598: $folder);
2599: if ($result) {
2600: $total++;
2601: } else {
2602: $failed++;
2603: push(@failed_msg,$msg);
1.1 albertel 2604: }
2605: }
2606: &printheader($r,'','Deleted Messages');
1.9 albertel 2607: if ($failed) {
2608: $r->print('<p class="LC_error">
1.10 albertel 2609: '.&mt('Failed to delete [_1] message(s)',$failed).
2610: '</p>');
1.9 albertel 2611: $r->print('<p class="LC_error">'.
2612: join("</p>\n<p class=\"LC_error\">",@failed_msg).
2613: "</p>\n");
2614: }
1.10 albertel 2615: $r->print(&mt('Deleted [_1] message(s)',$total).'<p>');
1.1 albertel 2616: &Apache::loncommunicate::menu($r);
1.53 raeburn 2617: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 2618: } elsif ($env{'form.markunread'}) {
2619: &printheader($r,'','Marked Message as Unread');
2620: &statuschange($env{'form.markunread'},'new');
2621: &Apache::loncommunicate::menu($r);
1.53 raeburn 2622: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 2623: } elsif ($env{'form.compose'}) {
2624: &compout($r,'','',$env{'form.compose'});
2625: } elsif ($env{'form.recordftf'}) {
2626: &facetoface($r,$env{'form.recordftf'});
2627: } elsif ($env{'form.block'}) {
2628: &examblock($r,$env{'form.block'});
2629: } elsif ($env{'form.sendmail'}) {
1.53 raeburn 2630: if ($env{'form.multiforward'}) {
2631: &printheader($r,'','Messages being sent.');
2632: my $fixed_subj = $env{'form.subject'};
2633: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2634: my (%sendresult,%forwardok,%forwardfail,$fwdcount);
2635: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
2636: foreach my $item (@to_forward) {
2637: my $msgid=&unescape($item);
2638: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2639: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2640: if ($env{'form.showorigsubj'}) {
2641: $env{'form.subject'} = $fixed_subj.$content{'subject'};
2642: } else {
2643: $env{'form.subject'} = '';
2644: }
2645: my $uname = $content{'sendername'};
2646: my $udom = $content{'senderdomain'};
2647: &statuschange($msgid,'forwarded',$folder);
2648: if ($env{'form.showorigsender'}) {
2649: $env{'form.message'} = $env{'form.msgheader'}.' '.
2650: &Apache::loncommon::plainname($uname,$udom).' ('.
2651: $uname.':'.$udom.')';
2652: }
2653: $env{'form.message'} .= "\n\n-- Forwarded message --\n\n".
2654: $content{'message'};
2655: $fwdcount ++;
2656: $r->print($fwdcount.': ');
2657: $sendresult{$msgid} = &sendoffmail($r,$folder);
2658: $r->print('<br />');
2659: }
2660: foreach my $key (keys(%sendresult)) {
2661: if ($sendresult{$key} =~/^(\s*(?:ok|con_delayed)\s*)*$/) {
2662: $forwardok{$key} = $sendresult{$key};
2663: } else {
2664: $forwardfail{$key} = $sendresult{$key};
2665: }
2666: }
2667: if (keys(%forwardok) > 0) {
2668: my $count = keys(%forwardok);
2669: $r->print('<br /><span class="LC_success">'.
2670: &mt('[quant,_1,message] forwarded.',$count).
2671: '</span>');
2672: }
2673: if (keys(%forwardfail) > 0) {
2674: my $count = keys(%forwardfail);
2675: $r->print('<p><span class="LC_error">'.
2676: &mt('Could not forward [quant,_1,message].',$count).
2677: '</span> ');
2678: foreach my $key (keys(%forwardfail)) {
2679: $r->print(&mt('Could not deliver forwarded message.').'</span> '.
2680: &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.').<br /><br />');
2681: }
2682: }
2683: &Apache::loncommunicate::menu($r);
2684: } else {
2685: &sendoffmail($r,$folder);
2686: }
1.1 albertel 2687: if ($env{'form.storebasecomment'}) {
2688: &storecomment($r);
1.38 raeburn 2689: }
1.1 albertel 2690: if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
1.38 raeburn 2691: &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
1.1 albertel 2692: $env{'course.'.$env{'request.course.id'}.'.domain'},
2693: 'Course_Announcements',
2694: $env{'form.subject'},
2695: $env{'form.message'},'/adm/communicate','public');
2696: }
1.38 raeburn 2697: if ((!exists($env{'form.group'})) && (!$env{'form.displayedcrit'})) {
1.53 raeburn 2698: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.36 albertel 2699: }
1.1 albertel 2700: } elsif ($env{'form.newfolder'}) {
2701: &printheader($r,'','New Folder');
1.46 raeburn 2702: my $showfolder = $env{'form.newfolder'};
2703: my ($makeresult,$warning) = &makefolder($env{'form.newfolder'});
2704: if ($makeresult eq 'ok') {
2705: $r->print(&mt('Mail folder "[_1]" created.',$showfolder).'<br />');
2706: } else {
2707: $r->print(&mt('Creation failed.').' '.$makeresult.'<br />'.
2708: $warning);
2709: $showfolder = $folder;
2710: }
2711: &Apache::loncommunicate::menu($r);
1.53 raeburn 2712: &disall($r,$showfolder,$msgstatus);
1.1 albertel 2713: } elsif ($env{'form.showcommentbaseurl'}) {
2714: &storedcommentlisting($r);
1.46 raeburn 2715: } elsif ($env{'form.folderaction'} eq 'delete') {
2716: &printheader($r,'','Deleted Folder');
2717: my $showfolder = '';
2718: my $delresult = &deletefolder($folder);
2719: if ($delresult eq 'ok') {
2720: $r->print(&mt('Mail folder "[_1]" deleted.',$folder).'<br />');
2721: } else {
2722: $r->print(&mt('Deletion failed.').' '.$delresult.'<br />');
2723: $showfolder = $folder;
2724: }
2725: &Apache::loncommunicate::menu($r);
1.53 raeburn 2726: &disall($r,$showfolder,$msgstatus);
1.46 raeburn 2727: } elsif ($env{'form.folderaction'} eq 'rename') {
2728: &printheader($r,'','Renamed Folder');
2729: my $showfolder = $env{'form.renamed'};
2730: my $renresult = &renamefolder($folder);
2731: if ($renresult eq 'ok') {
2732: $r->print(&mt('Mail folder "[_1]" renamed "[_2]".',$folder,$showfolder).'<br />');
2733: } else {
2734: $r->print(&mt('Renaming failed.').' '.$renresult.'<br />');
2735: $showfolder = $folder;
2736: }
2737: &Apache::loncommunicate::menu($r);
1.53 raeburn 2738: &disall($r,$showfolder,$msgstatus);
1.1 albertel 2739: } else {
2740: &printheader($r,'','Display All Messages');
1.44 raeburn 2741: &Apache::loncommunicate::menu($r);
1.53 raeburn 2742: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 2743: }
2744: $r->print(&Apache::loncommon::end_page());
2745: return OK;
2746: }
2747: # ================================================= Main program, reset counter
2748:
2749: =pod
2750:
2751: =back
2752:
2753: =cut
2754:
2755: 1;
2756:
2757: __END__
2758:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>