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