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