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