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