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