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