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