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