Annotation of loncom/interface/lonmsgdisplay.pm, revision 1.71
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # Routines for messaging display
3: #
1.71 ! raeburn 4: # $Id: lonmsgdisplay.pm,v 1.70 2007/04/22 13:41:22 raeburn Exp $
1.1 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29:
30: package Apache::lonmsgdisplay;
31:
32: =pod
33:
34: =head1 NAME
35:
1.69 raeburn 36: Apache::lonmsgdisplay: supports internal messaging
1.1 albertel 37:
38: =head1 SYNOPSIS
39:
1.69 raeburn 40: lonmsgdisplay provides a handler to allow users to read, send,
41: and delete messages, and to create and delete message folders,
42: and to move messages between folders.
1.1 albertel 43:
44: =head1 OVERVIEW
45:
46: =head2 Messaging Overview
47:
48: X<messages>LON-CAPA provides an internal messaging system similar to
49: email, but customized for LON-CAPA's usage. LON-CAPA implements its
50: own messaging system, rather then building on top of email, because of
51: the features LON-CAPA messages can offer that conventional e-mail can
52: not:
53:
54: =over 4
55:
56: =item * B<Critical messages>: A message the recipient B<must>
57: acknowlegde receipt of before they are allowed to continue using the
58: system, preventing a user from claiming they never got a message
59:
60: =item * B<Receipts>: LON-CAPA can reliably send reciepts informing the
61: sender that it has been read; again, useful for preventing students
62: from claiming they did not see a message. (While conventional e-mail
63: has some reciept support, it's sporadic, e-mail client-specific, and
64: generally the receiver can opt to not send one, making it useless in
65: this case.)
66:
67: =item * B<Context>: LON-CAPA knows about the sender, such as where
68: they are in a course. When a student mails an instructor asking for
69: help on the problem, the instructor receives not just the student's
70: question, but all submissions the student has made up to that point,
71: the user's rendering of the problem, and the complete view the student
72: saw of the resource, including discussion up to that point. Finally,
73: the instructor is reading all of this inside of LON-CAPA, not their
74: email program, so they have full access to LON-CAPA's grading
75: interface, or other features they may wish to use in response to the
76: student's query.
77:
1.50 raeburn 78: =item * B<Blocking>: LON-CAPA can block selected communication
79: features for students during an online exam. A course coordinator or
1.1 albertel 80: instructor can set an open and close date/time for scheduled online
81: exams in a course. If a user uses the LON-CAPA internal messaging
82: system to display e-mails during the scheduled blocking event,
83: display of all e-mail sent during the blocking period will be
84: suppressed, and a message of explanation, including details of the
85: currently active blocking periods will be displayed instead. A user
86: who has a course coordinator or instructor role in a course will be
87: unaffected by any blocking periods for the course, unless the user
88: also has a student role in the course, AND has selected the student role.
89:
90: =back
91:
92: Users can ask LON-CAPA to forward messages to conventional e-mail
93: addresses on their B<PREF> screen, but generally, LON-CAPA messages
94: are much more useful than traditional email can be made to be, even
95: with HTML support.
96:
97: =cut
98:
99: use strict;
100: use Apache::lonnet;
101: use HTML::TokeParser();
102: use Apache::Constants qw(:common);
103: use Apache::loncommon();
1.67 www 104: use Apache::lonhtmlcommon();
1.1 albertel 105: use Apache::lontexconvert();
106: use HTML::Entities();
107: use Apache::lonlocal;
108: use Apache::loncommunicate;
109: use Apache::lonfeedback;
110: use Apache::lonrss();
1.27 albertel 111: use Apache::lonselstudent();
1.29 www 112: use lib '/home/httpd/lib/perl/';
113: use LONCAPA;
1.1 albertel 114:
115: # Querystring component with sorting type
116: my $sqs;
117: my $startdis;
118:
119: # ============================================================ List all folders
120:
121: sub folderlist {
1.53 raeburn 122: my ($folder,$msgstatus) = @_;
1.46 raeburn 123: my %lt = &Apache::lonlocal::texthash(
124: actn => 'Action',
125: fold => 'Folder',
126: show => 'Show',
1.53 raeburn 127: status => 'Message Status',
1.46 raeburn 128: go => 'Go',
1.50 raeburn 129: nnff => 'New Name for Folder',
130: newn => 'New Name',
131: thfm => 'The folder may not be renamed',
132: fmnb => 'folder may not be renamed as it is a folder provided by the system.',
133: asth => 'as this name is already in use for a system-provided or user-defined folder.',
134: the => 'The',
135: tnfm => 'The new folder may not be named',
136:
1.46 raeburn 137: );
138:
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');
1.70 raeburn 1189: if ($multiforward > 1) {
1190: $r->print(&mt('Each of the <b>[quant,_1,message]</b> you checked
1191: will be forwarded to the recipient(s) you select below.',$multiforward).'<br />');
1192: } else {
1193: $r->print(&mt('The message you checked will be forwarded to the recipient(s) you select below.').'<br />');
1194: }
1195:
1.1 albertel 1196: } else {
1197: &printheader($r,'/adm/email?compose=upload',
1198: 'Distribute from Uploaded File');
1199: }
1200:
1201: my $dispcrit='';
1202: my $dissub='';
1203: my $dismsg='';
1204: my $disbase='';
1205: my $func=&mt('Send New');
1.50 raeburn 1206: my %lt=&Apache::lonlocal::texthash('us' => 'Username',
1207: 'do' => 'Domain',
1208: 'ad' => 'Additional Recipients',
1209: 'sb' => 'Subject',
1210: 'ca' => 'Cancel',
1211: 'ma' => 'Mail',
1.53 raeburn 1212: 'msg' => 'Messages',
1.50 raeburn 1213: 'gen' => 'Generate messages from a file',
1214: 'gmt' => 'General message text',
1215: 'tff' => 'The file format for the uploaded portion of the message is',
1216: 'uas' => 'Upload and Send',
1217: );
1.1 albertel 1218: if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
1219: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
1220: '/'.$env{'request.course.sec'})) {
1221: my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message");
1222: $dispcrit=
1223: '<p><label><input type="checkbox" name="critmsg" /> '.&mt('Send as critical message').'</label> ' . $crithelp .
1224: '</p><p>'.
1225: '<label><input type="checkbox" name="sendbck" /> '.&mt('Send as critical message').' ' .
1226: &mt('and return receipt') . '</label>' . $crithelp .
1227: '</p><p><label><input type="checkbox" name="permanent" /> '.
1228: &mt('Send copy to permanent email address (if known)').'</label></p>'.
1229: '<p><label><input type="checkbox" name="rsspost" /> '.
1230: &mt('Include in course RSS newsfeed').'</label></p>';
1.70 raeburn 1231: }
1.71 ! raeburn 1232: if ($broadcast ne 'group') {
! 1233: if (&Apache::lonnet::allowed('dff',$env{'request.course.id'}) ||
! 1234: &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
! 1235: '/'.$env{'request.course.sec'})) {
! 1236:
! 1237: $dispcrit.='<p><label>'.
! 1238: '<input type="checkbox" name="courserecord" value="1" /> '.
! 1239: &mt("Include in course's 'User records' for recipient(s)").
! 1240: '</label></p>';
! 1241: }
1.70 raeburn 1242: }
1243:
1.1 albertel 1244: my %message;
1245: my %content;
1246: my $defdom=$env{'user.domain'};
1247: if ($forwarding) {
1248: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$forwarding]);
1249: %content=&Apache::lonmsg::unpackagemsg($message{$forwarding},$folder);
1250: $dispcrit.='<input type="hidden" name="forwid" value="'.
1251: $forwarding.'" />';
1252: $func=&mt('Forward');
1253:
1254: $dissub=&mt('Forwarding').': '.$content{'subject'};
1255: $dismsg=&mt('Forwarded message from').' '.
1256: $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'};
1257: if ($content{'baseurl'}) {
1.29 www 1258: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1 albertel 1259: }
1260: }
1261: if ($replying) {
1262: %message=&Apache::lonnet::get('nohist_email'.$suffix,[$replying]);
1263: %content=&Apache::lonmsg::unpackagemsg($message{$replying},$folder);
1264: $dispcrit.='<input type="hidden" name="replyid" value="'.
1265: $replying.'" />';
1266: $func=&mt('Send Reply to');
1267:
1268: $dissub=&mt('Reply').': '.$content{'subject'};
1269: $dismsg='> '.$content{'message'};
1270: $dismsg=~s/\r/\n/g;
1271: $dismsg=~s/\f/\n/g;
1272: $dismsg=~s/\n+/\n\> /g;
1273: if ($content{'baseurl'}) {
1.29 www 1274: $disbase='<input type="hidden" name="baseurl" value="'.&escape($content{'baseurl'}).'" />';
1.1 albertel 1275: if ($env{'user.adv'}) {
1276: $disbase.='<label><input type="checkbox" name="storebasecomment" />'.&mt('Store message for re-use').
1277: '</label> <a href="/adm/email?showcommentbaseurl='.
1.29 www 1278: &escape($content{'baseurl'}).'" target="comments">'.
1.1 albertel 1279: &mt('Show re-usable messages').'</a><br />';
1280: }
1281: }
1282: }
1283: my $citation=&displayresource(%content);
1.38 raeburn 1284: my ($can_grp_broadcast,$viewgrps,$editgrps);
1.1 albertel 1285: if ($env{'form.recdom'}) { $defdom=$env{'form.recdom'}; }
1.23 www 1286: if ($env{'form.text'}) { $dismsg=$env{'form.text'}; }
1287: if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; }
1288: $r->print(
1.1 albertel 1289: '<form action="/adm/email" name="compemail" method="post"'.
1290: ' enctype="multipart/form-data">'."\n".
1.38 raeburn 1291: '<input type="hidden" name="sendmail" value="on" />'."\n");
1292: if ($broadcast eq 'group' && $env{'form.group'} ne '') {
1293: $can_grp_broadcast =
1294: &Apache::lonnet::allowed('sgb',$env{'request.course.id'}.'/'.
1295: $group);
1296: $viewgrps =
1297: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.
1298: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1299: $editgrps =
1300: &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
1301: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1302: if ($viewgrps || $editgrps || $can_grp_broadcast) {
1303: $r->print(&disgroup($cdom,$cnum,$group,$viewgrps,$editgrps));
1304: }
1305: }
1306: $r->print('<table>');
1307: if (($broadcast eq 'group') && ($group ne '') &&
1308: (!$can_grp_broadcast && !$viewgrps && !$editgrps)) {
1309: $r->print(&recipient_input_row($cdom,%lt));
1310: }
1311: if (($broadcast ne 'group') && ($broadcast ne 'upload')) {
1.1 albertel 1312: if ($replying) {
1313: $r->print('<tr><td colspan="2">'.&mt('Replying to').' '.
1314: &Apache::loncommon::aboutmewrapper(
1315: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('.
1.14 albertel 1316: $content{'sendername'}.':'.
1.1 albertel 1317: $content{'senderdomain'}.')'.
1318: '<input type="hidden" name="recuname" value="'.$content{'sendername'}.'" />'.
1319: '<input type="hidden" name="recdomain" value="'.$content{'senderdomain'}.'" />'.
1320: '</td></tr>');
1321: } else {
1.38 raeburn 1322: $r->print(&recipient_input_row($defdom,%lt));
1.1 albertel 1323: }
1324: }
1325: my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
1.53 raeburn 1326: my $subj_size;
1327: if ($multiforward) {
1328: $r->print(&additional_rec_row(\%lt));
1329: $r->print('<tr><td colspan="2">'.
1330: &mt('Unless you choose otherwise:').'<ul><li>'.
1331: &mt("The subject in each forwarded message will be <i>'Forwarding:'</i> followed by the original subject.").'</li><li>'.
1332: &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>');
1333: $func=&mt('Forward');
1334: $dissub = &mt('Forwarding').': ';
1335: $subj_size = '10';
1336: my $extra = '<'.&mt('original subject').'> '.
1337: '<input type="radio" name="showorigsubj" value="1" checked="checked" />'.&mt('Yes').' <input type="radio" name="showorigsubj" value="0" />'.&mt('No');
1338: $dismsg = &mt('Forwarded message from ').' ';
1339: my $sender = &mt("sender's name");
1340: $r->print(&msg_subject_row($dissub,\%lt,$subj_size,$extra));
1341: $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>
1342: </table>
1343: <br />'.
1344: $latexHelp.
1345: &mt("Any new text to display before the text of the original messages:").'<br />
1346: <textarea name="message" id="message" cols="80" rows="5" wrap="hard">
1347: </textarea></p><br />');
1348: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
1349: foreach my $msg (@to_forward) {
1350: $r->print('<input type="hidden" name="delmark" value="'.$msg.'" />');
1351: }
1352: $r->print(&submit_button_row($folder,$dismode,$func.' '.$lt{'msg'},
1353: \%lt));
1354: } elsif ($broadcast ne 'upload') {
1355: $subj_size = '50';
1356: $r->print(&additional_rec_row(\%lt));
1357: $r->print(&msg_subject_row($dissub,\%lt,$subj_size));
1358: $r->print(<<"ENDCOMP");
1359: </table>
1.1 albertel 1360: $latexHelp
1361: <textarea name="message" id="message" cols="80" rows="15" wrap="hard">$dismsg
1362: </textarea></p><br />
1363: $dispcrit
1364: $disbase
1365: ENDCOMP
1.53 raeburn 1366: $r->print(&submit_button_row($folder,$dismode,$func.' '.$lt{'ma'},
1367: \%lt));
1368: $r->print($citation);
1.38 raeburn 1369: if (exists($env{'form.ref'})) {
1370: $r->print('<input type="hidden" name="ref" value="'.
1371: $env{'form.ref'}.'" />');
1372: }
1373: if (exists($env{'form.group'})) {
1374: $r->print('<input type="hidden" name="group" value="'.
1375: $env{'form.group'}.'" />');
1376: }
1.1 albertel 1377: } else { # $broadcast is 'upload'
1.50 raeburn 1378: $r->print(<<ENDBLOCK);
1.1 albertel 1379: <input type="hidden" name="sendmode" value="upload" />
1380: <input type="hidden" name="send" value="on" />
1.50 raeburn 1381: <h3>$lt{'gen'}</h3>
1.1 albertel 1382: <p>
1383: Subject: <input type="text" size="50" name="subject" />
1384: </p>
1.50 raeburn 1385: <p>$lt{'gmt'}:<br />
1.1 albertel 1386: <textarea name="message" id="message" cols="60" rows="10" wrap="hard">$dismsg
1387: </textarea></p>
1388: <p>
1.50 raeburn 1389: $lt{'tff'}:
1390: ENDBLOCK
1391: $r->print('
1392: <pre>'."\n".
1393: &mt('username1:domain1: text')."\n".
1394: &mt('username2:domain2: text')."\n".
1395: &mt('username3:domain1: text')."\n".
1396: '</pre>
1.1 albertel 1397: </p>
1398: <p>
1.50 raeburn 1399: '.&mt('The messages will be assembled from all lines with the respective'."\n".'<tt>username:domain</tt>, and appended to the general message text.'));
1400: $r->print(<<ENDUPLOAD);
1401: </p>
1.1 albertel 1402: <p>
1403: <input type="file" name="upfile" size="40" /></p><p>
1404: $dispcrit
1.50 raeburn 1405: <input type="submit" value="$lt{'uas'}" /></p>
1.1 albertel 1406: ENDUPLOAD
1407: }
1408: if ($broadcast eq 'group') {
1.38 raeburn 1409: if ($group eq '') {
1410: my $studentsel = &discourse();
1411: $r->print($studentsel);
1412: }
1.1 albertel 1413: }
1.36 albertel 1414: if ($env{'form.displayedcrit'}) {
1415: $r->print('<input type="hidden" name="displayedcrit" value="true" />');
1416: }
1.1 albertel 1417: $r->print('</form>'.
1418: &Apache::lonfeedback::generate_preview_button('compemail','message').
1419: &Apache::lonhtmlcommon::htmlareaselectactive('message'));
1420: }
1421:
1422: # ---------------------------------------------------- Display all face to face
1423:
1.38 raeburn 1424: sub recipient_input_row {
1425: my ($dom,%lt) = @_;
1426: my $domform = &Apache::loncommon::select_dom_form($dom,'recdomain');
1427: my $selectlink=
1428: &Apache::loncommon::selectstudent_link('compemail','recuname',
1429: 'recdomain');
1430: my $output = <<"ENDREC";
1431: <tr><td>$lt{'us'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recname'}" /></td><td rowspan="2">$selectlink</td></tr>
1432: <tr><td>$lt{'do'}:</td>
1433: <td>$domform</td></tr>
1434: ENDREC
1435: return $output;
1436: }
1437:
1.53 raeburn 1438: sub additional_rec_row {
1439: my ($lt) = @_;
1440: my $output = <<"ENDADD";
1441: <tr><td>$lt->{'ad'}:<br /><tt>username:domain,username:domain, ...
1442: </tt></td><td>
1443: <input type="text" size="50" name="additionalrec" /></td></tr>
1444: ENDADD
1445: return $output;
1446: }
1447:
1448: sub submit_button_row {
1449: my ($folder,$dismode,$sendtext,$lt) = @_;
1450: my $output = qq|
1451: <input type="hidden" name="folder" value="$folder" />
1452: <input type="hidden" name="dismode" value="$dismode" />
1453: <input type="submit" name="send" value="$sendtext" />
1454: <input type="submit" name="cancel" value="$lt->{'ca'}" /><hr />
1455: |;
1456: return $output;
1457: }
1458:
1459: sub msg_subject_row {
1460: my ($dissub,$lt,$subj_size,$extra) = @_;
1461: my $output = '<tr><td>'.$lt->{'sb'}.':</td><td><input type="text" size="'.
1462: $subj_size.'" name="subject" value="'.$dissub.'" />'.$extra.
1463: '</td></tr>';
1464: return $output;
1465: }
1466:
1.1 albertel 1467: sub retrieve_instructor_comments {
1468: my ($user,$domain)=@_;
1469: my $target=$env{'form.grade_target'};
1470: if (! $env{'request.course.id'}) { return; }
1.49 albertel 1471: if (! &Apache::lonnet::allowed('dff',$env{'request.course.id'})
1472: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1473: '/'.$env{'request.course.sec'})) {
1474: return;
1475: }
1476: my %records=&Apache::lonnet::dump('nohist_email',
1477: $env{'course.'.$env{'request.course.id'}.'.domain'},
1478: $env{'course.'.$env{'request.course.id'}.'.num'},
1479: '%255b'.$user.'%253a'.$domain.'%255d');
1480: my $result='';
1.42 raeburn 1481: foreach my $key (sort(keys(%records))) {
1482: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1 albertel 1483: next if ($content{'senderdomain'} eq '');
1484: next if ($content{'subject'} !~ /^Record/);
1485: # &Apache::lonfeedback::newline_to_br(\$content{'message'});
1486: $result.='Recorded by '.
1.14 albertel 1487: $content{'sendername'}.':'.$content{'senderdomain'}."\n";
1.1 albertel 1488: $result.=
1489: &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
1490: }
1491: return $result;
1492: }
1493:
1494: sub disfacetoface {
1495: my ($r,$user,$domain)=@_;
1496: my $target=$env{'form.grade_target'};
1497: unless ($env{'request.course.id'}) { return; }
1.49 albertel 1498: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
1499: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1500: '/'.$env{'request.course.sec'})) {
1.50 raeburn 1501: $r->print(&mt('Not allowed'));
1.1 albertel 1502: return;
1503: }
1504: my %records=&Apache::lonnet::dump('nohist_email',
1505: $env{'course.'.$env{'request.course.id'}.'.domain'},
1506: $env{'course.'.$env{'request.course.id'}.'.num'},
1507: '%255b'.$user.'%253a'.$domain.'%255d');
1508: my $result='';
1.42 raeburn 1509: foreach my $key (sort(keys(%records))) {
1510: my %content=&Apache::lonmsg::unpackagemsg($records{$key});
1.1 albertel 1511: next if ($content{'senderdomain'} eq '');
1512: &Apache::lonfeedback::newline_to_br(\$content{'message'});
1513: if ($content{'subject'}=~/^Record/) {
1514: $result.='<h3>'.&mt('Record').'</h3>';
1515: } elsif ($content{'subject'}=~/^Broadcast/) {
1516: $result .='<h3>'.&mt('Broadcast Message').'</h3>';
1517: if ($content{'subject'}=~/^Broadcast\./) {
1518: if (defined($content{'coursemsgid'})) {
1.29 www 1519: my $crsmsgid = &escape($content{'coursemsgid'});
1.1 albertel 1520: my $broadcast_message = &general_message($crsmsgid);
1521: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$broadcast_message;
1522: } else {
1523: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1524: $content{'message'} =
1525: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1526: $content{'message'};
1527: }
1.70 raeburn 1528: }
1529: } elsif ($content{'subject'}=~/^Archive/) {
1530: $result.='<h3>'.&mt('Archived Message').'</h3>';
1531: if (defined($content{'coursemsgid'})) {
1532: my $crsmsgid = &escape($content{'coursemsgid'});
1533: my $archive_message = &general_message($crsmsgid);
1534: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$archive_message;
1535: } else {
1536: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1537: $content{'message'} =
1538: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br
1539: '.
1540: $content{'message'};
1541: }
1.1 albertel 1542: } else {
1543: $result.='<h3>'.&mt('Critical Message').'</h3>';
1544: if (defined($content{'coursemsgid'})) {
1.29 www 1545: my $crsmsgid=&escape($content{'coursemsgid'});
1.1 albertel 1546: my $critical_message = &general_message($crsmsgid);
1547: $content{'message'} = '<b>'.&mt('Subject').': '.$content{'message'}.'</b><br />'.$critical_message;
1548: } else {
1549: %content=&Apache::lonmsg::unpackagemsg($content{'message'});
1550: $content{'message'}=
1551: '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
1552: $content{'message'};
1553: }
1554: }
1555: $result.=&mt('By').': <b>'.
1556: &Apache::loncommon::aboutmewrapper(
1557: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).'</b> ('.
1.14 albertel 1558: $content{'sendername'}.':'.
1.1 albertel 1559: $content{'senderdomain'}.') '.$content{'time'}.
1560: '<br /><pre>'.
1561: &Apache::lontexconvert::msgtexconverted($content{'message'}).
1562: '</pre>';
1563: }
1564: # Check to see if there were any messages.
1565: if ($result eq '') {
1.33 albertel 1566: my $lctype = lc(&Apache::loncommon::course_type());
1.1 albertel 1567: if ($target ne 'tex') {
1.30 raeburn 1568: $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 1569: } else {
1.30 raeburn 1570: $r->print('\textbf{'.&mt('No notes, face-to-face discussion records, critical messages or broadcast messages in this [_1].',$lctype).'}\\\\');
1.1 albertel 1571: }
1572: } else {
1573: $r->print($result);
1574: }
1575: }
1576:
1577: sub general_message {
1578: my ($crsmsgid) = @_;
1579: my %general_content;
1580: if ($crsmsgid) {
1581: my %course_content = &Apache::lonnet::get('nohist_email',[$crsmsgid],
1582: $env{'course.'.$env{'request.course.id'}.'.domain'},
1583: $env{'course.'.$env{'request.course.id'}.'.num'});
1584: %general_content = &Apache::lonmsg::unpackagemsg($course_content{$crsmsgid});
1585: }
1586: return $general_content{'message'};
1587: }
1588:
1589: # ---------------------------------------------------------------- Face to face
1590:
1591: sub facetoface {
1592: my ($r,$stage)=@_;
1.49 albertel 1593: if (!&Apache::lonnet::allowed('dff',$env{'request.course.id'})
1594: && ! &Apache::lonnet::allowed('dff',$env{'request.course.id'}.
1.1 albertel 1595: '/'.$env{'request.course.sec'})) {
1.50 raeburn 1596: $r->print(&mt('Not allowed'));
1.1 albertel 1597: return;
1598: }
1.33 albertel 1599: my $crstype = &Apache::loncommon::course_type();
1600: my $leaders = ($crstype eq 'Group') ? 'coordinators and leaders'
1601: : 'faculty and staff';
1.1 albertel 1602: &printheader($r,
1603: '/adm/email?recordftf=query',
1.70 raeburn 1604: "User Notes, Face-to-Face, Critical Messages, Broadcast Messages, Archived Messages");
1.1 albertel 1605: # from query string
1606:
1607: if ($env{'form.recname'}) { $env{'form.recuname'}=$env{'form.recname'}; }
1608: if ($env{'form.recdom'}) { $env{'form.recdomain'}=$env{'form.recdom'}; }
1609:
1610: my $defdom=$env{'user.domain'};
1611: # already filled in
1612: if ($env{'form.recdomain'}) { $defdom=$env{'form.recdomain'}; }
1613: # generate output
1614: my $domform = &Apache::loncommon::select_dom_form($defdom,'recdomain');
1615: my $stdbrws = &Apache::loncommon::selectstudent_link
1616: ('stdselect','recuname','recdomain');
1617: my %lt=&Apache::lonlocal::texthash('user' => 'Username',
1618: 'dom' => 'Domain',
1.70 raeburn 1619: 'head' => "User Notes, Records of Face-To-Face Discussions, Critical Messages, Broadcast Messages and Archived Messages in $crstype",
1.1 albertel 1620: 'subm' => 'Retrieve discussion and message records',
1.30 raeburn 1621: 'newr' => 'New Record (record is visible to '.lc($crstype).' '.$leaders.')',
1.1 albertel 1622: 'post' => 'Post this Record');
1623: $r->print(<<"ENDTREC");
1624: <h3>$lt{'head'}</h3>
1625: <form method="post" action="/adm/email" name="stdselect">
1626: <input type="hidden" name="recordftf" value="retrieve" />
1627: <table>
1628: <tr><td>$lt{'user'}:</td><td><input type="text" size="12" name="recuname" value="$env{'form.recuname'}" /></td>
1629: <td rowspan="2">
1630: $stdbrws
1631: <input type="submit" value="$lt{'subm'}" /></td>
1632: </tr>
1633: <tr><td>$lt{'dom'}:</td>
1634: <td>$domform</td></tr>
1635: </table>
1636: </form>
1637: ENDTREC
1638: if (($stage ne 'query') &&
1639: ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
1640: chomp($env{'form.newrecord'});
1641: if ($env{'form.newrecord'}) {
1.31 albertel 1642: &Apache::lonmsg::store_instructor_comment($env{'form.newrecord'},
1643: $env{'form.recuname'},
1644: $env{'form.recdomain'});
1.1 albertel 1645: }
1646: $r->print('<h3>'.&Apache::loncommon::plainname($env{'form.recuname'},
1647: $env{'form.recdomain'}).'</h3>');
1648: &disfacetoface($r,$env{'form.recuname'},$env{'form.recdomain'});
1649: $r->print(<<ENDRHEAD);
1650: <form method="post" action="/adm/email">
1651: <input name="recdomain" value="$env{'form.recdomain'}" type="hidden" />
1652: <input name="recuname" value="$env{'form.recuname'}" type="hidden" />
1653: ENDRHEAD
1654: $r->print(<<ENDBFORM);
1655: <hr />$lt{'newr'}<br />
1656: <textarea name="newrecord" cols="80" rows="10" wrap="hard"></textarea>
1657: <br />
1658: <input type="hidden" name="recordftf" value="post" />
1659: <input type="submit" value="$lt{'post'}" />
1660: </form>
1661: ENDBFORM
1662: }
1663: }
1664:
1665: # ----------------------------------------------------------- Blocking during exams
1666:
1667: sub examblock {
1668: my ($r,$action) = @_;
1669: unless ($env{'request.course.id'}) { return;}
1.44 raeburn 1670: if (!&Apache::lonnet::allowed('dcm',$env{'request.course.id'})
1671: && ! &Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
1.1 albertel 1672: '/'.$env{'request.course.sec'})) {
1673: $r->print('Not allowed');
1674: return;
1675: }
1.34 albertel 1676: my $usertype = (&Apache::loncommon::course_type() eq 'Group') ? 'members'
1.33 albertel 1677: : 'students';
1.1 albertel 1678: my %lt=&Apache::lonlocal::texthash(
1679: 'comb' => 'Communication Blocking',
1680: 'cbds' => 'Communication blocking during scheduled exams',
1.30 raeburn 1681: '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 1682: 'mecb' => 'Modify existing communication blocking periods',
1.50 raeburn 1683: 'ncbc' => 'No communication blocks currently stored',
1684: 'stor' => 'Store',
1.1 albertel 1685: );
1686:
1687: my %ltext = &Apache::lonlocal::texthash(
1688: 'dura' => 'Duration',
1689: 'setb' => 'Set by',
1690: 'even' => 'Event',
1.44 raeburn 1691: 'blck' => 'Blocked?',
1.1 albertel 1692: 'actn' => 'Action',
1693: 'star' => 'Start',
1694: 'endd' => 'End'
1695: );
1696:
1697: &printheader($r,'/adm/email?block=display',$lt{'comb'});
1698: $r->print('<h3>'.$lt{'cbds'}.'</h3>');
1699:
1700: if ($action eq 'store') {
1701: &blockstore($r);
1702: }
1703:
1704: $r->print($lt{'desc'}.'<br /><br />
1705: <form name="blockform" method="post" action="/adm/email?block=store">
1706: ');
1707:
1708: $r->print('<h4>'.$lt{'mecb'}.'</h4>');
1709: my %records = ();
1710: my $blockcount = 0;
1711: my $parmcount = 0;
1712: &get_blockdates(\%records,\$blockcount);
1713: if ($blockcount > 0) {
1714: $parmcount = &display_blocker_status($r,\%records,\%ltext);
1715: } else {
1716: $r->print($lt{'ncbc'}.'<br /><br />');
1717: }
1718: &display_addblocker_table($r,$parmcount,\%ltext);
1719: my $end_page=&Apache::loncommon::end_page();
1720: $r->print(<<"END");
1721: <br />
1722: <input type="hidden" name="blocktotal" value="$blockcount" />
1.50 raeburn 1723: <input type ="submit" value="$lt{'stor'}" />
1.1 albertel 1724: </form>
1725: $end_page
1726: END
1727: return;
1728: }
1729:
1730: sub blockstore {
1731: my $r = shift;
1732: my %lt=&Apache::lonlocal::texthash(
1733: 'tfcm' => 'The following changes were made',
1734: 'ncwm' => 'No changes were made.'
1735: );
1736: my %adds = ();
1737: my %removals = ();
1738: my %cancels = ();
1739: my $modtotal = 0;
1740: my $canceltotal = 0;
1741: my $addtotal = 0;
1742: my %blocking = ();
1743: $r->print('<h3>'.$lt{'head'}.'</h3>');
1.42 raeburn 1744: foreach my $envkey (keys(%env)) {
1.44 raeburn 1745: if ($envkey =~ m/^form\.modify_(\d+)$/) {
1.1 albertel 1746: $adds{$1} = $1;
1747: $removals{$1} = $1;
1748: $modtotal ++;
1.42 raeburn 1749: } elsif ($envkey =~ m/^form\.cancel_(\d+)$/) {
1.1 albertel 1750: $cancels{$1} = $1;
1751: unless ( defined($removals{$1}) ) {
1752: $removals{$1} = $1;
1753: $canceltotal ++;
1754: }
1.42 raeburn 1755: } elsif ($envkey =~ m/^form\.add_(\d+)$/) {
1.1 albertel 1756: $adds{$1} = $1;
1757: $addtotal ++;
1.44 raeburn 1758: }
1.1 albertel 1759: }
1760:
1.42 raeburn 1761: foreach my $key (keys(%removals)) {
1762: my $hashkey = $env{'form.key_'.$key};
1.1 albertel 1763: &Apache::lonnet::del('comm_block',["$hashkey"],
1764: $env{'course.'.$env{'request.course.id'}.'.domain'},
1765: $env{'course.'.$env{'request.course.id'}.'.num'}
1766: );
1767: }
1.42 raeburn 1768: foreach my $key (keys(%adds)) {
1769: unless ( defined($cancels{$key}) ) {
1770: my ($newstart,$newend) = &get_dates_from_form($key);
1.1 albertel 1771: my $newkey = $newstart.'____'.$newend;
1.44 raeburn 1772: my $blocktypes = &get_block_choices($key);
1773: $blocking{$newkey} = {
1774: setter => $env{'user.name'}.':'.$env{'user.domain'},
1775: event => &escape($env{'form.title_'.$key}),
1776: blocks => $blocktypes,
1777: };
1.1 albertel 1778: }
1779: }
1780: if ($addtotal + $modtotal > 0) {
1781: &Apache::lonnet::put('comm_block',\%blocking,
1782: $env{'course.'.$env{'request.course.id'}.'.domain'},
1783: $env{'course.'.$env{'request.course.id'}.'.num'}
1784: );
1785: }
1786: my $chgestotal = $canceltotal + $modtotal + $addtotal;
1787: if ($chgestotal > 0) {
1788: $r->print($lt{'tfcm'}.'<ul>');
1789: if ($canceltotal > 0) {
1.50 raeburn 1790: $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] removed.',$canceltotal).'</li>');
1.1 albertel 1791: }
1792: if ($modtotal > 0) {
1.50 raeburn 1793: $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] modified.',$modtotal).'</li>');
1.1 albertel 1794: }
1795: if ($addtotal > 0) {
1.50 raeburn 1796: $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] added.',$addtotal).'</li>');
1.1 albertel 1797: }
1798: $r->print('</ul>');
1799: } else {
1800: $r->print($lt{'ncwm'});
1801: }
1802: $r->print('<br />');
1803: return;
1804: }
1805:
1806: sub get_dates_from_form {
1807: my $item = shift;
1808: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
1809: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
1810: return ($startdate,$enddate);
1811: }
1812:
1813: sub get_blockdates {
1814: my ($records,$blockcount) = @_;
1815: $$blockcount = 0;
1816: %{$records} = &Apache::lonnet::dump('comm_block',
1817: $env{'course.'.$env{'request.course.id'}.'.domain'},
1818: $env{'course.'.$env{'request.course.id'}.'.num'}
1819: );
1.15 albertel 1820: $$blockcount = keys(%{$records});
1821:
1822: if ((keys(%{$records}))[0] =~ /^error: 2 /) {
1823: $records = {};
1824: $$blockcount = 0;
1.1 albertel 1825: }
1826: }
1827:
1.44 raeburn 1828: sub get_block_choices {
1829: my $item = shift;
1830: my $blocklist;
1831: my ($typeorder,$types) = &blocktype_text();
1832: foreach my $type (@{$typeorder}) {
1833: if ($env{'form.'.$type.'_'.$item}) {
1834: $blocklist->{$type} = 'on';
1835: } else {
1836: $blocklist->{$type} = 'off';
1837: }
1838: }
1839: return $blocklist;
1840: }
1841:
1.1 albertel 1842: sub display_blocker_status {
1843: my ($r,$records,$ltext) = @_;
1844: my $parmcount = 0;
1.16 albertel 1845:
1.1 albertel 1846: my %lt = &Apache::lonlocal::texthash(
1847: 'modi' => 'Modify',
1848: 'canc' => 'Cancel',
1849: );
1.44 raeburn 1850: my ($typeorder,$types) = &blocktype_text();
1.18 albertel 1851: $r->print(&Apache::loncommon::start_data_table());
1.1 albertel 1852: $r->print(<<"END");
1.16 albertel 1853: <tr>
1.44 raeburn 1854: <th>$ltext->{'dura'}</th>
1855: <th>$ltext->{'setb'}</th>
1856: <th>$ltext->{'even'}</th>
1857: <th>$ltext->{'blck'}</th>
1858: <th>$ltext->{'actn'}?</th>
1.16 albertel 1859: </tr>
1.1 albertel 1860: END
1.18 albertel 1861: foreach my $record (sort(keys(%{$records}))) {
1.1 albertel 1862: my $onchange = 'onFocus="javascript:window.document.forms['.
1863: "'blockform'].elements['modify_".$parmcount."'].".
1864: 'checked=true;"';
1.18 albertel 1865: my ($start,$end) = split(/____/,$record);
1.1 albertel 1866: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
1867: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1.15 albertel 1868:
1.44 raeburn 1869: my ($setuname,$setudom,$title,$blocks) =
1870: &Apache::loncommon::parse_block_record($$records{$record});
1.21 albertel 1871: $title = &HTML::Entities::encode($title,'"<>&');
1.44 raeburn 1872: my $settername =
1873: &Apache::loncommon::aboutmewrapper(
1874: &Apache::loncommon::plainname($setuname,$setudom),
1875: $setuname,$setudom);
1.18 albertel 1876: $r->print(&Apache::loncommon::start_data_table_row());
1.1 albertel 1877: $r->print(<<"END");
1.44 raeburn 1878: <td>$ltext->{'star'}: $startform<br/>$ltext->{'endd'}: $endform</td>
1.1 albertel 1879: <td>$settername</td>
1.18 albertel 1880: <td><input type="text" name="title_$parmcount" size="15" value="$title" /><input type="hidden" name="key_$parmcount" value="$record" /></td>
1.44 raeburn 1881: <td>
1882: END
1883: foreach my $block (@{$typeorder}) {
1884: my $blockstatus = '';
1885: if ($blocks->{$block} eq 'on') {
1886: $blockstatus = 'checked="true"';
1887: }
1888: $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" '.$blockstatus.' value="1" />'.$types->{$block}.'</label><br />');
1889: }
1890: $r->print(<<"END");
1891: </td>
1.1 albertel 1892: <td><label>$lt{'modi'}? <input type="checkbox" name="modify_$parmcount" /></label><br /><label>$lt{'canc'}? <input type="checkbox" name="cancel_$parmcount" /></label>
1893: END
1.18 albertel 1894: $r->print(&Apache::loncommon::end_data_table_row());
1895: $parmcount++;
1.1 albertel 1896: }
1897: $r->print(<<"END");
1898: </table>
1899: <br />
1900: <br />
1901: END
1902: return $parmcount;
1903: }
1904:
1905: sub display_addblocker_table {
1906: my ($r,$parmcount,$ltext) = @_;
1907: my $start = time;
1908: my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
1909: my $onchange = 'onFocus="javascript:window.document.forms['.
1910: "'blockform'].elements['add_".$parmcount."'].".
1911: 'checked=true;"';
1912: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
1913: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
1914: my %lt = &Apache::lonlocal::texthash(
1915: 'addb' => 'Add block',
1916: 'exam' => 'e.g., Exam 1',
1917: 'addn' => 'Add new communication blocking periods'
1918: );
1.44 raeburn 1919: my ($typeorder,$types) = &blocktype_text();
1.1 albertel 1920: $r->print(<<"END");
1921: <h4>$lt{'addn'}</h4>
1.18 albertel 1922: END
1923: $r->print(&Apache::loncommon::start_data_table());
1924: $r->print(<<"END");
1.16 albertel 1925: <tr>
1.44 raeburn 1926: <th>$ltext->{'dura'}</th>
1927: <th>$ltext->{'even'} $lt{'exam'}</th>
1928: <th>$ltext->{'blck'}</th>
1929: <th>$ltext->{'actn'}?</th>
1.16 albertel 1930: </tr>
1.18 albertel 1931: END
1.44 raeburn 1932: $r->print(&Apache::loncommon::start_data_table_row());
1.18 albertel 1933: $r->print(<<"END");
1.44 raeburn 1934: <td>$ltext->{'star'}: $startform<br />$ltext->{'endd'}: $endform</td>
1.16 albertel 1935: <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
1.44 raeburn 1936: <td>
1937: END
1938: foreach my $block (@{$typeorder}) {
1939: $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" value="1" />'.$types->{$block}.'</label><br />');
1940: }
1941: $r->print(<<"END");
1942: </td>
1.16 albertel 1943: <td><label>$lt{'addb'}? <input type="checkbox" name="add_$parmcount" value="1" /></label></td>
1.1 albertel 1944: END
1.18 albertel 1945: $r->print(&Apache::loncommon::end_data_table_row());
1946: $r->print(&Apache::loncommon::end_data_table());
1.1 albertel 1947: return;
1948: }
1949:
1.44 raeburn 1950: sub blocktype_text {
1951: my %types = &Apache::lonlocal::texthash(
1952: 'com' => 'Messaging',
1953: 'chat' => 'Chat',
1954: 'boards' => 'Discussion',
1955: 'port' => 'Portfolio',
1.45 raeburn 1956: 'groups' => 'Groups',
1957: 'blogs' => 'Blogs',
1.18 albertel 1958: );
1.45 raeburn 1959: my $typeorder = ['com','chat','boards','port','groups','blogs'];
1.44 raeburn 1960: return ($typeorder,\%types);
1.1 albertel 1961: }
1962:
1963: # ----------------------------------------------------------- Display a message
1964:
1965: sub displaymessage {
1.53 raeburn 1966: my ($r,$msgid,$folder,$msgstatus)=@_;
1.1 albertel 1967: my $suffix=&Apache::lonmsg::foldersuffix($folder);
1968: my %blocked = ();
1969: my %setters = ();
1970: my $numblocked = 0;
1.33 albertel 1971: my $crstype = &Apache::loncommon::course_type();
1.30 raeburn 1972:
1.1 albertel 1973: # info to generate "next" and "previous" buttons and check if message is blocked
1.44 raeburn 1974: my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com');
1.53 raeburn 1975: my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder,$msgstatus);
1.1 albertel 1976: if ( $blocked{$msgid} eq 'ON' ) {
1977: &printheader($r,'/adm/email',&mt('Display a Message'));
1978: $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.'));
1979: &build_block_table($r,$startblock,$endblock,\%setters);
1980: return;
1981: }
1.59 raeburn 1982: if ($msgstatus eq '') {
1983: &statuschange($msgid,'read',$folder);
1984: }
1.1 albertel 1985: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
1986: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid});
1987:
1988: my $counter=0;
1989: $r->print('<pre>');
1.29 www 1990: my $escmsgid=&escape($msgid);
1.1 albertel 1991: foreach (@messages) {
1992: if ($_->[5] eq $escmsgid){
1993: last;
1994: }
1995: $counter++;
1996: }
1997: $r->print('</pre>');
1998: my $number_of_messages = scalar(@messages); #subtract 1 for last index
1999: # start output
1.29 www 2000: &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'});
1.1 albertel 2001: my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'});
2002: # Functions
2003: $r->print('<table border="2" width="100%"><tr bgcolor="#FFFFAA"><td>'.&mt('Functions').':</td>'.
1.29 www 2004: '<td><a href="/adm/email?replyto='.&escape($msgid).$sqs.
1.1 albertel 2005: '"><b>'.&mt('Reply').'</b></a></td>'.
1.29 www 2006: '<td><a href="/adm/email?forward='.&escape($msgid).$sqs.
1.1 albertel 2007: '"><b>'.&mt('Forward').'</b></a></td>'.
1.29 www 2008: '<td><a href="/adm/email?markunread='.&escape($msgid).$sqs.
1.1 albertel 2009: '"><b>'.&mt('Mark Unread').'</b></a></td>'.
1.29 www 2010: '<td><a href="/adm/email?markdel='.&escape($msgid).$sqs.
1.1 albertel 2011: '"><b>'.&mt('Delete').'</b></a></td>'.
2012: '<td><a href="/adm/email?'.$sqs.
2013: '"><b>'.&mt('Back to Folder Display').'</b></a></td>');
2014: if ($counter > 0){
2015: $r->print('<td><a href="/adm/email?display='.$messages[$counter-1]->[5].$sqs.
2016: '"><b>'.&mt('Previous').'</b></a></td>');
2017: }
2018: if ($counter < $number_of_messages - 1){
2019: $r->print('<td><a href="/adm/email?display='.$messages[$counter+1]->[5].$sqs.
2020: '"><b>'.&mt('Next').'</b></a></td>');
2021: }
2022: $r->print('</tr></table>');
1.59 raeburn 2023: my $symb;
2024: if (defined($content{'symb'})) {
2025: $symb = $content{'symb'};
2026: } elsif (defined($content{'baseurl'})) {
2027: $symb=&Apache::lonnet::symbread($content{'baseurl'});
2028: }
1.1 albertel 2029: if ($env{'user.adv'}) {
2030: $r->print('<table border="2" width="100%"><tr bgcolor="#FFAAAA"><td>'.&mt('Currently available actions (will open extra window)').':</td>');
2031: if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
2032: $r->print('<td><b>'.&Apache::loncommon::track_student_link(&mt('View recent activity'),$content{'sendername'},$content{'senderdomain'},'check').'</b></td>');
2033: }
2034: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
2035: $r->print('<td><b>'.&Apache::loncommon::pprmlink(&mt('Set/Change parameters'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
2036: }
2037: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
2038: $r->print('<td><b>'.&Apache::loncommon::pgrdlink(&mt('Set/Change grades'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
2039: }
2040: $r->print('</tr></table>');
2041: }
2042: my $tolist;
2043: my @recipients = ();
2044: for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
2045: $recipients[$i] = &Apache::loncommon::aboutmewrapper(
2046: &Apache::loncommon::plainname($content{'recuser'}[$i],
2047: $content{'recdomain'}[$i]),
2048: $content{'recuser'}[$i],$content{'recdomain'}[$i]).
2049: ' ('.$content{'recuser'}[$i].' at '.$content{'recdomain'}[$i].') ';
2050: }
2051: $tolist = join(', ',@recipients);
1.59 raeburn 2052: my ($restitle,$baseurl,$refers_to);
2053: if (defined($content{'resource_title'})) {
2054: $restitle = $content{'resource_title'};
2055: } else {
2056: if (defined($content{'baseurl'})) {
2057: $restitle = &Apache::lonnet::gettitle($content{'baseurl'});
2058: }
2059: }
2060: if (defined($content{'baseurl'})) {
2061: $baseurl = &Apache::lonenc::check_encrypt($content{'baseurl'});
2062: }
1.68 www 2063: $r->print(&Apache::loncommon::student_image_tag($content{'senderdomain'},$content{'sendername'}));
1.1 albertel 2064: $r->print('<br /><b>'.&mt('Subject').':</b> '.$content{'subject'}.
2065: ($folder ne 'sent'?'<br /><b>'.&mt('From').':</b> '.
2066: &Apache::loncommon::aboutmewrapper(
2067: &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),
2068: $content{'sendername'},$content{'senderdomain'}).' ('.
2069: $content{'sendername'}.' at '.
2070: $content{'senderdomain'}.') ':'<br /><b>'.&mt('To').':</b> '.
2071: $tolist).
1.30 raeburn 2072: ($content{'courseid'}?'<br /><b>'.&mt($crstype).':</b> '.$courseinfo{'description'}.
2073: ($content{'coursesec'}?' ('.&mt('Section').': '.$content{'coursesec'}.')':''):'').
1.59 raeburn 2074: '<br /><b>'.&mt('Time').':</b> '.$content{'time'});
2075: if ($baseurl) {
2076: if (defined($content{'courseid'}) && defined($env{'request.course.id'})) {
2077: if ($content{'courseid'} eq $env{'request.course.id'}) {
2078: my $symblink;
1.62 raeburn 2079: my $showsymb = &Apache::lonenc::check_decrypt($symb);
2080: my $showurl = &Apache::lonenc::check_decrypt($baseurl);
2081: my $encrypturl = &Apache::lonnet::EXT('resource.0.encrypturl',
2082: $showsymb,$env{'user.domain'},$env{'user.name'});
1.59 raeburn 2083: if ($symb) {
1.62 raeburn 2084: if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
2085: $showsymb = &Apache::lonenc::check_encrypt($symb);
2086: }
2087: $symblink = '?symb='.$showsymb;
2088: }
2089: if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
2090: $showurl = $baseurl;
1.59 raeburn 2091: }
1.62 raeburn 2092: $r->print('<br /><b>'.&mt('Refers to').':</b> <a href="'.$showurl.$symblink.'">'.$restitle.'</a>');
1.59 raeburn 2093: $refers_to = 1;
2094: }
2095: }
2096: if (!$refers_to) {
2097: if ($baseurl =~ m-^/enc/-) {
2098: if (defined($content{'courseid'})) {
1.62 raeburn 2099: if (!$env{'request.course.id'}) {
2100: my $unencurl =
2101: &Apache::lonenc::unencrypted($baseurl,
2102: $content{'courseid'});
2103: if ($unencurl ne '') {
2104: if (&Apache::lonnet::allowed('bre',$unencurl)) {
2105: $r->print('<br /><b>'.&mt('Refers to').
2106: ':</b> <a href="'.$unencurl.'">'.
2107: $restitle.'</a>');
2108: }
1.59 raeburn 2109: }
2110: }
2111: }
2112: } else {
2113: if (&Apache::lonnet::allowed('bre',$baseurl)) {
2114: $r->print('<br /><b>'.&mt('Refers to').
2115: ':</b> <a href="'.$baseurl.
2116: '">'.$restitle.'</a>');
2117: }
2118: }
2119: }
2120: }
2121: $r->print('<p><pre>'.
1.1 albertel 2122: &Apache::lontexconvert::msgtexconverted($content{'message'},1).
2123: '</pre><hr />'.&displayresource(%content).'</p>');
1.59 raeburn 2124: return;
1.1 albertel 2125: }
2126:
2127: # =========================================================== Show the citation
2128:
2129: sub displayresource {
2130: my %content=@_;
2131: #
2132: # If the recipient is in the same course that the message was sent from and
2133: # has sufficient privileges, show "all details," else show citation
2134: #
2135: if (($env{'request.course.id'} eq $content{'courseid'})
2136: && (&Apache::lonnet::allowed('vgr',$content{'courseid'}))) {
1.59 raeburn 2137: my $symb;
2138: if (defined($content{'symb'})) {
2139: $symb = $content{'symb'};
2140: } else {
2141: $symb=&Apache::lonnet::symbread($content{'baseurl'});
2142: }
1.1 albertel 2143: # Could not get a symb, give up
2144: unless ($symb) { return $content{'citation'}; }
2145: # Have a symb, can render
2146: return '<h2>'.&mt('Current attempts of student (if applicable)').'</h2>'.
2147: &Apache::loncommon::get_previous_attempt($symb,
2148: $content{'sendername'},
2149: $content{'senderdomain'},
2150: $content{'courseid'}).
2151: '<hr /><h2>'.&mt('Current screen output (if applicable)').'</h2>'.
2152: &Apache::loncommon::get_student_view($symb,
2153: $content{'sendername'},
2154: $content{'senderdomain'},
2155: $content{'courseid'}).
2156: '<h2>'.&mt('Correct Answer(s) (if applicable)').'</h2>'.
2157: &Apache::loncommon::get_student_answers($symb,
2158: $content{'sendername'},
2159: $content{'senderdomain'},
2160: $content{'courseid'});
2161: } elsif ($env{'user.adv'}) {
2162: return $content{'citation'};
2163: }
2164: return '';
2165: }
2166:
2167: # ================================================================== The Header
2168:
2169: sub header {
2170: my ($r,$title,$baseurl)=@_;
2171:
2172: my $extra = &Apache::loncommon::studentbrowser_javascript();
2173: if ($baseurl) {
1.41 albertel 2174: $extra .= "<base href=\"".&Apache::lonnet::absolute_url()."/$baseurl\" />";
1.1 albertel 2175: }
2176: $r->print(&Apache::loncommon::start_page('Communication and Messages',
1.38 raeburn 2177: $extra));
1.1 albertel 2178: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.38 raeburn 2179: (($title?$title:'Communication and Messages')));
1.1 albertel 2180: }
2181:
2182: # ---------------------------------------------------------------- Print header
2183:
2184: sub printheader {
2185: my ($r,$url,$desc,$title,$baseurl)=@_;
2186: &Apache::lonhtmlcommon::add_breadcrumb
2187: ({href=>$url,
2188: text=>$desc});
2189: &header($r,$title,$baseurl);
2190: }
2191:
2192: # ------------------------------------------------------------ Store the comment
2193:
2194: sub storecomment {
2195: my ($r)=@_;
2196: my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2197: my $cleanmsgtxt='';
1.42 raeburn 2198: foreach my $line (split(/[\n\r]/,$msgtxt)) {
2199: unless ($line=~/^\s*(\>|\>\;)/) {
2200: $cleanmsgtxt.=$line."\n";
1.1 albertel 2201: }
2202: }
1.29 www 2203: my $key=&escape($env{'form.baseurl'}).'___'.time;
1.1 albertel 2204: &Apache::lonnet::put('nohist_stored_comments',{ $key => $cleanmsgtxt });
2205: }
2206:
2207: sub storedcommentlisting {
2208: my ($r)=@_;
2209: my %msgs=&Apache::lonnet::dump('nohist_stored_comments',undef,undef,
1.29 www 2210: '^'.&escape(&escape($env{'form.showcommentbaseurl'})));
1.1 albertel 2211: $r->print(&Apache::loncommon::start_page('Stored Comment Listing',undef,
2212: {'onlybody' => 1}));
2213: if ((keys %msgs)[0]=~/^error\:/) {
2214: $r->print(&mt('No stored comments yet.'));
2215: } else {
2216: my $found=0;
1.42 raeburn 2217: foreach my $key (sort(keys(%msgs))) {
2218: $r->print("\n".$msgs{$key}."<hr />");
1.1 albertel 2219: $found=1;
2220: }
2221: unless ($found) {
2222: $r->print(&mt('No stored comments yet for this resource.'));
2223: }
2224: }
2225: }
2226:
2227: # ---------------------------------------------------------------- Send an email
2228:
2229: sub sendoffmail {
2230: my ($r,$folder)=@_;
2231: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2232: my $sendstatus='';
1.71 ! raeburn 2233: my %msg_status;
! 2234: my $numsent = 0;
! 2235: my $nosentstore = 1;
1.38 raeburn 2236: my ($cdom,$cnum,$group);
2237: if (exists($env{'form.group'})) {
2238: $group = $env{'form.group'};
2239: }
2240: if (exists($env{'request.course.id'})) {
2241: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2242: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2243: }
1.1 albertel 2244: if ($env{'form.send'}) {
1.53 raeburn 2245: if (!$env{'form.multiforward'}) {
2246: if ($group eq '') {
2247: &printheader($r,'','Messages being sent.');
2248: } else {
2249: $r->print(&groupmail_header('sending',$group));
2250: }
1.38 raeburn 2251: }
1.1 albertel 2252: $r->rflush();
2253: my %content=();
2254: undef %content;
2255: if ($env{'form.forwid'}) {
2256: my $msgid=$env{'form.forwid'};
2257: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2258: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2259: &statuschange($msgid,'forwarded',$folder);
2260: $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
2261: $content{'message'};
2262: }
2263: if ($env{'form.replyid'}) {
2264: my $msgid=$env{'form.replyid'};
2265: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2266: %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2267: &statuschange($msgid,'replied',$folder);
2268: }
1.13 albertel 2269:
1.35 albertel 2270: my @to =
1.37 raeburn 2271: &Apache::loncommon::get_env_multiple('form.selectedusers_forminput');
1.25 foxr 2272: my $mode = $env{'form.sendmode'};
2273:
1.13 albertel 2274: my %toaddr;
1.35 albertel 2275: if (@to) {
2276: foreach my $dest (@to) {
1.27 albertel 2277: my ($user,$domain) = split(/:/, $dest);
1.25 foxr 2278: if (($user ne '') && ($domain ne '')) {
2279: my $address = $user.":".$domain; # How the code below expects it.
2280: $toaddr{$address} = '';
2281: }
2282: }
2283: }
2284:
1.1 albertel 2285: if ($env{'form.sendmode'} eq 'group') {
1.25 foxr 2286: foreach my $address (keys(%env)) {
2287: if ($address=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
2288: $toaddr{$1}='';
2289: }
1.1 albertel 2290: }
2291: } elsif ($env{'form.sendmode'} eq 'upload') {
1.71 ! raeburn 2292: $nosentstore = 0;
1.13 albertel 2293: foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) {
1.43 raeburn 2294: my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/);
1.1 albertel 2295: if ($txt) {
1.43 raeburn 2296: $rec =~ s/^\s+//;
1.44 raeburn 2297: $rec =~ s/\s+$//;
1.1 albertel 2298: $toaddr{$rec}.=$txt."\n";
2299: }
2300: }
2301: } else {
1.25 foxr 2302: if (($env{'form.recuname'} ne '') && ($env{'form.recdomain'} ne '')) {
2303: $toaddr{$env{'form.recuname'}.':'.$env{'form.recdomain'}}='';
2304: }
1.1 albertel 2305: }
2306: if ($env{'form.additionalrec'}) {
1.66 albertel 2307: foreach my $rec (split(/\s*,\s*/,$env{'form.additionalrec'})) {
1.43 raeburn 2308: my ($auname,$audom)=split(/:/,$rec);
1.25 foxr 2309: if (($auname ne "") && ($audom ne "")) {
2310: $toaddr{$auname.':'.$audom}='';
2311: }
1.1 albertel 2312: }
2313: }
2314:
2315: my $savemsg;
2316: my $msgtype;
2317: my %sentmessage;
1.7 albertel 2318: my $msgsubj=&Apache::lonfeedback::clear_out_html($env{'form.subject'},
2319: undef,1);
1.1 albertel 2320: if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
2321: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
2322: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
2323: '/'.$env{'request.course.sec'})
2324: )) {
2325: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
2326: $msgtype = 'critical';
2327: } else {
2328: $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
2329: }
1.71 ! raeburn 2330: my @recusers;
! 2331: my @recudoms;
1.13 albertel 2332: foreach my $address (sort(keys(%toaddr))) {
2333: my ($recuname,$recdomain)=split(/\:/,$address);
1.1 albertel 2334: my $msgtxt = $savemsg;
1.13 albertel 2335: if ($toaddr{$address}) { $msgtxt.='<hr />'.$toaddr{$address}; }
1.12 albertel 2336: my @thismsg;
1.60 raeburn 2337: if ($msgtype eq 'critical') {
2338: $r->print(&mt('Sending critical message').' '.
2339: $recuname.':'.$recdomain.': ');
1.13 albertel 2340: @thismsg=
2341: &Apache::lonmsg::user_crit_msg($recuname,$recdomain,
2342: $msgsubj,$msgtxt,
2343: $env{'form.sendbck'},
2344: $env{'form.permanent'},
1.71 ! raeburn 2345: \$sentmessage{$address},
! 2346: $nosentstore);
1.1 albertel 2347: } else {
1.14 albertel 2348: $r->print(&mt('Sending').' '.$recuname.':'.$recdomain.': ');
1.13 albertel 2349: @thismsg=
2350: &Apache::lonmsg::user_normal_msg($recuname,$recdomain,
2351: $msgsubj,$msgtxt,
2352: $content{'citation'},
2353: undef,undef,
2354: $env{'form.permanent'},
1.71 ! raeburn 2355: \$sentmessage{$address},
! 2356: undef,undef,undef,
! 2357: $nosentstore);
! 2358: }
! 2359: $msg_status{$recuname.':'.$recdomain}=join(' ',@thismsg);
! 2360: if ($msg_status{$recuname.':'.$recdomain} =~ /(ok|con_delayed)/) {
! 2361: $numsent++;
! 2362: push(@recusers,$recuname);
! 2363: push(@recudoms,$recdomain);
1.1 albertel 2364: }
1.12 albertel 2365: $sendstatus.=' '.join(' ',@thismsg);
1.1 albertel 2366: }
1.71 ! raeburn 2367: my $subj_prefix;
! 2368: if ($numsent > 0) {
! 2369: if (($env{'request.course.id'}) &&
! 2370: (($env{'form.sendmode'} eq 'group') ||
! 2371: ($env{'form.courserecord'}) ||
! 2372: ($msgtype eq 'critical'))) {
! 2373: if ($msgtype eq 'critical') {
! 2374: $subj_prefix = 'Critical.';
! 2375: } elsif ($env{'form.sendmode'} eq 'group') {
! 2376: $subj_prefix = 'Broadcast.';
! 2377: } else {
! 2378: $subj_prefix = 'Archive';
! 2379: }
! 2380: my ($specialmsgid,$specialresult);
! 2381: my $course_str = &escape('['.$cnum.':'.$cdom.']');
1.1 albertel 2382:
1.71 ! raeburn 2383: $specialresult =
! 2384: &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
! 2385: $subj_prefix.' '.$course_str,$savemsg,undef,undef,
! 2386: undef,undef,undef,\$specialmsgid,undef,undef,undef,
! 2387: undef,undef,1);
1.29 www 2388: $specialmsgid = &unescape($specialmsgid);
1.71 ! raeburn 2389: if ($specialresult eq 'ok') {
! 2390: my ($stamp,$crssubj,$msgname,$msgdom,$msgcount,$context,$pid) =
! 2391: split(/\:/,&unescape($specialmsgid));
! 2392:
! 2393: foreach my $recipient (sort(keys(%toaddr))) {
! 2394: if ($msg_status{$recipient} =~ /\s*(ok|con_delayed)\s*/) {
! 2395: my $usersubj = $subj_prefix.'['.$recipient.']';
! 2396: my $usermsgid =
! 2397: &Apache::lonmsg::buildmsgid($stamp,$usersubj,
! 2398: $msgname,$msgdom,
! 2399: $msgcount,$context,
! 2400: $pid);
! 2401: &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
! 2402: $subj_prefix.' ['.$recipient.']',$msgsubj,
! 2403: undef,undef,undef,undef,$usermsgid,undef,
! 2404: undef,$specialmsgid,undef,undef,undef,1);
! 2405: }
! 2406: }
! 2407: if (($env{'form.sendmode'} ne 'upload') && (@recusers > 0)) {
! 2408: &Apache::lonmsg::process_sent_mail($msgsubj,
! 2409: $subj_prefix,$numsent,$stamp,$msgname,$msgdom,
! 2410: $msgcount,$context,$pid,$savemsg,\@recusers,
! 2411: \@recudoms);
1.1 albertel 2412: }
1.71 ! raeburn 2413: } else {
! 2414: &Apache::lonnet::logthis('Failed to create record of critical, broadcast or archived message in '.$env{'course.'.$env{'request.course.id'}.'.num'}.' at '.$env{'course.'.$env{'request.course.id'}.'.domain'}.' - no msgid generated');
1.1 albertel 2415: }
2416: } else {
1.71 ! raeburn 2417: my $stamp = time;
! 2418: my $msgcount = &Apache::lonmsg::get_uniq();
! 2419: my $context = &Apache::lonmsg::get_course_context();
! 2420: &Apache::lonmsg::process_sent_mail($msgsubj,$subj_prefix,
! 2421: $numsent,$stamp,$env{'user.name'},
! 2422: $env{'user.domain'},$msgcount,$context,
! 2423: $$,$savemsg,\@recusers,\@recudoms);
1.1 albertel 2424: }
2425: }
1.71 ! raeburn 2426: if (!$env{'form.multiforward'}) {
! 2427: if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) {
! 2428: $r->print('<br /><span class="LC_success">'.&mt('Completed.').
! 2429: '</span>');
! 2430: if ($env{'form.displayedcrit'}) {
! 2431: &discrit($r);
! 2432: }
! 2433: if ($group ne '') {
! 2434: $r->print(&groupmail_sent($group,$cdom,$cnum));
! 2435: } else {
! 2436: &Apache::loncommunicate::menu($r);
! 2437: }
! 2438: } else {
! 2439: $r->print('<p><span class="LC_error">'.&mt('Could not deliver message').'</span> '.
! 2440: &mt('Please use the browser "Back" button and correct the recipient addresses '."($sendstatus)").'</p>');
1.53 raeburn 2441: }
1.38 raeburn 2442: }
1.1 albertel 2443: }
1.53 raeburn 2444: return $sendstatus;
1.1 albertel 2445: }
2446:
2447: # ===================================================================== Handler
2448:
2449: sub handler {
2450: my $r=shift;
2451:
2452: # ----------------------------------------------------------- Set document type
2453:
2454: &Apache::loncommon::content_type($r,'text/html');
2455: $r->send_http_header;
2456:
2457: return OK if $r->header_only;
2458:
2459: # --------------------------- Get query string for limited number of parameters
2460: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2461: ['display','replyto','forward','markread','markdel','markunread',
2462: 'sendreply','compose','sendmail','critical','recname','recdom',
2463: 'recordftf','sortedby','block','folder','startdis','interdis',
1.53 raeburn 2464: 'showcommentbaseurl','dismode','group','subject','text','ref',
2465: 'msgstatus']);
1.1 albertel 2466: $sqs='&sortedby='.$env{'form.sortedby'};
2467:
2468: # ------------------------------------------------------ They checked for email
2469: unless ($env{'form.block'}) {
2470: &Apache::lonnet::put('email_status',{'recnewemail'=>0});
2471: }
2472:
2473: # ----------------------------------------------------------------- Breadcrumbs
2474:
2475: &Apache::lonhtmlcommon::clear_breadcrumbs();
2476: &Apache::lonhtmlcommon::add_breadcrumb
2477: ({href=>"/adm/communicate",
2478: text=>"Communication/Messages",
2479: faq=>12,bug=>'Communication Tools',});
2480:
2481: # ------------------------------------------------------------------ Get Folder
2482:
2483: my $folder=$env{'form.folder'};
2484: unless ($folder) {
2485: $folder='';
2486: } else {
1.29 www 2487: $sqs.='&folder='.&escape($folder);
1.1 albertel 2488: }
2489: # ------------------------------------------------------------ Get Display Mode
2490:
2491: my $dismode=$env{'form.dismode'};
2492: unless ($dismode) {
2493: $dismode='';
2494: } else {
1.48 albertel 2495: $sqs.='&dismode='.&escape($dismode);
1.1 albertel 2496: }
2497:
2498: # --------------------------------------------------------------------- Display
1.53 raeburn 2499: my $msgstatus = $env{'form.msgstatus'};
1.1 albertel 2500: $startdis=$env{'form.startdis'};
1.53 raeburn 2501: if ($startdis ne '') {
2502: $startdis--;
2503: }
1.1 albertel 2504: unless ($startdis) { $startdis=0; }
2505:
2506: if ($env{'form.firstview'}) {
2507: $startdis=0;
2508: }
2509: if ($env{'form.lastview'}) {
2510: $startdis=-1;
2511: }
2512: if ($env{'form.prevview'}) {
2513: $startdis--;
2514: }
2515: if ($env{'form.nextview'}) {
2516: $startdis++;
2517: }
2518: my $postedstartdis=$startdis+1;
2519: $sqs.='&startdis='.$postedstartdis;
2520:
2521: # --------------------------------------------------------------- Render Output
2522:
2523: if ($env{'form.display'}) {
1.53 raeburn 2524: &displaymessage($r,$env{'form.display'},$folder,$msgstatus);
1.1 albertel 2525: } elsif ($env{'form.replyto'}) {
2526: &compout($r,'',$env{'form.replyto'},undef,undef,$folder,$dismode);
2527: } elsif ($env{'form.confirm'}) {
2528: &printheader($r,'','Confirmed Receipt');
1.36 albertel 2529: my $replying = 0;
1.42 raeburn 2530: foreach my $envkey (keys(%env)) {
2531: if ($envkey=~/^form\.rec\_(.*)$/) {
1.1 albertel 2532: $r->print('<b>'.&mt('Confirming Receipt').':</b> '.
2533: &Apache::lonmsg::user_crit_received($1).'<br>');
2534: }
1.42 raeburn 2535: if ($envkey=~/^form\.reprec\_(.*)$/) {
1.1 albertel 2536: my $msgid=$1;
2537: $r->print('<b>'.&mt('Confirming Receipt').':</b> '.
2538: &Apache::lonmsg::user_crit_received($msgid).'<br>');
2539: &compout($r,'','','',$msgid);
1.36 albertel 2540: $replying = 1;
1.1 albertel 2541: }
2542: }
1.36 albertel 2543: if (!$replying) {
2544: &discrit($r);
2545: }
1.1 albertel 2546: } elsif ($env{'form.critical'}) {
2547: &printheader($r,'','Displaying Critical Messages');
2548: &discrit($r);
2549: } elsif ($env{'form.forward'}) {
2550: &compout($r,$env{'form.forward'},undef,undef,undef,$folder);
2551: } elsif ($env{'form.markdel'}) {
2552: &printheader($r,'','Deleted Message');
1.9 albertel 2553: my ($result,$msg) =
2554: &statuschange($env{'form.markdel'},'deleted',$folder);
2555: if (!$result) {
1.10 albertel 2556: $r->print('<p class="LC_error">'.
2557: &mt('Failed to delete the message.').'</p>'.
1.9 albertel 2558: '<p class="LC_error">'.$msg."</p>\n");
2559: }
1.1 albertel 2560: &Apache::loncommunicate::menu($r);
1.53 raeburn 2561: &disall($r,($folder?$folder:$dismode),$msgstatus);
2562: } elsif ($env{'form.markedaction'} eq 'markedforward') {
2563: my $total = 0;
2564: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
2565: foreach my $msgid (@to_forward) {
2566: &statuschange(&unescape($msgid),'forwarded',$folder);
2567: $total ++;
2568: }
2569: if ($total > 0) {
2570: &compout($r,undef,undef,undef,undef,$folder,$dismode,$total);
2571: }
2572: } elsif ($env{'form.markedaction'} eq 'markedread') {
2573: my $total = 0;
2574: my @to_markread = &Apache::loncommon::get_env_multiple('form.delmark');
2575: foreach my $msgid (@to_markread) {
2576: &statuschange(&unescape($msgid),'read',$folder);
2577: $total ++;
2578: }
2579: &printheader($r,'','Marked Messages Read');
2580: $r->print(&mt('Marked [_1] message(s) read',$total).'<p>');
2581: &Apache::loncommunicate::menu($r);
2582: &disall($r,($folder?$folder:$dismode),$msgstatus);
2583: } elsif ($env{'form.markedaction'} eq 'markedunread') {
2584: my $total = 0;
2585: my @to_markunread = &Apache::loncommon::get_env_multiple('form.delmark');
2586: foreach my $msgid (@to_markunread) {
2587: &statuschange(&unescape($msgid),'new',$folder);
2588: $total ++;
2589: }
2590: &printheader($r,'','Marked Messages Unread');
2591: $r->print(&mt('Marked [_1] message(s) unread',$total).'<p>');
2592: &Apache::loncommunicate::menu($r);
2593: &disall($r,($folder?$folder:$dismode),$msgstatus);
2594: } elsif ($env{'form.markedaction'} eq 'markedmove') {
2595: my $destfolder = $env{'form.movetofolder'};
2596: my %gotfolders = &Apache::lonmsg::get_user_folders();
2597: &printheader($r,'','Moved Messages');
2598: if (!defined($gotfolders{$destfolder})) {
2599: $r->print(&mt('Destination folder [_1] is not a valid folder',
2600: $destfolder));
2601: } else {
2602: my ($total,$failed,@failed_msg)=(0,0);
2603: my @to_move = &Apache::loncommon::get_env_multiple('form.delmark');
2604: foreach my $msgid (@to_move) {
2605: my ($result,$msg) = &movemsg(&unescape($msgid),$folder,
2606: $env{'form.movetofolder'});
2607: if ($result) {
1.9 albertel 2608: $total++;
1.53 raeburn 2609: } else {
1.9 albertel 2610: $failed++;
2611: push(@failed_msg,$msg);
1.53 raeburn 2612: }
1.1 albertel 2613: }
1.53 raeburn 2614: if ($failed) {
2615: $r->print('<p class="LC_error">
1.10 albertel 2616: '.&mt('Failed to move [_1] message(s)',$failed).
2617: '</p>');
1.53 raeburn 2618: $r->print('<p class="LC_error">'.
2619: join("</p>\n<p class=\"LC_error\">",@failed_msg).
2620: "</p>\n");
2621: }
2622: $r->print(&mt('Moved [_1] message(s)',$total).'<p>');
2623: }
1.1 albertel 2624: &Apache::loncommunicate::menu($r);
1.53 raeburn 2625: &disall($r,($folder?$folder:$dismode),$msgstatus);
2626: } elsif ($env{'form.markedaction'} eq 'markeddel') {
1.9 albertel 2627: my ($total,$failed,@failed_msg)=(0,0);
1.53 raeburn 2628: my @to_delete = &Apache::loncommon::get_env_multiple('form.delmark');
2629: foreach my $msgid (@to_delete) {
2630: my ($result,$msg) = &statuschange(&unescape($msgid),'deleted',
2631: $folder);
2632: if ($result) {
2633: $total++;
2634: } else {
2635: $failed++;
2636: push(@failed_msg,$msg);
1.1 albertel 2637: }
2638: }
2639: &printheader($r,'','Deleted Messages');
1.9 albertel 2640: if ($failed) {
2641: $r->print('<p class="LC_error">
1.10 albertel 2642: '.&mt('Failed to delete [_1] message(s)',$failed).
2643: '</p>');
1.9 albertel 2644: $r->print('<p class="LC_error">'.
2645: join("</p>\n<p class=\"LC_error\">",@failed_msg).
2646: "</p>\n");
2647: }
1.10 albertel 2648: $r->print(&mt('Deleted [_1] message(s)',$total).'<p>');
1.1 albertel 2649: &Apache::loncommunicate::menu($r);
1.53 raeburn 2650: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 2651: } elsif ($env{'form.markunread'}) {
2652: &printheader($r,'','Marked Message as Unread');
2653: &statuschange($env{'form.markunread'},'new');
2654: &Apache::loncommunicate::menu($r);
1.53 raeburn 2655: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 2656: } elsif ($env{'form.compose'}) {
2657: &compout($r,'','',$env{'form.compose'});
2658: } elsif ($env{'form.recordftf'}) {
2659: &facetoface($r,$env{'form.recordftf'});
2660: } elsif ($env{'form.block'}) {
2661: &examblock($r,$env{'form.block'});
2662: } elsif ($env{'form.sendmail'}) {
1.53 raeburn 2663: if ($env{'form.multiforward'}) {
2664: &printheader($r,'','Messages being sent.');
2665: my $fixed_subj = $env{'form.subject'};
2666: my $suffix=&Apache::lonmsg::foldersuffix($folder);
2667: my (%sendresult,%forwardok,%forwardfail,$fwdcount);
2668: my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark');
2669: foreach my $item (@to_forward) {
2670: my $msgid=&unescape($item);
2671: my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
2672: my %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
2673: if ($env{'form.showorigsubj'}) {
2674: $env{'form.subject'} = $fixed_subj.$content{'subject'};
2675: } else {
2676: $env{'form.subject'} = '';
2677: }
2678: my $uname = $content{'sendername'};
2679: my $udom = $content{'senderdomain'};
2680: &statuschange($msgid,'forwarded',$folder);
2681: if ($env{'form.showorigsender'}) {
2682: $env{'form.message'} = $env{'form.msgheader'}.' '.
2683: &Apache::loncommon::plainname($uname,$udom).' ('.
2684: $uname.':'.$udom.')';
2685: }
2686: $env{'form.message'} .= "\n\n-- Forwarded message --\n\n".
2687: $content{'message'};
2688: $fwdcount ++;
2689: $r->print($fwdcount.': ');
2690: $sendresult{$msgid} = &sendoffmail($r,$folder);
2691: $r->print('<br />');
2692: }
2693: foreach my $key (keys(%sendresult)) {
2694: if ($sendresult{$key} =~/^(\s*(?:ok|con_delayed)\s*)*$/) {
2695: $forwardok{$key} = $sendresult{$key};
2696: } else {
2697: $forwardfail{$key} = $sendresult{$key};
2698: }
2699: }
2700: if (keys(%forwardok) > 0) {
2701: my $count = keys(%forwardok);
2702: $r->print('<br /><span class="LC_success">'.
2703: &mt('[quant,_1,message] forwarded.',$count).
2704: '</span>');
2705: }
2706: if (keys(%forwardfail) > 0) {
2707: my $count = keys(%forwardfail);
2708: $r->print('<p><span class="LC_error">'.
2709: &mt('Could not forward [quant,_1,message].',$count).
2710: '</span> ');
2711: foreach my $key (keys(%forwardfail)) {
2712: $r->print(&mt('Could not deliver forwarded message.').'</span> '.
2713: &mt('The recipient addresses may need to be corrected').' ('.$forwardfail{$key}.').<br /><br />');
2714: }
2715: }
2716: &Apache::loncommunicate::menu($r);
2717: } else {
2718: &sendoffmail($r,$folder);
2719: }
1.1 albertel 2720: if ($env{'form.storebasecomment'}) {
2721: &storecomment($r);
1.38 raeburn 2722: }
1.1 albertel 2723: if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
1.38 raeburn 2724: &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
1.1 albertel 2725: $env{'course.'.$env{'request.course.id'}.'.domain'},
2726: 'Course_Announcements',
2727: $env{'form.subject'},
2728: $env{'form.message'},'/adm/communicate','public');
2729: }
1.38 raeburn 2730: if ((!exists($env{'form.group'})) && (!$env{'form.displayedcrit'})) {
1.53 raeburn 2731: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.36 albertel 2732: }
1.1 albertel 2733: } elsif ($env{'form.newfolder'}) {
2734: &printheader($r,'','New Folder');
1.46 raeburn 2735: my $showfolder = $env{'form.newfolder'};
2736: my ($makeresult,$warning) = &makefolder($env{'form.newfolder'});
2737: if ($makeresult eq 'ok') {
2738: $r->print(&mt('Mail folder "[_1]" created.',$showfolder).'<br />');
2739: } else {
2740: $r->print(&mt('Creation failed.').' '.$makeresult.'<br />'.
2741: $warning);
2742: $showfolder = $folder;
2743: }
2744: &Apache::loncommunicate::menu($r);
1.53 raeburn 2745: &disall($r,$showfolder,$msgstatus);
1.1 albertel 2746: } elsif ($env{'form.showcommentbaseurl'}) {
2747: &storedcommentlisting($r);
1.46 raeburn 2748: } elsif ($env{'form.folderaction'} eq 'delete') {
2749: &printheader($r,'','Deleted Folder');
2750: my $showfolder = '';
2751: my $delresult = &deletefolder($folder);
2752: if ($delresult eq 'ok') {
2753: $r->print(&mt('Mail folder "[_1]" deleted.',$folder).'<br />');
1.65 raeburn 2754: $env{'form.folder'} = '';
1.46 raeburn 2755: } else {
2756: $r->print(&mt('Deletion failed.').' '.$delresult.'<br />');
2757: $showfolder = $folder;
2758: }
2759: &Apache::loncommunicate::menu($r);
1.53 raeburn 2760: &disall($r,$showfolder,$msgstatus);
1.46 raeburn 2761: } elsif ($env{'form.folderaction'} eq 'rename') {
2762: &printheader($r,'','Renamed Folder');
2763: my $showfolder = $env{'form.renamed'};
2764: my $renresult = &renamefolder($folder);
2765: if ($renresult eq 'ok') {
2766: $r->print(&mt('Mail folder "[_1]" renamed "[_2]".',$folder,$showfolder).'<br />');
2767: } else {
2768: $r->print(&mt('Renaming failed.').' '.$renresult.'<br />');
2769: $showfolder = $folder;
2770: }
2771: &Apache::loncommunicate::menu($r);
1.53 raeburn 2772: &disall($r,$showfolder,$msgstatus);
1.1 albertel 2773: } else {
2774: &printheader($r,'','Display All Messages');
1.44 raeburn 2775: &Apache::loncommunicate::menu($r);
1.53 raeburn 2776: &disall($r,($folder?$folder:$dismode),$msgstatus);
1.1 albertel 2777: }
2778: $r->print(&Apache::loncommon::end_page());
2779: return OK;
2780: }
2781: # ================================================= Main program, reset counter
2782:
2783: =pod
2784:
2785: =cut
2786:
2787: 1;
2788:
2789: __END__
2790:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>