Annotation of loncom/interface/lonmsgdisplay.pm, revision 1.179
1.158 raeburn 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # Routines for messaging display
3: #
1.179 ! raeburn 4: # $Id: lonmsgdisplay.pm,v 1.178 2014/12/11 01:52:30 raeburn Exp $
1.1 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29:
30: package Apache::lonmsgdisplay;
31:
32: =pod
33:
34: =head1 NAME
35:
1.69 raeburn 36: Apache::lonmsgdisplay: supports internal messaging
1.1 albertel 37:
38: =head1 SYNOPSIS
39:
1.69 raeburn 40: lonmsgdisplay provides a handler to allow users to read, send,
41: and delete messages, and to create and delete message folders,
42: and to move messages between folders.
1.1 albertel 43:
44: =head1 OVERVIEW
45:
46: =head2 Messaging Overview
47:
48: X<messages>LON-CAPA provides an internal messaging system similar to
49: email, but customized for LON-CAPA's usage. LON-CAPA implements its
50: own messaging system, rather then building on top of email, because of
51: the features LON-CAPA messages can offer that conventional e-mail can
52: not:
53:
54: =over 4
55:
56: =item * B<Critical messages>: A message the recipient B<must>
57: acknowlegde receipt of before they are allowed to continue using the
58: system, preventing a user from claiming they never got a message
59:
60: =item * B<Receipts>: LON-CAPA can reliably send reciepts informing the
61: sender that it has been read; again, useful for preventing students
62: from claiming they did not see a message. (While conventional e-mail
63: has some reciept support, it's sporadic, e-mail client-specific, and
64: generally the receiver can opt to not send one, making it useless in
65: this case.)
66:
67: =item * B<Context>: LON-CAPA knows about the sender, such as where
68: they are in a course. When a student mails an instructor asking for
69: help on the problem, the instructor receives not just the student's
70: question, but all submissions the student has made up to that point,
71: the user's rendering of the problem, and the complete view the student
72: saw of the resource, including discussion up to that point. Finally,
73: the instructor is reading all of this inside of LON-CAPA, not their
74: email program, so they have full access to LON-CAPA's grading
75: interface, or other features they may wish to use in response to the
76: student's query.
77:
1.50 raeburn 78: =item * B<Blocking>: LON-CAPA can block selected communication
79: features for students during an online exam. A course coordinator or
1.1 albertel 80: instructor can set an open and close date/time for scheduled online
81: exams in a course. If a user uses the LON-CAPA internal messaging
82: system to display e-mails during the scheduled blocking event,
83: display of all e-mail sent during the blocking period will be
84: suppressed, and a message of explanation, including details of the
85: currently active blocking periods will be displayed instead. A user
86: who has a course coordinator or instructor role in a course will be
87: unaffected by any blocking periods for the course, unless the user
88: also has a student role in the course, AND has selected the student role.
89:
90: =back
91:
92: Users can ask LON-CAPA to forward messages to conventional e-mail
93: addresses on their B<PREF> screen, but generally, LON-CAPA messages
94: are much more useful than traditional email can be made to be, even
95: with HTML support.
96:
97: =cut
98:
99: use strict;
100: use Apache::lonnet;
101: use HTML::TokeParser();
102: use Apache::Constants qw(:common);
103: use Apache::loncommon();
1.67 www 104: use Apache::lonhtmlcommon();
1.1 albertel 105: use Apache::lontexconvert();
106: use HTML::Entities();
107: use Apache::lonlocal;
108: use Apache::loncommunicate;
109: use Apache::lonfeedback;
110: use Apache::lonrss();
1.27 albertel 111: use Apache::lonselstudent();
1.29 www 112: use lib '/home/httpd/lib/perl/';
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))) {
1.42 raeburn 818: my %content=&Apache::lonmsg::unpackagemsg($what{$key});
1.1 albertel 819: next if ($content{'senderdomain'} eq '');
1.157 raeburn 820: my $description;
821: if ($content{'courseid'} ne '') {
822: if ($content{'courseid'} =~ m{/^$match_domain\_$match_courseid$}) {
823: my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'},{'one_time' => 1});
824: if ($courseinfo{'description'} ne '') {
825: $description = $courseinfo{'description'};
826: }
827: }
828: }
1.88 bisitz 829: $result .= &Apache::lonhtmlcommon::start_pick_box()
830: .&Apache::lonhtmlcommon::row_title(&mt('From'),undef,'LC_oddrow_value')
831: .'<b>'.&Apache::loncommon::aboutmewrapper(
832: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b>'
833: .' ('.$content{'sendername'}.':'.$content{'senderdomain'}.')'
834: .&Apache::lonhtmlcommon::row_closure(1)
835: .&Apache::lonhtmlcommon::row_title(&mt('Date'),undef,'LC_evenrow_value')
836: .$content{'time'}
837: .&Apache::lonhtmlcommon::row_closure(1)
838: .&Apache::lonhtmlcommon::row_title(&mt('Subject'),undef,'LC_oddrow_value')
839: .$content{'subject'}
1.156 bisitz 840: .&Apache::lonhtmlcommon::row_closure(1);
1.157 raeburn 841: if ($description ne '') {
1.156 bisitz 842: $result .= &Apache::lonhtmlcommon::row_title(&mt('Course'),undef,'LC_oddrow_value')
1.157 raeburn 843: .$description
1.156 bisitz 844: .&Apache::lonhtmlcommon::row_closure(1);
845: }
846: $result .= &Apache::lonhtmlcommon::row_title(&mt('Message'),undef,'LC_evenrow_value')
1.88 bisitz 847: .'<pre>'.&Apache::lontexconvert::msgtexconverted($content{'message'}).'</pre>'
848: .&Apache::lonhtmlcommon::row_closure()
849: .&Apache::lonhtmlcommon::row_title('',undef,'LC_oddrow_value')
850: .'<div class="LC_warning">';
1.78 raeburn 851: my ($rec_button,$reprec_button);
852: $rec_button = &mt('Move to Inbox');
853: if (!$content{'noreplies'}) {
854: $reprec_button = &mt('Move to Inbox/Compose reply');
855: }
1.75 raeburn 856: if ($content{'sendback'}) {
857: $rec_button = &mt('Confirm Receipt');
1.78 raeburn 858: if (!$content{'noreplies'}) {
859: $reprec_button = &mt('Confirm Receipt and Reply');
860: }
1.75 raeburn 861: $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');
862: } else {
1.78 raeburn 863: $result .= &mt('Access to other pages will be prevented until you have moved the message to your inbox.');
1.75 raeburn 864: }
1.88 bisitz 865: $result .= '</div>'
866: .&Apache::lonhtmlcommon::row_closure(1)
867: .&Apache::lonhtmlcommon::row_title('',undef,'LC_evenrow_value')
868: .'<input type="submit" name="rec_'.$key.'" value="'.$rec_button.'" />';
1.78 raeburn 869: if (!$content{'noreplies'}) {
1.88 bisitz 870: $result .= '<input type="submit" name="reprec_'.$key.'" '
871: .'value="'.$reprec_button.'" />'
1.78 raeburn 872: }
1.88 bisitz 873: $result .= &Apache::lonhtmlcommon::row_closure(1)
874: .&Apache::lonhtmlcommon::end_pick_box()
875: .'<br />';
1.1 albertel 876: }
877: # Check to see if there were any messages.
878: if ($result eq '') {
1.141 bisitz 879: $result =
880: '<p class="LC_info">'.
881: &mt('You have no critical messages.').
882: '</p>'.
1.162 bisitz 883: &Apache::lonhtmlcommon::actionbox(
884: ['<a href="/adm/roles">'.&mt('Select a course').'</a>',
885: '<a href="/adm/email">'.&mt('Communicate').'</a>']);
1.1 albertel 886: } else {
887: $r->print($header);
888: }
889: $r->print($result);
890: $r->print('<input type="hidden" name="displayedcrit" value="true" /></form>');
891: }
892:
893: sub sortedmessages {
1.53 raeburn 894: my ($blocked,$startblock,$endblock,$numblocked,$folder,$msgstatus) = @_;
1.1 albertel 895: my $suffix=&Apache::lonmsg::foldersuffix($folder);
896: my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
897: #unpack the varibles and repack into temp for sorting
898: my @temp;
899: my %descriptions;
900: my %status_cache =
901: &Apache::lonnet::get('email_status'.&Apache::lonmsg::foldersuffix($folder),\@messages);
1.11 albertel 902:
903: my $get_received;
904: if ($folder eq 'sent'
905: && ($env{'form.sortedby'} =~ m/^(rev)?(user|domain)$/)) {
906: $get_received = 1;
907: }
908:
909: foreach my $msgid (@messages) {
1.114 raeburn 910: next if ($msgid eq '');
1.29 www 911: my $esc_msgid=&escape($msgid);
1.59 raeburn 912: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,$processid,$symb,$error) =
1.11 albertel 913: &Apache::lonmsg::unpackmsgid($esc_msgid,$folder,undef,
1.1 albertel 914: \%status_cache);
1.53 raeburn 915: next if ($msgstatus ne '' && $msgstatus ne $status);
1.1 albertel 916: my $description = &get_course_desc($fromcid,\%descriptions);
917: my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
1.11 albertel 918: $esc_msgid,$description);
919: if ($get_received) {
920: my %message = &Apache::lonnet::get('nohist_email'.$suffix,
921: [$msgid]);
922: my %content = &Apache::lonmsg::unpackagemsg($message{$msgid});
923: push(@temp1,$content{'recuser'},$content{'recdomain'});
924: }
1.1 albertel 925: # Check whether message was sent during blocking period.
926: if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
1.11 albertel 927: $$blocked{$msgid} = 'ON';
1.1 albertel 928: $$numblocked ++;
929: } else {
930: push @temp ,\@temp1;
931: }
932: }
933: #default sort
934: @temp = sort {$a->[0] <=> $b->[0]} @temp;
935: if ($env{'form.sortedby'} eq "date"){
936: @temp = sort {$a->[0] <=> $b->[0]} @temp;
937: }
938: if ($env{'form.sortedby'} eq "revdate"){
939: @temp = sort {$b->[0] <=> $a->[0]} @temp;
940: }
941: if ($env{'form.sortedby'} eq "user"){
1.11 albertel 942: if ($get_received) {
943: @temp = sort {lc($a->[7][0]) cmp lc($b->[7][0])} @temp;
944: } else {
945: @temp = sort {lc($a->[2]) cmp lc($b->[2])} @temp;
946: }
1.1 albertel 947: }
948: if ($env{'form.sortedby'} eq "revuser"){
1.11 albertel 949: if ($get_received) {
950: @temp = sort {lc($b->[7][0]) cmp lc($a->[7][0])} @temp;
951: } else {
952: @temp = sort {lc($b->[2]) cmp lc($a->[2])} @temp;
953: }
1.1 albertel 954: }
955: if ($env{'form.sortedby'} eq "domain"){
1.11 albertel 956: if ($get_received) {
957: @temp = sort {$a->[8][0] cmp $b->[8][0]} @temp;
958: } else {
959: @temp = sort {$a->[3] cmp $b->[3]} @temp;
960: }
1.1 albertel 961: }
962: if ($env{'form.sortedby'} eq "revdomain"){
1.11 albertel 963: if ($get_received) {
964: @temp = sort {$b->[8][0] cmp $a->[8][0]} @temp;
965: } else {
966: @temp = sort {$b->[3] cmp $a->[3]} @temp;
967: }
1.1 albertel 968: }
969: if ($env{'form.sortedby'} eq "subject"){
970: @temp = sort {lc($a->[1]) cmp lc($b->[1])} @temp;
971: }
972: if ($env{'form.sortedby'} eq "revsubject"){
973: @temp = sort {lc($b->[1]) cmp lc($a->[1])} @temp;
974: }
975: if ($env{'form.sortedby'} eq "course"){
976: @temp = sort {lc($a->[6]) cmp lc($b->[6])} @temp;
977: }
978: if ($env{'form.sortedby'} eq "revcourse"){
979: @temp = sort {lc($b->[6]) cmp lc($a->[6])} @temp;
980: }
981: if ($env{'form.sortedby'} eq "status"){
982: @temp = sort {$a->[4] cmp $b->[4]} @temp;
983: }
984: if ($env{'form.sortedby'} eq "revstatus"){
985: @temp = sort {$b->[4] cmp $a->[4]} @temp;
986: }
987: return @temp;
988: }
989:
990: sub get_course_desc {
991: my ($fromcid,$descriptions) = @_;
992: my $description;
993: if (!$fromcid) {
994: return $description;
995: } else {
996: if (defined($$descriptions{$fromcid})) {
997: $description = $$descriptions{$fromcid};
998: } else {
999: if (defined($env{'course.'.$fromcid.'.description'})) {
1000: $description = $env{'course.'.$fromcid.'.description'};
1001: } else {
1.157 raeburn 1002: if ($fromcid =~ m{/^$match_domain\_$match_courseid$}) {
1003: my %courseinfo=&Apache::lonnet::coursedescription($fromcid,
1004: {'one_time' => 1});
1005: $description = $courseinfo{'description'};
1006: }
1007: }
1008: if ($description ne '') {
1009: $$descriptions{$fromcid} = $description;
1.1 albertel 1010: }
1011: }
1012: return $description;
1013: }
1014: }
1015:
1016: # ======================================================== Display all messages
1017:
1018: sub disall {
1.53 raeburn 1019: my ($r,$folder,$msgstatus)=@_;
1.81 albertel 1020: my %saveable = ('msgstatus' => 'scalar',
1.57 albertel 1021: 'sortedby' => 'scalar',
1022: 'interdis' => 'scalar',
1023: );
1024: &Apache::loncommon::store_settings('user','mail',\%saveable);
1025: &Apache::loncommon::restore_settings('user','mail',\%saveable);
1026: $folder ||= $env{'form.folder'};
1.175 musolffc 1027: # Always show critical messages if present
1028: my @what=&Apache::lonnet::dump('critical',$env{'user.domain'},$env{'user.name'});
1029: if ($what[0]) {
1030: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
1031: $folder = 'critical';
1032: }
1033: }
1.57 albertel 1034: $msgstatus ||= $env{'form.msgstatus'};
1035: $env{'form.interdis'} ||= 20;
1036:
1.53 raeburn 1037: $r->print(&folderlist($folder,$msgstatus));
1038: if ($folder eq 'critical') {
1.1 albertel 1039: &discrit($r);
1040: } else {
1.53 raeburn 1041: &disfolder($r,$folder,$msgstatus);
1.1 albertel 1042: }
1043: }
1044:
1045: # ============================================================ Display a folder
1046:
1047: sub disfolder {
1.53 raeburn 1048: my ($r,$folder,$msgstatus)=@_;
1049: my %statushash = &get_msgstatus_types();
1.1 albertel 1050: my %blocked = ();
1051: my %setters = ();
1052: my $numblocked = 0;
1.44 raeburn 1053: my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53 raeburn 1054: my %lt = &Apache::lonlocal::texthash(
1055: sede => 'Select a destination folder to which the messages will be moved.',
1.148 bisitz 1056: nome => 'No messages have been selected to apply this action to.',
1.53 raeburn 1057: chec => 'Check the checkbox for at least one message.',
1058: );
1.64 raeburn 1059: my $jscript = &Apache::loncommon::check_uncheck_jscript();
1.1 albertel 1060: $r->print(<<ENDDISHEADER);
1.16 albertel 1061: <script type="text/javascript">
1.127 bisitz 1062: // <![CDATA[
1.64 raeburn 1063: $jscript
1.1 albertel 1064:
1.53 raeburn 1065: function validate_checkedaction() {
1066: document.disall.markedaction.value = document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value;
1067: if (document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value == 'markedmove') {
1068: if (document.disall.movetofolder.options[document.disall.movetofolder.selectedIndex].value == "") {
1069: alert("$lt{'sede'}");
1070: return;
1071: }
1072: }
1073: var checktotal = 0;
1.64 raeburn 1074: if (document.forms.disall.delmark.length > 0) {
1075: for (var i=0; i<document.forms.disall.delmark.length; i++) {
1076: if (document.forms.disall.delmark[i].checked) {
1077: checktotal ++;
1078: }
1079: }
1080: } else {
1081: if (document.forms.disall.delmark.checked) {
1.53 raeburn 1082: checktotal ++;
1083: }
1.64 raeburn 1084: }
1.53 raeburn 1085: if (checktotal == 0) {
1086: alert("$lt{'nome'}\\n$lt{'chec'}");
1087: return;
1088: }
1089: document.disall.submit();
1090: }
1.127 bisitz 1091: // ]]>
1.1 albertel 1092: </script>
1093: ENDDISHEADER
1.54 albertel 1094:
1.127 bisitz 1095: my $fsqs='&folder='.$folder;
1.53 raeburn 1096: my @temp=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1 albertel 1097: my $totalnumber=$#temp+1;
1.53 raeburn 1098: if ($totalnumber < 1) {
1.141 bisitz 1099: $r->print('<p class="LC_info">');
1.53 raeburn 1100: if ($msgstatus eq '') {
1.141 bisitz 1101: $r->print(&mt('There are no messages in this folder.'));
1.53 raeburn 1102: } elsif ($msgstatus eq 'replied') {
1.141 bisitz 1103: $r->print(&mt('You have not replied to any messages in this folder.'));
1104: } else {
1105: $r->print(&mt('There are no '.lc($statushash{$msgstatus}).' messages in this folder.'));
1.53 raeburn 1106: }
1.141 bisitz 1107: $r->print('</p>');
1.65 raeburn 1108: if ($numblocked > 0) {
1109: $r->print(&blocked_in_folder($numblocked,$startblock,$endblock,
1110: \%setters));
1111: }
1.141 bisitz 1112: return;
1.1 albertel 1113: }
1.57 albertel 1114: my $interdis = $env{'form.interdis'};
1.1 albertel 1115: my $number=int($totalnumber/$interdis);
1.57 albertel 1116: if ($totalnumber%$interdis == 0) {
1117: $number--;
1.53 raeburn 1118: }
1119:
1.1 albertel 1120: if (($startdis<0) || ($startdis>$number)) { $startdis=$number; }
1121: my $firstdis=$interdis*$startdis;
1122: if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; }
1123: my $lastdis=$firstdis+$interdis-1;
1124: if ($lastdis>$#temp) { $lastdis=$#temp; }
1.53 raeburn 1125: $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber,$msgstatus));
1.1 albertel 1126: $r->print('<form method="post" name="disall" action="/adm/email">'.
1.149 bisitz 1127: &Apache::loncommon::start_data_table().
1128: &Apache::loncommon::start_data_table_row().
1129: '<th colspan="1"> </th><th>');
1.1 albertel 1130: if ($env{'form.sortedby'} eq "revdate") {
1.134 raeburn 1131: $r->print('<a href = "/adm/email?sortedby=date'.$fsqs.'">'.&mt('Date').'</a></th>');
1.1 albertel 1132: } else {
1.134 raeburn 1133: $r->print('<a href = "/adm/email?sortedby=revdate'.$fsqs.'">'.&mt('Date').'</a></th>');
1.1 albertel 1134: }
1135: $r->print('<th>');
1136: if ($env{'form.sortedby'} eq "revuser") {
1.134 raeburn 1137: $r->print('<a href = "/adm/email?sortedby=user'.$fsqs.'">'.&mt('Username').'</a>');
1.1 albertel 1138: } else {
1.134 raeburn 1139: $r->print('<a href = "/adm/email?sortedby=revuser'.$fsqs.'">'.&mt('Username').'</a>');
1.1 albertel 1140: }
1141: $r->print('</th><th>');
1142: if ($env{'form.sortedby'} eq "revdomain") {
1.134 raeburn 1143: $r->print('<a href = "/adm/email?sortedby=domain'.$fsqs.'">'.&mt('Domain').'</a>');
1.1 albertel 1144: } else {
1.134 raeburn 1145: $r->print('<a href = "/adm/email?sortedby=revdomain'.$fsqs.'">'.&mt('Domain').'</a>');
1.1 albertel 1146: }
1147: $r->print('</th><th>');
1148: if ($env{'form.sortedby'} eq "revsubject") {
1.134 raeburn 1149: $r->print('<a href = "/adm/email?sortedby=subject'.$fsqs.'">'.&mt('Subject').'</a>');
1.1 albertel 1150: } else {
1.134 raeburn 1151: $r->print('<a href = "/adm/email?sortedby=revsubject'.$fsqs.'">'.&mt('Subject').'</a>');
1.1 albertel 1152: }
1153: $r->print('</th><th>');
1154: if ($env{'form.sortedby'} eq "revcourse") {
1.134 raeburn 1155: $r->print('<a href = "/adm/email?sortedby=course'.$fsqs.'">'.&mt('Course').'</a>');
1.1 albertel 1156: } else {
1.134 raeburn 1157: $r->print('<a href = "/adm/email?sortedby=revcourse'.$fsqs.'">'.&mt('Course').'</a>');
1.1 albertel 1158: }
1.149 bisitz 1159: $r->print('</th><th colspan="2">');
1.1 albertel 1160: if ($env{'form.sortedby'} eq "revstatus") {
1.134 raeburn 1161: $r->print('<a href = "/adm/email?sortedby=status'.$fsqs.'">'.&mt('Status').'</a></th>');
1.1 albertel 1162: } else {
1.134 raeburn 1163: $r->print('<a href = "/adm/email?sortedby=revstatus'.$fsqs.'">'.&mt('Status').'</a></th>');
1.1 albertel 1164: }
1165: $r->print("</tr>\n");
1.6 albertel 1166:
1167: my $suffix = &Apache::lonmsg::foldersuffix($folder);
1.132 raeburn 1168: my $count = $firstdis;
1.1 albertel 1169: for (my $n=$firstdis;$n<=$lastdis;$n++) {
1.11 albertel 1170: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,
1171: $description,$recv_name,$recv_domain)=
1172: @{$temp[$n]};
1.149 bisitz 1173: if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
1174: my $class_msgstatus = '';
1.114 raeburn 1175: $count ++;
1.149 bisitz 1176: if ($status eq 'new') {
1177: $class_msgstatus = 'LC_mail_new';
1178: } elsif ($status eq 'read') {
1179: $class_msgstatus = 'LC_mail_read';
1180: } elsif ($status eq 'replied') {
1181: $class_msgstatus = 'LC_mail_replied';
1182: } else {
1183: $class_msgstatus = 'LC_mail_other';
1184: }
1185: $r->print(&Apache::loncommon::start_data_table_row($class_msgstatus));
1.6 albertel 1186: my ($dis_name,$dis_domain) = ($fromname,$fromdomain);
1187: if ($folder eq 'sent') {
1.69 raeburn 1188: if (defined($recv_name) && defined($recv_domain)) {
1189: if (ref($recv_name) eq 'ARRAY' &&
1190: ref($recv_domain) eq 'ARRAY') {
1191: $dis_name = join('<br />',@{$recv_name});
1192: $dis_domain = join('<br />',@{$recv_domain});
1193: }
1.11 albertel 1194: } else {
1.29 www 1195: my $msg_id = &unescape($origID);
1.11 albertel 1196: my %message = &Apache::lonnet::get('nohist_email'.$suffix,
1197: [$msg_id]);
1198: my %content = &Apache::lonmsg::unpackagemsg($message{$msg_id});
1.69 raeburn 1199: if (ref($content{'recuser'}) eq 'ARRAY') {
1200: $dis_name = join('<br />',@{$content{'recuser'}});
1201: }
1202: if (ref($content{'recdomain'}) eq 'ARRAY') {
1203: $dis_domain = join('<br />',@{$content{'recdomain'}});
1204: }
1.11 albertel 1205: }
1.6 albertel 1206: }
1.53 raeburn 1207: my $localsenttime = &Apache::lonlocal::locallocaltime($sendtime);
1.102 bisitz 1208: $r->print('<td align="right"><span class="LC_nobreak">'.(($status eq 'new')?'<b>':'').
1.53 raeburn 1209: $count.'.'.(($status eq 'new')?'</b>':'').' '.
1210: '<input type="checkbox" name="delmark"'.
1.102 bisitz 1211: ' value="'.$origID.'" /></span></td>');
1.53 raeburn 1212: foreach my $item ($localsenttime,$dis_name,$dis_domain,$shortsubj) {
1213: $r->print('<td>'.(($status eq 'new')?'<b>':'').
1.61 raeburn 1214: '<a href="/adm/email?display='.$origID.$sqs.'">'.
1.170 bisitz 1215: $item.'</a>'.(($status eq 'new')?'</b>':'').'</td>');
1.53 raeburn 1216: }
1.149 bisitz 1217: # Description and Status
1.53 raeburn 1218: my $showstatus;
1219: my %statushash = &get_msgstatus_types();
1220: if ($status eq '') {
1221: $showstatus = '';
1222: } else {
1223: $showstatus = $statushash{$status};
1224: }
1.149 bisitz 1225: $r->print('<td>'.(($status eq 'new')?'<b>':'').$description.
1226: (($status eq 'new')?'</b>':'').
1227: '</td>');
1228: $r->print('<td class="'.$class_msgstatus.'"> </td>'.
1229: '<td>'.
1230: (($status eq 'new')?'<b>':'').&mt($showstatus).
1231: (($status eq 'new')?'</b>':'').
1232: '</td>');
1233:
1234: $r->print(&Apache::loncommon::end_data_table_row());
1235:
1236: } elsif ($status eq 'deleted') {
1.1 albertel 1237: # purge
1.149 bisitz 1238: my ($result,$msg) =
1239: &movemsg(&unescape($origID),$folder,'trash');
1240: }
1.1 albertel 1241: }
1.149 bisitz 1242: $r->print(&Apache::loncommon::end_data_table());
1243:
1244:
1245: # Bottom Functions
1.162 bisitz 1246: $r->print('
1247: <div class="LC_columnSection"><fieldset>
1248: <legend>'.&mt('Message Actions').'</legend>
1249: <table border="0" cellspacing="2" cellpadding="8">
1.53 raeburn 1250: <tr>
1.162 bisitz 1251: <td><b>'.&mt('Select Messages').'</b><br />
1.148 bisitz 1252: <span class="LC_nobreak">
1253: <input type="button" onclick="javascript:checkAll(document.disall.delmark)" value="'.&mt('Check All').'" />'."\n".
1254: ' <input type="button" onclick="javascript:uncheckAll(document.disall.delmark)" value="'.&mt('Uncheck All').'" />'."\n".
1255: '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" />
1256: </span>
1257: </td>'."\n".
1258: '<td><b>'.&mt('Action').'</b><br />'."\n".
1.83 raeburn 1259: ' <select name="checkedaction">'."\n");
1.53 raeburn 1260:
1.1 albertel 1261: if ($folder ne 'trash') {
1.53 raeburn 1262: $r->print(' <option value="markeddel">'.&mt('Delete').'</option>'."\n");
1263: }
1264: if ($msgstatus ne 'read') {
1.170 bisitz 1265: $r->print(' <option value="markedread">'.&mt('Mark Read').'</option>'."\n");
1.53 raeburn 1266: }
1267: if ($msgstatus ne 'unread') {
1268: $r->print(' <option value="markedunread">'.&mt('Mark Unread').'</option>'."\n");
1.1 albertel 1269: }
1.53 raeburn 1270: $r->print(' <option value="markedforward">'.&mt('Forward').'</option>'."\n");
1.54 albertel 1271:
1272: my %gotfolders = &Apache::lonmsg::get_user_folders();
1.53 raeburn 1273: if (keys(%gotfolders) > 0) {
1274: $r->print(' <option value="markedmove">'.&mt('Move to Folder ->').
1275: '</option>');
1276: }
1277: $r->print("\n".'</select></td>'."\n");
1.54 albertel 1278:
1.53 raeburn 1279: if (keys(%gotfolders) > 0) {
1.162 bisitz 1280: $r->print('<td><b>'.&mt('Destination folder').'</b><br />');
1.54 albertel 1281: my %userfolders;
1.53 raeburn 1282: foreach my $key (keys(%gotfolders)) {
1283: $userfolders{$key} = $key;
1284: }
1285: $userfolders{''} = "";
1.153 raeburn 1286: $r->print(&Apache::loncommon::select_form('','movetofolder',\%userfolders).
1.53 raeburn 1287: '</td>');
1288: }
1.162 bisitz 1289: $r->print('<td style="vertical-align:bottom;">'.
1.53 raeburn 1290: '<input type="button" name="go" value="'.&mt('Go').
1291: '" onclick="javascript:validate_checkedaction()"/></td>'."\n".
1.162 bisitz 1292: '</tr></table>'."\n".
1293: '</fieldset></div>'."\n"
1294: );
1.1 albertel 1295: my $postedstartdis=$startdis+1;
1.121 bisitz 1296: $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 1297: if ($numblocked > 0) {
1.65 raeburn 1298: $r->print(&blocked_in_folder($numblocked,$startblock,$endblock,
1299: \%setters));
1.1 albertel 1300: }
1301: }
1302:
1.65 raeburn 1303: sub blocked_in_folder {
1304: my ($numblocked,$startblock,$endblock,$setters) = @_;
1305: my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
1306: my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
1307: my $output = '<br /><br />'.
1308: &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 1309: #$output .= &Apache::loncommon::build_block_table($startblock,$endblock,
1310: # $setters);
1311:
1.130 kalberla 1312: my ($blocked, $blocktext) = &Apache::loncommon::blocking_status("com");
1.131 kalberla 1313: $output .="<br /><br />".$blocktext;
1.129 kalberla 1314:
1.65 raeburn 1315: return $output;
1316: }
1317:
1.1 albertel 1318: # ============================================================== Compose output
1319:
1320: sub compout {
1.53 raeburn 1321: my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode,
1322: $multiforward)=@_;
1.1 albertel 1323: my $suffix=&Apache::lonmsg::foldersuffix($folder);
1.38 raeburn 1324: my ($cdom,$cnum,$group,$refarg);
1325: if (exists($env{'form.group'})) {
1326: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1327: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1328: $group = $env{'form.group'};
1329: my $action = 'composing';
1330: $r->print(&groupmail_header($action,$group,$cdom,$cnum));
1331: } elsif ($broadcast eq 'individual') {
1.1 albertel 1332: &printheader($r,'/adm/email?compose=individual',
1333: 'Send a Message');
1334: } elsif ($broadcast) {
1335: &printheader($r,'/adm/email?compose=group',
1336: 'Broadcast Message');
1337: } elsif ($forwarding) {
1338: &Apache::lonhtmlcommon::add_breadcrumb
1.29 www 1339: ({href=>"/adm/email?display=".&escape($forwarding),
1.1 albertel 1340: text=>"Display Message"});
1.29 www 1341: &printheader($r,'/adm/email?forward='.&escape($forwarding),
1.1 albertel 1342: 'Forwarding a Message');
1343: } elsif ($replying) {
1344: &Apache::lonhtmlcommon::add_breadcrumb
1.29 www 1345: ({href=>"/adm/email?display=".&escape($replying),
1.1 albertel 1346: text=>"Display Message"});
1.29 www 1347: &printheader($r,'/adm/email?replyto='.&escape($replying),
1.1 albertel 1348: 'Replying to a Message');
1349: } elsif ($replycrit) {
1350: $r->print('<h3>'.&mt('Replying to a Critical Message').'</h3>');
1351: $replying=$replycrit;
1.53 raeburn 1352: } elsif ($multiforward) {
1353: &Apache::lonhtmlcommon::add_breadcrumb
1354: ({href=>"/adm/email?folder=".&escape($folder),
1.112 weissno 1355: text=>"Display All Messages"});
1.53 raeburn 1356: &printheader($r,'/adm/email?compose=multiforward',
1357: 'Forwarding Multiple Messages');
1.70 raeburn 1358: if ($multiforward > 1) {
1.144 raeburn 1359: $r->print(&mt('Each of the[_1] [quant,_2,message] [_3]you checked'
1.135 bisitz 1360: .' will be forwarded to the recipient(s) you select below.'
1.144 raeburn 1361: ,'<b>',$multiforward,'</b>')
1.85 bisitz 1362: .'<br />');
1.70 raeburn 1363: } else {
1364: $r->print(&mt('The message you checked will be forwarded to the recipient(s) you select below.').'<br />');
1365: }
1366:
1.1 albertel 1367: } else {
1368: &printheader($r,'/adm/email?compose=upload',
1369: 'Distribute from Uploaded File');
1370: }
1371:
1372: my $dispcrit='';
1373: my $dissub='';
1374: my $dismsg='';
1375: my $disbase='';
1.86 raeburn 1376: my $attachrow;
1.94 bisitz 1377: my $func1='Send'; # do not translate here!
1378: my %func2=( # do not translate here!
1379: 'ma' => 'Message',
1380: 'msg' => 'Messages',
1381: );
1.50 raeburn 1382: my %lt=&Apache::lonlocal::texthash('us' => 'Username',
1383: 'do' => 'Domain',
1384: 'ad' => 'Additional Recipients',
1.78 raeburn 1385: 'rt' => 'Reply to',
1386: 'ar' => 'Allow replies',
1.50 raeburn 1387: 'sb' => 'Subject',
1388: 'ca' => 'Cancel',
1389: 'gen' => 'Generate messages from a file',
1390: 'gmt' => 'General message text',
1391: 'tff' => 'The file format for the uploaded portion of the message is',
1392: 'uas' => 'Upload and Send',
1.86 raeburn 1393: 'atta' => 'Attachment',
1.95 raeburn 1394: 'to' => 'To:',
1.50 raeburn 1395: );
1.86 raeburn 1396: my %attachmax = (
1.93 bisitz 1397: text => &mt('(128 KB max size)'),
1.86 raeburn 1398: num => 131072,
1399: );
1400: if (!$forwarding && !$multiforward) {
1.95 raeburn 1401: $attachrow = '<tr><td colspan="3"><b>'.$lt{'atta'}.'</b> '.$attachmax{'text'}.': <input type="file" name="attachment" /></td></tr>';
1.86 raeburn 1402: }
1.1 albertel 1403: if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
1404: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
1405: '/'.$env{'request.course.sec'})) {
1.138 raeburn 1406: my $crstype = &Apache::loncommon::course_type();
1.1 albertel 1407: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1.138 raeburn 1408: my $rsstxt;
1409: if (&Apache::loncommon::course_type() eq 'Community') {
1410: $rsstxt = &mt('Include in community RSS newsfeed');
1411: } else {
1412: $rsstxt = &mt('Include in course RSS newsfeed');
1413: }
1.1 albertel 1414: $dispcrit=
1.95 raeburn 1415: '<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 />'.
1416: '<label><input type="checkbox" name="permanent" /> '.
1.100 schafran 1417: &mt('Send copy to permanent e-mail address (if known)').'</label><br />'.
1.95 raeburn 1418: '<label><input type="checkbox" name="rsspost" /> '.
1.138 raeburn 1419: $rsstxt.'</label><br />';
1.70 raeburn 1420: }
1.71 raeburn 1421: if ($broadcast ne 'group') {
1422: if (&Apache::lonnet::allowed('dff',$env{'request.course.id'}) ||
1423: &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1424: '/'.$env{'request.course.sec'})) {
1425:
1.138 raeburn 1426: my $rectxt;
1427: if (&Apache::loncommon::course_type() eq 'Community') {
1428: $rectxt = &mt("Include in community's 'User records' for recipient(s)");
1429: } else {
1430: $rectxt = &mt("Include in course's 'User records' for recipient(s)");
1431: }
1432:
1.95 raeburn 1433: $dispcrit.='<label>'.
1.71 raeburn 1434: '<input type="checkbox" name="courserecord" value="1" /> '.
1.138 raeburn 1435: $rectxt.
1.95 raeburn 1436: '</label><br />';
1.71 raeburn 1437: }
1.70 raeburn 1438: }
1439:
1.1 albertel 1440: my %message;
1441: my %content;
1.95 raeburn 1442: my ($hasfloat,$broadcast_js,$sendmode,$can_grp_broadcast);
1.1 albertel 1443: my $defdom=$env{'user.domain'};
1.95 raeburn 1444: if ($broadcast eq 'group') {
1445: my %access_status = (
1446: active => 0,
1447: previous => 0,
1448: future => 0,
1449: );
1450:
1451: if ($group eq '') {
1452: my $studentsel = &discourse(\%access_status);
1453: if ($studentsel) {
1.154 raeburn 1454: $r->print('<div class="LC_left_float">'.$studentsel.'</div>');
1.95 raeburn 1455: $hasfloat = 1;
1456: }
1457: } else {
1458: $can_grp_broadcast = &check_group_priv($group);
1459: if ($can_grp_broadcast) {
1.105 raeburn 1460: $hasfloat = &disgroup($r,$cdom,$cnum,$group,\%access_status);
1.95 raeburn 1461: }
1462: }
1463: if ($hasfloat) {
1464: $sendmode = '<input type="hidden" name="sendmode" value="group" />'."\n";
1465: $broadcast_js = qq|
1466: <script type="text/javascript">
1.127 bisitz 1467: // <![CDATA[
1.95 raeburn 1468: function courseRecipients() {
1469: |;
1470: foreach my $type (keys(%access_status)) {
1471: if ($access_status{$type}) {
1472: my $formname = $type.'users';
1473: if ($type eq 'active' && $group ne '') {
1474: $broadcast_js .= qq|
1475: document.compemail.groupmail.value = document.$formname.groupmail[document.$formname.groupmail.selectedIndex].value;
1476: |;
1477: }
1.160 golterma 1478: #typeof(...forminput.length) returns 'undefined' if only one entry exists
1.95 raeburn 1479: $broadcast_js .= qq|
1480: if (typeof(document.$formname.selectedusers_forminput.length)=="undefined") {
1.160 golterma 1481: if (document.$formname.selectedusers_forminput.checked) {
1482: document.compemail.courserecips.value += '_&&&_'+document.$formname.selectedusers_forminput.value;
1483: }
1.95 raeburn 1484: } else {
1485: for (var i=0; i<document.$formname.selectedusers_forminput.length; i++) {
1486: if (document.$formname.selectedusers_forminput[i].checked) {
1487: document.compemail.courserecips.value += '_&&&_'+document.$formname.selectedusers_forminput[i].value;
1488: }
1489: }
1490: }
1491: |;
1492: }
1493: }
1494: $broadcast_js .= qq|
1495: return;
1496: }
1.127 bisitz 1497: // ]]>
1.95 raeburn 1498: </script>
1499:
1500: |;
1501: }
1502: }
1.1 albertel 1503: if ($forwarding) {
1504: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]);
1505: %content=&Apache::lonmsg::unpackagemsg($message{$forwarding},$folder);
1506: $dispcrit.='<input type="hidden" name="forwid" value="'.
1507: $forwarding.'" />';
1.94 bisitz 1508: $func1='Forward'; # do not translate here!
1.1 albertel 1509:
1510: $dissub=&mt('Forwarding').': '.$content{'subject'};
1511: $dismsg=&mt('Forwarded message from').' '.
1512: $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
1513: if ($content{'baseurl'}) {
1.29 www 1514: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1 albertel 1515: }
1516: }
1517: if ($replying) {
1518: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
1519: %content=&Apache::lonmsg::unpackagemsg($message{$replying},$folder);
1520: $dispcrit.='<input type="hidden" name="replyid" value="'.
1521: $replying.'" />';
1.94 bisitz 1522: $func1='Send Reply to'; # do not translate here!
1.1 albertel 1523:
1524: $dissub=&mt('Reply').': '.$content{'subject'};
1525: $dismsg='> '.$content{'message'};
1526: $dismsg=~s/\r/\n/g;
1527: $dismsg=~s/\f/\n/g;
1528: $dismsg=~s/\n+/\n\> /g;
1529: if ($content{'baseurl'}) {
1.29 www 1530: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1 albertel 1531: if ($env{'user.adv'}) {
1.72 albertel 1532: $disbase.='<label><input type="checkbox" name="storebasecomment" />'.&mt('Save message for re-use').
1.1 albertel 1533: '</label> <a href="/adm/email?showcommentbaseurl='.
1.29 www 1534: &escape($content{'baseurl'}).'" target="comments">'.
1.1 albertel 1535: &mt('Show re-usable messages').'</a><br />';
1536: }
1537: }
1.73 raeburn 1538: my $jscript = &Apache::loncommon::check_uncheck_jscript();
1539: $r->print(<<"ENDREPSCRIPT");
1540: <script type="text/javascript">
1.127 bisitz 1541: // <![CDATA[
1.73 raeburn 1542: $jscript
1.127 bisitz 1543: // ]]>
1.73 raeburn 1544: </script>
1545: ENDREPSCRIPT
1.1 albertel 1546: }
1547: my $citation=&displayresource(%content);
1.95 raeburn 1548: my $onsubmit;
1.1 albertel 1549: if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
1.23 www 1550: if ($env{'form.text'}) { $dismsg=$env{'form.text'}; }
1551: if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; }
1.95 raeburn 1552: if ($hasfloat) {
1.154 raeburn 1553: $r->print($broadcast_js.'<div class="LC_left_float">');
1.95 raeburn 1554: $onsubmit = ' onsubmit="javascript:courseRecipients();" ';
1555: }
1.23 www 1556: $r->print(
1.1 albertel 1557: '<form action="/adm/email" name="compemail" method="post"'.
1.95 raeburn 1558: ' enctype="multipart/form-data"'.$onsubmit.'>'."\n".
1559: '<input type="hidden" name="sendmail" value="on" />'."\n".
1560: '<table>');
1561: if (($broadcast eq 'group') && ($group ne '') && (!$can_grp_broadcast)) {
1.38 raeburn 1562: $r->print(&recipient_input_row($cdom,%lt));
1.95 raeburn 1563: }
1.38 raeburn 1564: if (($broadcast ne 'group') && ($broadcast ne 'upload')) {
1.1 albertel 1565: if ($replying) {
1.78 raeburn 1566: if ($content{'noreplies'}) {
1567: $r->print('<tr><td>'.&mt('This message was designated by the sender not to allow replies.').'</td></tr></table></form>');
1568: return;
1569: }
1.95 raeburn 1570: $r->print('<tr><td colspan="3"><b>'.&mt('Replying to').'</b> ');
1.78 raeburn 1571: if ($content{'replytoaddr'}) {
1572: my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
1573: if ($replytoname ne '' && $replytodom ne '') {
1574: $r->print(&Apache::loncommon::plainname($replytoname,
1575: $replytodom).' ('.$replytoname.':'.
1576: $replytodom.')');
1577: $r->print('<input type="hidden" name="recuname" value="'.
1578: $replytoname.'" />'.
1579: '<input type="hidden" name="recdomain" value="'.
1580: $replytodom.'" /></td></tr>');
1581:
1582: } else {
1583: $r->print(&mt('The sender did not designate a reply to address for this message.').'</td></tr></table>');
1584: return;
1585: }
1586: } else {
1587: $r->print(&Apache::loncommon::aboutmewrapper(
1.1 albertel 1588: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
1.14 albertel 1589: $content{'sendername'}.':'.
1.78 raeburn 1590: $content{'senderdomain'}.')');
1591: $r->print('<input type="hidden" name="recuname" value="'.
1592: $content{'sendername'}.'" />'.
1593: '<input type="hidden" name="recdomain" value="'.
1594: $content{'senderdomain'}.'" /></td></tr>');
1595: }
1.73 raeburn 1596: if ($content{'recipid'}) {
1.95 raeburn 1597: my %recips;
1598: &retrieve_recips('replying',\%content,\%recips);
1599: if (ref($recips{'to'}) eq 'ARRAY') {
1600: if (@{$recips{'to'}} > 0) {
1601: my $replyall;
1602: if (@{$recips{'to'}} > 1) {
1603: $replyall = qq|
1604: <span class="LC_nobreak">
1605: <input type="button" value="check all"
1606: onclick="javascript:checkAll(document.compemail.replying_to)" />
1607:
1608: <input type="button" value="uncheck all"
1609: onclick="javascript:uncheckAll(document.compemail.replying_to)" />
1610: </span>
1611: |;
1612: }
1613: my $tolist = join(' ',@{$recips{'to'}});
1614: $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>');
1615: }
1616: }
1617: if (ref($recips{'cc'}) eq 'ARRAY') {
1618: if (@{$recips{'cc'}} > 0) {
1619: my $replyall;
1620: if (@{$recips{'cc'}} > 1) {
1621: $replyall = qq|
1.73 raeburn 1622: <span class="LC_nobreak">
1623: <input type="button" value="check all"
1624: onclick="javascript:checkAll(document.compemail.replying_cc)" />
1625:
1626: <input type="button" value="uncheck all"
1627: onclick="javascript:uncheckAll(document.compemail.replying_cc)" />
1628: </span>
1629: |;
1.95 raeburn 1630: }
1631: my $cclist = join(' ',@{$recips{'cc'}});
1632: $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>');
1633: }
1634: }
1635: if ($content{'group'} ne '') {
1636: if (&check_group_priv($content{'group'})) {
1637: if (ref($recips{'group_cc_broadcast'}) eq 'ARRAY') {
1638: if (@{$recips{'group_cc_broadcast'}} > 0) {
1639: my $replyall;
1640: if (@{$recips{'group_cc_broadcast'}} > 1) {
1641: $replyall = qq|
1642: <span class="LC_nobreak">
1643: <input type="button" value="check all"
1644: onclick="javascript:checkAll(document.compemail.replying_groupcc)" />
1645:
1646: <input type="button" value="uncheck all"
1647: onclick="javascript:uncheckAll(document.compemail.replying_groupcc)" />
1648: </span>
1649: |;
1650: }
1651: my $groupcclist = join(' ',@{$recips{'group_cc_broadcast'}});
1652: $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>');
1653: }
1654: }
1655: }
1.73 raeburn 1656: }
1657: }
1.1 albertel 1658: } else {
1.38 raeburn 1659: $r->print(&recipient_input_row($defdom,%lt));
1.1 albertel 1660: }
1661: }
1.109 raeburn 1662: my $latexHelp = &Apache::loncommon::helpLatexCheatsheet(undef,undef,1);
1.154 raeburn 1663: my $textareaclass;
1664: if (&Apache::lonhtmlcommon::htmlareabrowser()) {
1665: $r->print(&Apache::lonhtmlcommon::htmlareaselectactive());
1666: $textareaclass = 'class="LC_richDefaultOff"';
1667: }
1.53 raeburn 1668: my $subj_size;
1669: if ($multiforward) {
1670: $r->print(&additional_rec_row(\%lt));
1671: $r->print('<tr><td colspan="2">'.
1672: &mt('Unless you choose otherwise:').'<ul><li>'.
1.166 raeburn 1673: &mt("The subject in each forwarded message will be [_1]'Forwarding:'[_2] followed by the original subject.",'<i>','</i>').'</li><li>'.
1.165 bisitz 1674: &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 1675: $func1='Forward'; # do not translate here!
1.53 raeburn 1676: $dissub = &mt('Forwarding').': ';
1677: $subj_size = '10';
1678: my $extra = '<'.&mt('original subject').'> '.
1679: '<input type="radio" name="showorigsubj" value="1" checked="checked" />'.&mt('Yes').' <input type="radio" name="showorigsubj" value="0" />'.&mt('No');
1680: $dismsg = &mt('Forwarded message from ').' ';
1681: my $sender = &mt("sender's name");
1682: $r->print(&msg_subject_row($dissub,\%lt,$subj_size,$extra));
1683: $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>
1684: </table>
1.95 raeburn 1685: <br /><table>
1686: <tr><td align="left">'."\n".
1687: $latexHelp."<br />\n".
1688: &mt("Any new text to display before the text of the original messages:").'<br />'."\n".
1.154 raeburn 1689: '<textarea name="message" id="message" cols="80" rows="5" wrap="hard" $textareaclass></textarea>');
1.53 raeburn 1690: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
1691: foreach my $msg (@to_forward) {
1692: $r->print('<input type="hidden" name="delmark" value="'.$msg.'" />');
1693: }
1.94 bisitz 1694: $r->print(&submit_button_row($folder,$dismode,&mt($func1.' '.$func2{'msg'}),
1.53 raeburn 1695: \%lt));
1696: } elsif ($broadcast ne 'upload') {
1697: $subj_size = '50';
1698: $r->print(&additional_rec_row(\%lt));
1.78 raeburn 1699: if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
1700: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
1701: '/'.$env{'request.course.sec'})) {
1702: $r->print(&reply_to_row(\%lt));
1703: }
1.53 raeburn 1704: $r->print(&msg_subject_row($dissub,\%lt,$subj_size));
1705: $r->print(<<"ENDCOMP");
1.95 raeburn 1706: $attachrow
1707: </table><br />
1.117 bisitz 1708: $latexHelp<br />
1.154 raeburn 1709: <textarea name="message" id="message" cols="80" rows="15" wrap="hard" $textareaclass>$dismsg
1710: </textarea>
1711: <br />
1.95 raeburn 1712: $sendmode
1.1 albertel 1713: $dispcrit
1714: $disbase
1715: ENDCOMP
1.97 schafran 1716: $r->print(&submit_button_row($folder,$dismode,&mt($func1.' '.$func2{'ma'}),
1.95 raeburn 1717: \%lt,$hasfloat,$group));
1.53 raeburn 1718: $r->print($citation);
1.38 raeburn 1719: if (exists($env{'form.ref'})) {
1720: $r->print('<input type="hidden" name="ref" value="'.
1721: $env{'form.ref'}.'" />');
1722: }
1723: if (exists($env{'form.group'})) {
1724: $r->print('<input type="hidden" name="group" value="'.
1725: $env{'form.group'}.'" />');
1726: }
1.1 albertel 1727: } else { # $broadcast is 'upload'
1.50 raeburn 1728: $r->print(<<ENDBLOCK);
1.1 albertel 1729: <input type="hidden" name="sendmode" value="upload" />
1730: <input type="hidden" name="send" value="on" />
1.50 raeburn 1731: <h3>$lt{'gen'}</h3>
1.1 albertel 1732: <p>
1733: Subject: <input type="text" size="50" name="subject" />
1734: </p>
1.50 raeburn 1735: <p>$lt{'gmt'}:<br />
1.154 raeburn 1736: <textarea name="message" id="message" cols="60" rows="10" wrap="hard" $textareaclass>$dismsg
1737: </textarea></p>
1.1 albertel 1738: <p>
1.50 raeburn 1739: $lt{'tff'}:
1740: ENDBLOCK
1741: $r->print('
1742: <pre>'."\n".
1743: &mt('username1:domain1: text')."\n".
1744: &mt('username2:domain2: text')."\n".
1745: &mt('username3:domain1: text')."\n".
1746: '</pre>
1.1 albertel 1747: </p>
1748: <p>
1.164 bisitz 1749: '.&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 1750: $r->print(<<ENDUPLOAD);
1751: </p>
1.1 albertel 1752: <p>
1753: <input type="file" name="upfile" size="40" /></p><p>
1754: $dispcrit
1.50 raeburn 1755: <input type="submit" value="$lt{'uas'}" /></p>
1.1 albertel 1756: ENDUPLOAD
1757: }
1.36 albertel 1758: if ($env{'form.displayedcrit'}) {
1759: $r->print('<input type="hidden" name="displayedcrit" value="true" />');
1760: }
1.95 raeburn 1761: $r->print('</form>');
1762: if ($hasfloat) {
1.154 raeburn 1763: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.95 raeburn 1764: }
1765: $r->print(&generate_preview_form);
1766: }
1767:
1768: sub check_group_priv {
1769: my ($group) = @_;
1770: my $cid = $env{'request.course.id'};
1771: my $sec = $env{'request.course.sec'};
1772: return if !$cid;
1773: my $can_broadcast = &Apache::lonnet::allowed('sgb',$cid.'/'.$group);
1774: my $viewgrps = &Apache::lonnet::allowed('vcg',$cid.($sec?'/'.$sec:''));
1775: my $editgrps = &Apache::lonnet::allowed('mdg',$cid.($sec?'/'.$sec:''));
1776: if ($viewgrps || $editgrps || $can_broadcast) {
1777: return 1;
1778: }
1779: return;
1.1 albertel 1780: }
1781:
1.38 raeburn 1782: sub recipient_input_row {
1783: my ($dom,%lt) = @_;
1784: my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain');
1785: my $selectlink=
1786: &Apache::loncommon::selectstudent_link('compemail','recuname',
1787: 'recdomain');
1788: my $output = <<"ENDREC";
1.95 raeburn 1789: <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 1790: ENDREC
1791: return $output;
1792: }
1793:
1.78 raeburn 1794: sub reply_to_row {
1795: my ($lt) = @_;
1796: my $radioyes = &mt('Yes');
1797: my $radiono = &mt('No');
1798: my $output = <<"ENDREP";
1.95 raeburn 1799: <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 1800: ENDREP
1801: return $output;
1802: }
1803:
1.53 raeburn 1804: sub additional_rec_row {
1805: my ($lt) = @_;
1.73 raeburn 1806: my $cc = &mt('Cc:');
1.85 bisitz 1807: my $bcc = &mt('Bcc:');
1808: my $exmpl = &mt('username:domain,username:domain,...');
1.53 raeburn 1809: my $output = <<"ENDADD";
1.125 bisitz 1810: <tr><td colspan="3"><fieldset id="LC_additionalrecips"><legend>$lt->{'ad'} <tt>($exmpl)</tt></legend><table>
1.95 raeburn 1811: <tr><td> </td><td>$lt->{'to'}</td><td><input type="text" size="50" name="additionalrec_to" /></td></tr>
1812: <tr><td> </td><td>$cc</td><td><input type="text" size="50" name="additionalrec_cc" /></td></tr>
1.110 raeburn 1813: <tr><td> </td><td>$bcc</td><td><input type="text" size="50" name="additionalrec_bcc" /></td></tr></table></fieldset></td></tr>
1.53 raeburn 1814: ENDADD
1815: return $output;
1816: }
1817:
1818: sub submit_button_row {
1.95 raeburn 1819: my ($folder,$dismode,$sendtext,$lt,$is_crsform,$group) = @_;
1820: my $pre=&mt("Show Preview and Check Spelling");
1.98 schafran 1821: my $value=&mt('Send');
1.95 raeburn 1822: 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();" />';
1823: my $output = qq|
1.53 raeburn 1824: <input type="hidden" name="folder" value="$folder" />
1.95 raeburn 1825: <input type="hidden" name="dismode" value="$dismode" />|;
1826: if ($is_crsform) {
1827: $output .= '<input type="hidden" name="courserecips" value="" />'."\n";
1828: if ($group ne '') {
1829: $output .= '<input type="hidden" name="groupmail" value="" />'."\n";
1830: }
1831: }
1832: $output .= qq|
1833: <table><tr><td align="left">
1.98 schafran 1834: <input type="submit" name="send" value="$value" title="$sendtext" />
1.95 raeburn 1835: <input type="submit" name="cancel" value="$lt->{'ca'}" />
1836: </td><td width="60"> </td><td align="right">$prevbutton</td></tr></table>
1.53 raeburn 1837: |;
1838: return $output;
1839: }
1840:
1841: sub msg_subject_row {
1842: my ($dissub,$lt,$subj_size,$extra) = @_;
1.95 raeburn 1843: my $output = '<tr><td colspan="3"><b>'.$lt->{'sb'}.'</b>: <input type="text" size="'.
1.53 raeburn 1844: $subj_size.'" name="subject" value="'.$dissub.'" />'.$extra.
1845: '</td></tr>';
1846: return $output;
1847: }
1848:
1.95 raeburn 1849: sub generate_preview_form {
1850: my $prevbutton = (<<ENDPREVIEW);
1851: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1852: <input type="hidden" name="subject" />
1853: <input type="hidden" name="comment" />
1854: </form>
1855: ENDPREVIEW
1856: }
1857:
1858: # ---------------------------------------------------- Display all face to face
1859:
1.1 albertel 1860: sub retrieve_instructor_comments {
1861: my ($user,$domain)=@_;
1862: my $target=$env{'form.grade_target'};
1863: if (! $env{'request.course.id'}) { return; }
1.49 albertel 1864: if (! &Apache::lonnet::allowed('dff',$env{'request.course.id'})
1865: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1866: '/'.$env{'request.course.sec'})) {
1867: return;
1868: }
1869: my %records=&Apache::lonnet::dump('nohist_email',
1870: $env{'course.'.$env{'request.course.id'}.'.domain'},
1871: $env{'course.'.$env{'request.course.id'}.'.num'},
1872: '%255b'.$user.'%253a'.$domain.'%255d');
1873: my $result='';
1.42 raeburn 1874: foreach my $key (sort(keys(%records))) {
1875: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1 albertel 1876: next if ($content{'senderdomain'} eq '');
1877: next if ($content{'subject'} !~ /^Record/);
1878: # &Apache::lonfeedback::newline_to_br(\$content{'message'});
1879: $result.='Recorded by '.
1.14 albertel 1880: $content{'sendername'}.':'.$content{'senderdomain'}."\n";
1.1 albertel 1881: $result.=
1882: &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
1883: }
1884: return $result;
1885: }
1886:
1887: sub disfacetoface {
1.136 amueller 1888: my ($r,$user,$domain,$target)=@_;
1.145 raeburn 1889: if ($target eq '') {
1890: $target=$env{'form.grade_target'};
1891: }
1.1 albertel 1892: unless ($env{'request.course.id'}) { return; }
1.49 albertel 1893: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
1894: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1895: '/'.$env{'request.course.sec'})) {
1.50 raeburn 1896: $r->print(&mt('Not allowed'));
1.1 albertel 1897: return;
1898: }
1899: my %records=&Apache::lonnet::dump('nohist_email',
1900: $env{'course.'.$env{'request.course.id'}.'.domain'},
1901: $env{'course.'.$env{'request.course.id'}.'.num'},
1902: '%255b'.$user.'%253a'.$domain.'%255d');
1.177 raeburn 1903: my $result='';
1.42 raeburn 1904: foreach my $key (sort(keys(%records))) {
1905: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1 albertel 1906: next if ($content{'senderdomain'} eq '');
1.139 faziophi 1907: if (!&Apache::lonfeedback::contains_block_html($content{'message'})) {
1908: &Apache::lonfeedback::newline_to_br(\$content{'message'});
1909: }
1.1 albertel 1910: if ($content{'subject'}=~/^Record/) {
1911: $result.='<h3>'.&mt('Record').'</h3>';
1912: } elsif ($content{'subject'}=~/^Broadcast/) {
1913: $result .='<h3>'.&mt('Broadcast Message').'</h3>';
1914: if ($content{'subject'}=~/^Broadcast\./) {
1915: if (defined($content{'coursemsgid'})) {
1.29 www 1916: my $crsmsgid = &escape($content{'coursemsgid'});
1.1 albertel 1917: my $broadcast_message = &general_message($crsmsgid);
1918: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$broadcast_message;
1919: } else {
1920: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1921: $content{'message'} =
1922: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1923: $content{'message'};
1924: }
1.70 raeburn 1925: }
1926: } elsif ($content{'subject'}=~/^Archive/) {
1927: $result.='<h3>'.&mt('Archived Message').'</h3>';
1928: if (defined($content{'coursemsgid'})) {
1929: my $crsmsgid = &escape($content{'coursemsgid'});
1930: my $archive_message = &general_message($crsmsgid);
1931: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$archive_message;
1932: } else {
1933: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1934: $content{'message'} =
1.170 bisitz 1935: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1.70 raeburn 1936: $content{'message'};
1937: }
1.1 albertel 1938: } else {
1939: $result.='<h3>'.&mt('Critical Message').'</h3>';
1940: if (defined($content{'coursemsgid'})) {
1.29 www 1941: my $crsmsgid=&escape($content{'coursemsgid'});
1.1 albertel 1942: my $critical_message = &general_message($crsmsgid);
1943: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$critical_message;
1944: } else {
1945: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1946: $content{'message'}=
1947: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1948: $content{'message'};
1949: }
1950: }
1951: $result.=&mt('By').': <b>'.
1952: &Apache::loncommon::aboutmewrapper(
1953: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14 albertel 1954: $content{'sendername'}.':'.
1.1 albertel 1955: $content{'senderdomain'}.') '.$content{'time'}.
1956: '<br /><pre>'.
1957: &Apache::lontexconvert::msgtexconverted($content{'message'}).
1958: '</pre>';
1959: }
1960: # Check to see if there were any messages.
1961: if ($result eq '') {
1.106 riegler 1962: my $lctype = &mt(lc(&Apache::loncommon::course_type()));
1.1 albertel 1963: if ($target ne 'tex') {
1.174 bisitz 1964: $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 1965: } else {
1.174 bisitz 1966: $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this '.$lctype.'.').'}\\\\');
1.1 albertel 1967: }
1.177 raeburn 1968: } elsif ($target eq 'tex') {
1969: $r->print(&Apache::lonxml::xmlparse($r,$target,$result));
1.1 albertel 1970: } else {
1.177 raeburn 1971: $r->print('<div>'.$result.'</div>');
1972: }
1.1 albertel 1973: }
1974:
1975: sub general_message {
1976: my ($crsmsgid) = @_;
1977: my %general_content;
1978: if ($crsmsgid) {
1979: my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid],
1980: $env{'course.'.$env{'request.course.id'}.'.domain'},
1981: $env{'course.'.$env{'request.course.id'}.'.num'});
1982: %general_content = &Apache::lonmsg::unpackagemsg($course_content{$crsmsgid});
1983: }
1984: return $general_content{'message'};
1985: }
1986:
1987: # ---------------------------------------------------------------- Face to face
1988:
1989: sub facetoface {
1990: my ($r,$stage)=@_;
1.49 albertel 1991: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
1992: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1993: '/'.$env{'request.course.sec'})) {
1.50 raeburn 1994: $r->print(&mt('Not allowed'));
1.1 albertel 1995: return;
1996: }
1.33 albertel 1997: my $crstype = &Apache::loncommon::course_type();
1.128 raeburn 1998: my $leaders = ($crstype eq 'Community') ? 'coordinators and leaders'
1999: : 'faculty and staff';
1.1 albertel 2000: &printheader($r,
2001: '/adm/email?recordftf=query',
1.70 raeburn 2002: "User Notes, Face-to-Face, Critical Messages, Broadcast Messages, Archived Messages");
1.1 albertel 2003: # from query string
2004:
2005: if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
2006: if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
2007:
2008: my $defdom=$env{'user.domain'};
2009: # already filled in
2010: if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
2011: # generate output
2012: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
2013: my $stdbrws = &Apache::loncommon::selectstudent_link
2014: ('stdselect','recuname','recdomain');
2015: my %lt=&Apache::lonlocal::texthash('user' => 'Username',
2016: 'dom' => 'Domain',
1.70 raeburn 2017: 'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, Broadcast Messages and Archived Messages in $crstype",
1.1 albertel 2018: 'subm' => 'Retrieve discussion and message records',
1.30 raeburn 2019: 'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')',
1.1 albertel 2020: 'post' => 'Post this Record');
1.123 bisitz 2021:
2022: $r->print('<h2>'.$lt{'head'}.'</h2>'
2023: .'<form method="post" action="/adm/email" name="stdselect">'
2024: .'<input type="hidden" name="recordftf" value="retrieve" />'
2025: .&Apache::lonhtmlcommon::start_pick_box()
2026: .&Apache::lonhtmlcommon::row_title($lt{'user'})
2027: .'<input type="text" size="12" name="recuname" value="'.$env{'form.recuname'}.'" />'
2028: .' '.$stdbrws
2029: .&Apache::lonhtmlcommon::row_closure()
2030: .&Apache::lonhtmlcommon::row_title($lt{'dom'})
2031: .$domform
2032: .&Apache::lonhtmlcommon::row_closure(1)
2033: .&Apache::lonhtmlcommon::end_pick_box()
2034: .'<br />'
2035: .'<input type="submit" value="'.$lt{'subm'}.'" />'
1.150 raeburn 2036: .'</form>'
1.123 bisitz 2037: );
2038:
1.1 albertel 2039: if (($stage ne 'query') &&
2040: ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
2041: chomp($env{'form.newrecord'});
2042: if ($env{'form.newrecord'}) {
1.31 albertel 2043: &Apache::lonmsg::store_instructor_comment($env{'form.newrecord'},
2044: $env{'form.recuname'},
2045: $env{'form.recdomain'});
1.1 albertel 2046: }
1.123 bisitz 2047: my $aboutmelink=&Apache::loncommon::aboutmewrapper(
2048: &Apache::loncommon::plainname($env{'form.recuname'}
2049: ,$env{'form.recdomain'})
2050: ,$env{'form.recuname'},$env{'form.recdomain'});
2051: $r->print('<hr />'
2052: .'<h2>'
2053: .&mt('Discussion and message records for [_1] ([_2])'
2054: ,$aboutmelink
2055: ,$env{'form.recuname'}.':'.$env{'form.recdomain'})
1.161 bisitz 2056: .'</h2>'
1.123 bisitz 2057: );
1.1 albertel 2058: &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
2059: $r->print(<<ENDRHEAD);
2060: <form method="post" action="/adm/email">
2061: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
2062: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
2063: ENDRHEAD
2064: $r->print(<<ENDBFORM);
2065: <hr />$lt{'newr'}<br />
2066: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
2067: <br />
2068: <input type="hidden" name="recordftf" value="post" />
2069: <input type="submit" value="$lt{'post'}" />
2070: </form>
2071: ENDBFORM
2072: }
2073: }
2074:
2075: # ----------------------------------------------------------- Display a message
2076:
2077: sub displaymessage {
1.53 raeburn 2078: my ($r,$msgid,$folder,$msgstatus)=@_;
1.1 albertel 2079: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2080: my %blocked = ();
2081: my %setters = ();
2082: my $numblocked = 0;
1.33 albertel 2083: my $crstype = &Apache::loncommon::course_type();
1.30 raeburn 2084:
1.1 albertel 2085: # info to generate "next" and "previous" buttons and check if message is blocked
1.44 raeburn 2086: my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53 raeburn 2087: my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1 albertel 2088: if ( $blocked{$msgid} eq 'ON' ) {
2089: &printheader($r,'/adm/email',&mt('Display a Message'));
1.129 kalberla 2090: #$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 2091: my($blocked, $blocktext) = &Apache::loncommon::blocking_status("com");
1.129 kalberla 2092: $r->print("<br />".$blocktext);
1.1 albertel 2093: return;
2094: }
1.59 raeburn 2095: if ($msgstatus eq '') {
2096: &statuschange($msgid,'read',$folder);
2097: }
1.1 albertel 2098: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2099: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid});
2100: my $counter=0;
1.29 www 2101: my $escmsgid=&escape($msgid);
1.1 albertel 2102: foreach (@messages) {
2103: if ($_->[5] eq $escmsgid){
2104: last;
2105: }
2106: $counter++;
2107: }
1.82 albertel 2108:
2109: my $see_anonymous;
2110: my $from_student = 0;
2111: if ($env{'request.course.id'} eq $content{'courseid'}) {
2112: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2113: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2114: my $username = $content{'sendername'}.':'.$content{'senderdomain'};
2115: my %classlist_entry =
2116: &Apache::lonnet::get('classlist',[$username],$cdom,$cnum);
2117: if (exists($classlist_entry{$username})) {
2118: $from_student = 1;
2119: $see_anonymous = &Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
2120: }
2121: }
2122:
2123:
1.1 albertel 2124: my $number_of_messages = scalar(@messages); #subtract 1 for last index
2125: # start output
1.29 www 2126: &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'});
1.101 bisitz 2127:
2128: # Prepare available functions
1.119 bisitz 2129: my @functionlist;
1.78 raeburn 2130: if (!$content{'noreplies'}) {
1.119 bisitz 2131: push(@functionlist,'<a href="/adm/email?replyto='.&escape($msgid).$sqs.'">'
1.101 bisitz 2132: .&mt('Reply')
1.119 bisitz 2133: .'</a>');
1.101 bisitz 2134: }
1.119 bisitz 2135: push(@functionlist,'<a href="/adm/email?forward='.&escape($msgid).$sqs.'">'
1.101 bisitz 2136: .&mt('Forward')
1.119 bisitz 2137: .'</a>');
2138: push(@functionlist,'<a href="/adm/email?markunread='.&escape($msgid).$sqs.'">'
1.101 bisitz 2139: .&mt('Mark Unread')
1.119 bisitz 2140: .'</a>');
2141: push(@functionlist,'<a href="/adm/email?markdel='.&escape($msgid).$sqs.'">'
1.101 bisitz 2142: .&mt('Delete')
1.119 bisitz 2143: .'</a>');
1.162 bisitz 2144:
2145: # Prepare available navigation
2146: my @navigationlist;
1.1 albertel 2147: if ($counter > 0){
1.162 bisitz 2148: push(@navigationlist,'<a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.'">'
1.119 bisitz 2149: .&mt('Previous')
2150: .'</a>');
1.1 albertel 2151: }
2152: if ($counter < $number_of_messages - 1){
1.162 bisitz 2153: push(@navigationlist,'<a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.'">'
1.119 bisitz 2154: .&mt('Next')
2155: .'</a>');
1.101 bisitz 2156: }
1.162 bisitz 2157: push(@navigationlist,'<a href="/adm/email?'.$sqs.'">'
2158: .&mt('Back to Folder Display')
2159: .'</a>');
1.101 bisitz 2160:
2161: # Prepare available actions
1.59 raeburn 2162: my $symb;
2163: if (defined($content{'symb'})) {
2164: $symb = $content{'symb'};
2165: } elsif (defined($content{'baseurl'})) {
2166: $symb=&Apache::lonnet::symbread($content{'baseurl'});
2167: }
1.162 bisitz 2168: my @actionlist;
1.1 albertel 2169: if ($env{'user.adv'}) {
1.101 bisitz 2170:
1.1 albertel 2171: if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
1.119 bisitz 2172: push(@actionlist,&Apache::loncommon::track_student_link(
1.171 bisitz 2173: 'View recent activity'
1.119 bisitz 2174: ,$content{'sendername'}
2175: ,$content{'senderdomain'}
2176: ,'check'));
1.90 bisitz 2177: }
1.1 albertel 2178: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
1.119 bisitz 2179: push(@actionlist,&Apache::loncommon::pprmlink(
2180: &mt('Set/Change parameters')
2181: ,$content{'sendername'}
2182: ,$content{'senderdomain'}
2183: ,$symb
2184: ,'check'));
1.1 albertel 2185: }
2186: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
1.119 bisitz 2187: push(@actionlist,&Apache::loncommon::pgrdlink(
2188: &mt('Set/Change grades')
2189: ,$content{'sendername'}
2190: ,$content{'senderdomain'}
2191: ,$symb
2192: ,'check'));
1.90 bisitz 2193: }
1.126 bisitz 2194: }
2195:
1.162 bisitz 2196: # Print functionlist, navigationlist, and actionlist in page header
1.126 bisitz 2197: my $functions='<div class="LC_columnSection">';
1.101 bisitz 2198:
1.126 bisitz 2199: # Functionlist
2200: $functions.=&Apache::lonhtmlcommon::start_funclist();
2201: foreach my $item (@functionlist) {
2202: $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
2203: }
2204: $functions .= &Apache::lonhtmlcommon::end_funclist();
2205:
1.162 bisitz 2206: # Navigationlist
2207: $functions.=&Apache::lonhtmlcommon::start_funclist(
2208: &mt('Navigation'));
2209: foreach my $item (@navigationlist) {
2210: $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
2211: }
2212: $functions .= &Apache::lonhtmlcommon::end_funclist();
2213:
1.126 bisitz 2214: # Actionlist
1.119 bisitz 2215: if (@actionlist) {
1.162 bisitz 2216: $functions.=&Apache::lonhtmlcommon::start_funclist(
2217: &mt('Currently available actions (will open extra window)'));
1.119 bisitz 2218: foreach my $item (@actionlist) {
1.126 bisitz 2219: $functions.=&Apache::lonhtmlcommon::add_item_funclist($item);
1.119 bisitz 2220: }
1.126 bisitz 2221: $functions.=&Apache::lonhtmlcommon::end_funclist();
1.90 bisitz 2222: }
1.126 bisitz 2223:
2224: $functions.='</div>';
2225: $r->print(&Apache::loncommon::head_subbox($functions));
2226:
1.101 bisitz 2227:
1.95 raeburn 2228: my ($tonum,$tolist,$cclist,$bcclist,$groupcclist,%recipients);
2229: if ($content{'recipid'}) {
2230: $tonum = &retrieve_recips('display',\%content,\%recipients);
2231: if (ref($recipients{'cc'}) eq 'ARRAY') {
2232: $cclist = join(', ',@{$recipients{'cc'}});
2233: }
2234: if (ref($recipients{'to'}) eq 'ARRAY') {
2235: $tolist = join(', ',@{$recipients{'to'}});
2236: }
2237: if (ref($recipients{'bcc'}) eq 'ARRAY') {
2238: $bcclist = join(', ',@{$recipients{'bcc'}});
2239: }
2240: }
1.107 raeburn 2241:
2242: my $broadcast_link;
2243: if (($content{'courseid'}) && ($content{'recipid'} &&
2244: (ref($recipients{'course_broadcast'}) eq 'ARRAY') ||
2245: (ref($recipients{'group_cc_broadcast'}) eq 'ARRAY') ||
2246: (ref($recipients{'group_bcc_broadcast'}) eq 'ARRAY'))) {
2247: $broadcast_link = &recipients_link($r,\%content,\%recipients);
2248: }
2249:
2250: if (((!$tolist) && (!$broadcast_link)) && ref($content{'recuser'}) eq 'ARRAY') {
1.95 raeburn 2251: my @recipients;
1.73 raeburn 2252: for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
2253: $recipients[$i] = &Apache::loncommon::aboutmewrapper(
2254: &Apache::loncommon::plainname($content{'recuser'}[$i],
1.1 albertel 2255: $content{'recdomain'}[$i]),
1.73 raeburn 2256: $content{'recuser'}[$i],$content{'recdomain'}[$i]).
1.95 raeburn 2257: ' ('.$content{'recuser'}[$i].':'.$content{'recdomain'}[$i].') ';
1.73 raeburn 2258: }
1.95 raeburn 2259: $tolist = join(', ',@recipients);
1.73 raeburn 2260: }
1.59 raeburn 2261: my ($restitle,$baseurl,$refers_to);
2262: if (defined($content{'resource_title'})) {
2263: $restitle = $content{'resource_title'};
2264: } else {
2265: if (defined($content{'baseurl'})) {
2266: $restitle = &Apache::lonnet::gettitle($content{'baseurl'});
2267: }
2268: }
2269: if (defined($content{'baseurl'})) {
2270: $baseurl = &Apache::lonenc::check_encrypt($content{'baseurl'});
2271: }
1.104 raeburn 2272: $r->print('<div class="LC_clear_float_footer">');
1.82 albertel 2273: if ($from_student && $see_anonymous ) {
1.104 raeburn 2274: $r->print(&Apache::loncommon::student_image_tag($content{'senderdomain'},$content{'sendername'}).'</br>');
1.82 albertel 2275: }
2276:
1.91 bisitz 2277: # Display LON-CAPA Message (Start)
2278: # Subject
1.104 raeburn 2279: $r->print('</div>'
1.91 bisitz 2280: .&Apache::lonhtmlcommon::start_pick_box()
2281: .&Apache::lonhtmlcommon::row_title(&mt('Subject'))
2282: .$content{'subject'}
2283: .&Apache::lonhtmlcommon::row_closure()
2284: );
1.73 raeburn 2285: if ($folder eq 'sent') {
1.91 bisitz 2286: # To
1.107 raeburn 2287: if ($tolist) {
2288: $r->print(&Apache::lonhtmlcommon::row_title(&mt('To'))
2289: .$tolist
2290: .&Apache::lonhtmlcommon::row_closure()
2291: );
2292: }
1.95 raeburn 2293: if ($cclist) {
2294: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Cc'))
2295: .$cclist
2296: .&Apache::lonhtmlcommon::row_closure()
2297: );
2298: }
2299: if ($bcclist) {
2300: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Bcc'))
2301: .$bcclist
2302: .&Apache::lonhtmlcommon::row_closure()
2303: );
2304: }
2305: if (($content{'courseid'}) && ($content{'recipid'})) {
2306: my %broadcast_types =
2307: &Apache::lonlocal::texthash (
2308: course_broadcast => 'Broadcast to',
2309: group_cc_broadcast => 'Cc to group',
2310: group_bcc_broadcast => 'Bcc to group',
2311: );
2312: foreach my $type (sort(keys(%broadcast_types))) {
2313: if (ref($recipients{$type}) eq 'ARRAY') {
2314: my $num = @{$recipients{$type}};
2315: my $broadcastlist = join(', ',@{$recipients{$type}});
2316: if ($broadcastlist && $broadcast_link) {
2317: if ($type eq 'group_cc_broadcast') {
2318: $groupcclist = $broadcastlist;
2319: }
2320: $r->print(&Apache::lonhtmlcommon::row_title(
2321: $broadcast_types{$type})
2322: .&mt('[quant,_1,recipient]',$num)
2323: .' <a href="javascript:showBroadcastList();">['
2324: .&mt('Show').']</a>'
2325: .&Apache::lonhtmlcommon::row_closure());
2326: }
2327: }
2328: }
2329: }
1.78 raeburn 2330: if ($content{'replytoaddr'}) {
2331: my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
2332: if ($replytoname ne '' && $replytodom ne '') {
1.91 bisitz 2333: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Reply To'))
1.95 raeburn 2334: .$replytoname.':'.$replytodom
1.91 bisitz 2335: .&Apache::lonhtmlcommon::row_closure()
2336: );
1.78 raeburn 2337: }
2338: }
1.73 raeburn 2339: } else {
1.91 bisitz 2340: # From, Reply
2341: $r->print(&Apache::lonhtmlcommon::row_title(&mt('From'))
2342: .&Apache::loncommon::aboutmewrapper(
2343: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
2344: $content{'sendername'},$content{'senderdomain'})
2345: );
1.78 raeburn 2346: if ($content{'noreplies'}) {
1.91 bisitz 2347: $r->print(' ('.&mt('No replies to sender').')'
2348: .&Apache::lonhtmlcommon::row_closure()
1.95 raeburn 2349: );
1.78 raeburn 2350: } else {
2351: if ($content{'replytoaddr'}) {
2352: my ($replytoname,$replytodom) = split(/:/,$content{'replytoaddr'});
2353: if ($replytoname ne '' && $replytodom ne '') {
1.91 bisitz 2354: $r->print(&Apache::lonhtmlcommon::row_closure()
2355: .&Apache::lonhtmlcommon::row_title(&mt('Reply To'))
1.95 raeburn 2356: .$replytoname.':'.$replytodom
1.91 bisitz 2357: .&Apache::lonhtmlcommon::row_closure()
2358: );
2359: } else {
2360: $r->print(&Apache::lonhtmlcommon::row_closure());
1.78 raeburn 2361: }
2362: } else {
1.95 raeburn 2363: $r->print(' ('.$content{'sendername'}.':'.$content{'senderdomain'}.') '
1.91 bisitz 2364: .&Apache::lonhtmlcommon::row_closure()
2365: );
1.78 raeburn 2366: }
1.95 raeburn 2367: if ($tonum && $tolist) {
2368: $r->print(&Apache::lonhtmlcommon::row_title(&mt('To'))
2369: .$tolist
2370: .&Apache::lonhtmlcommon::row_closure()
2371: );
2372: }
2373: if ($cclist) {
1.91 bisitz 2374: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Cc'))
2375: .$cclist
2376: .&Apache::lonhtmlcommon::row_closure()
2377: );
1.95 raeburn 2378: }
2379: if ($content{'group'} ne '') {
2380: if (&check_group_priv($content{'group'})) {
1.155 raeburn 2381: if (ref($recipients{'group_cc_broadcast'}) eq 'ARRAY') {
2382: $groupcclist = join(', ',@{$recipients{'group_cc_broadcast'}});
2383: if ($groupcclist) {
2384: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Group Cc'))
2385: .$groupcclist
2386: .&Apache::lonhtmlcommon::row_closure()
2387: );
2388: }
1.95 raeburn 2389: }
2390: }
1.78 raeburn 2391: }
1.91 bisitz 2392: }
1.73 raeburn 2393: }
1.91 bisitz 2394:
2395: # Course
1.157 raeburn 2396: if ($content{'courseid'} ne '') {
2397: if ($content{'courseid'} =~ m{^$match_domain\_$match_courseid$}) {
2398: my %courseinfo;
2399: %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'},
2400: {'one_time' => 1});
2401: my $description = $courseinfo{'description'};
2402: if ($description ne '') {
2403: $r->print(&Apache::lonhtmlcommon::row_title(&mt($crstype))
2404: .$description
2405: );
2406: if ($content{'coursesec'}) {
2407: $r->print(' ('.&mt('Section').': '.$content{'coursesec'}.')');
2408: }
2409: $r->print(&Apache::lonhtmlcommon::row_closure());
2410: }
1.73 raeburn 2411: }
2412: }
1.91 bisitz 2413: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Time'))
2414: .$content{'time'}
2415: .&Apache::lonhtmlcommon::row_closure()
2416: );
2417:
2418: # Refers to
1.59 raeburn 2419: if ($baseurl) {
2420: if (defined($content{'courseid'}) && defined($env{'request.course.id'})) {
2421: if ($content{'courseid'} eq $env{'request.course.id'}) {
2422: my $symblink;
1.62 raeburn 2423: my $showsymb = &Apache::lonenc::check_decrypt($symb);
2424: my $showurl = &Apache::lonenc::check_decrypt($baseurl);
2425: my $encrypturl = &Apache::lonnet::EXT('resource.0.encrypturl',
2426: $showsymb,$env{'user.domain'},$env{'user.name'});
1.59 raeburn 2427: if ($symb) {
1.62 raeburn 2428: if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
2429: $showsymb = &Apache::lonenc::check_encrypt($symb);
2430: }
2431: $symblink = '?symb='.$showsymb;
2432: }
2433: if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
2434: $showurl = $baseurl;
1.59 raeburn 2435: }
1.91 bisitz 2436: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
2437: .'<a href="'.$showurl.$symblink.'">'.$restitle.'</a>'
2438: .&Apache::lonhtmlcommon::row_closure()
2439: );
1.59 raeburn 2440: $refers_to = 1;
2441: }
2442: }
2443: if (!$refers_to) {
2444: if ($baseurl =~ m-^/enc/-) {
2445: if (defined($content{'courseid'})) {
1.62 raeburn 2446: if (!$env{'request.course.id'}) {
2447: my $unencurl =
2448: &Apache::lonenc::unencrypted($baseurl,
2449: $content{'courseid'});
2450: if ($unencurl ne '') {
2451: if (&Apache::lonnet::allowed('bre',$unencurl)) {
1.91 bisitz 2452: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
2453: .'<a href="'.$unencurl.'">'.$restitle.'</a>'
2454: .&Apache::lonhtmlcommon::row_closure()
2455: );
1.62 raeburn 2456: }
1.59 raeburn 2457: }
2458: }
2459: }
2460: } else {
2461: if (&Apache::lonnet::allowed('bre',$baseurl)) {
1.91 bisitz 2462: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Refers to'))
2463: .'<a href="'.$baseurl.'">'.$restitle.'</a>'
2464: .&Apache::lonhtmlcommon::row_closure()
2465: );
2466:
1.59 raeburn 2467: }
2468: }
2469: }
2470: }
1.91 bisitz 2471:
2472: # Message
2473: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Message'))
2474: .'<pre>'
2475: .&Apache::lontexconvert::msgtexconverted($content{'message'},1)
2476: .'</pre>'
2477: );
2478: if (&displayresource(%content)) {
2479: $r->print(&Apache::lonhtmlcommon::row_closure()
2480: .&Apache::lonhtmlcommon::row_title(&mt('Resource Details'))
2481: .&displayresource(%content)
2482: );
2483: }
1.92 raeburn 2484: $r->print(&Apache::lonhtmlcommon::row_closure(1).
2485: &Apache::lonhtmlcommon::end_pick_box());
1.91 bisitz 2486: # Display LON-CAPA Message (End)
1.59 raeburn 2487: return;
1.1 albertel 2488: }
2489:
1.95 raeburn 2490: sub retrieve_recips {
2491: my ($context,$content,$recips)= @_;
2492: my $tonum = 0;
2493: if (ref($content) eq 'HASH') {
2494: my %reciphash =
2495: &Apache::lonnet::get('nohist_emailrecip',[$content->{'recipid'}],
2496: $content->{'senderdomain'},$content->{'sendername'});
2497: my $recipinfo = $reciphash{$content->{'recipid'}};
2498: if (ref($recipinfo) eq 'HASH') {
2499: foreach my $type ('to','cc','course_broadcast','group_cc_broadcast','group_bcc_broadcast') {
2500: if (ref($recipinfo->{$type}) eq 'HASH') {
2501: if ($type eq 'to') {
2502: $tonum = keys(%{$recipinfo->{$type}});
2503: }
2504: foreach my $user (sort(keys(%{$recipinfo->{$type}}))) {
2505: my ($uname,$udom) = split(/:/,$user);
2506: next if (($context eq 'replying') && ($uname eq $env{'user.name'})
2507: && ($udom eq $env{'user.domain'}));
2508: my $showuser ='<span class="LC_nobreak">';
2509: if ($context eq 'replying') {
2510: if (($type eq 'to') || ($type eq 'cc')) {
2511: $showuser = '<label><input type="checkbox" name="replying_'.$type.'" value="'.$user.'" />';
2512: } elsif ($type eq 'group_cc_broadcast') {
2513: $showuser = '<label><input type="checkbox" name="replying_groupcc" value="'.$user.'" />';
2514: }
2515: }
2516: $showuser .= &Apache::loncommon::aboutmewrapper(
2517: &Apache::loncommon::plainname($uname,
2518: $udom),$uname,$udom);
2519: if ($context eq 'replying') {
2520: $showuser .='</label>';
2521: }
2522: $showuser .= '</span>';
2523: if (ref($recips) eq 'HASH') {
2524: push(@{$recips->{$type}},$showuser);
2525: }
2526: }
1.73 raeburn 2527: }
2528: }
2529: }
2530: }
1.95 raeburn 2531: return $tonum;
2532: }
2533:
2534: sub recipients_link {
2535: my ($r,$content,$recipients) = @_;
2536: my ($broadcast_link,$show);
2537: if ((ref($content) eq 'HASH') && (ref($recipients) eq 'HASH')) {
2538: if (ref($recipients->{'course_broadcast'}) eq 'ARRAY') {
2539: if (@{$recipients->{'course_broadcast'}} > 0) {
2540: $show = 'course';
2541: }
2542: } elsif (ref($recipients->{'group_cc_broadcast'}) eq 'ARRAY') {
2543: if (@{$recipients->{'group_cc_broadcast'}} > 0) {
2544: $show = 'group_cc';
2545: }
2546: } elsif (ref($recipients->{'group_bcc_broadcast'}) eq 'ARRAY') {
2547: if (@{$recipients->{'group_bcc_broadcast'}} > 0) {
2548: $show = 'group_bcc';
2549: }
2550: }
2551: if ($show) {
2552: my ($nothing,$height,$width,$start_page,$end_page,$body);
2553: $nothing=&Apache::lonhtmlcommon::javascript_nothing();
2554: $height = 400;
2555: $width = 600;
1.108 raeburn 2556: $start_page =
2557: &Apache::loncommon::start_page('Broadcast List', undef,
2558: {only_body => 1,
2559: js_ready => 1,});
2560: $end_page = &Apache::loncommon::end_page({js_ready => 1,});
2561: $body = '<h3>'.&mt("Recipients of broadcast message").'</h3>'.
2562: &Apache::loncommon::start_data_table();
1.95 raeburn 2563: my $cell = 0;
2564: $body .= &Apache::loncommon::start_data_table_row();
2565: foreach my $item (@{$recipients->{$show.'_broadcast'}}) {
2566: $item =~ s/'/\\'/g;
2567: if (!($cell%2) && $cell > 0) {
2568: $body .= &Apache::loncommon::end_data_table_row().
2569: &Apache::loncommon::start_data_table_row();
2570: }
2571: $cell ++;
2572: $body .= '<td>'.$cell.' '.$item.' </td>';
2573: }
2574: if ($cell%2) {
2575: $body .= '<td> </td>';
2576: }
2577: $body .= &Apache::loncommon::end_data_table_row().
2578: &Apache::loncommon::end_data_table();
2579: $body =~ s{</}{<\\/}g;
2580: $body =~ s{\n}{}g;
2581: $r->print(<<ENDJS);
2582: <script type="text/javascript">
1.127 bisitz 2583: // <![CDATA[
1.95 raeburn 2584: function showBroadcastList() {
2585: var caller = this;
2586: var newWindow = null;
2587: try {
2588: newWindow = window.open($nothing,"broadcast","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" );
2589: }
2590: catch(error) {
2591: writeWin(caller);
2592: return;
2593: }
2594: if (newWindow) {
2595: caller = newWindow;
2596: }
2597: writeWin(caller);
2598: return;
2599: }
2600:
2601: function writeWin(caller) {
2602: caller.document.writeln('$start_page $body $end_page');
2603: caller.document.close();
2604: caller.focus();
2605: }
1.127 bisitz 2606: // ]]>
1.95 raeburn 2607: </script>
2608:
2609: ENDJS
2610: $broadcast_link = 1;
2611: }
2612: }
2613: return $broadcast_link;
1.73 raeburn 2614: }
2615:
1.1 albertel 2616: # =========================================================== Show the citation
2617:
2618: sub displayresource {
2619: my %content=@_;
2620: #
2621: # If the recipient is in the same course that the message was sent from and
2622: # has sufficient privileges, show "all details," else show citation
2623: #
2624: if (($env{'request.course.id'} eq $content{'courseid'})
2625: && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
1.59 raeburn 2626: my $symb;
2627: if (defined($content{'symb'})) {
2628: $symb = $content{'symb'};
2629: } else {
2630: $symb=&Apache::lonnet::symbread($content{'baseurl'});
2631: }
1.1 albertel 2632: # Could not get a symb, give up
2633: unless ($symb) { return $content{'citation'}; }
2634: # Have a symb, can render
2635: return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
2636: &Apache::loncommon::get_previous_attempt($symb,
2637: $content{'sendername'},
2638: $content{'senderdomain'},
2639: $content{'courseid'}).
2640: '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
2641: &Apache::loncommon::get_student_view($symb,
2642: $content{'sendername'},
2643: $content{'senderdomain'},
2644: $content{'courseid'}).
2645: '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
2646: &Apache::loncommon::get_student_answers($symb,
2647: $content{'sendername'},
2648: $content{'senderdomain'},
2649: $content{'courseid'});
2650: } elsif ($env{'user.adv'}) {
2651: return $content{'citation'};
2652: }
2653: return '';
2654: }
2655:
2656: # ================================================================== The Header
2657:
2658: sub header {
2659: my ($r,$title,$baseurl)=@_;
2660: my $extra = &Apache::loncommon::studentbrowser_javascript();
2661: if ($baseurl) {
1.41 albertel 2662: $extra .= "<base href=\"".&Apache::lonnet::absolute_url()."/$baseurl\" />";
1.1 albertel 2663: }
1.138 raeburn 2664: $r->print(&Apache::loncommon::start_page('Messages',
1.38 raeburn 2665: $extra));
1.1 albertel 2666: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.138 raeburn 2667: (($title?$title:'Send and display messages')));
1.1 albertel 2668: }
2669:
2670: # ---------------------------------------------------------------- Print header
2671:
2672: sub printheader {
2673: my ($r,$url,$desc,$title,$baseurl)=@_;
2674: &Apache::lonhtmlcommon::add_breadcrumb
2675: ({href=>$url,
2676: text=>$desc});
2677: &header($r,$title,$baseurl);
2678: }
2679:
2680: # ------------------------------------------------------------ Store the comment
2681:
2682: sub storecomment {
2683: my ($r)=@_;
2684: my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2685: my $cleanmsgtxt='';
1.42 raeburn 2686: foreach my $line (split(/[\n\r]/,$msgtxt)) {
2687: unless ($line=~/^\s*(\>|\>\;)/) {
2688: $cleanmsgtxt.=$line."\n";
1.1 albertel 2689: }
2690: }
1.29 www 2691: my $key=&escape($env{'form.baseurl'}).'___'.time;
1.1 albertel 2692: &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
2693: }
2694:
2695: sub storedcommentlisting {
2696: my ($r)=@_;
2697: my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
1.29 www 2698: '^'.&escape(&escape($env{'form.showcommentbaseurl'})));
1.72 albertel 2699: $r->print(&Apache::loncommon::start_page('Saved Comment Listing',undef,
1.1 albertel 2700: {'onlybody' => 1}));
1.178 raeburn 2701: if ((keys(%msgs))[0]=~/^error\:/) {
1.72 albertel 2702: $r->print(&mt('No saved comments yet.'));
1.1 albertel 2703: } else {
2704: my $found=0;
1.42 raeburn 2705: foreach my $key (sort(keys(%msgs))) {
2706: $r->print("\n".$msgs{$key}."<hr />");
1.1 albertel 2707: $found=1;
2708: }
2709: unless ($found) {
1.72 albertel 2710: $r->print(&mt('No saved comments yet for this resource.'));
1.1 albertel 2711: }
2712: }
2713: }
2714:
2715: # ---------------------------------------------------------------- Send an email
2716:
2717: sub sendoffmail {
2718: my ($r,$folder)=@_;
2719: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2720: my $sendstatus='';
1.71 raeburn 2721: my %msg_status;
2722: my $numsent = 0;
2723: my $nosentstore = 1;
1.86 raeburn 2724: my $attachmenturl;
2725: my $now = time;
1.38 raeburn 2726: my ($cdom,$cnum,$group);
2727: if (exists($env{'form.group'})) {
2728: $group = $env{'form.group'};
2729: }
2730: if (exists($env{'request.course.id'})) {
2731: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2732: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2733: }
1.1 albertel 2734: if ($env{'form.send'}) {
1.53 raeburn 2735: if (!$env{'form.multiforward'}) {
2736: if ($group eq '') {
2737: &printheader($r,'','Messages being sent.');
2738: } else {
2739: $r->print(&groupmail_header('sending',$group));
2740: }
1.38 raeburn 2741: }
1.1 albertel 2742: $r->rflush();
2743: my %content=();
2744: undef %content;
2745: if ($env{'form.forwid'}) {
2746: my $msgid=$env{'form.forwid'};
2747: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1.86 raeburn 2748: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1,1);
1.1 albertel 2749: &statuschange($msgid,'forwarded',$folder);
1.86 raeburn 2750: if ($content{'attachmenturl'} ne '') {
2751: $attachmenturl = $content{'attachmenturl'};
2752: }
2753: $env{'form.message'} .= "\n\n-- Forwarded message --\n\n".
2754: $content{'message'};
1.1 albertel 2755: }
2756: if ($env{'form.replyid'}) {
2757: my $msgid=$env{'form.replyid'};
2758: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2759: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2760: &statuschange($msgid,'replied',$folder);
2761: }
1.13 albertel 2762:
1.25 foxr 2763: my $mode = $env{'form.sendmode'};
1.95 raeburn 2764: my (%toaddr,$tos,$cc,$bcc,$broadcast);
1.25 foxr 2765:
1.95 raeburn 2766: if ($mode eq 'group') {
2767: if (defined($env{'form.courserecips'})) {
2768: my $courseusers = $env{'form.courserecips'};
2769: $courseusers =~ s/^_\&\&\&_//;
2770: my @to = split('_&&&_',$courseusers);
2771: foreach my $dest (@to) {
2772: my ($user,$domain) = split(/:/, $dest);
2773: if (($user ne '') && ($domain ne '')) {
2774: my $rec = $user.":".$domain;
2775: $toaddr{$rec} = '';
2776: $broadcast->{$rec} = '';
2777: }
2778: }
2779: }
2780: } elsif ($mode eq 'upload') {
1.71 raeburn 2781: $nosentstore = 0;
1.13 albertel 2782: foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
1.43 raeburn 2783: my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/);
1.1 albertel 2784: if ($txt) {
1.43 raeburn 2785: $rec =~ s/^\s+//;
1.44 raeburn 2786: $rec =~ s/\s+$//;
1.1 albertel 2787: $toaddr{$rec}.=$txt."\n";
1.95 raeburn 2788: $broadcast->{$rec} = '';
1.1 albertel 2789: }
2790: }
2791: } else {
1.25 foxr 2792: if (($env{'form.recuname'} ne '') && ($env{'form.recdomain'} ne '')) {
2793: $toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
1.95 raeburn 2794: $tos->{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
1.25 foxr 2795: }
1.1 albertel 2796: }
1.95 raeburn 2797: if ($env{'form.additionalrec_to'}) {
2798: foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_to'})) {
2799: my ($auname,$audom)=split(/:/,$rec);
2800: if (($auname ne "") && ($audom ne "")) {
2801: $toaddr{$auname.':'.$audom}='';
2802: $tos->{$auname.':'.$audom}='';
2803: }
2804: }
2805: }
2806: if ($env{'form.replying_to'}) {
2807: my @toreplies =
2808: &Apache::loncommon::get_env_multiple('form.replying_to');
2809: foreach my $rec (@toreplies) {
2810: my ($auname,$audom)=split(/:/,$rec);
2811: if (($auname ne "") && ($audom ne "")) {
2812: $toaddr{$auname.':'.$audom}='';
2813: $tos->{$auname.':'.$audom}='';
2814: }
2815: }
2816: }
1.73 raeburn 2817: if ($env{'form.additionalrec_cc'}) {
2818: foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_cc'})) {
1.43 raeburn 2819: my ($auname,$audom)=split(/:/,$rec);
1.25 foxr 2820: if (($auname ne "") && ($audom ne "")) {
1.73 raeburn 2821: $toaddr{$auname.':'.$audom}='';
1.95 raeburn 2822: if (!defined($tos->{$auname.':'.$audom})) {
2823: $cc->{$auname.':'.$audom}='';
2824: }
1.25 foxr 2825: }
1.1 albertel 2826: }
2827: }
1.95 raeburn 2828: if ($env{'form.replying_cc'}) {
2829: my @ccreplies =
2830: &Apache::loncommon::get_env_multiple('form.replying_cc');
2831: foreach my $rec (@ccreplies) {
2832: my ($auname,$audom)=split(/:/,$rec);
2833: if (($auname ne "") && ($audom ne "")) {
2834: $toaddr{$auname.':'.$audom}='';
2835: if (!defined($tos->{$auname.':'.$audom})) {
2836: $cc->{$auname.':'.$audom}='';
2837: }
2838: }
2839: }
2840: }
2841: if ($env{'form.replying_groupcc'}) {
2842: my @groupreplies =
2843: &Apache::loncommon::get_env_multiple('form.replying_groupcc');
2844: foreach my $rec (@groupreplies) {
1.73 raeburn 2845: my ($auname,$audom)=split(/:/,$rec);
2846: if (($auname ne "") && ($audom ne "")) {
2847: $toaddr{$auname.':'.$audom}='';
1.95 raeburn 2848: if (!defined($tos->{$auname.':'.$audom})) {
2849: $broadcast->{$auname.':'.$audom}='';
2850: }
1.73 raeburn 2851: }
2852: }
2853: }
1.95 raeburn 2854: if ($env{'form.additionalrec_bcc'}) {
2855: foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec_bcc'})) {
1.73 raeburn 2856: my ($auname,$audom)=split(/:/,$rec);
2857: if (($auname ne "") && ($audom ne "")) {
2858: $toaddr{$auname.':'.$audom}='';
1.95 raeburn 2859: if ((!defined($tos->{$auname.':'.$audom})) &&
2860: (!defined($cc->{$auname.':'.$audom}))) {
2861: $bcc->{$auname.':'.$audom}='';
2862: }
1.73 raeburn 2863: }
2864: }
2865: }
1.1 albertel 2866: my $savemsg;
2867: my $msgtype;
2868: my %sentmessage;
1.7 albertel 2869: my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'},
2870: undef,1);
1.1 albertel 2871: if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
2872: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
2873: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
2874: '/'.$env{'request.course.sec'})
2875: )) {
2876: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
2877: $msgtype = 'critical';
2878: } else {
2879: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2880: }
1.73 raeburn 2881: my %reciphash = (
1.95 raeburn 2882: to => $tos,
1.73 raeburn 2883: cc => $cc,
2884: bcc => $bcc,
1.95 raeburn 2885: );
2886: if ($mode eq 'group') {
2887: if ($group eq '') {
2888: $reciphash{'course_broadcast'} = $broadcast;
2889: } else {
2890: if ($env{'form.groupmail'} eq 'cc') {
2891: $reciphash{'group_cc_broadcast'} = $broadcast;
2892: } else {
2893: $reciphash{'group_bcc_broadcast'} = $broadcast;
2894: }
2895: }
2896: }
1.73 raeburn 2897: my ($recipid,$recipstatus) =
2898: &Apache::lonmsg::store_recipients($msgsubj,$env{'user.name'},
2899: $env{'user.domain'},\%reciphash);
2900: if ($recipstatus ne 'ok') {
1.95 raeburn 2901: &Apache::lonnet::logthis('Failed to store To, Bcc and Cc recipients for '.$env{'user.name'}.':'.$env{'user.domain'});
1.86 raeburn 2902: }
2903: if ($env{'form.attachment'}) {
2904: if (length($env{'form.attachment'})<131072) {
2905: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback/'.$now);
2906: } else {
2907: $r->print('<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>');
2908: }
2909: } elsif ($env{'form.multiforward'}) {
2910: if ($env{'form.attachmenturl'} ne '') {
2911: $attachmenturl = $env{'form.attachmenturl'};
2912: }
2913: }
1.71 raeburn 2914: my @recusers;
2915: my @recudoms;
1.13 albertel 2916: foreach my $address (sort(keys(%toaddr))) {
2917: my ($recuname,$recdomain)=split(/\:/,$address);
1.1 albertel 2918: my $msgtxt = $savemsg;
1.73 raeburn 2919: if ($toaddr{$address}) {
1.151 raeburn 2920: $msgtxt.="\n".'<hr />'."\n".$toaddr{$address};
1.73 raeburn 2921: }
1.12 albertel 2922: my @thismsg;
1.60 raeburn 2923: if ($msgtype eq 'critical') {
2924: $r->print(&mt('Sending critical message').' '.
2925: $recuname.':'.$recdomain.': ');
1.13 albertel 2926: @thismsg=
2927: &Apache::lonmsg::user_crit_msg($recuname,$recdomain,
2928: $msgsubj,$msgtxt,
2929: $env{'form.sendbck'},
2930: $env{'form.permanent'},
1.71 raeburn 2931: \$sentmessage{$address},
1.179 ! raeburn 2932: $nosentstore,$recipid,
! 2933: $attachmenturl);
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>