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