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