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