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