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