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