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