1: # The LearningOnline Network with CAPA
2: # Routines for messaging display
3: #
4: # $Id: lonmsgdisplay.pm,v 1.181.2.11 2024/07/05 18:06:47 raeburn Exp $
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::lonmsgdisplay: supports internal messaging
37:
38: =head1 SYNOPSIS
39:
40: lonmsgdisplay provides a handler to allow users to read, send,
41: and delete messages, and to create and delete message folders,
42: and to move messages between folders.
43:
44: =head1 OVERVIEW
45:
46: =head2 Messaging Overview
47:
48: X<messages>LON-CAPA provides an internal messaging system similar to
49: email, but customized for LON-CAPA's usage. LON-CAPA implements its
50: own messaging system, rather then building on top of email, because of
51: the features LON-CAPA messages can offer that conventional e-mail can
52: not:
53:
54: =over 4
55:
56: =item * B<Critical messages>: A message the recipient B<must>
57: acknowlegde receipt of before they are allowed to continue using the
58: system, preventing a user from claiming they never got a message
59:
60: =item * B<Receipts>: LON-CAPA can reliably send reciepts informing the
61: sender that it has been read; again, useful for preventing students
62: from claiming they did not see a message. (While conventional e-mail
63: has some reciept support, it's sporadic, e-mail client-specific, and
64: generally the receiver can opt to not send one, making it useless in
65: this case.)
66:
67: =item * B<Context>: LON-CAPA knows about the sender, such as where
68: they are in a course. When a student mails an instructor asking for
69: help on the problem, the instructor receives not just the student's
70: question, but all submissions the student has made up to that point,
71: the user's rendering of the problem, and the complete view the student
72: saw of the resource, including discussion up to that point. Finally,
73: the instructor is reading all of this inside of LON-CAPA, not their
74: email program, so they have full access to LON-CAPA's grading
75: interface, or other features they may wish to use in response to the
76: student's query.
77:
78: =item * B<Blocking>: LON-CAPA can block selected communication
79: features for students during an online exam. A course coordinator or
80: instructor can set an open and close date/time for scheduled online
81: exams in a course. If a user uses the LON-CAPA internal messaging
82: system to display e-mails during the scheduled blocking event,
83: display of all e-mail sent during the blocking period will be
84: suppressed, and a message of explanation, including details of the
85: currently active blocking periods will be displayed instead. A user
86: who has a course coordinator or instructor role in a course will be
87: unaffected by any blocking periods for the course, unless the user
88: also has a student role in the course, AND has selected the student role.
89:
90: =back
91:
92: Users can ask LON-CAPA to forward messages to conventional e-mail
93: addresses on their B<PREF> screen, but generally, LON-CAPA messages
94: are much more useful than traditional email can be made to be, even
95: with HTML support.
96:
97: =cut
98:
99: use strict;
100: use Apache::lonnet;
101: use HTML::TokeParser();
102: use Apache::Constants qw(:common);
103: use Apache::loncommon();
104: use Apache::lonhtmlcommon();
105: use Apache::longroup;
106: use Apache::lonnavmaps;
107: use Apache::lontexconvert();
108: use HTML::Entities();
109: use Apache::lonlocal;
110: use Apache::loncommunicate;
111: use Apache::lonfeedback;
112: use Apache::lonrss();
113: use Apache::lonselstudent();
114: use Apache::lonenc();
115: use lib '/home/httpd/lib/perl/';
116: use LONCAPA qw(:DEFAULT :match);
117:
118: # Querystring component with sorting type
119: my $sqs='';
120: my $startdis='';
121:
122: # ============================================================ List all folders
123:
124: sub folderlist {
125: my ($folder,$msgstatus) = @_;
126: my %html_lt = &Apache::lonlocal::texthash(
127: actn => 'Action',
128: fold => 'Folder',
129: show => 'Show',
130: status => 'Message Status',
131: go => 'Go',
132:
133: );
134: &html_escape(\%html_lt);
135: my %js_lt = &Apache::lonlocal::texthash(
136: nnff => 'New Name for Folder',
137: newn => 'New Name',
138: fmnb => 'Folder may not be renamed as it is a folder provided by the system.',
139: asth => 'Requested name already in use for a system-provided or user-defined folder.',
140:
141: );
142: &js_escape(\%js_lt);
143:
144: # set se lastvisit for the new mail check in the toplevel menu
145: &Apache::lonnet::appenv({'user.mailcheck.lastvisit'=>time});
146:
147: my %actions = &Apache::lonlocal::texthash(
148: view => 'View Folder',
149: rename => 'Rename Folder',
150: delete => 'Delete Folder',
151: );
152: $actions{'select_form_order'} = ['view','rename','delete'];
153:
154: my %statushash = &Apache::lonlocal::texthash(&get_msgstatus_types());
155:
156: $statushash{'select_form_order'} = ['','new','read','replied','forwarded'];
157:
158: my %permfolders = &get_permanent_folders();
159: my $permlist = join("','",sort(keys(%permfolders)));
160: my ($permlistkeys,$permlistvals);
161: foreach my $key (sort(keys(%permfolders))) {
162: $permlistvals .= $permfolders{$key}."','";
163: $permlistkeys .= $key."','";
164: }
165: $permlistvals =~ s/','$//;
166: $permlistkeys =~ s/','$//;
167: my %gotfolders = &Apache::lonmsg::get_user_folders();
168: my %userfolders;
169:
170: foreach my $key (keys(%gotfolders)) {
171: $key =~ s/(['"])/\$1/g; #' stupid emacs
172: $userfolders{$key} = $key;
173: }
174: my @userorder = sort(keys(%userfolders));
175: my %formhash = (%permfolders,%userfolders);
176: my $folderlist = join("','",@userorder);
177: $folderlist .= "','".$permlistvals;
178:
179: $formhash{'select_form_order'} = ['','critical',@userorder,'sent','trash'];
180: my $output = qq|<script type="text/javascript">
181: // <![CDATA[
182: function folder_choice(targetform,caller) {
183: var permfolders_keys = new Array('$permlistkeys');
184: var permfolders_vals = new Array('$permlistvals');
185: var allfolders = new Array('$folderlist');
186: if (caller == 'change') {
187: if (targetform.folderaction.options[targetform.folderaction.selectedIndex].value == 'rename') {
188: for (var i=0; i<permfolders_keys.length; i++) {
189: if (permfolders_keys[i] == targetform.folder.value) {
190: alert("'"+permfolders_vals[i]+"' -- $js_lt{'fmnb'}");
191: return;
192: }
193: }
194: var foldername=prompt('$js_lt{'nnff'}','$js_lt{'newn'}');
195: if (foldername) {
196: targetform.renamed.value=foldername;
197: for (var i=0; i<allfolders.length; i++) {
198: if (allfolders[i] == foldername) {
199: alert("'"+foldername+"' $js_lt{'asth'}");
200: return;
201: }
202: }
203: targetform.submit();
204: }
205: }
206: else {
207: targetform.submit();
208: }
209: }
210: if (caller == 'new') {
211: var newname=targetform.newfolder.value;
212: if (newname) {
213: for (var i=0; i<allfolders.length; i++) {
214: if (allfolders[i] == newname) {
215: alert("'"+newname+"' -- $js_lt{'asth'}");
216: return;
217: }
218: }
219: targetform.submit();
220: }
221: }
222: }
223: // ]]>
224: </script>|;
225: my %show = ('select_form_order' => [10,20,50,100,200],
226: map {$_=>$_} (10,20,50,100,200));
227:
228: $output .= '
229: <form method="post" action="/adm/email" name="folderlist">
230: <div class="LC_columnSection"><fieldset>
231: <legend>'.&mt('Folder Actions').'</legend>
232: <table border="0" cellspacing="2" cellpadding="8">
233: <tr>
234: <td><b>'.$html_lt{'fold'}.'</b><br />'."\n".
235: &Apache::loncommon::select_form($folder,'folder',\%formhash).'
236: </td>
237: <td><b>'.$html_lt{'show'}.'</b><br />'."\n".
238: &Apache::loncommon::select_form($env{'form.interdis'},'interdis',
239: \%show).'
240: </td>
241: <td><b>'.$html_lt{'status'}.'</b><br />'."\n".
242: &Apache::loncommon::select_form($msgstatus,'msgstatus',\%statushash).'
243: </td>
244: <td style="padding-right: 40px;">
245: <b>'.$html_lt{'actn'}.'</b><br />'."\n".'
246: <span class="LC_nobreak">'.
247: &Apache::loncommon::select_form('view','folderaction',\%actions).
248: ' <input type="button" value="'.$html_lt{'go'}.
249: '" onclick="javascript:folder_choice(this.form,'."'change'".');" />
250: </span>
251: </td>
252: <td style="border-left: 1px solid;padding-left: 40px;">
253: <b>'.&mt('New Folder').'</b><br />'."\n".'
254: <span class="LC_nobreak">
255: <input type="text" size="15" name="newfolder" value="" />
256: <input type="button" value="'.$html_lt{'go'}.
257: '" onclick="javascript:folder_choice(this.form,'."'new'".');" />
258: </span>
259: </td>
260: </tr>
261: </table>
262: </fieldset></div>
263: '."\n".
264: '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" />'.
265: '<input type="hidden" name="renamed" value="" />'.
266: ($folder=~/^critical/?'</form>':'');
267: return $output;
268: }
269:
270: sub get_permanent_folders {
271: my %permfolders =
272: &Apache::lonlocal::texthash('' => 'INBOX',
273: 'trash' => 'TRASH',
274: 'critical' => 'CRITICAL',
275: 'sent' => 'SENT MESSAGES',
276: );
277: return %permfolders;
278: }
279:
280: sub get_msgstatus_types {
281: # Don't translate here!
282: my %statushash = (
283: '' => 'Any',
284: 'new' => 'Unread',
285: 'read' => 'Read',
286: 'replied' => 'Replied to',
287: 'forwarded' => 'Forwarded',
288: );
289: return %statushash;
290: }
291:
292: sub scrollbuttons {
293: my ($start,$maxdis,$first,$finish,$total,$msgstatus)=@_;
294: unless ($total>0) { return ''; }
295: $start++; $maxdis++;$first++;$finish++;
296:
297: my %statushash = &get_msgstatus_types();
298: my $status;
299: if ($msgstatus eq '') {
300: $status = 'All'; # Don't translate here!
301: } else {
302: $status = $statushash{$msgstatus};
303: }
304: my $output = '<b>'.&mt('Page:').'</b> ';
305: if ($maxdis == 1) {
306: # No buttons if only one page is displayed
307: $output .= '1/1';
308: } else {
309: $output .=
310: '<input type="submit" name="firstview" value="|<" />'.
311: '<input type="submit" name="prevview" value="<" />'.
312: ' <input type="text" size="5" name="startdis" value="'.$start.'" onchange="this.form.submit()" /> / '.$maxdis.' '.
313: '<input type="submit" name="nextview" value=">" />'.
314: '<input type="submit" name="lastview" value=">|" />';
315: }
316: $output .=
317: '<p>'
318: .'<b>'.&mt($status.' messages:').'</b> '
319: .&mt('showing messages [_1] through [_2] of [_3].',
320: $first,$finish,$total)
321: .'</p>'
322: .'</form>';
323:
324: return $output;
325: }
326: # =============================================================== Status Change
327:
328: sub statuschange {
329: my ($msgid,$newstatus,$folder)=@_;
330: my $suffix=&Apache::lonmsg::foldersuffix($folder);
331: my %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
332: if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
333: unless ($status{$msgid}) { $status{$msgid}='new'; }
334: unless (($status{$msgid} eq 'replied') ||
335: ($status{$msgid} eq 'forwarded')) {
336: &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
337: }
338: if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
339: &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
340: }
341: if ($newstatus eq 'deleted') {
342: return &movemsg($msgid,$folder,'trash');
343: }
344: return ;
345: }
346:
347: # ============================================================= Make new folder
348:
349: sub makefolder {
350: my ($newfolder) = @_;
351: my %permfolders = &get_permanent_folders();
352: my %userfolders = &Apache::lonmsg::get_user_folders();
353: my ($outcome,$warning);
354: if (defined($userfolders{$newfolder})) {
355: return &mt('The folder name: "[_1]" is already in use for an existing folder.',$newfolder);
356: }
357: foreach my $perm (keys(%permfolders)) {
358: if ($permfolders{$perm} eq $newfolder) {
359: return &mt('The folder name: "[_1]" is already used for one of the folders automatically generated by the system.',$newfolder);
360: }
361: }
362: if (&get_msgfolder_lock() eq 'ok') {
363: my %counter_hash = &Apache::lonnet::get('email_folders',["\0".'idcount']);
364: my $lastcount = $counter_hash{"\0".'idcount'};
365: my $folder_id = $lastcount + 1;
366: while (defined($userfolders{$folder_id})) {
367: $folder_id ++;
368: }
369: my %folderinfo = ( id => $folder_id,
370: created => time, );
371: $outcome =
372: &Apache::lonnet::put('email_folders',{$newfolder => \%folderinfo,
373: "\0".'idcount' => $folder_id});
374: my $releaseresult = &release_msgfolder_lock();
375: if ($releaseresult ne 'ok') {
376: $warning = $releaseresult;
377: }
378: } else {
379: $outcome =
380: &mt('Error - could not obtain lock on message folders record.');
381: }
382: return ($outcome,$warning);
383: }
384:
385: # ============================================================= Delete folder
386:
387: sub deletefolder {
388: my ($folder)=@_;
389: my %permfolders = &get_permanent_folders();
390: if (defined($permfolders{$folder})) {
391: return &mt('The folder "[_1]" may not be deleted.',$permfolders{$folder});
392: }
393: my %userfolders = &Apache::lonmsg::get_user_folders();
394: if (!defined($userfolders{$folder})) {
395: return &mt('The folder "[_1]" does not exist so deletion is not required.',
396: $folder);
397: }
398: # check folder is empty;
399: my $suffix=&Apache::lonmsg::foldersuffix($folder);
400: my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
401: if (@messages > 0) {
402: return &mt('The folder "[_1]" contains messages so it may not be deleted.',$folder).
403: '<br />'.
404: &mt('Delete or move the messages to a different folder first.');
405: }
406: my $delresult = &Apache::lonnet::del('email_folders',[$folder]);
407: return $delresult;
408: }
409:
410: sub renamefolder {
411: my ($folder) = @_;
412: my $newname = $env{'form.renamed'};
413: my %permfolders = &get_permanent_folders();
414: if ($env{'form.renamed'} eq '') {
415: return &mt('The folder "[_1]" may not be renamed to "[_2]" as the new name you requested is an invalid name.',$folder,$newname);
416: }
417: if (defined($permfolders{$folder})) {
418: return &mt('The folder "[_1]" may not be renamed as it is a folder provided by the system.',$folder);
419: }
420: if (defined($permfolders{$newname})) {
421: 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);
422: }
423: my %userfolders = &Apache::lonmsg::get_user_folders();
424: if (defined($userfolders{$newname})) {
425: 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);
426: }
427: if (!defined($userfolders{$folder})) {
428: return &mt('The folder "[_1]" could not be renamed to "[_2]" because the folder does not exist.',$folder,$newname);
429: }
430: my %folderinfo;
431: if (ref($userfolders{$folder}) eq 'HASH') {
432: %folderinfo = %{$userfolders{$folder}};
433: } else {
434: %folderinfo = ( id => $folder,
435: created => $userfolders{$folder},);
436: }
437: my $outcome =
438: &Apache::lonnet::put('email_folders',{$newname => \%folderinfo});
439: if ($outcome eq 'ok') {
440: $outcome = &Apache::lonnet::del('email_folders',[$folder]);
441: }
442: return $outcome;
443: }
444:
445: sub get_msgfolder_lock {
446: # get lock for mail folder counter.
447: my $lockhash = { "\0".'lock_counter' => time, };
448: my $tries = 0;
449: my $gotlock = &Apache::lonnet::newput('email_folders',$lockhash);
450: while (($gotlock ne 'ok') && $tries <3) {
451: $tries ++;
452: sleep(1);
453: $gotlock = &Apache::lonnet::newput('email_folders',$lockhash);
454: }
455: return $gotlock;
456: }
457:
458: sub release_msgfolder_lock {
459: # remove lock
460: my @del_lock = ("\0".'lock_counter');
461: my $dellockoutcome=&Apache::lonnet::del('email_folders',\@del_lock);
462: if ($dellockoutcome ne 'ok') {
463: return ('<br />'.&mt('Warning: failed to release lock for counter').'<br />');
464: } else {
465: return 'ok';
466: }
467: }
468:
469:
470: # ======================================================== Move between folders
471:
472: sub movemsg {
473: my ($msgid,$srcfolder,$trgfolder)=@_;
474: if ($srcfolder eq 'new') { $srcfolder=''; }
475: my $srcsuffix=&Apache::lonmsg::foldersuffix($srcfolder);
476: my $trgsuffix=&Apache::lonmsg::foldersuffix($trgfolder);
477: if ($srcsuffix eq $trgsuffix) {
478: return (0,&mt('Message not moved, Attempted to move message to the same folder as it already is in.'));
479: }
480:
481: # Copy message
482: my %message=&Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid]);
483: if (!exists($message{$msgid}) || $message{$msgid} eq '') {
484: if (&Apache::lonnet::error(%message)) {
485: return (0,&mt('Message not moved, A network error occurred.'));
486: } else {
487: return (0,&mt('Message not moved as the message is no longer in the source folder.'));
488: }
489: }
490:
491: my $result =&Apache::lonnet::put('nohist_email'.$trgsuffix,
492: {$msgid => $message{$msgid}});
493: if (&Apache::lonnet::error($result)) {
494: return (0,&mt('Message not moved, A network error occurred.'));
495: }
496:
497: # Copy status
498: unless ($trgfolder eq 'trash') {
499: my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]);
500: # a non-existant status is the mark of an unread msg
501: if (&Apache::lonnet::error(%status)) {
502: return (0,&mt('Message copied to new folder but status was not, A network error occurred.'));
503: }
504: my $result=&Apache::lonnet::put('email_status'.$trgsuffix,
505: {$msgid => $status{$msgid}});
506: if (&Apache::lonnet::error($result)) {
507: return (0,&mt('Message copied to new folder but status was not, A network error occurred.'));
508: }
509: }
510:
511: # Delete orginals
512: my $result_del_msg =
513: &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]);
514: my $result_del_stat =
515: &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]);
516: if (&Apache::lonnet::error($result_del_msg)) {
517: return (0,&mt('Message copied, but unable to delete the original from the source folder.'));
518: }
519: if (&Apache::lonnet::error($result_del_stat)) {
520: return (0,&mt('Message copied, but unable to delete the original status from the source folder.'));
521: }
522:
523: return (1);
524: }
525:
526: # ======================================================= Display a course list
527:
528: sub discourse {
529: my ($statushash) = @_;
530: my ($result,$active,$previous,$future);
531: my $crstype = &Apache::loncommon::course_type();
532: my ($course_personnel,
533: $current_members,
534: $expired_members,
535: $future_members) =
536: &Apache::lonselstudent::get_people_in_class($env{'request.course.sec'});
537: unshift @$current_members, (@$course_personnel);
538: my %defaultUsers;
539:
540: my $tmptext;
541: if ($tmptext = &Apache::lonselstudent::render_student_list($current_members,
542: "activeusers",
543: "current",
544: \%defaultUsers,
545: 1,"selectedusers",1,'email')
546: ) {
547: my $bcc_curr_hdr;
548: if ($crstype eq 'Community') {
549: $bcc_curr_hdr = &mt('Bcc: community participants with current access');
550: } else {
551: $bcc_curr_hdr = &mt('Bcc: course members with current access');
552: }
553: $result .= '<fieldset id="LC_activeusers"><legend>'
554: .$bcc_curr_hdr
555: .'</legend>'
556: .'<form name="activeusers" action="">';
557: $result .= $tmptext.'</form></fieldset><br />';
558: if (ref($statushash) eq 'HASH') {
559: $statushash->{'active'} = 1;
560: }
561: }
562: if ($tmptext = &Apache::lonselstudent::render_student_list($expired_members,
563: "previoususers",
564: "expired",
565: \%defaultUsers,
566: 1, "selectedusers",0,'email')
567: ) {
568: my $bcc_prev_hdr;
569: if ($crstype eq 'Community') {
570: $bcc_prev_hdr = &mt('Bcc: community participants with expired access');
571: } else {
572: $bcc_prev_hdr = &mt('Bcc: course members with expired access');
573: }
574: $result .= '<fieldset id="LC_previoususers"><legend>'
575: .$bcc_prev_hdr
576: .'</legend>'
577: .'<form name="previoususers" action="">';
578: $result .= $tmptext.'</form></fieldset><br />';
579: if (ref($statushash) eq 'HASH') {
580: $statushash->{'previous'} = 1;
581: }
582:
583: }
584: if ($tmptext = &Apache::lonselstudent::render_student_list($future_members,
585: "futureusers",
586: "future",
587: \%defaultUsers,
588: 1, "selectedusers",0,'email')
589: ) {
590: my $bcc_future_hdr;
591: if ($crstype eq 'Community') {
592: $bcc_future_hdr = &mt('Bcc: community participants with future access');
593: } else {
594: $bcc_future_hdr = &mt('Bcc: course members with future access');
595: }
596:
597: $result .= '<fieldset id="LC_futureusers"><legend>'
598: .$bcc_future_hdr
599: .'</legend>'
600: .'<form name="futureusers" action="">';
601: $result .= $tmptext.'</form></fieldset>';
602: if (ref($statushash) eq 'HASH') {
603: $statushash->{'future'} = 1;
604: }
605:
606: }
607: return $result;
608: }
609:
610: sub disgroup {
611: my ($r,$cdom,$cnum,$group,$access_status) = @_;
612: my $hasfloat;
613: # Needs to be in a course
614: if (!($env{'request.course.fn'})) {
615: $r->print('<span class="LC_error">'.&mt('Error: you must have a course role selected to be able to send a broadcast message to a group in the course.').'</span>');
616: return;
617: }
618: if ($cdom eq '' || $cnum eq '') {
619: $r->print('<span class="LC_error">'.&mt('Error: could not determine domain or number of course').'</span>');
620: return;
621: }
622: my ($memberinfo,$numitems) =
623: &Apache::longroup::group_memberlist($cdom,$cnum,$group,{},[]);
624: my @statustypes = ('active');
625: my $viewgrps = &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
626: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
627: my $editgrps = &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
628: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
629: if ($viewgrps || $editgrps) {
630: push(@statustypes,('future','previous'));
631: }
632: if (keys(%{$memberinfo}) == 0) {
633: $r->print('<span class="LC_warning">'.
634: &mt('As this group has no members, there are no recipients to select').
635: '</span>');
636: return;
637: } else {
638: $hasfloat = 1;
639: $r->print('<div class="LC_left_float">');
640: my %Sortby = (
641: active => {},
642: previous => {},
643: future => {},
644: );
645: my %lt = &Apache::lonlocal::texthash(
646: 'name' => 'Name',
647: 'usnm' => 'Username',
648: 'doma' => 'Domain',
649: 'active' => 'Broadcast to Active Members',
650: 'previous' => 'Broadcast (Bcc) to Former Members',
651: 'future' => 'Broadcast (Bcc) to Future Members',
652: );
653: foreach my $user (sort(keys(%{$memberinfo}))) {
654: my $status = $$memberinfo{$user}{status};
655: if ($env{'form.'.$status.'.sortby'} eq 'fullname') {
656: push(@{$Sortby{$status}{$$memberinfo{$user}{fullname}}},$user);
657: } elsif ($env{'form.'.$status.'.sortby'} eq 'username') {
658: push(@{$Sortby{$status}{$$memberinfo{$user}{uname}}},$user);
659: } elsif ($env{'form.'.$status.'.sortby'} eq 'domain') {
660: push(@{$Sortby{$status}{$$memberinfo{$user}{udom}}},$user);
661: } else {
662: push(@{$Sortby{$status}{$$memberinfo{$user}{fullname}}},$user);
663: }
664: }
665: $r->print(&group_check_uncheck());
666: foreach my $status (@statustypes) {
667: if (ref($numitems) eq 'HASH') {
668: if ((defined($$numitems{$status})) && ($$numitems{$status})) {
669: my $formname = $status.'users';
670: if (ref($access_status) eq 'HASH') {
671: $access_status->{$status} = $$numitems{$status};
672: }
673: $r->print('<fieldset>'.
674: '<legend>'.$lt{$status}.'</legend>'.
675: '<form name="'.$formname.'" action="">'.
676: '<span class="LC_nobreak">'.
677: '<input type="button" value="'.&mt('Check All').'" '.
678: 'onclick="javascript:toggleAll('."this.form,'check'".')" />'.
679: ' '.
680: '<input type="button" value="'.&mt('Uncheck All').'" '.
681: 'onclick="javascript:toggleAll('."this.form,'uncheck'".')" />'.
682: '</span>');
683: if ($status eq 'active') {
684: $r->print((' 'x3).'<select name="groupmail">'.
685: '<option value="bcc" selected="selected">'.&mt('Bcc').'</option>'.
686: '<option value="cc">'.&mt('Cc').'</option>'.
687: '</select>');
688: }
689: $r->print('<br />'.&Apache::loncommon::start_data_table().
690: &Apache::loncommon::start_data_table_header_row().
691: "<th>$lt{'name'}</th>".
692: "<th>$lt{'usnm'}</th>".
693: "<th>$lt{'doma'}</th>".
694: &Apache::loncommon::end_data_table_header_row());
695: foreach my $key (sort(keys(%{$Sortby{$status}}))) {
696: foreach my $user (@{$Sortby{$status}{$key}}) {
697: $r->print(&Apache::loncommon::start_data_table_row().
698: '<td><span class="LC_nobreak"><input type="checkbox" '.
699: 'name="selectedusers_forminput" value="'.
700: $user.':'.$status.'" />'.
701: $$memberinfo{$user}{'fullname'}.'</span></td>'.
702: '<td>'.$$memberinfo{$user}{'uname'}.'</td>'.
703: '<td>'.$$memberinfo{$user}{'udom'}.'</td>'.
704: &Apache::loncommon::end_data_table_row());
705: }
706: }
707: $r->print(&Apache::loncommon::end_data_table().'</form>'.
708: '</fieldset><br />');
709: }
710: }
711: }
712: $r->print('</div>');
713: }
714: return $hasfloat;
715: }
716:
717: sub group_check_uncheck {
718: my $output = qq|
719: <script type="text/javascript">
720: // <![CDATA[
721: function toggleAll(form,action) {
722: if (typeof(form.selectedusers_forminput.length)=="undefined") {
723: if (action == 'check') {
724: form.selectedusers_forminput.checked = true;
725: } else {
726: form.selectedusers_forminput.checked = false;
727: }
728: } else {
729: for (var i=0; i<form.selectedusers_forminput.length; i++) {
730: if (action == 'check') {
731: form.selectedusers_forminput[i].checked = true;
732: } else {
733: form.selectedusers_forminput[i].checked = false;
734: }
735: }
736: }
737: }
738: // ]]>
739: </script>
740: |;
741: }
742:
743: sub groupmail_header {
744: my ($action,$group,$cdom,$cnum) = @_;
745: my ($description,$refarg);
746: if (!$cdom || !$cnum) {
747: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
748: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
749: }
750: if (exists($env{'form.ref'})) {
751: $refarg = 'ref='.$env{'form.ref'};
752: }
753: if (!$group) {
754: $group = $env{'form.group'};
755: }
756: if ($group eq '') {
757: return '';
758: } else {
759: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
760: if (defined($curr_groups{$group})) {
761: my %groupinfo =
762: &Apache::longroup::get_group_settings($curr_groups{$group});
763: $description = &unescape($groupinfo{'description'});
764: }
765: }
766: &Apache::lonhtmlcommon::clear_breadcrumbs();
767: if ($refarg) {
768: my $brtitle;
769: if (&Apache::loncommon::course_type() eq 'Community') {
770: $brtitle = 'View community groups';
771: } else {
772: $brtitle = 'View course groups';
773: }
774: &Apache::lonhtmlcommon::add_breadcrumb
775: ({href=>"/adm/coursegroups",
776: text=>"Groups",
777: title=>$brtitle});
778: }
779: my $view_permission =
780: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
781: my $navmap=Apache::lonnavmaps::navmap->new();
782: my $grouppagelink = &Apache::longroup::get_group_link($cdom,$cnum,$group,$navmap,$view_permission,$refarg);
783: if ($grouppagelink) {
784: &Apache::lonhtmlcommon::add_breadcrumb
785: ({href=>$grouppagelink,
786: text=>&mt('Group').": $description",
787: title=>&mt("Go to group's home page"),
788: no_mt=>1,
789: },);
790: } else {
791: &Apache::lonhtmlcommon::add_breadcrumb
792: ({text=>&mt('Group').": $description",
793: no_mt=>1,});
794: }
795: &Apache::lonhtmlcommon::add_breadcrumb
796: ({href=>"/adm/email?compose=group&group=".
797: "$env{'form.group'}&$refarg",
798: text=>"Send a Message in a Group",
799: title=>"Compose Group Message"},);
800: if ($action eq 'sending') {
801: &Apache::lonhtmlcommon::add_breadcrumb
802: ({text=>"Messages being sent.",
803: title=>"E-mails sent"},);
804: }
805: my $groupheader = &Apache::loncommon::start_page('Group Message');
806: $groupheader .= &Apache::lonhtmlcommon::breadcrumbs(
807: &mt('Group messages - [_1]',$description),
808: undef,undef,undef,undef,1);
809: return $groupheader;
810: }
811:
812: sub groupmail_sent {
813: my ($group,$cdom,$cnum) = @_;
814: my $refarg;
815: if (exists($env{'form.ref'})) {
816: $refarg = 'ref='.$env{'form.ref'};
817: }
818: my $output .= '<br /><br /><a href="/adm/email?compose=group&group='.
819: $group.'&'.$refarg.'">'.
820: &mt('Send another group message').'</a>'.' '.
821: '<a href="/adm/'.$cdom.'/'.$cnum.'/'.$group.'/smppg?'.
822: $refarg.'">'. &mt('Return to group page').'</a>';
823: return $output;
824: }
825:
826: # ==================================================== Display Critical Message
827:
828: sub discrit {
829: my $r=shift;
830: my $header = '<h1>'.&mt('Critical Messages').'</h1>'
831: .'<div class="LC_warning">'
832: .&mt('Access to other pages will be prevented until you have moved all critical messages to your inbox.')
833: .'</div><br />'
834: .'<form action="/adm/email" method="post">'
835: .'<input type="hidden" name="confirm" value="true" />';
836: my %what=&Apache::lonnet::dump('critical');
837: my $result = '';
838: # Sort by date in descending order
839: foreach my $key (sort{$b <=> $a}(keys(%what))) {
840: my %content=&Apache::lonmsg::unpackagemsg($what{$key});
841: next if ($content{'senderdomain'} eq '');
842: my $description;
843: if ($content{'courseid'} ne '') {
844: if ($content{'courseid'} =~ m{/^$match_domain\_$match_courseid$}) {
845: my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'},{'one_time' => 1});
846: if ($courseinfo{'description'} ne '') {
847: $description = $courseinfo{'description'};
848: }
849: }
850: }
851: $result .= &Apache::lonhtmlcommon::start_pick_box()
852: .&Apache::lonhtmlcommon::row_title(&mt('From'),undef,'LC_oddrow_value')
853: .'<b>'.&Apache::loncommon::aboutmewrapper(
854: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b>'
855: .' ('.$content{'sendername'}.':'.$content{'senderdomain'}.')'
856: .&Apache::lonhtmlcommon::row_closure(1)
857: .&Apache::lonhtmlcommon::row_title(&mt('Date'),undef,'LC_evenrow_value')
858: .$content{'time'}
859: .&Apache::lonhtmlcommon::row_closure(1)
860: .&Apache::lonhtmlcommon::row_title(&mt('Subject'),undef,'LC_oddrow_value')
861: .$content{'subject'}
862: .&Apache::lonhtmlcommon::row_closure(1);
863: if ($description ne '') {
864: $result .= &Apache::lonhtmlcommon::row_title(&mt('Course'),undef,'LC_oddrow_value')
865: .$description
866: .&Apache::lonhtmlcommon::row_closure(1);
867: }
868: $result .= &Apache::lonhtmlcommon::row_title(&mt('Message'),undef,'LC_evenrow_value')
869: .'<pre class="LC_wordwrap">'.&Apache::lontexconvert::msgtexconverted($content{'message'}).'</pre>'
870: .&Apache::lonhtmlcommon::row_closure()
871: .&Apache::lonhtmlcommon::row_title('',undef,'LC_oddrow_value')
872: .'<div class="LC_warning">';
873: my ($rec_button,$reprec_button);
874: $rec_button = &mt('Move to Inbox');
875: if (!$content{'noreplies'}) {
876: $reprec_button = &mt('Move to Inbox/Compose reply');
877: }
878: if ($content{'sendback'}) {
879: $rec_button = &mt('Confirm Receipt');
880: if (!$content{'noreplies'}) {
881: $reprec_button = &mt('Confirm Receipt and Reply');
882: }
883: $result .= &mt('You have to confirm that you have received this message before you can view other pages. After confirmation, this message will be moved to your regular inbox');
884: } else {
885: $result .= &mt('Access to other pages will be prevented until you have moved the message to your inbox.');
886: }
887: $result .= '</div>'
888: .&Apache::lonhtmlcommon::row_closure(1)
889: .&Apache::lonhtmlcommon::row_title('',undef,'LC_evenrow_value')
890: .'<input type="submit" name="rec_'.$key.'" value="'.$rec_button.'" />';
891: if (!$content{'noreplies'}) {
892: $result .= '<input type="submit" name="reprec_'.$key.'" '
893: .'value="'.$reprec_button.'" />'
894: }
895: $result .= &Apache::lonhtmlcommon::row_closure(1)
896: .&Apache::lonhtmlcommon::end_pick_box()
897: .'<br />';
898: }
899: # Check to see if there were any messages.
900: if ($result eq '') {
901: $result =
902: '<p class="LC_info">'.
903: &mt('You have no critical messages.').
904: '</p>'.
905: &Apache::lonhtmlcommon::actionbox(
906: ['<a href="/adm/roles">'.&mt('Select a course').'</a>',
907: '<a href="/adm/email">'.&mt('Communicate').'</a>']);
908: } else {
909: $r->print($header);
910: }
911: $r->print($result);
912: $r->print('<input type="hidden" name="displayedcrit" value="true" /></form>');
913: }
914:
915: sub sortedmessages {
916: my ($blocked,$startblock,$endblock,$by_ip,$numblocked,$folder,$msgstatus) = @_;
917: my $suffix=&Apache::lonmsg::foldersuffix($folder);
918: my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
919: #unpack the varibles and repack into temp for sorting
920: my @temp;
921: my %descriptions;
922: my %status_cache =
923: &Apache::lonnet::get('email_status'.&Apache::lonmsg::foldersuffix($folder),\@messages);
924:
925: my $get_received;
926: if ($folder eq 'sent'
927: && ($env{'form.sortedby'} =~ m/^(rev)?(user|domain)$/)) {
928: $get_received = 1;
929: }
930:
931: foreach my $msgid (@messages) {
932: next if ($msgid eq '');
933: my $esc_msgid=&escape($msgid);
934: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,$processid,$symb,$error) =
935: &Apache::lonmsg::unpackmsgid($esc_msgid,$folder,undef,
936: \%status_cache);
937: next if ($msgstatus ne '' && $msgstatus ne $status);
938: my $description = &get_course_desc($fromcid,\%descriptions);
939: my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
940: $esc_msgid,$description);
941: if ($get_received) {
942: my %message = &Apache::lonnet::get('nohist_email'.$suffix,
943: [$msgid]);
944: my %content = &Apache::lonmsg::unpackagemsg($message{$msgid});
945: push(@temp1,$content{'recuser'},$content{'recdomain'});
946: }
947: # Check whether message was sent during blocking period.
948: if (($by_ip) ||
949: (($sendtime >= $startblock) && ($sendtime <= $endblock && $endblock > 0))) {
950: $$blocked{$msgid} = 'ON';
951: $$numblocked ++;
952: } else {
953: push @temp ,\@temp1;
954: }
955: }
956: #default sort
957: @temp = sort {$a->[0] <=> $b->[0]} @temp;
958: if ($env{'form.sortedby'} eq "date"){
959: @temp = sort {$a->[0] <=> $b->[0]} @temp;
960: }
961: if ($env{'form.sortedby'} eq "revdate"){
962: @temp = sort {$b->[0] <=> $a->[0]} @temp;
963: }
964: if ($env{'form.sortedby'} eq "user"){
965: if ($get_received) {
966: @temp = sort {lc($a->[7][0]) cmp lc($b->[7][0])} @temp;
967: } else {
968: @temp = sort {lc($a->[2]) cmp lc($b->[2])} @temp;
969: }
970: }
971: if ($env{'form.sortedby'} eq "revuser"){
972: if ($get_received) {
973: @temp = sort {lc($b->[7][0]) cmp lc($a->[7][0])} @temp;
974: } else {
975: @temp = sort {lc($b->[2]) cmp lc($a->[2])} @temp;
976: }
977: }
978: if ($env{'form.sortedby'} eq "domain"){
979: if ($get_received) {
980: @temp = sort {$a->[8][0] cmp $b->[8][0]} @temp;
981: } else {
982: @temp = sort {$a->[3] cmp $b->[3]} @temp;
983: }
984: }
985: if ($env{'form.sortedby'} eq "revdomain"){
986: if ($get_received) {
987: @temp = sort {$b->[8][0] cmp $a->[8][0]} @temp;
988: } else {
989: @temp = sort {$b->[3] cmp $a->[3]} @temp;
990: }
991: }
992: if ($env{'form.sortedby'} eq "subject"){
993: @temp = sort {lc($a->[1]) cmp lc($b->[1])} @temp;
994: }
995: if ($env{'form.sortedby'} eq "revsubject"){
996: @temp = sort {lc($b->[1]) cmp lc($a->[1])} @temp;
997: }
998: if ($env{'form.sortedby'} eq "course"){
999: @temp = sort {lc($a->[6]) cmp lc($b->[6])} @temp;
1000: }
1001: if ($env{'form.sortedby'} eq "revcourse"){
1002: @temp = sort {lc($b->[6]) cmp lc($a->[6])} @temp;
1003: }
1004: if ($env{'form.sortedby'} eq "status"){
1005: @temp = sort {$a->[4] cmp $b->[4]} @temp;
1006: }
1007: if ($env{'form.sortedby'} eq "revstatus"){
1008: @temp = sort {$b->[4] cmp $a->[4]} @temp;
1009: }
1010: return @temp;
1011: }
1012:
1013: sub get_course_desc {
1014: my ($fromcid,$descriptions) = @_;
1015: my $description;
1016: if (!$fromcid) {
1017: return $description;
1018: } else {
1019: if (defined($$descriptions{$fromcid})) {
1020: $description = $$descriptions{$fromcid};
1021: } else {
1022: if (defined($env{'course.'.$fromcid.'.description'})) {
1023: $description = $env{'course.'.$fromcid.'.description'};
1024: } else {
1025: if ($fromcid =~ m{/^$match_domain\_$match_courseid$}) {
1026: my %courseinfo=&Apache::lonnet::coursedescription($fromcid,
1027: {'one_time' => 1});
1028: $description = $courseinfo{'description'};
1029: }
1030: }
1031: if ($description ne '') {
1032: $$descriptions{$fromcid} = $description;
1033: }
1034: }
1035: return $description;
1036: }
1037: }
1038:
1039: # ======================================================== Display all messages
1040:
1041: sub disall {
1042: my ($r,$folder,$msgstatus)=@_;
1043: my %saveable = ('msgstatus' => 'scalar',
1044: 'sortedby' => 'scalar',
1045: 'interdis' => 'scalar',
1046: );
1047: &Apache::loncommon::store_settings('user','mail',\%saveable);
1048: &Apache::loncommon::restore_settings('user','mail',\%saveable);
1049: $folder ||= $env{'form.folder'};
1050: # Always show critical messages if present
1051: my @what=&Apache::lonnet::dump('critical',$env{'user.domain'},$env{'user.name'});
1052: if ($what[0]) {
1053: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
1054: $folder = 'critical';
1055: }
1056: }
1057: $msgstatus ||= $env{'form.msgstatus'};
1058: $env{'form.interdis'} ||= 20;
1059:
1060: $r->print(&folderlist($folder,$msgstatus));
1061: if ($folder eq 'critical') {
1062: &discrit($r);
1063: } else {
1064: &disfolder($r,$folder,$msgstatus);
1065: }
1066: }
1067:
1068: # ============================================================ Display a folder
1069:
1070: sub disfolder {
1071: my ($r,$folder,$msgstatus)=@_;
1072: my %statushash = &get_msgstatus_types();
1073: my %blocked = ();
1074: my %setters = ();
1075: my $numblocked = 0;
1076: my $clientip = &Apache::lonnet::get_requestor_ip($r);
1077: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
1078: &Apache::loncommon::blockcheck(\%setters,'com',$clientip);
1079: my %js_lt = &Apache::lonlocal::texthash(
1080: sede => 'Select a destination folder to which the messages will be moved.',
1081: nome => 'No messages have been selected to apply this action to.',
1082: chec => 'Check the checkbox for at least one message.',
1083: );
1084: &js_escape(\%js_lt);
1085: my $jscript = &Apache::loncommon::check_uncheck_jscript();
1086: $r->print(<<ENDDISHEADER);
1087: <script type="text/javascript">
1088: // <![CDATA[
1089: $jscript
1090:
1091: function validate_checkedaction() {
1092: document.disall.markedaction.value = document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value;
1093: if (document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value == 'markedmove') {
1094: if (document.disall.movetofolder.options[document.disall.movetofolder.selectedIndex].value == "") {
1095: alert("$js_lt{'sede'}");
1096: return;
1097: }
1098: }
1099: var checktotal = 0;
1100: if (document.forms.disall.delmark.length > 0) {
1101: for (var i=0; i<document.forms.disall.delmark.length; i++) {
1102: if (document.forms.disall.delmark[i].checked) {
1103: checktotal ++;
1104: }
1105: }
1106: } else {
1107: if (document.forms.disall.delmark.checked) {
1108: checktotal ++;
1109: }
1110: }
1111: if (checktotal == 0) {
1112: alert("$js_lt{'nome'}\\n$js_lt{'chec'}");
1113: return;
1114: }
1115: document.disall.submit();
1116: }
1117: // ]]>
1118: </script>
1119: ENDDISHEADER
1120:
1121: my $fsqs='&folder='.$folder;
1122: my @temp=&sortedmessages(\%blocked,$startblock,$endblock,$by_ip,\$numblocked,$folder,$msgstatus);
1123: my $totalnumber=$#temp+1;
1124: if ($totalnumber < 1) {
1125: $r->print('<p class="LC_info">');
1126: if ($msgstatus eq '') {
1127: $r->print(&mt('There are no messages in this folder.'));
1128: } elsif ($msgstatus eq 'replied') {
1129: $r->print(&mt('You have not replied to any messages in this folder.'));
1130: } else {
1131: $r->print(&mt('There are no '.lc($statushash{$msgstatus}).' messages in this folder.'));
1132: }
1133: $r->print('</p>');
1134: if ($numblocked > 0) {
1135: $r->print(&blocked_in_folder($numblocked,$startblock,$endblock,$by_ip,$clientip,$blockdom,
1136: \%setters));
1137: }
1138: return;
1139: }
1140: my $interdis = $env{'form.interdis'};
1141: my $number=int($totalnumber/$interdis);
1142: if ($totalnumber%$interdis == 0) {
1143: $number--;
1144: }
1145:
1146: if (($startdis<0) || ($startdis>$number)) { $startdis=$number; }
1147: my $firstdis=$interdis*$startdis;
1148: if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; }
1149: my $lastdis=$firstdis+$interdis-1;
1150: if ($lastdis>$#temp) { $lastdis=$#temp; }
1151: $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber,$msgstatus));
1152: $r->print('<form method="post" name="disall" action="/adm/email">'.
1153: &Apache::loncommon::start_data_table().
1154: &Apache::loncommon::start_data_table_row().
1155: '<th colspan="1"> </th><th>');
1156: if ($env{'form.sortedby'} eq "revdate") {
1157: $r->print('<a href = "/adm/email?sortedby=date'.$fsqs.'">'.&mt('Date').'</a></th>');
1158: } else {
1159: $r->print('<a href = "/adm/email?sortedby=revdate'.$fsqs.'">'.&mt('Date').'</a></th>');
1160: }
1161: $r->print('<th>');
1162: if ($env{'form.sortedby'} eq "revuser") {
1163: $r->print('<a href = "/adm/email?sortedby=user'.$fsqs.'">'.&mt('Username').'</a>');
1164: } else {
1165: $r->print('<a href = "/adm/email?sortedby=revuser'.$fsqs.'">'.&mt('Username').'</a>');
1166: }
1167: $r->print('</th><th>');
1168: if ($env{'form.sortedby'} eq "revdomain") {
1169: $r->print('<a href = "/adm/email?sortedby=domain'.$fsqs.'">'.&mt('Domain').'</a>');
1170: } else {
1171: $r->print('<a href = "/adm/email?sortedby=revdomain'.$fsqs.'">'.&mt('Domain').'</a>');
1172: }
1173: $r->print('</th><th>');
1174: if ($env{'form.sortedby'} eq "revsubject") {
1175: $r->print('<a href = "/adm/email?sortedby=subject'.$fsqs.'">'.&mt('Subject').'</a>');
1176: } else {
1177: $r->print('<a href = "/adm/email?sortedby=revsubject'.$fsqs.'">'.&mt('Subject').'</a>');
1178: }
1179: $r->print('</th><th>');
1180: if ($env{'form.sortedby'} eq "revcourse") {
1181: $r->print('<a href = "/adm/email?sortedby=course'.$fsqs.'">'.&mt('Course').'</a>');
1182: } else {
1183: $r->print('<a href = "/adm/email?sortedby=revcourse'.$fsqs.'">'.&mt('Course').'</a>');
1184: }
1185: $r->print('</th><th colspan="2">');
1186: if ($env{'form.sortedby'} eq "revstatus") {
1187: $r->print('<a href = "/adm/email?sortedby=status'.$fsqs.'">'.&mt('Status').'</a></th>');
1188: } else {
1189: $r->print('<a href = "/adm/email?sortedby=revstatus'.$fsqs.'">'.&mt('Status').'</a></th>');
1190: }
1191: $r->print("</tr>\n");
1192:
1193: my $suffix = &Apache::lonmsg::foldersuffix($folder);
1194: my $count = $firstdis;
1195: for (my $n=$firstdis;$n<=$lastdis;$n++) {
1196: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,
1197: $description,$recv_name,$recv_domain)=
1198: @{$temp[$n]};
1199: if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
1200: my $class_msgstatus = '';
1201: $count ++;
1202: if ($status eq 'new') {
1203: $class_msgstatus = 'LC_mail_new';
1204: } elsif ($status eq 'read') {
1205: $class_msgstatus = 'LC_mail_read';
1206: } elsif ($status eq 'replied') {
1207: $class_msgstatus = 'LC_mail_replied';
1208: } else {
1209: $class_msgstatus = 'LC_mail_other';
1210: }
1211: $r->print(&Apache::loncommon::start_data_table_row($class_msgstatus));
1212: my ($dis_name,$dis_domain) = ($fromname,$fromdomain);
1213: if ($folder eq 'sent') {
1214: if (defined($recv_name) && defined($recv_domain)) {
1215: if (ref($recv_name) eq 'ARRAY' &&
1216: ref($recv_domain) eq 'ARRAY') {
1217: $dis_name = join('<br />',@{$recv_name});
1218: $dis_domain = join('<br />',@{$recv_domain});
1219: }
1220: } else {
1221: my $msg_id = &unescape($origID);
1222: my %message = &Apache::lonnet::get('nohist_email'.$suffix,
1223: [$msg_id]);
1224: my %content = &Apache::lonmsg::unpackagemsg($message{$msg_id});
1225: if (ref($content{'recuser'}) eq 'ARRAY') {
1226: $dis_name = join('<br />',@{$content{'recuser'}});
1227: }
1228: if (ref($content{'recdomain'}) eq 'ARRAY') {
1229: $dis_domain = join('<br />',@{$content{'recdomain'}});
1230: }
1231: }
1232: }
1233: my $localsenttime = &Apache::lonlocal::locallocaltime($sendtime);
1234: $r->print('<td align="right"><span class="LC_nobreak">'.(($status eq 'new')?'<b>':'').
1235: $count.'.'.(($status eq 'new')?'</b>':'').' '.
1236: '<input type="checkbox" name="delmark"'.
1237: ' value="'.$origID.'" /></span></td>');
1238: foreach my $item ($localsenttime,$dis_name,$dis_domain,$shortsubj) {
1239: $r->print('<td>'.(($status eq 'new')?'<b>':'').
1240: '<a href="/adm/email?display='.$origID.$sqs.'">'.
1241: $item.'</a>'.(($status eq 'new')?'</b>':'').'</td>');
1242: }
1243: # Description and Status
1244: my $showstatus;
1245: my %statushash = &get_msgstatus_types();
1246: if ($status eq '') {
1247: $showstatus = '';
1248: } else {
1249: $showstatus = $statushash{$status};
1250: }
1251: $r->print('<td>'.(($status eq 'new')?'<b>':'').$description.
1252: (($status eq 'new')?'</b>':'').
1253: '</td>');
1254: $r->print('<td class="'.$class_msgstatus.'"> </td>'.
1255: '<td>'.
1256: (($status eq 'new')?'<b>':'').&mt($showstatus).
1257: (($status eq 'new')?'</b>':'').
1258: '</td>');
1259:
1260: $r->print(&Apache::loncommon::end_data_table_row());
1261:
1262: } elsif ($status eq 'deleted') {
1263: # purge
1264: my ($result,$msg) =
1265: &movemsg(&unescape($origID),$folder,'trash');
1266: }
1267: }
1268: $r->print(&Apache::loncommon::end_data_table());
1269:
1270:
1271: # Bottom Functions
1272: $r->print('
1273: <div class="LC_columnSection"><fieldset>
1274: <legend>'.&mt('Message Actions').'</legend>
1275: <table border="0" cellspacing="2" cellpadding="8">
1276: <tr>
1277: <td><b>'.&mt('Select Messages').'</b><br />
1278: <span class="LC_nobreak">
1279: <input type="button" onclick="javascript:checkAll(document.disall.delmark)" value="'.&mt('Check All').'" />'."\n".
1280: ' <input type="button" onclick="javascript:uncheckAll(document.disall.delmark)" value="'.&mt('Uncheck All').'" />'."\n".
1281: '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" />
1282: </span>
1283: </td>'."\n".
1284: '<td><b>'.&mt('Action').'</b><br />'."\n".
1285: ' <select name="checkedaction">'."\n");
1286:
1287: if ($folder ne 'trash') {
1288: $r->print(' <option value="markeddel">'.&mt('Delete').'</option>'."\n");
1289: }
1290: if ($msgstatus ne 'read') {
1291: $r->print(' <option value="markedread">'.&mt('Mark Read').'</option>'."\n");
1292: }
1293: if ($msgstatus ne 'unread') {
1294: $r->print(' <option value="markedunread">'.&mt('Mark Unread').'</option>'."\n");
1295: }
1296: $r->print(' <option value="markedforward">'.&mt('Forward').'</option>'."\n");
1297:
1298: my %gotfolders = &Apache::lonmsg::get_user_folders();
1299: if (keys(%gotfolders) > 0) {
1300: $r->print(' <option value="markedmove">'.&mt('Move to Folder ->').
1301: '</option>');
1302: }
1303: $r->print("\n".'</select></td>'."\n");
1304:
1305: if (keys(%gotfolders) > 0) {
1306: $r->print('<td><b>'.&mt('Destination folder').'</b><br />');
1307: my %userfolders;
1308: foreach my $key (keys(%gotfolders)) {
1309: $userfolders{$key} = $key;
1310: }
1311: $userfolders{''} = "";
1312: $r->print(&Apache::loncommon::select_form('','movetofolder',\%userfolders).
1313: '</td>');
1314: }
1315: $r->print('<td style="vertical-align:bottom;">'.
1316: '<input type="button" name="go" value="'.&mt('Go').
1317: '" onclick="javascript:validate_checkedaction()"/></td>'."\n".
1318: '</tr></table>'."\n".
1319: '</fieldset></div>'."\n"
1320: );
1321: my $postedstartdis=$startdis+1;
1322: $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>');
1323: if ($numblocked > 0) {
1324: $r->print(&blocked_in_folder($numblocked,$startblock,$endblock,
1325: $by_ip,$clientip,$blockdom,\%setters));
1326: }
1327: }
1328:
1329: sub blocked_in_folder {
1330: my ($numblocked,$startblock,$endblock,$by_ip,$clientip,$blockdom,$setters) = @_;
1331: my $output;
1332: if ($by_ip) {
1333: $output = '<br /><br />'.
1334: &mt('[quant,_1,message is, messages are] not viewable because display of LON-CAPA messages is blocked for your current IP address: [_2].',$numblocked,$clientip).'<br />'.
1335: &mt('Note: communication is being blocked for certain IP address(es).');
1336: } else {
1337: my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
1338: my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
1339: $output = '<br /><br />'.
1340: &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);
1341: }
1342: #$output .= &Apache::loncommon::build_block_table($startblock,$endblock,
1343: # $setters);
1344: my ($blocked, $blocktext) = &Apache::loncommon::blocking_status("com",$clientip);
1345: $output .="<br /><br />".$blocktext;
1346:
1347: return $output;
1348: }
1349:
1350: # ============================================================== Compose output
1351:
1352: sub compout {
1353: my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode,
1354: $multiforward)=@_;
1355: my $clientip = &Apache::lonnet::get_requestor_ip($r);
1356: my %setters;
1357: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
1358: &Apache::loncommon::blockcheck(\%setters,'com',$clientip);
1359: if ($by_ip) {
1360: my $showdom = &Apache::lonnet::domain($blockdom);
1361: if ($showdom eq '') {
1362: $showdom = $blockdom;
1363: }
1364: $r->print(&Apache::loncommon::start_page('Messages'));
1365: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Send and display messages'));
1366: $r->print('<p class="LC_warning">'.
1367: &mt('Sending of LON-CAPA messages is blocked for your current IP address: [_1].',$clientip).'</p>'.
1368: '<ul><li>'.
1369: &mt('Note: communication is being blocked for certain IP address(es).').
1370: '</li><li>'.
1371: &mt('This restriction was set by an administrator in the [_1] LON-CAPA domain.',$showdom).
1372: '</li></ul>');
1373: return;
1374: }
1375: my $suffix=&Apache::lonmsg::foldersuffix($folder);
1376: my ($cdom,$cnum,$group,$refarg);
1377: if (exists($env{'form.group'})) {
1378: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1379: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1380: $group = $env{'form.group'};
1381: my $action = 'composing';
1382: $r->print(&groupmail_header($action,$group,$cdom,$cnum));
1383: } elsif ($broadcast eq 'individual') {
1384: &printheader($r,'/adm/email?compose=individual',
1385: 'Send a Message');
1386: } elsif ($broadcast) {
1387: &printheader($r,'/adm/email?compose=group',
1388: 'Broadcast Message');
1389: } elsif ($forwarding) {
1390: &Apache::lonhtmlcommon::add_breadcrumb
1391: ({href=>"/adm/email?display=".&escape($forwarding),
1392: text=>"Display Message"});
1393: &printheader($r,'/adm/email?forward='.&escape($forwarding),
1394: 'Forwarding a Message');
1395: } elsif ($replying) {
1396: &Apache::lonhtmlcommon::add_breadcrumb
1397: ({href=>"/adm/email?display=".&escape($replying),
1398: text=>"Display Message"});
1399: &printheader($r,'/adm/email?replyto='.&escape($replying),
1400: 'Replying to a Message');
1401: } elsif ($replycrit) {
1402: $r->print('<h3>'.&mt('Replying to a Critical Message').'</h3>');
1403: $replying=$replycrit;
1404: } elsif ($multiforward) {
1405: &Apache::lonhtmlcommon::add_breadcrumb
1406: ({href=>"/adm/email?folder=".&escape($folder),
1407: text=>"Display All Messages"});
1408: &printheader($r,'/adm/email?compose=multiforward',
1409: 'Forwarding Multiple Messages');
1410: if ($multiforward > 1) {
1411: $r->print(&mt('Each of the[_1] [quant,_2,message] [_3]you checked'
1412: .' will be forwarded to the recipient(s) you select below.'
1413: ,'<b>',$multiforward,'</b>')
1414: .'<br />');
1415: } else {
1416: $r->print(&mt('The message you checked will be forwarded to the recipient(s) you select below.').'<br />');
1417: }
1418:
1419: } else {
1420: &printheader($r,'/adm/email?compose=upload',
1421: 'Distribute from Uploaded File');
1422: }
1423:
1424: my $dispcrit='';
1425: my $dissub='';
1426: my $dismsg='';
1427: my $disbase='';
1428: my $attachrow;
1429: my $func1='Send'; # do not translate here!
1430: my %func2=( # do not translate here!
1431: 'ma' => 'Message',
1432: 'msg' => 'Messages',
1433: );
1434: my %lt=&Apache::lonlocal::texthash('us' => 'Username',
1435: 'do' => 'Domain',
1436: 'ad' => 'Additional Recipients',
1437: 'rt' => 'Reply to',
1438: 'ar' => 'Allow replies',
1439: 'sb' => 'Subject',
1440: 'ca' => 'Cancel',
1441: 'gen' => 'Generate messages from a file',
1442: 'gmt' => 'General message text',
1443: 'tff' => 'The file format for the uploaded portion of the message is',
1444: 'uas' => 'Upload and Send',
1445: 'atta' => 'Attachment',
1446: 'to' => 'To:',
1447: );
1448: my %attachmax = (
1449: text => &mt('(1 MB max size)'),
1450: num => 1048576,
1451: );
1452: if (!$forwarding && !$multiforward) {
1453: $attachrow = '<tr><td colspan="3"><b>'.$lt{'atta'}.'</b> '.$attachmax{'text'}
1454: .': <input type="file" name="attachment" class="LC_flUpload" />'
1455: .'<input type="hidden" id="LC_free_space" value="'.$attachmax{'num'}.'" />'
1456: .'</td></tr>';
1457: }
1458: if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
1459: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
1460: '/'.$env{'request.course.sec'})) {
1461: my $crstype = &Apache::loncommon::course_type();
1462: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1463: my $rsstxt;
1464: if (&Apache::loncommon::course_type() eq 'Community') {
1465: $rsstxt = &mt('Include in community RSS newsfeed');
1466: } else {
1467: $rsstxt = &mt('Include in course RSS newsfeed');
1468: }
1469: $dispcrit=
1470: '<span class="LC_nobreak"><label><input type="checkbox" name="critmsg" /> '.&mt('Send as critical message').'.</label>'.$crithelp.' '.&mt('Require return receipt?').'<label><input type="radio" name="sendbck" value="1" />'.&mt('Yes').'</label> <label><input type="radio" name="sendbck" value="" checked="checked" />'.&mt('No').'</label></span><br />'.
1471: '<label><input type="checkbox" name="permanent" /> '.
1472: &mt('Send copy to permanent e-mail address (if known)').'</label><br />'.
1473: '<label><input type="checkbox" name="rsspost" /> '.
1474: $rsstxt.'</label><br />';
1475: }
1476: if ($broadcast ne 'group') {
1477: if (&Apache::lonnet::allowed('dff',$env{'request.course.id'}) ||
1478: &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1479: '/'.$env{'request.course.sec'})) {
1480:
1481: my $rectxt;
1482: if (&Apache::loncommon::course_type() eq 'Community') {
1483: $rectxt = &mt("Include in community's 'User records' for recipient(s)");
1484: } else {
1485: $rectxt = &mt("Include in course's 'User records' for recipient(s)");
1486: }
1487:
1488: $dispcrit.='<label>'.
1489: '<input type="checkbox" name="courserecord" value="1" /> '.
1490: $rectxt.
1491: '</label><br />';
1492: }
1493: }
1494:
1495: my %message;
1496: my %content;
1497: my ($hasfloat,$broadcast_js,$sendmode,$can_grp_broadcast);
1498: my $defdom=$env{'user.domain'};
1499: if ($broadcast eq 'group') {
1500: my %access_status = (
1501: active => 0,
1502: previous => 0,
1503: future => 0,
1504: );
1505:
1506: if ($group eq '') {
1507: my $studentsel = &discourse(\%access_status);
1508: if ($studentsel) {
1509: $r->print('<div class="LC_left_float">'.$studentsel.'</div>');
1510: $hasfloat = 1;
1511: }
1512: } else {
1513: $can_grp_broadcast = &check_group_priv($group);
1514: if ($can_grp_broadcast) {
1515: $hasfloat = &disgroup($r,$cdom,$cnum,$group,\%access_status);
1516: }
1517: }
1518: if ($hasfloat) {
1519: $sendmode = '<input type="hidden" name="sendmode" value="group" />'."\n";
1520: $broadcast_js = qq|
1521: <script type="text/javascript">
1522: // <![CDATA[
1523: function courseRecipients() {
1524: |;
1525: foreach my $type (keys(%access_status)) {
1526: if ($access_status{$type}) {
1527: my $formname = $type.'users';
1528: if ($type eq 'active' && $group ne '') {
1529: $broadcast_js .= qq|
1530: document.compemail.groupmail.value = document.$formname.groupmail[document.$formname.groupmail.selectedIndex].value;
1531: |;
1532: }
1533: #typeof(...forminput.length) returns 'undefined' if only one entry exists
1534: $broadcast_js .= qq|
1535: if (typeof(document.$formname.selectedusers_forminput.length)=="undefined") {
1536: if (document.$formname.selectedusers_forminput.checked) {
1537: document.compemail.courserecips.value += '_&&&_'+document.$formname.selectedusers_forminput.value;
1538: }
1539: } else {
1540: for (var i=0; i<document.$formname.selectedusers_forminput.length; i++) {
1541: if (document.$formname.selectedusers_forminput[i].checked) {
1542: document.compemail.courserecips.value += '_&&&_'+document.$formname.selectedusers_forminput[i].value;
1543: }
1544: }
1545: }
1546: |;
1547: }
1548: }
1549: $broadcast_js .= qq|
1550: return;
1551: }
1552: // ]]>
1553: </script>
1554:
1555: |;
1556: }
1557: }
1558: if ($forwarding) {
1559: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]);
1560: %content=&Apache::lonmsg::unpackagemsg($message{$forwarding},$folder);
1561: $dispcrit.='<input type="hidden" name="forwid" value="'.
1562: $forwarding.'" />';
1563: $func1='Forward'; # do not translate here!
1564:
1565: $dissub=&mt('Forwarding').': '.$content{'subject'};
1566: $dismsg=&mt('Forwarded message from').' '.
1567: $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
1568: if ($content{'baseurl'}) {
1569: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1570: }
1571: }
1572: if ($replying) {
1573: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
1574: %content=&Apache::lonmsg::unpackagemsg($message{$replying},$folder);
1575: $dispcrit.='<input type="hidden" name="replyid" value="'.
1576: $replying.'" />';
1577: $func1='Send Reply to'; # do not translate here!
1578:
1579: $dissub=&mt('Reply').': '.$content{'subject'};
1580: $dismsg='> '.$content{'message'};
1581: $dismsg=~s/\r/\n/g;
1582: $dismsg=~s/\f/\n/g;
1583: $dismsg=~s/\n+/\n\> /g;
1584: if ($content{'baseurl'}) {
1585: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1586: if ($env{'user.adv'}) {
1587: $disbase.='<label><input type="checkbox" name="storebasecomment" />'.&mt('Save message for re-use').
1588: '</label> <a href="/adm/email?showcommentbaseurl='.
1589: &escape($content{'baseurl'}).'" target="comments">'.
1590: &mt('Show re-usable messages').'</a><br />';
1591: }
1592: }
1593: my $jscript = &Apache::loncommon::check_uncheck_jscript();
1594: $r->print(<<"ENDREPSCRIPT");
1595: <script type="text/javascript">
1596: // <![CDATA[
1597: $jscript
1598: // ]]>
1599: </script>
1600: ENDREPSCRIPT
1601: }
1602: my $citation=&displayresource(%content);
1603: my $onsubmit;
1604: if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
1605: if ($env{'form.text'}) { $dismsg=$env{'form.text'}; }
1606: if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; }
1607: if ($hasfloat) {
1608: $r->print($broadcast_js.'<div class="LC_left_float">');
1609: $onsubmit = ' onsubmit="javascript:courseRecipients();" ';
1610: }
1611: $r->print(
1612: '<form action="/adm/email" name="compemail" method="post"'.
1613: ' enctype="multipart/form-data"'.$onsubmit.'>'."\n".
1614: '<input type="hidden" name="sendmail" value="on" />'."\n".
1615: '<table>');
1616: if (($broadcast eq 'group') && ($group ne '') && (!$can_grp_broadcast)) {
1617: $r->print(&recipient_input_row($cdom,%lt));
1618: }
1619: if (($broadcast ne 'group') && ($broadcast ne 'upload')) {
1620: if ($replying) {
1621: if ($content{'noreplies'}) {
1622: $r->print('<tr><td>'.&mt('This message was designated by the sender not to allow replies.').'</td></tr></table></form>');
1623: return;
1624: }
1625: $r->print('<tr><td colspan="3"><b>'.&mt('Replying to').'</b> ');
1626: if ($content{'replytoaddr'}) {
1627: my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
1628: if ($replytoname ne '' && $replytodom ne '') {
1629: $r->print(&Apache::loncommon::plainname($replytoname,
1630: $replytodom).' ('.$replytoname.':'.
1631: $replytodom.')');
1632: $r->print('<input type="hidden" name="recuname" value="'.
1633: $replytoname.'" />'.
1634: '<input type="hidden" name="recdomain" value="'.
1635: $replytodom.'" /></td></tr>');
1636:
1637: } else {
1638: $r->print(&mt('The sender did not designate a reply to address for this message.').'</td></tr></table>');
1639: return;
1640: }
1641: } else {
1642: $r->print(&Apache::loncommon::aboutmewrapper(
1643: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
1644: $content{'sendername'}.':'.
1645: $content{'senderdomain'}.')');
1646: $r->print('<input type="hidden" name="recuname" value="'.
1647: $content{'sendername'}.'" />'.
1648: '<input type="hidden" name="recdomain" value="'.
1649: $content{'senderdomain'}.'" /></td></tr>');
1650: }
1651: if ($content{'recipid'}) {
1652: my %recips;
1653: &retrieve_recips('replying',\%content,\%recips);
1654: if (ref($recips{'to'}) eq 'ARRAY') {
1655: if (@{$recips{'to'}} > 0) {
1656: my $replyall;
1657: if (@{$recips{'to'}} > 1) {
1658: $replyall = qq|
1659: <span class="LC_nobreak">
1660: <input type="button" value="check all"
1661: onclick="javascript:checkAll(document.compemail.replying_to)" />
1662:
1663: <input type="button" value="uncheck all"
1664: onclick="javascript:uncheckAll(document.compemail.replying_to)" />
1665: </span>
1666: |;
1667: }
1668: my $tolist = join(' ',@{$recips{'to'}});
1669: $r->print('<tr><td colspan="3"><table><tr><td>'.&mt('[_1]Send reply[_2] to other recipients','<b>','</b>').':<br />'.$replyall.'</td><td>'.$tolist.'</td></tr></table></td></tr>');
1670: }
1671: }
1672: if (ref($recips{'cc'}) eq 'ARRAY') {
1673: if (@{$recips{'cc'}} > 0) {
1674: my $replyall;
1675: if (@{$recips{'cc'}} > 1) {
1676: $replyall = qq|
1677: <span class="LC_nobreak">
1678: <input type="button" value="check all"
1679: onclick="javascript:checkAll(document.compemail.replying_cc)" />
1680:
1681: <input type="button" value="uncheck all"
1682: onclick="javascript:uncheckAll(document.compemail.replying_cc)" />
1683: </span>
1684: |;
1685: }
1686: my $cclist = join(' ',@{$recips{'cc'}});
1687: $r->print('<tr><td colspan="3"><table><tr><td>'.&mt('[_1]Cc[_2] to other copied recipients','<b>','</b>').':<br />'.$replyall.'</td><td>'.$cclist.'</td></tr></table></td></tr>');
1688: }
1689: }
1690: if ($content{'group'} ne '') {
1691: if (&check_group_priv($content{'group'})) {
1692: if (ref($recips{'group_cc_broadcast'}) eq 'ARRAY') {
1693: if (@{$recips{'group_cc_broadcast'}} > 0) {
1694: my $replyall;
1695: if (@{$recips{'group_cc_broadcast'}} > 1) {
1696: $replyall = qq|
1697: <span class="LC_nobreak">
1698: <input type="button" value="check all"
1699: onclick="javascript:checkAll(document.compemail.replying_groupcc)" />
1700:
1701: <input type="button" value="uncheck all"
1702: onclick="javascript:uncheckAll(document.compemail.replying_groupcc)" />
1703: </span>
1704: |;
1705: }
1706: my $groupcclist = join(' ',@{$recips{'group_cc_broadcast'}});
1707: $r->print('<tr><td colspan="3"><table><tr><td>'.&mt('[_1]Cc[_2] to other copied group members','<b>','</b>').':<br />'.$replyall.'</td><td>'.$groupcclist.'<input type="hidden" name="group" value="'.$content{'group'}.'" /><input type="hidden" name="sendmode" value="group" /><input type="hidden" name="groupmail" value="cc" /></td></tr></table></td></tr>');
1708: }
1709: }
1710: }
1711: }
1712: }
1713: } else {
1714: $r->print(&recipient_input_row($defdom,%lt));
1715: }
1716: }
1717: my $latexHelp = &Apache::loncommon::helpLatexCheatsheet(undef,undef,1);
1718: my $textareaclass;
1719: if (&Apache::lonhtmlcommon::htmlareabrowser()) {
1720: $r->print(&Apache::lonhtmlcommon::htmlareaselectactive());
1721: $textareaclass = 'class="LC_richDefaultOff"';
1722: }
1723: my $subj_size;
1724: if ($multiforward) {
1725: $r->print(&additional_rec_row(\%lt));
1726: $r->print('<tr><td colspan="2">'.
1727: &mt('Unless you choose otherwise:').'<ul><li>'.
1728: &mt("The subject in each forwarded message will be [_1]'Forwarding:'[_2] followed by the original subject.",'<i>','</i>').'</li><li>'.
1729: &mt("The message itself will begin with a first line: [_1]'Forwarded message from'[_2] followed by the original sender's name.",'<i>','</i>').'</li></ul></td></tr>');
1730: $func1='Forward'; # do not translate here!
1731: $dissub = &mt('Forwarding').': ';
1732: $subj_size = '10';
1733: my $extra = '<'.&mt('original subject').'> '.
1734: '<input type="radio" name="showorigsubj" value="1" checked="checked" />'.&mt('Yes').' <input type="radio" name="showorigsubj" value="0" />'.&mt('No');
1735: $dismsg = &mt('Forwarded message from ').' ';
1736: my $sender = &mt("sender's name");
1737: $r->print(&msg_subject_row($dissub,\%lt,$subj_size,$extra));
1738: $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>
1739: </table>
1740: <br /><table>
1741: <tr><td align="left">'."\n".
1742: $latexHelp."<br />\n".
1743: &mt("Any new text to display before the text of the original messages:").'<br />'."\n".
1744: '<textarea name="message" id="message" cols="80" rows="5" wrap="hard" $textareaclass></textarea>');
1745: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
1746: foreach my $msg (@to_forward) {
1747: $r->print('<input type="hidden" name="delmark" value="'.$msg.'" />');
1748: }
1749: $r->print(&submit_button_row($folder,$dismode,&mt($func1.' '.$func2{'msg'}),
1750: \%lt));
1751: } elsif ($broadcast ne 'upload') {
1752: $subj_size = '50';
1753: $r->print(&additional_rec_row(\%lt));
1754: if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
1755: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
1756: '/'.$env{'request.course.sec'})) {
1757: $r->print(&reply_to_row(\%lt));
1758: }
1759: $r->print(&msg_subject_row($dissub,\%lt,$subj_size));
1760: $r->print(<<"ENDCOMP");
1761: $attachrow
1762: </table><br />
1763: $latexHelp<br />
1764: <textarea name="message" id="message" cols="80" rows="15" wrap="hard" $textareaclass>$dismsg
1765: </textarea>
1766: <br />
1767: $sendmode
1768: $dispcrit
1769: $disbase
1770: ENDCOMP
1771: $r->print(&submit_button_row($folder,$dismode,&mt($func1.' '.$func2{'ma'}),
1772: \%lt,$hasfloat,$group));
1773: $r->print($citation);
1774: if (exists($env{'form.ref'})) {
1775: $r->print('<input type="hidden" name="ref" value="'.
1776: $env{'form.ref'}.'" />');
1777: }
1778: if (exists($env{'form.group'})) {
1779: $r->print('<input type="hidden" name="group" value="'.
1780: $env{'form.group'}.'" />');
1781: }
1782: } else { # $broadcast is 'upload'
1783: $r->print(<<ENDBLOCK);
1784: <input type="hidden" name="sendmode" value="upload" />
1785: <input type="hidden" name="send" value="on" />
1786: <h3>$lt{'gen'}</h3>
1787: <p>
1788: Subject: <input type="text" size="50" name="subject" />
1789: </p>
1790: <p>$lt{'gmt'}:<br />
1791: <textarea name="message" id="message" cols="60" rows="10" wrap="hard" $textareaclass>$dismsg
1792: </textarea></p>
1793: <p>
1794: $lt{'tff'}:
1795: ENDBLOCK
1796: $r->print('
1797: <pre>'."\n".
1798: &mt('username1:domain1: text')."\n".
1799: &mt('username2:domain2: text')."\n".
1800: &mt('username3:domain1: text')."\n".
1801: '</pre>
1802: </p>
1803: <p>
1804: '.&mt('The messages will be assembled from all lines with the respective [_1][_2]username:domain[_3], and appended to the general message text.','<br />','<tt>','</tt>'));
1805: $r->print(<<ENDUPLOAD);
1806: </p>
1807: <p>
1808: <input type="file" name="upfile" size="40" /></p><p>
1809: $dispcrit
1810: <input type="submit" value="$lt{'uas'}" /></p>
1811: ENDUPLOAD
1812: }
1813: if ($env{'form.displayedcrit'}) {
1814: $r->print('<input type="hidden" name="displayedcrit" value="true" />');
1815: }
1816: $r->print('</form>');
1817: if ($hasfloat) {
1818: $r->print('</div><div class="LC_clear_float_footer"></div>');
1819: }
1820: $r->print(&generate_preview_form);
1821: }
1822:
1823: sub check_group_priv {
1824: my ($group) = @_;
1825: my $cid = $env{'request.course.id'};
1826: my $sec = $env{'request.course.sec'};
1827: return if !$cid;
1828: my $can_broadcast = &Apache::lonnet::allowed('sgb',$cid.'/'.$group);
1829: my $viewgrps = &Apache::lonnet::allowed('vcg',$cid.($sec?'/'.$sec:''));
1830: my $editgrps = &Apache::lonnet::allowed('mdg',$cid.($sec?'/'.$sec:''));
1831: if ($viewgrps || $editgrps || $can_broadcast) {
1832: return 1;
1833: }
1834: return;
1835: }
1836:
1837: sub recipient_input_row {
1838: my ($dom,%lt) = @_;
1839: my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain');
1840: my $selectlink=
1841: &Apache::loncommon::selectstudent_link('compemail','recuname',
1842: 'recdomain');
1843: my $output = <<"ENDREC";
1844: <tr><td colspan="3"><span class="LC_nobreak"><b>$lt{'to'}</b> $lt{'us'}: <input type="text" size="12" name="recuname" value="$env{'form.recname'}" /> $lt{'do'}: $domform $selectlink</span></td></tr>
1845: ENDREC
1846: return $output;
1847: }
1848:
1849: sub reply_to_row {
1850: my ($lt) = @_;
1851: my $radioyes = &mt('Yes');
1852: my $radiono = &mt('No');
1853: my $output = <<"ENDREP";
1854: <tr><td colspan="3"><span class="LC_nobreak"><b>$lt->{'ar'}</b>:<label><input type="radio" name="can_reply" value="Y" checked="checked" />$radioyes</label> <label><input type="radio" name="can_reply" value="N" />$radiono</label></span> <span class="LC_nobreak">$lt->{'rt'}: <input type="text" size="25" name="reply_to_addr" value="$env{'user.name'}:$env{'user.domain'}" /></span></td></tr>
1855: ENDREP
1856: return $output;
1857: }
1858:
1859: sub additional_rec_row {
1860: my ($lt) = @_;
1861: my $cc = &mt('Cc:');
1862: my $bcc = &mt('Bcc:');
1863: my $exmpl = &mt('username:domain,username:domain,...');
1864: my $output = <<"ENDADD";
1865: <tr><td colspan="3"><fieldset id="LC_additionalrecips"><legend>$lt->{'ad'} <tt>($exmpl)</tt></legend><table>
1866: <tr><td> </td><td>$lt->{'to'}</td><td><input type="text" size="50" name="additionalrec_to" /></td></tr>
1867: <tr><td> </td><td>$cc</td><td><input type="text" size="50" name="additionalrec_cc" /></td></tr>
1868: <tr><td> </td><td>$bcc</td><td><input type="text" size="50" name="additionalrec_bcc" /></td></tr></table></fieldset></td></tr>
1869: ENDADD
1870: return $output;
1871: }
1872:
1873: sub submit_button_row {
1874: my ($folder,$dismode,$sendtext,$lt,$is_crsform,$group) = @_;
1875: my $pre=&mt("Show Preview and Check Spelling");
1876: my $value=&mt('Send');
1877: my $prevbutton = '<input type="button" name="preview" value="'.$pre.'" onclick="if (typeof(document.compemail.onsubmit)=='."'function'".') {document.compemail.onsubmit();};document.preview.comment.value=document.compemail.message.value;document.preview.subject.value=document.compemail.subject.value;document.preview.submit();" />';
1878: my $output = qq|
1879: <input type="hidden" name="folder" value="$folder" />
1880: <input type="hidden" name="dismode" value="$dismode" />|;
1881: if ($is_crsform) {
1882: $output .= '<input type="hidden" name="courserecips" value="" />'."\n";
1883: if ($group ne '') {
1884: $output .= '<input type="hidden" name="groupmail" value="" />'."\n";
1885: }
1886: }
1887: $output .= qq|
1888: <table><tr><td align="left">
1889: <input type="submit" name="send" value="$value" title="$sendtext" />
1890: <input type="submit" name="cancel" value="$lt->{'ca'}" />
1891: </td><td width="60"> </td><td align="right">$prevbutton</td></tr></table>
1892: |;
1893: return $output;
1894: }
1895:
1896: sub msg_subject_row {
1897: my ($dissub,$lt,$subj_size,$extra) = @_;
1898: my $output = '<tr><td colspan="3"><b>'.$lt->{'sb'}.'</b>: <input type="text" size="'.
1899: $subj_size.'" name="subject" value="'.$dissub.'" />'.$extra.
1900: '</td></tr>';
1901: return $output;
1902: }
1903:
1904: sub generate_preview_form {
1905: my $prevbutton = (<<ENDPREVIEW);
1906: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1907: <input type="hidden" name="subject" />
1908: <input type="hidden" name="comment" />
1909: </form>
1910: ENDPREVIEW
1911: }
1912:
1913: # ---------------------------------------------------- Display all face to face
1914:
1915: sub retrieve_instructor_comments {
1916: my ($user,$domain)=@_;
1917: my $target=$env{'form.grade_target'};
1918: if (! $env{'request.course.id'}) { return; }
1919: if (! &Apache::lonnet::allowed('dff',$env{'request.course.id'})
1920: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1921: '/'.$env{'request.course.sec'})) {
1922: return;
1923: }
1924: my %records=&Apache::lonnet::dump('nohist_email',
1925: $env{'course.'.$env{'request.course.id'}.'.domain'},
1926: $env{'course.'.$env{'request.course.id'}.'.num'},
1927: '%255b'.$user.'%253a'.$domain.'%255d');
1928: my $result='';
1929: foreach my $key (sort(keys(%records))) {
1930: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1931: next if ($content{'senderdomain'} eq '');
1932: next if ($content{'subject'} !~ /^Record/);
1933: # &Apache::lonfeedback::newline_to_br(\$content{'message'});
1934: $result.='Recorded by '.
1935: $content{'sendername'}.':'.$content{'senderdomain'}."\n";
1936: $result.=
1937: &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
1938: }
1939: return $result;
1940: }
1941:
1942: sub disfacetoface {
1943: my ($r,$user,$domain,$target)=@_;
1944: if ($target eq '') {
1945: $target=$env{'form.grade_target'};
1946: }
1947: unless ($env{'request.course.id'}) { return; }
1948: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
1949: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1950: '/'.$env{'request.course.sec'})) {
1951: $r->print(&mt('Not allowed'));
1952: return;
1953: }
1954: my %records=&Apache::lonnet::dump('nohist_email',
1955: $env{'course.'.$env{'request.course.id'}.'.domain'},
1956: $env{'course.'.$env{'request.course.id'}.'.num'},
1957: '%255b'.$user.'%253a'.$domain.'%255d');
1958: my $result='';
1959: foreach my $key (sort(keys(%records))) {
1960: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1961: next if ($content{'senderdomain'} eq '');
1962: if (!&Apache::lonfeedback::contains_block_html($content{'message'})) {
1963: &Apache::lonfeedback::newline_to_br(\$content{'message'});
1964: }
1965: if ($content{'subject'}=~/^Record/) {
1966: $result.='<h3>'.&mt('Record').'</h3>';
1967: } elsif ($content{'subject'}=~/^Broadcast/) {
1968: $result .='<h3>'.&mt('Broadcast Message').'</h3>';
1969: if ($content{'subject'}=~/^Broadcast\./) {
1970: if (defined($content{'coursemsgid'})) {
1971: my $crsmsgid = &escape($content{'coursemsgid'});
1972: my $broadcast_message = &general_message($crsmsgid);
1973: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$broadcast_message;
1974: } else {
1975: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1976: $content{'message'} =
1977: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1978: $content{'message'};
1979: }
1980: }
1981: } elsif ($content{'subject'}=~/^Archive/) {
1982: $result.='<h3>'.&mt('Archived Message').'</h3>';
1983: if (defined($content{'coursemsgid'})) {
1984: my $crsmsgid = &escape($content{'coursemsgid'});
1985: my $archive_message = &general_message($crsmsgid);
1986: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$archive_message;
1987: } else {
1988: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1989: $content{'message'} =
1990: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1991: $content{'message'};
1992: }
1993: } else {
1994: $result.='<h3>'.&mt('Critical Message').'</h3>';
1995: if (defined($content{'coursemsgid'})) {
1996: my $crsmsgid=&escape($content{'coursemsgid'});
1997: my $critical_message = &general_message($crsmsgid);
1998: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$critical_message;
1999: } else {
2000: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
2001: $content{'message'}=
2002: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
2003: $content{'message'};
2004: }
2005: }
2006: $result.=&mt('By').': <b>'.
2007: &Apache::loncommon::aboutmewrapper(
2008: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
2009: $content{'sendername'}.':'.
2010: $content{'senderdomain'}.') '.$content{'time'}.
2011: '<br /><pre class="LC_wordwrap">'.
2012: &Apache::lontexconvert::msgtexconverted($content{'message'}).
2013: '</pre>';
2014: }
2015: # Check to see if there were any messages.
2016: if ($result eq '') {
2017: my $lctype = &mt(lc(&Apache::loncommon::course_type()));
2018: if ($target ne 'tex') {
2019: $r->print("<p><b>".&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this '.$lctype.'.')."</b></p>");
2020: } else {
2021: $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this '.$lctype.'.').'}\\\\');
2022: }
2023: } elsif ($target eq 'tex') {
2024: $r->print(&Apache::lonxml::xmlparse($r,$target,$result));
2025: } else {
2026: $r->print('<div>'.$result.'</div>');
2027: }
2028: }
2029:
2030: sub general_message {
2031: my ($crsmsgid) = @_;
2032: my %general_content;
2033: if ($crsmsgid) {
2034: my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid],
2035: $env{'course.'.$env{'request.course.id'}.'.domain'},
2036: $env{'course.'.$env{'request.course.id'}.'.num'});
2037: %general_content = &Apache::lonmsg::unpackagemsg($course_content{$crsmsgid});
2038: }
2039: return $general_content{'message'};
2040: }
2041:
2042: # ---------------------------------------------------------------- Face to face
2043:
2044: sub facetoface {
2045: my ($r,$stage)=@_;
2046: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
2047: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
2048: '/'.$env{'request.course.sec'})) {
2049: $r->print(&mt('Not allowed'));
2050: return;
2051: }
2052: my $crstype = &Apache::loncommon::course_type();
2053: my $leaders = ($crstype eq 'Community') ? 'coordinators and leaders'
2054: : 'faculty and staff';
2055: &printheader($r,
2056: '/adm/email?recordftf=query',
2057: "User Notes, Face-to-Face, Critical Messages, Broadcast Messages, Archived Messages");
2058: # from query string
2059:
2060: if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
2061: if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
2062:
2063: my $defdom=$env{'user.domain'};
2064: # already filled in
2065: if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
2066: # generate output
2067: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
2068: my $stdbrws = &Apache::loncommon::selectstudent_link
2069: ('stdselect','recuname','recdomain');
2070: my %lt=&Apache::lonlocal::texthash('user' => 'Username',
2071: 'dom' => 'Domain',
2072: 'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, Broadcast Messages and Archived Messages in $crstype",
2073: 'subm' => 'Retrieve discussion and message records',
2074: 'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')',
2075: 'post' => 'Post this Record');
2076:
2077: $r->print('<h2>'.$lt{'head'}.'</h2>'
2078: .'<form method="post" action="/adm/email" name="stdselect">'
2079: .'<input type="hidden" name="recordftf" value="retrieve" />'
2080: .&Apache::lonhtmlcommon::start_pick_box()
2081: .&Apache::lonhtmlcommon::row_title($lt{'user'})
2082: .'<input type="text" size="12" name="recuname" value="'.$env{'form.recuname'}.'" />'
2083: .' '.$stdbrws
2084: .&Apache::lonhtmlcommon::row_closure()
2085: .&Apache::lonhtmlcommon::row_title($lt{'dom'})
2086: .$domform
2087: .&Apache::lonhtmlcommon::row_closure(1)
2088: .&Apache::lonhtmlcommon::end_pick_box()
2089: .'<br />'
2090: .'<input type="submit" value="'.$lt{'subm'}.'" />'
2091: .'</form>'
2092: );
2093:
2094: if (($stage ne 'query') &&
2095: ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
2096: chomp($env{'form.newrecord'});
2097: if ($env{'form.newrecord'}) {
2098: &Apache::lonmsg::store_instructor_comment($env{'form.newrecord'},
2099: $env{'form.recuname'},
2100: $env{'form.recdomain'});
2101: }
2102: my $aboutmelink=&Apache::loncommon::aboutmewrapper(
2103: &Apache::loncommon::plainname($env{'form.recuname'}
2104: ,$env{'form.recdomain'})
2105: ,$env{'form.recuname'},$env{'form.recdomain'});
2106: $r->print('<hr />'
2107: .'<h2>'
2108: .&mt('Discussion and message records for [_1] ([_2])'
2109: ,$aboutmelink
2110: ,$env{'form.recuname'}.':'.$env{'form.recdomain'})
2111: .'</h2>'
2112: );
2113: &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
2114: $r->print(<<ENDRHEAD);
2115: <form method="post" action="/adm/email">
2116: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
2117: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
2118: ENDRHEAD
2119: $r->print(<<ENDBFORM);
2120: <hr />$lt{'newr'}<br />
2121: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
2122: <br />
2123: <input type="hidden" name="recordftf" value="post" />
2124: <input type="submit" value="$lt{'post'}" />
2125: </form>
2126: ENDBFORM
2127: }
2128: }
2129:
2130: # ----------------------------------------------------------- Display a message
2131:
2132: sub displaymessage {
2133: my ($r,$msgid,$folder,$msgstatus)=@_;
2134: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2135: my %blocked = ();
2136: my %setters = ();
2137: my $numblocked = 0;
2138: my $crstype = &Apache::loncommon::course_type();
2139: my $clientip = &Apache::lonnet::get_requestor_ip($r);
2140:
2141: # info to generate "next" and "previous" buttons and check if message is blocked
2142: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
2143: &Apache::loncommon::blockcheck(\%setters,'com',$clientip);
2144: my @messages=&sortedmessages(\%blocked,$startblock,$endblock,$by_ip,\$numblocked,$folder,$msgstatus);
2145: if ( $blocked{$msgid} eq 'ON' ) {
2146: &printheader($r,'/adm/email',&mt('Display a Message'));
2147: #$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.'));
2148: my($blocked, $blocktext) = &Apache::loncommon::blocking_status("com",$clientip);
2149: $r->print("<br />".$blocktext);
2150: return;
2151: }
2152: if ($msgstatus eq '') {
2153: &statuschange($msgid,'read',$folder);
2154: }
2155: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2156: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid});
2157: my $counter=0;
2158: my $escmsgid=&escape($msgid);
2159: foreach (@messages) {
2160: if ($_->[5] eq $escmsgid){
2161: last;
2162: }
2163: $counter++;
2164: }
2165:
2166: my $see_anonymous;
2167: my $from_student = 0;
2168: if ($env{'request.course.id'} eq $content{'courseid'}) {
2169: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2170: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2171: my $username = $content{'sendername'}.':'.$content{'senderdomain'};
2172: my %classlist_entry =
2173: &Apache::lonnet::get('classlist',[$username],$cdom,$cnum);
2174: if (exists($classlist_entry{$username})) {
2175: $from_student = 1;
2176: $see_anonymous = &Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
2177: }
2178: }
2179:
2180:
2181: my $number_of_messages = scalar(@messages); #subtract 1 for last index
2182: my $head_extra;
2183:
2184: # if student's view of resource will be included
2185: # get <link> tag(s) for css file(s) in use, and pass to &header to include
2186: # in call to loncommon::start_page()
2187:
2188: if (($env{'request.course.id'} eq $content{'courseid'}) &&
2189: (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
2190: my $symb;
2191: if (defined($content{'symb'})) {
2192: $symb = $content{'symb'};
2193: } elsif (defined($content{'baseurl'})) {
2194: $symb=&Apache::lonnet::symbread($content{'baseurl'});
2195: }
2196: if ($symb) {
2197: $head_extra = &Apache::loncommon::css_links($symb);
2198: }
2199: }
2200:
2201: # start output
2202: &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',
2203: $content{'baseurl'},$head_extra);
2204:
2205: # Prepare available functions
2206: my @functionlist;
2207: if (!$content{'noreplies'}) {
2208: push(@functionlist,'<a href="/adm/email?replyto='.&escape($msgid).$sqs.'">'
2209: .&mt('Reply')
2210: .'</a>');
2211: }
2212: push(@functionlist,'<a href="/adm/email?forward='.&escape($msgid).$sqs.'">'
2213: .&mt('Forward')
2214: .'</a>');
2215: push(@functionlist,'<a href="/adm/email?markunread='.&escape($msgid).$sqs.'">'
2216: .&mt('Mark Unread')
2217: .'</a>');
2218: push(@functionlist,'<a href="/adm/email?markdel='.&escape($msgid).$sqs.'">'
2219: .&mt('Delete')
2220: .'</a>');
2221:
2222: # Prepare available navigation
2223: my @navigationlist;
2224: if ($counter > 0){
2225: push(@navigationlist,'<a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.'">'
2226: .&mt('Previous')
2227: .'</a>');
2228: }
2229: if ($counter < $number_of_messages - 1){
2230: push(@navigationlist,'<a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.'">'
2231: .&mt('Next')
2232: .'</a>');
2233: }
2234: push(@navigationlist,'<a href="/adm/email?'.$sqs.'">'
2235: .&mt('Back to Folder Display')
2236: .'</a>');
2237:
2238: # Prepare available actions
2239: my $symb;
2240: if (defined($content{'symb'})) {
2241: $symb = $content{'symb'};
2242: } elsif (defined($content{'baseurl'})) {
2243: $symb=&Apache::lonnet::symbread($content{'baseurl'});
2244: }
2245: my @actionlist;
2246: if ($env{'user.adv'}) {
2247:
2248: if (($env{'request.course.id'}) && ($from_student) &&
2249: (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
2250: push(@actionlist,&Apache::loncommon::track_student_link(
2251: 'View recent activity'
2252: ,$content{'sendername'}
2253: ,$content{'senderdomain'}
2254: ,'check'));
2255: }
2256: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
2257: push(@actionlist,&Apache::loncommon::pprmlink(
2258: &mt('Set/Change parameters')
2259: ,$content{'sendername'}
2260: ,$content{'senderdomain'}
2261: ,$symb
2262: ,'check'));
2263: }
2264: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
2265: push(@actionlist,&Apache::loncommon::pgrdlink(
2266: &mt('Set/Change grades')
2267: ,$content{'sendername'}
2268: ,$content{'senderdomain'}
2269: ,$symb
2270: ,'check'));
2271: }
2272: }
2273:
2274: # Print functionlist, navigationlist, and actionlist in page header
2275: my $functions='<div class="LC_columnSection">';
2276:
2277: # Functionlist
2278: $functions.=&Apache::lonhtmlcommon::start_funclist();
2279: foreach my $item (@functionlist) {
2280: $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
2281: }
2282: $functions .= &Apache::lonhtmlcommon::end_funclist();
2283:
2284: # Navigationlist
2285: $functions.=&Apache::lonhtmlcommon::start_funclist(
2286: &mt('Navigation'));
2287: foreach my $item (@navigationlist) {
2288: $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
2289: }
2290: $functions .= &Apache::lonhtmlcommon::end_funclist();
2291:
2292: # Actionlist
2293: if (@actionlist) {
2294: $functions.=&Apache::lonhtmlcommon::start_funclist(
2295: &mt('Currently available actions (will open extra window)'));
2296: foreach my $item (@actionlist) {
2297: $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
2298: }
2299: $functions.=&Apache::lonhtmlcommon::end_funclist();
2300: }
2301:
2302: $functions.='</div>';
2303: $r->print(&Apache::loncommon::head_subbox($functions));
2304:
2305:
2306: my ($tonum,$tolist,$cclist,$bcclist,$groupcclist,%recipients);
2307: if ($content{'recipid'}) {
2308: $tonum = &retrieve_recips('display',\%content,\%recipients);
2309: if (ref($recipients{'cc'}) eq 'ARRAY') {
2310: $cclist = join(', ',@{$recipients{'cc'}});
2311: }
2312: if (ref($recipients{'to'}) eq 'ARRAY') {
2313: $tolist = join(', ',@{$recipients{'to'}});
2314: }
2315: if (ref($recipients{'bcc'}) eq 'ARRAY') {
2316: $bcclist = join(', ',@{$recipients{'bcc'}});
2317: }
2318: }
2319:
2320: my $broadcast_link;
2321: if (($content{'courseid'}) && ($content{'recipid'} &&
2322: (ref($recipients{'course_broadcast'}) eq 'ARRAY') ||
2323: (ref($recipients{'group_cc_broadcast'}) eq 'ARRAY') ||
2324: (ref($recipients{'group_bcc_broadcast'}) eq 'ARRAY'))) {
2325: $broadcast_link = &recipients_link($r,\%content,\%recipients);
2326: }
2327:
2328: if (((!$tolist) && (!$broadcast_link)) && ref($content{'recuser'}) eq 'ARRAY') {
2329: my @recipients;
2330: for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
2331: $recipients[$i] = &Apache::loncommon::aboutmewrapper(
2332: &Apache::loncommon::plainname($content{'recuser'}[$i],
2333: $content{'recdomain'}[$i]),
2334: $content{'recuser'}[$i],$content{'recdomain'}[$i]).
2335: ' ('.$content{'recuser'}[$i].':'.$content{'recdomain'}[$i].') ';
2336: }
2337: $tolist = join(', ',@recipients);
2338: }
2339: my ($restitle,$baseurl,$refers_to);
2340: if (defined($content{'resource_title'})) {
2341: $restitle = $content{'resource_title'};
2342: } else {
2343: if (defined($content{'baseurl'})) {
2344: $restitle = &Apache::lonnet::gettitle($content{'baseurl'});
2345: }
2346: }
2347: if (defined($content{'baseurl'})) {
2348: $baseurl = &Apache::lonenc::check_encrypt($content{'baseurl'});
2349: }
2350: $r->print('<div class="LC_clear_float_footer">');
2351: if ($from_student && $see_anonymous ) {
2352: $r->print(&Apache::loncommon::student_image_tag($content{'senderdomain'},$content{'sendername'}).'</br>');
2353: }
2354:
2355: # Display LON-CAPA Message (Start)
2356: # Subject
2357: $r->print('</div>'
2358: .&Apache::lonhtmlcommon::start_pick_box()
2359: .&Apache::lonhtmlcommon::row_title(&mt('Subject'))
2360: .$content{'subject'}
2361: .&Apache::lonhtmlcommon::row_closure()
2362: );
2363: if ($folder eq 'sent') {
2364: # To
2365: if ($tolist) {
2366: $r->print(&Apache::lonhtmlcommon::row_title(&mt('To'))
2367: .$tolist
2368: .&Apache::lonhtmlcommon::row_closure()
2369: );
2370: }
2371: if ($cclist) {
2372: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Cc'))
2373: .$cclist
2374: .&Apache::lonhtmlcommon::row_closure()
2375: );
2376: }
2377: if ($bcclist) {
2378: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Bcc'))
2379: .$bcclist
2380: .&Apache::lonhtmlcommon::row_closure()
2381: );
2382: }
2383: if (($content{'courseid'}) && ($content{'recipid'})) {
2384: my %broadcast_types =
2385: &Apache::lonlocal::texthash (
2386: course_broadcast => 'Broadcast to',
2387: group_cc_broadcast => 'Cc to group',
2388: group_bcc_broadcast => 'Bcc to group',
2389: );
2390: foreach my $type (sort(keys(%broadcast_types))) {
2391: if (ref($recipients{$type}) eq 'ARRAY') {
2392: my $num = @{$recipients{$type}};
2393: my $broadcastlist = join(', ',@{$recipients{$type}});
2394: if ($broadcastlist && $broadcast_link) {
2395: if ($type eq 'group_cc_broadcast') {
2396: $groupcclist = $broadcastlist;
2397: }
2398: $r->print(&Apache::lonhtmlcommon::row_title(
2399: $broadcast_types{$type})
2400: .&mt('[quant,_1,recipient]',$num)
2401: .' <a href="javascript:showBroadcastList();">['
2402: .&mt('Show').']</a>'
2403: .&Apache::lonhtmlcommon::row_closure());
2404: }
2405: }
2406: }
2407: }
2408: if ($content{'replytoaddr'}) {
2409: my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
2410: if ($replytoname ne '' && $replytodom ne '') {
2411: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Reply To'))
2412: .$replytoname.':'.$replytodom
2413: .&Apache::lonhtmlcommon::row_closure()
2414: );
2415: }
2416: }
2417: } else {
2418: # From, Reply
2419: $r->print(&Apache::lonhtmlcommon::row_title(&mt('From'))
2420: .&Apache::loncommon::aboutmewrapper(
2421: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
2422: $content{'sendername'},$content{'senderdomain'})
2423: );
2424: if ($content{'noreplies'}) {
2425: $r->print(' ('.&mt('No replies to sender').')'
2426: .&Apache::lonhtmlcommon::row_closure()
2427: );
2428: } else {
2429: if ($content{'replytoaddr'}) {
2430: my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
2431: if ($replytoname ne '' && $replytodom ne '') {
2432: $r->print(&Apache::lonhtmlcommon::row_closure()
2433: .&Apache::lonhtmlcommon::row_title(&mt('Reply To'))
2434: .$replytoname.':'.$replytodom
2435: .&Apache::lonhtmlcommon::row_closure()
2436: );
2437: } else {
2438: $r->print(&Apache::lonhtmlcommon::row_closure());
2439: }
2440: } else {
2441: $r->print(' ('.$content{'sendername'}.':'.$content{'senderdomain'}.') '
2442: .&Apache::lonhtmlcommon::row_closure()
2443: );
2444: }
2445: if ($tonum && $tolist) {
2446: $r->print(&Apache::lonhtmlcommon::row_title(&mt('To'))
2447: .$tolist
2448: .&Apache::lonhtmlcommon::row_closure()
2449: );
2450: }
2451: if ($cclist) {
2452: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Cc'))
2453: .$cclist
2454: .&Apache::lonhtmlcommon::row_closure()
2455: );
2456: }
2457: if ($content{'group'} ne '') {
2458: if (&check_group_priv($content{'group'})) {
2459: if (ref($recipients{'group_cc_broadcast'}) eq 'ARRAY') {
2460: $groupcclist = join(', ',@{$recipients{'group_cc_broadcast'}});
2461: if ($groupcclist) {
2462: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Group Cc'))
2463: .$groupcclist
2464: .&Apache::lonhtmlcommon::row_closure()
2465: );
2466: }
2467: }
2468: }
2469: }
2470: }
2471: }
2472:
2473: # Course
2474: if ($content{'courseid'} ne '') {
2475: if ($content{'courseid'} =~ m{^$match_domain\_$match_courseid$}) {
2476: my %courseinfo;
2477: %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'},
2478: {'one_time' => 1});
2479: my $description = $courseinfo{'description'};
2480: if ($description ne '') {
2481: $r->print(&Apache::lonhtmlcommon::row_title(&mt($crstype))
2482: .$description
2483: );
2484: if ($content{'coursesec'}) {
2485: $r->print(' ('.&mt('Section').': '.$content{'coursesec'}.')');
2486: }
2487: $r->print(&Apache::lonhtmlcommon::row_closure());
2488: }
2489: }
2490: }
2491: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Time'))
2492: .$content{'time'}
2493: .&Apache::lonhtmlcommon::row_closure()
2494: );
2495:
2496: # Refers to
2497: if ($baseurl) {
2498: if (defined($content{'courseid'}) && defined($env{'request.course.id'})) {
2499: if ($content{'courseid'} eq $env{'request.course.id'}) {
2500: my $symblink;
2501: my $showsymb = &Apache::lonenc::check_decrypt($symb);
2502: my $showurl = &Apache::lonenc::check_decrypt($baseurl);
2503: my $encrypturl = &Apache::lonnet::EXT('resource.0.encrypturl',
2504: $showsymb,$env{'user.domain'},$env{'user.name'});
2505: if ($symb) {
2506: if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
2507: unless ($showsymb =~ m{^/enc/}) {
2508: $showsymb = &Apache::lonenc::encrypted($showsymb);
2509: }
2510: }
2511: $symblink = '?symb='.$showsymb;
2512: }
2513: if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
2514: unless ($showurl =~ m{^/enc/}) {
2515: $showurl = &Apache::lonenc::encrypted($showurl);
2516: }
2517: }
2518: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
2519: .'<a href="'.$showurl.$symblink.'">'.$restitle.'</a>'
2520: .&Apache::lonhtmlcommon::row_closure()
2521: );
2522: $refers_to = 1;
2523: }
2524: }
2525: if (!$refers_to) {
2526: if ($baseurl =~ m-^/enc/-) {
2527: if (defined($content{'courseid'})) {
2528: if (!$env{'request.course.id'}) {
2529: my $unencurl =
2530: &Apache::lonenc::unencrypted($baseurl,
2531: $content{'courseid'});
2532: if ($unencurl ne '') {
2533: if (&Apache::lonnet::allowed('bre',$unencurl)) {
2534: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
2535: .'<a href="'.$unencurl.'">'.$restitle.'</a>'
2536: .&Apache::lonhtmlcommon::row_closure()
2537: );
2538: }
2539: }
2540: }
2541: }
2542: } else {
2543: if (&Apache::lonnet::allowed('bre',$baseurl)) {
2544: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
2545: .'<a href="'.$baseurl.'">'.$restitle.'</a>'
2546: .&Apache::lonhtmlcommon::row_closure()
2547: );
2548:
2549: }
2550: }
2551: }
2552: }
2553:
2554: # Message
2555: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Message'))
2556: .'<pre class="LC_wordwrap">'
2557: .&Apache::lontexconvert::msgtexconverted($content{'message'},1)
2558: .'</pre>'
2559: );
2560: if (&displayresource(%content)) {
2561: $r->print(&Apache::lonhtmlcommon::row_closure()
2562: .&Apache::lonhtmlcommon::row_title(&mt('Resource Details'))
2563: .&displayresource(%content)
2564: );
2565: }
2566: $r->print(&Apache::lonhtmlcommon::row_closure(1).
2567: &Apache::lonhtmlcommon::end_pick_box());
2568: # Display LON-CAPA Message (End)
2569: return;
2570: }
2571:
2572: sub retrieve_recips {
2573: my ($context,$content,$recips)= @_;
2574: my $tonum = 0;
2575: if (ref($content) eq 'HASH') {
2576: my %reciphash =
2577: &Apache::lonnet::get('nohist_emailrecip',[$content->{'recipid'}],
2578: $content->{'senderdomain'},$content->{'sendername'});
2579: my $recipinfo = $reciphash{$content->{'recipid'}};
2580: if (ref($recipinfo) eq 'HASH') {
2581: foreach my $type ('to','cc','course_broadcast','group_cc_broadcast','group_bcc_broadcast') {
2582: if (ref($recipinfo->{$type}) eq 'HASH') {
2583: if ($type eq 'to') {
2584: $tonum = keys(%{$recipinfo->{$type}});
2585: }
2586: foreach my $user (sort(keys(%{$recipinfo->{$type}}))) {
2587: my ($uname,$udom) = split(/:/,$user);
2588: next if (($context eq 'replying') && ($uname eq $env{'user.name'})
2589: && ($udom eq $env{'user.domain'}));
2590: my $showuser ='<span class="LC_nobreak">';
2591: if ($context eq 'replying') {
2592: if (($type eq 'to') || ($type eq 'cc')) {
2593: $showuser = '<label><input type="checkbox" name="replying_'.$type.'" value="'.$user.'" />';
2594: } elsif ($type eq 'group_cc_broadcast') {
2595: $showuser = '<label><input type="checkbox" name="replying_groupcc" value="'.$user.'" />';
2596: }
2597: }
2598: $showuser .= &Apache::loncommon::aboutmewrapper(
2599: &Apache::loncommon::plainname($uname,
2600: $udom),$uname,$udom);
2601: if ($context eq 'replying') {
2602: $showuser .='</label>';
2603: }
2604: $showuser .= '</span>';
2605: if (ref($recips) eq 'HASH') {
2606: push(@{$recips->{$type}},$showuser);
2607: }
2608: }
2609: }
2610: }
2611: }
2612: }
2613: return $tonum;
2614: }
2615:
2616: sub recipients_link {
2617: my ($r,$content,$recipients) = @_;
2618: my ($broadcast_link,$show);
2619: if ((ref($content) eq 'HASH') && (ref($recipients) eq 'HASH')) {
2620: if (ref($recipients->{'course_broadcast'}) eq 'ARRAY') {
2621: if (@{$recipients->{'course_broadcast'}} > 0) {
2622: $show = 'course';
2623: }
2624: } elsif (ref($recipients->{'group_cc_broadcast'}) eq 'ARRAY') {
2625: if (@{$recipients->{'group_cc_broadcast'}} > 0) {
2626: $show = 'group_cc';
2627: }
2628: } elsif (ref($recipients->{'group_bcc_broadcast'}) eq 'ARRAY') {
2629: if (@{$recipients->{'group_bcc_broadcast'}} > 0) {
2630: $show = 'group_bcc';
2631: }
2632: }
2633: if ($show) {
2634: my ($nothing,$height,$width,$start_page,$end_page,$body);
2635: $nothing=&Apache::lonhtmlcommon::javascript_nothing();
2636: $height = 400;
2637: $width = 600;
2638: $start_page =
2639: &Apache::loncommon::start_page('Broadcast List', undef,
2640: {only_body => 1,
2641: js_ready => 1,});
2642: $end_page = &Apache::loncommon::end_page({js_ready => 1,});
2643: $body = '<h3>'.&mt("Recipients of broadcast message").'</h3>'.
2644: &Apache::loncommon::start_data_table();
2645: my $cell = 0;
2646: $body .= &Apache::loncommon::start_data_table_row();
2647: foreach my $item (@{$recipients->{$show.'_broadcast'}}) {
2648: $item =~ s/'/\\'/g;
2649: if (!($cell%2) && $cell > 0) {
2650: $body .= &Apache::loncommon::end_data_table_row().
2651: &Apache::loncommon::start_data_table_row();
2652: }
2653: $cell ++;
2654: $body .= '<td>'.$cell.' '.$item.' </td>';
2655: }
2656: if ($cell%2) {
2657: $body .= '<td> </td>';
2658: }
2659: $body .= &Apache::loncommon::end_data_table_row().
2660: &Apache::loncommon::end_data_table();
2661: $body =~ s{</}{<\\/}g;
2662: $body =~ s{\n}{}g;
2663: $r->print(<<ENDJS);
2664: <script type="text/javascript">
2665: // <![CDATA[
2666: function showBroadcastList() {
2667: var caller = this;
2668: var newWindow = null;
2669: try {
2670: newWindow = window.open($nothing,"broadcast","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" );
2671: }
2672: catch(error) {
2673: writeWin(caller);
2674: return;
2675: }
2676: if (newWindow) {
2677: caller = newWindow;
2678: }
2679: writeWin(caller);
2680: return;
2681: }
2682:
2683: function writeWin(caller) {
2684: caller.document.writeln('$start_page $body $end_page');
2685: caller.document.close();
2686: caller.focus();
2687: }
2688: // ]]>
2689: </script>
2690:
2691: ENDJS
2692: $broadcast_link = 1;
2693: }
2694: }
2695: return $broadcast_link;
2696: }
2697:
2698: # =========================================================== Show the citation
2699:
2700: sub displayresource {
2701: my %content=@_;
2702: #
2703: # If the recipient is in the same course that the message was sent from and
2704: # has sufficient privileges, show "all details," else show citation
2705: #
2706: if (($env{'request.course.id'} eq $content{'courseid'})
2707: && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
2708: my $symb;
2709: if (defined($content{'symb'})) {
2710: $symb = &Apache::lonenc::check_decrypt($content{'symb'});
2711: } elsif (defined($content{'baseurl'})) {
2712: $symb =
2713: &Apache::lonnet::symbread(&Apache::lonenc::check_decrypt($content{'baseurl'}));
2714: }
2715: # Could not get a symb, give up
2716: unless ($symb) { return $content{'citation'}; }
2717: # Have a symb, can render
2718: return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
2719: &Apache::loncommon::get_previous_attempt($symb,
2720: $content{'sendername'},
2721: $content{'senderdomain'},
2722: $content{'courseid'}).
2723: '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
2724: &Apache::loncommon::get_student_view($symb,
2725: $content{'sendername'},
2726: $content{'senderdomain'},
2727: $content{'courseid'}).
2728: '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
2729: &Apache::loncommon::get_student_answers($symb,
2730: $content{'sendername'},
2731: $content{'senderdomain'},
2732: $content{'courseid'});
2733: } elsif ($env{'user.adv'}) {
2734: return $content{'citation'};
2735: }
2736: return '';
2737: }
2738:
2739: # ================================================================== The Header
2740:
2741: sub header {
2742: my ($r,$title,$baseurl,$head_extra)=@_;
2743: my $extra = &Apache::loncommon::studentbrowser_javascript();
2744: if ($baseurl) {
2745: $extra .= "<base href=\"".&Apache::lonnet::absolute_url()."/$baseurl\" />";
2746: }
2747: $extra .= '<script type="text/javascript"
2748: src="/res/adm/includes/file_upload.js"></script>';
2749: if ($head_extra) {
2750: $extra .= "\n$head_extra";
2751: }
2752: $r->print(&Apache::loncommon::start_page('Messages',
2753: $extra));
2754: $r->print(&Apache::lonhtmlcommon::breadcrumbs
2755: (($title?$title:'Send and display messages')));
2756: }
2757:
2758: # ---------------------------------------------------------------- Print header
2759:
2760: sub printheader {
2761: my ($r,$url,$desc,$title,$baseurl,$head_extra)=@_;
2762: &Apache::lonhtmlcommon::add_breadcrumb
2763: ({href=>$url,
2764: text=>$desc});
2765: &header($r,$title,$baseurl,$head_extra);
2766: }
2767:
2768: # ------------------------------------------------------------ Store the comment
2769:
2770: sub storecomment {
2771: my ($r)=@_;
2772: my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2773: my $cleanmsgtxt='';
2774: foreach my $line (split(/[\n\r]/,$msgtxt)) {
2775: unless ($line=~/^\s*(\>|\>\;)/) {
2776: $cleanmsgtxt.=$line."\n";
2777: }
2778: }
2779: my $key=&escape($env{'form.baseurl'}).'___'.time;
2780: &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
2781: }
2782:
2783: sub storedcommentlisting {
2784: my ($r)=@_;
2785: my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
2786: '^'.&escape(&escape($env{'form.showcommentbaseurl'})));
2787: $r->print(&Apache::loncommon::start_page('Saved Comment Listing',undef,
2788: {'onlybody' => 1}));
2789: if ((keys(%msgs))[0]=~/^error\:/) {
2790: $r->print(&mt('No saved comments yet.'));
2791: } else {
2792: my $found=0;
2793: foreach my $key (sort(keys(%msgs))) {
2794: $r->print("\n".$msgs{$key}."<hr />");
2795: $found=1;
2796: }
2797: unless ($found) {
2798: $r->print(&mt('No saved comments yet for this resource.'));
2799: }
2800: }
2801: }
2802:
2803: # ---------------------------------------------------------------- Send an email
2804:
2805: sub sendoffmail {
2806: my ($r,$folder)=@_;
2807: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2808: my $sendstatus='';
2809: my %msg_status;
2810: my $numsent = 0;
2811: my $nosentstore = 1;
2812: my $attachmenturl;
2813: my $now = time;
2814: my ($cdom,$cnum,$group);
2815: if (exists($env{'form.group'})) {
2816: $group = $env{'form.group'};
2817: }
2818: if (exists($env{'request.course.id'})) {
2819: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2820: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2821: }
2822: my $clientip = &Apache::lonnet::get_requestor_ip($r);
2823: my %setters;
2824: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
2825: &Apache::loncommon::blockcheck(\%setters,'com',$clientip);
2826: if ($by_ip) {
2827: &printheader($r,'','Sending messages blocked from your location.');
2828: return 'blocked';
2829: } elsif ($env{'form.send'}) {
2830: if (!$env{'form.multiforward'}) {
2831: if ($group eq '') {
2832: &printheader($r,'','Messages being sent.');
2833: } else {
2834: $r->print(&groupmail_header('sending',$group));
2835: }
2836: }
2837: $r->rflush();
2838: my %content=();
2839: undef %content;
2840: if ($env{'form.forwid'}) {
2841: my $msgid=$env{'form.forwid'};
2842: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2843: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1,1);
2844: &statuschange($msgid,'forwarded',$folder);
2845: if ($content{'attachmenturl'} ne '') {
2846: $attachmenturl = $content{'attachmenturl'};
2847: }
2848: $env{'form.message'} .= "\n\n-- Forwarded message --\n\n".
2849: $content{'message'};
2850: }
2851: if ($env{'form.replyid'}) {
2852: my $msgid=$env{'form.replyid'};
2853: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2854: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2855: &statuschange($msgid,'replied',$folder);
2856: }
2857:
2858: my $mode = $env{'form.sendmode'};
2859: my (%toaddr,$tos,$cc,$bcc,$broadcast);
2860:
2861: if ($mode eq 'group') {
2862: if (defined($env{'form.courserecips'})) {
2863: my $courseusers = $env{'form.courserecips'};
2864: $courseusers =~ s/^_\&\&\&_//;
2865: my @to = split('_&&&_',$courseusers);
2866: foreach my $dest (@to) {
2867: my ($user,$domain) = split(/:/, $dest);
2868: if (($user ne '') && ($domain ne '')) {
2869: my $rec = $user.":".$domain;
2870: $toaddr{$rec} = '';
2871: $broadcast->{$rec} = '';
2872: }
2873: }
2874: }
2875: } elsif ($mode eq 'upload') {
2876: $nosentstore = 0;
2877: foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
2878: my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/);
2879: if ($txt) {
2880: $rec =~ s/^\s+//;
2881: $rec =~ s/\s+$//;
2882: $toaddr{$rec}.=$txt."\n";
2883: $broadcast->{$rec} = '';
2884: }
2885: }
2886: } else {
2887: if (($env{'form.recuname'} ne '') && ($env{'form.recdomain'} ne '')) {
2888: $toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
2889: $tos->{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
2890: }
2891: }
2892: if ($env{'form.additionalrec_to'}) {
2893: foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_to'})) {
2894: my ($auname,$audom)=split(/:/,$rec);
2895: if (($auname ne "") && ($audom ne "")) {
2896: $toaddr{$auname.':'.$audom}='';
2897: $tos->{$auname.':'.$audom}='';
2898: }
2899: }
2900: }
2901: if ($env{'form.replying_to'}) {
2902: my @toreplies =
2903: &Apache::loncommon::get_env_multiple('form.replying_to');
2904: foreach my $rec (@toreplies) {
2905: my ($auname,$audom)=split(/:/,$rec);
2906: if (($auname ne "") && ($audom ne "")) {
2907: $toaddr{$auname.':'.$audom}='';
2908: $tos->{$auname.':'.$audom}='';
2909: }
2910: }
2911: }
2912: if ($env{'form.additionalrec_cc'}) {
2913: foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_cc'})) {
2914: my ($auname,$audom)=split(/:/,$rec);
2915: if (($auname ne "") && ($audom ne "")) {
2916: $toaddr{$auname.':'.$audom}='';
2917: if (!defined($tos->{$auname.':'.$audom})) {
2918: $cc->{$auname.':'.$audom}='';
2919: }
2920: }
2921: }
2922: }
2923: if ($env{'form.replying_cc'}) {
2924: my @ccreplies =
2925: &Apache::loncommon::get_env_multiple('form.replying_cc');
2926: foreach my $rec (@ccreplies) {
2927: my ($auname,$audom)=split(/:/,$rec);
2928: if (($auname ne "") && ($audom ne "")) {
2929: $toaddr{$auname.':'.$audom}='';
2930: if (!defined($tos->{$auname.':'.$audom})) {
2931: $cc->{$auname.':'.$audom}='';
2932: }
2933: }
2934: }
2935: }
2936: if ($env{'form.replying_groupcc'}) {
2937: my @groupreplies =
2938: &Apache::loncommon::get_env_multiple('form.replying_groupcc');
2939: foreach my $rec (@groupreplies) {
2940: my ($auname,$audom)=split(/:/,$rec);
2941: if (($auname ne "") && ($audom ne "")) {
2942: $toaddr{$auname.':'.$audom}='';
2943: if (!defined($tos->{$auname.':'.$audom})) {
2944: $broadcast->{$auname.':'.$audom}='';
2945: }
2946: }
2947: }
2948: }
2949: if ($env{'form.additionalrec_bcc'}) {
2950: foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_bcc'})) {
2951: my ($auname,$audom)=split(/:/,$rec);
2952: if (($auname ne "") && ($audom ne "")) {
2953: $toaddr{$auname.':'.$audom}='';
2954: if ((!defined($tos->{$auname.':'.$audom})) &&
2955: (!defined($cc->{$auname.':'.$audom}))) {
2956: $bcc->{$auname.':'.$audom}='';
2957: }
2958: }
2959: }
2960: }
2961: my $savemsg;
2962: my $msgtype;
2963: my %sentmessage;
2964: my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'},
2965: undef,1);
2966: if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
2967: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
2968: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
2969: '/'.$env{'request.course.sec'})
2970: )) {
2971: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
2972: $msgtype = 'critical';
2973: } else {
2974: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2975: }
2976: my %reciphash = (
2977: to => $tos,
2978: cc => $cc,
2979: bcc => $bcc,
2980: );
2981: if ($mode eq 'group') {
2982: if ($group eq '') {
2983: $reciphash{'course_broadcast'} = $broadcast;
2984: } else {
2985: if ($env{'form.groupmail'} eq 'cc') {
2986: $reciphash{'group_cc_broadcast'} = $broadcast;
2987: } else {
2988: $reciphash{'group_bcc_broadcast'} = $broadcast;
2989: }
2990: }
2991: }
2992: my ($recipid,$recipstatus) =
2993: &Apache::lonmsg::store_recipients($msgsubj,$env{'user.name'},
2994: $env{'user.domain'},\%reciphash);
2995: if ($recipstatus ne 'ok') {
2996: &Apache::lonnet::logthis('Failed to store To, Bcc and Cc recipients for '.$env{'user.name'}.':'.$env{'user.domain'});
2997: }
2998: if ($env{'form.attachment'}) {
2999: if (length($env{'form.attachment'}) <= 1048576) {
3000: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback/'.$now);
3001: } else {
3002: $r->print('<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>');
3003: }
3004: } elsif ($env{'form.multiforward'}) {
3005: if ($env{'form.attachmenturl'} ne '') {
3006: $attachmenturl = $env{'form.attachmenturl'};
3007: }
3008: }
3009: my @recusers;
3010: my @recudoms;
3011: my %permresults;
3012: foreach my $address (sort(keys(%toaddr))) {
3013: my ($recuname,$recdomain)=split(/\:/,$address);
3014: my $msgtxt = $savemsg;
3015: if ($toaddr{$address}) {
3016: $msgtxt.="\n".'<hr />'."\n".$toaddr{$address};
3017: }
3018: my @thismsg;
3019: if ($msgtype eq 'critical') {
3020: $r->print(&mt('Sending critical message').' '.
3021: $recuname.':'.$recdomain.': ');
3022: @thismsg=
3023: &Apache::lonmsg::user_crit_msg($recuname,$recdomain,
3024: $msgsubj,$msgtxt,
3025: $env{'form.sendbck'},
3026: $env{'form.permanent'},
3027: \$sentmessage{$address},
3028: $nosentstore,$recipid,
3029: $attachmenturl,\%permresults);
3030: } else {
3031: $r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': ');
3032: @thismsg=
3033: &Apache::lonmsg::user_normal_msg($recuname,$recdomain,
3034: $msgsubj,$msgtxt,
3035: $content{'citation'},
3036: undef,$attachmenturl,
3037: $env{'form.permanent'},
3038: \$sentmessage{$address},
3039: undef,undef,undef,
3040: $nosentstore,$recipid,
3041: \%permresults);
3042: }
3043: $msg_status{$recuname.':'.$recdomain}=join(' ',@thismsg);
3044: if ($msg_status{$recuname.':'.$recdomain} =~ /(ok|con_delayed)/) {
3045: $numsent++;
3046: push(@recusers,$recuname);
3047: push(@recudoms,$recdomain);
3048: if ($1 eq 'ok') {
3049: $r->print('ok ');
3050: }
3051: if ($permresults{$recuname.':'.$recdomain}) {
3052: $r->print(' (email) ');
3053: }
3054: }
3055: $sendstatus.=' '.join(' ',@thismsg);
3056: }
3057: my $subj_prefix;
3058: if ($numsent > 0) {
3059: if (($env{'request.course.id'}) &&
3060: (($mode eq 'group') ||
3061: ($env{'form.courserecord'}) ||
3062: ($msgtype eq 'critical')) ||
3063: ($env{'form.replyid'} &&
3064: (($content{'courseid'} ne '') &&
3065: ($mode eq 'group')))) {
3066: if ($msgtype eq 'critical') {
3067: $subj_prefix = 'Critical.';
3068: } elsif ($mode eq 'group') {
3069: $subj_prefix = 'Broadcast.';
3070: } else {
3071: $subj_prefix = 'Archive';
3072: }
3073: my ($specialmsgid,$specialresult);
3074: my $course_str;
3075: if ($env{'form.replyid'}) {
3076: if ($content{'courseid'} ne '') {
3077: my %crsdesc =
3078: &Apache::lonnet::coursedescription($content{'courseid'},
3079: {'one_time' => 1});
3080: $course_str = &escape('['.$crsdesc{'num'}.':'.$crsdesc{'domain'}.']');
3081: }
3082: } elsif ($env{'request.course.id'}) {
3083: $course_str = &escape('['.$cnum.':'.$cdom.']');
3084: }
3085: $specialresult =
3086: &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
3087: $subj_prefix.' '.$course_str,$savemsg,undef,undef,
3088: $attachmenturl,undef,undef,\$specialmsgid,undef,undef,undef,
3089: undef,undef,1);
3090: $specialmsgid = &unescape($specialmsgid);
3091: if ($specialresult eq 'ok') {
3092: my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
3093: split(/\:/,&unescape($specialmsgid));
3094:
3095: foreach my $recipient (sort(keys(%toaddr))) {
3096: if ($msg_status{$recipient} =~ /\s*(ok|con_delayed)\s*/) {
3097: my $usersubj = $subj_prefix.'['.$recipient.']';
3098: my $usermsgid =
3099: &Apache::lonmsg::buildmsgid($stamp,$usersubj,
3100: $msgname,$msgdom,
3101: $msgcount,$context,
3102: $pid);
3103: &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
3104: $subj_prefix.' ['.$recipient.']',$msgsubj,
3105: undef,undef,$attachmenturl,undef,$usermsgid,undef,
3106: undef,$specialmsgid,undef,undef,undef,1);
3107: }
3108: }
3109: if (($mode ne 'upload') && (@recusers > 0)) {
3110: &Apache::lonmsg::process_sent_mail($msgsubj,
3111: $subj_prefix,$numsent,$stamp,$msgname,$msgdom,
3112: $msgcount,$context,$pid,$savemsg,\@recusers,
3113: \@recudoms,undef,$attachmenturl,'','','','',$recipid);
3114: }
3115: } else {
3116: &Apache::lonnet::logthis('Failed to create record of critical, broadcast or archived message in '.$env{'course.'.$env{'request.course.id'}.'.num'}.' '&mt('at').' '.$env{'course.'.$env{'request.course.id'}.'.domain'}.' - no msgid generated');
3117: }
3118: } else {
3119: my $stamp = time;
3120: my $msgcount = &Apache::lonmsg::get_uniq();
3121: my $context = &Apache::lonmsg::get_course_context();
3122: &Apache::lonmsg::process_sent_mail($msgsubj,$subj_prefix,
3123: $numsent,$stamp,$env{'user.name'},
3124: $env{'user.domain'},$msgcount,$context,
3125: $$,$savemsg,\@recusers,\@recudoms,undef,$attachmenturl,
3126: '','','','',$recipid);
3127: }
3128: }
3129: if (!$env{'form.multiforward'}) {
3130: if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
3131: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Completed.'));
3132: $message = &Apache::loncommon::confirmwrapper($message);
3133: $r->print($message);
3134: if ($env{'form.displayedcrit'}) {
3135: &discrit($r);
3136: }
3137: if ($group ne '') {
3138: $r->print(&groupmail_sent($group,$cdom,$cnum));
3139: } else {
3140: &Apache::loncommunicate::menu($r);
3141: }
3142: } else {
3143: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Could not deliver message'),1);
3144: $message .= '<br />'.&mt('Please use the browser "Back" button and correct the recipient addresses ([_1]).',$sendstatus);
3145: $message = &Apache::loncommon::confirmwrapper($message);
3146: $r->print($message);
3147: }
3148: }
3149: } else {
3150: &printheader($r,'','Messages cancelled.');
3151: return 'cancelled';
3152: }
3153: return $sendstatus;
3154: }
3155:
3156: # ===================================================================== Handler
3157:
3158: sub handler {
3159: my $r=shift;
3160:
3161: # ----------------------------------------------------------- Set document type
3162:
3163: &Apache::loncommon::content_type($r,'text/html');
3164: $r->send_http_header;
3165:
3166: return OK if $r->header_only;
3167:
3168: # --------------------------- Get query string for limited number of parameters
3169: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
3170: ['display','replyto','forward','markread','markdel','markunread',
3171: 'sendreply','compose','sendmail','critical','recname','recdom',
3172: 'recordftf','sortedby','folder','startdis','interdis',
3173: 'showcommentbaseurl','dismode','group','subject','text','ref',
3174: 'msgstatus']);
3175: $sqs='&sortedby='.$env{'form.sortedby'};
3176:
3177: # ------------------------------------------------------ They checked for email
3178: &Apache::lonnet::put('email_status',{'recnewemail'=>0});
3179:
3180: # ----------------------------------------------------------------- Breadcrumbs
3181:
3182: &Apache::lonhtmlcommon::clear_breadcrumbs();
3183: &Apache::lonhtmlcommon::add_breadcrumb
3184: ({href=>"/adm/communicate",
3185: text=>"Messages",
3186: faq=>12,bug=>'Communication Tools',});
3187:
3188: # ------------------------------------------------------------------ Get Folder
3189:
3190: my $folder=$env{'form.folder'};
3191: unless ($folder) {
3192: $folder='';
3193: } else {
3194: $sqs.='&folder='.&escape($folder);
3195: }
3196: # ------------------------------------------------------------ Get Display Mode
3197:
3198: my $dismode=$env{'form.dismode'};
3199: unless ($dismode) {
3200: $dismode='';
3201: } else {
3202: $sqs.='&dismode='.&escape($dismode);
3203: }
3204:
3205: # --------------------------------------------------------------------- Display
3206: my $msgstatus = $env{'form.msgstatus'};
3207: $startdis=$env{'form.startdis'};
3208: if ($startdis ne '') {
3209: $startdis--;
3210: }
3211: unless ($startdis) { $startdis=0; }
3212:
3213: if ($env{'form.firstview'}) {
3214: $startdis=0;
3215: }
3216: if ($env{'form.lastview'}) {
3217: $startdis=-1;
3218: }
3219: if ($env{'form.prevview'}) {
3220: $startdis--;
3221: }
3222: if ($env{'form.nextview'}) {
3223: $startdis++;
3224: }
3225: my $postedstartdis=$startdis+1;
3226: $sqs.='&startdis='.$postedstartdis;
3227:
3228: # --------------------------------------------------------------- Render Output
3229:
3230: if ($env{'form.display'}) {
3231: &displaymessage($r,$env{'form.display'},$folder,$msgstatus);
3232: } elsif ($env{'form.replyto'}) {
3233: &compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode);
3234: } elsif ($env{'form.confirm'}) {
3235: &printheader($r,'','Confirmed Receipt');
3236: my $replying = 0;
3237: foreach my $envkey (keys(%env)) {
3238: if ($envkey=~/^form\.(rep)?rec\_(.*)$/) {
3239: my $repchk = $1;
3240: my $msgid = $2;
3241: $r->print('<b>'.&mt('Confirming Receipt').':</b> ');
3242: my $result = &Apache::lonmsg::user_crit_received($msgid);
3243: if ($result =~ /trans:\s+ok/) {
3244: &statuschange($msgid,'read');
3245: }
3246: $r->print($result.'<br />');
3247: if ($repchk eq 'rep') {
3248: &compout($r,'','','',$msgid);
3249: $replying = 1;
3250: }
3251: }
3252: }
3253: if (!$replying) {
3254: &discrit($r);
3255: }
3256: } elsif ($env{'form.critical'}) {
3257: &printheader($r,'','Displaying Critical Messages');
3258: &discrit($r);
3259: } elsif ($env{'form.forward'}) {
3260: &compout($r,$env{'form.forward'},undef,undef,undef,$folder);
3261: } elsif ($env{'form.markdel'}) {
3262: &printheader($r,'','Deleted Message');
3263: my ($result,$msg) =
3264: &statuschange($env{'form.markdel'},'deleted',$folder);
3265: if (!$result) {
3266: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Failed to delete the message.'),1);
3267: $message .= '<p class="LC_error" style="font-size: inherit;">'.$msg.'</p>';
3268: $message = &Apache::loncommon::confirmwrapper($message);
3269: $r->print($message);
3270: }
3271: &Apache::loncommunicate::menu($r);
3272: &disall($r,($folder?$folder:$dismode),$msgstatus);
3273: } elsif ($env{'form.markedaction'} eq 'markedforward') {
3274: my $total = 0;
3275: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
3276: foreach my $msgid (@to_forward) {
3277: &statuschange(&unescape($msgid),'forwarded',$folder);
3278: $total ++;
3279: }
3280: if ($total > 0) {
3281: &compout($r,undef,undef,undef,undef,$folder,$dismode,$total);
3282: }
3283: } elsif ($env{'form.markedaction'} eq 'markedread') {
3284: my $total = 0;
3285: my @to_markread = &Apache::loncommon::get_env_multiple('form.delmark');
3286: foreach my $msgid (@to_markread) {
3287: &statuschange(&unescape($msgid),'read',$folder);
3288: $total ++;
3289: }
3290: &printheader($r,'','Marked Messages Read');
3291: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Marked [quant,_1,message] read',$total));
3292: $message = &Apache::loncommon::confirmwrapper($message);
3293: $r->print($message);
3294: # $r->print('<p>');
3295: &Apache::loncommunicate::menu($r);
3296: &disall($r,($folder?$folder:$dismode),$msgstatus);
3297: } elsif ($env{'form.markedaction'} eq 'markedunread') {
3298: my $total = 0;
3299: my @to_markunread = &Apache::loncommon::get_env_multiple('form.delmark');
3300: foreach my $msgid (@to_markunread) {
3301: &statuschange(&unescape($msgid),'new',$folder);
3302: $total ++;
3303: }
3304: &printheader($r,'','Marked Messages Unread');
3305: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Marked [quant,_1,message] unread',$total));
3306: $message = &Apache::loncommon::confirmwrapper($message);
3307: $r->print($message);
3308: # $r->print('<p>');
3309: &Apache::loncommunicate::menu($r);
3310: &disall($r,($folder?$folder:$dismode),$msgstatus);
3311: } elsif ($env{'form.markedaction'} eq 'markedmove') {
3312: my $destfolder = $env{'form.movetofolder'};
3313: my %gotfolders = &Apache::lonmsg::get_user_folders();
3314: &printheader($r,'','Moved Messages');
3315: if (!defined($gotfolders{$destfolder})) {
3316: $r->print(&mt('Destination folder [_1] is not a valid folder',
3317: '<span class="LC_filename">'.$destfolder.'</span>'));
3318: } else {
3319: my ($total,$failed,@failed_msg)=(0,0);
3320: my @to_move = &Apache::loncommon::get_env_multiple('form.delmark');
3321: foreach my $msgid (@to_move) {
3322: my ($result,$msg) = &movemsg(&unescape($msgid),$folder,
3323: $env{'form.movetofolder'});
3324: if ($result) {
3325: $total++;
3326: } else {
3327: $failed++;
3328: push(@failed_msg,$msg);
3329: }
3330: }
3331: my $message = '';
3332: if ($failed) {
3333: $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Failed to move [quant,_1,message]',$failed),1);
3334: $message .= '<p class="LC_error" style="font-size: inherit;">'.
3335: join("</p>\n<p class=\"LC_error\" style=\"font-size: inherit;\">",@failed_msg).
3336: "</p>\n";
3337: }
3338: $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Moved [quant,_1,message]',$total));
3339: $message = &Apache::loncommon::confirmwrapper($message);
3340: $r->print($message);
3341: # $r->print('<p>');
3342: }
3343: &Apache::loncommunicate::menu($r);
3344: &disall($r,($folder?$folder:$dismode),$msgstatus);
3345: } elsif ($env{'form.markedaction'} eq 'markeddel') {
3346: my ($total,$failed,@failed_msg)=(0,0);
3347: my @to_delete = &Apache::loncommon::get_env_multiple('form.delmark');
3348: foreach my $msgid (@to_delete) {
3349: my ($result,$msg) = &statuschange(&unescape($msgid),'deleted',
3350: $folder);
3351: if ($result) {
3352: $total++;
3353: } else {
3354: $failed++;
3355: push(@failed_msg,$msg);
3356: }
3357: }
3358: &printheader($r,'','Deleted Messages');
3359: my $message = '';
3360: if ($failed) {
3361: $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Failed to delete [quant,_1,message]',$failed),1);
3362: $message .= '<p class="LC_error" style="font-size: inherit;">'.
3363: join("</p>\n<p class=\"LC_error\" style=\"font-size: inherit;\">",@failed_msg).
3364: "</p>\n";
3365: }
3366: $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Deleted [quant,_1,message]',$total));
3367: $message = &Apache::loncommon::confirmwrapper($message);
3368: $r->print($message);
3369: # $r->print('<p>');
3370: &Apache::loncommunicate::menu($r);
3371: &disall($r,($folder?$folder:$dismode),$msgstatus);
3372: } elsif ($env{'form.markunread'}) {
3373: &printheader($r,'','Marked Message as Unread');
3374: &statuschange($env{'form.markunread'},'new');
3375: &Apache::loncommunicate::menu($r);
3376: &disall($r,($folder?$folder:$dismode),$msgstatus);
3377: } elsif ($env{'form.compose'}) {
3378: &compout($r,'','',$env{'form.compose'});
3379: } elsif ($env{'form.recordftf'}) {
3380: &facetoface($r,$env{'form.recordftf'});
3381: } elsif ($env{'form.sendmail'}) {
3382: if ($env{'form.multiforward'}) {
3383: &printheader($r,'','Messages being sent.');
3384: my $fixed_subj = $env{'form.subject'};
3385: my $suffix=&Apache::lonmsg::foldersuffix($folder);
3386: my (%sendresult,%forwardok,%forwardfail,$fwdcount);
3387: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
3388: foreach my $item (@to_forward) {
3389: my $msgid=&unescape($item);
3390: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
3391: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1,1);
3392: if ($env{'form.showorigsubj'}) {
3393: $env{'form.subject'} = $fixed_subj.$content{'subject'};
3394: } else {
3395: $env{'form.subject'} = '';
3396: }
3397: my $uname = $content{'sendername'};
3398: my $udom = $content{'senderdomain'};
3399: &statuschange($msgid,'forwarded',$folder);
3400: if ($env{'form.showorigsender'}) {
3401: $env{'form.message'} = $env{'form.msgheader'}.' '.
3402: &Apache::loncommon::plainname($uname,$udom).' ('.
3403: $uname.':'.$udom.')';
3404: }
3405: $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
3406: $content{'message'};
3407: $env{'form.attachmenturl'} = $content{'attachmenturl'};
3408: $env{'form.multiforwid'} = $item;
3409: $fwdcount ++;
3410: $r->print($fwdcount.': ');
3411: $sendresult{$msgid} = &sendoffmail($r,$folder);
3412: $r->print('<br />');
3413: }
3414: foreach my $key (keys(%sendresult)) {
3415: if ($sendresult{$key} =~/^(\s*(?:ok|con_delayed)\s*)*$/) {
3416: $forwardok{$key} = $sendresult{$key};
3417: } else {
3418: $forwardfail{$key} = $sendresult{$key};
3419: }
3420: }
3421: if (keys(%forwardok) > 0) {
3422: my $count = keys(%forwardok);
3423: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('[quant,_1,message] forwarded.',$count));
3424: $message = &Apache::loncommon::confirmwrapper($message);
3425: $r->print($message);
3426: }
3427: if (keys(%forwardfail) > 0) {
3428: my $count = keys(%forwardfail);
3429: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Could not forward [quant,_1,message].',$count),1);
3430: foreach my $key (keys(%forwardfail)) {
3431: $message .= '<br />'.&mt('Could not deliver forwarded message.').' ';
3432: if ($forwardfail{$key} eq 'blocked') {
3433: $message .= &mt('Sending messages is blocked from your IP address');
3434: } else {
3435: $message .= &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.')';
3436: }
3437: }
3438: $message = &Apache::loncommon::confirmwrapper($message);
3439: $r->print($message);
3440: }
3441: &Apache::loncommunicate::menu($r);
3442: } else {
3443: &sendoffmail($r,$folder);
3444: }
3445: if ($env{'form.storebasecomment'}) {
3446: &storecomment($r);
3447: }
3448: if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
3449: &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
3450: $env{'course.'.$env{'request.course.id'}.'.domain'},
3451: 'Course_Announcements',
3452: $env{'form.subject'},
3453: $env{'form.message'},'/adm/communicate','public');
3454: }
3455: if ((!exists($env{'form.group'})) && (!$env{'form.displayedcrit'})) {
3456: &disall($r,($folder?$folder:$dismode),$msgstatus);
3457: }
3458: } elsif ($env{'form.newfolder'}) {
3459: &printheader($r,'','New Folder');
3460: my $showfolder = $env{'form.newfolder'};
3461: my ($makeresult,$warning) = &makefolder($env{'form.newfolder'});
3462: if ($makeresult eq 'ok') {
3463: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" created.',$showfolder));
3464: $message = &Apache::loncommon::confirmwrapper($message);
3465: $r->print($message);
3466: } else {
3467: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Creation failed.').' '.$makeresult.'<br />'.$warning,1);
3468: $message = &Apache::loncommon::confirmwrapper($message);
3469: $r->print($message);
3470: $showfolder = $folder;
3471: }
3472: &Apache::loncommunicate::menu($r);
3473: &disall($r,$showfolder,$msgstatus);
3474: } elsif ($env{'form.showcommentbaseurl'}) {
3475: &storedcommentlisting($r);
3476: } elsif ($env{'form.folderaction'} eq 'delete') {
3477: &printheader($r,'','Deleted Folder');
3478: my $showfolder = '';
3479: my $delresult = &deletefolder($folder);
3480: if ($delresult eq 'ok') {
3481: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" deleted.',$folder));
3482: $message = &Apache::loncommon::confirmwrapper($message);
3483: $r->print($message);
3484: $env{'form.folder'} = '';
3485: } else {
3486: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Deletion failed.').' '.$delresult,1);
3487: $message = &Apache::loncommon::confirmwrapper($message);
3488: $r->print($message);
3489: $showfolder = $folder;
3490: }
3491: &Apache::loncommunicate::menu($r);
3492: &disall($r,$showfolder,$msgstatus);
3493: } elsif ($env{'form.folderaction'} eq 'rename') {
3494: &printheader($r,'','Renamed Folder');
3495: my $showfolder = $env{'form.renamed'};
3496: my $renresult = &renamefolder($folder);
3497: if ($renresult eq 'ok') {
3498: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" renamed to "[_2]".',$folder,$showfolder));
3499: $message = &Apache::loncommon::confirmwrapper($message);
3500: $r->print($message);
3501: } else {
3502: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Renaming failed.').' '.$renresult,1);
3503: $message = &Apache::loncommon::confirmwrapper($message);
3504: $r->print($message);
3505: $showfolder = $folder;
3506: }
3507: &Apache::loncommunicate::menu($r);
3508: &disall($r,$showfolder,$msgstatus);
3509: } else {
3510: &printheader($r,'','Display All Messages');
3511: &Apache::loncommunicate::menu($r);
3512: &disall($r,($folder?$folder:$dismode),$msgstatus);
3513: }
3514: $r->print(&Apache::loncommon::end_page());
3515: return OK;
3516: }
3517: # ================================================= Main program, reset counter
3518:
3519: =pod
3520:
3521: =cut
3522:
3523: 1;
3524:
3525: __END__
3526:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>