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