Annotation of loncom/interface/lonmsgdisplay.pm, revision 1.56.2.1
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # Routines for messaging display
3: #
1.56 albertel 4: # $Id: lonmsgdisplay.pm,v 1.55 2006/12/23 04:39:32 albertel 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:
36: Apache::lonmsg: supports internal messaging
37:
38: =head1 SYNOPSIS
39:
40: lonmsg provides routines for sending messages, receiving messages, and
41: a handler to allow users to read, send, and delete messages.
42:
43: =head1 OVERVIEW
44:
45: =head2 Messaging Overview
46:
47: X<messages>LON-CAPA provides an internal messaging system similar to
48: email, but customized for LON-CAPA's usage. LON-CAPA implements its
49: own messaging system, rather then building on top of email, because of
50: the features LON-CAPA messages can offer that conventional e-mail can
51: not:
52:
53: =over 4
54:
55: =item * B<Critical messages>: A message the recipient B<must>
56: acknowlegde receipt of before they are allowed to continue using the
57: system, preventing a user from claiming they never got a message
58:
59: =item * B<Receipts>: LON-CAPA can reliably send reciepts informing the
60: sender that it has been read; again, useful for preventing students
61: from claiming they did not see a message. (While conventional e-mail
62: has some reciept support, it's sporadic, e-mail client-specific, and
63: generally the receiver can opt to not send one, making it useless in
64: this case.)
65:
66: =item * B<Context>: LON-CAPA knows about the sender, such as where
67: they are in a course. When a student mails an instructor asking for
68: help on the problem, the instructor receives not just the student's
69: question, but all submissions the student has made up to that point,
70: the user's rendering of the problem, and the complete view the student
71: saw of the resource, including discussion up to that point. Finally,
72: the instructor is reading all of this inside of LON-CAPA, not their
73: email program, so they have full access to LON-CAPA's grading
74: interface, or other features they may wish to use in response to the
75: student's query.
76:
1.50 raeburn 77: =item * B<Blocking>: LON-CAPA can block selected communication
78: features for students during an online exam. A course coordinator or
1.1 albertel 79: instructor can set an open and close date/time for scheduled online
80: exams in a course. If a user uses the LON-CAPA internal messaging
81: system to display e-mails during the scheduled blocking event,
82: display of all e-mail sent during the blocking period will be
83: suppressed, and a message of explanation, including details of the
84: currently active blocking periods will be displayed instead. A user
85: who has a course coordinator or instructor role in a course will be
86: unaffected by any blocking periods for the course, unless the user
87: also has a student role in the course, AND has selected the student role.
88:
89: =back
90:
91: Users can ask LON-CAPA to forward messages to conventional e-mail
92: addresses on their B<PREF> screen, but generally, LON-CAPA messages
93: are much more useful than traditional email can be made to be, even
94: with HTML support.
95:
96: Right now, this document will cover just how to send a message, since
97: it is likely you will not need to programmatically read messages,
98: since lonmsg already implements that functionality.
99:
100: The routines used to package messages and unpackage messages are not
101: only used by lonmsg when creating/extracting messages for LON-CAPA's
102: internal messaging system, but also by lonnotify.pm which is available
103: for use by Domain Coordinators to broadcast standard e-mail to specified
104: users in their domain. The XML packaging used in the two cases is very
105: similar. The differences are the use of <recuser>$uname</recuser> and
106: <recdomain>$udom</recdomain> in stored internal messages, compared
107: with <recipient username="$uname:$udom">$email</recipient> in stored
108: Domain Coordinator e-mail for the storage of information about
109: recipients of the message/e-mail.
110:
111: =head1 FUNCTIONS
112:
113: =over 4
114:
115: =cut
116:
117: use strict;
118: use Apache::lonnet;
119: use HTML::TokeParser();
120: use Apache::Constants qw(:common);
121: use Apache::loncommon();
122: use Apache::lontexconvert();
123: use HTML::Entities();
124: use Apache::lonlocal;
125: use Apache::loncommunicate;
126: use Apache::lonfeedback;
127: use Apache::lonrss();
1.27 albertel 128: use Apache::lonselstudent();
1.29 www 129: use lib '/home/httpd/lib/perl/';
130: use LONCAPA;
1.1 albertel 131:
132: # Querystring component with sorting type
133: my $sqs;
134: my $startdis;
135: my $interdis;
136:
137: # ============================================================ List all folders
138:
139: sub folderlist {
1.53 raeburn 140: my ($folder,$msgstatus) = @_;
1.46 raeburn 141: my %lt = &Apache::lonlocal::texthash(
142: actn => 'Action',
143: fold => 'Folder',
144: show => 'Show',
1.53 raeburn 145: status => 'Message Status',
1.46 raeburn 146: go => 'Go',
1.50 raeburn 147: nnff => 'New Name for Folder',
148: newn => 'New Name',
149: thfm => 'The folder may not be renamed',
150: fmnb => 'folder may not be renamed as it is a folder provided by the system.',
151: asth => 'as this name is already in use for a system-provided or user-defined folder.',
152: the => 'The',
153: tnfm => 'The new folder may not be named',
154:
1.46 raeburn 155: );
156:
157: my %actions = &Apache::lonlocal::texthash(
158: view => 'View Folder',
159: rename => 'Rename Folder',
160: delete => 'Delete Folder',
161: );
162: $actions{'select_form_order'} = ['view','rename','delete'];
163:
1.53 raeburn 164: my %statushash = &get_msgstatus_types();
165:
166: $statushash{'select_form_order'} = ['','new','read','replied','forwarded'];
167:
1.46 raeburn 168: my %permfolders = &get_permanent_folders();
169: my $permlist = join("','",sort(keys(%permfolders)));
170: my ($permlistkeys,$permlistvals);
171: foreach my $key (sort(keys(%permfolders))) {
172: $permlistvals .= $permfolders{$key}."','";
173: $permlistkeys .= $key."','";
174: }
175: $permlistvals =~ s/','$//;
176: $permlistkeys =~ s/','$//;
177: my %gotfolders = &Apache::lonmsg::get_user_folders();
178: my %userfolders;
179:
180: foreach my $key (keys(%gotfolders)) {
1.54 albertel 181: $key =~ s/(['"])/\$1/g; #' stupid emacs
1.46 raeburn 182: $userfolders{$key} = $key;
183: }
184: my @userorder = sort(keys(%userfolders));
185: my %formhash = (%permfolders,%userfolders);
186: my $folderlist = join("','",@userorder);
187: $folderlist .= "','".$permlistvals;
188:
1.53 raeburn 189: $formhash{'select_form_order'} = ['','critical',@userorder,'sent','trash'];
1.46 raeburn 190: my $output = qq|<script type="text/javascript">
191: function folder_choice(targetform,caller) {
192: var permfolders_keys = new Array('$permlistkeys');
193: var permfolders_vals = new Array('$permlistvals');
194: var allfolders = new Array('$folderlist');
195: if (caller == 'change') {
196: if (targetform.folderaction.options[targetform.folderaction.selectedIndex].value == 'rename') {
197: for (var i=0; i<permfolders_keys.length; i++) {
198: if (permfolders_keys[i] == targetform.folder.value) {
1.50 raeburn 199: alert("$lt{'the'} '"+permfolders_vals[i]+"' $lt{'fmnb'}");
1.46 raeburn 200: return;
201: }
202: }
1.50 raeburn 203: var foldername=prompt('$lt{'nnff'}','$lt{'newn'}');
1.46 raeburn 204: if (foldername) {
205: targetform.renamed.value=foldername;
206: for (var i=0; i<allfolders.length; i++) {
207: if (allfolders[i] == foldername) {
1.50 raeburn 208: alert("$lt{'thfm'} '"+foldername+"' $lt{'asth'}");
1.46 raeburn 209: return;
210: }
211: }
212: targetform.submit();
213: }
214: }
215: else {
216: targetform.submit();
217: }
218: }
219: if (caller == 'new') {
220: var newname=targetform.newfolder.value;
221: if (newname) {
222: for (var i=0; i<allfolders.length; i++) {
223: if (allfolders[i] == newname) {
1.50 raeburn 224: alert("$lt{'tnfm'} '"+newname+"' $lt{'asth'}");
1.46 raeburn 225: return;
226: }
227: }
228: targetform.submit();
229: }
230: }
231: }
232: </script>|;
233: $output .= '
234: <form method="post" action="/adm/email" name="folderlist">
235: <table border="0" cellspacing="2" cellpadding="2">
236: <tr>
237: <td align="left">
238: <table border="0" cellspacing="2" cellpadding="2">
239: <tr>
240: <td align="center"><b>'.$lt{'fold'}.'</b><br />'."\n".
1.47 albertel 241: &Apache::loncommon::select_form($folder,'folder',%formhash).'
1.46 raeburn 242: </td>
243: <td align="center"><b>'.$lt{'show'}.'</b><br />
244: <select name="interdis">'.
1.47 albertel 245: join("\n",map { '<option value="'.$_.'"'.
246: ($_==$interdis?' selected="selected"':'').'>'.$_.'</option>'
247: }
248: (10,20,50,100,200)).'</select>
1.46 raeburn 249: </td>
1.53 raeburn 250: <td align="center"><b>'.$lt{'status'}.'</b><br />'."\n".
251: &Apache::loncommon::select_form($msgstatus,'msgstatus',%statushash).'
252: </td>
1.46 raeburn 253: <td align="center"><b>'.$lt{'actn'}.'</b><br />'.
1.47 albertel 254: &Apache::loncommon::select_form('view','folderaction',%actions).'
1.46 raeburn 255: </td><td><br />'.
256: '<input type="button" value="'.$lt{'go'}.'" onClick="javascript:folder_choice(this.form,'."'change'".');" />
257: </td>
258: </tr>
259: </table>
260: </td><td> </td><td> </td><td> </td><td> </td>
261: <td align="right">
262: <table><tr><td><br />
263: <input type="button" value="'.&mt('Make New Folder').
264: '" onClick="javascript:folder_choice(this.form,'."'new'".');" /></td>'.
1.48 albertel 265: '<td align="center"><b>'.&mt('New Folder').'</b><br />'.
1.46 raeburn 266: '<input type="text" size="15" name="newfolder" value="" />
267: </td></tr></table>
268: </td>
269: </tr>
270: </table>'."\n".
1.1 albertel 271: '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" />'.
1.46 raeburn 272: '<input type="hidden" name="renamed" value="" />'.
1.53 raeburn 273: ($folder=~/^critical/?'</form>':'');
1.46 raeburn 274: return $output;
275: }
276:
277: sub get_permanent_folders {
1.47 albertel 278: my %permfolders =
279: &Apache::lonlocal::texthash('' => 'INBOX',
280: 'trash' => 'TRASH',
281: 'critical' => 'Critical',
282: 'sent' => 'Sent Messages',
283: );
1.46 raeburn 284: return %permfolders;
1.1 albertel 285: }
286:
1.53 raeburn 287: sub get_msgstatus_types {
288: my %statushash = &Apache::lonlocal::texthash(
289: '' => 'Any',
290: new => 'Unread',
291: read => 'Read',
292: replied => 'Replied to',
293: forwarded => 'Forwarded',
294: );
295: return %statushash;
296: }
297:
1.1 albertel 298: sub scrollbuttons {
1.53 raeburn 299: my ($start,$maxdis,$first,$finish,$total,$msgstatus)=@_;
1.1 albertel 300: unless ($total>0) { return ''; }
301: $start++; $maxdis++;$first++;$finish++;
1.53 raeburn 302:
303: my %statushash = &get_msgstatus_types();
1.56.2.1! albertel 304:
1.1 albertel 305: return
1.56.2.1! albertel 306: '<b>'.&mt('Page').'</b>: '.
! 307: '<input type="submit" name="firstview" value="'.&mt('First').'" />'.
! 308: '<input type="submit" name="prevview" value="'.&mt('Previous').'" />'.
! 309: '<input type="text" size="5" name="startdis" value="'.$start.'" onChange="this.form.submit()" /> of '.$maxdis.
! 310: '<input type="submit" name="nextview" value="'.&mt('Next').'" />'.
! 311: '<input type="submit" name="lastview" value="'.&mt('Last').'" /><br />'.
! 312: &mt('_location_in_mail_folder',$msgstatus,$statushash{$msgstatus},
! 313: $first,$finish,$total).'</form>';
1.1 albertel 314: }
315: # =============================================================== Status Change
316:
317: sub statuschange {
318: my ($msgid,$newstatus,$folder)=@_;
1.3 albertel 319: my $suffix=&Apache::lonmsg::foldersuffix($folder);
1.1 albertel 320: my %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
321: if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
322: unless ($status{$msgid}) { $status{$msgid}='new'; }
323: unless (($status{$msgid} eq 'replied') ||
324: ($status{$msgid} eq 'forwarded')) {
325: &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
326: }
327: if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
328: &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
329: }
330: if ($newstatus eq 'deleted') {
1.9 albertel 331: return &movemsg($msgid,$folder,'trash');
332: }
333: return ;
1.1 albertel 334: }
335:
336: # ============================================================= Make new folder
337:
338: sub makefolder {
1.46 raeburn 339: my ($newfolder) = @_;
340: my %permfolders = &get_permanent_folders();
341: my %userfolders = &Apache::lonmsg::get_user_folders();
342: my ($outcome,$warning);
343: if (defined($userfolders{$newfolder})) {
344: return &mt('The folder name: "[_1]" is already in use for an existing folder.',$newfolder);
345: }
346: foreach my $perm (keys(%permfolders)) {
347: if ($permfolders{$perm} eq $newfolder) {
348: return &mt('The folder name: "[_1]" is already used for one of the folders automatically generated by the system.',$newfolder);
349: }
350: }
351: if (&get_msgfolder_lock() eq 'ok') {
352: my %counter_hash = &Apache::lonnet::get('email_folders',["\0".'idcount']);
353: my $lastcount = $counter_hash{"\0".'idcount'};
354: my $folder_id = $lastcount + 1;
355: while (defined($userfolders{$folder_id})) {
356: $folder_id ++;
357: }
1.47 albertel 358: my %folderinfo = ( id => $folder_id,
359: created => time, );
1.46 raeburn 360: $outcome =
1.47 albertel 361: &Apache::lonnet::put('email_folders',{$newfolder => \%folderinfo,
362: "\0".'idcount' => $folder_id});
1.46 raeburn 363: my $releaseresult = &release_msgfolder_lock();
364: if ($releaseresult ne 'ok') {
365: $warning = $releaseresult;
366: }
367: } else {
1.47 albertel 368: $outcome =
369: &mt('Error - could not obtain lock on email folders record.');
1.46 raeburn 370: }
371: return ($outcome,$warning);
1.1 albertel 372: }
373:
1.46 raeburn 374: # ============================================================= Delete folder
375:
376: sub deletefolder {
377: my ($folder)=@_;
378: my %permfolders = &get_permanent_folders();
379: if (defined($permfolders{$folder})) {
1.56 albertel 380: return &mt('The folder "[_1]" may not be deleted',$folder);
1.46 raeburn 381: }
382: my %userfolders = &Apache::lonmsg::get_user_folders();
383: if (!defined($userfolders{$folder})) {
1.56 albertel 384: return &mt('The folder "[_1]" does not exist so deletion is not required.',
1.46 raeburn 385: $folder);
386: }
387: # check folder is empty;
388: my $suffix=&Apache::lonmsg::foldersuffix($folder);
389: my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
390: if (@messages > 0) {
1.56 albertel 391: return &mt('The folder "[_1]" contains messages so it may not be deleted.',$folder).
1.56.2.1! albertel 392: '<br />'.
! 393: &mt('Delete or move the messages to a different folder first.');
1.46 raeburn 394: }
395: my $delresult = &Apache::lonnet::del('email_folders',[$folder]);
396: return $delresult;
397: }
398:
399: sub renamefolder {
400: my ($folder) = @_;
401: my $newname = $env{'form.renamed'};
402: my %permfolders = &get_permanent_folders();
403: if ($env{'form.renamed'} eq '') {
404: return &mt('The folder "[_1]" may not be renamed to "[_2]" as the new name you requested is an invalid name.',$folder,$newname);
405: }
406: if (defined($permfolders{$newname})) {
407: 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);
408: }
409: my %userfolders = &Apache::lonmsg::get_user_folders();
410: if (defined($userfolders{$newname})) {
411: 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);
412: }
413: if (!defined($userfolders{$folder})) {
414: return &mt('The folder "[_1]" could not be renamed to "[_2]" because the folder does not exist.',$folder,$newname);
415: }
416: my %folderinfo;
417: if (ref($userfolders{$folder}) eq 'HASH') {
418: %folderinfo = %{$userfolders{$folder}};
419: } else {
1.47 albertel 420: %folderinfo = ( id => $folder,
421: created => $userfolders{$folder},);
1.46 raeburn 422: }
423: my $outcome =
424: &Apache::lonnet::put('email_folders',{$newname => \%folderinfo});
425: if ($outcome eq 'ok') {
426: $outcome = &Apache::lonnet::del('email_folders',[$folder]);
427: }
428: return $outcome;
429: }
430:
431: sub get_msgfolder_lock {
432: # get lock for mail folder counter.
1.47 albertel 433: my $lockhash = { "\0".'lock_counter' => time, };
1.46 raeburn 434: my $tries = 0;
435: my $gotlock = &Apache::lonnet::newput('email_folders',$lockhash);
436: while (($gotlock ne 'ok') && $tries <3) {
437: $tries ++;
1.47 albertel 438: sleep(1);
1.46 raeburn 439: $gotlock = &Apache::lonnet::newput('email_folders',$lockhash);
440: }
441: return $gotlock;
442: }
443:
444: sub release_msgfolder_lock {
445: # remove lock
446: my @del_lock = ("\0".'lock_counter');
447: my $dellockoutcome=&Apache::lonnet::del('email_folders',\@del_lock);
448: if ($dellockoutcome ne 'ok') {
449: return ('<br />'.&mt('Warning: failed to release lock for counter').'<br />');
450: } else {
451: return 'ok';
452: }
453: }
454:
455:
1.1 albertel 456: # ======================================================== Move between folders
457:
458: sub movemsg {
459: my ($msgid,$srcfolder,$trgfolder)=@_;
460: if ($srcfolder eq 'new') { $srcfolder=''; }
1.3 albertel 461: my $srcsuffix=&Apache::lonmsg::foldersuffix($srcfolder);
462: my $trgsuffix=&Apache::lonmsg::foldersuffix($trgfolder);
1.9 albertel 463: if ($srcsuffix eq $trgsuffix) {
464: return (0,&mt('Message not moved, Attempted to move message to the same folder as it already is in.'));
465: }
1.1 albertel 466:
467: # Copy message
468: my %message=&Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid]);
1.9 albertel 469: if (!exists($message{$msgid}) || $message{$msgid} eq '') {
1.32 albertel 470: if (&Apache::lonnet::error(%message)) {
1.9 albertel 471: return (0,&mt('Message not moved, A network error occurred.'));
472: } else {
473: return (0,&mt('Message not moved as the message is no longer in the source folder.'));
474: }
475: }
476:
477: my $result =&Apache::lonnet::put('nohist_email'.$trgsuffix,
478: {$msgid => $message{$msgid}});
1.32 albertel 479: if (&Apache::lonnet::error($result)) {
1.9 albertel 480: return (0,&mt('Message not moved, A network error occurred.'));
481: }
1.1 albertel 482:
483: # Copy status
484: unless ($trgfolder eq 'trash') {
1.9 albertel 485: my %status=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]);
486: # a non-existant status is the mark of an unread msg
1.32 albertel 487: if (&Apache::lonnet::error(%status)) {
1.9 albertel 488: return (0,&mt('Message copied to new folder but status was not, A network error occurred.'));
489: }
490: my $result=&Apache::lonnet::put('email_status'.$trgsuffix,
491: {$msgid => $status{$msgid}});
1.32 albertel 492: if (&Apache::lonnet::error($result)) {
1.9 albertel 493: return (0,&mt('Message copied to new folder but status was not, A network error occurred.'));
494: }
1.1 albertel 495: }
1.9 albertel 496:
1.1 albertel 497: # Delete orginals
1.9 albertel 498: my $result_del_msg =
499: &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]);
500: my $result_del_stat =
501: &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]);
1.32 albertel 502: if (&Apache::lonnet::error($result_del_msg)) {
1.9 albertel 503: return (0,&mt('Message copied, but unable to delete the original from the source folder.'));
504: }
1.32 albertel 505: if (&Apache::lonnet::error($result_del_stat)) {
1.9 albertel 506: return (0,&mt('Message copied, but unable to delete the original status from the source folder.'));
507: }
508:
509: return (1);
1.1 albertel 510: }
511:
512: # ======================================================= Display a course list
513:
514: sub discourse {
1.25 foxr 515: my $result;
516: my ($course_personnel,
517: $current_members,
518: $expired_members,
1.28 foxr 519: $future_members) =
520: &Apache::lonselstudent::get_people_in_class($env{'request.course.sec'});
1.25 foxr 521: unshift @$current_members, (@$course_personnel);
522: my %defaultUsers;
1.40 albertel 523:
524: $result .= '<input type="hidden" name="sendmode" value="group" />'."\n";
1.25 foxr 525:
1.40 albertel 526: $result .= &Apache::lonselstudent::render_student_list($current_members,
527: "compemail",
528: "current",
529: \%defaultUsers,
530: 1,"selectedusers",1);
1.25 foxr 531:
1.28 foxr 532: $result .= &Apache::lonselstudent::render_student_list($expired_members,
533: "compemail",
534: "expired",
535: \%defaultUsers,
536: 1, "selectedusers",0);
537: $result .= &Apache::lonselstudent::render_student_list($future_members,
538: "compemail",
539: "future",
540: \%defaultUsers,
541: 1, "selectedusers", 0);
1.25 foxr 542: return $result;
543: }
544:
1.38 raeburn 545: sub disgroup {
546: my ($cdom,$cnum,$group,$viewgrps,$editgrps) = @_;
547: my $result;
548: # Needs to be in a course
549: if (!($env{'request.course.fn'})) {
550: $result = &mt('Error: you must have a course role selected to be able to send a broadcast message to a group in the course.');
551: return $result;
552: }
553: if ($cdom eq '' || $cnum eq '') {
554: $result = &mt('Error: could not determine domain or number of course');
555: return $result;
556: }
557: my ($memberinfo,$numitems) =
558: &Apache::longroup::group_memberlist($cdom,$cnum,$group,{},[]);
559: my @statustypes = ('active');
560: if ($viewgrps || $editgrps) {
561: push(@statustypes,('future','previous'));
562: }
563: if (keys(%{$memberinfo}) == 0) {
564: $result = &mt('As this group has no members, there are no '.
565: 'recipients to select.');
566: return $result;
567: } else {
568: $result = &mt('Select message recipients from the group members listed below.<br />');
569: my %Sortby = (
570: active => {},
571: previous => {},
572: future => {},
573: );
574: my %lt = &Apache::lonlocal::texthash(
575: 'name' => 'Name',
576: 'usnm' => 'Username',
577: 'doma' => 'Domain',
578: 'active' => 'Active Members',
579: 'previous' => 'Former Members',
580: 'future' => 'Future Members',
581: );
582: foreach my $user (sort(keys(%{$memberinfo}))) {
583: my $status = $$memberinfo{$user}{status};
584: if ($env{'form.'.$status.'.sortby'} eq 'fullname') {
585: push(@{$Sortby{$status}{$$memberinfo{$user}{fullname}}},$user);
586: } elsif ($env{'form.'.$status.'.sortby'} eq 'username') {
587: push(@{$Sortby{$status}{$$memberinfo{$user}{uname}}},$user);
588: } elsif ($env{'form.'.$status.'.sortby'} eq 'domain') {
589: push(@{$Sortby{$status}{$$memberinfo{$user}{udom}}},$user);
590: } else {
591: push(@{$Sortby{$status}{$$memberinfo{$user}{fullname}}},$user);
592: }
593: }
594: $result .= &group_check_uncheck();
595: $result .= '<table border="0" cellspacing="8" cellpadding="2">'.
596: '<tr>';
597: foreach my $status (@statustypes) {
598: if (ref($numitems) eq 'HASH') {
599: if ((defined($$numitems{$status})) && ($$numitems{$status})) {
1.39 raeburn 600: $result.='<td valign="top">'.
1.38 raeburn 601: '<fieldset><legend><b>'.$lt{$status}.
602: '</b></legend><nobr>'.
1.50 raeburn 603: '<input type="button" value="'.&mt('Check All').'" '.
1.38 raeburn 604: 'onclick="javascript:toggleAll('."'".$status."','check'".')" />'.
605: ' '.
1.50 raeburn 606: '<input type="button" value="'.&mt('Uncheck All').'" '.
1.38 raeburn 607: 'onclick="javascript:toggleAll('."'".$status."','uncheck'".')" />'.
608: '</nobr></fieldset><br />'.
609: &Apache::loncommon::start_data_table().
610: &Apache::loncommon::start_data_table_header_row();
1.39 raeburn 611: $result .= "<th>$lt{'name'}</a></th>".
612: "<th>$lt{'usnm'}</a></th>".
613: "<th>$lt{'doma'}</a></th>".
1.38 raeburn 614: &Apache::loncommon::end_data_table_header_row();
615: foreach my $key (sort(keys(%{$Sortby{$status}}))) {
616: foreach my $user (@{$Sortby{$status}{$key}}) {
617: $result .=
618: &Apache::loncommon::start_data_table_row().
619: '<td><input type="checkbox" '.
620: 'name="selectedusers_forminput" value="'.
621: $user.':'.$status.'" />'.
622: $$memberinfo{$user}{'fullname'}.'</td>'.
623: '<td>'.$$memberinfo{$user}{'uname'}.'</td>'.
624: '<td>'.$$memberinfo{$user}{'udom'}.'</td>'.
625: &Apache::loncommon::end_data_table_row();
626: }
627: }
628: $result .= &Apache::loncommon::end_data_table();
629: }
630: }
631: $result .= '</td><td> </td>';
632: }
633: $result .= '</tr></table>';
634: }
635: return $result;
636: }
637:
638: sub group_check_uncheck {
639: my $output = qq|
640: <script type="text/javascript">
641: function toggleAll(caller,action) {
642: var pattern = new RegExp(":"+caller+"\$");
643: if (typeof(document.compemail.selectedusers_forminput.length)=="undefined") {
644: if (document.compemail.selectedusers_forminput.value.match(pattern)) {
645: if (action == 'check') {
646: document.groupmail.selectedusers_forminput.checked = true;
647: } else {
648: document.groupmail.selectedusers_forminput.checked = false;
649: }
650: }
651: } else {
652: for (var i=0; i<document.compemail.selectedusers_forminput.length; i++) {
653: if (document.compemail.selectedusers_forminput[i].value.match(pattern)) {
654: if (action == 'check') {
655: document.compemail.selectedusers_forminput[i].checked = true;
656: } else {
657: document.compemail.selectedusers_forminput[i].checked = false;
658: }
659: }
660: }
661: }
662: }
663: </script>
664: |;
665: }
666:
667: sub groupmail_header {
668: my ($action,$group,$cdom,$cnum) = @_;
669: my ($description,$refarg);
670: if (!$cdom || !$cnum) {
671: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
672: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
673: }
674: if (exists($env{'form.ref'})) {
675: $refarg = 'ref='.$env{'form.ref'};
676: }
677: if (!$group) {
678: $group = $env{'form.group'};
679: }
680: if ($group eq '') {
681: return '';
682: } else {
683: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
684: if (defined($curr_groups{$group})) {
685: my %groupinfo =
686: &Apache::longroup::get_group_settings($curr_groups{$group});
687: $description = &unescape($groupinfo{'description'});
688: }
689: }
690: &Apache::lonhtmlcommon::clear_breadcrumbs();
691: if ($refarg) {
692: &Apache::lonhtmlcommon::add_breadcrumb
693: ({href=>"/adm/coursegroups",
694: text=>"Groups",
695: title=>"View course groups"});
696: }
697: &Apache::lonhtmlcommon::add_breadcrumb
698: ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
699: text=>"Group: $description",
700: title=>"Go to group's home page"},
701: {href=>"/adm/email?compose=group&group=".
702: "$env{'form.group'}&$refarg",
703: text=>"Send a Message in a Group",
704: title=>"Compose Group Email Message"},);
705: if ($action eq 'sending') {
706: &Apache::lonhtmlcommon::add_breadcrumb
707: ({text=>"Messages being sent.",
708: title=>"Messages sent"},);
709: }
710: my $groupheader = &Apache::loncommon::start_page('Group Email');
711: $groupheader .= &Apache::lonhtmlcommon::breadcrumbs
712: ('Group - '.$env{'form.group'}.' Email');
713: return $groupheader;
714: }
715:
716: sub groupmail_sent {
717: my ($group,$cdom,$cnum) = @_;
718: my $refarg;
719: if (exists($env{'form.ref'})) {
720: $refarg = 'ref='.$env{'form.ref'};
721: }
722: my $output .= '<br /><br /><a href="/adm/email?compose=group&group='.
723: $group.'&'.$refarg.'">'.
724: &mt('Send another group email').'</a>'.' '.
725: '<a href="/adm/'.$cdom.'/'.$cnum.'/'.$group.'/smppg?'.
726: $refarg.'">'. &mt('Return to group page').'</a>';
727: return $output;
728: }
729:
1.1 albertel 730: # ==================================================== Display Critical Message
731:
732: sub discrit {
733: my $r=shift;
1.5 albertel 734: my $header = '<h1><font color="red">'.&mt('Critical Messages').'</font></h1>'.
1.1 albertel 735: '<form action="/adm/email" method="POST">'.
736: '<input type="hidden" name="confirm" value="true" />';
737: my %what=&Apache::lonnet::dump('critical');
738: my $result = '';
1.42 raeburn 739: foreach my $key (sort(keys(%what))) {
740: my %content=&Apache::lonmsg::unpackagemsg($what{$key});
1.1 albertel 741: next if ($content{'senderdomain'} eq '');
742: $result.='<hr />'.&mt('From').': <b>'.
743: &Apache::loncommon::aboutmewrapper(
744: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14 albertel 745: $content{'sendername'}.':'.
1.1 albertel 746: $content{'senderdomain'}.') '.$content{'time'}.
747: '<br />'.&mt('Subject').': '.$content{'subject'}.
748: '<br /><pre>'.
749: &Apache::lontexconvert::msgtexconverted($content{'message'}).
750: '</pre><small>'.
751: &mt('You have to confirm that you received this message. After confirmation, this message will be moved to your regular inbox').
752: '</small><br />'.
1.42 raeburn 753: '<input type="submit" name="rec_'.$key.'" value="'.&mt('Confirm Receipt').'" />'.
754: '<input type="submit" name="reprec_'.$key.'" '.
1.1 albertel 755: 'value="'.&mt('Confirm Receipt and Reply').'" />';
756: }
757: # Check to see if there were any messages.
758: if ($result eq '') {
759: $result = "<h2>".&mt('You have no critical messages.')."</h2>".
1.38 raeburn 760: '<a href="/adm/roles">'.&mt('Select a course').'</a><br />'.
1.1 albertel 761: '<a href="/adm/email">'.&mt('Communicate').'</a>';
762: } else {
763: $r->print($header);
764: }
765: $r->print($result);
766: $r->print('<input type="hidden" name="displayedcrit" value="true" /></form>');
767: }
768:
769: sub sortedmessages {
1.53 raeburn 770: my ($blocked,$startblock,$endblock,$numblocked,$folder,$msgstatus) = @_;
1.1 albertel 771: my $suffix=&Apache::lonmsg::foldersuffix($folder);
772: my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix);
1.46 raeburn 773:
1.1 albertel 774: #unpack the varibles and repack into temp for sorting
775: my @temp;
776: my %descriptions;
777: my %status_cache =
778: &Apache::lonnet::get('email_status'.&Apache::lonmsg::foldersuffix($folder),\@messages);
1.11 albertel 779:
780: my $get_received;
781: if ($folder eq 'sent'
782: && ($env{'form.sortedby'} =~ m/^(rev)?(user|domain)$/)) {
783: $get_received = 1;
784: }
785:
786: foreach my $msgid (@messages) {
1.29 www 787: my $esc_msgid=&escape($msgid);
1.1 albertel 788: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)=
1.11 albertel 789: &Apache::lonmsg::unpackmsgid($esc_msgid,$folder,undef,
1.1 albertel 790: \%status_cache);
1.53 raeburn 791: next if ($msgstatus ne '' && $msgstatus ne $status);
1.1 albertel 792: my $description = &get_course_desc($fromcid,\%descriptions);
793: my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
1.11 albertel 794: $esc_msgid,$description);
795: if ($get_received) {
796: my %message = &Apache::lonnet::get('nohist_email'.$suffix,
797: [$msgid]);
798: my %content = &Apache::lonmsg::unpackagemsg($message{$msgid});
799: push(@temp1,$content{'recuser'},$content{'recdomain'});
800: }
1.1 albertel 801: # Check whether message was sent during blocking period.
802: if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
1.11 albertel 803: $$blocked{$msgid} = 'ON';
1.1 albertel 804: $$numblocked ++;
805: } else {
806: push @temp ,\@temp1;
807: }
808: }
809: #default sort
810: @temp = sort {$a->[0] <=> $b->[0]} @temp;
811: if ($env{'form.sortedby'} eq "date"){
812: @temp = sort {$a->[0] <=> $b->[0]} @temp;
813: }
814: if ($env{'form.sortedby'} eq "revdate"){
815: @temp = sort {$b->[0] <=> $a->[0]} @temp;
816: }
817: if ($env{'form.sortedby'} eq "user"){
1.11 albertel 818: if ($get_received) {
819: @temp = sort {lc($a->[7][0]) cmp lc($b->[7][0])} @temp;
820: } else {
821: @temp = sort {lc($a->[2]) cmp lc($b->[2])} @temp;
822: }
1.1 albertel 823: }
824: if ($env{'form.sortedby'} eq "revuser"){
1.11 albertel 825: if ($get_received) {
826: @temp = sort {lc($b->[7][0]) cmp lc($a->[7][0])} @temp;
827: } else {
828: @temp = sort {lc($b->[2]) cmp lc($a->[2])} @temp;
829: }
1.1 albertel 830: }
831: if ($env{'form.sortedby'} eq "domain"){
1.11 albertel 832: if ($get_received) {
833: @temp = sort {$a->[8][0] cmp $b->[8][0]} @temp;
834: } else {
835: @temp = sort {$a->[3] cmp $b->[3]} @temp;
836: }
1.1 albertel 837: }
838: if ($env{'form.sortedby'} eq "revdomain"){
1.11 albertel 839: if ($get_received) {
840: @temp = sort {$b->[8][0] cmp $a->[8][0]} @temp;
841: } else {
842: @temp = sort {$b->[3] cmp $a->[3]} @temp;
843: }
1.1 albertel 844: }
845: if ($env{'form.sortedby'} eq "subject"){
846: @temp = sort {lc($a->[1]) cmp lc($b->[1])} @temp;
847: }
848: if ($env{'form.sortedby'} eq "revsubject"){
849: @temp = sort {lc($b->[1]) cmp lc($a->[1])} @temp;
850: }
851: if ($env{'form.sortedby'} eq "course"){
852: @temp = sort {lc($a->[6]) cmp lc($b->[6])} @temp;
853: }
854: if ($env{'form.sortedby'} eq "revcourse"){
855: @temp = sort {lc($b->[6]) cmp lc($a->[6])} @temp;
856: }
857: if ($env{'form.sortedby'} eq "status"){
858: @temp = sort {$a->[4] cmp $b->[4]} @temp;
859: }
860: if ($env{'form.sortedby'} eq "revstatus"){
861: @temp = sort {$b->[4] cmp $a->[4]} @temp;
862: }
863: return @temp;
864: }
865:
866: sub get_course_desc {
867: my ($fromcid,$descriptions) = @_;
868: my $description;
869: if (!$fromcid) {
870: return $description;
871: } else {
872: if (defined($$descriptions{$fromcid})) {
873: $description = $$descriptions{$fromcid};
874: } else {
875: if (defined($env{'course.'.$fromcid.'.description'})) {
876: $description = $env{'course.'.$fromcid.'.description'};
877: } else {
1.48 albertel 878: my %courseinfo=&Apache::lonnet::coursedescription($fromcid);
1.1 albertel 879: $description = $courseinfo{'description'};
880: }
881: $$descriptions{$fromcid} = $description;
882: }
883: return $description;
884: }
885: }
886:
887: # ======================================================== Display all messages
888:
889: sub disall {
1.53 raeburn 890: my ($r,$folder,$msgstatus)=@_;
891: $r->print(&folderlist($folder,$msgstatus));
892: if ($folder eq 'critical') {
1.1 albertel 893: &discrit($r);
894: } else {
1.53 raeburn 895: &disfolder($r,$folder,$msgstatus);
1.1 albertel 896: }
897: }
898:
899: # ============================================================ Display a folder
900:
901: sub disfolder {
1.53 raeburn 902: my ($r,$folder,$msgstatus)=@_;
903: my %statushash = &get_msgstatus_types();
1.1 albertel 904: my %blocked = ();
905: my %setters = ();
906: my $numblocked = 0;
1.44 raeburn 907: my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53 raeburn 908: my %lt = &Apache::lonlocal::texthash(
909: sede => 'Select a destination folder to which the messages will be moved.',
910: nome => 'No messages have been selected to apply ths action to.',
911: chec => 'Check the checkbox for at least one message.',
912: );
1.1 albertel 913: $r->print(<<ENDDISHEADER);
1.16 albertel 914: <script type="text/javascript">
1.1 albertel 915: function checkall() {
1.53 raeburn 916: for (i=0; i<document.forms.disall.delmark.length; i++) {
917: document.forms.disall.delmark[i].checked=true;
1.1 albertel 918: }
919: }
920:
921: function uncheckall() {
1.53 raeburn 922: for (i=0; i<document.forms.disall.delmark.length; i++) {
923: document.forms.disall.delmark[i].checked=false;
924: }
925: }
926: function checkfoldermove() {
927: if (document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value == 'markedmove') {
928: if (document.disall.movetofolder.options[document.disall.movetofolder.selectedIndex].value == "") {
929: alert("$lt{'sede'}");
930: return;
1.1 albertel 931: }
932: }
1.53 raeburn 933: return;
1.1 albertel 934: }
1.53 raeburn 935:
936: function validate_checkedaction() {
937: document.disall.markedaction.value = document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value;
938: if (document.disall.checkedaction.options[document.disall.checkedaction.selectedIndex].value == 'markedmove') {
939: if (document.disall.movetofolder.options[document.disall.movetofolder.selectedIndex].value == "") {
940: alert("$lt{'sede'}");
941: return;
942: }
943: }
944: var checktotal = 0;
945: for (var i=0; i<document.forms.disall.delmark.length; i++) {
946: if (document.forms.disall.delmark[i].checked) {
947: checktotal ++;
948: }
949: }
950: if (checktotal == 0) {
951: alert("$lt{'nome'}\\n$lt{'chec'}");
952: return;
953: }
954: document.disall.submit();
955: }
956:
1.1 albertel 957: </script>
958: ENDDISHEADER
1.54 albertel 959:
1.1 albertel 960: my $fsqs='&folder='.$folder;
1.53 raeburn 961: my @temp=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1 albertel 962: my $totalnumber=$#temp+1;
1.53 raeburn 963: if ($totalnumber < 1) {
1.56.2.1! albertel 964: $r->print('<h2>'.&mt('_empty_mail_folder',
! 965: $msgstatus,
! 966: $statushash{$msgstatus}).'</h2>');
1.1 albertel 967: return;
968: }
969: unless ($interdis) {
970: $interdis=20;
971: }
972: my $number=int($totalnumber/$interdis);
1.53 raeburn 973: if ($interdis) {
974: if ($totalnumber%$interdis == 0) {
975: $number--;
976: }
977: }
978:
1.1 albertel 979: if (($startdis<0) || ($startdis>$number)) { $startdis=$number; }
980: my $firstdis=$interdis*$startdis;
981: if ($firstdis>$#temp) { $firstdis=$#temp-$interdis+1; }
982: my $lastdis=$firstdis+$interdis-1;
983: if ($lastdis>$#temp) { $lastdis=$#temp; }
1.53 raeburn 984: $r->print(&scrollbuttons($startdis,$number,$firstdis,$lastdis,$totalnumber,$msgstatus));
1.1 albertel 985: $r->print('<form method="post" name="disall" action="/adm/email">'.
1.53 raeburn 986: '<table class="LC_mail_list"><tr><th colspan="1"> </th><th>');
1.1 albertel 987: if ($env{'form.sortedby'} eq "revdate") {
988: $r->print('<a href = "?sortedby=date'.$fsqs.'">'.&mt('Date').'</a></th>');
989: } else {
990: $r->print('<a href = "?sortedby=revdate'.$fsqs.'">'.&mt('Date').'</a></th>');
991: }
992: $r->print('<th>');
993: if ($env{'form.sortedby'} eq "revuser") {
994: $r->print('<a href = "?sortedby=user'.$fsqs.'">'.&mt('Username').'</a>');
995: } else {
996: $r->print('<a href = "?sortedby=revuser'.$fsqs.'">'.&mt('Username').'</a>');
997: }
998: $r->print('</th><th>');
999: if ($env{'form.sortedby'} eq "revdomain") {
1000: $r->print('<a href = "?sortedby=domain'.$fsqs.'">'.&mt('Domain').'</a>');
1001: } else {
1002: $r->print('<a href = "?sortedby=revdomain'.$fsqs.'">'.&mt('Domain').'</a>');
1003: }
1004: $r->print('</th><th>');
1005: if ($env{'form.sortedby'} eq "revsubject") {
1006: $r->print('<a href = "?sortedby=subject'.$fsqs.'">'.&mt('Subject').'</a>');
1007: } else {
1008: $r->print('<a href = "?sortedby=revsubject'.$fsqs.'">'.&mt('Subject').'</a>');
1009: }
1010: $r->print('</th><th>');
1011: if ($env{'form.sortedby'} eq "revcourse") {
1.46 raeburn 1012: $r->print('<a href = "?sortedby=course'.$fsqs.'">'.&mt('Course').'</a>');
1.1 albertel 1013: } else {
1.46 raeburn 1014: $r->print('<a href = "?sortedby=revcourse'.$fsqs.'">'.&mt('Course').'</a>');
1.1 albertel 1015: }
1016: $r->print('</th><th>');
1017: if ($env{'form.sortedby'} eq "revstatus") {
1018: $r->print('<a href = "?sortedby=status'.$fsqs.'">'.&mt('Status').'</a></th>');
1019: } else {
1020: $r->print('<a href = "?sortedby=revstatus'.$fsqs.'">'.&mt('Status').'</a></th>');
1021: }
1022: $r->print("</tr>\n");
1.6 albertel 1023:
1024: my $suffix = &Apache::lonmsg::foldersuffix($folder);
1.1 albertel 1025: for (my $n=$firstdis;$n<=$lastdis;$n++) {
1.11 albertel 1026: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,
1027: $description,$recv_name,$recv_domain)=
1028: @{$temp[$n]};
1.1 albertel 1029: if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
1030: if ($status eq 'new') {
1.4 albertel 1031: $r->print('<tr class="LC_mail_new">');
1.1 albertel 1032: } elsif ($status eq 'read') {
1.4 albertel 1033: $r->print('<tr class="LC_mail_read">');
1.1 albertel 1034: } elsif ($status eq 'replied') {
1.4 albertel 1035: $r->print('<tr class="LC_mail_replied">');
1.1 albertel 1036: } else {
1.4 albertel 1037: $r->print('<tr class="LC_mail_other">');
1.1 albertel 1038: }
1.6 albertel 1039: my ($dis_name,$dis_domain) = ($fromname,$fromdomain);
1040: if ($folder eq 'sent') {
1.11 albertel 1041: if (defined($recv_name) && !defined($recv_domain)) {
1042: $dis_name = join('<br />',@{$recv_name});
1043: $dis_domain = join('<br />',@{$recv_domain});
1044: } else {
1.29 www 1045: my $msg_id = &unescape($origID);
1.11 albertel 1046: my %message = &Apache::lonnet::get('nohist_email'.$suffix,
1047: [$msg_id]);
1048: my %content = &Apache::lonmsg::unpackagemsg($message{$msg_id});
1049: $dis_name = join('<br />',@{$content{'recuser'}});
1050: $dis_domain = join('<br />',@{$content{'recdomain'}});
1051: }
1.6 albertel 1052: }
1.53 raeburn 1053: my $localsenttime = &Apache::lonlocal::locallocaltime($sendtime);
1054: my $count = $n +1;
1055: $r->print('<td align="right"><nobr>'.(($status eq 'new')?'<b>':'').
1056: $count.'.'.(($status eq 'new')?'</b>':'').' '.
1057: '<input type="checkbox" name="delmark"'.
1058: ' value="'.$origID.'" /></nobr></td>');
1059: foreach my $item ($localsenttime,$dis_name,$dis_domain,$shortsubj) {
1060: $r->print('<td>'.(($status eq 'new')?'<b>':'').
1061: '<a href="/adm/email?display='.$origID.$sqs.'">'.
1062: $item.(($status eq 'new')?'</b>':'').'</td>');
1063: }
1064: my $showstatus;
1065: my %statushash = &get_msgstatus_types();
1066: if ($status eq '') {
1067: $showstatus = '';
1068: } else {
1069: $showstatus = $statushash{$status};
1070: }
1071: $r->print('<td>'.(($status eq 'new')?'<b>':'').$description.
1072: (($status eq 'new')?'</b>':'').'</td><td>'.
1073: (($status eq 'new')?'<b>':'').$showstatus.
1074: (($status eq 'new')?'</b>':'').'</td></tr>'."\n");
1.1 albertel 1075: } elsif ($status eq 'deleted') {
1076: # purge
1.9 albertel 1077: my ($result,$msg) =
1.29 www 1078: &movemsg(&unescape($origID),$folder,'trash');
1.9 albertel 1079:
1.1 albertel 1080: }
1081: }
1.53 raeburn 1082: $r->print("</table>\n");
1083: $r->print('<table border="0" cellspacing="2" cellpadding="2">
1084: <tr>
1085: <td>'.
1086: '<input type="button" onclick="javascript:checkall()" value="'.&mt('Check All').'" /><br />'."\n".
1087: '<input type="button" onclick="javascript:uncheckall()" value="'.&mt('Uncheck All').'" />'."\n".
1088: '<input type="hidden" name="sortedby" value="'.$env{'form.sortedby'}.'" /></td><td> </td>'."\n".
1089: '<td align="center"><b>'.&mt('Action').'</b><br />'."\n".
1090: ' <select name="checkedaction" onchange="javascript:checkfoldermove()">'."\n");
1091:
1.1 albertel 1092: if ($folder ne 'trash') {
1.53 raeburn 1093: $r->print(' <option value="markeddel">'.&mt('Delete').'</option>'."\n");
1094: }
1095: if ($msgstatus ne 'read') {
1096: $r->print(' <option value="markedread">'.&mt('Mark Read').'</option>."\n"');
1097: }
1098: if ($msgstatus ne 'unread') {
1099: $r->print(' <option value="markedunread">'.&mt('Mark Unread').'</option>'."\n");
1.1 albertel 1100: }
1.53 raeburn 1101: $r->print(' <option value="markedforward">'.&mt('Forward').'</option>'."\n");
1.54 albertel 1102:
1103: my %gotfolders = &Apache::lonmsg::get_user_folders();
1.53 raeburn 1104: if (keys(%gotfolders) > 0) {
1105: $r->print(' <option value="markedmove">'.&mt('Move to Folder ->').
1106: '</option>');
1107: }
1108: $r->print("\n".'</select></td>'."\n");
1.54 albertel 1109:
1.53 raeburn 1110: if (keys(%gotfolders) > 0) {
1111: $r->print('<td align="center"><b>'.&mt('Destination folder').'<b><br />');
1.54 albertel 1112: my %userfolders;
1.53 raeburn 1113: foreach my $key (keys(%gotfolders)) {
1114: $userfolders{$key} = $key;
1115: }
1116: $userfolders{''} = "";
1117: $r->print(&Apache::loncommon::select_form('','movetofolder',%userfolders).
1118: '</td>');
1119: }
1120: $r->print('<td> </td><td> '.
1121: '<input type="button" name="go" value="'.&mt('Go').
1122: '" onclick="javascript:validate_checkedaction()"/></td>'."\n".
1123: '</tr></table>');
1.1 albertel 1124: my $postedstartdis=$startdis+1;
1.53 raeburn 1125: $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 1126: if ($numblocked > 0) {
1127: my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
1128: my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
1129: $r->print('<br /><br />'.
1.51 raeburn 1130: &mt('[quant,_1,message is, messages are] not viewable because display of LON-CAPA messages sent to you by other students between [_2] and [_3] is currently being blocked because of online exams.',$numblocked,$beginblock,$finishblock));
1.44 raeburn 1131: $r->print(&Apache::loncommon::build_block_table($startblock,$endblock,
1132: \%setters));
1.1 albertel 1133: }
1134: }
1135:
1136: # ============================================================== Compose output
1137:
1138: sub compout {
1.53 raeburn 1139: my ($r,$forwarding,$replying,$broadcast,$replycrit,$folder,$dismode,
1140: $multiforward)=@_;
1.1 albertel 1141: my $suffix=&Apache::lonmsg::foldersuffix($folder);
1.38 raeburn 1142: my ($cdom,$cnum,$group,$refarg);
1143: if (exists($env{'form.group'})) {
1144: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1145: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1146: $group = $env{'form.group'};
1147: my $action = 'composing';
1148: $r->print(&groupmail_header($action,$group,$cdom,$cnum));
1149: } elsif ($broadcast eq 'individual') {
1.1 albertel 1150: &printheader($r,'/adm/email?compose=individual',
1151: 'Send a Message');
1152: } elsif ($broadcast) {
1153: &printheader($r,'/adm/email?compose=group',
1154: 'Broadcast Message');
1155: } elsif ($forwarding) {
1156: &Apache::lonhtmlcommon::add_breadcrumb
1.29 www 1157: ({href=>"/adm/email?display=".&escape($forwarding),
1.1 albertel 1158: text=>"Display Message"});
1.29 www 1159: &printheader($r,'/adm/email?forward='.&escape($forwarding),
1.1 albertel 1160: 'Forwarding a Message');
1161: } elsif ($replying) {
1162: &Apache::lonhtmlcommon::add_breadcrumb
1.29 www 1163: ({href=>"/adm/email?display=".&escape($replying),
1.1 albertel 1164: text=>"Display Message"});
1.29 www 1165: &printheader($r,'/adm/email?replyto='.&escape($replying),
1.1 albertel 1166: 'Replying to a Message');
1167: } elsif ($replycrit) {
1168: $r->print('<h3>'.&mt('Replying to a Critical Message').'</h3>');
1169: $replying=$replycrit;
1.53 raeburn 1170: } elsif ($multiforward) {
1171: &Apache::lonhtmlcommon::add_breadcrumb
1172: ({href=>"/adm/email?folder=".&escape($folder),
1173: text=>"Display All Messages"});
1174: &printheader($r,'/adm/email?compose=multiforward',
1175: 'Forwarding Multiple Messages');
1176: $r->print(&mt('Each of the <b>[quant,_1,message]</b> you checked will be forwarded to the recipient(s) you select below.',$multiforward).'<br />');
1.1 albertel 1177: } else {
1178: &printheader($r,'/adm/email?compose=upload',
1179: 'Distribute from Uploaded File');
1180: }
1181:
1182: my $dispcrit='';
1183: my $dissub='';
1184: my $dismsg='';
1185: my $disbase='';
1186: my $func=&mt('Send New');
1.50 raeburn 1187: my %lt=&Apache::lonlocal::texthash('us' => 'Username',
1188: 'do' => 'Domain',
1189: 'ad' => 'Additional Recipients',
1190: 'sb' => 'Subject',
1191: 'ca' => 'Cancel',
1192: 'ma' => 'Mail',
1.53 raeburn 1193: 'msg' => 'Messages',
1.50 raeburn 1194: 'gen' => 'Generate messages from a file',
1195: 'gmt' => 'General message text',
1196: 'tff' => 'The file format for the uploaded portion of the message is',
1197: 'uas' => 'Upload and Send',
1198: );
1.1 albertel 1199: if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
1200: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
1201: '/'.$env{'request.course.sec'})) {
1202: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1203: $dispcrit=
1204: '<p><label><input type="checkbox" name="critmsg" /> '.&mt('Send as critical message').'</label> ' . $crithelp .
1205: '</p><p>'.
1206: '<label><input type="checkbox" name="sendbck" /> '.&mt('Send as critical message').' ' .
1207: &mt('and return receipt') . '</label>' . $crithelp .
1208: '</p><p><label><input type="checkbox" name="permanent" /> '.
1209: &mt('Send copy to permanent email address (if known)').'</label></p>'.
1210: '<p><label><input type="checkbox" name="rsspost" /> '.
1211: &mt('Include in course RSS newsfeed').'</label></p>';
1212: }
1213: my %message;
1214: my %content;
1215: my $defdom=$env{'user.domain'};
1216: if ($forwarding) {
1217: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]);
1218: %content=&Apache::lonmsg::unpackagemsg($message{$forwarding},$folder);
1219: $dispcrit.='<input type="hidden" name="forwid" value="'.
1220: $forwarding.'" />';
1221: $func=&mt('Forward');
1222:
1223: $dissub=&mt('Forwarding').': '.$content{'subject'};
1224: $dismsg=&mt('Forwarded message from').' '.
1225: $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
1226: if ($content{'baseurl'}) {
1.29 www 1227: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1 albertel 1228: }
1229: }
1230: if ($replying) {
1231: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
1232: %content=&Apache::lonmsg::unpackagemsg($message{$replying},$folder);
1233: $dispcrit.='<input type="hidden" name="replyid" value="'.
1234: $replying.'" />';
1235: $func=&mt('Send Reply to');
1236:
1237: $dissub=&mt('Reply').': '.$content{'subject'};
1238: $dismsg='> '.$content{'message'};
1239: $dismsg=~s/\r/\n/g;
1240: $dismsg=~s/\f/\n/g;
1241: $dismsg=~s/\n+/\n\> /g;
1242: if ($content{'baseurl'}) {
1.29 www 1243: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1 albertel 1244: if ($env{'user.adv'}) {
1245: $disbase.='<label><input type="checkbox" name="storebasecomment" />'.&mt('Store message for re-use').
1246: '</label> <a href="/adm/email?showcommentbaseurl='.
1.29 www 1247: &escape($content{'baseurl'}).'" target="comments">'.
1.1 albertel 1248: &mt('Show re-usable messages').'</a><br />';
1249: }
1250: }
1251: }
1252: my $citation=&displayresource(%content);
1.38 raeburn 1253: my ($can_grp_broadcast,$viewgrps,$editgrps);
1.1 albertel 1254: if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
1.23 www 1255: if ($env{'form.text'}) { $dismsg=$env{'form.text'}; }
1256: if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; }
1257: $r->print(
1.1 albertel 1258: '<form action="/adm/email" name="compemail" method="post"'.
1259: ' enctype="multipart/form-data">'."\n".
1.38 raeburn 1260: '<input type="hidden" name="sendmail" value="on" />'."\n");
1261: if ($broadcast eq 'group' && $env{'form.group'} ne '') {
1262: $can_grp_broadcast =
1263: &Apache::lonnet::allowed('sgb',$env{'request.course.id'}.'/'.
1264: $group);
1265: $viewgrps =
1266: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
1267: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1268: $editgrps =
1269: &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
1270: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1271: if ($viewgrps || $editgrps || $can_grp_broadcast) {
1272: $r->print(&disgroup($cdom,$cnum,$group,$viewgrps,$editgrps));
1273: }
1274: }
1275: $r->print('<table>');
1276: if (($broadcast eq 'group') && ($group ne '') &&
1277: (!$can_grp_broadcast && !$viewgrps && !$editgrps)) {
1278: $r->print(&recipient_input_row($cdom,%lt));
1279: }
1280: if (($broadcast ne 'group') && ($broadcast ne 'upload')) {
1.1 albertel 1281: if ($replying) {
1282: $r->print('<tr><td colspan="2">'.&mt('Replying to').' '.
1283: &Apache::loncommon::aboutmewrapper(
1284: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
1.14 albertel 1285: $content{'sendername'}.':'.
1.1 albertel 1286: $content{'senderdomain'}.')'.
1287: '<input type="hidden" name="recuname" value="'.$content{'sendername'}.'" />'.
1288: '<input type="hidden" name="recdomain" value="'.$content{'senderdomain'}.'" />'.
1289: '</td></tr>');
1290: } else {
1.38 raeburn 1291: $r->print(&recipient_input_row($defdom,%lt));
1.1 albertel 1292: }
1293: }
1294: my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
1.53 raeburn 1295: my $subj_size;
1296: if ($multiforward) {
1297: $r->print(&additional_rec_row(\%lt));
1298: $r->print('<tr><td colspan="2">'.
1299: &mt('Unless you choose otherwise:').'<ul><li>'.
1300: &mt("The subject in each forwarded message will be <i>'Forwarding:'</i> followed by the original subject.").'</li><li>'.
1301: &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>');
1302: $func=&mt('Forward');
1303: $dissub = &mt('Forwarding').': ';
1304: $subj_size = '10';
1305: my $extra = '<'.&mt('original subject').'> '.
1306: '<input type="radio" name="showorigsubj" value="1" checked="checked" />'.&mt('Yes').' <input type="radio" name="showorigsubj" value="0" />'.&mt('No');
1307: $dismsg = &mt('Forwarded message from ').' ';
1308: my $sender = &mt("sender's name");
1309: $r->print(&msg_subject_row($dissub,\%lt,$subj_size,$extra));
1310: $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>
1311: </table>
1312: <br />'.
1313: $latexHelp.
1314: &mt("Any new text to display before the text of the original messages:").'<br />
1315: <textarea name="message" id="message" cols="80" rows="5" wrap="hard">
1316: </textarea></p><br />');
1317: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
1318: foreach my $msg (@to_forward) {
1319: $r->print('<input type="hidden" name="delmark" value="'.$msg.'" />');
1320: }
1321: $r->print(&submit_button_row($folder,$dismode,$func.' '.$lt{'msg'},
1322: \%lt));
1323: } elsif ($broadcast ne 'upload') {
1324: $subj_size = '50';
1325: $r->print(&additional_rec_row(\%lt));
1326: $r->print(&msg_subject_row($dissub,\%lt,$subj_size));
1327: $r->print(<<"ENDCOMP");
1328: </table>
1.1 albertel 1329: $latexHelp
1330: <textarea name="message" id="message" cols="80" rows="15" wrap="hard">$dismsg
1331: </textarea></p><br />
1332: $dispcrit
1333: $disbase
1334: ENDCOMP
1.53 raeburn 1335: $r->print(&submit_button_row($folder,$dismode,$func.' '.$lt{'ma'},
1336: \%lt));
1337: $r->print($citation);
1.38 raeburn 1338: if (exists($env{'form.ref'})) {
1339: $r->print('<input type="hidden" name="ref" value="'.
1340: $env{'form.ref'}.'" />');
1341: }
1342: if (exists($env{'form.group'})) {
1343: $r->print('<input type="hidden" name="group" value="'.
1344: $env{'form.group'}.'" />');
1345: }
1.1 albertel 1346: } else { # $broadcast is 'upload'
1.50 raeburn 1347: $r->print(<<ENDBLOCK);
1.1 albertel 1348: <input type="hidden" name="sendmode" value="upload" />
1349: <input type="hidden" name="send" value="on" />
1.50 raeburn 1350: <h3>$lt{'gen'}</h3>
1.1 albertel 1351: <p>
1352: Subject: <input type="text" size="50" name="subject" />
1353: </p>
1.50 raeburn 1354: <p>$lt{'gmt'}:<br />
1.1 albertel 1355: <textarea name="message" id="message" cols="60" rows="10" wrap="hard">$dismsg
1356: </textarea></p>
1357: <p>
1.50 raeburn 1358: $lt{'tff'}:
1359: ENDBLOCK
1360: $r->print('
1361: <pre>'."\n".
1362: &mt('username1:domain1: text')."\n".
1363: &mt('username2:domain2: text')."\n".
1364: &mt('username3:domain1: text')."\n".
1365: '</pre>
1.1 albertel 1366: </p>
1367: <p>
1.50 raeburn 1368: '.&mt('The messages will be assembled from all lines with the respective'."\n".'<tt>username:domain</tt>, and appended to the general message text.'));
1369: $r->print(<<ENDUPLOAD);
1370: </p>
1.1 albertel 1371: <p>
1372: <input type="file" name="upfile" size="40" /></p><p>
1373: $dispcrit
1.50 raeburn 1374: <input type="submit" value="$lt{'uas'}" /></p>
1.1 albertel 1375: ENDUPLOAD
1376: }
1377: if ($broadcast eq 'group') {
1.38 raeburn 1378: if ($group eq '') {
1379: my $studentsel = &discourse();
1380: $r->print($studentsel);
1381: }
1.1 albertel 1382: }
1.36 albertel 1383: if ($env{'form.displayedcrit'}) {
1384: $r->print('<input type="hidden" name="displayedcrit" value="true" />');
1385: }
1.1 albertel 1386: $r->print('</form>'.
1387: &Apache::lonfeedback::generate_preview_button('compemail','message').
1388: &Apache::lonhtmlcommon::htmlareaselectactive('message'));
1389: }
1390:
1391: # ---------------------------------------------------- Display all face to face
1392:
1.38 raeburn 1393: sub recipient_input_row {
1394: my ($dom,%lt) = @_;
1395: my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain');
1396: my $selectlink=
1397: &Apache::loncommon::selectstudent_link('compemail','recuname',
1398: 'recdomain');
1399: my $output = <<"ENDREC";
1400: <tr><td>$lt{'us'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recname'}" /></td><td rowspan="2">$selectlink</td></tr>
1401: <tr><td>$lt{'do'}:</td>
1402: <td>$domform</td></tr>
1403: ENDREC
1404: return $output;
1405: }
1406:
1.53 raeburn 1407: sub additional_rec_row {
1408: my ($lt) = @_;
1409: my $output = <<"ENDADD";
1410: <tr><td>$lt->{'ad'}:<br /><tt>username:domain,username:domain, ...
1411: </tt></td><td>
1412: <input type="text" size="50" name="additionalrec" /></td></tr>
1413: ENDADD
1414: return $output;
1415: }
1416:
1417: sub submit_button_row {
1418: my ($folder,$dismode,$sendtext,$lt) = @_;
1419: my $output = qq|
1420: <input type="hidden" name="folder" value="$folder" />
1421: <input type="hidden" name="dismode" value="$dismode" />
1422: <input type="submit" name="send" value="$sendtext" />
1423: <input type="submit" name="cancel" value="$lt->{'ca'}" /><hr />
1424: |;
1425: return $output;
1426: }
1427:
1428: sub msg_subject_row {
1429: my ($dissub,$lt,$subj_size,$extra) = @_;
1430: my $output = '<tr><td>'.$lt->{'sb'}.':</td><td><input type="text" size="'.
1431: $subj_size.'" name="subject" value="'.$dissub.'" />'.$extra.
1432: '</td></tr>';
1433: return $output;
1434: }
1435:
1.1 albertel 1436: sub retrieve_instructor_comments {
1437: my ($user,$domain)=@_;
1438: my $target=$env{'form.grade_target'};
1439: if (! $env{'request.course.id'}) { return; }
1.49 albertel 1440: if (! &Apache::lonnet::allowed('dff',$env{'request.course.id'})
1441: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1442: '/'.$env{'request.course.sec'})) {
1443: return;
1444: }
1445: my %records=&Apache::lonnet::dump('nohist_email',
1446: $env{'course.'.$env{'request.course.id'}.'.domain'},
1447: $env{'course.'.$env{'request.course.id'}.'.num'},
1448: '%255b'.$user.'%253a'.$domain.'%255d');
1449: my $result='';
1.42 raeburn 1450: foreach my $key (sort(keys(%records))) {
1451: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1 albertel 1452: next if ($content{'senderdomain'} eq '');
1453: next if ($content{'subject'} !~ /^Record/);
1454: # &Apache::lonfeedback::newline_to_br(\$content{'message'});
1455: $result.='Recorded by '.
1.14 albertel 1456: $content{'sendername'}.':'.$content{'senderdomain'}."\n";
1.1 albertel 1457: $result.=
1458: &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
1459: }
1460: return $result;
1461: }
1462:
1463: sub disfacetoface {
1464: my ($r,$user,$domain)=@_;
1465: my $target=$env{'form.grade_target'};
1466: unless ($env{'request.course.id'}) { return; }
1.49 albertel 1467: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
1468: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1469: '/'.$env{'request.course.sec'})) {
1.50 raeburn 1470: $r->print(&mt('Not allowed'));
1.1 albertel 1471: return;
1472: }
1473: my %records=&Apache::lonnet::dump('nohist_email',
1474: $env{'course.'.$env{'request.course.id'}.'.domain'},
1475: $env{'course.'.$env{'request.course.id'}.'.num'},
1476: '%255b'.$user.'%253a'.$domain.'%255d');
1477: my $result='';
1.42 raeburn 1478: foreach my $key (sort(keys(%records))) {
1479: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1 albertel 1480: next if ($content{'senderdomain'} eq '');
1481: &Apache::lonfeedback::newline_to_br(\$content{'message'});
1482: if ($content{'subject'}=~/^Record/) {
1483: $result.='<h3>'.&mt('Record').'</h3>';
1484: } elsif ($content{'subject'}=~/^Broadcast/) {
1485: $result .='<h3>'.&mt('Broadcast Message').'</h3>';
1486: if ($content{'subject'}=~/^Broadcast\./) {
1487: if (defined($content{'coursemsgid'})) {
1.29 www 1488: my $crsmsgid = &escape($content{'coursemsgid'});
1.1 albertel 1489: my $broadcast_message = &general_message($crsmsgid);
1490: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$broadcast_message;
1491: } else {
1492: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1493: $content{'message'} =
1494: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1495: $content{'message'};
1496: }
1497: }
1498: } else {
1499: $result.='<h3>'.&mt('Critical Message').'</h3>';
1500: if (defined($content{'coursemsgid'})) {
1.29 www 1501: my $crsmsgid=&escape($content{'coursemsgid'});
1.1 albertel 1502: my $critical_message = &general_message($crsmsgid);
1503: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$critical_message;
1504: } else {
1505: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1506: $content{'message'}=
1507: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1508: $content{'message'};
1509: }
1510: }
1511: $result.=&mt('By').': <b>'.
1512: &Apache::loncommon::aboutmewrapper(
1513: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14 albertel 1514: $content{'sendername'}.':'.
1.1 albertel 1515: $content{'senderdomain'}.') '.$content{'time'}.
1516: '<br /><pre>'.
1517: &Apache::lontexconvert::msgtexconverted($content{'message'}).
1518: '</pre>';
1519: }
1520: # Check to see if there were any messages.
1521: if ($result eq '') {
1.33 albertel 1522: my $lctype = lc(&Apache::loncommon::course_type());
1.1 albertel 1523: if ($target ne 'tex') {
1.30 raeburn 1524: $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 1525: } else {
1.30 raeburn 1526: $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this [_1].',$lctype).'}\\\\');
1.1 albertel 1527: }
1528: } else {
1529: $r->print($result);
1530: }
1531: }
1532:
1533: sub general_message {
1534: my ($crsmsgid) = @_;
1535: my %general_content;
1536: if ($crsmsgid) {
1537: my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid],
1538: $env{'course.'.$env{'request.course.id'}.'.domain'},
1539: $env{'course.'.$env{'request.course.id'}.'.num'});
1540: %general_content = &Apache::lonmsg::unpackagemsg($course_content{$crsmsgid});
1541: }
1542: return $general_content{'message'};
1543: }
1544:
1545: # ---------------------------------------------------------------- Face to face
1546:
1547: sub facetoface {
1548: my ($r,$stage)=@_;
1.49 albertel 1549: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
1550: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1551: '/'.$env{'request.course.sec'})) {
1.50 raeburn 1552: $r->print(&mt('Not allowed'));
1.1 albertel 1553: return;
1554: }
1.33 albertel 1555: my $crstype = &Apache::loncommon::course_type();
1556: my $leaders = ($crstype eq 'Group') ? 'coordinators and leaders'
1557: : 'faculty and staff';
1.1 albertel 1558: &printheader($r,
1559: '/adm/email?recordftf=query',
1560: "User Notes, Face-to-Face, Critical Messages, Broadcast Messages");
1561: # from query string
1562:
1563: if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
1564: if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
1565:
1566: my $defdom=$env{'user.domain'};
1567: # already filled in
1568: if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
1569: # generate output
1570: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
1571: my $stdbrws = &Apache::loncommon::selectstudent_link
1572: ('stdselect','recuname','recdomain');
1573: my %lt=&Apache::lonlocal::texthash('user' => 'Username',
1574: 'dom' => 'Domain',
1.30 raeburn 1575: 'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, and Broadcast Messages in $crstype",
1.1 albertel 1576: 'subm' => 'Retrieve discussion and message records',
1.30 raeburn 1577: 'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')',
1.1 albertel 1578: 'post' => 'Post this Record');
1579: $r->print(<<"ENDTREC");
1580: <h3>$lt{'head'}</h3>
1581: <form method="post" action="/adm/email" name="stdselect">
1582: <input type="hidden" name="recordftf" value="retrieve" />
1583: <table>
1584: <tr><td>$lt{'user'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recuname'}" /></td>
1585: <td rowspan="2">
1586: $stdbrws
1587: <input type="submit" value="$lt{'subm'}" /></td>
1588: </tr>
1589: <tr><td>$lt{'dom'}:</td>
1590: <td>$domform</td></tr>
1591: </table>
1592: </form>
1593: ENDTREC
1594: if (($stage ne 'query') &&
1595: ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
1596: chomp($env{'form.newrecord'});
1597: if ($env{'form.newrecord'}) {
1.31 albertel 1598: &Apache::lonmsg::store_instructor_comment($env{'form.newrecord'},
1599: $env{'form.recuname'},
1600: $env{'form.recdomain'});
1.1 albertel 1601: }
1602: $r->print('<h3>'.&Apache::loncommon::plainname($env{'form.recuname'},
1603: $env{'form.recdomain'}).'</h3>');
1604: &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
1605: $r->print(<<ENDRHEAD);
1606: <form method="post" action="/adm/email">
1607: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
1608: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
1609: ENDRHEAD
1610: $r->print(<<ENDBFORM);
1611: <hr />$lt{'newr'}<br />
1612: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
1613: <br />
1614: <input type="hidden" name="recordftf" value="post" />
1615: <input type="submit" value="$lt{'post'}" />
1616: </form>
1617: ENDBFORM
1618: }
1619: }
1620:
1621: # ----------------------------------------------------------- Blocking during exams
1622:
1623: sub examblock {
1624: my ($r,$action) = @_;
1625: unless ($env{'request.course.id'}) { return;}
1.44 raeburn 1626: if (!&Apache::lonnet::allowed('dcm',$env{'request.course.id'})
1627: && ! &Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
1.1 albertel 1628: '/'.$env{'request.course.sec'})) {
1629: $r->print('Not allowed');
1630: return;
1631: }
1.34 albertel 1632: my $usertype = (&Apache::loncommon::course_type() eq 'Group') ? 'members'
1.33 albertel 1633: : 'students';
1.1 albertel 1634: my %lt=&Apache::lonlocal::texthash(
1635: 'comb' => 'Communication Blocking',
1636: 'cbds' => 'Communication blocking during scheduled exams',
1.30 raeburn 1637: '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 1638: 'mecb' => 'Modify existing communication blocking periods',
1.50 raeburn 1639: 'ncbc' => 'No communication blocks currently stored',
1640: 'stor' => 'Store',
1.1 albertel 1641: );
1642:
1643: my %ltext = &Apache::lonlocal::texthash(
1644: 'dura' => 'Duration',
1645: 'setb' => 'Set by',
1646: 'even' => 'Event',
1.44 raeburn 1647: 'blck' => 'Blocked?',
1.1 albertel 1648: 'actn' => 'Action',
1649: 'star' => 'Start',
1650: 'endd' => 'End'
1651: );
1652:
1653: &printheader($r,'/adm/email?block=display',$lt{'comb'});
1654: $r->print('<h3>'.$lt{'cbds'}.'</h3>');
1655:
1656: if ($action eq 'store') {
1657: &blockstore($r);
1658: }
1659:
1660: $r->print($lt{'desc'}.'<br /><br />
1661: <form name="blockform" method="post" action="/adm/email?block=store">
1662: ');
1663:
1664: $r->print('<h4>'.$lt{'mecb'}.'</h4>');
1665: my %records = ();
1666: my $blockcount = 0;
1667: my $parmcount = 0;
1668: &get_blockdates(\%records,\$blockcount);
1669: if ($blockcount > 0) {
1670: $parmcount = &display_blocker_status($r,\%records,\%ltext);
1671: } else {
1672: $r->print($lt{'ncbc'}.'<br /><br />');
1673: }
1674: &display_addblocker_table($r,$parmcount,\%ltext);
1675: my $end_page=&Apache::loncommon::end_page();
1676: $r->print(<<"END");
1677: <br />
1678: <input type="hidden" name="blocktotal" value="$blockcount" />
1.50 raeburn 1679: <input type ="submit" value="$lt{'stor'}" />
1.1 albertel 1680: </form>
1681: $end_page
1682: END
1683: return;
1684: }
1685:
1686: sub blockstore {
1687: my $r = shift;
1688: my %lt=&Apache::lonlocal::texthash(
1689: 'tfcm' => 'The following changes were made',
1690: 'ncwm' => 'No changes were made.'
1691: );
1692: my %adds = ();
1693: my %removals = ();
1694: my %cancels = ();
1695: my $modtotal = 0;
1696: my $canceltotal = 0;
1697: my $addtotal = 0;
1698: my %blocking = ();
1699: $r->print('<h3>'.$lt{'head'}.'</h3>');
1.42 raeburn 1700: foreach my $envkey (keys(%env)) {
1.44 raeburn 1701: if ($envkey =~ m/^form\.modify_(\d+)$/) {
1.1 albertel 1702: $adds{$1} = $1;
1703: $removals{$1} = $1;
1704: $modtotal ++;
1.42 raeburn 1705: } elsif ($envkey =~ m/^form\.cancel_(\d+)$/) {
1.1 albertel 1706: $cancels{$1} = $1;
1707: unless ( defined($removals{$1}) ) {
1708: $removals{$1} = $1;
1709: $canceltotal ++;
1710: }
1.42 raeburn 1711: } elsif ($envkey =~ m/^form\.add_(\d+)$/) {
1.1 albertel 1712: $adds{$1} = $1;
1713: $addtotal ++;
1.44 raeburn 1714: }
1.1 albertel 1715: }
1716:
1.42 raeburn 1717: foreach my $key (keys(%removals)) {
1718: my $hashkey = $env{'form.key_'.$key};
1.1 albertel 1719: &Apache::lonnet::del('comm_block',["$hashkey"],
1720: $env{'course.'.$env{'request.course.id'}.'.domain'},
1721: $env{'course.'.$env{'request.course.id'}.'.num'}
1722: );
1723: }
1.42 raeburn 1724: foreach my $key (keys(%adds)) {
1725: unless ( defined($cancels{$key}) ) {
1726: my ($newstart,$newend) = &get_dates_from_form($key);
1.1 albertel 1727: my $newkey = $newstart.'____'.$newend;
1.44 raeburn 1728: my $blocktypes = &get_block_choices($key);
1729: $blocking{$newkey} = {
1730: setter => $env{'user.name'}.':'.$env{'user.domain'},
1731: event => &escape($env{'form.title_'.$key}),
1732: blocks => $blocktypes,
1733: };
1.1 albertel 1734: }
1735: }
1736: if ($addtotal + $modtotal > 0) {
1737: &Apache::lonnet::put('comm_block',\%blocking,
1738: $env{'course.'.$env{'request.course.id'}.'.domain'},
1739: $env{'course.'.$env{'request.course.id'}.'.num'}
1740: );
1741: }
1742: my $chgestotal = $canceltotal + $modtotal + $addtotal;
1743: if ($chgestotal > 0) {
1744: $r->print($lt{'tfcm'}.'<ul>');
1745: if ($canceltotal > 0) {
1.50 raeburn 1746: $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] removed.',$canceltotal).'</li>');
1.1 albertel 1747: }
1748: if ($modtotal > 0) {
1.50 raeburn 1749: $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] modified.',$modtotal).'</li>');
1.1 albertel 1750: }
1751: if ($addtotal > 0) {
1.50 raeburn 1752: $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] added.',$addtotal).'</li>');
1.1 albertel 1753: }
1754: $r->print('</ul>');
1755: } else {
1756: $r->print($lt{'ncwm'});
1757: }
1758: $r->print('<br />');
1759: return;
1760: }
1761:
1762: sub get_dates_from_form {
1763: my $item = shift;
1764: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
1765: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
1766: return ($startdate,$enddate);
1767: }
1768:
1769: sub get_blockdates {
1770: my ($records,$blockcount) = @_;
1771: $$blockcount = 0;
1772: %{$records} = &Apache::lonnet::dump('comm_block',
1773: $env{'course.'.$env{'request.course.id'}.'.domain'},
1774: $env{'course.'.$env{'request.course.id'}.'.num'}
1775: );
1.15 albertel 1776: $$blockcount = keys(%{$records});
1777:
1778: if ((keys(%{$records}))[0] =~ /^error: 2 /) {
1779: $records = {};
1780: $$blockcount = 0;
1.1 albertel 1781: }
1782: }
1783:
1.44 raeburn 1784: sub get_block_choices {
1785: my $item = shift;
1786: my $blocklist;
1787: my ($typeorder,$types) = &blocktype_text();
1788: foreach my $type (@{$typeorder}) {
1789: if ($env{'form.'.$type.'_'.$item}) {
1790: $blocklist->{$type} = 'on';
1791: } else {
1792: $blocklist->{$type} = 'off';
1793: }
1794: }
1795: return $blocklist;
1796: }
1797:
1.1 albertel 1798: sub display_blocker_status {
1799: my ($r,$records,$ltext) = @_;
1800: my $parmcount = 0;
1.16 albertel 1801:
1.1 albertel 1802: my %lt = &Apache::lonlocal::texthash(
1803: 'modi' => 'Modify',
1804: 'canc' => 'Cancel',
1805: );
1.44 raeburn 1806: my ($typeorder,$types) = &blocktype_text();
1.18 albertel 1807: $r->print(&Apache::loncommon::start_data_table());
1.1 albertel 1808: $r->print(<<"END");
1.16 albertel 1809: <tr>
1.44 raeburn 1810: <th>$ltext->{'dura'}</th>
1811: <th>$ltext->{'setb'}</th>
1812: <th>$ltext->{'even'}</th>
1813: <th>$ltext->{'blck'}</th>
1814: <th>$ltext->{'actn'}?</th>
1.16 albertel 1815: </tr>
1.1 albertel 1816: END
1.18 albertel 1817: foreach my $record (sort(keys(%{$records}))) {
1.1 albertel 1818: my $onchange = 'onFocus="javascript:window.document.forms['.
1819: "'blockform'].elements['modify_".$parmcount."'].".
1820: 'checked=true;"';
1.18 albertel 1821: my ($start,$end) = split(/____/,$record);
1.1 albertel 1822: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
1823: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1.15 albertel 1824:
1.44 raeburn 1825: my ($setuname,$setudom,$title,$blocks) =
1826: &Apache::loncommon::parse_block_record($$records{$record});
1.21 albertel 1827: $title = &HTML::Entities::encode($title,'"<>&');
1.44 raeburn 1828: my $settername =
1829: &Apache::loncommon::aboutmewrapper(
1830: &Apache::loncommon::plainname($setuname,$setudom),
1831: $setuname,$setudom);
1.18 albertel 1832: $r->print(&Apache::loncommon::start_data_table_row());
1.1 albertel 1833: $r->print(<<"END");
1.44 raeburn 1834: <td>$ltext->{'star'}: $startform<br/>$ltext->{'endd'}: $endform</td>
1.1 albertel 1835: <td>$settername</td>
1.18 albertel 1836: <td><input type="text" name="title_$parmcount" size="15" value="$title" /><input type="hidden" name="key_$parmcount" value="$record" /></td>
1.44 raeburn 1837: <td>
1838: END
1839: foreach my $block (@{$typeorder}) {
1840: my $blockstatus = '';
1841: if ($blocks->{$block} eq 'on') {
1842: $blockstatus = 'checked="true"';
1843: }
1844: $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" '.$blockstatus.' value="1" />'.$types->{$block}.'</label><br />');
1845: }
1846: $r->print(<<"END");
1847: </td>
1.1 albertel 1848: <td><label>$lt{'modi'}? <input type="checkbox" name="modify_$parmcount" /></label><br /><label>$lt{'canc'}? <input type="checkbox" name="cancel_$parmcount" /></label>
1849: END
1.18 albertel 1850: $r->print(&Apache::loncommon::end_data_table_row());
1851: $parmcount++;
1.1 albertel 1852: }
1853: $r->print(<<"END");
1854: </table>
1855: <br />
1856: <br />
1857: END
1858: return $parmcount;
1859: }
1860:
1861: sub display_addblocker_table {
1862: my ($r,$parmcount,$ltext) = @_;
1863: my $start = time;
1864: my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
1865: my $onchange = 'onFocus="javascript:window.document.forms['.
1866: "'blockform'].elements['add_".$parmcount."'].".
1867: 'checked=true;"';
1868: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
1869: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1870: my %lt = &Apache::lonlocal::texthash(
1871: 'addb' => 'Add block',
1872: 'exam' => 'e.g., Exam 1',
1873: 'addn' => 'Add new communication blocking periods'
1874: );
1.44 raeburn 1875: my ($typeorder,$types) = &blocktype_text();
1.1 albertel 1876: $r->print(<<"END");
1877: <h4>$lt{'addn'}</h4>
1.18 albertel 1878: END
1879: $r->print(&Apache::loncommon::start_data_table());
1880: $r->print(<<"END");
1.16 albertel 1881: <tr>
1.44 raeburn 1882: <th>$ltext->{'dura'}</th>
1883: <th>$ltext->{'even'} $lt{'exam'}</th>
1884: <th>$ltext->{'blck'}</th>
1885: <th>$ltext->{'actn'}?</th>
1.16 albertel 1886: </tr>
1.18 albertel 1887: END
1.44 raeburn 1888: $r->print(&Apache::loncommon::start_data_table_row());
1.18 albertel 1889: $r->print(<<"END");
1.44 raeburn 1890: <td>$ltext->{'star'}: $startform<br />$ltext->{'endd'}: $endform</td>
1.16 albertel 1891: <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
1.44 raeburn 1892: <td>
1893: END
1894: foreach my $block (@{$typeorder}) {
1895: $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" value="1" />'.$types->{$block}.'</label><br />');
1896: }
1897: $r->print(<<"END");
1898: </td>
1.16 albertel 1899: <td><label>$lt{'addb'}? <input type="checkbox" name="add_$parmcount" value="1" /></label></td>
1.1 albertel 1900: END
1.18 albertel 1901: $r->print(&Apache::loncommon::end_data_table_row());
1902: $r->print(&Apache::loncommon::end_data_table());
1.1 albertel 1903: return;
1904: }
1905:
1.44 raeburn 1906: sub blocktype_text {
1907: my %types = &Apache::lonlocal::texthash(
1908: 'com' => 'Messaging',
1909: 'chat' => 'Chat',
1910: 'boards' => 'Discussion',
1911: 'port' => 'Portfolio',
1.45 raeburn 1912: 'groups' => 'Groups',
1913: 'blogs' => 'Blogs',
1.18 albertel 1914: );
1.45 raeburn 1915: my $typeorder = ['com','chat','boards','port','groups','blogs'];
1.44 raeburn 1916: return ($typeorder,\%types);
1.1 albertel 1917: }
1918:
1919: # ----------------------------------------------------------- Display a message
1920:
1921: sub displaymessage {
1.53 raeburn 1922: my ($r,$msgid,$folder,$msgstatus)=@_;
1.1 albertel 1923: my $suffix=&Apache::lonmsg::foldersuffix($folder);
1924: my %blocked = ();
1925: my %setters = ();
1926: my $numblocked = 0;
1.33 albertel 1927: my $crstype = &Apache::loncommon::course_type();
1.30 raeburn 1928:
1.1 albertel 1929: # info to generate "next" and "previous" buttons and check if message is blocked
1.44 raeburn 1930: my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53 raeburn 1931: my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1 albertel 1932: if ( $blocked{$msgid} eq 'ON' ) {
1933: &printheader($r,'/adm/email',&mt('Display a Message'));
1934: $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.'));
1935: &build_block_table($r,$startblock,$endblock,\%setters);
1936: return;
1937: }
1938: &statuschange($msgid,'read',$folder);
1939: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1940: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid});
1941:
1942: my $counter=0;
1943: $r->print('<pre>');
1.29 www 1944: my $escmsgid=&escape($msgid);
1.1 albertel 1945: foreach (@messages) {
1946: if ($_->[5] eq $escmsgid){
1947: last;
1948: }
1949: $counter++;
1950: }
1951: $r->print('</pre>');
1952: my $number_of_messages = scalar(@messages); #subtract 1 for last index
1953: # start output
1.29 www 1954: &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'});
1.1 albertel 1955: my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'});
1956: # Functions
1957: $r->print('<table border="2" width="100%"><tr bgcolor="#FFFFAA"><td>'.&mt('Functions').':</td>'.
1.29 www 1958: '<td><a href="/adm/email?replyto='.&escape($msgid).$sqs.
1.1 albertel 1959: '"><b>'.&mt('Reply').'</b></a></td>'.
1.29 www 1960: '<td><a href="/adm/email?forward='.&escape($msgid).$sqs.
1.1 albertel 1961: '"><b>'.&mt('Forward').'</b></a></td>'.
1.29 www 1962: '<td><a href="/adm/email?markunread='.&escape($msgid).$sqs.
1.1 albertel 1963: '"><b>'.&mt('Mark Unread').'</b></a></td>'.
1.29 www 1964: '<td><a href="/adm/email?markdel='.&escape($msgid).$sqs.
1.1 albertel 1965: '"><b>'.&mt('Delete').'</b></a></td>'.
1966: '<td><a href="/adm/email?'.$sqs.
1967: '"><b>'.&mt('Back to Folder Display').'</b></a></td>');
1968: if ($counter > 0){
1969: $r->print('<td><a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.
1970: '"><b>'.&mt('Previous').'</b></a></td>');
1971: }
1972: if ($counter < $number_of_messages - 1){
1973: $r->print('<td><a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.
1974: '"><b>'.&mt('Next').'</b></a></td>');
1975: }
1976: $r->print('</tr></table>');
1977: if ($env{'user.adv'}) {
1978: $r->print('<table border="2" width="100%"><tr bgcolor="#FFAAAA"><td>'.&mt('Currently available actions (will open extra window)').':</td>');
1979: my $symb=&Apache::lonnet::symbread($content{'baseurl'});
1980: if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
1981: $r->print('<td><b>'.&Apache::loncommon::track_student_link(&mt('View recent activity'),$content{'sendername'},$content{'senderdomain'},'check').'</b></td>');
1982: }
1983: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
1984: $r->print('<td><b>'.&Apache::loncommon::pprmlink(&mt('Set/Change parameters'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
1985: }
1986: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
1987: $r->print('<td><b>'.&Apache::loncommon::pgrdlink(&mt('Set/Change grades'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
1988: }
1989: $r->print('</tr></table>');
1990: }
1991: my $tolist;
1992: my @recipients = ();
1993: for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
1994: $recipients[$i] = &Apache::loncommon::aboutmewrapper(
1995: &Apache::loncommon::plainname($content{'recuser'}[$i],
1996: $content{'recdomain'}[$i]),
1997: $content{'recuser'}[$i],$content{'recdomain'}[$i]).
1998: ' ('.$content{'recuser'}[$i].' at '.$content{'recdomain'}[$i].') ';
1999: }
2000: $tolist = join(', ',@recipients);
2001: $r->print('<br /><b>'.&mt('Subject').':</b> '.$content{'subject'}.
2002: ($folder ne 'sent'?'<br /><b>'.&mt('From').':</b> '.
2003: &Apache::loncommon::aboutmewrapper(
2004: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
2005: $content{'sendername'},$content{'senderdomain'}).' ('.
2006: $content{'sendername'}.' at '.
2007: $content{'senderdomain'}.') ':'<br /><b>'.&mt('To').':</b> '.
2008: $tolist).
1.30 raeburn 2009: ($content{'courseid'}?'<br /><b>'.&mt($crstype).':</b> '.$courseinfo{'description'}.
2010: ($content{'coursesec'}?' ('.&mt('Section').': '.$content{'coursesec'}.')':''):'').
1.1 albertel 2011: '<br /><b>'.&mt('Time').':</b> '.$content{'time'}.
2012: ($content{'baseurl'}?'<br /><b>'.&mt('Refers to').':</b> <a href="'.$content{'baseurl'}.'">'.
2013: $content{'baseurl'}.' ('.&Apache::lonnet::gettitle($content{'baseurl'}).')</a>':'').
2014: '<p><pre>'.
2015: &Apache::lontexconvert::msgtexconverted($content{'message'},1).
2016: '</pre><hr />'.&displayresource(%content).'</p>');
2017: return;
2018: }
2019:
2020: # =========================================================== Show the citation
2021:
2022: sub displayresource {
2023: my %content=@_;
2024: #
2025: # If the recipient is in the same course that the message was sent from and
2026: # has sufficient privileges, show "all details," else show citation
2027: #
2028: if (($env{'request.course.id'} eq $content{'courseid'})
2029: && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
2030: my $symb=&Apache::lonnet::symbread($content{'baseurl'});
2031: # Could not get a symb, give up
2032: unless ($symb) { return $content{'citation'}; }
2033: # Have a symb, can render
2034: return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
2035: &Apache::loncommon::get_previous_attempt($symb,
2036: $content{'sendername'},
2037: $content{'senderdomain'},
2038: $content{'courseid'}).
2039: '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
2040: &Apache::loncommon::get_student_view($symb,
2041: $content{'sendername'},
2042: $content{'senderdomain'},
2043: $content{'courseid'}).
2044: '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
2045: &Apache::loncommon::get_student_answers($symb,
2046: $content{'sendername'},
2047: $content{'senderdomain'},
2048: $content{'courseid'});
2049: } elsif ($env{'user.adv'}) {
2050: return $content{'citation'};
2051: }
2052: return '';
2053: }
2054:
2055: # ================================================================== The Header
2056:
2057: sub header {
2058: my ($r,$title,$baseurl)=@_;
2059:
2060: my $extra = &Apache::loncommon::studentbrowser_javascript();
2061: if ($baseurl) {
1.41 albertel 2062: $extra .= "<base href=\"".&Apache::lonnet::absolute_url()."/$baseurl\" />";
1.1 albertel 2063: }
2064: $r->print(&Apache::loncommon::start_page('Communication and Messages',
1.38 raeburn 2065: $extra));
1.1 albertel 2066: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.38 raeburn 2067: (($title?$title:'Communication and Messages')));
1.1 albertel 2068: }
2069:
2070: # ---------------------------------------------------------------- Print header
2071:
2072: sub printheader {
2073: my ($r,$url,$desc,$title,$baseurl)=@_;
2074: &Apache::lonhtmlcommon::add_breadcrumb
2075: ({href=>$url,
2076: text=>$desc});
2077: &header($r,$title,$baseurl);
2078: }
2079:
2080: # ------------------------------------------------------------ Store the comment
2081:
2082: sub storecomment {
2083: my ($r)=@_;
2084: my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2085: my $cleanmsgtxt='';
1.42 raeburn 2086: foreach my $line (split(/[\n\r]/,$msgtxt)) {
2087: unless ($line=~/^\s*(\>|\>\;)/) {
2088: $cleanmsgtxt.=$line."\n";
1.1 albertel 2089: }
2090: }
1.29 www 2091: my $key=&escape($env{'form.baseurl'}).'___'.time;
1.1 albertel 2092: &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
2093: }
2094:
2095: sub storedcommentlisting {
2096: my ($r)=@_;
2097: my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
1.29 www 2098: '^'.&escape(&escape($env{'form.showcommentbaseurl'})));
1.1 albertel 2099: $r->print(&Apache::loncommon::start_page('Stored Comment Listing',undef,
2100: {'onlybody' => 1}));
2101: if ((keys %msgs)[0]=~/^error\:/) {
2102: $r->print(&mt('No stored comments yet.'));
2103: } else {
2104: my $found=0;
1.42 raeburn 2105: foreach my $key (sort(keys(%msgs))) {
2106: $r->print("\n".$msgs{$key}."<hr />");
1.1 albertel 2107: $found=1;
2108: }
2109: unless ($found) {
2110: $r->print(&mt('No stored comments yet for this resource.'));
2111: }
2112: }
2113: }
2114:
2115: # ---------------------------------------------------------------- Send an email
2116:
2117: sub sendoffmail {
2118: my ($r,$folder)=@_;
2119: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2120: my $sendstatus='';
2121: my %specialmsg_status;
2122: my $numspecial = 0;
1.38 raeburn 2123: my ($cdom,$cnum,$group);
2124: if (exists($env{'form.group'})) {
2125: $group = $env{'form.group'};
2126: }
2127: if (exists($env{'request.course.id'})) {
2128: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2129: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2130: }
1.1 albertel 2131: if ($env{'form.send'}) {
1.53 raeburn 2132: if (!$env{'form.multiforward'}) {
2133: if ($group eq '') {
2134: &printheader($r,'','Messages being sent.');
2135: } else {
2136: $r->print(&groupmail_header('sending',$group));
2137: }
1.38 raeburn 2138: }
1.1 albertel 2139: $r->rflush();
2140: my %content=();
2141: undef %content;
2142: if ($env{'form.forwid'}) {
2143: my $msgid=$env{'form.forwid'};
2144: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2145: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2146: &statuschange($msgid,'forwarded',$folder);
2147: $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
2148: $content{'message'};
2149: }
2150: if ($env{'form.replyid'}) {
2151: my $msgid=$env{'form.replyid'};
2152: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2153: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2154: &statuschange($msgid,'replied',$folder);
2155: }
1.13 albertel 2156:
1.35 albertel 2157: my @to =
1.37 raeburn 2158: &Apache::loncommon::get_env_multiple('form.selectedusers_forminput');
1.25 foxr 2159: my $mode = $env{'form.sendmode'};
2160:
1.13 albertel 2161: my %toaddr;
1.35 albertel 2162: if (@to) {
2163: foreach my $dest (@to) {
1.27 albertel 2164: my ($user,$domain) = split(/:/, $dest);
1.25 foxr 2165: if (($user ne '') && ($domain ne '')) {
2166: my $address = $user.":".$domain; # How the code below expects it.
2167: $toaddr{$address} = '';
2168: }
2169: }
2170: }
2171:
1.1 albertel 2172: if ($env{'form.sendmode'} eq 'group') {
1.25 foxr 2173: foreach my $address (keys(%env)) {
2174: if ($address=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
2175: $toaddr{$1}='';
2176: }
1.1 albertel 2177: }
2178: } elsif ($env{'form.sendmode'} eq 'upload') {
1.13 albertel 2179: foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
1.43 raeburn 2180: my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/);
1.1 albertel 2181: if ($txt) {
1.43 raeburn 2182: $rec =~ s/^\s+//;
1.44 raeburn 2183: $rec =~ s/\s+$//;
1.1 albertel 2184: $toaddr{$rec}.=$txt."\n";
2185: }
2186: }
2187: } else {
1.25 foxr 2188: if (($env{'form.recuname'} ne '') && ($env{'form.recdomain'} ne '')) {
2189: $toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
2190: }
1.1 albertel 2191: }
2192: if ($env{'form.additionalrec'}) {
1.42 raeburn 2193: foreach my $rec (split(/\,/,$env{'form.additionalrec'})) {
1.43 raeburn 2194: my ($auname,$audom)=split(/:/,$rec);
1.25 foxr 2195: if (($auname ne "") && ($audom ne "")) {
2196: $toaddr{$auname.':'.$audom}='';
2197: }
1.1 albertel 2198: }
2199: }
2200:
2201: my $savemsg;
2202: my $msgtype;
2203: my %sentmessage;
1.7 albertel 2204: my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'},
2205: undef,1);
1.1 albertel 2206: if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
2207: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
2208: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
2209: '/'.$env{'request.course.sec'})
2210: )) {
2211: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
2212: $msgtype = 'critical';
2213: } else {
2214: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2215: }
2216:
1.13 albertel 2217: foreach my $address (sort(keys(%toaddr))) {
2218: my ($recuname,$recdomain)=split(/\:/,$address);
1.1 albertel 2219: my $msgtxt = $savemsg;
1.13 albertel 2220: if ($toaddr{$address}) { $msgtxt.='<hr />'.$toaddr{$address}; }
1.12 albertel 2221: my @thismsg;
1.1 albertel 2222: if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
2223: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
2224: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
2225: '/'.$env{'request.course.sec'}))) {
1.13 albertel 2226: $r->print(&mt('Sending critical message').' '.$recuname.':'.$recdomain.': ');
2227: @thismsg=
2228: &Apache::lonmsg::user_crit_msg($recuname,$recdomain,
2229: $msgsubj,$msgtxt,
2230: $env{'form.sendbck'},
2231: $env{'form.permanent'},
2232: \$sentmessage{$address});
1.1 albertel 2233: } else {
1.14 albertel 2234: $r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': ');
1.13 albertel 2235: @thismsg=
2236: &Apache::lonmsg::user_normal_msg($recuname,$recdomain,
2237: $msgsubj,$msgtxt,
2238: $content{'citation'},
2239: undef,undef,
2240: $env{'form.permanent'},
2241: \$sentmessage{$address});
1.1 albertel 2242: }
2243: if (($env{'request.course.id'}) && (($msgtype eq 'critical') ||
2244: ($env{'form.sendmode'} eq 'group'))) {
1.12 albertel 2245: $specialmsg_status{$recuname.':'.$recdomain} =
2246: join(' ',@thismsg);
2247: foreach my $result (@thismsg) {
2248: if ($result eq 'ok') {
2249: $numspecial++;
2250: }
2251: }
1.1 albertel 2252: }
1.12 albertel 2253: $sendstatus.=' '.join(' ',@thismsg);
1.1 albertel 2254: }
2255: if (($env{'request.course.id'}) && (($env{'form.sendmode'} eq 'group')
2256: || ($msgtype eq 'critical'))) {
2257: my $subj_prefix;
2258: if ($msgtype eq 'critical') {
2259: $subj_prefix = 'Critical.';
2260: } else {
2261: $subj_prefix = 'Broadcast.';
2262: }
2263: my ($specialmsgid,$specialresult);
1.29 www 2264: my $course_str = &escape('['.$cnum.':'.$cdom.']');
1.1 albertel 2265:
2266: if ($numspecial) {
2267: $specialresult = &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
2268: ' '.$course_str,$savemsg,undef,undef,undef,
2269: undef,undef,\$specialmsgid);
1.29 www 2270: $specialmsgid = &unescape($specialmsgid);
1.1 albertel 2271: }
2272: if ($specialresult eq 'ok') {
2273: my $record_sent;
1.13 albertel 2274: my @recusers;
2275: my @recudoms;
2276: my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
1.29 www 2277: split(/\:/,&unescape($specialmsgid));
1.13 albertel 2278:
1.1 albertel 2279: foreach my $recipient (sort(keys(%toaddr))) {
2280: if ($specialmsg_status{$recipient} eq 'ok') {
2281: my $usersubj = $subj_prefix.'['.$recipient.']';
2282: my $usermsgid =
2283: &Apache::lonmsg::buildmsgid($stamp,$usersubj,
2284: $msgname,$msgdom,
2285: $msgcount,$context,
2286: $pid);
2287: &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,$subj_prefix.
2288: ' ['.$recipient.']',$msgsubj,undef,
2289: undef,undef,undef,$usermsgid,undef,undef,$specialmsgid);
1.13 albertel 2290: my ($uname,$udom) = split(/:/,$recipient);
1.1 albertel 2291: push(@recusers,$uname);
2292: push(@recudoms,$udom);
2293: }
2294: }
2295: if (@recusers) {
2296: my $specialmessage;
1.13 albertel 2297: my $sentsubj =
2298: $subj_prefix.' ('.$numspecial.' sent) '.$msgsubj;
1.1 albertel 2299: $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
2300: my $sentmsgid =
2301: &Apache::lonmsg::buildmsgid($stamp,$sentsubj,$msgname,
2302: $msgdom,$msgcount,$context,
2303: $pid);
2304: ($specialmsgid,$specialmessage) = &Apache::lonmsg::packagemsg($msgsubj,$savemsg,
2305: undef,undef,undef,\@recusers,\@recudoms,$sentmsgid);
2306: $record_sent = &Apache::lonmsg::store_sent_mail($specialmsgid,$specialmessage);
2307: }
2308: } else {
2309: &Apache::lonnet::logthis('Failed to create record of critical message or broadcast in '.$env{'course.'.$env{'request.course.id'}.'.num'}.' at '.$env{'course.'.$env{'request.course.id'}.'.domain'}.' - no msgid generated');
2310: }
2311: }
2312: } else {
2313: &printheader($r,'','No messages sent.');
2314: }
1.53 raeburn 2315: if (!$env{'form.multiforward'}) {
2316: if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
2317: $r->print('<br /><span class="LC_success">'.&mt('Completed.').
2318: '</span>');
2319: if ($env{'form.displayedcrit'}) {
2320: &discrit($r);
2321: }
2322: if ($group ne '') {
2323: $r->print(&groupmail_sent($group,$cdom,$cnum));
2324: } else {
2325: &Apache::loncommunicate::menu($r);
2326: }
2327: } else {
2328: $r->print('<p><span class="LC_error">'.&mt('Could not deliver message').'</span> '.
2329: &mt('Please use the browser "Back" button and correct the recipient addresses '."($sendstatus)").'</p>');
1.38 raeburn 2330: }
1.1 albertel 2331: }
1.53 raeburn 2332: return $sendstatus;
1.1 albertel 2333: }
2334:
2335: # ===================================================================== Handler
2336:
2337: sub handler {
2338: my $r=shift;
2339:
2340: # ----------------------------------------------------------- Set document type
2341:
2342: &Apache::loncommon::content_type($r,'text/html');
2343: $r->send_http_header;
2344:
2345: return OK if $r->header_only;
2346:
2347: # --------------------------- Get query string for limited number of parameters
2348: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2349: ['display','replyto','forward','markread','markdel','markunread',
2350: 'sendreply','compose','sendmail','critical','recname','recdom',
2351: 'recordftf','sortedby','block','folder','startdis','interdis',
1.53 raeburn 2352: 'showcommentbaseurl','dismode','group','subject','text','ref',
2353: 'msgstatus']);
1.1 albertel 2354: $sqs='&sortedby='.$env{'form.sortedby'};
2355:
2356: # ------------------------------------------------------ They checked for email
2357: unless ($env{'form.block'}) {
2358: &Apache::lonnet::put('email_status',{'recnewemail'=>0});
2359: }
2360:
2361: # ----------------------------------------------------------------- Breadcrumbs
2362:
2363: &Apache::lonhtmlcommon::clear_breadcrumbs();
2364: &Apache::lonhtmlcommon::add_breadcrumb
2365: ({href=>"/adm/communicate",
2366: text=>"Communication/Messages",
2367: faq=>12,bug=>'Communication Tools',});
2368:
2369: # ------------------------------------------------------------------ Get Folder
2370:
2371: my $folder=$env{'form.folder'};
2372: unless ($folder) {
2373: $folder='';
2374: } else {
1.29 www 2375: $sqs.='&folder='.&escape($folder);
1.1 albertel 2376: }
2377: # ------------------------------------------------------------ Get Display Mode
2378:
2379: my $dismode=$env{'form.dismode'};
2380: unless ($dismode) {
2381: $dismode='';
2382: } else {
1.48 albertel 2383: $sqs.='&dismode='.&escape($dismode);
1.1 albertel 2384: }
2385:
2386: # --------------------------------------------------------------------- Display
1.53 raeburn 2387: my $msgstatus = $env{'form.msgstatus'};
1.1 albertel 2388: $startdis=$env{'form.startdis'};
1.53 raeburn 2389: if ($startdis ne '') {
2390: $startdis--;
2391: }
1.1 albertel 2392: unless ($startdis) { $startdis=0; }
2393:
2394: $interdis=$env{'form.interdis'};
2395: unless ($interdis) { $interdis=20; }
2396: $sqs.='&interdis='.$interdis;
2397:
2398: if ($env{'form.firstview'}) {
2399: $startdis=0;
2400: }
2401: if ($env{'form.lastview'}) {
2402: $startdis=-1;
2403: }
2404: if ($env{'form.prevview'}) {
2405: $startdis--;
2406: }
2407: if ($env{'form.nextview'}) {
2408: $startdis++;
2409: }
2410: my $postedstartdis=$startdis+1;
2411: $sqs.='&startdis='.$postedstartdis;
2412:
2413: # --------------------------------------------------------------- Render Output
2414:
2415: if ($env{'form.display'}) {
1.53 raeburn 2416: &displaymessage($r,$env{'form.display'},$folder,$msgstatus);
1.1 albertel 2417: } elsif ($env{'form.replyto'}) {
2418: &compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode);
2419: } elsif ($env{'form.confirm'}) {
2420: &printheader($r,'','Confirmed Receipt');
1.36 albertel 2421: my $replying = 0;
1.42 raeburn 2422: foreach my $envkey (keys(%env)) {
2423: if ($envkey=~/^form\.rec\_(.*)$/) {
1.1 albertel 2424: $r->print('<b>'.&mt('Confirming Receipt').':</b> '.
2425: &Apache::lonmsg::user_crit_received($1).'<br>');
2426: }
1.42 raeburn 2427: if ($envkey=~/^form\.reprec\_(.*)$/) {
1.1 albertel 2428: my $msgid=$1;
2429: $r->print('<b>'.&mt('Confirming Receipt').':</b> '.
2430: &Apache::lonmsg::user_crit_received($msgid).'<br>');
2431: &compout($r,'','','',$msgid);
1.36 albertel 2432: $replying = 1;
1.1 albertel 2433: }
2434: }
1.36 albertel 2435: if (!$replying) {
2436: &discrit($r);
2437: }
1.1 albertel 2438: } elsif ($env{'form.critical'}) {
2439: &printheader($r,'','Displaying Critical Messages');
2440: &discrit($r);
2441: } elsif ($env{'form.forward'}) {
2442: &compout($r,$env{'form.forward'},undef,undef,undef,$folder);
2443: } elsif ($env{'form.markdel'}) {
2444: &printheader($r,'','Deleted Message');
1.9 albertel 2445: my ($result,$msg) =
2446: &statuschange($env{'form.markdel'},'deleted',$folder);
2447: if (!$result) {
1.10 albertel 2448: $r->print('<p class="LC_error">'.
2449: &mt('Failed to delete the message.').'</p>'.
1.9 albertel 2450: '<p class="LC_error">'.$msg."</p>\n");
2451: }
1.1 albertel 2452: &Apache::loncommunicate::menu($r);
1.53 raeburn 2453: &disall($r,($folder?$folder:$dismode),$msgstatus);
2454: } elsif ($env{'form.markedaction'} eq 'markedforward') {
2455: my $total = 0;
2456: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
2457: foreach my $msgid (@to_forward) {
2458: &statuschange(&unescape($msgid),'forwarded',$folder);
2459: $total ++;
2460: }
2461: if ($total > 0) {
2462: &compout($r,undef,undef,undef,undef,$folder,$dismode,$total);
2463: }
2464: } elsif ($env{'form.markedaction'} eq 'markedread') {
2465: my $total = 0;
2466: my @to_markread = &Apache::loncommon::get_env_multiple('form.delmark');
2467: foreach my $msgid (@to_markread) {
2468: &statuschange(&unescape($msgid),'read',$folder);
2469: $total ++;
2470: }
2471: &printheader($r,'','Marked Messages Read');
2472: $r->print(&mt('Marked [_1] message(s) read',$total).'<p>');
2473: &Apache::loncommunicate::menu($r);
2474: &disall($r,($folder?$folder:$dismode),$msgstatus);
2475: } elsif ($env{'form.markedaction'} eq 'markedunread') {
2476: my $total = 0;
2477: my @to_markunread = &Apache::loncommon::get_env_multiple('form.delmark');
2478: foreach my $msgid (@to_markunread) {
2479: &statuschange(&unescape($msgid),'new',$folder);
2480: $total ++;
2481: }
2482: &printheader($r,'','Marked Messages Unread');
2483: $r->print(&mt('Marked [_1] message(s) unread',$total).'<p>');
2484: &Apache::loncommunicate::menu($r);
2485: &disall($r,($folder?$folder:$dismode),$msgstatus);
2486: } elsif ($env{'form.markedaction'} eq 'markedmove') {
2487: my $destfolder = $env{'form.movetofolder'};
2488: my %gotfolders = &Apache::lonmsg::get_user_folders();
2489: &printheader($r,'','Moved Messages');
2490: if (!defined($gotfolders{$destfolder})) {
2491: $r->print(&mt('Destination folder [_1] is not a valid folder',
2492: $destfolder));
2493: } else {
2494: my ($total,$failed,@failed_msg)=(0,0);
2495: my @to_move = &Apache::loncommon::get_env_multiple('form.delmark');
2496: foreach my $msgid (@to_move) {
2497: my ($result,$msg) = &movemsg(&unescape($msgid),$folder,
2498: $env{'form.movetofolder'});
2499: if ($result) {
1.9 albertel 2500: $total++;
1.53 raeburn 2501: } else {
1.9 albertel 2502: $failed++;
2503: push(@failed_msg,$msg);
1.53 raeburn 2504: }
1.1 albertel 2505: }
1.53 raeburn 2506: if ($failed) {
2507: $r->print('<p class="LC_error">
1.10 albertel 2508: '.&mt('Failed to move [_1] message(s)',$failed).
2509: '</p>');
1.53 raeburn 2510: $r->print('<p class="LC_error">'.
2511: join("</p>\n<p class=\"LC_error\">",@failed_msg).
2512: "</p>\n");
2513: }
2514: $r->print(&mt('Moved [_1] message(s)',$total).'<p>');
2515: }
1.1 albertel 2516: &Apache::loncommunicate::menu($r);
1.53 raeburn 2517: &disall($r,($folder?$folder:$dismode),$msgstatus);
2518: } elsif ($env{'form.markedaction'} eq 'markeddel') {
1.9 albertel 2519: my ($total,$failed,@failed_msg)=(0,0);
1.53 raeburn 2520: my @to_delete = &Apache::loncommon::get_env_multiple('form.delmark');
2521: foreach my $msgid (@to_delete) {
2522: my ($result,$msg) = &statuschange(&unescape($msgid),'deleted',
2523: $folder);
2524: if ($result) {
2525: $total++;
2526: } else {
2527: $failed++;
2528: push(@failed_msg,$msg);
1.1 albertel 2529: }
2530: }
2531: &printheader($r,'','Deleted Messages');
1.9 albertel 2532: if ($failed) {
2533: $r->print('<p class="LC_error">
1.10 albertel 2534: '.&mt('Failed to delete [_1] message(s)',$failed).
2535: '</p>');
1.9 albertel 2536: $r->print('<p class="LC_error">'.
2537: join("</p>\n<p class=\"LC_error\">",@failed_msg).
2538: "</p>\n");
2539: }
1.10 albertel 2540: $r->print(&mt('Deleted [_1] message(s)',$total).'<p>');
1.1 albertel 2541: &Apache::loncommunicate::menu($r);
1.53 raeburn 2542: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 2543: } elsif ($env{'form.markunread'}) {
2544: &printheader($r,'','Marked Message as Unread');
2545: &statuschange($env{'form.markunread'},'new');
2546: &Apache::loncommunicate::menu($r);
1.53 raeburn 2547: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 2548: } elsif ($env{'form.compose'}) {
2549: &compout($r,'','',$env{'form.compose'});
2550: } elsif ($env{'form.recordftf'}) {
2551: &facetoface($r,$env{'form.recordftf'});
2552: } elsif ($env{'form.block'}) {
2553: &examblock($r,$env{'form.block'});
2554: } elsif ($env{'form.sendmail'}) {
1.53 raeburn 2555: if ($env{'form.multiforward'}) {
2556: &printheader($r,'','Messages being sent.');
2557: my $fixed_subj = $env{'form.subject'};
2558: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2559: my (%sendresult,%forwardok,%forwardfail,$fwdcount);
2560: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
2561: foreach my $item (@to_forward) {
2562: my $msgid=&unescape($item);
2563: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2564: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2565: if ($env{'form.showorigsubj'}) {
2566: $env{'form.subject'} = $fixed_subj.$content{'subject'};
2567: } else {
2568: $env{'form.subject'} = '';
2569: }
2570: my $uname = $content{'sendername'};
2571: my $udom = $content{'senderdomain'};
2572: &statuschange($msgid,'forwarded',$folder);
2573: if ($env{'form.showorigsender'}) {
2574: $env{'form.message'} = $env{'form.msgheader'}.' '.
2575: &Apache::loncommon::plainname($uname,$udom).' ('.
2576: $uname.':'.$udom.')';
2577: }
2578: $env{'form.message'} .= "\n\n-- Forwarded message --\n\n".
2579: $content{'message'};
2580: $fwdcount ++;
2581: $r->print($fwdcount.': ');
2582: $sendresult{$msgid} = &sendoffmail($r,$folder);
2583: $r->print('<br />');
2584: }
2585: foreach my $key (keys(%sendresult)) {
2586: if ($sendresult{$key} =~/^(\s*(?:ok|con_delayed)\s*)*$/) {
2587: $forwardok{$key} = $sendresult{$key};
2588: } else {
2589: $forwardfail{$key} = $sendresult{$key};
2590: }
2591: }
2592: if (keys(%forwardok) > 0) {
2593: my $count = keys(%forwardok);
2594: $r->print('<br /><span class="LC_success">'.
2595: &mt('[quant,_1,message] forwarded.',$count).
2596: '</span>');
2597: }
2598: if (keys(%forwardfail) > 0) {
2599: my $count = keys(%forwardfail);
2600: $r->print('<p><span class="LC_error">'.
2601: &mt('Could not forward [quant,_1,message].',$count).
2602: '</span> ');
2603: foreach my $key (keys(%forwardfail)) {
2604: $r->print(&mt('Could not deliver forwarded message.').'</span> '.
2605: &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.').<br /><br />');
2606: }
2607: }
2608: &Apache::loncommunicate::menu($r);
2609: } else {
2610: &sendoffmail($r,$folder);
2611: }
1.1 albertel 2612: if ($env{'form.storebasecomment'}) {
2613: &storecomment($r);
1.38 raeburn 2614: }
1.1 albertel 2615: if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
1.38 raeburn 2616: &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
1.1 albertel 2617: $env{'course.'.$env{'request.course.id'}.'.domain'},
2618: 'Course_Announcements',
2619: $env{'form.subject'},
2620: $env{'form.message'},'/adm/communicate','public');
2621: }
1.38 raeburn 2622: if ((!exists($env{'form.group'})) && (!$env{'form.displayedcrit'})) {
1.53 raeburn 2623: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.36 albertel 2624: }
1.1 albertel 2625: } elsif ($env{'form.newfolder'}) {
2626: &printheader($r,'','New Folder');
1.46 raeburn 2627: my $showfolder = $env{'form.newfolder'};
2628: my ($makeresult,$warning) = &makefolder($env{'form.newfolder'});
2629: if ($makeresult eq 'ok') {
2630: $r->print(&mt('Mail folder "[_1]" created.',$showfolder).'<br />');
2631: } else {
2632: $r->print(&mt('Creation failed.').' '.$makeresult.'<br />'.
2633: $warning);
2634: $showfolder = $folder;
2635: }
2636: &Apache::loncommunicate::menu($r);
1.53 raeburn 2637: &disall($r,$showfolder,$msgstatus);
1.1 albertel 2638: } elsif ($env{'form.showcommentbaseurl'}) {
2639: &storedcommentlisting($r);
1.46 raeburn 2640: } elsif ($env{'form.folderaction'} eq 'delete') {
2641: &printheader($r,'','Deleted Folder');
2642: my $showfolder = '';
2643: my $delresult = &deletefolder($folder);
2644: if ($delresult eq 'ok') {
2645: $r->print(&mt('Mail folder "[_1]" deleted.',$folder).'<br />');
2646: } else {
2647: $r->print(&mt('Deletion failed.').' '.$delresult.'<br />');
2648: $showfolder = $folder;
2649: }
2650: &Apache::loncommunicate::menu($r);
1.53 raeburn 2651: &disall($r,$showfolder,$msgstatus);
1.46 raeburn 2652: } elsif ($env{'form.folderaction'} eq 'rename') {
2653: &printheader($r,'','Renamed Folder');
2654: my $showfolder = $env{'form.renamed'};
2655: my $renresult = &renamefolder($folder);
2656: if ($renresult eq 'ok') {
2657: $r->print(&mt('Mail folder "[_1]" renamed "[_2]".',$folder,$showfolder).'<br />');
2658: } else {
2659: $r->print(&mt('Renaming failed.').' '.$renresult.'<br />');
2660: $showfolder = $folder;
2661: }
2662: &Apache::loncommunicate::menu($r);
1.53 raeburn 2663: &disall($r,$showfolder,$msgstatus);
1.1 albertel 2664: } else {
2665: &printheader($r,'','Display All Messages');
1.44 raeburn 2666: &Apache::loncommunicate::menu($r);
1.53 raeburn 2667: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 2668: }
2669: $r->print(&Apache::loncommon::end_page());
2670: return OK;
2671: }
2672: # ================================================= Main program, reset counter
2673:
2674: =pod
2675:
2676: =back
2677:
2678: =cut
2679:
2680: 1;
2681:
2682: __END__
2683:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>