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