File:
[LON-CAPA] /
loncom /
interface /
lonfeedback.pm
Revision
1.100:
download - view:
text,
annotated -
select for diffs
Wed Jul 21 21:47:13 2004 UTC (20 years, 2 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Can choose different sorting mechanism for discussion posts. Interface provided for filtering of posts for display (by poster's role, status -active/inactive, section). Choices currently have no effect (work-in-progress).
1: # The LearningOnline Network
2: # Feedback
3: #
4: # $Id: lonfeedback.pm,v 1.100 2004/07/21 21:47:13 raeburn Exp $
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::lonfeedback;
31:
32: use strict;
33: use Apache::Constants qw(:common);
34: use Apache::lonmsg();
35: use Apache::loncommon();
36: use Apache::lontexconvert();
37: use Apache::lonlocal; # must not have ()
38: use Apache::lonhtmlcommon();
39:
40: sub discussion_open {
41: my ($status)=@_;
42: if (defined($status) &&
43: !($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER'
44: || $status eq 'OPEN')) {
45: return 0;
46: }
47: my $close=&Apache::lonnet::EXT('resource.0.discussend');
48: if (defined($close) && $close ne '' && $close < time) {
49: return 0;
50: }
51: return 1;
52: }
53:
54: sub discussion_visible {
55: my ($status)=@_;
56: if (not &discussion_open($status)) {
57: my $hidden=&Apache::lonnet::EXT('resource.0.discusshide');
58: if (lc($hidden) eq 'yes' or $hidden eq '' or !defined($hidden)) {
59: return 0;
60: }
61: }
62: return 1;
63: }
64:
65: sub list_discussion {
66: my ($mode,$status,$symb)=@_;
67:
68: my $outputtarget=$ENV{'form.grade_target'};
69: if (not &discussion_visible($status)) { return ''; }
70: my @bgcols = ("#cccccc","#eeeeee");
71: my $discussiononly=0;
72: if ($mode eq 'board') { $discussiononly=1; }
73: unless ($ENV{'request.course.id'}) { return ''; }
74: my $crs='/'.$ENV{'request.course.id'};
75: if ($ENV{'request.course.sec'}) {
76: $crs.='_'.$ENV{'request.course.sec'};
77: }
78: $crs=~s/\_/\//g;
79: unless ($symb) {
80: $symb=&Apache::lonnet::symbread();
81: }
82: unless ($symb) { return ''; }
83: my %usernamesort = ();
84: my %namesort =();
85: my %subjectsort = ();
86: # backward compatibility (bulletin boards used to be 'wrapped')
87: my $ressymb=$symb;
88: if ($mode eq 'board') {
89: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
90: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
91: }
92: }
93:
94: # Get discussion display settings for this discussion
95: my $lastkey = $ressymb.'_lastread';
96: my $showkey = $ressymb.'_showonlyunread';
97: my $visitkey = $ressymb.'_visit';
98: my $ondispkey = $ressymb.'_markondisp';
99: my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$visitkey,$ondispkey],$ENV{'user.domain'},$ENV{'user.name'});
100: my %discinfo = ();
101: my $showonlyunread = 0;
102: my $markondisp = 0;
103: my $prevread = 0;
104: my $previous = 0;
105: my $visit = 0;
106: my $newpostsflag = 0;
107:
108: # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts.
109: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous','sortposts']);
110: my $sortposts = $ENV{'form.sortposts'};
111: $previous = $ENV{'form.previous'};
112: if ($previous > 0) {
113: $prevread = $previous;
114: } elsif (defined($dischash{$lastkey})) {
115: unless ($dischash{$lastkey} eq '') {
116: $prevread = $dischash{$lastkey};
117: }
118: }
119:
120: # Get discussion display default settings for user
121: my %userenv = &Apache::lonnet::get('environment',['discdisplay','discmarkread'],$ENV{'user.domain'},$ENV{'user.name'});
122: my $discdisplay=$userenv{'discdisplay'};
123: if ($discdisplay eq 'unread') {
124: $showonlyunread = 1;
125: }
126: my $discmarkread=$userenv{'discmarkread'};
127: if ($discmarkread eq 'ondisp') {
128: $markondisp = 1;
129: }
130:
131: # Override user's default if user specified display setting for this discussion
132: if (defined($dischash{$ondispkey})) {
133: $markondisp = $dischash{$ondispkey};
134: }
135: if ($markondisp) {
136: $discinfo{$lastkey} = time;
137: }
138:
139: if (defined($dischash{$showkey})) {
140: $showonlyunread = $dischash{$showkey};
141: }
142:
143: if (defined($dischash{$visitkey})) {
144: $visit = $dischash{$visitkey};
145: }
146: $visit ++;
147:
148: my $seeid=&Apache::lonnet::allowed('rin',$crs);
149: my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
150: && ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/));
151: my @discussionitems=();
152: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
153: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
154: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
155: my $visible=0;
156: my @depth=();
157: my @original=();
158: my @index=();
159: my @replies=();
160: my %alldiscussion=();
161: my %notshown = ();
162: my %newitem = ();
163: my $maxdepth=0;
164:
165: my $target='';
166: unless ($ENV{'browser.interface'} eq 'textual' ||
167: $ENV{'environment.remote'} eq 'off' ) {
168: $target='target="LONcom"';
169: }
170:
171: my $now = time;
172: $discinfo{$visitkey} = $visit;
173:
174: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
175:
176: if ($contrib{'version'}) {
177: my $oldest = $contrib{'1:timestamp'};
178: if ($prevread eq '0') {
179: $prevread = $oldest-1;
180: }
181: for (my $id=1;$id<=$contrib{'version'};$id++) {
182: my $idx=$id;
183: my $posttime = $contrib{$idx.':timestamp'};
184: if ($prevread <= $posttime) {
185: $newpostsflag = 1;
186: }
187: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
188: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
189: my $origindex='0.';
190: if ($contrib{$idx.':replyto'}) {
191: if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread')) {
192: # this is a follow-up message
193: $original[$idx]=$original[$contrib{$idx.':replyto'}];
194: $depth[$idx]=$depth[$contrib{$idx.':replyto'}]+1;
195: $origindex=$index[$contrib{$idx.':replyto'}];
196: if ($depth[$idx]>$maxdepth) { $maxdepth=$depth[$idx]; }
197: } else {
198: $original[$idx]=0;
199: $depth[$idx]=0;
200: }
201: } else {
202: # this is an original message
203: $original[$idx]=0;
204: $depth[$idx]=0;
205: }
206: if ($replies[$depth[$idx]]) {
207: $replies[$depth[$idx]]++;
208: } else {
209: $replies[$depth[$idx]]=1;
210: }
211: unless ((($hidden) && (!$seeid)) || ($deleted)) {
212: $visible++;
213: my $message=$contrib{$idx.':message'};
214: $message=~s/\n/\<br \/\>/g;
215: $message=&Apache::lontexconvert::msgtexconverted($message);
216: my $subject=$contrib{$idx.':subject'};
217: if (defined($subject)) {
218: $subject=~s/\n/\<br \/\>/g;
219: $subject=&Apache::lontexconvert::msgtexconverted($subject);
220: }
221: if ($contrib{$idx.':attachmenturl'}) {
222: my ($fname)
223: =($contrib{$idx.':attachmenturl'}=~m|/([^/]+)$|);
224: &Apache::lonnet::allowuploaded('/adm/feedback',
225: $contrib{$idx.':attachmenturl'});
226: $message.='<p>'.&mt('Attachment').
227: ': <a href="'.$contrib{$idx.':attachmenturl'}.'"><tt>'.
228: $fname.'</tt></a></p>';
229: }
230: if ($message) {
231: if ($hidden) {
232: $message='<font color="#888888">'.$message.'</font>';
233: }
234: my $screenname=&Apache::loncommon::screenname(
235: $contrib{$idx.':sendername'},
236: $contrib{$idx.':senderdomain'});
237: my $plainname=&Apache::loncommon::nickname(
238: $contrib{$idx.':sendername'},
239: $contrib{$idx.':senderdomain'});
240:
241: my $sender=&mt('Anonymous');
242: # Set up for sorting by subject
243: if ($contrib{$idx.':subject'} eq '') {
244: if (defined($subjectsort{'__No subject'})) {
245: push @{$subjectsort{'__No subject'}}, $idx;
246: } else {
247: @{$subjectsort{'__No subject'}} = ("$idx");
248: }
249: } else {
250: if (defined($subjectsort{$contrib{$idx.':subject'}})) {
251: push @{$subjectsort{$contrib{$idx.':subject'}}}, $idx;
252: } else {
253: @{$subjectsort{$contrib{$idx.':subject'}}} = ("$idx");
254: }
255: }
256: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
257: $sender=&Apache::loncommon::aboutmewrapper(
258: $plainname,
259: $contrib{$idx.':sendername'},
260: $contrib{$idx.':senderdomain'}).' ('.
261: $contrib{$idx.':sendername'}.' at '.
262: $contrib{$idx.':senderdomain'}.')';
263: if ($contrib{$idx.':anonymous'}) {
264: $sender.=' ['.&mt('anonymous').'] '.
265: $screenname;
266: }
267: # Set up for sorting by domain, then username
268: unless (defined($usernamesort{$contrib{$idx.':senderdomain'}})) {
269: %{$usernamesort{$contrib{$idx.':senderdomain'}}} = ();
270: }
271: if (defined($usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}})) {
272: push @{$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}}, $idx;
273: } else {
274: @{$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}} = ("$idx");
275: }
276: # Set up for sorting by last name, then first name
277: my %names = &Apache::lonnet::get('environment',['firstname','lastname'],
278: $contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
279: my $lastname = $names{'lastname'};
280: my $firstname = $names{'firstname'};
281: if ($lastname eq '') {
282: $lastname = '_';
283: }
284: if ($firstname eq '') {
285: $firstname = '_';
286: }
287: unless (defined($namesort{$lastname})) {
288: %{$namesort{$lastname}} = ();
289: }
290: if (defined($namesort{$lastname}{$firstname})) {
291: push @{$namesort{$lastname}{$firstname}}, $idx;
292: } else {
293: @{$namesort{$lastname}{$firstname}} = ("$idx");
294: }
295: if ($seeid) {
296: if ($hidden) {
297: $sender.=' <a href="/adm/feedback?unhide='.
298: $ressymb.':::'.$idx;
299: if ($newpostsflag) {
300: $sender .= '&previous='.$prevread;
301: }
302: $sender .= '">'.&mt('Make Visible').'</a>';
303: } else {
304: $sender.=' <a href="/adm/feedback?hide='.
305: $ressymb.':::'.$idx;
306: if ($newpostsflag) {
307: $sender .= '&previous='.$prevread;
308: }
309: $sender .= '">'.&mt('Hide').'</a>';
310: }
311: $sender.=' <a href="/adm/feedback?deldisc='.
312: $ressymb.':::'.$idx;
313: if ($newpostsflag) {
314: $sender .= '&previous='.$prevread;
315: }
316: $sender .= '">'.&mt('Delete').'</a>';
317: }
318: } else {
319: if ($screenname) {
320: $sender='<i>'.$screenname.'</i>';
321: }
322: # Set up for sorting by domain, then username for anonymous
323: unless (defined($usernamesort{'__anon'})) {
324: %{$usernamesort{'__anon'}} = ();
325: }
326: if (defined($usernamesort{'__anon'}{'__anon'})) {
327: push @{$usernamesort{'__anon'}{'__anon'}}, $idx;
328: } else {
329: @{$usernamesort{'__anon'}{'__anon'}} = ("$idx");
330: }
331: # Set up for sorting by last name, then first name for anonymous
332: unless (defined($namesort{'__anon'})) {
333: %{$namesort{'__anon'}} = ();
334: }
335: if (defined($namesort{'__anon'}{'__anon'})) {
336: push @{$namesort{'__anon'}{'__anon'}}, $idx;
337: } else {
338: @{$namesort{'__anon'}{'__anon'}} = ("$idx");
339: }
340: }
341: if (&discussion_open($status) &&
342: &Apache::lonnet::allowed('pch',
343: $ENV{'request.course.id'}.
344: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
345: $sender.=' <a href="/adm/feedback?replydisc='.
346: $ressymb.':::'.$idx;
347: if ($newpostsflag) {
348: $sender .= '&previous='.$prevread;
349: }
350: $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
351: }
352: my $vgrlink;
353: if ($viewgrades) {
354: $vgrlink=&Apache::loncommon::submlink('Submissions',
355: $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb);
356: }
357: #figure out at what position this needs to print
358: my $thisindex=$idx;
359: if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread')) {
360: $thisindex=$origindex.substr('00'.$replies[$depth[$idx]],-2,2);
361: }
362: $alldiscussion{$thisindex}=$idx;
363: $index[$idx]=$thisindex;
364: my $spansize = 2;
365: if ($showonlyunread && $prevread > $posttime) {
366: $notshown{$idx} = 1;
367: } else {
368: if ($prevread > 0 && $prevread <= $posttime) {
369: $newitem{$idx} = 1;
370: $discussionitems[$idx] .= '
371: <p><table border="0" width="100%">
372: <tr><td align="left"><font color="#FF0000"><b>NEW</b></font></td>';
373: } else {
374: $newitem{$idx} = 0;
375: $discussionitems[$idx] .= '
376: <p><table border="0" width="100%">
377: <tr><td align="left"> </td>';
378: }
379: $discussionitems[$idx] .= '<td align ="left"> '.
380: '<b>'.$subject.'</b> '.
381: $sender.'</b> '.$vgrlink.' ('.
382: localtime($posttime).')</td></tr>'.
383: '</table><blockquote>'.$message.'</blockquote></p>';
384: }
385: }
386: }
387: }
388: }
389:
390: my $discussion='';
391:
392: my $function = &Apache::loncommon::get_users_function();
393: my $color = &Apache::loncommon::designparm($function.'.tabbg',
394: $ENV{'user.domain'});
395: my %lt = &Apache::lonlocal::texthash(
396: 'cuse' => 'Current discussion settings',
397: 'allposts' => 'All posts',
398: 'unread' => 'New posts only',
399: 'ondisp' => 'Once displayed',
400: 'onmark' => 'Once marked read',
401: 'disa' => 'Posts to be displayed',
402: 'npce' => 'Posts cease to be marked "NEW"',
403: 'chgt' => 'Change',
404: 'disp' => 'Display',
405: 'nolo' => 'Not new',
406: );
407:
408: my $currdisp = $lt{'allposts'};
409: my $currmark = $lt{'onmark'};
410: my $dispchange = $lt{'unread'};
411: my $markchange = $lt{'ondisp'};
412: my $chglink = '/adm/feedback?modifydisp='.$ressymb;
413: my $displink = 'onlyunread';
414: my $marklink = 'markondisp';
415:
416: if ($markondisp) {
417: $currmark = $lt{'ondisp'};
418: $markchange = $lt{'onmark'};
419: $marklink = 'markonread';
420: }
421:
422: if ($showonlyunread) {
423: $currdisp = $lt{'unread'};
424: $dispchange = $lt{'allposts'};
425: $displink = 'allposts';
426: }
427:
428: $chglink .= '&changes='.$displink.'_'.$marklink;
429:
430: if ($newpostsflag) {
431: $chglink .= '&previous='.$prevread;
432: }
433:
434: if ($visible) {
435: # Print the discusssion
436: if ($outputtarget ne 'tex') {
437: my $colspan=$maxdepth+1;
438: $discussion.='<table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
439: $discussion .='<tr><td bgcolor="#DDDDBB" colspan="'.$colspan.'">'.
440: '<table border="0" width="100%" bgcolor="#DDDDBB"><tr>';
441: if ($visible>2) {
442: $discussion.='<td align="left">'.
443: '<a href="/adm/feedback?threadedon='.$ressymb;
444: if ($newpostsflag) {
445: $discussion .= '&previous='.$prevread;
446: }
447: $discussion .='">'.&mt('Threaded View').'</a> '.
448: '<a href="/adm/feedback?threadedoff='.$ressymb;
449: if ($newpostsflag) {
450: $discussion .= '&previous='.$prevread;
451: }
452: $discussion .='">'.&mt('Chronological View').'</a>
453: <a href= "/adm/feedback?sortfilter='.$ressymb;
454: if ($newpostsflag) {
455: $discussion .= '&previous='.$prevread;
456: }
457: $discussion .='">'.&mt('Sorting/Filtering options').'</a>  ';
458: } else {
459: $discussion .= '<td align="left">';
460: }
461: $discussion .='<a href= "/adm/feedback?export='.$ressymb;
462: if ($newpostsflag) {
463: $discussion .= '&previous='.$prevread;
464: }
465: $discussion .= '">'.&mt('Export').'?</a> </td>';
466: if ($newpostsflag) {
467: if (!$markondisp) {
468: $discussion .='<td align="right"><a href="/adm/feedback?markread='.$ressymb.'">'.&mt('Mark new posts as read').'</a> ';
469: } else {
470: $discussion .= '<td> </td>';
471: }
472: } else {
473: $discussion .= '<td> </td>';
474: }
475: $discussion .= '</tr></table></td></tr>';
476: } else {
477: $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.
478: '\textbf{DISCUSSIONS}\makebox[2 cm][b]{\hrulefill}'.
479: '\vskip 0 mm\noindent\textbf{'.$lt{'cuse'}.'}:\vskip 0 mm'.
480: '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'.
481: '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}';
482: }
483: my $numhidden = keys %notshown;
484: if ($numhidden > 0) {
485: my $colspan = $maxdepth+1;
486: $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
487: '<a href="/adm/feedback?allposts='.$ressymb;
488: if ($newpostsflag) {
489: $discussion .= '&previous='.$prevread;
490: }
491: $discussion .= '">'.&mt('Show all posts').'</a> '.&mt('to display').' '.
492: $numhidden.' '.&mt('previously viewed posts').
493: '<br/></td></tr>';
494: }
495:
496: # Choose sort mechanism
497: my @showposts = ();
498: if ($sortposts eq 'descdate') {
499: @showposts = (sort { $b <=> $a } keys %alldiscussion);
500: } elsif ($sortposts eq 'thread') {
501: @showposts = (sort { $a <=> $b } keys %alldiscussion);
502: } elsif ($sortposts eq 'subject') {
503: foreach (sort keys %subjectsort) {
504: push @showposts, @{$subjectsort{$_}};
505: }
506: } elsif ($sortposts eq 'username') {
507: foreach my $domain (sort keys %usernamesort) {
508: foreach (sort keys %{$usernamesort{$domain}}) {
509: push @showposts, @{$usernamesort{$domain}{$_}};
510: }
511: }
512: } elsif ($sortposts eq 'lastfirst') {
513: foreach my $last (sort keys %namesort) {
514: foreach (sort keys %{$namesort{$last}}) {
515: push @showposts, @{$namesort{$last}{$_}};
516: }
517: }
518: } else {
519: $sortposts = 'ascdate';
520: @showposts = (sort { $a <=> $b } keys %alldiscussion);
521: }
522: foreach (@showposts) {
523: unless (($sortposts eq 'thread') || ($sortposts eq 'ascdate' && $ENV{'environment.threadeddiscussion'})) {
524: $alldiscussion{$_} = $_;
525: }
526: unless ($notshown{$alldiscussion{$_}} eq '1') {
527: if ($outputtarget ne 'tex') {
528: $discussion.="\n<tr>";
529: } else {
530: $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}';
531: }
532: my $thisdepth=$depth[$alldiscussion{$_}];
533: if ($outputtarget ne 'tex') {
534: for (1..$thisdepth) {
535: $discussion.='<td> </td>';
536: }
537: }
538: my $colspan=$maxdepth-$thisdepth+1;
539: if ($outputtarget ne 'tex') {
540: $discussion.='<td bgcolor="'.$bgcols[$newitem{$alldiscussion{$_}}].'" colspan="'.$colspan.'">'.
541: $discussionitems[$alldiscussion{$_}].
542: '</td></tr>';
543: } else {
544: #cleanup block
545: $discussionitems[$alldiscussion{$_}]=~s/<table([^>]*)>/<table TeXwidth="90 mm">/;
546: $discussionitems[$alldiscussion{$_}]=~s/<tr([^>]*)><td([^>]*)>/<tr><td TeXwidth="20 mm" align="left">/;
547: my $threadinsert='';
548: if ($thisdepth > 0) {
549: $threadinsert='<br /><strong>Reply: '.$thisdepth.'</strong>';
550: }
551: $discussionitems[$alldiscussion{$_}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;
552: $discussionitems[$alldiscussion{$_}]=~s/<a([^>]+)>(Hide|Delete|Reply|Submissions)<\/a>//g;
553: $discussionitems[$alldiscussion{$_}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;
554:
555: #FIXME xmlparse can't be safely called from inside xmlparse
556: # due to the global variables that are use, the safe
557: # space etc. I expect this has unforseen issues that
558: # need resolving.
559:
560: $discussion.=&Apache::lonxml::xmlparse('','tex',$discussionitems[$alldiscussion{$_}]);
561: }
562: }
563: }
564: if ($outputtarget ne 'tex') {
565: my $colspan=$maxdepth+1;
566: $discussion .= <<END;
567: <tr bgcolor="#FFFFFF">
568: <td colspan="$colspan" valign="top">
569: <table border="0" bgcolor="#FFFFFF" width="100%" cellspacing="2" cellpadding="2">
570: <tr>
571: <td align="left">
572: <table border="0" cellpadding="0" cellspacing="4">
573: <tr>
574: <td>
575: <font size="-1"><b>$lt{'cuse'}</b>:</td>
576: <td> </td>
577: END
578: if ($newpostsflag) {
579: $discussion .=
580: '<td><font size="-1">1. '.$lt{'disp'}.' - <i>'.$currdisp.'</i> 2. '.$lt{'nolo'}.' - <i>'.$currmark.'</i></font></td>';
581: } else {
582: $discussion .=
583: '<td><font size="-1">'.$lt{'disp'}.' - <i>'.$currdisp.'</i></font></td>';
584: }
585: $discussion .= <<END;
586: <td> </td>
587: <td>
588: <font size="-1"><b><a href="$chglink">$lt{'chgt'}</a>?</font></b></td>
589: </tr>
590: </table>
591: </td>
592: </tr>
593: </table>
594: </td>
595: </tr>
596: </table>
597: <br /><br />
598: END
599: }
600: }
601: if ($discussiononly) {
602: $discussion.=(<<ENDDISCUSS);
603: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
604: <input type="submit" name="discuss" value="Post Discussion" />
605: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
606: <input type="hidden" name="symb" value="$ressymb" />
607: <input type="hidden" name="sendit" value="true" />
608: <br />
609: <font size="1">Note: in anonymous discussion, your name is visible only to
610: course faculty</font><br />
611: <b>Title:</b> <input type="text" name="subject" value="" size="30" /><br /><br />
612: <textarea name="comment" cols="80" rows="14" wrap="hard"></textarea>
613: <p>
614: Attachment (128 KB max size): <input type="file" name="attachment" />
615: </p>
616: </form>
617: ENDDISCUSS
618: if ($outputtarget ne 'tex') {
619: $discussion.=&generate_preview_button();
620: }
621: } else {
622: if (&discussion_open($status) &&
623: &Apache::lonnet::allowed('pch',
624: $ENV{'request.course.id'}.
625: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
626: if ($outputtarget ne 'tex') {
627: $discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
628: $symb.':::" '.$target.'>'.
629: '<img src="/adm/lonMisc/chat.gif" border="0" />'.
630: &mt('Post Discussion').'</a></td></tr></table>';
631: }
632: }
633: }
634: return $discussion;
635: }
636:
637: sub mail_screen {
638: my ($r,$feedurl,$options) = @_;
639: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
640: '','onLoad="window.focus();"');
641: my $title=&Apache::lonnet::gettitle($feedurl);
642: if (!$title) { $title = $feedurl; }
643: my $quote='';
644: my $subject = '';
645: my $prevtag = '';
646: if ($ENV{'form.replydisc'}) {
647: my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
648: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
649: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
650: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
651: unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
652: my $message=$contrib{$idx.':message'};
653: $message=~s/\n/\<br \/\>/g;
654: $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
655: if ($idx > 0) {
656: $subject = 'Re: '.$contrib{$idx.':subject'};
657: }
658: }
659: if ($ENV{'form.previous'}) {
660: $prevtag = '<input type="hidden" name="previous" value="'.$ENV{'form.previous'}.'" />';
661: }
662: }
663: my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
664: my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
665: my $onsubmit='';
666: if ((&Apache::lonhtmlcommon::htmlareabrowser()) &&
667: (!&Apache::lonhtmlcommon::htmlareablocked())) {
668: $onsubmit='document.mailform.onsubmit();';
669: }
670: my $send=&mt('Send');
671: $r->print(<<ENDDOCUMENT);
672: <html>
673: <head>
674: <title>The LearningOnline Network with CAPA</title>
675: <meta http-equiv="pragma" content="no-cache"></meta>
676: $htmlheader
677: <script type="text/javascript">
678: //<!--
679: function gosubmit() {
680: var rec=0;
681: if (typeof(document.mailform.elements.author)!="undefined") {
682: if (document.mailform.elements.author.checked) {
683: rec=1;
684: }
685: }
686: if (typeof(document.mailform.elements.question)!="undefined") {
687: if (document.mailform.elements.question.checked) {
688: rec=1;
689: }
690: }
691: if (typeof(document.mailform.elements.course)!="undefined") {
692: if (document.mailform.elements.course.checked) {
693: rec=1;
694: }
695: }
696: if (typeof(document.mailform.elements.policy)!="undefined") {
697: if (document.mailform.elements.policy.checked) {
698: rec=1;
699: }
700: }
701: if (typeof(document.mailform.elements.discuss)!="undefined") {
702: if (document.mailform.elements.discuss.checked) {
703: rec=1;
704: }
705: }
706: if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
707: if (document.mailform.elements.anondiscuss.checked) {
708: rec=1;
709: }
710: }
711:
712: if (rec) {
713: $onsubmit
714: document.mailform.submit();
715: } else {
716: alert('Please check a feedback type.');
717: }
718: }
719: //-->
720: </script>
721: </head>
722: $bodytag
723: <h2><tt>$title</tt></h2>
724: <form action="/adm/feedback" method="post" name="mailform"
725: enctype="multipart/form-data">
726: $prevtag
727: <input type="hidden" name="postdata" value="$feedurl" />
728: <input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
729: Please check at least one of the following feedback types:
730: $options<hr />
731: $quote
732: <p>My question/comment/feedback:</p>
733: <p>
734: $latexHelp
735: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
736: <p>
737: <textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">
738: </textarea></p>
739: <p>
740: Attachment (128 KB max size): <input type="file" name="attachment" />
741: </p>
742: <p>
743: <input type="hidden" name="sendit" value="1" />
744: <input type="button" value="$send" onClick='gosubmit();' />
745: </p>
746: </form>
747: ENDDOCUMENT
748: $r->print(&generate_preview_button().
749: &Apache::lonhtmlcommon::htmlareaselectactive('comment').
750: '</body></html>');
751: }
752:
753: sub print_display_options {
754: my ($r,$symb,$previous,$dispchg,$markchg,$feedurl) = @_;
755: # backward compatibility (bulletin boards used to be 'wrapped')
756: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
757: $feedurl=~s|^/adm/wrapper||;
758: }
759:
760: my $function = &Apache::loncommon::get_users_function();
761: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
762: $ENV{'user.domain'});
763: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
764: '','');
765:
766: my %lt = &Apache::lonlocal::texthash(
767: 'dido' => 'Discussion display options',
768: 'pref' => 'Display Preference',
769: 'curr' => 'Current setting ',
770: 'actn' => 'Action',
771: 'deff' => 'Default for all discussions',
772: 'prca' => 'Preferences can be set for this discussion that determine ....',
773: 'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and',
774: 'unwh' => 'Under what circumstances posts are identfied as "New."',
775: 'allposts' => 'All posts',
776: 'unread' => 'New posts only',
777: 'ondisp' => 'Once displayed',
778: 'onmark' => 'Once marked as read',
779: 'disa' => 'Posts displayed?',
780: 'npmr' => 'New posts cease to be identified as "New"?',
781: 'chgt' => 'Change to ',
782: 'mkdf' => 'Set to ',
783: 'yhni' => 'You have not indicated that you wish to change either of the discussion settings',
784: 'ywbr' => 'You will be returned to the previous page if you click OK.'
785: );
786:
787: my $dispchange = $lt{'unread'};
788: my $markchange = $lt{'ondisp'};
789: my $currdisp = $lt{'allposts'};
790: my $currmark = $lt{'onmark'};
791: my $discdisp = 'allposts';
792: my $discmark = 'onmark';
793:
794: if ($dispchg eq 'allposts') {
795: $dispchange = $lt{'allposts'};
796: $currdisp = $lt{'unread'};
797: $discdisp = 'unread';
798: }
799:
800: if ($markchg eq 'markonread') {
801: $markchange = $lt{'onmark'};
802: $currmark = $lt{'ondisp'};
803: $discmark = 'ondisp';
804: }
805: $r->print(<<END);
806: <html>
807: <head>
808: <title>$lt{'dido'}</title>
809: <meta http-equiv="pragma" content="no-cache" />
810: <script>
811: function setDisp() {
812: var prev = "$previous"
813: var chktotal = 0
814: if (document.modifydisp.discdisp.checked == true) {
815: document.modifydisp.$dispchg.value = "$symb"
816: chktotal ++
817: }
818: if (document.modifydisp.discmark.checked == true) {
819: document.modifydisp.$markchg.value = "$symb"
820: chktotal ++
821: }
822: if (chktotal > 0) {
823: document.modifydisp.submit()
824: } else {
825: if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}")) {
826: if (prev > 0) {
827: location.href = "$feedurl?previous=$previous"
828: } else {
829: location.href = "$feedurl"
830: }
831: }
832: }
833: }
834: </script>
835: </head>
836: $bodytag
837: <form name="modifydisp" method="post" action="/adm/feedback">
838: $lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
839: <br />
840: <table border="0" cellpadding="0" cellspacing="0">
841: <tr>
842: <td width="100%" bgcolor="#000000">
843: <table width="100%" border="0" cellpadding="1" cellspacing="0">
844: <tr>
845: <td width="100%" bgcolor="#000000">
846: <table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
847: <tr bgcolor="$tabcolor">
848: <td><b>$lt{'pref'}</b></td>
849: <td><b>$lt{'curr'}</b></td>
850: <td><b>$lt{'actn'}?</b></td>
851: </tr>
852: <tr bgcolor="#dddddd">
853: <td>$lt{'disa'}</td>
854: <td>$lt{$discdisp}</td>
855: <td><input type="checkbox" name="discdisp" /> $lt{'chgt'} "$dispchange"</td>
856: </tr><tr bgcolor="#eeeeee">
857: <td>$lt{'npmr'}</td>
858: <td>$lt{$discmark}</td>
859: <td><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</td>
860: </tr>
861: </table>
862: </td>
863: </tr>
864: </table>
865: </td>
866: </tr>
867: </table>
868: <br />
869: <br />
870: <input type="hidden" name="previous" value="$previous" />
871: <input type="hidden" name="$dispchg" value=""/>
872: <input type="hidden" name="$markchg" value=""/>
873: <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />
874: <br />
875: <br />
876: </form>
877: </body>
878: </html>
879: END
880: return;
881: }
882:
883: sub print_sortfilter_options {
884: my ($r,$symb,$previous,$feedurl) = @_;
885: # backward compatibility (bulletin boards used to be 'wrapped')
886: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
887: $feedurl=~s|^/adm/wrapper||;
888: }
889: my @sections = ();
890: my $section_sel = '';
891: my $numsections = 0;
892: my $numvisible = 5;
893: my ($classlist) = &Apache::loncoursedata::get_classlist(
894: $ENV{'request.course.id'},
895: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
896: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
897:
898: my $sec_index = &Apache::loncoursedata::CL_SECTION();
899: my $status_index = &Apache::loncoursedata::CL_STATUS();
900: my %sectioncount = ();
901: while (my ($student,$data) = each %$classlist) {
902: my ($section,$status) = ($data->[$sec_index],
903: $data->[$status_index]);
904: unless ($section eq '' || $section =~ /^\s*$/) {
905: if (!defined($sectioncount{$section})) {
906: $sectioncount{$section} = 1;
907: $numsections ++;
908: } else {
909: $sectioncount{$section} ++;
910: }
911: }
912: }
913:
914: if ($ENV{'request.course.sec'} !~ /^\s*$/) {
915: @sections = ($ENV{'request.course.sec'});
916: $numvisible = 1;
917: } else {
918: @sections = sort {$a cmp $b} keys(%sectioncount);
919: unshift(@sections,'all'); # Put 'all' at the front of the list
920: if ($numsections < 4) {
921: $numvisible = $numsections + 1;
922: }
923: }
924: foreach (@sections) {
925: $section_sel .= " <option value=\"$_\" />$_\n";
926: }
927:
928: my $function = &Apache::loncommon::get_users_function();
929: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
930: $ENV{'user.domain'});
931: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
932: '','');
933: my %lt = &Apache::lonlocal::texthash(
934: 'diso' => 'Discussion sorting and filtering options',
935: 'diop' => 'Display Options',
936: 'curr' => 'Current setting ',
937: 'actn' => 'Action',
938: 'prca' => 'Options can be set that control the sort order of the posts, in
939: addition to which posts are displayed.',
940: 'soor' => 'Sort order',
941: 'disp' => 'Specific user roles',
942: 'actv' => 'Specific role status',
943: 'spse' => 'Specific sections',
944: 'psub' => 'Pick specific users (by name)',
945: 'shal' => 'Show a list of current posters',
946: 'yhni' => 'You have not indicated that you do not wish to change any of the discussion settings',
947: 'ywbr' => 'You will be returned to the previous page if you click OK.'
948: );
949: $r->print(<<END);
950: <html>
951: <head>
952: <title>$lt{'diso'}</title>
953: <meta http-equiv="pragma" content="no-cache" />
954: </head>
955: $bodytag
956: <form name="modifyshown" method="post" action="/adm/feedback">
957: <b>$lt{'diso'}</b><br/> $lt{'prca'}
958: <br /><br />
959: <table border="0">
960: <tr>
961: <td><b>$lt{'soor'}</b></td>
962: <td> </td>
963: <td><b>$lt{'disp'}</b></td>
964: <td> </td>
965: <td><b>$lt{'actv'}</b></td>
966: <td> </td>
967: <td><b>$lt{'spse'}</b></td>
968: <td> </td>
969: <td><b>$lt{'psub'}</b></td>
970: </tr>
971: <tr>
972: <td>
973: <select name="sortposts">
974: <option value="ascdate" />Date order - oldest first
975: <option value="descdate" />Date order - newest first
976: <option value="thread" />Threaded
977: <option value="subject" />By subject
978: <option value="username" />By domain and username
979: <option value="lastfirst" />By last name, first name
980: </select>
981: </td>
982: <td> </td>
983: <td>
984: <select name="filterposts" multiple="true" size="5">
985: <option value="all" />All users
986: <option value="st" />Students
987: <option value="cc" />Course Coordinators
988: <option value="in" />Instructors
989: <option value="ta" />TAs
990: <option value="pr" />Exam proctors
991: <option value="cr" />Custom roles
992: </select>
993: </td>
994: <td> </td>
995: <td>
996: <select name="statusfilter">
997: <option value="all" />Roles of any status
998: <option value="act" />Only active roles
999: <option value="ina" />Only inactive roles
1000: </select>
1001: </td>
1002: <td> </td>
1003: <td>
1004: <select name="sectionpick" multiple="true" size="$numvisible">
1005: $section_sel
1006: </select>
1007: </td>
1008: <td> </td>
1009: <td><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</td>
1010: </tr>
1011: </table>
1012: <br />
1013: <br />
1014: <input type="hidden" name="previous" value="$previous" />
1015: <input type="hidden" name="applysort" value="$symb" />
1016: <input type="button" name="sub" value="Store Changes" onClick="javascript:document.modifyshown.submit()" />
1017: <br />
1018: <br />
1019: </form>
1020: </body>
1021: </html>
1022: END
1023: }
1024:
1025: sub fail_redirect {
1026: my ($r,$feedurl) = @_;
1027: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1028: $r->print (<<ENDFAILREDIR);
1029: <html>
1030: <head><title>Feedback not sent</title>
1031: <meta http-equiv="pragma" content="no-cache" />
1032: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1033: </head>
1034: <body bgcolor="#FFFFFF">
1035: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1036: <b>Sorry, no recipients ...</b>
1037: </body>
1038: </html>
1039: ENDFAILREDIR
1040: }
1041:
1042: sub redirect_back {
1043: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous,$sort) = @_;
1044: my $sorttag = '';
1045: my $prevtag = '';
1046: my $qrystr = '';
1047: # backward compatibility (bulletin boards used to be 'wrapped')
1048: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1049: $feedurl=~s|^/adm/wrapper||;
1050: }
1051: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1052: if ($previous > 0) {
1053: $qrystr = 'previous='.$previous;
1054: if ($feedurl =~ /\?register=1/) {
1055: $feedurl .= '&'.$qrystr;
1056: } else {
1057: $feedurl .= '?'.$qrystr;
1058: }
1059: $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
1060: }
1061: if (defined($sort)) {
1062: my $sortqry = 'sortposts='.$sort;
1063: if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) {
1064: $feedurl .= '&'.$sortqry;
1065: } else {
1066: $feedurl .= '?'.$sortqry;
1067: }
1068: $sorttag = '<input type="hidden" name="sortposts" value="'.$sort.'" />';
1069: }
1070: $r->print (<<ENDREDIR);
1071: <html>
1072: <head>
1073: <title>Feedback sent</title>
1074: <meta http-equiv="pragma" content="no-cache" />
1075: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1076: </head>
1077: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1078: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1079: $typestyle
1080: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1081: <font color="red">$status</font>
1082: <form name="reldt" action="$feedurl" target="loncapaclient">
1083: $prevtag
1084: $sorttag
1085: </form>
1086: </body>
1087: </html>
1088: ENDREDIR
1089: }
1090:
1091: sub no_redirect_back {
1092: my ($r,$feedurl) = @_;
1093: $r->print (<<ENDNOREDIR);
1094: <html>
1095: <head><title>Feedback not sent</title>
1096: <meta http-equiv="pragma" content="no-cache" />
1097: ENDNOREDIR
1098:
1099: if ($feedurl!~/^\/adm\/feedback/) {
1100: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
1101: }
1102:
1103: $r->print (<<ENDNOREDIRTWO);
1104: </head>
1105: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
1106: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1107: <b>Sorry, no feedback possible on this resource ...</b>
1108: </body>
1109: </html>
1110: ENDNOREDIRTWO
1111: }
1112:
1113: sub screen_header {
1114: my ($feedurl) = @_;
1115: my $msgoptions='';
1116: my $discussoptions='';
1117: unless ($ENV{'form.replydisc'}) {
1118: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
1119: $msgoptions=
1120: '<p><input type="checkbox" name="author" /> '.
1121: &mt('Feedback to resource author').'</p>';
1122: }
1123: if (&feedback_available(1)) {
1124: $msgoptions.=
1125: '<br /><input type="checkbox" name="question" /> '.
1126: &mt('Question about resource content');
1127: }
1128: if (&feedback_available(0,1)) {
1129: $msgoptions.=
1130: '<br /><input type="checkbox" name="course" /> '.
1131: &mt('Question/Comment/Feedback about course content');
1132: }
1133: if (&feedback_available(0,0,1)) {
1134: $msgoptions.=
1135: '<br /><input type="checkbox" name="policy" /> '.
1136: &mt('Question/Comment/Feedback about course policy');
1137: }
1138: }
1139: if ($ENV{'request.course.id'}) {
1140: if (&discussion_open() &&
1141: &Apache::lonnet::allowed('pch',
1142: $ENV{'request.course.id'}.
1143: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1144: $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
1145: ($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
1146: &mt('Contribution to course discussion of resource');
1147: $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
1148: &mt('Anonymous contribution to course discussion of resource').
1149: ' <i>('.&mt('name only visible to course faculty').')</i>';
1150: }
1151: }
1152: if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
1153: if ($discussoptions) {
1154: $discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
1155: return $msgoptions.$discussoptions;
1156: }
1157:
1158: sub resource_output {
1159: my ($feedurl) = @_;
1160: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1161: $usersaw=~s/\<body[^\>]*\>//gi;
1162: $usersaw=~s/\<\/body\>//gi;
1163: $usersaw=~s/\<html\>//gi;
1164: $usersaw=~s/\<\/html\>//gi;
1165: $usersaw=~s/\<head\>//gi;
1166: $usersaw=~s/\<\/head\>//gi;
1167: $usersaw=~s/action\s*\=/would_be_action\=/gi;
1168: return $usersaw;
1169: }
1170:
1171: sub clear_out_html {
1172: my ($message,$override)=@_;
1173: unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
1174: my $cid=$ENV{'request.course.id'};
1175: if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
1176: ($override)) {
1177: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
1178: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
1179: # <SUP>
1180: my %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
1181: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
1182: M=>1, SUB=>1, SUP=>1, SPAN=>1,
1183: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
1184:
1185: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1186: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
1187: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1188: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
1189: } else {
1190: $message=~s/\</\<\;/g;
1191: $message=~s/\>/\>\;/g;
1192: }
1193: return $message;
1194: }
1195:
1196: sub assemble_email {
1197: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1198: my $email=<<"ENDEMAIL";
1199: Refers to <a href="$feedurl">$feedurl</a>
1200:
1201: $message
1202: ENDEMAIL
1203: my $citations=<<"ENDCITE";
1204: <h2>Previous attempts of student (if applicable)</h2>
1205: $prevattempts
1206: <br /><hr />
1207: <h2>Original screen output (if applicable)</h2>
1208: $usersaw
1209: <h2>Correct Answer(s) (if applicable)</h2>
1210: $useranswer
1211: ENDCITE
1212: return ($email,$citations);
1213: }
1214:
1215: sub secapply {
1216: my $rec=shift;
1217: my $defaultflag=shift;
1218: $rec=~s/\s+//g;
1219: $rec=~s/\@/\:/g;
1220: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
1221: if ($sections) {
1222: foreach (split(/\;/,$sections)) {
1223: if (($_ eq $ENV{'request.course.sec'}) ||
1224: ($defaultflag && ($_ eq '*'))) {
1225: return $adr;
1226: }
1227: }
1228: } else {
1229: return $rec;
1230: }
1231: return '';
1232: }
1233:
1234: sub decide_receiver {
1235: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1236: my $typestyle='';
1237: my %to=();
1238: if ($ENV{'form.author'}||$author) {
1239: $typestyle.='Submitting as Author Feedback<br>';
1240: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
1241: $to{$2.':'.$1}=1;
1242: }
1243: if ($ENV{'form.question'}||$question) {
1244: $typestyle.='Submitting as Question<br>';
1245: foreach (split(/\,/,
1246: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
1247: ) {
1248: my $rec=&secapply($_,$defaultflag);
1249: if ($rec) { $to{$rec}=1; }
1250: }
1251: }
1252: if ($ENV{'form.course'}||$course) {
1253: $typestyle.='Submitting as Comment<br />';
1254: foreach (split(/\,/,
1255: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
1256: ) {
1257: my $rec=&secapply($_,$defaultflag);
1258: if ($rec) { $to{$rec}=1; }
1259: }
1260: }
1261: if ($ENV{'form.policy'}||$policy) {
1262: $typestyle.='Submitting as Policy Feedback<br />';
1263: foreach (split(/\,/,
1264: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
1265: ) {
1266: my $rec=&secapply($_,$defaultflag);
1267: if ($rec) { $to{$rec}=1; }
1268: }
1269: }
1270: if ((scalar(%to) eq '0') && (!$defaultflag)) {
1271: ($typestyle,%to)=
1272: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
1273: }
1274: return ($typestyle,%to);
1275: }
1276:
1277: sub feedback_available {
1278: my ($question,$course,$policy)=@_;
1279: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
1280: return scalar(%to);
1281: }
1282:
1283: sub send_msg {
1284: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1285: my $status='';
1286: my $sendsomething=0;
1287: foreach (keys %to) {
1288: if ($_) {
1289: my $declutter=&Apache::lonnet::declutter($feedurl);
1290: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1291: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
1292: $attachmenturl)=~/ok/) {
1293: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1294: } else {
1295: $sendsomething++;
1296: }
1297: }
1298: }
1299:
1300: my %record=&Apache::lonnet::restore('_feedback');
1301: my ($temp)=keys %record;
1302: unless ($temp=~/^error\:/) {
1303: my %newrecord=();
1304: $newrecord{'resource'}=$feedurl;
1305: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1306: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1307: $status.='<br />'.&mt('Not registered').'<br />';
1308: }
1309: }
1310:
1311: return ($status,$sendsomething);
1312: }
1313:
1314: sub adddiscuss {
1315: my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1316: my $status='';
1317: if (&discussion_open() &&
1318: &Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
1319: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1320:
1321: my %contrib=('message' => $email,
1322: 'sendername' => $ENV{'user.name'},
1323: 'senderdomain' => $ENV{'user.domain'},
1324: 'screenname' => $ENV{'environment.screenname'},
1325: 'plainname' => $ENV{'environment.firstname'}.' '.
1326: $ENV{'environment.middlename'}.' '.
1327: $ENV{'environment.lastname'}.' '.
1328: $ENV{'enrironment.generation'},
1329: 'attachmenturl'=> $attachmenturl,
1330: 'subject' => $subject);
1331: if ($ENV{'form.replydisc'}) {
1332: $contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
1333: }
1334: if ($anon) {
1335: $contrib{'anonymous'}='true';
1336: }
1337: if (($symb) && ($email)) {
1338: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1339: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
1340: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1341: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1342: my %storenewentry=($symb => time);
1343: $status.='<br />'.&mt('Updating discussion time').': '.
1344: &Apache::lonnet::put('discussiontimes',\%storenewentry,
1345: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1346: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1347: }
1348: my %record=&Apache::lonnet::restore('_discussion');
1349: my ($temp)=keys %record;
1350: unless ($temp=~/^error\:/) {
1351: my %newrecord=();
1352: $newrecord{'resource'}=$symb;
1353: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1354: $status.='<br />'.&mt('Registering').': '.
1355: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1356: }
1357: } else {
1358: $status.='Failed.';
1359: }
1360: return $status.'<br />';
1361: }
1362:
1363: # ----------------------------------------------------------- Preview function
1364:
1365: sub show_preview {
1366: my $r=shift;
1367: my $message=&clear_out_html($ENV{'form.comment'});
1368: $message=~s/\n/\<br \/\>/g;
1369: $message=&Apache::lontexconvert::msgtexconverted($message);
1370: my $subject=&clear_out_html($ENV{'form.subject'});
1371: $subject=~s/\n/\<br \/\>/g;
1372: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1373: $r->print('<table border="2"><tr><td>'.
1374: '<b>Subject:</b> '.$subject.'<br /><br />'.
1375: $message.'</td></tr></table>');
1376: }
1377:
1378: sub generate_preview_button {
1379: my $pre=&mt("Show Preview");
1380: return(<<ENDPREVIEW);
1381: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1382: <input type="hidden" name="subject">
1383: <input type="hidden" name="comment" />
1384: <input type="button" value="$pre"
1385: onClick="document.mailform.onsubmit();this.form.comment.value=document.mailform.comment.value;this.form.subject.value=document.mailform.subject.value;this.form.submit();" />
1386: </form>
1387: ENDPREVIEW
1388: }
1389:
1390: sub handler {
1391: my $r = shift;
1392: if ($r->header_only) {
1393: &Apache::loncommon::content_type($r,'text/html');
1394: $r->send_http_header;
1395: return OK;
1396: }
1397:
1398: # --------------------------- Get query string for limited number of parameters
1399:
1400: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1401: ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff','onlyunread','allposts','previous','markread','markonread','markondisp','modifydisp','changes','navmaps','navurl','sortfilter','sortposts','applysort']);
1402: if ($ENV{'form.applysort'}) {
1403: &Apache::loncommon::content_type($r,'text/html');
1404: $r->send_http_header;
1405: my $symb=$ENV{'form.applysort'};
1406: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1407: my $previous=$ENV{'form.previous'};
1408: my $sort = $ENV{'form.sortposts'};
1409: my $filter = $ENV{'form.filterposts'};
1410: my $statusfilter = $ENV{'form.statusfilter'};
1411: my $secpick = $ENV{'form.sectionpick'};
1412: my $feedurl = &Apache::lonnet::clutter($url);
1413: # backward compatibility (bulletin boards used to be 'wrapped')
1414: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1415: $feedurl=~s|^/adm/wrapper||;
1416: }
1417: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',$previous,$sort,$filter,$secpick);
1418: return OK;
1419: } elsif ($ENV{'form.sortfilter'}) {
1420: &Apache::loncommon::content_type($r,'text/html');
1421: $r->send_http_header;
1422: my $symb=$ENV{'form.sortfilter'};
1423: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1424: my $previous=$ENV{'form.previous'};
1425: my $feedurl = &Apache::lonnet::clutter($url);
1426: # backward compatibility (bulletin boards used to be 'wrapped')
1427: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1428: $feedurl=~s|^/adm/wrapper||;
1429: }
1430: &print_sortfilter_options($r,$symb,$previous,$feedurl);
1431: return OK;
1432: } elsif ($ENV{'form.navmaps'}) {
1433: my %discinfo = ();
1434: my @resources = ();
1435: if ($ENV{'form.navmaps'} =~ /:/) {
1436: @resources = split/:/,$ENV{'form.navmaps'};
1437: } else {
1438: @resources = ("$ENV{'form.navmaps'}");
1439: }
1440: my $numitems = @resources;
1441: my $feedurl = '/adm/navmaps';
1442: if ($ENV{'form.navurl'}) {
1443: $feedurl .= '?'.$ENV{'form.navurl'};
1444: }
1445: my %lt = &Apache::lonlocal::texthash(
1446: 'mnpa' => 'Marked "New" posts as read in a total of',
1447: 'robb' => 'resources/bulletin boards.'
1448: );
1449: foreach (@resources) {
1450: # backward compatibility (bulletin boards used to be 'wrapped')
1451: my $ressymb=$_;
1452: if ($ressymb =~ m/bulletin___\d+___/) {
1453: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1454: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper/|;
1455: }
1456: }
1457: my $lastkey = $ressymb.'_lastread';
1458: $discinfo{$lastkey} = time;
1459: }
1460: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1461: &Apache::loncommon::content_type($r,'text/html');
1462: $r->send_http_header;
1463: $r->print (<<ENDREDIR);
1464: <html>
1465: <head>
1466: <title>New posts marked as read</title>
1467: <meta http-equiv="pragma" content="no-cache" />
1468: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1469: </head>
1470: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1471: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1472: <b>$lt{'mnpa'} $numitems $lt{'robb'}</b>
1473: <form name="reldt" action="$feedurl" target="loncapaclient">
1474: </form>
1475: </body>
1476: </html>
1477: ENDREDIR
1478: return OK;
1479: } elsif ($ENV{'form.modifydisp'}) {
1480: &Apache::loncommon::content_type($r,'text/html');
1481: $r->send_http_header;
1482: my $symb=$ENV{'form.modifydisp'};
1483: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1484: my $previous=$ENV{'form.previous'};
1485: my ($dispchg,$markchg) = split/_/,$ENV{'form.changes'};
1486: my $feedurl = &Apache::lonnet::clutter($url);
1487: # backward compatibility (bulletin boards used to be 'wrapped')
1488: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1489: $feedurl=~s|^/adm/wrapper||;
1490: }
1491: &print_display_options($r,$symb,$previous,$dispchg,$markchg,$feedurl);
1492: return OK;
1493: } elsif (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) ) {
1494: &Apache::loncommon::content_type($r,'text/html');
1495: $r->send_http_header;
1496: my $previous=$ENV{'form.previous'};
1497: my ($map,$ind,$url);
1498: if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
1499: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
1500: my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
1501: my $ressymb = $symb;
1502: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1503: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1504: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1505: }
1506: my %discinfo = ();
1507: my $lastkey = $ressymb.'_lastread';
1508: my $ondispkey = $ressymb.'_markondisp';
1509: if ($ENV{'form.markondisp'}) {
1510: $discinfo{$lastkey} = time;
1511: $discinfo{$ondispkey} = 1;
1512: } elsif ($ENV{'form.markonread'}) {
1513: if ( $previous > 0 ) {
1514: $discinfo{$lastkey} = $previous;
1515: }
1516: $discinfo{$ondispkey} = 0;
1517: }
1518: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1519: }
1520: if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'})) {
1521: # ----------------------------------------------------------------- Modify display setting for this discussion
1522: my $symb=$ENV{'form.allposts'}?$ENV{'form.allposts'}:$ENV{'form.onlyunread'};
1523: my $ressymb = $symb;
1524: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1525: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1526: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1527: }
1528: my %discinfo = ();
1529: if ($ENV{'form.allposts'}) {
1530: $discinfo{$ressymb.'_showonlyunread'} = 0;
1531: } elsif ($ENV{'form.onlyunread'}) {
1532: $discinfo{$ressymb.'_showonlyunread'} = 1;
1533: }
1534: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1535: }
1536: if (($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) ) {
1537: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$previous);
1538: } else {
1539: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
1540: }
1541: return OK;
1542: } elsif ($ENV{'form.markread'}) {
1543: # ----------------------------------------------------------------- Mark new posts as read
1544: &Apache::loncommon::content_type($r,'text/html');
1545: $r->send_http_header;
1546: my $symb=$ENV{'form.markread'};
1547: my $ressymb = $symb;
1548: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1549: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1550: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1551: }
1552: my %discinfo = ();
1553: my $lastkey = $ressymb.'_lastread';
1554: $discinfo{$lastkey} = time;
1555: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1556: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
1557: return OK;
1558: } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1559: # ----------------------------------------------------------------- Hide/unhide
1560: &Apache::loncommon::content_type($r,'text/html');
1561: $r->send_http_header;
1562:
1563: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
1564:
1565: my ($symb,$idx)=split(/\:\:\:/,$entry);
1566: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1567:
1568: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
1569: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1570: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1571:
1572:
1573: my $currenthidden=$contrib{'hidden'};
1574:
1575: if ($ENV{'form.hide'}) {
1576: $currenthidden.='.'.$idx.'.';
1577: } else {
1578: $currenthidden=~s/\.$idx\.//g;
1579: }
1580: my %newhash=('hidden' => $currenthidden);
1581:
1582: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
1583: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1584: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1585:
1586: &redirect_back($r,&Apache::lonnet::clutter($url),
1587: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1588: } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1589: &Apache::loncommon::content_type($r,'text/html');
1590: $r->send_http_header;
1591: if ($ENV{'form.threadedon'}) {
1592: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
1593: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
1594: } else {
1595: &Apache::lonnet::del('environment',['threadeddiscussion']);
1596: &Apache::lonnet::delenv('environment\.threadeddiscussion');
1597: }
1598: my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
1599: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1600: &redirect_back($r,&Apache::lonnet::clutter($url),
1601: &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1602: } elsif ($ENV{'form.deldisc'}) {
1603: # --------------------------------------------------------------- Hide for good
1604: &Apache::loncommon::content_type($r,'text/html');
1605: $r->send_http_header;
1606:
1607: my $entry=$ENV{'form.deldisc'};
1608:
1609: my ($symb,$idx)=split(/\:\:\:/,$entry);
1610: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1611:
1612: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
1613: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1614: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1615:
1616:
1617: my $currentdeleted=$contrib{'deleted'};
1618:
1619: $currentdeleted.='.'.$idx.'.';
1620:
1621: my %newhash=('deleted' => $currentdeleted);
1622:
1623: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
1624: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1625: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1626:
1627: &redirect_back($r,&Apache::lonnet::clutter($url),
1628: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1629: } elsif ($ENV{'form.preview'}) {
1630: # -------------------------------------------------------- User wants a preview
1631: $r->content_type('text/html');
1632: $r->send_http_header;
1633: &show_preview($r);
1634: } else {
1635: # ------------------------------------------------------------- Normal feedback
1636: my $feedurl=$ENV{'form.postdata'};
1637: $feedurl=~s/^http\:\/\///;
1638: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
1639: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1640: $feedurl=~s/\?.+$//;
1641:
1642: my $symb;
1643: if ($ENV{'form.replydisc'}) {
1644: $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
1645: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1646: $feedurl=&Apache::lonnet::clutter($url);
1647: } else {
1648: $symb=&Apache::lonnet::symbread($feedurl);
1649: }
1650: unless ($symb) {
1651: $symb=$ENV{'form.symb'};
1652: if ($symb) {
1653: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1654: $feedurl=&Apache::lonnet::clutter($url);
1655: }
1656: }
1657: my $goahead=1;
1658: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1659: unless ($symb) { $goahead=0; }
1660: }
1661: # backward compatibility (bulletin boards used to be 'wrapped')
1662: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1663: $feedurl=~s|^/adm/wrapper||;
1664: }
1665: if ($goahead) {
1666: # Go ahead with feedback, no ambiguous reference
1667: &Apache::loncommon::content_type($r,'text/html');
1668: $r->send_http_header;
1669:
1670: if (
1671: (
1672: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
1673: )
1674: ||
1675: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1676: ||
1677: ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1678: ) {
1679: # --------------------------------------------------- Print login screen header
1680: unless ($ENV{'form.sendit'}) {
1681: my $options=&screen_header($feedurl);
1682: if ($options) {
1683: &mail_screen($r,$feedurl,$options);
1684: } else {
1685: &fail_redirect($r,$feedurl);
1686: }
1687: } else {
1688:
1689: # Get previous user input
1690: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1691: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1692: $ENV{'request.course.id'});
1693:
1694: # Get output from resource
1695: my $usersaw=&resource_output($feedurl);
1696:
1697: # Get resource answer (need to allow student to view grades for this to work)
1698: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1699: my $useranswer=&Apache::loncommon::get_student_answers(
1700: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1701: $ENV{'request.course.id'});
1702: &Apache::lonnet::delenv('allowed.vgr');
1703: # Get attachments, if any, and not too large
1704: my $attachmenturl='';
1705: if ($ENV{'form.attachment.filename'}) {
1706: unless (length($ENV{'form.attachment'})>131072) {
1707: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1708: }
1709: }
1710: # Filter HTML out of message (could be nasty)
1711: my $message=&clear_out_html($ENV{'form.comment'});
1712:
1713: # Assemble email
1714: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1715: $usersaw,$useranswer);
1716:
1717: # Who gets this?
1718: my ($typestyle,%to) = &decide_receiver($feedurl);
1719:
1720: # Actually send mail
1721: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
1722: $attachmenturl,%to);
1723:
1724: # Discussion? Store that.
1725:
1726: my $numpost=0;
1727: if ($ENV{'form.discuss'}) {
1728: my $subject = &clear_out_html($ENV{'form.subject'});
1729: $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1730: $numpost++;
1731: }
1732:
1733: if ($ENV{'form.anondiscuss'}) {
1734: my $subject = &clear_out_html($ENV{'form.subject'});
1735: $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1736: $numpost++;
1737: }
1738:
1739:
1740: # Receipt screen and redirect back to where came from
1741: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1742:
1743: }
1744: } else {
1745: # Unable to give feedback
1746: &no_redirect_back($r,$feedurl);
1747: }
1748: } else {
1749: # Ambiguous Problem Resource
1750: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1751: &Apache::lonnet::cleanenv();
1752: }
1753: $r->internal_redirect('/adm/ambiguous');
1754: }
1755: }
1756: return OK;
1757: }
1758:
1759: 1;
1760: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>