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