Annotation of loncom/interface/lonmsgdisplay.pm, revision 1.181.2.4
1.158 raeburn 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # Routines for messaging display
3: #
1.181.2.4! raeburn 4: # $Id: lonmsgdisplay.pm,v 1.181.2.3 2019/08/12 15:19:06 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.181.2.3 raeburn 1415: text => &mt('(1 MB max size)'),
1416: num => 1048576,
1.86 raeburn 1417: );
1418: if (!$forwarding && !$multiforward) {
1.181.2.3 raeburn 1419: $attachrow = '<tr><td colspan="3"><b>'.$lt{'atta'}.'</b> '.$attachmax{'text'}
1.181.2.4! raeburn 1420: .': <input type="file" name="attachment" class="LC_flUpload" />'
! 1421: .'<input type="hidden" id="LC_free_space" value="'.$attachmax{'num'}.'" />'
1.181.2.3 raeburn 1422: .'</td></tr>';
1.86 raeburn 1423: }
1.1 albertel 1424: if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
1425: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
1426: '/'.$env{'request.course.sec'})) {
1.138 raeburn 1427: my $crstype = &Apache::loncommon::course_type();
1.1 albertel 1428: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1.138 raeburn 1429: my $rsstxt;
1430: if (&Apache::loncommon::course_type() eq 'Community') {
1431: $rsstxt = &mt('Include in community RSS newsfeed');
1432: } else {
1433: $rsstxt = &mt('Include in course RSS newsfeed');
1434: }
1.1 albertel 1435: $dispcrit=
1.95 raeburn 1436: '<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 />'.
1437: '<label><input type="checkbox" name="permanent" /> '.
1.100 schafran 1438: &mt('Send copy to permanent e-mail address (if known)').'</label><br />'.
1.95 raeburn 1439: '<label><input type="checkbox" name="rsspost" /> '.
1.138 raeburn 1440: $rsstxt.'</label><br />';
1.70 raeburn 1441: }
1.71 raeburn 1442: if ($broadcast ne 'group') {
1443: if (&Apache::lonnet::allowed('dff',$env{'request.course.id'}) ||
1444: &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1445: '/'.$env{'request.course.sec'})) {
1446:
1.138 raeburn 1447: my $rectxt;
1448: if (&Apache::loncommon::course_type() eq 'Community') {
1449: $rectxt = &mt("Include in community's 'User records' for recipient(s)");
1450: } else {
1451: $rectxt = &mt("Include in course's 'User records' for recipient(s)");
1452: }
1453:
1.95 raeburn 1454: $dispcrit.='<label>'.
1.71 raeburn 1455: '<input type="checkbox" name="courserecord" value="1" /> '.
1.138 raeburn 1456: $rectxt.
1.95 raeburn 1457: '</label><br />';
1.71 raeburn 1458: }
1.70 raeburn 1459: }
1460:
1.1 albertel 1461: my %message;
1462: my %content;
1.95 raeburn 1463: my ($hasfloat,$broadcast_js,$sendmode,$can_grp_broadcast);
1.1 albertel 1464: my $defdom=$env{'user.domain'};
1.95 raeburn 1465: if ($broadcast eq 'group') {
1466: my %access_status = (
1467: active => 0,
1468: previous => 0,
1469: future => 0,
1470: );
1471:
1472: if ($group eq '') {
1473: my $studentsel = &discourse(\%access_status);
1474: if ($studentsel) {
1.154 raeburn 1475: $r->print('<div class="LC_left_float">'.$studentsel.'</div>');
1.95 raeburn 1476: $hasfloat = 1;
1477: }
1478: } else {
1479: $can_grp_broadcast = &check_group_priv($group);
1480: if ($can_grp_broadcast) {
1.105 raeburn 1481: $hasfloat = &disgroup($r,$cdom,$cnum,$group,\%access_status);
1.95 raeburn 1482: }
1483: }
1484: if ($hasfloat) {
1485: $sendmode = '<input type="hidden" name="sendmode" value="group" />'."\n";
1486: $broadcast_js = qq|
1487: <script type="text/javascript">
1.127 bisitz 1488: // <![CDATA[
1.95 raeburn 1489: function courseRecipients() {
1490: |;
1491: foreach my $type (keys(%access_status)) {
1492: if ($access_status{$type}) {
1493: my $formname = $type.'users';
1494: if ($type eq 'active' && $group ne '') {
1495: $broadcast_js .= qq|
1496: document.compemail.groupmail.value = document.$formname.groupmail[document.$formname.groupmail.selectedIndex].value;
1497: |;
1498: }
1.160 golterma 1499: #typeof(...forminput.length) returns 'undefined' if only one entry exists
1.95 raeburn 1500: $broadcast_js .= qq|
1501: if (typeof(document.$formname.selectedusers_forminput.length)=="undefined") {
1.160 golterma 1502: if (document.$formname.selectedusers_forminput.checked) {
1503: document.compemail.courserecips.value += '_&&&_'+document.$formname.selectedusers_forminput.value;
1504: }
1.95 raeburn 1505: } else {
1506: for (var i=0; i<document.$formname.selectedusers_forminput.length; i++) {
1507: if (document.$formname.selectedusers_forminput[i].checked) {
1508: document.compemail.courserecips.value += '_&&&_'+document.$formname.selectedusers_forminput[i].value;
1509: }
1510: }
1511: }
1512: |;
1513: }
1514: }
1515: $broadcast_js .= qq|
1516: return;
1517: }
1.127 bisitz 1518: // ]]>
1.95 raeburn 1519: </script>
1520:
1521: |;
1522: }
1523: }
1.1 albertel 1524: if ($forwarding) {
1525: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]);
1526: %content=&Apache::lonmsg::unpackagemsg($message{$forwarding},$folder);
1527: $dispcrit.='<input type="hidden" name="forwid" value="'.
1528: $forwarding.'" />';
1.94 bisitz 1529: $func1='Forward'; # do not translate here!
1.1 albertel 1530:
1531: $dissub=&mt('Forwarding').': '.$content{'subject'};
1532: $dismsg=&mt('Forwarded message from').' '.
1533: $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
1534: if ($content{'baseurl'}) {
1.29 www 1535: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1 albertel 1536: }
1537: }
1538: if ($replying) {
1539: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
1540: %content=&Apache::lonmsg::unpackagemsg($message{$replying},$folder);
1541: $dispcrit.='<input type="hidden" name="replyid" value="'.
1542: $replying.'" />';
1.94 bisitz 1543: $func1='Send Reply to'; # do not translate here!
1.1 albertel 1544:
1545: $dissub=&mt('Reply').': '.$content{'subject'};
1546: $dismsg='> '.$content{'message'};
1547: $dismsg=~s/\r/\n/g;
1548: $dismsg=~s/\f/\n/g;
1549: $dismsg=~s/\n+/\n\> /g;
1550: if ($content{'baseurl'}) {
1.29 www 1551: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1 albertel 1552: if ($env{'user.adv'}) {
1.72 albertel 1553: $disbase.='<label><input type="checkbox" name="storebasecomment" />'.&mt('Save message for re-use').
1.1 albertel 1554: '</label> <a href="/adm/email?showcommentbaseurl='.
1.29 www 1555: &escape($content{'baseurl'}).'" target="comments">'.
1.1 albertel 1556: &mt('Show re-usable messages').'</a><br />';
1557: }
1558: }
1.73 raeburn 1559: my $jscript = &Apache::loncommon::check_uncheck_jscript();
1560: $r->print(<<"ENDREPSCRIPT");
1561: <script type="text/javascript">
1.127 bisitz 1562: // <![CDATA[
1.73 raeburn 1563: $jscript
1.127 bisitz 1564: // ]]>
1.73 raeburn 1565: </script>
1566: ENDREPSCRIPT
1.1 albertel 1567: }
1568: my $citation=&displayresource(%content);
1.95 raeburn 1569: my $onsubmit;
1.1 albertel 1570: if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
1.23 www 1571: if ($env{'form.text'}) { $dismsg=$env{'form.text'}; }
1572: if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; }
1.95 raeburn 1573: if ($hasfloat) {
1.154 raeburn 1574: $r->print($broadcast_js.'<div class="LC_left_float">');
1.95 raeburn 1575: $onsubmit = ' onsubmit="javascript:courseRecipients();" ';
1576: }
1.23 www 1577: $r->print(
1.1 albertel 1578: '<form action="/adm/email" name="compemail" method="post"'.
1.95 raeburn 1579: ' enctype="multipart/form-data"'.$onsubmit.'>'."\n".
1580: '<input type="hidden" name="sendmail" value="on" />'."\n".
1581: '<table>');
1582: if (($broadcast eq 'group') && ($group ne '') && (!$can_grp_broadcast)) {
1.38 raeburn 1583: $r->print(&recipient_input_row($cdom,%lt));
1.95 raeburn 1584: }
1.38 raeburn 1585: if (($broadcast ne 'group') && ($broadcast ne 'upload')) {
1.1 albertel 1586: if ($replying) {
1.78 raeburn 1587: if ($content{'noreplies'}) {
1588: $r->print('<tr><td>'.&mt('This message was designated by the sender not to allow replies.').'</td></tr></table></form>');
1589: return;
1590: }
1.95 raeburn 1591: $r->print('<tr><td colspan="3"><b>'.&mt('Replying to').'</b> ');
1.78 raeburn 1592: if ($content{'replytoaddr'}) {
1593: my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
1594: if ($replytoname ne '' && $replytodom ne '') {
1595: $r->print(&Apache::loncommon::plainname($replytoname,
1596: $replytodom).' ('.$replytoname.':'.
1597: $replytodom.')');
1598: $r->print('<input type="hidden" name="recuname" value="'.
1599: $replytoname.'" />'.
1600: '<input type="hidden" name="recdomain" value="'.
1601: $replytodom.'" /></td></tr>');
1602:
1603: } else {
1604: $r->print(&mt('The sender did not designate a reply to address for this message.').'</td></tr></table>');
1605: return;
1606: }
1607: } else {
1608: $r->print(&Apache::loncommon::aboutmewrapper(
1.1 albertel 1609: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
1.14 albertel 1610: $content{'sendername'}.':'.
1.78 raeburn 1611: $content{'senderdomain'}.')');
1612: $r->print('<input type="hidden" name="recuname" value="'.
1613: $content{'sendername'}.'" />'.
1614: '<input type="hidden" name="recdomain" value="'.
1615: $content{'senderdomain'}.'" /></td></tr>');
1616: }
1.73 raeburn 1617: if ($content{'recipid'}) {
1.95 raeburn 1618: my %recips;
1619: &retrieve_recips('replying',\%content,\%recips);
1620: if (ref($recips{'to'}) eq 'ARRAY') {
1621: if (@{$recips{'to'}} > 0) {
1622: my $replyall;
1623: if (@{$recips{'to'}} > 1) {
1624: $replyall = qq|
1625: <span class="LC_nobreak">
1626: <input type="button" value="check all"
1627: onclick="javascript:checkAll(document.compemail.replying_to)" />
1628:
1629: <input type="button" value="uncheck all"
1630: onclick="javascript:uncheckAll(document.compemail.replying_to)" />
1631: </span>
1632: |;
1633: }
1634: my $tolist = join(' ',@{$recips{'to'}});
1635: $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>');
1636: }
1637: }
1638: if (ref($recips{'cc'}) eq 'ARRAY') {
1639: if (@{$recips{'cc'}} > 0) {
1640: my $replyall;
1641: if (@{$recips{'cc'}} > 1) {
1642: $replyall = qq|
1.73 raeburn 1643: <span class="LC_nobreak">
1644: <input type="button" value="check all"
1645: onclick="javascript:checkAll(document.compemail.replying_cc)" />
1646:
1647: <input type="button" value="uncheck all"
1648: onclick="javascript:uncheckAll(document.compemail.replying_cc)" />
1649: </span>
1650: |;
1.95 raeburn 1651: }
1652: my $cclist = join(' ',@{$recips{'cc'}});
1653: $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>');
1654: }
1655: }
1656: if ($content{'group'} ne '') {
1657: if (&check_group_priv($content{'group'})) {
1658: if (ref($recips{'group_cc_broadcast'}) eq 'ARRAY') {
1659: if (@{$recips{'group_cc_broadcast'}} > 0) {
1660: my $replyall;
1661: if (@{$recips{'group_cc_broadcast'}} > 1) {
1662: $replyall = qq|
1663: <span class="LC_nobreak">
1664: <input type="button" value="check all"
1665: onclick="javascript:checkAll(document.compemail.replying_groupcc)" />
1666:
1667: <input type="button" value="uncheck all"
1668: onclick="javascript:uncheckAll(document.compemail.replying_groupcc)" />
1669: </span>
1670: |;
1671: }
1672: my $groupcclist = join(' ',@{$recips{'group_cc_broadcast'}});
1673: $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>');
1674: }
1675: }
1676: }
1.73 raeburn 1677: }
1678: }
1.1 albertel 1679: } else {
1.38 raeburn 1680: $r->print(&recipient_input_row($defdom,%lt));
1.1 albertel 1681: }
1682: }
1.109 raeburn 1683: my $latexHelp = &Apache::loncommon::helpLatexCheatsheet(undef,undef,1);
1.154 raeburn 1684: my $textareaclass;
1685: if (&Apache::lonhtmlcommon::htmlareabrowser()) {
1686: $r->print(&Apache::lonhtmlcommon::htmlareaselectactive());
1687: $textareaclass = 'class="LC_richDefaultOff"';
1688: }
1.53 raeburn 1689: my $subj_size;
1690: if ($multiforward) {
1691: $r->print(&additional_rec_row(\%lt));
1692: $r->print('<tr><td colspan="2">'.
1693: &mt('Unless you choose otherwise:').'<ul><li>'.
1.166 raeburn 1694: &mt("The subject in each forwarded message will be [_1]'Forwarding:'[_2] followed by the original subject.",'<i>','</i>').'</li><li>'.
1.165 bisitz 1695: &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 1696: $func1='Forward'; # do not translate here!
1.53 raeburn 1697: $dissub = &mt('Forwarding').': ';
1698: $subj_size = '10';
1699: my $extra = '<'.&mt('original subject').'> '.
1700: '<input type="radio" name="showorigsubj" value="1" checked="checked" />'.&mt('Yes').' <input type="radio" name="showorigsubj" value="0" />'.&mt('No');
1701: $dismsg = &mt('Forwarded message from ').' ';
1702: my $sender = &mt("sender's name");
1703: $r->print(&msg_subject_row($dissub,\%lt,$subj_size,$extra));
1704: $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>
1705: </table>
1.95 raeburn 1706: <br /><table>
1707: <tr><td align="left">'."\n".
1708: $latexHelp."<br />\n".
1709: &mt("Any new text to display before the text of the original messages:").'<br />'."\n".
1.154 raeburn 1710: '<textarea name="message" id="message" cols="80" rows="5" wrap="hard" $textareaclass></textarea>');
1.53 raeburn 1711: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
1712: foreach my $msg (@to_forward) {
1713: $r->print('<input type="hidden" name="delmark" value="'.$msg.'" />');
1714: }
1.94 bisitz 1715: $r->print(&submit_button_row($folder,$dismode,&mt($func1.' '.$func2{'msg'}),
1.53 raeburn 1716: \%lt));
1717: } elsif ($broadcast ne 'upload') {
1718: $subj_size = '50';
1719: $r->print(&additional_rec_row(\%lt));
1.78 raeburn 1720: if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
1721: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
1722: '/'.$env{'request.course.sec'})) {
1723: $r->print(&reply_to_row(\%lt));
1724: }
1.53 raeburn 1725: $r->print(&msg_subject_row($dissub,\%lt,$subj_size));
1726: $r->print(<<"ENDCOMP");
1.95 raeburn 1727: $attachrow
1728: </table><br />
1.117 bisitz 1729: $latexHelp<br />
1.154 raeburn 1730: <textarea name="message" id="message" cols="80" rows="15" wrap="hard" $textareaclass>$dismsg
1731: </textarea>
1732: <br />
1.95 raeburn 1733: $sendmode
1.1 albertel 1734: $dispcrit
1735: $disbase
1736: ENDCOMP
1.97 schafran 1737: $r->print(&submit_button_row($folder,$dismode,&mt($func1.' '.$func2{'ma'}),
1.95 raeburn 1738: \%lt,$hasfloat,$group));
1.53 raeburn 1739: $r->print($citation);
1.38 raeburn 1740: if (exists($env{'form.ref'})) {
1741: $r->print('<input type="hidden" name="ref" value="'.
1742: $env{'form.ref'}.'" />');
1743: }
1744: if (exists($env{'form.group'})) {
1745: $r->print('<input type="hidden" name="group" value="'.
1746: $env{'form.group'}.'" />');
1747: }
1.1 albertel 1748: } else { # $broadcast is 'upload'
1.50 raeburn 1749: $r->print(<<ENDBLOCK);
1.1 albertel 1750: <input type="hidden" name="sendmode" value="upload" />
1751: <input type="hidden" name="send" value="on" />
1.50 raeburn 1752: <h3>$lt{'gen'}</h3>
1.1 albertel 1753: <p>
1754: Subject: <input type="text" size="50" name="subject" />
1755: </p>
1.50 raeburn 1756: <p>$lt{'gmt'}:<br />
1.154 raeburn 1757: <textarea name="message" id="message" cols="60" rows="10" wrap="hard" $textareaclass>$dismsg
1758: </textarea></p>
1.1 albertel 1759: <p>
1.50 raeburn 1760: $lt{'tff'}:
1761: ENDBLOCK
1762: $r->print('
1763: <pre>'."\n".
1764: &mt('username1:domain1: text')."\n".
1765: &mt('username2:domain2: text')."\n".
1766: &mt('username3:domain1: text')."\n".
1767: '</pre>
1.1 albertel 1768: </p>
1769: <p>
1.164 bisitz 1770: '.&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 1771: $r->print(<<ENDUPLOAD);
1772: </p>
1.1 albertel 1773: <p>
1774: <input type="file" name="upfile" size="40" /></p><p>
1775: $dispcrit
1.50 raeburn 1776: <input type="submit" value="$lt{'uas'}" /></p>
1.1 albertel 1777: ENDUPLOAD
1778: }
1.36 albertel 1779: if ($env{'form.displayedcrit'}) {
1780: $r->print('<input type="hidden" name="displayedcrit" value="true" />');
1781: }
1.95 raeburn 1782: $r->print('</form>');
1783: if ($hasfloat) {
1.154 raeburn 1784: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.95 raeburn 1785: }
1786: $r->print(&generate_preview_form);
1787: }
1788:
1789: sub check_group_priv {
1790: my ($group) = @_;
1791: my $cid = $env{'request.course.id'};
1792: my $sec = $env{'request.course.sec'};
1793: return if !$cid;
1794: my $can_broadcast = &Apache::lonnet::allowed('sgb',$cid.'/'.$group);
1795: my $viewgrps = &Apache::lonnet::allowed('vcg',$cid.($sec?'/'.$sec:''));
1796: my $editgrps = &Apache::lonnet::allowed('mdg',$cid.($sec?'/'.$sec:''));
1797: if ($viewgrps || $editgrps || $can_broadcast) {
1798: return 1;
1799: }
1800: return;
1.1 albertel 1801: }
1802:
1.38 raeburn 1803: sub recipient_input_row {
1804: my ($dom,%lt) = @_;
1805: my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain');
1806: my $selectlink=
1807: &Apache::loncommon::selectstudent_link('compemail','recuname',
1808: 'recdomain');
1809: my $output = <<"ENDREC";
1.95 raeburn 1810: <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 1811: ENDREC
1812: return $output;
1813: }
1814:
1.78 raeburn 1815: sub reply_to_row {
1816: my ($lt) = @_;
1817: my $radioyes = &mt('Yes');
1818: my $radiono = &mt('No');
1819: my $output = <<"ENDREP";
1.95 raeburn 1820: <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 1821: ENDREP
1822: return $output;
1823: }
1824:
1.53 raeburn 1825: sub additional_rec_row {
1826: my ($lt) = @_;
1.73 raeburn 1827: my $cc = &mt('Cc:');
1.85 bisitz 1828: my $bcc = &mt('Bcc:');
1829: my $exmpl = &mt('username:domain,username:domain,...');
1.53 raeburn 1830: my $output = <<"ENDADD";
1.125 bisitz 1831: <tr><td colspan="3"><fieldset id="LC_additionalrecips"><legend>$lt->{'ad'} <tt>($exmpl)</tt></legend><table>
1.95 raeburn 1832: <tr><td> </td><td>$lt->{'to'}</td><td><input type="text" size="50" name="additionalrec_to" /></td></tr>
1833: <tr><td> </td><td>$cc</td><td><input type="text" size="50" name="additionalrec_cc" /></td></tr>
1.110 raeburn 1834: <tr><td> </td><td>$bcc</td><td><input type="text" size="50" name="additionalrec_bcc" /></td></tr></table></fieldset></td></tr>
1.53 raeburn 1835: ENDADD
1836: return $output;
1837: }
1838:
1839: sub submit_button_row {
1.95 raeburn 1840: my ($folder,$dismode,$sendtext,$lt,$is_crsform,$group) = @_;
1841: my $pre=&mt("Show Preview and Check Spelling");
1.98 schafran 1842: my $value=&mt('Send');
1.95 raeburn 1843: 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();" />';
1844: my $output = qq|
1.53 raeburn 1845: <input type="hidden" name="folder" value="$folder" />
1.95 raeburn 1846: <input type="hidden" name="dismode" value="$dismode" />|;
1847: if ($is_crsform) {
1848: $output .= '<input type="hidden" name="courserecips" value="" />'."\n";
1849: if ($group ne '') {
1850: $output .= '<input type="hidden" name="groupmail" value="" />'."\n";
1851: }
1852: }
1853: $output .= qq|
1854: <table><tr><td align="left">
1.98 schafran 1855: <input type="submit" name="send" value="$value" title="$sendtext" />
1.95 raeburn 1856: <input type="submit" name="cancel" value="$lt->{'ca'}" />
1857: </td><td width="60"> </td><td align="right">$prevbutton</td></tr></table>
1.53 raeburn 1858: |;
1859: return $output;
1860: }
1861:
1862: sub msg_subject_row {
1863: my ($dissub,$lt,$subj_size,$extra) = @_;
1.95 raeburn 1864: my $output = '<tr><td colspan="3"><b>'.$lt->{'sb'}.'</b>: <input type="text" size="'.
1.53 raeburn 1865: $subj_size.'" name="subject" value="'.$dissub.'" />'.$extra.
1866: '</td></tr>';
1867: return $output;
1868: }
1869:
1.95 raeburn 1870: sub generate_preview_form {
1871: my $prevbutton = (<<ENDPREVIEW);
1872: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1873: <input type="hidden" name="subject" />
1874: <input type="hidden" name="comment" />
1875: </form>
1876: ENDPREVIEW
1877: }
1878:
1879: # ---------------------------------------------------- Display all face to face
1880:
1.1 albertel 1881: sub retrieve_instructor_comments {
1882: my ($user,$domain)=@_;
1883: my $target=$env{'form.grade_target'};
1884: if (! $env{'request.course.id'}) { return; }
1.49 albertel 1885: if (! &Apache::lonnet::allowed('dff',$env{'request.course.id'})
1886: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1887: '/'.$env{'request.course.sec'})) {
1888: return;
1889: }
1890: my %records=&Apache::lonnet::dump('nohist_email',
1891: $env{'course.'.$env{'request.course.id'}.'.domain'},
1892: $env{'course.'.$env{'request.course.id'}.'.num'},
1893: '%255b'.$user.'%253a'.$domain.'%255d');
1894: my $result='';
1.42 raeburn 1895: foreach my $key (sort(keys(%records))) {
1896: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1 albertel 1897: next if ($content{'senderdomain'} eq '');
1898: next if ($content{'subject'} !~ /^Record/);
1899: # &Apache::lonfeedback::newline_to_br(\$content{'message'});
1900: $result.='Recorded by '.
1.14 albertel 1901: $content{'sendername'}.':'.$content{'senderdomain'}."\n";
1.1 albertel 1902: $result.=
1903: &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
1904: }
1905: return $result;
1906: }
1907:
1908: sub disfacetoface {
1.136 amueller 1909: my ($r,$user,$domain,$target)=@_;
1.145 raeburn 1910: if ($target eq '') {
1911: $target=$env{'form.grade_target'};
1912: }
1.1 albertel 1913: unless ($env{'request.course.id'}) { return; }
1.49 albertel 1914: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
1915: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1916: '/'.$env{'request.course.sec'})) {
1.50 raeburn 1917: $r->print(&mt('Not allowed'));
1.1 albertel 1918: return;
1919: }
1920: my %records=&Apache::lonnet::dump('nohist_email',
1921: $env{'course.'.$env{'request.course.id'}.'.domain'},
1922: $env{'course.'.$env{'request.course.id'}.'.num'},
1923: '%255b'.$user.'%253a'.$domain.'%255d');
1.177 raeburn 1924: my $result='';
1.42 raeburn 1925: foreach my $key (sort(keys(%records))) {
1926: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1 albertel 1927: next if ($content{'senderdomain'} eq '');
1.139 faziophi 1928: if (!&Apache::lonfeedback::contains_block_html($content{'message'})) {
1929: &Apache::lonfeedback::newline_to_br(\$content{'message'});
1930: }
1.1 albertel 1931: if ($content{'subject'}=~/^Record/) {
1932: $result.='<h3>'.&mt('Record').'</h3>';
1933: } elsif ($content{'subject'}=~/^Broadcast/) {
1934: $result .='<h3>'.&mt('Broadcast Message').'</h3>';
1935: if ($content{'subject'}=~/^Broadcast\./) {
1936: if (defined($content{'coursemsgid'})) {
1.29 www 1937: my $crsmsgid = &escape($content{'coursemsgid'});
1.1 albertel 1938: my $broadcast_message = &general_message($crsmsgid);
1939: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$broadcast_message;
1940: } else {
1941: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1942: $content{'message'} =
1943: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1944: $content{'message'};
1945: }
1.70 raeburn 1946: }
1947: } elsif ($content{'subject'}=~/^Archive/) {
1948: $result.='<h3>'.&mt('Archived Message').'</h3>';
1949: if (defined($content{'coursemsgid'})) {
1950: my $crsmsgid = &escape($content{'coursemsgid'});
1951: my $archive_message = &general_message($crsmsgid);
1952: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$archive_message;
1953: } else {
1954: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1955: $content{'message'} =
1.170 bisitz 1956: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1.70 raeburn 1957: $content{'message'};
1958: }
1.1 albertel 1959: } else {
1960: $result.='<h3>'.&mt('Critical Message').'</h3>';
1961: if (defined($content{'coursemsgid'})) {
1.29 www 1962: my $crsmsgid=&escape($content{'coursemsgid'});
1.1 albertel 1963: my $critical_message = &general_message($crsmsgid);
1964: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$critical_message;
1965: } else {
1966: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1967: $content{'message'}=
1968: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1969: $content{'message'};
1970: }
1971: }
1972: $result.=&mt('By').': <b>'.
1973: &Apache::loncommon::aboutmewrapper(
1974: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14 albertel 1975: $content{'sendername'}.':'.
1.1 albertel 1976: $content{'senderdomain'}.') '.$content{'time'}.
1977: '<br /><pre>'.
1978: &Apache::lontexconvert::msgtexconverted($content{'message'}).
1979: '</pre>';
1980: }
1981: # Check to see if there were any messages.
1982: if ($result eq '') {
1.106 riegler 1983: my $lctype = &mt(lc(&Apache::loncommon::course_type()));
1.1 albertel 1984: if ($target ne 'tex') {
1.174 bisitz 1985: $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 1986: } else {
1.174 bisitz 1987: $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this '.$lctype.'.').'}\\\\');
1.1 albertel 1988: }
1.177 raeburn 1989: } elsif ($target eq 'tex') {
1990: $r->print(&Apache::lonxml::xmlparse($r,$target,$result));
1.1 albertel 1991: } else {
1.177 raeburn 1992: $r->print('<div>'.$result.'</div>');
1993: }
1.1 albertel 1994: }
1995:
1996: sub general_message {
1997: my ($crsmsgid) = @_;
1998: my %general_content;
1999: if ($crsmsgid) {
2000: my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid],
2001: $env{'course.'.$env{'request.course.id'}.'.domain'},
2002: $env{'course.'.$env{'request.course.id'}.'.num'});
2003: %general_content = &Apache::lonmsg::unpackagemsg($course_content{$crsmsgid});
2004: }
2005: return $general_content{'message'};
2006: }
2007:
2008: # ---------------------------------------------------------------- Face to face
2009:
2010: sub facetoface {
2011: my ($r,$stage)=@_;
1.49 albertel 2012: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
2013: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 2014: '/'.$env{'request.course.sec'})) {
1.50 raeburn 2015: $r->print(&mt('Not allowed'));
1.1 albertel 2016: return;
2017: }
1.33 albertel 2018: my $crstype = &Apache::loncommon::course_type();
1.128 raeburn 2019: my $leaders = ($crstype eq 'Community') ? 'coordinators and leaders'
2020: : 'faculty and staff';
1.1 albertel 2021: &printheader($r,
2022: '/adm/email?recordftf=query',
1.70 raeburn 2023: "User Notes, Face-to-Face, Critical Messages, Broadcast Messages, Archived Messages");
1.1 albertel 2024: # from query string
2025:
2026: if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
2027: if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
2028:
2029: my $defdom=$env{'user.domain'};
2030: # already filled in
2031: if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
2032: # generate output
2033: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
2034: my $stdbrws = &Apache::loncommon::selectstudent_link
2035: ('stdselect','recuname','recdomain');
2036: my %lt=&Apache::lonlocal::texthash('user' => 'Username',
2037: 'dom' => 'Domain',
1.70 raeburn 2038: 'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, Broadcast Messages and Archived Messages in $crstype",
1.1 albertel 2039: 'subm' => 'Retrieve discussion and message records',
1.30 raeburn 2040: 'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')',
1.1 albertel 2041: 'post' => 'Post this Record');
1.123 bisitz 2042:
2043: $r->print('<h2>'.$lt{'head'}.'</h2>'
2044: .'<form method="post" action="/adm/email" name="stdselect">'
2045: .'<input type="hidden" name="recordftf" value="retrieve" />'
2046: .&Apache::lonhtmlcommon::start_pick_box()
2047: .&Apache::lonhtmlcommon::row_title($lt{'user'})
2048: .'<input type="text" size="12" name="recuname" value="'.$env{'form.recuname'}.'" />'
2049: .' '.$stdbrws
2050: .&Apache::lonhtmlcommon::row_closure()
2051: .&Apache::lonhtmlcommon::row_title($lt{'dom'})
2052: .$domform
2053: .&Apache::lonhtmlcommon::row_closure(1)
2054: .&Apache::lonhtmlcommon::end_pick_box()
2055: .'<br />'
2056: .'<input type="submit" value="'.$lt{'subm'}.'" />'
1.150 raeburn 2057: .'</form>'
1.123 bisitz 2058: );
2059:
1.1 albertel 2060: if (($stage ne 'query') &&
2061: ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
2062: chomp($env{'form.newrecord'});
2063: if ($env{'form.newrecord'}) {
1.31 albertel 2064: &Apache::lonmsg::store_instructor_comment($env{'form.newrecord'},
2065: $env{'form.recuname'},
2066: $env{'form.recdomain'});
1.1 albertel 2067: }
1.123 bisitz 2068: my $aboutmelink=&Apache::loncommon::aboutmewrapper(
2069: &Apache::loncommon::plainname($env{'form.recuname'}
2070: ,$env{'form.recdomain'})
2071: ,$env{'form.recuname'},$env{'form.recdomain'});
2072: $r->print('<hr />'
2073: .'<h2>'
2074: .&mt('Discussion and message records for [_1] ([_2])'
2075: ,$aboutmelink
2076: ,$env{'form.recuname'}.':'.$env{'form.recdomain'})
1.161 bisitz 2077: .'</h2>'
1.123 bisitz 2078: );
1.1 albertel 2079: &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
2080: $r->print(<<ENDRHEAD);
2081: <form method="post" action="/adm/email">
2082: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
2083: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
2084: ENDRHEAD
2085: $r->print(<<ENDBFORM);
2086: <hr />$lt{'newr'}<br />
2087: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
2088: <br />
2089: <input type="hidden" name="recordftf" value="post" />
2090: <input type="submit" value="$lt{'post'}" />
2091: </form>
2092: ENDBFORM
2093: }
2094: }
2095:
2096: # ----------------------------------------------------------- Display a message
2097:
2098: sub displaymessage {
1.53 raeburn 2099: my ($r,$msgid,$folder,$msgstatus)=@_;
1.1 albertel 2100: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2101: my %blocked = ();
2102: my %setters = ();
2103: my $numblocked = 0;
1.33 albertel 2104: my $crstype = &Apache::loncommon::course_type();
1.30 raeburn 2105:
1.1 albertel 2106: # info to generate "next" and "previous" buttons and check if message is blocked
1.44 raeburn 2107: my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53 raeburn 2108: my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1 albertel 2109: if ( $blocked{$msgid} eq 'ON' ) {
2110: &printheader($r,'/adm/email',&mt('Display a Message'));
1.129 kalberla 2111: #$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 2112: my($blocked, $blocktext) = &Apache::loncommon::blocking_status("com");
1.129 kalberla 2113: $r->print("<br />".$blocktext);
1.1 albertel 2114: return;
2115: }
1.59 raeburn 2116: if ($msgstatus eq '') {
2117: &statuschange($msgid,'read',$folder);
2118: }
1.1 albertel 2119: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2120: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid});
2121: my $counter=0;
1.29 www 2122: my $escmsgid=&escape($msgid);
1.1 albertel 2123: foreach (@messages) {
2124: if ($_->[5] eq $escmsgid){
2125: last;
2126: }
2127: $counter++;
2128: }
1.82 albertel 2129:
2130: my $see_anonymous;
2131: my $from_student = 0;
2132: if ($env{'request.course.id'} eq $content{'courseid'}) {
2133: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2134: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2135: my $username = $content{'sendername'}.':'.$content{'senderdomain'};
2136: my %classlist_entry =
2137: &Apache::lonnet::get('classlist',[$username],$cdom,$cnum);
2138: if (exists($classlist_entry{$username})) {
2139: $from_student = 1;
2140: $see_anonymous = &Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
2141: }
2142: }
2143:
2144:
1.1 albertel 2145: my $number_of_messages = scalar(@messages); #subtract 1 for last index
2146: # start output
1.29 www 2147: &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'});
1.101 bisitz 2148:
2149: # Prepare available functions
1.119 bisitz 2150: my @functionlist;
1.78 raeburn 2151: if (!$content{'noreplies'}) {
1.119 bisitz 2152: push(@functionlist,'<a href="/adm/email?replyto='.&escape($msgid).$sqs.'">'
1.101 bisitz 2153: .&mt('Reply')
1.119 bisitz 2154: .'</a>');
1.101 bisitz 2155: }
1.119 bisitz 2156: push(@functionlist,'<a href="/adm/email?forward='.&escape($msgid).$sqs.'">'
1.101 bisitz 2157: .&mt('Forward')
1.119 bisitz 2158: .'</a>');
2159: push(@functionlist,'<a href="/adm/email?markunread='.&escape($msgid).$sqs.'">'
1.101 bisitz 2160: .&mt('Mark Unread')
1.119 bisitz 2161: .'</a>');
2162: push(@functionlist,'<a href="/adm/email?markdel='.&escape($msgid).$sqs.'">'
1.101 bisitz 2163: .&mt('Delete')
1.119 bisitz 2164: .'</a>');
1.162 bisitz 2165:
2166: # Prepare available navigation
2167: my @navigationlist;
1.1 albertel 2168: if ($counter > 0){
1.162 bisitz 2169: push(@navigationlist,'<a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.'">'
1.119 bisitz 2170: .&mt('Previous')
2171: .'</a>');
1.1 albertel 2172: }
2173: if ($counter < $number_of_messages - 1){
1.162 bisitz 2174: push(@navigationlist,'<a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.'">'
1.119 bisitz 2175: .&mt('Next')
2176: .'</a>');
1.101 bisitz 2177: }
1.162 bisitz 2178: push(@navigationlist,'<a href="/adm/email?'.$sqs.'">'
2179: .&mt('Back to Folder Display')
2180: .'</a>');
1.101 bisitz 2181:
2182: # Prepare available actions
1.59 raeburn 2183: my $symb;
2184: if (defined($content{'symb'})) {
2185: $symb = $content{'symb'};
2186: } elsif (defined($content{'baseurl'})) {
2187: $symb=&Apache::lonnet::symbread($content{'baseurl'});
2188: }
1.162 bisitz 2189: my @actionlist;
1.1 albertel 2190: if ($env{'user.adv'}) {
1.101 bisitz 2191:
1.181.2.1 raeburn 2192: if (($env{'request.course.id'}) && ($from_student) &&
2193: (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
1.119 bisitz 2194: push(@actionlist,&Apache::loncommon::track_student_link(
1.171 bisitz 2195: 'View recent activity'
1.119 bisitz 2196: ,$content{'sendername'}
2197: ,$content{'senderdomain'}
2198: ,'check'));
1.90 bisitz 2199: }
1.1 albertel 2200: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
1.119 bisitz 2201: push(@actionlist,&Apache::loncommon::pprmlink(
2202: &mt('Set/Change parameters')
2203: ,$content{'sendername'}
2204: ,$content{'senderdomain'}
2205: ,$symb
2206: ,'check'));
1.1 albertel 2207: }
2208: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
1.119 bisitz 2209: push(@actionlist,&Apache::loncommon::pgrdlink(
2210: &mt('Set/Change grades')
2211: ,$content{'sendername'}
2212: ,$content{'senderdomain'}
2213: ,$symb
2214: ,'check'));
1.90 bisitz 2215: }
1.126 bisitz 2216: }
2217:
1.162 bisitz 2218: # Print functionlist, navigationlist, and actionlist in page header
1.126 bisitz 2219: my $functions='<div class="LC_columnSection">';
1.101 bisitz 2220:
1.126 bisitz 2221: # Functionlist
2222: $functions.=&Apache::lonhtmlcommon::start_funclist();
2223: foreach my $item (@functionlist) {
2224: $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
2225: }
2226: $functions .= &Apache::lonhtmlcommon::end_funclist();
2227:
1.162 bisitz 2228: # Navigationlist
2229: $functions.=&Apache::lonhtmlcommon::start_funclist(
2230: &mt('Navigation'));
2231: foreach my $item (@navigationlist) {
2232: $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
2233: }
2234: $functions .= &Apache::lonhtmlcommon::end_funclist();
2235:
1.126 bisitz 2236: # Actionlist
1.119 bisitz 2237: if (@actionlist) {
1.162 bisitz 2238: $functions.=&Apache::lonhtmlcommon::start_funclist(
2239: &mt('Currently available actions (will open extra window)'));
1.119 bisitz 2240: foreach my $item (@actionlist) {
1.126 bisitz 2241: $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
1.119 bisitz 2242: }
1.126 bisitz 2243: $functions.=&Apache::lonhtmlcommon::end_funclist();
1.90 bisitz 2244: }
1.126 bisitz 2245:
2246: $functions.='</div>';
2247: $r->print(&Apache::loncommon::head_subbox($functions));
2248:
1.101 bisitz 2249:
1.95 raeburn 2250: my ($tonum,$tolist,$cclist,$bcclist,$groupcclist,%recipients);
2251: if ($content{'recipid'}) {
2252: $tonum = &retrieve_recips('display',\%content,\%recipients);
2253: if (ref($recipients{'cc'}) eq 'ARRAY') {
2254: $cclist = join(', ',@{$recipients{'cc'}});
2255: }
2256: if (ref($recipients{'to'}) eq 'ARRAY') {
2257: $tolist = join(', ',@{$recipients{'to'}});
2258: }
2259: if (ref($recipients{'bcc'}) eq 'ARRAY') {
2260: $bcclist = join(', ',@{$recipients{'bcc'}});
2261: }
2262: }
1.107 raeburn 2263:
2264: my $broadcast_link;
2265: if (($content{'courseid'}) && ($content{'recipid'} &&
2266: (ref($recipients{'course_broadcast'}) eq 'ARRAY') ||
2267: (ref($recipients{'group_cc_broadcast'}) eq 'ARRAY') ||
2268: (ref($recipients{'group_bcc_broadcast'}) eq 'ARRAY'))) {
2269: $broadcast_link = &recipients_link($r,\%content,\%recipients);
2270: }
2271:
2272: if (((!$tolist) && (!$broadcast_link)) && ref($content{'recuser'}) eq 'ARRAY') {
1.95 raeburn 2273: my @recipients;
1.73 raeburn 2274: for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
2275: $recipients[$i] = &Apache::loncommon::aboutmewrapper(
2276: &Apache::loncommon::plainname($content{'recuser'}[$i],
1.1 albertel 2277: $content{'recdomain'}[$i]),
1.73 raeburn 2278: $content{'recuser'}[$i],$content{'recdomain'}[$i]).
1.95 raeburn 2279: ' ('.$content{'recuser'}[$i].':'.$content{'recdomain'}[$i].') ';
1.73 raeburn 2280: }
1.95 raeburn 2281: $tolist = join(', ',@recipients);
1.73 raeburn 2282: }
1.59 raeburn 2283: my ($restitle,$baseurl,$refers_to);
2284: if (defined($content{'resource_title'})) {
2285: $restitle = $content{'resource_title'};
2286: } else {
2287: if (defined($content{'baseurl'})) {
2288: $restitle = &Apache::lonnet::gettitle($content{'baseurl'});
2289: }
2290: }
2291: if (defined($content{'baseurl'})) {
2292: $baseurl = &Apache::lonenc::check_encrypt($content{'baseurl'});
2293: }
1.104 raeburn 2294: $r->print('<div class="LC_clear_float_footer">');
1.82 albertel 2295: if ($from_student && $see_anonymous ) {
1.104 raeburn 2296: $r->print(&Apache::loncommon::student_image_tag($content{'senderdomain'},$content{'sendername'}).'</br>');
1.82 albertel 2297: }
2298:
1.91 bisitz 2299: # Display LON-CAPA Message (Start)
2300: # Subject
1.104 raeburn 2301: $r->print('</div>'
1.91 bisitz 2302: .&Apache::lonhtmlcommon::start_pick_box()
2303: .&Apache::lonhtmlcommon::row_title(&mt('Subject'))
2304: .$content{'subject'}
2305: .&Apache::lonhtmlcommon::row_closure()
2306: );
1.73 raeburn 2307: if ($folder eq 'sent') {
1.91 bisitz 2308: # To
1.107 raeburn 2309: if ($tolist) {
2310: $r->print(&Apache::lonhtmlcommon::row_title(&mt('To'))
2311: .$tolist
2312: .&Apache::lonhtmlcommon::row_closure()
2313: );
2314: }
1.95 raeburn 2315: if ($cclist) {
2316: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Cc'))
2317: .$cclist
2318: .&Apache::lonhtmlcommon::row_closure()
2319: );
2320: }
2321: if ($bcclist) {
2322: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Bcc'))
2323: .$bcclist
2324: .&Apache::lonhtmlcommon::row_closure()
2325: );
2326: }
2327: if (($content{'courseid'}) && ($content{'recipid'})) {
2328: my %broadcast_types =
2329: &Apache::lonlocal::texthash (
2330: course_broadcast => 'Broadcast to',
2331: group_cc_broadcast => 'Cc to group',
2332: group_bcc_broadcast => 'Bcc to group',
2333: );
2334: foreach my $type (sort(keys(%broadcast_types))) {
2335: if (ref($recipients{$type}) eq 'ARRAY') {
2336: my $num = @{$recipients{$type}};
2337: my $broadcastlist = join(', ',@{$recipients{$type}});
2338: if ($broadcastlist && $broadcast_link) {
2339: if ($type eq 'group_cc_broadcast') {
2340: $groupcclist = $broadcastlist;
2341: }
2342: $r->print(&Apache::lonhtmlcommon::row_title(
2343: $broadcast_types{$type})
2344: .&mt('[quant,_1,recipient]',$num)
2345: .' <a href="javascript:showBroadcastList();">['
2346: .&mt('Show').']</a>'
2347: .&Apache::lonhtmlcommon::row_closure());
2348: }
2349: }
2350: }
2351: }
1.78 raeburn 2352: if ($content{'replytoaddr'}) {
2353: my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
2354: if ($replytoname ne '' && $replytodom ne '') {
1.91 bisitz 2355: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Reply To'))
1.95 raeburn 2356: .$replytoname.':'.$replytodom
1.91 bisitz 2357: .&Apache::lonhtmlcommon::row_closure()
2358: );
1.78 raeburn 2359: }
2360: }
1.73 raeburn 2361: } else {
1.91 bisitz 2362: # From, Reply
2363: $r->print(&Apache::lonhtmlcommon::row_title(&mt('From'))
2364: .&Apache::loncommon::aboutmewrapper(
2365: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
2366: $content{'sendername'},$content{'senderdomain'})
2367: );
1.78 raeburn 2368: if ($content{'noreplies'}) {
1.91 bisitz 2369: $r->print(' ('.&mt('No replies to sender').')'
2370: .&Apache::lonhtmlcommon::row_closure()
1.95 raeburn 2371: );
1.78 raeburn 2372: } else {
2373: if ($content{'replytoaddr'}) {
2374: my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
2375: if ($replytoname ne '' && $replytodom ne '') {
1.91 bisitz 2376: $r->print(&Apache::lonhtmlcommon::row_closure()
2377: .&Apache::lonhtmlcommon::row_title(&mt('Reply To'))
1.95 raeburn 2378: .$replytoname.':'.$replytodom
1.91 bisitz 2379: .&Apache::lonhtmlcommon::row_closure()
2380: );
2381: } else {
2382: $r->print(&Apache::lonhtmlcommon::row_closure());
1.78 raeburn 2383: }
2384: } else {
1.95 raeburn 2385: $r->print(' ('.$content{'sendername'}.':'.$content{'senderdomain'}.') '
1.91 bisitz 2386: .&Apache::lonhtmlcommon::row_closure()
2387: );
1.78 raeburn 2388: }
1.95 raeburn 2389: if ($tonum && $tolist) {
2390: $r->print(&Apache::lonhtmlcommon::row_title(&mt('To'))
2391: .$tolist
2392: .&Apache::lonhtmlcommon::row_closure()
2393: );
2394: }
2395: if ($cclist) {
1.91 bisitz 2396: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Cc'))
2397: .$cclist
2398: .&Apache::lonhtmlcommon::row_closure()
2399: );
1.95 raeburn 2400: }
2401: if ($content{'group'} ne '') {
2402: if (&check_group_priv($content{'group'})) {
1.155 raeburn 2403: if (ref($recipients{'group_cc_broadcast'}) eq 'ARRAY') {
2404: $groupcclist = join(', ',@{$recipients{'group_cc_broadcast'}});
2405: if ($groupcclist) {
2406: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Group Cc'))
2407: .$groupcclist
2408: .&Apache::lonhtmlcommon::row_closure()
2409: );
2410: }
1.95 raeburn 2411: }
2412: }
1.78 raeburn 2413: }
1.91 bisitz 2414: }
1.73 raeburn 2415: }
1.91 bisitz 2416:
2417: # Course
1.157 raeburn 2418: if ($content{'courseid'} ne '') {
2419: if ($content{'courseid'} =~ m{^$match_domain\_$match_courseid$}) {
2420: my %courseinfo;
2421: %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'},
2422: {'one_time' => 1});
2423: my $description = $courseinfo{'description'};
2424: if ($description ne '') {
2425: $r->print(&Apache::lonhtmlcommon::row_title(&mt($crstype))
2426: .$description
2427: );
2428: if ($content{'coursesec'}) {
2429: $r->print(' ('.&mt('Section').': '.$content{'coursesec'}.')');
2430: }
2431: $r->print(&Apache::lonhtmlcommon::row_closure());
2432: }
1.73 raeburn 2433: }
2434: }
1.91 bisitz 2435: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Time'))
2436: .$content{'time'}
2437: .&Apache::lonhtmlcommon::row_closure()
2438: );
2439:
2440: # Refers to
1.59 raeburn 2441: if ($baseurl) {
2442: if (defined($content{'courseid'}) && defined($env{'request.course.id'})) {
2443: if ($content{'courseid'} eq $env{'request.course.id'}) {
2444: my $symblink;
1.62 raeburn 2445: my $showsymb = &Apache::lonenc::check_decrypt($symb);
2446: my $showurl = &Apache::lonenc::check_decrypt($baseurl);
2447: my $encrypturl = &Apache::lonnet::EXT('resource.0.encrypturl',
2448: $showsymb,$env{'user.domain'},$env{'user.name'});
1.59 raeburn 2449: if ($symb) {
1.62 raeburn 2450: if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
2451: $showsymb = &Apache::lonenc::check_encrypt($symb);
2452: }
2453: $symblink = '?symb='.$showsymb;
2454: }
2455: if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
2456: $showurl = $baseurl;
1.59 raeburn 2457: }
1.91 bisitz 2458: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
2459: .'<a href="'.$showurl.$symblink.'">'.$restitle.'</a>'
2460: .&Apache::lonhtmlcommon::row_closure()
2461: );
1.59 raeburn 2462: $refers_to = 1;
2463: }
2464: }
2465: if (!$refers_to) {
2466: if ($baseurl =~ m-^/enc/-) {
2467: if (defined($content{'courseid'})) {
1.62 raeburn 2468: if (!$env{'request.course.id'}) {
2469: my $unencurl =
2470: &Apache::lonenc::unencrypted($baseurl,
2471: $content{'courseid'});
2472: if ($unencurl ne '') {
2473: if (&Apache::lonnet::allowed('bre',$unencurl)) {
1.91 bisitz 2474: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
2475: .'<a href="'.$unencurl.'">'.$restitle.'</a>'
2476: .&Apache::lonhtmlcommon::row_closure()
2477: );
1.62 raeburn 2478: }
1.59 raeburn 2479: }
2480: }
2481: }
2482: } else {
2483: if (&Apache::lonnet::allowed('bre',$baseurl)) {
1.91 bisitz 2484: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
2485: .'<a href="'.$baseurl.'">'.$restitle.'</a>'
2486: .&Apache::lonhtmlcommon::row_closure()
2487: );
2488:
1.59 raeburn 2489: }
2490: }
2491: }
2492: }
1.91 bisitz 2493:
2494: # Message
2495: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Message'))
2496: .'<pre>'
2497: .&Apache::lontexconvert::msgtexconverted($content{'message'},1)
2498: .'</pre>'
2499: );
2500: if (&displayresource(%content)) {
2501: $r->print(&Apache::lonhtmlcommon::row_closure()
2502: .&Apache::lonhtmlcommon::row_title(&mt('Resource Details'))
2503: .&displayresource(%content)
2504: );
2505: }
1.92 raeburn 2506: $r->print(&Apache::lonhtmlcommon::row_closure(1).
2507: &Apache::lonhtmlcommon::end_pick_box());
1.91 bisitz 2508: # Display LON-CAPA Message (End)
1.59 raeburn 2509: return;
1.1 albertel 2510: }
2511:
1.95 raeburn 2512: sub retrieve_recips {
2513: my ($context,$content,$recips)= @_;
2514: my $tonum = 0;
2515: if (ref($content) eq 'HASH') {
2516: my %reciphash =
2517: &Apache::lonnet::get('nohist_emailrecip',[$content->{'recipid'}],
2518: $content->{'senderdomain'},$content->{'sendername'});
2519: my $recipinfo = $reciphash{$content->{'recipid'}};
2520: if (ref($recipinfo) eq 'HASH') {
2521: foreach my $type ('to','cc','course_broadcast','group_cc_broadcast','group_bcc_broadcast') {
2522: if (ref($recipinfo->{$type}) eq 'HASH') {
2523: if ($type eq 'to') {
2524: $tonum = keys(%{$recipinfo->{$type}});
2525: }
2526: foreach my $user (sort(keys(%{$recipinfo->{$type}}))) {
2527: my ($uname,$udom) = split(/:/,$user);
2528: next if (($context eq 'replying') && ($uname eq $env{'user.name'})
2529: && ($udom eq $env{'user.domain'}));
2530: my $showuser ='<span class="LC_nobreak">';
2531: if ($context eq 'replying') {
2532: if (($type eq 'to') || ($type eq 'cc')) {
2533: $showuser = '<label><input type="checkbox" name="replying_'.$type.'" value="'.$user.'" />';
2534: } elsif ($type eq 'group_cc_broadcast') {
2535: $showuser = '<label><input type="checkbox" name="replying_groupcc" value="'.$user.'" />';
2536: }
2537: }
2538: $showuser .= &Apache::loncommon::aboutmewrapper(
2539: &Apache::loncommon::plainname($uname,
2540: $udom),$uname,$udom);
2541: if ($context eq 'replying') {
2542: $showuser .='</label>';
2543: }
2544: $showuser .= '</span>';
2545: if (ref($recips) eq 'HASH') {
2546: push(@{$recips->{$type}},$showuser);
2547: }
2548: }
1.73 raeburn 2549: }
2550: }
2551: }
2552: }
1.95 raeburn 2553: return $tonum;
2554: }
2555:
2556: sub recipients_link {
2557: my ($r,$content,$recipients) = @_;
2558: my ($broadcast_link,$show);
2559: if ((ref($content) eq 'HASH') && (ref($recipients) eq 'HASH')) {
2560: if (ref($recipients->{'course_broadcast'}) eq 'ARRAY') {
2561: if (@{$recipients->{'course_broadcast'}} > 0) {
2562: $show = 'course';
2563: }
2564: } elsif (ref($recipients->{'group_cc_broadcast'}) eq 'ARRAY') {
2565: if (@{$recipients->{'group_cc_broadcast'}} > 0) {
2566: $show = 'group_cc';
2567: }
2568: } elsif (ref($recipients->{'group_bcc_broadcast'}) eq 'ARRAY') {
2569: if (@{$recipients->{'group_bcc_broadcast'}} > 0) {
2570: $show = 'group_bcc';
2571: }
2572: }
2573: if ($show) {
2574: my ($nothing,$height,$width,$start_page,$end_page,$body);
2575: $nothing=&Apache::lonhtmlcommon::javascript_nothing();
2576: $height = 400;
2577: $width = 600;
1.108 raeburn 2578: $start_page =
2579: &Apache::loncommon::start_page('Broadcast List', undef,
2580: {only_body => 1,
2581: js_ready => 1,});
2582: $end_page = &Apache::loncommon::end_page({js_ready => 1,});
2583: $body = '<h3>'.&mt("Recipients of broadcast message").'</h3>'.
2584: &Apache::loncommon::start_data_table();
1.95 raeburn 2585: my $cell = 0;
2586: $body .= &Apache::loncommon::start_data_table_row();
2587: foreach my $item (@{$recipients->{$show.'_broadcast'}}) {
2588: $item =~ s/'/\\'/g;
2589: if (!($cell%2) && $cell > 0) {
2590: $body .= &Apache::loncommon::end_data_table_row().
2591: &Apache::loncommon::start_data_table_row();
2592: }
2593: $cell ++;
2594: $body .= '<td>'.$cell.' '.$item.' </td>';
2595: }
2596: if ($cell%2) {
2597: $body .= '<td> </td>';
2598: }
2599: $body .= &Apache::loncommon::end_data_table_row().
2600: &Apache::loncommon::end_data_table();
2601: $body =~ s{</}{<\\/}g;
2602: $body =~ s{\n}{}g;
2603: $r->print(<<ENDJS);
2604: <script type="text/javascript">
1.127 bisitz 2605: // <![CDATA[
1.95 raeburn 2606: function showBroadcastList() {
2607: var caller = this;
2608: var newWindow = null;
2609: try {
2610: newWindow = window.open($nothing,"broadcast","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" );
2611: }
2612: catch(error) {
2613: writeWin(caller);
2614: return;
2615: }
2616: if (newWindow) {
2617: caller = newWindow;
2618: }
2619: writeWin(caller);
2620: return;
2621: }
2622:
2623: function writeWin(caller) {
2624: caller.document.writeln('$start_page $body $end_page');
2625: caller.document.close();
2626: caller.focus();
2627: }
1.127 bisitz 2628: // ]]>
1.95 raeburn 2629: </script>
2630:
2631: ENDJS
2632: $broadcast_link = 1;
2633: }
2634: }
2635: return $broadcast_link;
1.73 raeburn 2636: }
2637:
1.1 albertel 2638: # =========================================================== Show the citation
2639:
2640: sub displayresource {
2641: my %content=@_;
2642: #
2643: # If the recipient is in the same course that the message was sent from and
2644: # has sufficient privileges, show "all details," else show citation
2645: #
2646: if (($env{'request.course.id'} eq $content{'courseid'})
2647: && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
1.59 raeburn 2648: my $symb;
2649: if (defined($content{'symb'})) {
2650: $symb = $content{'symb'};
2651: } else {
2652: $symb=&Apache::lonnet::symbread($content{'baseurl'});
2653: }
1.1 albertel 2654: # Could not get a symb, give up
2655: unless ($symb) { return $content{'citation'}; }
2656: # Have a symb, can render
2657: return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
2658: &Apache::loncommon::get_previous_attempt($symb,
2659: $content{'sendername'},
2660: $content{'senderdomain'},
2661: $content{'courseid'}).
2662: '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
2663: &Apache::loncommon::get_student_view($symb,
2664: $content{'sendername'},
2665: $content{'senderdomain'},
2666: $content{'courseid'}).
2667: '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
2668: &Apache::loncommon::get_student_answers($symb,
2669: $content{'sendername'},
2670: $content{'senderdomain'},
2671: $content{'courseid'});
2672: } elsif ($env{'user.adv'}) {
2673: return $content{'citation'};
2674: }
2675: return '';
2676: }
2677:
2678: # ================================================================== The Header
2679:
2680: sub header {
2681: my ($r,$title,$baseurl)=@_;
2682: my $extra = &Apache::loncommon::studentbrowser_javascript();
2683: if ($baseurl) {
1.41 albertel 2684: $extra .= "<base href=\"".&Apache::lonnet::absolute_url()."/$baseurl\" />";
1.1 albertel 2685: }
1.181.2.3 raeburn 2686: $extra .= '<script type="text/javascript"
2687: src="/res/adm/includes/file_upload.js"></script>';
1.138 raeburn 2688: $r->print(&Apache::loncommon::start_page('Messages',
1.38 raeburn 2689: $extra));
1.1 albertel 2690: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.138 raeburn 2691: (($title?$title:'Send and display messages')));
1.1 albertel 2692: }
2693:
2694: # ---------------------------------------------------------------- Print header
2695:
2696: sub printheader {
2697: my ($r,$url,$desc,$title,$baseurl)=@_;
2698: &Apache::lonhtmlcommon::add_breadcrumb
2699: ({href=>$url,
2700: text=>$desc});
2701: &header($r,$title,$baseurl);
2702: }
2703:
2704: # ------------------------------------------------------------ Store the comment
2705:
2706: sub storecomment {
2707: my ($r)=@_;
2708: my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2709: my $cleanmsgtxt='';
1.42 raeburn 2710: foreach my $line (split(/[\n\r]/,$msgtxt)) {
2711: unless ($line=~/^\s*(\>|\>\;)/) {
2712: $cleanmsgtxt.=$line."\n";
1.1 albertel 2713: }
2714: }
1.29 www 2715: my $key=&escape($env{'form.baseurl'}).'___'.time;
1.1 albertel 2716: &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
2717: }
2718:
2719: sub storedcommentlisting {
2720: my ($r)=@_;
2721: my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
1.29 www 2722: '^'.&escape(&escape($env{'form.showcommentbaseurl'})));
1.72 albertel 2723: $r->print(&Apache::loncommon::start_page('Saved Comment Listing',undef,
1.1 albertel 2724: {'onlybody' => 1}));
1.178 raeburn 2725: if ((keys(%msgs))[0]=~/^error\:/) {
1.72 albertel 2726: $r->print(&mt('No saved comments yet.'));
1.1 albertel 2727: } else {
2728: my $found=0;
1.42 raeburn 2729: foreach my $key (sort(keys(%msgs))) {
2730: $r->print("\n".$msgs{$key}."<hr />");
1.1 albertel 2731: $found=1;
2732: }
2733: unless ($found) {
1.72 albertel 2734: $r->print(&mt('No saved comments yet for this resource.'));
1.1 albertel 2735: }
2736: }
2737: }
2738:
2739: # ---------------------------------------------------------------- Send an email
2740:
2741: sub sendoffmail {
2742: my ($r,$folder)=@_;
2743: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2744: my $sendstatus='';
1.71 raeburn 2745: my %msg_status;
2746: my $numsent = 0;
2747: my $nosentstore = 1;
1.86 raeburn 2748: my $attachmenturl;
2749: my $now = time;
1.38 raeburn 2750: my ($cdom,$cnum,$group);
2751: if (exists($env{'form.group'})) {
2752: $group = $env{'form.group'};
2753: }
2754: if (exists($env{'request.course.id'})) {
2755: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2756: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2757: }
1.1 albertel 2758: if ($env{'form.send'}) {
1.53 raeburn 2759: if (!$env{'form.multiforward'}) {
2760: if ($group eq '') {
2761: &printheader($r,'','Messages being sent.');
2762: } else {
2763: $r->print(&groupmail_header('sending',$group));
2764: }
1.38 raeburn 2765: }
1.1 albertel 2766: $r->rflush();
2767: my %content=();
2768: undef %content;
2769: if ($env{'form.forwid'}) {
2770: my $msgid=$env{'form.forwid'};
2771: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1.86 raeburn 2772: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1,1);
1.1 albertel 2773: &statuschange($msgid,'forwarded',$folder);
1.86 raeburn 2774: if ($content{'attachmenturl'} ne '') {
2775: $attachmenturl = $content{'attachmenturl'};
2776: }
2777: $env{'form.message'} .= "\n\n-- Forwarded message --\n\n".
2778: $content{'message'};
1.1 albertel 2779: }
2780: if ($env{'form.replyid'}) {
2781: my $msgid=$env{'form.replyid'};
2782: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2783: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2784: &statuschange($msgid,'replied',$folder);
2785: }
1.13 albertel 2786:
1.25 foxr 2787: my $mode = $env{'form.sendmode'};
1.95 raeburn 2788: my (%toaddr,$tos,$cc,$bcc,$broadcast);
1.25 foxr 2789:
1.95 raeburn 2790: if ($mode eq 'group') {
2791: if (defined($env{'form.courserecips'})) {
2792: my $courseusers = $env{'form.courserecips'};
2793: $courseusers =~ s/^_\&\&\&_//;
2794: my @to = split('_&&&_',$courseusers);
2795: foreach my $dest (@to) {
2796: my ($user,$domain) = split(/:/, $dest);
2797: if (($user ne '') && ($domain ne '')) {
2798: my $rec = $user.":".$domain;
2799: $toaddr{$rec} = '';
2800: $broadcast->{$rec} = '';
2801: }
2802: }
2803: }
2804: } elsif ($mode eq 'upload') {
1.71 raeburn 2805: $nosentstore = 0;
1.13 albertel 2806: foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
1.43 raeburn 2807: my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/);
1.1 albertel 2808: if ($txt) {
1.43 raeburn 2809: $rec =~ s/^\s+//;
1.44 raeburn 2810: $rec =~ s/\s+$//;
1.1 albertel 2811: $toaddr{$rec}.=$txt."\n";
1.95 raeburn 2812: $broadcast->{$rec} = '';
1.1 albertel 2813: }
2814: }
2815: } else {
1.25 foxr 2816: if (($env{'form.recuname'} ne '') && ($env{'form.recdomain'} ne '')) {
2817: $toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
1.95 raeburn 2818: $tos->{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
1.25 foxr 2819: }
1.1 albertel 2820: }
1.95 raeburn 2821: if ($env{'form.additionalrec_to'}) {
2822: foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_to'})) {
2823: my ($auname,$audom)=split(/:/,$rec);
2824: if (($auname ne "") && ($audom ne "")) {
2825: $toaddr{$auname.':'.$audom}='';
2826: $tos->{$auname.':'.$audom}='';
2827: }
2828: }
2829: }
2830: if ($env{'form.replying_to'}) {
2831: my @toreplies =
2832: &Apache::loncommon::get_env_multiple('form.replying_to');
2833: foreach my $rec (@toreplies) {
2834: my ($auname,$audom)=split(/:/,$rec);
2835: if (($auname ne "") && ($audom ne "")) {
2836: $toaddr{$auname.':'.$audom}='';
2837: $tos->{$auname.':'.$audom}='';
2838: }
2839: }
2840: }
1.73 raeburn 2841: if ($env{'form.additionalrec_cc'}) {
2842: foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_cc'})) {
1.43 raeburn 2843: my ($auname,$audom)=split(/:/,$rec);
1.25 foxr 2844: if (($auname ne "") && ($audom ne "")) {
1.73 raeburn 2845: $toaddr{$auname.':'.$audom}='';
1.95 raeburn 2846: if (!defined($tos->{$auname.':'.$audom})) {
2847: $cc->{$auname.':'.$audom}='';
2848: }
1.25 foxr 2849: }
1.1 albertel 2850: }
2851: }
1.95 raeburn 2852: if ($env{'form.replying_cc'}) {
2853: my @ccreplies =
2854: &Apache::loncommon::get_env_multiple('form.replying_cc');
2855: foreach my $rec (@ccreplies) {
2856: my ($auname,$audom)=split(/:/,$rec);
2857: if (($auname ne "") && ($audom ne "")) {
2858: $toaddr{$auname.':'.$audom}='';
2859: if (!defined($tos->{$auname.':'.$audom})) {
2860: $cc->{$auname.':'.$audom}='';
2861: }
2862: }
2863: }
2864: }
2865: if ($env{'form.replying_groupcc'}) {
2866: my @groupreplies =
2867: &Apache::loncommon::get_env_multiple('form.replying_groupcc');
2868: foreach my $rec (@groupreplies) {
1.73 raeburn 2869: my ($auname,$audom)=split(/:/,$rec);
2870: if (($auname ne "") && ($audom ne "")) {
2871: $toaddr{$auname.':'.$audom}='';
1.95 raeburn 2872: if (!defined($tos->{$auname.':'.$audom})) {
2873: $broadcast->{$auname.':'.$audom}='';
2874: }
1.73 raeburn 2875: }
2876: }
2877: }
1.95 raeburn 2878: if ($env{'form.additionalrec_bcc'}) {
2879: foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_bcc'})) {
1.73 raeburn 2880: my ($auname,$audom)=split(/:/,$rec);
2881: if (($auname ne "") && ($audom ne "")) {
2882: $toaddr{$auname.':'.$audom}='';
1.95 raeburn 2883: if ((!defined($tos->{$auname.':'.$audom})) &&
2884: (!defined($cc->{$auname.':'.$audom}))) {
2885: $bcc->{$auname.':'.$audom}='';
2886: }
1.73 raeburn 2887: }
2888: }
2889: }
1.1 albertel 2890: my $savemsg;
2891: my $msgtype;
2892: my %sentmessage;
1.7 albertel 2893: my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'},
2894: undef,1);
1.1 albertel 2895: if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
2896: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
2897: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
2898: '/'.$env{'request.course.sec'})
2899: )) {
2900: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
2901: $msgtype = 'critical';
2902: } else {
2903: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2904: }
1.73 raeburn 2905: my %reciphash = (
1.95 raeburn 2906: to => $tos,
1.73 raeburn 2907: cc => $cc,
2908: bcc => $bcc,
1.95 raeburn 2909: );
2910: if ($mode eq 'group') {
2911: if ($group eq '') {
2912: $reciphash{'course_broadcast'} = $broadcast;
2913: } else {
2914: if ($env{'form.groupmail'} eq 'cc') {
2915: $reciphash{'group_cc_broadcast'} = $broadcast;
2916: } else {
2917: $reciphash{'group_bcc_broadcast'} = $broadcast;
2918: }
2919: }
2920: }
1.73 raeburn 2921: my ($recipid,$recipstatus) =
2922: &Apache::lonmsg::store_recipients($msgsubj,$env{'user.name'},
2923: $env{'user.domain'},\%reciphash);
2924: if ($recipstatus ne 'ok') {
1.95 raeburn 2925: &Apache::lonnet::logthis('Failed to store To, Bcc and Cc recipients for '.$env{'user.name'}.':'.$env{'user.domain'});
1.86 raeburn 2926: }
2927: if ($env{'form.attachment'}) {
1.181.2.3 raeburn 2928: if (length($env{'form.attachment'}) <= 1048576) {
1.86 raeburn 2929: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback/'.$now);
2930: } else {
2931: $r->print('<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>');
2932: }
2933: } elsif ($env{'form.multiforward'}) {
2934: if ($env{'form.attachmenturl'} ne '') {
2935: $attachmenturl = $env{'form.attachmenturl'};
2936: }
2937: }
1.71 raeburn 2938: my @recusers;
2939: my @recudoms;
1.180 raeburn 2940: my %permresults;
1.13 albertel 2941: foreach my $address (sort(keys(%toaddr))) {
2942: my ($recuname,$recdomain)=split(/\:/,$address);
1.1 albertel 2943: my $msgtxt = $savemsg;
1.73 raeburn 2944: if ($toaddr{$address}) {
1.151 raeburn 2945: $msgtxt.="\n".'<hr />'."\n".$toaddr{$address};
1.73 raeburn 2946: }
1.12 albertel 2947: my @thismsg;
1.60 raeburn 2948: if ($msgtype eq 'critical') {
2949: $r->print(&mt('Sending critical message').' '.
2950: $recuname.':'.$recdomain.': ');
1.13 albertel 2951: @thismsg=
2952: &Apache::lonmsg::user_crit_msg($recuname,$recdomain,
2953: $msgsubj,$msgtxt,
2954: $env{'form.sendbck'},
2955: $env{'form.permanent'},
1.71 raeburn 2956: \$sentmessage{$address},
1.179 raeburn 2957: $nosentstore,$recipid,
1.180 raeburn 2958: $attachmenturl,\%permresults);
1.1 albertel 2959: } else {
1.14 albertel 2960: $r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': ');
1.13 albertel 2961: @thismsg=
2962: &Apache::lonmsg::user_normal_msg($recuname,$recdomain,
2963: $msgsubj,$msgtxt,
2964: $content{'citation'},
1.86 raeburn 2965: undef,$attachmenturl,
1.13 albertel 2966: $env{'form.permanent'},
1.71 raeburn 2967: \$sentmessage{$address},
2968: undef,undef,undef,
1.180 raeburn 2969: $nosentstore,$recipid,
2970: \%permresults);
1.71 raeburn 2971: }
2972: $msg_status{$recuname.':'.$recdomain}=join(' ',@thismsg);
2973: if ($msg_status{$recuname.':'.$recdomain} =~ /(ok|con_delayed)/) {
2974: $numsent++;
2975: push(@recusers,$recuname);
2976: push(@recudoms,$recdomain);
1.180 raeburn 2977: if ($1 eq 'ok') {
2978: $r->print('ok ');
2979: }
2980: if ($permresults{$recuname.':'.$recdomain}) {
2981: $r->print(' (email) ');
2982: }
1.1 albertel 2983: }
1.12 albertel 2984: $sendstatus.=' '.join(' ',@thismsg);
1.1 albertel 2985: }
1.71 raeburn 2986: my $subj_prefix;
2987: if ($numsent > 0) {
2988: if (($env{'request.course.id'}) &&
1.95 raeburn 2989: (($mode eq 'group') ||
1.71 raeburn 2990: ($env{'form.courserecord'}) ||
1.95 raeburn 2991: ($msgtype eq 'critical')) ||
2992: ($env{'form.replyid'} &&
2993: (($content{'courseid'} ne '') &&
2994: ($mode eq 'group')))) {
1.71 raeburn 2995: if ($msgtype eq 'critical') {
2996: $subj_prefix = 'Critical.';
1.95 raeburn 2997: } elsif ($mode eq 'group') {
1.71 raeburn 2998: $subj_prefix = 'Broadcast.';
2999: } else {
3000: $subj_prefix = 'Archive';
3001: }
3002: my ($specialmsgid,$specialresult);
1.95 raeburn 3003: my $course_str;
3004: if ($env{'form.replyid'}) {
3005: if ($content{'courseid'} ne '') {
3006: my %crsdesc =
3007: &Apache::lonnet::coursedescription($content{'courseid'},
3008: {'one_time' => 1});
3009: $course_str = &escape('['.$crsdesc{'num'}.':'.$crsdesc{'domain'}.']');
3010: }
3011: } elsif ($env{'request.course.id'}) {
3012: $course_str = &escape('['.$cnum.':'.$cdom.']');
3013: }
1.71 raeburn 3014: $specialresult =
3015: &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
3016: $subj_prefix.' '.$course_str,$savemsg,undef,undef,
1.86 raeburn 3017: $attachmenturl,undef,undef,\$specialmsgid,undef,undef,undef,
1.71 raeburn 3018: undef,undef,1);
1.29 www 3019: $specialmsgid = &unescape($specialmsgid);
1.71 raeburn 3020: if ($specialresult eq 'ok') {
3021: my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
3022: split(/\:/,&unescape($specialmsgid));
3023:
3024: foreach my $recipient (sort(keys(%toaddr))) {
3025: if ($msg_status{$recipient} =~ /\s*(ok|con_delayed)\s*/) {
3026: my $usersubj = $subj_prefix.'['.$recipient.']';
3027: my $usermsgid =
3028: &Apache::lonmsg::buildmsgid($stamp,$usersubj,
3029: $msgname,$msgdom,
3030: $msgcount,$context,
3031: $pid);
3032: &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
3033: $subj_prefix.' ['.$recipient.']',$msgsubj,
1.86 raeburn 3034: undef,undef,$attachmenturl,undef,$usermsgid,undef,
1.71 raeburn 3035: undef,$specialmsgid,undef,undef,undef,1);
3036: }
3037: }
1.95 raeburn 3038: if (($mode ne 'upload') && (@recusers > 0)) {
1.71 raeburn 3039: &Apache::lonmsg::process_sent_mail($msgsubj,
3040: $subj_prefix,$numsent,$stamp,$msgname,$msgdom,
3041: $msgcount,$context,$pid,$savemsg,\@recusers,
1.95 raeburn 3042: \@recudoms,undef,$attachmenturl,'','','','',$recipid);
1.1 albertel 3043: }
1.71 raeburn 3044: } else {
1.78 raeburn 3045: &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 3046: }
3047: } else {
1.71 raeburn 3048: my $stamp = time;
3049: my $msgcount = &Apache::lonmsg::get_uniq();
3050: my $context = &Apache::lonmsg::get_course_context();
3051: &Apache::lonmsg::process_sent_mail($msgsubj,$subj_prefix,
3052: $numsent,$stamp,$env{'user.name'},
3053: $env{'user.domain'},$msgcount,$context,
1.95 raeburn 3054: $$,$savemsg,\@recusers,\@recudoms,undef,$attachmenturl,
3055: '','','','',$recipid);
1.1 albertel 3056: }
3057: }
1.143 wenzelju 3058: if (!$env{'form.multiforward'}) {
1.71 raeburn 3059: if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
1.143 wenzelju 3060: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Completed.'));
3061: $message = &Apache::loncommon::confirmwrapper($message);
3062: $r->print($message);
1.71 raeburn 3063: if ($env{'form.displayedcrit'}) {
3064: &discrit($r);
3065: }
3066: if ($group ne '') {
3067: $r->print(&groupmail_sent($group,$cdom,$cnum));
3068: } else {
3069: &Apache::loncommunicate::menu($r);
3070: }
3071: } else {
1.143 wenzelju 3072: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Could not deliver message'),1);
1.145 raeburn 3073: $message .= '<br />'.&mt('Please use the browser "Back" button and correct the recipient addresses ([_1]).',$sendstatus);
1.143 wenzelju 3074: $message = &Apache::loncommon::confirmwrapper($message);
3075: $r->print($message);
1.53 raeburn 3076: }
1.38 raeburn 3077: }
1.152 www 3078: } else {
3079: &printheader($r,'','Messages cancelled.');
3080: return 'cancelled';
1.1 albertel 3081: }
1.53 raeburn 3082: return $sendstatus;
1.1 albertel 3083: }
3084:
3085: # ===================================================================== Handler
3086:
3087: sub handler {
3088: my $r=shift;
3089:
3090: # ----------------------------------------------------------- Set document type
3091:
3092: &Apache::loncommon::content_type($r,'text/html');
3093: $r->send_http_header;
3094:
3095: return OK if $r->header_only;
3096:
3097: # --------------------------- Get query string for limited number of parameters
3098: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
3099: ['display','replyto','forward','markread','markdel','markunread',
3100: 'sendreply','compose','sendmail','critical','recname','recdom',
1.159 raeburn 3101: 'recordftf','sortedby','folder','startdis','interdis',
1.53 raeburn 3102: 'showcommentbaseurl','dismode','group','subject','text','ref',
3103: 'msgstatus']);
1.127 bisitz 3104: $sqs='&sortedby='.$env{'form.sortedby'};
1.1 albertel 3105:
3106: # ------------------------------------------------------ They checked for email
1.159 raeburn 3107: &Apache::lonnet::put('email_status',{'recnewemail'=>0});
1.1 albertel 3108:
3109: # ----------------------------------------------------------------- Breadcrumbs
3110:
3111: &Apache::lonhtmlcommon::clear_breadcrumbs();
3112: &Apache::lonhtmlcommon::add_breadcrumb
3113: ({href=>"/adm/communicate",
1.138 raeburn 3114: text=>"Messages",
1.1 albertel 3115: faq=>12,bug=>'Communication Tools',});
3116:
3117: # ------------------------------------------------------------------ Get Folder
3118:
3119: my $folder=$env{'form.folder'};
3120: unless ($folder) {
3121: $folder='';
3122: } else {
1.127 bisitz 3123: $sqs.='&folder='.&escape($folder);
1.1 albertel 3124: }
3125: # ------------------------------------------------------------ Get Display Mode
3126:
3127: my $dismode=$env{'form.dismode'};
3128: unless ($dismode) {
3129: $dismode='';
3130: } else {
1.48 albertel 3131: $sqs.='&dismode='.&escape($dismode);
1.1 albertel 3132: }
3133:
3134: # --------------------------------------------------------------------- Display
1.53 raeburn 3135: my $msgstatus = $env{'form.msgstatus'};
1.1 albertel 3136: $startdis=$env{'form.startdis'};
1.53 raeburn 3137: if ($startdis ne '') {
3138: $startdis--;
3139: }
1.1 albertel 3140: unless ($startdis) { $startdis=0; }
3141:
3142: if ($env{'form.firstview'}) {
3143: $startdis=0;
3144: }
3145: if ($env{'form.lastview'}) {
3146: $startdis=-1;
3147: }
3148: if ($env{'form.prevview'}) {
3149: $startdis--;
3150: }
3151: if ($env{'form.nextview'}) {
3152: $startdis++;
3153: }
3154: my $postedstartdis=$startdis+1;
1.127 bisitz 3155: $sqs.='&startdis='.$postedstartdis;
1.1 albertel 3156:
3157: # --------------------------------------------------------------- Render Output
3158:
3159: if ($env{'form.display'}) {
1.53 raeburn 3160: &displaymessage($r,$env{'form.display'},$folder,$msgstatus);
1.1 albertel 3161: } elsif ($env{'form.replyto'}) {
3162: &compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode);
3163: } elsif ($env{'form.confirm'}) {
3164: &printheader($r,'','Confirmed Receipt');
1.36 albertel 3165: my $replying = 0;
1.42 raeburn 3166: foreach my $envkey (keys(%env)) {
1.75 raeburn 3167: if ($envkey=~/^form\.(rep)?rec\_(.*)$/) {
1.77 raeburn 3168: my $repchk = $1;
1.75 raeburn 3169: my $msgid = $2;
3170: $r->print('<b>'.&mt('Confirming Receipt').':</b> ');
3171: my $result = &Apache::lonmsg::user_crit_received($msgid);
3172: if ($result =~ /trans:\s+ok/) {
3173: &statuschange($msgid,'read');
3174: }
1.76 albertel 3175: $r->print($result.'<br />');
1.77 raeburn 3176: if ($repchk eq 'rep') {
1.75 raeburn 3177: &compout($r,'','','',$msgid);
3178: $replying = 1;
3179: }
1.1 albertel 3180: }
3181: }
1.36 albertel 3182: if (!$replying) {
3183: &discrit($r);
3184: }
1.1 albertel 3185: } elsif ($env{'form.critical'}) {
3186: &printheader($r,'','Displaying Critical Messages');
3187: &discrit($r);
3188: } elsif ($env{'form.forward'}) {
3189: &compout($r,$env{'form.forward'},undef,undef,undef,$folder);
3190: } elsif ($env{'form.markdel'}) {
3191: &printheader($r,'','Deleted Message');
1.9 albertel 3192: my ($result,$msg) =
3193: &statuschange($env{'form.markdel'},'deleted',$folder);
3194: if (!$result) {
1.143 wenzelju 3195: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Failed to delete the message.'),1);
1.147 wenzelju 3196: $message .= '<p class="LC_error" style="font-size: inherit;">'.$msg.'</p>';
1.143 wenzelju 3197: $message = &Apache::loncommon::confirmwrapper($message);
3198: $r->print($message);
1.9 albertel 3199: }
1.1 albertel 3200: &Apache::loncommunicate::menu($r);
1.53 raeburn 3201: &disall($r,($folder?$folder:$dismode),$msgstatus);
3202: } elsif ($env{'form.markedaction'} eq 'markedforward') {
3203: my $total = 0;
3204: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
3205: foreach my $msgid (@to_forward) {
3206: &statuschange(&unescape($msgid),'forwarded',$folder);
3207: $total ++;
3208: }
3209: if ($total > 0) {
3210: &compout($r,undef,undef,undef,undef,$folder,$dismode,$total);
3211: }
3212: } elsif ($env{'form.markedaction'} eq 'markedread') {
3213: my $total = 0;
3214: my @to_markread = &Apache::loncommon::get_env_multiple('form.delmark');
3215: foreach my $msgid (@to_markread) {
3216: &statuschange(&unescape($msgid),'read',$folder);
3217: $total ++;
3218: }
3219: &printheader($r,'','Marked Messages Read');
1.143 wenzelju 3220: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Marked [quant,_1,message] read',$total));
3221: $message = &Apache::loncommon::confirmwrapper($message);
3222: $r->print($message);
3223: # $r->print('<p>');
1.53 raeburn 3224: &Apache::loncommunicate::menu($r);
3225: &disall($r,($folder?$folder:$dismode),$msgstatus);
3226: } elsif ($env{'form.markedaction'} eq 'markedunread') {
3227: my $total = 0;
3228: my @to_markunread = &Apache::loncommon::get_env_multiple('form.delmark');
3229: foreach my $msgid (@to_markunread) {
3230: &statuschange(&unescape($msgid),'new',$folder);
3231: $total ++;
3232: }
3233: &printheader($r,'','Marked Messages Unread');
1.143 wenzelju 3234: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Marked [quant,_1,message] unread',$total));
3235: $message = &Apache::loncommon::confirmwrapper($message);
3236: $r->print($message);
3237: # $r->print('<p>');
1.53 raeburn 3238: &Apache::loncommunicate::menu($r);
3239: &disall($r,($folder?$folder:$dismode),$msgstatus);
3240: } elsif ($env{'form.markedaction'} eq 'markedmove') {
3241: my $destfolder = $env{'form.movetofolder'};
3242: my %gotfolders = &Apache::lonmsg::get_user_folders();
3243: &printheader($r,'','Moved Messages');
3244: if (!defined($gotfolders{$destfolder})) {
3245: $r->print(&mt('Destination folder [_1] is not a valid folder',
1.148 bisitz 3246: '<span class="LC_filename">'.$destfolder.'</span>'));
1.53 raeburn 3247: } else {
3248: my ($total,$failed,@failed_msg)=(0,0);
3249: my @to_move = &Apache::loncommon::get_env_multiple('form.delmark');
3250: foreach my $msgid (@to_move) {
3251: my ($result,$msg) = &movemsg(&unescape($msgid),$folder,
3252: $env{'form.movetofolder'});
3253: if ($result) {
1.9 albertel 3254: $total++;
1.53 raeburn 3255: } else {
1.9 albertel 3256: $failed++;
3257: push(@failed_msg,$msg);
1.53 raeburn 3258: }
1.1 albertel 3259: }
1.143 wenzelju 3260: my $message = '';
3261: if ($failed) {
3262: $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Failed to move [quant,_1,message]',$failed),1);
1.147 wenzelju 3263: $message .= '<p class="LC_error" style="font-size: inherit;">'.
3264: join("</p>\n<p class=\"LC_error\" style=\"font-size: inherit;\">",@failed_msg).
1.143 wenzelju 3265: "</p>\n";
3266: }
3267: $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Moved [quant,_1,message]',$total));
3268: $message = &Apache::loncommon::confirmwrapper($message);
3269: $r->print($message);
3270: # $r->print('<p>');
1.53 raeburn 3271: }
1.1 albertel 3272: &Apache::loncommunicate::menu($r);
1.53 raeburn 3273: &disall($r,($folder?$folder:$dismode),$msgstatus);
3274: } elsif ($env{'form.markedaction'} eq 'markeddel') {
1.9 albertel 3275: my ($total,$failed,@failed_msg)=(0,0);
1.53 raeburn 3276: my @to_delete = &Apache::loncommon::get_env_multiple('form.delmark');
3277: foreach my $msgid (@to_delete) {
3278: my ($result,$msg) = &statuschange(&unescape($msgid),'deleted',
3279: $folder);
3280: if ($result) {
3281: $total++;
3282: } else {
3283: $failed++;
3284: push(@failed_msg,$msg);
1.1 albertel 3285: }
3286: }
3287: &printheader($r,'','Deleted Messages');
1.143 wenzelju 3288: my $message = '';
1.9 albertel 3289: if ($failed) {
1.143 wenzelju 3290: $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Failed to delete [quant,_1,message]',$failed),1);
1.147 wenzelju 3291: $message .= '<p class="LC_error" style="font-size: inherit;">'.
3292: join("</p>\n<p class=\"LC_error\" style=\"font-size: inherit;\">",@failed_msg).
1.143 wenzelju 3293: "</p>\n";
1.9 albertel 3294: }
1.143 wenzelju 3295: $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Deleted [quant,_1,message]',$total));
3296: $message = &Apache::loncommon::confirmwrapper($message);
3297: $r->print($message);
3298: # $r->print('<p>');
1.1 albertel 3299: &Apache::loncommunicate::menu($r);
1.53 raeburn 3300: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 3301: } elsif ($env{'form.markunread'}) {
3302: &printheader($r,'','Marked Message as Unread');
3303: &statuschange($env{'form.markunread'},'new');
3304: &Apache::loncommunicate::menu($r);
1.53 raeburn 3305: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 3306: } elsif ($env{'form.compose'}) {
3307: &compout($r,'','',$env{'form.compose'});
3308: } elsif ($env{'form.recordftf'}) {
3309: &facetoface($r,$env{'form.recordftf'});
3310: } elsif ($env{'form.sendmail'}) {
1.53 raeburn 3311: if ($env{'form.multiforward'}) {
3312: &printheader($r,'','Messages being sent.');
3313: my $fixed_subj = $env{'form.subject'};
3314: my $suffix=&Apache::lonmsg::foldersuffix($folder);
3315: my (%sendresult,%forwardok,%forwardfail,$fwdcount);
3316: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
3317: foreach my $item (@to_forward) {
3318: my $msgid=&unescape($item);
3319: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1.86 raeburn 3320: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1,1);
1.53 raeburn 3321: if ($env{'form.showorigsubj'}) {
3322: $env{'form.subject'} = $fixed_subj.$content{'subject'};
3323: } else {
3324: $env{'form.subject'} = '';
3325: }
3326: my $uname = $content{'sendername'};
3327: my $udom = $content{'senderdomain'};
3328: &statuschange($msgid,'forwarded',$folder);
3329: if ($env{'form.showorigsender'}) {
3330: $env{'form.message'} = $env{'form.msgheader'}.' '.
3331: &Apache::loncommon::plainname($uname,$udom).' ('.
3332: $uname.':'.$udom.')';
3333: }
1.86 raeburn 3334: $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
3335: $content{'message'};
3336: $env{'form.attachmenturl'} = $content{'attachmenturl'};
3337: $env{'form.multiforwid'} = $item;
1.53 raeburn 3338: $fwdcount ++;
3339: $r->print($fwdcount.': ');
3340: $sendresult{$msgid} = &sendoffmail($r,$folder);
3341: $r->print('<br />');
3342: }
3343: foreach my $key (keys(%sendresult)) {
3344: if ($sendresult{$key} =~/^(\s*(?:ok|con_delayed)\s*)*$/) {
3345: $forwardok{$key} = $sendresult{$key};
3346: } else {
3347: $forwardfail{$key} = $sendresult{$key};
3348: }
3349: }
3350: if (keys(%forwardok) > 0) {
3351: my $count = keys(%forwardok);
1.143 wenzelju 3352: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('[quant,_1,message] forwarded.',$count));
3353: $message = &Apache::loncommon::confirmwrapper($message);
3354: $r->print($message);
1.53 raeburn 3355: }
3356: if (keys(%forwardfail) > 0) {
3357: my $count = keys(%forwardfail);
1.143 wenzelju 3358: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Could not forward [quant,_1,message].',$count),1);
1.53 raeburn 3359: foreach my $key (keys(%forwardfail)) {
1.145 raeburn 3360: $message .= '<br />'.&mt('Could not deliver forwarded message.').'</span> '.
1.143 wenzelju 3361: &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.')';
1.53 raeburn 3362: }
1.143 wenzelju 3363: $message = &Apache::loncommon::confirmwrapper($message);
3364: $r->print($message);
1.53 raeburn 3365: }
3366: &Apache::loncommunicate::menu($r);
3367: } else {
3368: &sendoffmail($r,$folder);
3369: }
1.1 albertel 3370: if ($env{'form.storebasecomment'}) {
3371: &storecomment($r);
1.38 raeburn 3372: }
1.1 albertel 3373: if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
1.38 raeburn 3374: &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
1.1 albertel 3375: $env{'course.'.$env{'request.course.id'}.'.domain'},
3376: 'Course_Announcements',
3377: $env{'form.subject'},
3378: $env{'form.message'},'/adm/communicate','public');
3379: }
1.38 raeburn 3380: if ((!exists($env{'form.group'})) && (!$env{'form.displayedcrit'})) {
1.53 raeburn 3381: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.36 albertel 3382: }
1.1 albertel 3383: } elsif ($env{'form.newfolder'}) {
3384: &printheader($r,'','New Folder');
1.46 raeburn 3385: my $showfolder = $env{'form.newfolder'};
3386: my ($makeresult,$warning) = &makefolder($env{'form.newfolder'});
3387: if ($makeresult eq 'ok') {
1.143 wenzelju 3388: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" created.',$showfolder));
3389: $message = &Apache::loncommon::confirmwrapper($message);
3390: $r->print($message);
1.46 raeburn 3391: } else {
1.143 wenzelju 3392: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Creation failed.').' '.$makeresult.'<br />'.$warning,1);
3393: $message = &Apache::loncommon::confirmwrapper($message);
3394: $r->print($message);
1.46 raeburn 3395: $showfolder = $folder;
3396: }
3397: &Apache::loncommunicate::menu($r);
1.53 raeburn 3398: &disall($r,$showfolder,$msgstatus);
1.1 albertel 3399: } elsif ($env{'form.showcommentbaseurl'}) {
3400: &storedcommentlisting($r);
1.46 raeburn 3401: } elsif ($env{'form.folderaction'} eq 'delete') {
3402: &printheader($r,'','Deleted Folder');
3403: my $showfolder = '';
3404: my $delresult = &deletefolder($folder);
3405: if ($delresult eq 'ok') {
1.143 wenzelju 3406: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" deleted.',$folder));
3407: $message = &Apache::loncommon::confirmwrapper($message);
3408: $r->print($message);
1.65 raeburn 3409: $env{'form.folder'} = '';
1.46 raeburn 3410: } else {
1.143 wenzelju 3411: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Deletion failed.').' '.$delresult,1);
3412: $message = &Apache::loncommon::confirmwrapper($message);
3413: $r->print($message);
1.46 raeburn 3414: $showfolder = $folder;
3415: }
3416: &Apache::loncommunicate::menu($r);
1.53 raeburn 3417: &disall($r,$showfolder,$msgstatus);
1.46 raeburn 3418: } elsif ($env{'form.folderaction'} eq 'rename') {
3419: &printheader($r,'','Renamed Folder');
3420: my $showfolder = $env{'form.renamed'};
3421: my $renresult = &renamefolder($folder);
3422: if ($renresult eq 'ok') {
1.143 wenzelju 3423: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Folder "[_1]" renamed to "[_2]".',$folder,$showfolder));
3424: $message = &Apache::loncommon::confirmwrapper($message);
3425: $r->print($message);
1.46 raeburn 3426: } else {
1.143 wenzelju 3427: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Renaming failed.').' '.$renresult,1);
3428: $message = &Apache::loncommon::confirmwrapper($message);
3429: $r->print($message);
1.46 raeburn 3430: $showfolder = $folder;
3431: }
3432: &Apache::loncommunicate::menu($r);
1.53 raeburn 3433: &disall($r,$showfolder,$msgstatus);
1.1 albertel 3434: } else {
1.112 weissno 3435: &printheader($r,'','Display All Messages');
1.44 raeburn 3436: &Apache::loncommunicate::menu($r);
1.53 raeburn 3437: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 3438: }
3439: $r->print(&Apache::loncommon::end_page());
3440: return OK;
3441: }
3442: # ================================================= Main program, reset counter
3443:
3444: =pod
3445:
3446: =cut
3447:
3448: 1;
3449:
3450: __END__
3451:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>