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