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