Annotation of loncom/interface/lonmsgdisplay.pm, revision 1.57
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # Routines for messaging display
3: #
1.57 ! albertel 4: # $Id: lonmsgdisplay.pm,v 1.56 2006/12/23 06:19:10 albertel Exp $
1.1 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29:
30: package Apache::lonmsgdisplay;
31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::lonmsg: supports internal messaging
37:
38: =head1 SYNOPSIS
39:
40: lonmsg provides routines for sending messages, receiving messages, and
41: a handler to allow users to read, send, and delete messages.
42:
43: =head1 OVERVIEW
44:
45: =head2 Messaging Overview
46:
47: X<messages>LON-CAPA provides an internal messaging system similar to
48: email, but customized for LON-CAPA's usage. LON-CAPA implements its
49: own messaging system, rather then building on top of email, because of
50: the features LON-CAPA messages can offer that conventional e-mail can
51: not:
52:
53: =over 4
54:
55: =item * B<Critical messages>: A message the recipient B<must>
56: acknowlegde receipt of before they are allowed to continue using the
57: system, preventing a user from claiming they never got a message
58:
59: =item * B<Receipts>: LON-CAPA can reliably send reciepts informing the
60: sender that it has been read; again, useful for preventing students
61: from claiming they did not see a message. (While conventional e-mail
62: has some reciept support, it's sporadic, e-mail client-specific, and
63: generally the receiver can opt to not send one, making it useless in
64: this case.)
65:
66: =item * B<Context>: LON-CAPA knows about the sender, such as where
67: they are in a course. When a student mails an instructor asking for
68: help on the problem, the instructor receives not just the student's
69: question, but all submissions the student has made up to that point,
70: the user's rendering of the problem, and the complete view the student
71: saw of the resource, including discussion up to that point. Finally,
72: the instructor is reading all of this inside of LON-CAPA, not their
73: email program, so they have full access to LON-CAPA's grading
74: interface, or other features they may wish to use in response to the
75: student's query.
76:
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);
1.46 raeburn 777:
1.1 albertel 778: #unpack the varibles and repack into temp for sorting
779: my @temp;
780: my %descriptions;
781: my %status_cache =
782: &Apache::lonnet::get('email_status'.&Apache::lonmsg::foldersuffix($folder),\@messages);
1.11 albertel 783:
784: my $get_received;
785: if ($folder eq 'sent'
786: && ($env{'form.sortedby'} =~ m/^(rev)?(user|domain)$/)) {
787: $get_received = 1;
788: }
789:
790: foreach my $msgid (@messages) {
1.29 www 791: my $esc_msgid=&escape($msgid);
1.1 albertel 792: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)=
1.11 albertel 793: &Apache::lonmsg::unpackmsgid($esc_msgid,$folder,undef,
1.1 albertel 794: \%status_cache);
1.53 raeburn 795: next if ($msgstatus ne '' && $msgstatus ne $status);
1.1 albertel 796: my $description = &get_course_desc($fromcid,\%descriptions);
797: my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
1.11 albertel 798: $esc_msgid,$description);
799: if ($get_received) {
800: my %message = &Apache::lonnet::get('nohist_email'.$suffix,
801: [$msgid]);
802: my %content = &Apache::lonmsg::unpackagemsg($message{$msgid});
803: push(@temp1,$content{'recuser'},$content{'recdomain'});
804: }
1.1 albertel 805: # Check whether message was sent during blocking period.
806: if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
1.11 albertel 807: $$blocked{$msgid} = 'ON';
1.1 albertel 808: $$numblocked ++;
809: } else {
810: push @temp ,\@temp1;
811: }
812: }
813: #default sort
814: @temp = sort {$a->[0] <=> $b->[0]} @temp;
815: if ($env{'form.sortedby'} eq "date"){
816: @temp = sort {$a->[0] <=> $b->[0]} @temp;
817: }
818: if ($env{'form.sortedby'} eq "revdate"){
819: @temp = sort {$b->[0] <=> $a->[0]} @temp;
820: }
821: if ($env{'form.sortedby'} eq "user"){
1.11 albertel 822: if ($get_received) {
823: @temp = sort {lc($a->[7][0]) cmp lc($b->[7][0])} @temp;
824: } else {
825: @temp = sort {lc($a->[2]) cmp lc($b->[2])} @temp;
826: }
1.1 albertel 827: }
828: if ($env{'form.sortedby'} eq "revuser"){
1.11 albertel 829: if ($get_received) {
830: @temp = sort {lc($b->[7][0]) cmp lc($a->[7][0])} @temp;
831: } else {
832: @temp = sort {lc($b->[2]) cmp lc($a->[2])} @temp;
833: }
1.1 albertel 834: }
835: if ($env{'form.sortedby'} eq "domain"){
1.11 albertel 836: if ($get_received) {
837: @temp = sort {$a->[8][0] cmp $b->[8][0]} @temp;
838: } else {
839: @temp = sort {$a->[3] cmp $b->[3]} @temp;
840: }
1.1 albertel 841: }
842: if ($env{'form.sortedby'} eq "revdomain"){
1.11 albertel 843: if ($get_received) {
844: @temp = sort {$b->[8][0] cmp $a->[8][0]} @temp;
845: } else {
846: @temp = sort {$b->[3] cmp $a->[3]} @temp;
847: }
1.1 albertel 848: }
849: if ($env{'form.sortedby'} eq "subject"){
850: @temp = sort {lc($a->[1]) cmp lc($b->[1])} @temp;
851: }
852: if ($env{'form.sortedby'} eq "revsubject"){
853: @temp = sort {lc($b->[1]) cmp lc($a->[1])} @temp;
854: }
855: if ($env{'form.sortedby'} eq "course"){
856: @temp = sort {lc($a->[6]) cmp lc($b->[6])} @temp;
857: }
858: if ($env{'form.sortedby'} eq "revcourse"){
859: @temp = sort {lc($b->[6]) cmp lc($a->[6])} @temp;
860: }
861: if ($env{'form.sortedby'} eq "status"){
862: @temp = sort {$a->[4] cmp $b->[4]} @temp;
863: }
864: if ($env{'form.sortedby'} eq "revstatus"){
865: @temp = sort {$b->[4] cmp $a->[4]} @temp;
866: }
867: return @temp;
868: }
869:
870: sub get_course_desc {
871: my ($fromcid,$descriptions) = @_;
872: my $description;
873: if (!$fromcid) {
874: return $description;
875: } else {
876: if (defined($$descriptions{$fromcid})) {
877: $description = $$descriptions{$fromcid};
878: } else {
879: if (defined($env{'course.'.$fromcid.'.description'})) {
880: $description = $env{'course.'.$fromcid.'.description'};
881: } else {
1.48 albertel 882: my %courseinfo=&Apache::lonnet::coursedescription($fromcid);
1.1 albertel 883: $description = $courseinfo{'description'};
884: }
885: $$descriptions{$fromcid} = $description;
886: }
887: return $description;
888: }
889: }
890:
891: # ======================================================== Display all messages
892:
893: sub disall {
1.53 raeburn 894: my ($r,$folder,$msgstatus)=@_;
1.57 ! albertel 895: my %saveable = ('folder' => 'scalar',
! 896: 'msgstatus' => 'scalar',
! 897: 'sortedby' => 'scalar',
! 898: 'interdis' => 'scalar',
! 899: );
! 900: &Apache::loncommon::store_settings('user','mail',\%saveable);
! 901: &Apache::loncommon::restore_settings('user','mail',\%saveable);
! 902: $folder ||= $env{'form.folder'};
! 903: $msgstatus ||= $env{'form.msgstatus'};
! 904: $env{'form.interdis'} ||= 20;
! 905:
1.53 raeburn 906: $r->print(&folderlist($folder,$msgstatus));
907: if ($folder eq 'critical') {
1.1 albertel 908: &discrit($r);
909: } else {
1.53 raeburn 910: &disfolder($r,$folder,$msgstatus);
1.1 albertel 911: }
912: }
913:
914: # ============================================================ Display a folder
915:
916: sub disfolder {
1.53 raeburn 917: my ($r,$folder,$msgstatus)=@_;
918: my %statushash = &get_msgstatus_types();
1.1 albertel 919: my %blocked = ();
920: my %setters = ();
921: my $numblocked = 0;
1.44 raeburn 922: my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53 raeburn 923: my %lt = &Apache::lonlocal::texthash(
924: sede => 'Select a destination folder to which the messages will be moved.',
925: nome => 'No messages have been selected to apply ths action to.',
926: chec => 'Check the checkbox for at least one message.',
927: );
1.1 albertel 928: $r->print(<<ENDDISHEADER);
1.16 albertel 929: <script type="text/javascript">
1.1 albertel 930: function checkall() {
1.53 raeburn 931: for (i=0; i<document.forms.disall.delmark.length; i++) {
932: document.forms.disall.delmark[i].checked=true;
1.1 albertel 933: }
934: }
935:
936: function uncheckall() {
1.53 raeburn 937: for (i=0; i<document.forms.disall.delmark.length; i++) {
938: document.forms.disall.delmark[i].checked=false;
939: }
940: }
941: function checkfoldermove() {
942: if (document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value == 'markedmove') {
943: if (document.disall.movetofolder.options[document.disall.movetofolder.selectedIndex].value == "") {
944: alert("$lt{'sede'}");
945: return;
1.1 albertel 946: }
947: }
1.53 raeburn 948: return;
1.1 albertel 949: }
1.53 raeburn 950:
951: function validate_checkedaction() {
952: document.disall.markedaction.value = document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value;
953: if (document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value == 'markedmove') {
954: if (document.disall.movetofolder.options[document.disall.movetofolder.selectedIndex].value == "") {
955: alert("$lt{'sede'}");
956: return;
957: }
958: }
959: var checktotal = 0;
960: for (var i=0; i<document.forms.disall.delmark.length; i++) {
961: if (document.forms.disall.delmark[i].checked) {
962: checktotal ++;
963: }
964: }
965: if (checktotal == 0) {
966: alert("$lt{'nome'}\\n$lt{'chec'}");
967: return;
968: }
969: document.disall.submit();
970: }
971:
1.1 albertel 972: </script>
973: ENDDISHEADER
1.54 albertel 974:
1.1 albertel 975: my $fsqs='&folder='.$folder;
1.53 raeburn 976: my @temp=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1 albertel 977: my $totalnumber=$#temp+1;
1.53 raeburn 978: if ($totalnumber < 1) {
979: if ($msgstatus eq '') {
980: $r->print('<h2>'.&mt('Empty Folder').'</h2>');
981: } elsif ($msgstatus eq 'replied') {
982: $r->print('<h2>'.&mt('You have not replied to any messages in this folder.').'</h2>');
983: } else {
1.55 albertel 984: $r->print('<h2>'.&mt('There are no '.lc($statushash{$msgstatus}).' messages in this folder.').'</h2>');
1.53 raeburn 985: }
1.1 albertel 986: return;
987: }
1.57 ! albertel 988: my $interdis = $env{'form.interdis'};
1.1 albertel 989: my $number=int($totalnumber/$interdis);
1.57 ! albertel 990: if ($totalnumber%$interdis == 0) {
! 991: $number--;
1.53 raeburn 992: }
993:
1.1 albertel 994: if (($startdis<0) || ($startdis>$number)) { $startdis=$number; }
995: my $firstdis=$interdis*$startdis;
996: if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; }
997: my $lastdis=$firstdis+$interdis-1;
998: if ($lastdis>$#temp) { $lastdis=$#temp; }
1.53 raeburn 999: $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber,$msgstatus));
1.1 albertel 1000: $r->print('<form method="post" name="disall" action="/adm/email">'.
1.53 raeburn 1001: '<table class="LC_mail_list"><tr><th colspan="1"> </th><th>');
1.1 albertel 1002: if ($env{'form.sortedby'} eq "revdate") {
1003: $r->print('<a href = "?sortedby=date'.$fsqs.'">'.&mt('Date').'</a></th>');
1004: } else {
1005: $r->print('<a href = "?sortedby=revdate'.$fsqs.'">'.&mt('Date').'</a></th>');
1006: }
1007: $r->print('<th>');
1008: if ($env{'form.sortedby'} eq "revuser") {
1009: $r->print('<a href = "?sortedby=user'.$fsqs.'">'.&mt('Username').'</a>');
1010: } else {
1011: $r->print('<a href = "?sortedby=revuser'.$fsqs.'">'.&mt('Username').'</a>');
1012: }
1013: $r->print('</th><th>');
1014: if ($env{'form.sortedby'} eq "revdomain") {
1015: $r->print('<a href = "?sortedby=domain'.$fsqs.'">'.&mt('Domain').'</a>');
1016: } else {
1017: $r->print('<a href = "?sortedby=revdomain'.$fsqs.'">'.&mt('Domain').'</a>');
1018: }
1019: $r->print('</th><th>');
1020: if ($env{'form.sortedby'} eq "revsubject") {
1021: $r->print('<a href = "?sortedby=subject'.$fsqs.'">'.&mt('Subject').'</a>');
1022: } else {
1023: $r->print('<a href = "?sortedby=revsubject'.$fsqs.'">'.&mt('Subject').'</a>');
1024: }
1025: $r->print('</th><th>');
1026: if ($env{'form.sortedby'} eq "revcourse") {
1.46 raeburn 1027: $r->print('<a href = "?sortedby=course'.$fsqs.'">'.&mt('Course').'</a>');
1.1 albertel 1028: } else {
1.46 raeburn 1029: $r->print('<a href = "?sortedby=revcourse'.$fsqs.'">'.&mt('Course').'</a>');
1.1 albertel 1030: }
1031: $r->print('</th><th>');
1032: if ($env{'form.sortedby'} eq "revstatus") {
1033: $r->print('<a href = "?sortedby=status'.$fsqs.'">'.&mt('Status').'</a></th>');
1034: } else {
1035: $r->print('<a href = "?sortedby=revstatus'.$fsqs.'">'.&mt('Status').'</a></th>');
1036: }
1037: $r->print("</tr>\n");
1.6 albertel 1038:
1039: my $suffix = &Apache::lonmsg::foldersuffix($folder);
1.1 albertel 1040: for (my $n=$firstdis;$n<=$lastdis;$n++) {
1.11 albertel 1041: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,
1042: $description,$recv_name,$recv_domain)=
1043: @{$temp[$n]};
1.1 albertel 1044: if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
1045: if ($status eq 'new') {
1.4 albertel 1046: $r->print('<tr class="LC_mail_new">');
1.1 albertel 1047: } elsif ($status eq 'read') {
1.4 albertel 1048: $r->print('<tr class="LC_mail_read">');
1.1 albertel 1049: } elsif ($status eq 'replied') {
1.4 albertel 1050: $r->print('<tr class="LC_mail_replied">');
1.1 albertel 1051: } else {
1.4 albertel 1052: $r->print('<tr class="LC_mail_other">');
1.1 albertel 1053: }
1.6 albertel 1054: my ($dis_name,$dis_domain) = ($fromname,$fromdomain);
1055: if ($folder eq 'sent') {
1.11 albertel 1056: if (defined($recv_name) && !defined($recv_domain)) {
1057: $dis_name = join('<br />',@{$recv_name});
1058: $dis_domain = join('<br />',@{$recv_domain});
1059: } else {
1.29 www 1060: my $msg_id = &unescape($origID);
1.11 albertel 1061: my %message = &Apache::lonnet::get('nohist_email'.$suffix,
1062: [$msg_id]);
1063: my %content = &Apache::lonmsg::unpackagemsg($message{$msg_id});
1064: $dis_name = join('<br />',@{$content{'recuser'}});
1065: $dis_domain = join('<br />',@{$content{'recdomain'}});
1066: }
1.6 albertel 1067: }
1.53 raeburn 1068: my $localsenttime = &Apache::lonlocal::locallocaltime($sendtime);
1069: my $count = $n +1;
1070: $r->print('<td align="right"><nobr>'.(($status eq 'new')?'<b>':'').
1071: $count.'.'.(($status eq 'new')?'</b>':'').' '.
1072: '<input type="checkbox" name="delmark"'.
1073: ' value="'.$origID.'" /></nobr></td>');
1074: foreach my $item ($localsenttime,$dis_name,$dis_domain,$shortsubj) {
1075: $r->print('<td>'.(($status eq 'new')?'<b>':'').
1076: '<a href="/adm/email?display='.$origID.$sqs.'">'.
1077: $item.(($status eq 'new')?'</b>':'').'</td>');
1078: }
1079: my $showstatus;
1080: my %statushash = &get_msgstatus_types();
1081: if ($status eq '') {
1082: $showstatus = '';
1083: } else {
1084: $showstatus = $statushash{$status};
1085: }
1086: $r->print('<td>'.(($status eq 'new')?'<b>':'').$description.
1087: (($status eq 'new')?'</b>':'').'</td><td>'.
1088: (($status eq 'new')?'<b>':'').$showstatus.
1089: (($status eq 'new')?'</b>':'').'</td></tr>'."\n");
1.1 albertel 1090: } elsif ($status eq 'deleted') {
1091: # purge
1.9 albertel 1092: my ($result,$msg) =
1.29 www 1093: &movemsg(&unescape($origID),$folder,'trash');
1.9 albertel 1094:
1.1 albertel 1095: }
1096: }
1.53 raeburn 1097: $r->print("</table>\n");
1098: $r->print('<table border="0" cellspacing="2" cellpadding="2">
1099: <tr>
1100: <td>'.
1101: '<input type="button" onclick="javascript:checkall()" value="'.&mt('Check All').'" /><br />'."\n".
1102: '<input type="button" onclick="javascript:uncheckall()" value="'.&mt('Uncheck All').'" />'."\n".
1103: '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" /></td><td> </td>'."\n".
1104: '<td align="center"><b>'.&mt('Action').'</b><br />'."\n".
1105: ' <select name="checkedaction" onchange="javascript:checkfoldermove()">'."\n");
1106:
1.1 albertel 1107: if ($folder ne 'trash') {
1.53 raeburn 1108: $r->print(' <option value="markeddel">'.&mt('Delete').'</option>'."\n");
1109: }
1110: if ($msgstatus ne 'read') {
1111: $r->print(' <option value="markedread">'.&mt('Mark Read').'</option>."\n"');
1112: }
1113: if ($msgstatus ne 'unread') {
1114: $r->print(' <option value="markedunread">'.&mt('Mark Unread').'</option>'."\n");
1.1 albertel 1115: }
1.53 raeburn 1116: $r->print(' <option value="markedforward">'.&mt('Forward').'</option>'."\n");
1.54 albertel 1117:
1118: my %gotfolders = &Apache::lonmsg::get_user_folders();
1.53 raeburn 1119: if (keys(%gotfolders) > 0) {
1120: $r->print(' <option value="markedmove">'.&mt('Move to Folder ->').
1121: '</option>');
1122: }
1123: $r->print("\n".'</select></td>'."\n");
1.54 albertel 1124:
1.53 raeburn 1125: if (keys(%gotfolders) > 0) {
1126: $r->print('<td align="center"><b>'.&mt('Destination folder').'<b><br />');
1.54 albertel 1127: my %userfolders;
1.53 raeburn 1128: foreach my $key (keys(%gotfolders)) {
1129: $userfolders{$key} = $key;
1130: }
1131: $userfolders{''} = "";
1132: $r->print(&Apache::loncommon::select_form('','movetofolder',%userfolders).
1133: '</td>');
1134: }
1135: $r->print('<td> </td><td> '.
1136: '<input type="button" name="go" value="'.&mt('Go').
1137: '" onclick="javascript:validate_checkedaction()"/></td>'."\n".
1138: '</tr></table>');
1.1 albertel 1139: my $postedstartdis=$startdis+1;
1.53 raeburn 1140: $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 1141: if ($numblocked > 0) {
1142: my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
1143: my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
1144: $r->print('<br /><br />'.
1.51 raeburn 1145: &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 1146: $r->print(&Apache::loncommon::build_block_table($startblock,$endblock,
1147: \%setters));
1.1 albertel 1148: }
1149: }
1150:
1151: # ============================================================== Compose output
1152:
1153: sub compout {
1.53 raeburn 1154: my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode,
1155: $multiforward)=@_;
1.1 albertel 1156: my $suffix=&Apache::lonmsg::foldersuffix($folder);
1.38 raeburn 1157: my ($cdom,$cnum,$group,$refarg);
1158: if (exists($env{'form.group'})) {
1159: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1160: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1161: $group = $env{'form.group'};
1162: my $action = 'composing';
1163: $r->print(&groupmail_header($action,$group,$cdom,$cnum));
1164: } elsif ($broadcast eq 'individual') {
1.1 albertel 1165: &printheader($r,'/adm/email?compose=individual',
1166: 'Send a Message');
1167: } elsif ($broadcast) {
1168: &printheader($r,'/adm/email?compose=group',
1169: 'Broadcast Message');
1170: } elsif ($forwarding) {
1171: &Apache::lonhtmlcommon::add_breadcrumb
1.29 www 1172: ({href=>"/adm/email?display=".&escape($forwarding),
1.1 albertel 1173: text=>"Display Message"});
1.29 www 1174: &printheader($r,'/adm/email?forward='.&escape($forwarding),
1.1 albertel 1175: 'Forwarding a Message');
1176: } elsif ($replying) {
1177: &Apache::lonhtmlcommon::add_breadcrumb
1.29 www 1178: ({href=>"/adm/email?display=".&escape($replying),
1.1 albertel 1179: text=>"Display Message"});
1.29 www 1180: &printheader($r,'/adm/email?replyto='.&escape($replying),
1.1 albertel 1181: 'Replying to a Message');
1182: } elsif ($replycrit) {
1183: $r->print('<h3>'.&mt('Replying to a Critical Message').'</h3>');
1184: $replying=$replycrit;
1.53 raeburn 1185: } elsif ($multiforward) {
1186: &Apache::lonhtmlcommon::add_breadcrumb
1187: ({href=>"/adm/email?folder=".&escape($folder),
1188: text=>"Display All Messages"});
1189: &printheader($r,'/adm/email?compose=multiforward',
1190: 'Forwarding Multiple Messages');
1191: $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 1192: } else {
1193: &printheader($r,'/adm/email?compose=upload',
1194: 'Distribute from Uploaded File');
1195: }
1196:
1197: my $dispcrit='';
1198: my $dissub='';
1199: my $dismsg='';
1200: my $disbase='';
1201: my $func=&mt('Send New');
1.50 raeburn 1202: my %lt=&Apache::lonlocal::texthash('us' => 'Username',
1203: 'do' => 'Domain',
1204: 'ad' => 'Additional Recipients',
1205: 'sb' => 'Subject',
1206: 'ca' => 'Cancel',
1207: 'ma' => 'Mail',
1.53 raeburn 1208: 'msg' => 'Messages',
1.50 raeburn 1209: 'gen' => 'Generate messages from a file',
1210: 'gmt' => 'General message text',
1211: 'tff' => 'The file format for the uploaded portion of the message is',
1212: 'uas' => 'Upload and Send',
1213: );
1.1 albertel 1214: if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
1215: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
1216: '/'.$env{'request.course.sec'})) {
1217: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1218: $dispcrit=
1219: '<p><label><input type="checkbox" name="critmsg" /> '.&mt('Send as critical message').'</label> ' . $crithelp .
1220: '</p><p>'.
1221: '<label><input type="checkbox" name="sendbck" /> '.&mt('Send as critical message').' ' .
1222: &mt('and return receipt') . '</label>' . $crithelp .
1223: '</p><p><label><input type="checkbox" name="permanent" /> '.
1224: &mt('Send copy to permanent email address (if known)').'</label></p>'.
1225: '<p><label><input type="checkbox" name="rsspost" /> '.
1226: &mt('Include in course RSS newsfeed').'</label></p>';
1227: }
1228: my %message;
1229: my %content;
1230: my $defdom=$env{'user.domain'};
1231: if ($forwarding) {
1232: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]);
1233: %content=&Apache::lonmsg::unpackagemsg($message{$forwarding},$folder);
1234: $dispcrit.='<input type="hidden" name="forwid" value="'.
1235: $forwarding.'" />';
1236: $func=&mt('Forward');
1237:
1238: $dissub=&mt('Forwarding').': '.$content{'subject'};
1239: $dismsg=&mt('Forwarded message from').' '.
1240: $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
1241: if ($content{'baseurl'}) {
1.29 www 1242: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1 albertel 1243: }
1244: }
1245: if ($replying) {
1246: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
1247: %content=&Apache::lonmsg::unpackagemsg($message{$replying},$folder);
1248: $dispcrit.='<input type="hidden" name="replyid" value="'.
1249: $replying.'" />';
1250: $func=&mt('Send Reply to');
1251:
1252: $dissub=&mt('Reply').': '.$content{'subject'};
1253: $dismsg='> '.$content{'message'};
1254: $dismsg=~s/\r/\n/g;
1255: $dismsg=~s/\f/\n/g;
1256: $dismsg=~s/\n+/\n\> /g;
1257: if ($content{'baseurl'}) {
1.29 www 1258: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1 albertel 1259: if ($env{'user.adv'}) {
1260: $disbase.='<label><input type="checkbox" name="storebasecomment" />'.&mt('Store message for re-use').
1261: '</label> <a href="/adm/email?showcommentbaseurl='.
1.29 www 1262: &escape($content{'baseurl'}).'" target="comments">'.
1.1 albertel 1263: &mt('Show re-usable messages').'</a><br />';
1264: }
1265: }
1266: }
1267: my $citation=&displayresource(%content);
1.38 raeburn 1268: my ($can_grp_broadcast,$viewgrps,$editgrps);
1.1 albertel 1269: if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
1.23 www 1270: if ($env{'form.text'}) { $dismsg=$env{'form.text'}; }
1271: if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; }
1272: $r->print(
1.1 albertel 1273: '<form action="/adm/email" name="compemail" method="post"'.
1274: ' enctype="multipart/form-data">'."\n".
1.38 raeburn 1275: '<input type="hidden" name="sendmail" value="on" />'."\n");
1276: if ($broadcast eq 'group' && $env{'form.group'} ne '') {
1277: $can_grp_broadcast =
1278: &Apache::lonnet::allowed('sgb',$env{'request.course.id'}.'/'.
1279: $group);
1280: $viewgrps =
1281: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
1282: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1283: $editgrps =
1284: &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
1285: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1286: if ($viewgrps || $editgrps || $can_grp_broadcast) {
1287: $r->print(&disgroup($cdom,$cnum,$group,$viewgrps,$editgrps));
1288: }
1289: }
1290: $r->print('<table>');
1291: if (($broadcast eq 'group') && ($group ne '') &&
1292: (!$can_grp_broadcast && !$viewgrps && !$editgrps)) {
1293: $r->print(&recipient_input_row($cdom,%lt));
1294: }
1295: if (($broadcast ne 'group') && ($broadcast ne 'upload')) {
1.1 albertel 1296: if ($replying) {
1297: $r->print('<tr><td colspan="2">'.&mt('Replying to').' '.
1298: &Apache::loncommon::aboutmewrapper(
1299: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
1.14 albertel 1300: $content{'sendername'}.':'.
1.1 albertel 1301: $content{'senderdomain'}.')'.
1302: '<input type="hidden" name="recuname" value="'.$content{'sendername'}.'" />'.
1303: '<input type="hidden" name="recdomain" value="'.$content{'senderdomain'}.'" />'.
1304: '</td></tr>');
1305: } else {
1.38 raeburn 1306: $r->print(&recipient_input_row($defdom,%lt));
1.1 albertel 1307: }
1308: }
1309: my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
1.53 raeburn 1310: my $subj_size;
1311: if ($multiforward) {
1312: $r->print(&additional_rec_row(\%lt));
1313: $r->print('<tr><td colspan="2">'.
1314: &mt('Unless you choose otherwise:').'<ul><li>'.
1315: &mt("The subject in each forwarded message will be <i>'Forwarding:'</i> followed by the original subject.").'</li><li>'.
1316: &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>');
1317: $func=&mt('Forward');
1318: $dissub = &mt('Forwarding').': ';
1319: $subj_size = '10';
1320: my $extra = '<'.&mt('original subject').'> '.
1321: '<input type="radio" name="showorigsubj" value="1" checked="checked" />'.&mt('Yes').' <input type="radio" name="showorigsubj" value="0" />'.&mt('No');
1322: $dismsg = &mt('Forwarded message from ').' ';
1323: my $sender = &mt("sender's name");
1324: $r->print(&msg_subject_row($dissub,\%lt,$subj_size,$extra));
1325: $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>
1326: </table>
1327: <br />'.
1328: $latexHelp.
1329: &mt("Any new text to display before the text of the original messages:").'<br />
1330: <textarea name="message" id="message" cols="80" rows="5" wrap="hard">
1331: </textarea></p><br />');
1332: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
1333: foreach my $msg (@to_forward) {
1334: $r->print('<input type="hidden" name="delmark" value="'.$msg.'" />');
1335: }
1336: $r->print(&submit_button_row($folder,$dismode,$func.' '.$lt{'msg'},
1337: \%lt));
1338: } elsif ($broadcast ne 'upload') {
1339: $subj_size = '50';
1340: $r->print(&additional_rec_row(\%lt));
1341: $r->print(&msg_subject_row($dissub,\%lt,$subj_size));
1342: $r->print(<<"ENDCOMP");
1343: </table>
1.1 albertel 1344: $latexHelp
1345: <textarea name="message" id="message" cols="80" rows="15" wrap="hard">$dismsg
1346: </textarea></p><br />
1347: $dispcrit
1348: $disbase
1349: ENDCOMP
1.53 raeburn 1350: $r->print(&submit_button_row($folder,$dismode,$func.' '.$lt{'ma'},
1351: \%lt));
1352: $r->print($citation);
1.38 raeburn 1353: if (exists($env{'form.ref'})) {
1354: $r->print('<input type="hidden" name="ref" value="'.
1355: $env{'form.ref'}.'" />');
1356: }
1357: if (exists($env{'form.group'})) {
1358: $r->print('<input type="hidden" name="group" value="'.
1359: $env{'form.group'}.'" />');
1360: }
1.1 albertel 1361: } else { # $broadcast is 'upload'
1.50 raeburn 1362: $r->print(<<ENDBLOCK);
1.1 albertel 1363: <input type="hidden" name="sendmode" value="upload" />
1364: <input type="hidden" name="send" value="on" />
1.50 raeburn 1365: <h3>$lt{'gen'}</h3>
1.1 albertel 1366: <p>
1367: Subject: <input type="text" size="50" name="subject" />
1368: </p>
1.50 raeburn 1369: <p>$lt{'gmt'}:<br />
1.1 albertel 1370: <textarea name="message" id="message" cols="60" rows="10" wrap="hard">$dismsg
1371: </textarea></p>
1372: <p>
1.50 raeburn 1373: $lt{'tff'}:
1374: ENDBLOCK
1375: $r->print('
1376: <pre>'."\n".
1377: &mt('username1:domain1: text')."\n".
1378: &mt('username2:domain2: text')."\n".
1379: &mt('username3:domain1: text')."\n".
1380: '</pre>
1.1 albertel 1381: </p>
1382: <p>
1.50 raeburn 1383: '.&mt('The messages will be assembled from all lines with the respective'."\n".'<tt>username:domain</tt>, and appended to the general message text.'));
1384: $r->print(<<ENDUPLOAD);
1385: </p>
1.1 albertel 1386: <p>
1387: <input type="file" name="upfile" size="40" /></p><p>
1388: $dispcrit
1.50 raeburn 1389: <input type="submit" value="$lt{'uas'}" /></p>
1.1 albertel 1390: ENDUPLOAD
1391: }
1392: if ($broadcast eq 'group') {
1.38 raeburn 1393: if ($group eq '') {
1394: my $studentsel = &discourse();
1395: $r->print($studentsel);
1396: }
1.1 albertel 1397: }
1.36 albertel 1398: if ($env{'form.displayedcrit'}) {
1399: $r->print('<input type="hidden" name="displayedcrit" value="true" />');
1400: }
1.1 albertel 1401: $r->print('</form>'.
1402: &Apache::lonfeedback::generate_preview_button('compemail','message').
1403: &Apache::lonhtmlcommon::htmlareaselectactive('message'));
1404: }
1405:
1406: # ---------------------------------------------------- Display all face to face
1407:
1.38 raeburn 1408: sub recipient_input_row {
1409: my ($dom,%lt) = @_;
1410: my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain');
1411: my $selectlink=
1412: &Apache::loncommon::selectstudent_link('compemail','recuname',
1413: 'recdomain');
1414: my $output = <<"ENDREC";
1415: <tr><td>$lt{'us'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recname'}" /></td><td rowspan="2">$selectlink</td></tr>
1416: <tr><td>$lt{'do'}:</td>
1417: <td>$domform</td></tr>
1418: ENDREC
1419: return $output;
1420: }
1421:
1.53 raeburn 1422: sub additional_rec_row {
1423: my ($lt) = @_;
1424: my $output = <<"ENDADD";
1425: <tr><td>$lt->{'ad'}:<br /><tt>username:domain,username:domain, ...
1426: </tt></td><td>
1427: <input type="text" size="50" name="additionalrec" /></td></tr>
1428: ENDADD
1429: return $output;
1430: }
1431:
1432: sub submit_button_row {
1433: my ($folder,$dismode,$sendtext,$lt) = @_;
1434: my $output = qq|
1435: <input type="hidden" name="folder" value="$folder" />
1436: <input type="hidden" name="dismode" value="$dismode" />
1437: <input type="submit" name="send" value="$sendtext" />
1438: <input type="submit" name="cancel" value="$lt->{'ca'}" /><hr />
1439: |;
1440: return $output;
1441: }
1442:
1443: sub msg_subject_row {
1444: my ($dissub,$lt,$subj_size,$extra) = @_;
1445: my $output = '<tr><td>'.$lt->{'sb'}.':</td><td><input type="text" size="'.
1446: $subj_size.'" name="subject" value="'.$dissub.'" />'.$extra.
1447: '</td></tr>';
1448: return $output;
1449: }
1450:
1.1 albertel 1451: sub retrieve_instructor_comments {
1452: my ($user,$domain)=@_;
1453: my $target=$env{'form.grade_target'};
1454: if (! $env{'request.course.id'}) { return; }
1.49 albertel 1455: if (! &Apache::lonnet::allowed('dff',$env{'request.course.id'})
1456: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1457: '/'.$env{'request.course.sec'})) {
1458: return;
1459: }
1460: my %records=&Apache::lonnet::dump('nohist_email',
1461: $env{'course.'.$env{'request.course.id'}.'.domain'},
1462: $env{'course.'.$env{'request.course.id'}.'.num'},
1463: '%255b'.$user.'%253a'.$domain.'%255d');
1464: my $result='';
1.42 raeburn 1465: foreach my $key (sort(keys(%records))) {
1466: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1 albertel 1467: next if ($content{'senderdomain'} eq '');
1468: next if ($content{'subject'} !~ /^Record/);
1469: # &Apache::lonfeedback::newline_to_br(\$content{'message'});
1470: $result.='Recorded by '.
1.14 albertel 1471: $content{'sendername'}.':'.$content{'senderdomain'}."\n";
1.1 albertel 1472: $result.=
1473: &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
1474: }
1475: return $result;
1476: }
1477:
1478: sub disfacetoface {
1479: my ($r,$user,$domain)=@_;
1480: my $target=$env{'form.grade_target'};
1481: unless ($env{'request.course.id'}) { return; }
1.49 albertel 1482: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
1483: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1484: '/'.$env{'request.course.sec'})) {
1.50 raeburn 1485: $r->print(&mt('Not allowed'));
1.1 albertel 1486: return;
1487: }
1488: my %records=&Apache::lonnet::dump('nohist_email',
1489: $env{'course.'.$env{'request.course.id'}.'.domain'},
1490: $env{'course.'.$env{'request.course.id'}.'.num'},
1491: '%255b'.$user.'%253a'.$domain.'%255d');
1492: my $result='';
1.42 raeburn 1493: foreach my $key (sort(keys(%records))) {
1494: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1 albertel 1495: next if ($content{'senderdomain'} eq '');
1496: &Apache::lonfeedback::newline_to_br(\$content{'message'});
1497: if ($content{'subject'}=~/^Record/) {
1498: $result.='<h3>'.&mt('Record').'</h3>';
1499: } elsif ($content{'subject'}=~/^Broadcast/) {
1500: $result .='<h3>'.&mt('Broadcast Message').'</h3>';
1501: if ($content{'subject'}=~/^Broadcast\./) {
1502: if (defined($content{'coursemsgid'})) {
1.29 www 1503: my $crsmsgid = &escape($content{'coursemsgid'});
1.1 albertel 1504: my $broadcast_message = &general_message($crsmsgid);
1505: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$broadcast_message;
1506: } else {
1507: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1508: $content{'message'} =
1509: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1510: $content{'message'};
1511: }
1512: }
1513: } else {
1514: $result.='<h3>'.&mt('Critical Message').'</h3>';
1515: if (defined($content{'coursemsgid'})) {
1.29 www 1516: my $crsmsgid=&escape($content{'coursemsgid'});
1.1 albertel 1517: my $critical_message = &general_message($crsmsgid);
1518: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$critical_message;
1519: } else {
1520: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1521: $content{'message'}=
1522: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1523: $content{'message'};
1524: }
1525: }
1526: $result.=&mt('By').': <b>'.
1527: &Apache::loncommon::aboutmewrapper(
1528: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14 albertel 1529: $content{'sendername'}.':'.
1.1 albertel 1530: $content{'senderdomain'}.') '.$content{'time'}.
1531: '<br /><pre>'.
1532: &Apache::lontexconvert::msgtexconverted($content{'message'}).
1533: '</pre>';
1534: }
1535: # Check to see if there were any messages.
1536: if ($result eq '') {
1.33 albertel 1537: my $lctype = lc(&Apache::loncommon::course_type());
1.1 albertel 1538: if ($target ne 'tex') {
1.30 raeburn 1539: $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 1540: } else {
1.30 raeburn 1541: $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this [_1].',$lctype).'}\\\\');
1.1 albertel 1542: }
1543: } else {
1544: $r->print($result);
1545: }
1546: }
1547:
1548: sub general_message {
1549: my ($crsmsgid) = @_;
1550: my %general_content;
1551: if ($crsmsgid) {
1552: my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid],
1553: $env{'course.'.$env{'request.course.id'}.'.domain'},
1554: $env{'course.'.$env{'request.course.id'}.'.num'});
1555: %general_content = &Apache::lonmsg::unpackagemsg($course_content{$crsmsgid});
1556: }
1557: return $general_content{'message'};
1558: }
1559:
1560: # ---------------------------------------------------------------- Face to face
1561:
1562: sub facetoface {
1563: my ($r,$stage)=@_;
1.49 albertel 1564: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
1565: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1566: '/'.$env{'request.course.sec'})) {
1.50 raeburn 1567: $r->print(&mt('Not allowed'));
1.1 albertel 1568: return;
1569: }
1.33 albertel 1570: my $crstype = &Apache::loncommon::course_type();
1571: my $leaders = ($crstype eq 'Group') ? 'coordinators and leaders'
1572: : 'faculty and staff';
1.1 albertel 1573: &printheader($r,
1574: '/adm/email?recordftf=query',
1575: "User Notes, Face-to-Face, Critical Messages, Broadcast Messages");
1576: # from query string
1577:
1578: if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
1579: if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
1580:
1581: my $defdom=$env{'user.domain'};
1582: # already filled in
1583: if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
1584: # generate output
1585: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
1586: my $stdbrws = &Apache::loncommon::selectstudent_link
1587: ('stdselect','recuname','recdomain');
1588: my %lt=&Apache::lonlocal::texthash('user' => 'Username',
1589: 'dom' => 'Domain',
1.30 raeburn 1590: 'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, and Broadcast Messages in $crstype",
1.1 albertel 1591: 'subm' => 'Retrieve discussion and message records',
1.30 raeburn 1592: 'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')',
1.1 albertel 1593: 'post' => 'Post this Record');
1594: $r->print(<<"ENDTREC");
1595: <h3>$lt{'head'}</h3>
1596: <form method="post" action="/adm/email" name="stdselect">
1597: <input type="hidden" name="recordftf" value="retrieve" />
1598: <table>
1599: <tr><td>$lt{'user'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recuname'}" /></td>
1600: <td rowspan="2">
1601: $stdbrws
1602: <input type="submit" value="$lt{'subm'}" /></td>
1603: </tr>
1604: <tr><td>$lt{'dom'}:</td>
1605: <td>$domform</td></tr>
1606: </table>
1607: </form>
1608: ENDTREC
1609: if (($stage ne 'query') &&
1610: ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
1611: chomp($env{'form.newrecord'});
1612: if ($env{'form.newrecord'}) {
1.31 albertel 1613: &Apache::lonmsg::store_instructor_comment($env{'form.newrecord'},
1614: $env{'form.recuname'},
1615: $env{'form.recdomain'});
1.1 albertel 1616: }
1617: $r->print('<h3>'.&Apache::loncommon::plainname($env{'form.recuname'},
1618: $env{'form.recdomain'}).'</h3>');
1619: &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
1620: $r->print(<<ENDRHEAD);
1621: <form method="post" action="/adm/email">
1622: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
1623: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
1624: ENDRHEAD
1625: $r->print(<<ENDBFORM);
1626: <hr />$lt{'newr'}<br />
1627: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
1628: <br />
1629: <input type="hidden" name="recordftf" value="post" />
1630: <input type="submit" value="$lt{'post'}" />
1631: </form>
1632: ENDBFORM
1633: }
1634: }
1635:
1636: # ----------------------------------------------------------- Blocking during exams
1637:
1638: sub examblock {
1639: my ($r,$action) = @_;
1640: unless ($env{'request.course.id'}) { return;}
1.44 raeburn 1641: if (!&Apache::lonnet::allowed('dcm',$env{'request.course.id'})
1642: && ! &Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
1.1 albertel 1643: '/'.$env{'request.course.sec'})) {
1644: $r->print('Not allowed');
1645: return;
1646: }
1.34 albertel 1647: my $usertype = (&Apache::loncommon::course_type() eq 'Group') ? 'members'
1.33 albertel 1648: : 'students';
1.1 albertel 1649: my %lt=&Apache::lonlocal::texthash(
1650: 'comb' => 'Communication Blocking',
1651: 'cbds' => 'Communication blocking during scheduled exams',
1.30 raeburn 1652: '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 1653: 'mecb' => 'Modify existing communication blocking periods',
1.50 raeburn 1654: 'ncbc' => 'No communication blocks currently stored',
1655: 'stor' => 'Store',
1.1 albertel 1656: );
1657:
1658: my %ltext = &Apache::lonlocal::texthash(
1659: 'dura' => 'Duration',
1660: 'setb' => 'Set by',
1661: 'even' => 'Event',
1.44 raeburn 1662: 'blck' => 'Blocked?',
1.1 albertel 1663: 'actn' => 'Action',
1664: 'star' => 'Start',
1665: 'endd' => 'End'
1666: );
1667:
1668: &printheader($r,'/adm/email?block=display',$lt{'comb'});
1669: $r->print('<h3>'.$lt{'cbds'}.'</h3>');
1670:
1671: if ($action eq 'store') {
1672: &blockstore($r);
1673: }
1674:
1675: $r->print($lt{'desc'}.'<br /><br />
1676: <form name="blockform" method="post" action="/adm/email?block=store">
1677: ');
1678:
1679: $r->print('<h4>'.$lt{'mecb'}.'</h4>');
1680: my %records = ();
1681: my $blockcount = 0;
1682: my $parmcount = 0;
1683: &get_blockdates(\%records,\$blockcount);
1684: if ($blockcount > 0) {
1685: $parmcount = &display_blocker_status($r,\%records,\%ltext);
1686: } else {
1687: $r->print($lt{'ncbc'}.'<br /><br />');
1688: }
1689: &display_addblocker_table($r,$parmcount,\%ltext);
1690: my $end_page=&Apache::loncommon::end_page();
1691: $r->print(<<"END");
1692: <br />
1693: <input type="hidden" name="blocktotal" value="$blockcount" />
1.50 raeburn 1694: <input type ="submit" value="$lt{'stor'}" />
1.1 albertel 1695: </form>
1696: $end_page
1697: END
1698: return;
1699: }
1700:
1701: sub blockstore {
1702: my $r = shift;
1703: my %lt=&Apache::lonlocal::texthash(
1704: 'tfcm' => 'The following changes were made',
1705: 'ncwm' => 'No changes were made.'
1706: );
1707: my %adds = ();
1708: my %removals = ();
1709: my %cancels = ();
1710: my $modtotal = 0;
1711: my $canceltotal = 0;
1712: my $addtotal = 0;
1713: my %blocking = ();
1714: $r->print('<h3>'.$lt{'head'}.'</h3>');
1.42 raeburn 1715: foreach my $envkey (keys(%env)) {
1.44 raeburn 1716: if ($envkey =~ m/^form\.modify_(\d+)$/) {
1.1 albertel 1717: $adds{$1} = $1;
1718: $removals{$1} = $1;
1719: $modtotal ++;
1.42 raeburn 1720: } elsif ($envkey =~ m/^form\.cancel_(\d+)$/) {
1.1 albertel 1721: $cancels{$1} = $1;
1722: unless ( defined($removals{$1}) ) {
1723: $removals{$1} = $1;
1724: $canceltotal ++;
1725: }
1.42 raeburn 1726: } elsif ($envkey =~ m/^form\.add_(\d+)$/) {
1.1 albertel 1727: $adds{$1} = $1;
1728: $addtotal ++;
1.44 raeburn 1729: }
1.1 albertel 1730: }
1731:
1.42 raeburn 1732: foreach my $key (keys(%removals)) {
1733: my $hashkey = $env{'form.key_'.$key};
1.1 albertel 1734: &Apache::lonnet::del('comm_block',["$hashkey"],
1735: $env{'course.'.$env{'request.course.id'}.'.domain'},
1736: $env{'course.'.$env{'request.course.id'}.'.num'}
1737: );
1738: }
1.42 raeburn 1739: foreach my $key (keys(%adds)) {
1740: unless ( defined($cancels{$key}) ) {
1741: my ($newstart,$newend) = &get_dates_from_form($key);
1.1 albertel 1742: my $newkey = $newstart.'____'.$newend;
1.44 raeburn 1743: my $blocktypes = &get_block_choices($key);
1744: $blocking{$newkey} = {
1745: setter => $env{'user.name'}.':'.$env{'user.domain'},
1746: event => &escape($env{'form.title_'.$key}),
1747: blocks => $blocktypes,
1748: };
1.1 albertel 1749: }
1750: }
1751: if ($addtotal + $modtotal > 0) {
1752: &Apache::lonnet::put('comm_block',\%blocking,
1753: $env{'course.'.$env{'request.course.id'}.'.domain'},
1754: $env{'course.'.$env{'request.course.id'}.'.num'}
1755: );
1756: }
1757: my $chgestotal = $canceltotal + $modtotal + $addtotal;
1758: if ($chgestotal > 0) {
1759: $r->print($lt{'tfcm'}.'<ul>');
1760: if ($canceltotal > 0) {
1.50 raeburn 1761: $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] removed.',$canceltotal).'</li>');
1.1 albertel 1762: }
1763: if ($modtotal > 0) {
1.50 raeburn 1764: $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] modified.',$modtotal).'</li>');
1.1 albertel 1765: }
1766: if ($addtotal > 0) {
1.50 raeburn 1767: $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] added.',$addtotal).'</li>');
1.1 albertel 1768: }
1769: $r->print('</ul>');
1770: } else {
1771: $r->print($lt{'ncwm'});
1772: }
1773: $r->print('<br />');
1774: return;
1775: }
1776:
1777: sub get_dates_from_form {
1778: my $item = shift;
1779: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
1780: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
1781: return ($startdate,$enddate);
1782: }
1783:
1784: sub get_blockdates {
1785: my ($records,$blockcount) = @_;
1786: $$blockcount = 0;
1787: %{$records} = &Apache::lonnet::dump('comm_block',
1788: $env{'course.'.$env{'request.course.id'}.'.domain'},
1789: $env{'course.'.$env{'request.course.id'}.'.num'}
1790: );
1.15 albertel 1791: $$blockcount = keys(%{$records});
1792:
1793: if ((keys(%{$records}))[0] =~ /^error: 2 /) {
1794: $records = {};
1795: $$blockcount = 0;
1.1 albertel 1796: }
1797: }
1798:
1.44 raeburn 1799: sub get_block_choices {
1800: my $item = shift;
1801: my $blocklist;
1802: my ($typeorder,$types) = &blocktype_text();
1803: foreach my $type (@{$typeorder}) {
1804: if ($env{'form.'.$type.'_'.$item}) {
1805: $blocklist->{$type} = 'on';
1806: } else {
1807: $blocklist->{$type} = 'off';
1808: }
1809: }
1810: return $blocklist;
1811: }
1812:
1.1 albertel 1813: sub display_blocker_status {
1814: my ($r,$records,$ltext) = @_;
1815: my $parmcount = 0;
1.16 albertel 1816:
1.1 albertel 1817: my %lt = &Apache::lonlocal::texthash(
1818: 'modi' => 'Modify',
1819: 'canc' => 'Cancel',
1820: );
1.44 raeburn 1821: my ($typeorder,$types) = &blocktype_text();
1.18 albertel 1822: $r->print(&Apache::loncommon::start_data_table());
1.1 albertel 1823: $r->print(<<"END");
1.16 albertel 1824: <tr>
1.44 raeburn 1825: <th>$ltext->{'dura'}</th>
1826: <th>$ltext->{'setb'}</th>
1827: <th>$ltext->{'even'}</th>
1828: <th>$ltext->{'blck'}</th>
1829: <th>$ltext->{'actn'}?</th>
1.16 albertel 1830: </tr>
1.1 albertel 1831: END
1.18 albertel 1832: foreach my $record (sort(keys(%{$records}))) {
1.1 albertel 1833: my $onchange = 'onFocus="javascript:window.document.forms['.
1834: "'blockform'].elements['modify_".$parmcount."'].".
1835: 'checked=true;"';
1.18 albertel 1836: my ($start,$end) = split(/____/,$record);
1.1 albertel 1837: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
1838: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1.15 albertel 1839:
1.44 raeburn 1840: my ($setuname,$setudom,$title,$blocks) =
1841: &Apache::loncommon::parse_block_record($$records{$record});
1.21 albertel 1842: $title = &HTML::Entities::encode($title,'"<>&');
1.44 raeburn 1843: my $settername =
1844: &Apache::loncommon::aboutmewrapper(
1845: &Apache::loncommon::plainname($setuname,$setudom),
1846: $setuname,$setudom);
1.18 albertel 1847: $r->print(&Apache::loncommon::start_data_table_row());
1.1 albertel 1848: $r->print(<<"END");
1.44 raeburn 1849: <td>$ltext->{'star'}: $startform<br/>$ltext->{'endd'}: $endform</td>
1.1 albertel 1850: <td>$settername</td>
1.18 albertel 1851: <td><input type="text" name="title_$parmcount" size="15" value="$title" /><input type="hidden" name="key_$parmcount" value="$record" /></td>
1.44 raeburn 1852: <td>
1853: END
1854: foreach my $block (@{$typeorder}) {
1855: my $blockstatus = '';
1856: if ($blocks->{$block} eq 'on') {
1857: $blockstatus = 'checked="true"';
1858: }
1859: $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" '.$blockstatus.' value="1" />'.$types->{$block}.'</label><br />');
1860: }
1861: $r->print(<<"END");
1862: </td>
1.1 albertel 1863: <td><label>$lt{'modi'}? <input type="checkbox" name="modify_$parmcount" /></label><br /><label>$lt{'canc'}? <input type="checkbox" name="cancel_$parmcount" /></label>
1864: END
1.18 albertel 1865: $r->print(&Apache::loncommon::end_data_table_row());
1866: $parmcount++;
1.1 albertel 1867: }
1868: $r->print(<<"END");
1869: </table>
1870: <br />
1871: <br />
1872: END
1873: return $parmcount;
1874: }
1875:
1876: sub display_addblocker_table {
1877: my ($r,$parmcount,$ltext) = @_;
1878: my $start = time;
1879: my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
1880: my $onchange = 'onFocus="javascript:window.document.forms['.
1881: "'blockform'].elements['add_".$parmcount."'].".
1882: 'checked=true;"';
1883: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
1884: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1885: my %lt = &Apache::lonlocal::texthash(
1886: 'addb' => 'Add block',
1887: 'exam' => 'e.g., Exam 1',
1888: 'addn' => 'Add new communication blocking periods'
1889: );
1.44 raeburn 1890: my ($typeorder,$types) = &blocktype_text();
1.1 albertel 1891: $r->print(<<"END");
1892: <h4>$lt{'addn'}</h4>
1.18 albertel 1893: END
1894: $r->print(&Apache::loncommon::start_data_table());
1895: $r->print(<<"END");
1.16 albertel 1896: <tr>
1.44 raeburn 1897: <th>$ltext->{'dura'}</th>
1898: <th>$ltext->{'even'} $lt{'exam'}</th>
1899: <th>$ltext->{'blck'}</th>
1900: <th>$ltext->{'actn'}?</th>
1.16 albertel 1901: </tr>
1.18 albertel 1902: END
1.44 raeburn 1903: $r->print(&Apache::loncommon::start_data_table_row());
1.18 albertel 1904: $r->print(<<"END");
1.44 raeburn 1905: <td>$ltext->{'star'}: $startform<br />$ltext->{'endd'}: $endform</td>
1.16 albertel 1906: <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
1.44 raeburn 1907: <td>
1908: END
1909: foreach my $block (@{$typeorder}) {
1910: $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" value="1" />'.$types->{$block}.'</label><br />');
1911: }
1912: $r->print(<<"END");
1913: </td>
1.16 albertel 1914: <td><label>$lt{'addb'}? <input type="checkbox" name="add_$parmcount" value="1" /></label></td>
1.1 albertel 1915: END
1.18 albertel 1916: $r->print(&Apache::loncommon::end_data_table_row());
1917: $r->print(&Apache::loncommon::end_data_table());
1.1 albertel 1918: return;
1919: }
1920:
1.44 raeburn 1921: sub blocktype_text {
1922: my %types = &Apache::lonlocal::texthash(
1923: 'com' => 'Messaging',
1924: 'chat' => 'Chat',
1925: 'boards' => 'Discussion',
1926: 'port' => 'Portfolio',
1.45 raeburn 1927: 'groups' => 'Groups',
1928: 'blogs' => 'Blogs',
1.18 albertel 1929: );
1.45 raeburn 1930: my $typeorder = ['com','chat','boards','port','groups','blogs'];
1.44 raeburn 1931: return ($typeorder,\%types);
1.1 albertel 1932: }
1933:
1934: # ----------------------------------------------------------- Display a message
1935:
1936: sub displaymessage {
1.53 raeburn 1937: my ($r,$msgid,$folder,$msgstatus)=@_;
1.1 albertel 1938: my $suffix=&Apache::lonmsg::foldersuffix($folder);
1939: my %blocked = ();
1940: my %setters = ();
1941: my $numblocked = 0;
1.33 albertel 1942: my $crstype = &Apache::loncommon::course_type();
1.30 raeburn 1943:
1.1 albertel 1944: # info to generate "next" and "previous" buttons and check if message is blocked
1.44 raeburn 1945: my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53 raeburn 1946: my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1 albertel 1947: if ( $blocked{$msgid} eq 'ON' ) {
1948: &printheader($r,'/adm/email',&mt('Display a Message'));
1949: $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.'));
1950: &build_block_table($r,$startblock,$endblock,\%setters);
1951: return;
1952: }
1953: &statuschange($msgid,'read',$folder);
1954: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1955: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid});
1956:
1957: my $counter=0;
1958: $r->print('<pre>');
1.29 www 1959: my $escmsgid=&escape($msgid);
1.1 albertel 1960: foreach (@messages) {
1961: if ($_->[5] eq $escmsgid){
1962: last;
1963: }
1964: $counter++;
1965: }
1966: $r->print('</pre>');
1967: my $number_of_messages = scalar(@messages); #subtract 1 for last index
1968: # start output
1.29 www 1969: &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'});
1.1 albertel 1970: my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'});
1971: # Functions
1972: $r->print('<table border="2" width="100%"><tr bgcolor="#FFFFAA"><td>'.&mt('Functions').':</td>'.
1.29 www 1973: '<td><a href="/adm/email?replyto='.&escape($msgid).$sqs.
1.1 albertel 1974: '"><b>'.&mt('Reply').'</b></a></td>'.
1.29 www 1975: '<td><a href="/adm/email?forward='.&escape($msgid).$sqs.
1.1 albertel 1976: '"><b>'.&mt('Forward').'</b></a></td>'.
1.29 www 1977: '<td><a href="/adm/email?markunread='.&escape($msgid).$sqs.
1.1 albertel 1978: '"><b>'.&mt('Mark Unread').'</b></a></td>'.
1.29 www 1979: '<td><a href="/adm/email?markdel='.&escape($msgid).$sqs.
1.1 albertel 1980: '"><b>'.&mt('Delete').'</b></a></td>'.
1981: '<td><a href="/adm/email?'.$sqs.
1982: '"><b>'.&mt('Back to Folder Display').'</b></a></td>');
1983: if ($counter > 0){
1984: $r->print('<td><a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.
1985: '"><b>'.&mt('Previous').'</b></a></td>');
1986: }
1987: if ($counter < $number_of_messages - 1){
1988: $r->print('<td><a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.
1989: '"><b>'.&mt('Next').'</b></a></td>');
1990: }
1991: $r->print('</tr></table>');
1992: if ($env{'user.adv'}) {
1993: $r->print('<table border="2" width="100%"><tr bgcolor="#FFAAAA"><td>'.&mt('Currently available actions (will open extra window)').':</td>');
1994: my $symb=&Apache::lonnet::symbread($content{'baseurl'});
1995: if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
1996: $r->print('<td><b>'.&Apache::loncommon::track_student_link(&mt('View recent activity'),$content{'sendername'},$content{'senderdomain'},'check').'</b></td>');
1997: }
1998: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
1999: $r->print('<td><b>'.&Apache::loncommon::pprmlink(&mt('Set/Change parameters'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
2000: }
2001: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
2002: $r->print('<td><b>'.&Apache::loncommon::pgrdlink(&mt('Set/Change grades'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
2003: }
2004: $r->print('</tr></table>');
2005: }
2006: my $tolist;
2007: my @recipients = ();
2008: for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
2009: $recipients[$i] = &Apache::loncommon::aboutmewrapper(
2010: &Apache::loncommon::plainname($content{'recuser'}[$i],
2011: $content{'recdomain'}[$i]),
2012: $content{'recuser'}[$i],$content{'recdomain'}[$i]).
2013: ' ('.$content{'recuser'}[$i].' at '.$content{'recdomain'}[$i].') ';
2014: }
2015: $tolist = join(', ',@recipients);
2016: $r->print('<br /><b>'.&mt('Subject').':</b> '.$content{'subject'}.
2017: ($folder ne 'sent'?'<br /><b>'.&mt('From').':</b> '.
2018: &Apache::loncommon::aboutmewrapper(
2019: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
2020: $content{'sendername'},$content{'senderdomain'}).' ('.
2021: $content{'sendername'}.' at '.
2022: $content{'senderdomain'}.') ':'<br /><b>'.&mt('To').':</b> '.
2023: $tolist).
1.30 raeburn 2024: ($content{'courseid'}?'<br /><b>'.&mt($crstype).':</b> '.$courseinfo{'description'}.
2025: ($content{'coursesec'}?' ('.&mt('Section').': '.$content{'coursesec'}.')':''):'').
1.1 albertel 2026: '<br /><b>'.&mt('Time').':</b> '.$content{'time'}.
2027: ($content{'baseurl'}?'<br /><b>'.&mt('Refers to').':</b> <a href="'.$content{'baseurl'}.'">'.
2028: $content{'baseurl'}.' ('.&Apache::lonnet::gettitle($content{'baseurl'}).')</a>':'').
2029: '<p><pre>'.
2030: &Apache::lontexconvert::msgtexconverted($content{'message'},1).
2031: '</pre><hr />'.&displayresource(%content).'</p>');
2032: return;
2033: }
2034:
2035: # =========================================================== Show the citation
2036:
2037: sub displayresource {
2038: my %content=@_;
2039: #
2040: # If the recipient is in the same course that the message was sent from and
2041: # has sufficient privileges, show "all details," else show citation
2042: #
2043: if (($env{'request.course.id'} eq $content{'courseid'})
2044: && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
2045: my $symb=&Apache::lonnet::symbread($content{'baseurl'});
2046: # Could not get a symb, give up
2047: unless ($symb) { return $content{'citation'}; }
2048: # Have a symb, can render
2049: return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
2050: &Apache::loncommon::get_previous_attempt($symb,
2051: $content{'sendername'},
2052: $content{'senderdomain'},
2053: $content{'courseid'}).
2054: '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
2055: &Apache::loncommon::get_student_view($symb,
2056: $content{'sendername'},
2057: $content{'senderdomain'},
2058: $content{'courseid'}).
2059: '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
2060: &Apache::loncommon::get_student_answers($symb,
2061: $content{'sendername'},
2062: $content{'senderdomain'},
2063: $content{'courseid'});
2064: } elsif ($env{'user.adv'}) {
2065: return $content{'citation'};
2066: }
2067: return '';
2068: }
2069:
2070: # ================================================================== The Header
2071:
2072: sub header {
2073: my ($r,$title,$baseurl)=@_;
2074:
2075: my $extra = &Apache::loncommon::studentbrowser_javascript();
2076: if ($baseurl) {
1.41 albertel 2077: $extra .= "<base href=\"".&Apache::lonnet::absolute_url()."/$baseurl\" />";
1.1 albertel 2078: }
2079: $r->print(&Apache::loncommon::start_page('Communication and Messages',
1.38 raeburn 2080: $extra));
1.1 albertel 2081: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.38 raeburn 2082: (($title?$title:'Communication and Messages')));
1.1 albertel 2083: }
2084:
2085: # ---------------------------------------------------------------- Print header
2086:
2087: sub printheader {
2088: my ($r,$url,$desc,$title,$baseurl)=@_;
2089: &Apache::lonhtmlcommon::add_breadcrumb
2090: ({href=>$url,
2091: text=>$desc});
2092: &header($r,$title,$baseurl);
2093: }
2094:
2095: # ------------------------------------------------------------ Store the comment
2096:
2097: sub storecomment {
2098: my ($r)=@_;
2099: my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2100: my $cleanmsgtxt='';
1.42 raeburn 2101: foreach my $line (split(/[\n\r]/,$msgtxt)) {
2102: unless ($line=~/^\s*(\>|\>\;)/) {
2103: $cleanmsgtxt.=$line."\n";
1.1 albertel 2104: }
2105: }
1.29 www 2106: my $key=&escape($env{'form.baseurl'}).'___'.time;
1.1 albertel 2107: &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
2108: }
2109:
2110: sub storedcommentlisting {
2111: my ($r)=@_;
2112: my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
1.29 www 2113: '^'.&escape(&escape($env{'form.showcommentbaseurl'})));
1.1 albertel 2114: $r->print(&Apache::loncommon::start_page('Stored Comment Listing',undef,
2115: {'onlybody' => 1}));
2116: if ((keys %msgs)[0]=~/^error\:/) {
2117: $r->print(&mt('No stored comments yet.'));
2118: } else {
2119: my $found=0;
1.42 raeburn 2120: foreach my $key (sort(keys(%msgs))) {
2121: $r->print("\n".$msgs{$key}."<hr />");
1.1 albertel 2122: $found=1;
2123: }
2124: unless ($found) {
2125: $r->print(&mt('No stored comments yet for this resource.'));
2126: }
2127: }
2128: }
2129:
2130: # ---------------------------------------------------------------- Send an email
2131:
2132: sub sendoffmail {
2133: my ($r,$folder)=@_;
2134: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2135: my $sendstatus='';
2136: my %specialmsg_status;
2137: my $numspecial = 0;
1.38 raeburn 2138: my ($cdom,$cnum,$group);
2139: if (exists($env{'form.group'})) {
2140: $group = $env{'form.group'};
2141: }
2142: if (exists($env{'request.course.id'})) {
2143: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2144: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2145: }
1.1 albertel 2146: if ($env{'form.send'}) {
1.53 raeburn 2147: if (!$env{'form.multiforward'}) {
2148: if ($group eq '') {
2149: &printheader($r,'','Messages being sent.');
2150: } else {
2151: $r->print(&groupmail_header('sending',$group));
2152: }
1.38 raeburn 2153: }
1.1 albertel 2154: $r->rflush();
2155: my %content=();
2156: undef %content;
2157: if ($env{'form.forwid'}) {
2158: my $msgid=$env{'form.forwid'};
2159: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2160: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2161: &statuschange($msgid,'forwarded',$folder);
2162: $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
2163: $content{'message'};
2164: }
2165: if ($env{'form.replyid'}) {
2166: my $msgid=$env{'form.replyid'};
2167: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2168: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2169: &statuschange($msgid,'replied',$folder);
2170: }
1.13 albertel 2171:
1.35 albertel 2172: my @to =
1.37 raeburn 2173: &Apache::loncommon::get_env_multiple('form.selectedusers_forminput');
1.25 foxr 2174: my $mode = $env{'form.sendmode'};
2175:
1.13 albertel 2176: my %toaddr;
1.35 albertel 2177: if (@to) {
2178: foreach my $dest (@to) {
1.27 albertel 2179: my ($user,$domain) = split(/:/, $dest);
1.25 foxr 2180: if (($user ne '') && ($domain ne '')) {
2181: my $address = $user.":".$domain; # How the code below expects it.
2182: $toaddr{$address} = '';
2183: }
2184: }
2185: }
2186:
1.1 albertel 2187: if ($env{'form.sendmode'} eq 'group') {
1.25 foxr 2188: foreach my $address (keys(%env)) {
2189: if ($address=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
2190: $toaddr{$1}='';
2191: }
1.1 albertel 2192: }
2193: } elsif ($env{'form.sendmode'} eq 'upload') {
1.13 albertel 2194: foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
1.43 raeburn 2195: my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/);
1.1 albertel 2196: if ($txt) {
1.43 raeburn 2197: $rec =~ s/^\s+//;
1.44 raeburn 2198: $rec =~ s/\s+$//;
1.1 albertel 2199: $toaddr{$rec}.=$txt."\n";
2200: }
2201: }
2202: } else {
1.25 foxr 2203: if (($env{'form.recuname'} ne '') && ($env{'form.recdomain'} ne '')) {
2204: $toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
2205: }
1.1 albertel 2206: }
2207: if ($env{'form.additionalrec'}) {
1.42 raeburn 2208: foreach my $rec (split(/\,/,$env{'form.additionalrec'})) {
1.43 raeburn 2209: my ($auname,$audom)=split(/:/,$rec);
1.25 foxr 2210: if (($auname ne "") && ($audom ne "")) {
2211: $toaddr{$auname.':'.$audom}='';
2212: }
1.1 albertel 2213: }
2214: }
2215:
2216: my $savemsg;
2217: my $msgtype;
2218: my %sentmessage;
1.7 albertel 2219: my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'},
2220: undef,1);
1.1 albertel 2221: if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
2222: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
2223: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
2224: '/'.$env{'request.course.sec'})
2225: )) {
2226: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
2227: $msgtype = 'critical';
2228: } else {
2229: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2230: }
2231:
1.13 albertel 2232: foreach my $address (sort(keys(%toaddr))) {
2233: my ($recuname,$recdomain)=split(/\:/,$address);
1.1 albertel 2234: my $msgtxt = $savemsg;
1.13 albertel 2235: if ($toaddr{$address}) { $msgtxt.='<hr />'.$toaddr{$address}; }
1.12 albertel 2236: my @thismsg;
1.1 albertel 2237: if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
2238: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
2239: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
2240: '/'.$env{'request.course.sec'}))) {
1.13 albertel 2241: $r->print(&mt('Sending critical message').' '.$recuname.':'.$recdomain.': ');
2242: @thismsg=
2243: &Apache::lonmsg::user_crit_msg($recuname,$recdomain,
2244: $msgsubj,$msgtxt,
2245: $env{'form.sendbck'},
2246: $env{'form.permanent'},
2247: \$sentmessage{$address});
1.1 albertel 2248: } else {
1.14 albertel 2249: $r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': ');
1.13 albertel 2250: @thismsg=
2251: &Apache::lonmsg::user_normal_msg($recuname,$recdomain,
2252: $msgsubj,$msgtxt,
2253: $content{'citation'},
2254: undef,undef,
2255: $env{'form.permanent'},
2256: \$sentmessage{$address});
1.1 albertel 2257: }
2258: if (($env{'request.course.id'}) && (($msgtype eq 'critical') ||
2259: ($env{'form.sendmode'} eq 'group'))) {
1.12 albertel 2260: $specialmsg_status{$recuname.':'.$recdomain} =
2261: join(' ',@thismsg);
2262: foreach my $result (@thismsg) {
2263: if ($result eq 'ok') {
2264: $numspecial++;
2265: }
2266: }
1.1 albertel 2267: }
1.12 albertel 2268: $sendstatus.=' '.join(' ',@thismsg);
1.1 albertel 2269: }
2270: if (($env{'request.course.id'}) && (($env{'form.sendmode'} eq 'group')
2271: || ($msgtype eq 'critical'))) {
2272: my $subj_prefix;
2273: if ($msgtype eq 'critical') {
2274: $subj_prefix = 'Critical.';
2275: } else {
2276: $subj_prefix = 'Broadcast.';
2277: }
2278: my ($specialmsgid,$specialresult);
1.29 www 2279: my $course_str = &escape('['.$cnum.':'.$cdom.']');
1.1 albertel 2280:
2281: if ($numspecial) {
2282: $specialresult = &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
2283: ' '.$course_str,$savemsg,undef,undef,undef,
2284: undef,undef,\$specialmsgid);
1.29 www 2285: $specialmsgid = &unescape($specialmsgid);
1.1 albertel 2286: }
2287: if ($specialresult eq 'ok') {
2288: my $record_sent;
1.13 albertel 2289: my @recusers;
2290: my @recudoms;
2291: my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
1.29 www 2292: split(/\:/,&unescape($specialmsgid));
1.13 albertel 2293:
1.1 albertel 2294: foreach my $recipient (sort(keys(%toaddr))) {
2295: if ($specialmsg_status{$recipient} eq 'ok') {
2296: my $usersubj = $subj_prefix.'['.$recipient.']';
2297: my $usermsgid =
2298: &Apache::lonmsg::buildmsgid($stamp,$usersubj,
2299: $msgname,$msgdom,
2300: $msgcount,$context,
2301: $pid);
2302: &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
2303: ' ['.$recipient.']',$msgsubj,undef,
2304: undef,undef,undef,$usermsgid,undef,undef,$specialmsgid);
1.13 albertel 2305: my ($uname,$udom) = split(/:/,$recipient);
1.1 albertel 2306: push(@recusers,$uname);
2307: push(@recudoms,$udom);
2308: }
2309: }
2310: if (@recusers) {
2311: my $specialmessage;
1.13 albertel 2312: my $sentsubj =
2313: $subj_prefix.' ('.$numspecial.' sent) '.$msgsubj;
1.1 albertel 2314: $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
2315: my $sentmsgid =
2316: &Apache::lonmsg::buildmsgid($stamp,$sentsubj,$msgname,
2317: $msgdom,$msgcount,$context,
2318: $pid);
2319: ($specialmsgid,$specialmessage) = &Apache::lonmsg::packagemsg($msgsubj,$savemsg,
2320: undef,undef,undef,\@recusers,\@recudoms,$sentmsgid);
2321: $record_sent = &Apache::lonmsg::store_sent_mail($specialmsgid,$specialmessage);
2322: }
2323: } else {
2324: &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');
2325: }
2326: }
2327: } else {
2328: &printheader($r,'','No messages sent.');
2329: }
1.53 raeburn 2330: if (!$env{'form.multiforward'}) {
2331: if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
2332: $r->print('<br /><span class="LC_success">'.&mt('Completed.').
2333: '</span>');
2334: if ($env{'form.displayedcrit'}) {
2335: &discrit($r);
2336: }
2337: if ($group ne '') {
2338: $r->print(&groupmail_sent($group,$cdom,$cnum));
2339: } else {
2340: &Apache::loncommunicate::menu($r);
2341: }
2342: } else {
2343: $r->print('<p><span class="LC_error">'.&mt('Could not deliver message').'</span> '.
2344: &mt('Please use the browser "Back" button and correct the recipient addresses '."($sendstatus)").'</p>');
1.38 raeburn 2345: }
1.1 albertel 2346: }
1.53 raeburn 2347: return $sendstatus;
1.1 albertel 2348: }
2349:
2350: # ===================================================================== Handler
2351:
2352: sub handler {
2353: my $r=shift;
2354:
2355: # ----------------------------------------------------------- Set document type
2356:
2357: &Apache::loncommon::content_type($r,'text/html');
2358: $r->send_http_header;
2359:
2360: return OK if $r->header_only;
2361:
2362: # --------------------------- Get query string for limited number of parameters
2363: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2364: ['display','replyto','forward','markread','markdel','markunread',
2365: 'sendreply','compose','sendmail','critical','recname','recdom',
2366: 'recordftf','sortedby','block','folder','startdis','interdis',
1.53 raeburn 2367: 'showcommentbaseurl','dismode','group','subject','text','ref',
2368: 'msgstatus']);
1.1 albertel 2369: $sqs='&sortedby='.$env{'form.sortedby'};
2370:
2371: # ------------------------------------------------------ They checked for email
2372: unless ($env{'form.block'}) {
2373: &Apache::lonnet::put('email_status',{'recnewemail'=>0});
2374: }
2375:
2376: # ----------------------------------------------------------------- Breadcrumbs
2377:
2378: &Apache::lonhtmlcommon::clear_breadcrumbs();
2379: &Apache::lonhtmlcommon::add_breadcrumb
2380: ({href=>"/adm/communicate",
2381: text=>"Communication/Messages",
2382: faq=>12,bug=>'Communication Tools',});
2383:
2384: # ------------------------------------------------------------------ Get Folder
2385:
2386: my $folder=$env{'form.folder'};
2387: unless ($folder) {
2388: $folder='';
2389: } else {
1.29 www 2390: $sqs.='&folder='.&escape($folder);
1.1 albertel 2391: }
2392: # ------------------------------------------------------------ Get Display Mode
2393:
2394: my $dismode=$env{'form.dismode'};
2395: unless ($dismode) {
2396: $dismode='';
2397: } else {
1.48 albertel 2398: $sqs.='&dismode='.&escape($dismode);
1.1 albertel 2399: }
2400:
2401: # --------------------------------------------------------------------- Display
1.53 raeburn 2402: my $msgstatus = $env{'form.msgstatus'};
1.1 albertel 2403: $startdis=$env{'form.startdis'};
1.53 raeburn 2404: if ($startdis ne '') {
2405: $startdis--;
2406: }
1.1 albertel 2407: unless ($startdis) { $startdis=0; }
2408:
2409: if ($env{'form.firstview'}) {
2410: $startdis=0;
2411: }
2412: if ($env{'form.lastview'}) {
2413: $startdis=-1;
2414: }
2415: if ($env{'form.prevview'}) {
2416: $startdis--;
2417: }
2418: if ($env{'form.nextview'}) {
2419: $startdis++;
2420: }
2421: my $postedstartdis=$startdis+1;
2422: $sqs.='&startdis='.$postedstartdis;
2423:
2424: # --------------------------------------------------------------- Render Output
2425:
2426: if ($env{'form.display'}) {
1.53 raeburn 2427: &displaymessage($r,$env{'form.display'},$folder,$msgstatus);
1.1 albertel 2428: } elsif ($env{'form.replyto'}) {
2429: &compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode);
2430: } elsif ($env{'form.confirm'}) {
2431: &printheader($r,'','Confirmed Receipt');
1.36 albertel 2432: my $replying = 0;
1.42 raeburn 2433: foreach my $envkey (keys(%env)) {
2434: if ($envkey=~/^form\.rec\_(.*)$/) {
1.1 albertel 2435: $r->print('<b>'.&mt('Confirming Receipt').':</b> '.
2436: &Apache::lonmsg::user_crit_received($1).'<br>');
2437: }
1.42 raeburn 2438: if ($envkey=~/^form\.reprec\_(.*)$/) {
1.1 albertel 2439: my $msgid=$1;
2440: $r->print('<b>'.&mt('Confirming Receipt').':</b> '.
2441: &Apache::lonmsg::user_crit_received($msgid).'<br>');
2442: &compout($r,'','','',$msgid);
1.36 albertel 2443: $replying = 1;
1.1 albertel 2444: }
2445: }
1.36 albertel 2446: if (!$replying) {
2447: &discrit($r);
2448: }
1.1 albertel 2449: } elsif ($env{'form.critical'}) {
2450: &printheader($r,'','Displaying Critical Messages');
2451: &discrit($r);
2452: } elsif ($env{'form.forward'}) {
2453: &compout($r,$env{'form.forward'},undef,undef,undef,$folder);
2454: } elsif ($env{'form.markdel'}) {
2455: &printheader($r,'','Deleted Message');
1.9 albertel 2456: my ($result,$msg) =
2457: &statuschange($env{'form.markdel'},'deleted',$folder);
2458: if (!$result) {
1.10 albertel 2459: $r->print('<p class="LC_error">'.
2460: &mt('Failed to delete the message.').'</p>'.
1.9 albertel 2461: '<p class="LC_error">'.$msg."</p>\n");
2462: }
1.1 albertel 2463: &Apache::loncommunicate::menu($r);
1.53 raeburn 2464: &disall($r,($folder?$folder:$dismode),$msgstatus);
2465: } elsif ($env{'form.markedaction'} eq 'markedforward') {
2466: my $total = 0;
2467: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
2468: foreach my $msgid (@to_forward) {
2469: &statuschange(&unescape($msgid),'forwarded',$folder);
2470: $total ++;
2471: }
2472: if ($total > 0) {
2473: &compout($r,undef,undef,undef,undef,$folder,$dismode,$total);
2474: }
2475: } elsif ($env{'form.markedaction'} eq 'markedread') {
2476: my $total = 0;
2477: my @to_markread = &Apache::loncommon::get_env_multiple('form.delmark');
2478: foreach my $msgid (@to_markread) {
2479: &statuschange(&unescape($msgid),'read',$folder);
2480: $total ++;
2481: }
2482: &printheader($r,'','Marked Messages Read');
2483: $r->print(&mt('Marked [_1] message(s) read',$total).'<p>');
2484: &Apache::loncommunicate::menu($r);
2485: &disall($r,($folder?$folder:$dismode),$msgstatus);
2486: } elsif ($env{'form.markedaction'} eq 'markedunread') {
2487: my $total = 0;
2488: my @to_markunread = &Apache::loncommon::get_env_multiple('form.delmark');
2489: foreach my $msgid (@to_markunread) {
2490: &statuschange(&unescape($msgid),'new',$folder);
2491: $total ++;
2492: }
2493: &printheader($r,'','Marked Messages Unread');
2494: $r->print(&mt('Marked [_1] message(s) unread',$total).'<p>');
2495: &Apache::loncommunicate::menu($r);
2496: &disall($r,($folder?$folder:$dismode),$msgstatus);
2497: } elsif ($env{'form.markedaction'} eq 'markedmove') {
2498: my $destfolder = $env{'form.movetofolder'};
2499: my %gotfolders = &Apache::lonmsg::get_user_folders();
2500: &printheader($r,'','Moved Messages');
2501: if (!defined($gotfolders{$destfolder})) {
2502: $r->print(&mt('Destination folder [_1] is not a valid folder',
2503: $destfolder));
2504: } else {
2505: my ($total,$failed,@failed_msg)=(0,0);
2506: my @to_move = &Apache::loncommon::get_env_multiple('form.delmark');
2507: foreach my $msgid (@to_move) {
2508: my ($result,$msg) = &movemsg(&unescape($msgid),$folder,
2509: $env{'form.movetofolder'});
2510: if ($result) {
1.9 albertel 2511: $total++;
1.53 raeburn 2512: } else {
1.9 albertel 2513: $failed++;
2514: push(@failed_msg,$msg);
1.53 raeburn 2515: }
1.1 albertel 2516: }
1.53 raeburn 2517: if ($failed) {
2518: $r->print('<p class="LC_error">
1.10 albertel 2519: '.&mt('Failed to move [_1] message(s)',$failed).
2520: '</p>');
1.53 raeburn 2521: $r->print('<p class="LC_error">'.
2522: join("</p>\n<p class=\"LC_error\">",@failed_msg).
2523: "</p>\n");
2524: }
2525: $r->print(&mt('Moved [_1] message(s)',$total).'<p>');
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 'markeddel') {
1.9 albertel 2530: my ($total,$failed,@failed_msg)=(0,0);
1.53 raeburn 2531: my @to_delete = &Apache::loncommon::get_env_multiple('form.delmark');
2532: foreach my $msgid (@to_delete) {
2533: my ($result,$msg) = &statuschange(&unescape($msgid),'deleted',
2534: $folder);
2535: if ($result) {
2536: $total++;
2537: } else {
2538: $failed++;
2539: push(@failed_msg,$msg);
1.1 albertel 2540: }
2541: }
2542: &printheader($r,'','Deleted Messages');
1.9 albertel 2543: if ($failed) {
2544: $r->print('<p class="LC_error">
1.10 albertel 2545: '.&mt('Failed to delete [_1] message(s)',$failed).
2546: '</p>');
1.9 albertel 2547: $r->print('<p class="LC_error">'.
2548: join("</p>\n<p class=\"LC_error\">",@failed_msg).
2549: "</p>\n");
2550: }
1.10 albertel 2551: $r->print(&mt('Deleted [_1] message(s)',$total).'<p>');
1.1 albertel 2552: &Apache::loncommunicate::menu($r);
1.53 raeburn 2553: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 2554: } elsif ($env{'form.markunread'}) {
2555: &printheader($r,'','Marked Message as Unread');
2556: &statuschange($env{'form.markunread'},'new');
2557: &Apache::loncommunicate::menu($r);
1.53 raeburn 2558: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 2559: } elsif ($env{'form.compose'}) {
2560: &compout($r,'','',$env{'form.compose'});
2561: } elsif ($env{'form.recordftf'}) {
2562: &facetoface($r,$env{'form.recordftf'});
2563: } elsif ($env{'form.block'}) {
2564: &examblock($r,$env{'form.block'});
2565: } elsif ($env{'form.sendmail'}) {
1.53 raeburn 2566: if ($env{'form.multiforward'}) {
2567: &printheader($r,'','Messages being sent.');
2568: my $fixed_subj = $env{'form.subject'};
2569: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2570: my (%sendresult,%forwardok,%forwardfail,$fwdcount);
2571: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
2572: foreach my $item (@to_forward) {
2573: my $msgid=&unescape($item);
2574: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2575: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2576: if ($env{'form.showorigsubj'}) {
2577: $env{'form.subject'} = $fixed_subj.$content{'subject'};
2578: } else {
2579: $env{'form.subject'} = '';
2580: }
2581: my $uname = $content{'sendername'};
2582: my $udom = $content{'senderdomain'};
2583: &statuschange($msgid,'forwarded',$folder);
2584: if ($env{'form.showorigsender'}) {
2585: $env{'form.message'} = $env{'form.msgheader'}.' '.
2586: &Apache::loncommon::plainname($uname,$udom).' ('.
2587: $uname.':'.$udom.')';
2588: }
2589: $env{'form.message'} .= "\n\n-- Forwarded message --\n\n".
2590: $content{'message'};
2591: $fwdcount ++;
2592: $r->print($fwdcount.': ');
2593: $sendresult{$msgid} = &sendoffmail($r,$folder);
2594: $r->print('<br />');
2595: }
2596: foreach my $key (keys(%sendresult)) {
2597: if ($sendresult{$key} =~/^(\s*(?:ok|con_delayed)\s*)*$/) {
2598: $forwardok{$key} = $sendresult{$key};
2599: } else {
2600: $forwardfail{$key} = $sendresult{$key};
2601: }
2602: }
2603: if (keys(%forwardok) > 0) {
2604: my $count = keys(%forwardok);
2605: $r->print('<br /><span class="LC_success">'.
2606: &mt('[quant,_1,message] forwarded.',$count).
2607: '</span>');
2608: }
2609: if (keys(%forwardfail) > 0) {
2610: my $count = keys(%forwardfail);
2611: $r->print('<p><span class="LC_error">'.
2612: &mt('Could not forward [quant,_1,message].',$count).
2613: '</span> ');
2614: foreach my $key (keys(%forwardfail)) {
2615: $r->print(&mt('Could not deliver forwarded message.').'</span> '.
2616: &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.').<br /><br />');
2617: }
2618: }
2619: &Apache::loncommunicate::menu($r);
2620: } else {
2621: &sendoffmail($r,$folder);
2622: }
1.1 albertel 2623: if ($env{'form.storebasecomment'}) {
2624: &storecomment($r);
1.38 raeburn 2625: }
1.1 albertel 2626: if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
1.38 raeburn 2627: &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
1.1 albertel 2628: $env{'course.'.$env{'request.course.id'}.'.domain'},
2629: 'Course_Announcements',
2630: $env{'form.subject'},
2631: $env{'form.message'},'/adm/communicate','public');
2632: }
1.38 raeburn 2633: if ((!exists($env{'form.group'})) && (!$env{'form.displayedcrit'})) {
1.53 raeburn 2634: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.36 albertel 2635: }
1.1 albertel 2636: } elsif ($env{'form.newfolder'}) {
2637: &printheader($r,'','New Folder');
1.46 raeburn 2638: my $showfolder = $env{'form.newfolder'};
2639: my ($makeresult,$warning) = &makefolder($env{'form.newfolder'});
2640: if ($makeresult eq 'ok') {
2641: $r->print(&mt('Mail folder "[_1]" created.',$showfolder).'<br />');
2642: } else {
2643: $r->print(&mt('Creation failed.').' '.$makeresult.'<br />'.
2644: $warning);
2645: $showfolder = $folder;
2646: }
2647: &Apache::loncommunicate::menu($r);
1.53 raeburn 2648: &disall($r,$showfolder,$msgstatus);
1.1 albertel 2649: } elsif ($env{'form.showcommentbaseurl'}) {
2650: &storedcommentlisting($r);
1.46 raeburn 2651: } elsif ($env{'form.folderaction'} eq 'delete') {
2652: &printheader($r,'','Deleted Folder');
2653: my $showfolder = '';
2654: my $delresult = &deletefolder($folder);
2655: if ($delresult eq 'ok') {
2656: $r->print(&mt('Mail folder "[_1]" deleted.',$folder).'<br />');
2657: } else {
2658: $r->print(&mt('Deletion failed.').' '.$delresult.'<br />');
2659: $showfolder = $folder;
2660: }
2661: &Apache::loncommunicate::menu($r);
1.53 raeburn 2662: &disall($r,$showfolder,$msgstatus);
1.46 raeburn 2663: } elsif ($env{'form.folderaction'} eq 'rename') {
2664: &printheader($r,'','Renamed Folder');
2665: my $showfolder = $env{'form.renamed'};
2666: my $renresult = &renamefolder($folder);
2667: if ($renresult eq 'ok') {
2668: $r->print(&mt('Mail folder "[_1]" renamed "[_2]".',$folder,$showfolder).'<br />');
2669: } else {
2670: $r->print(&mt('Renaming failed.').' '.$renresult.'<br />');
2671: $showfolder = $folder;
2672: }
2673: &Apache::loncommunicate::menu($r);
1.53 raeburn 2674: &disall($r,$showfolder,$msgstatus);
1.1 albertel 2675: } else {
2676: &printheader($r,'','Display All Messages');
1.44 raeburn 2677: &Apache::loncommunicate::menu($r);
1.53 raeburn 2678: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 2679: }
2680: $r->print(&Apache::loncommon::end_page());
2681: return OK;
2682: }
2683: # ================================================= Main program, reset counter
2684:
2685: =pod
2686:
2687: =back
2688:
2689: =cut
2690:
2691: 1;
2692:
2693: __END__
2694:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>