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