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