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