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