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