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