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