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