1: # The LearningOnline Network
2: # Feedback
3: #
4: # $Id: lonfeedback.pm,v 1.95 2004/06/23 17:42:58 sakharuk 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:
84: # backward compatibility (bulletin boards used to be 'wrapped')
85: my $ressymb=$symb;
86: if ($mode eq 'board') {
87: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
88: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
89: }
90: }
91:
92: # Get discussion display settings for this discussion
93: my $lastkey = $ressymb.'_lastread';
94: my $showkey = $ressymb.'_showonlyunread';
95: my $visitkey = $ressymb.'_visit';
96: my $ondispkey = $ressymb.'_markondisp';
97: my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$visitkey,$ondispkey],$ENV{'user.domain'},$ENV{'user.name'});
98: my %discinfo = ();
99: my $showonlyunread = 0;
100: my $markondisp = 0;
101: my $prevread = 0;
102: my $previous = 0;
103: my $visit = 0;
104: my $newpostsflag = 0;
105:
106: # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts.
107: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous']);
108: $previous = $ENV{'form.previous'};
109: if ($previous > 0) {
110: $prevread = $previous;
111: } elsif (defined($dischash{$lastkey})) {
112: unless ($dischash{$lastkey} eq '') {
113: $prevread = $dischash{$lastkey};
114: }
115: }
116:
117: # Get discussion display default settings for user
118: my %userenv = &Apache::lonnet::get('environment',['discdisplay','discmarkread'],$ENV{'user.domain'},$ENV{'user.name'});
119: my $discdisplay=$userenv{'discdisplay'};
120: if ($discdisplay eq 'unread') {
121: $showonlyunread = 1;
122: }
123: my $discmarkread=$userenv{'discmarkread'};
124: if ($discmarkread eq 'ondisp') {
125: $markondisp = 1;
126: }
127:
128: # Override user's default if user specified display setting for this discussion
129: if (defined($dischash{$ondispkey})) {
130: $markondisp = $dischash{$ondispkey};
131: }
132: if ($markondisp) {
133: $discinfo{$lastkey} = time;
134: }
135:
136: if (defined($dischash{$showkey})) {
137: $showonlyunread = $dischash{$showkey};
138: }
139:
140: if (defined($dischash{$visitkey})) {
141: $visit = $dischash{$visitkey};
142: }
143: $visit ++;
144:
145: my $seeid=&Apache::lonnet::allowed('rin',$crs);
146: my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
147: && ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/));
148: my @discussionitems=();
149: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
150: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
151: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
152: my $visible=0;
153: my @depth=();
154: my @original=();
155: my @index=();
156: my @replies=();
157: my %alldiscussion=();
158: my %notshown = ();
159: my %newitem = ();
160: my $maxdepth=0;
161:
162: my $target='';
163: unless ($ENV{'browser.interface'} eq 'textual' ||
164: $ENV{'environment.remote'} eq 'off' ) {
165: $target='target="LONcom"';
166: }
167:
168: my $now = time;
169: $discinfo{$visitkey} = $visit;
170:
171: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
172:
173: if ($contrib{'version'}) {
174: my $oldest = $contrib{'1:timestamp'};
175: if ($prevread eq '0') {
176: $prevread = $oldest-1;
177: }
178: for (my $id=1;$id<=$contrib{'version'};$id++) {
179: my $idx=$id;
180: my $posttime = $contrib{$idx.':timestamp'};
181: if ($prevread <= $posttime) {
182: $newpostsflag = 1;
183: }
184: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
185: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
186: my $origindex='0.';
187: if (($contrib{$idx.':replyto'}) && ($ENV{'environment.threadeddiscussion'})) {
188: # this is a follow-up message
189: $original[$idx]=$original[$contrib{$idx.':replyto'}];
190: $depth[$idx]=$depth[$contrib{$idx.':replyto'}]+1;
191: $origindex=$index[$contrib{$idx.':replyto'}];
192: if ($depth[$idx]>$maxdepth) { $maxdepth=$depth[$idx]; }
193: } else {
194: # this is an original message
195: $original[$idx]=0;
196: $depth[$idx]=0;
197: }
198: if ($replies[$depth[$idx]]) {
199: $replies[$depth[$idx]]++;
200: } else {
201: $replies[$depth[$idx]]=1;
202: }
203: unless ((($hidden) && (!$seeid)) || ($deleted)) {
204: $visible++;
205: my $message=$contrib{$idx.':message'};
206: $message=~s/\n/\<br \/\>/g;
207: $message=&Apache::lontexconvert::msgtexconverted($message);
208: my $subject=$contrib{$idx.':subject'};
209: if (defined($subject)) {
210: $subject=~s/\n/\<br \/\>/g;
211: $subject=&Apache::lontexconvert::msgtexconverted($subject);
212: }
213: if ($contrib{$idx.':attachmenturl'}) {
214: my ($fname)
215: =($contrib{$idx.':attachmenturl'}=~m|/([^/]+)$|);
216: &Apache::lonnet::allowuploaded('/adm/feedback',
217: $contrib{$idx.':attachmenturl'});
218: $message.='<p>'.&mt('Attachment').
219: ': <a href="'.$contrib{$idx.':attachmenturl'}.'"><tt>'.
220: $fname.'</tt></a></p>';
221: }
222: if ($message) {
223: if ($hidden) {
224: $message='<font color="#888888">'.$message.'</font>';
225: }
226: my $screenname=&Apache::loncommon::screenname(
227: $contrib{$idx.':sendername'},
228: $contrib{$idx.':senderdomain'});
229: my $plainname=&Apache::loncommon::nickname(
230: $contrib{$idx.':sendername'},
231: $contrib{$idx.':senderdomain'});
232:
233: my $sender=&mt('Anonymous');
234: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
235: $sender=&Apache::loncommon::aboutmewrapper(
236: $plainname,
237: $contrib{$idx.':sendername'},
238: $contrib{$idx.':senderdomain'}).' ('.
239: $contrib{$idx.':sendername'}.' at '.
240: $contrib{$idx.':senderdomain'}.')';
241: if ($contrib{$idx.':anonymous'}) {
242: $sender.=' ['.&mt('anonymous').'] '.
243: $screenname;
244: }
245: if ($seeid) {
246: if ($hidden) {
247: $sender.=' <a href="/adm/feedback?unhide='.
248: $ressymb.':::'.$idx;
249: if ($newpostsflag) {
250: $sender .= '&previous='.$prevread;
251: }
252: $sender .= '">'.&mt('Make Visible').'</a>';
253: } else {
254: $sender.=' <a href="/adm/feedback?hide='.
255: $ressymb.':::'.$idx;
256: if ($newpostsflag) {
257: $sender .= '&previous='.$prevread;
258: }
259: $sender .= '">'.&mt('Hide').'</a>';
260: }
261: $sender.=' <a href="/adm/feedback?deldisc='.
262: $ressymb.':::'.$idx;
263: if ($newpostsflag) {
264: $sender .= '&previous='.$prevread;
265: }
266: $sender .= '">'.&mt('Delete').'</a>';
267: }
268: } else {
269: if ($screenname) {
270: $sender='<i>'.$screenname.'</i>';
271: }
272: }
273: if (&discussion_open($status) &&
274: &Apache::lonnet::allowed('pch',
275: $ENV{'request.course.id'}.
276: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
277: $sender.=' <a href="/adm/feedback?replydisc='.
278: $ressymb.':::'.$idx;
279: if ($newpostsflag) {
280: $sender .= '&previous='.$prevread;
281: }
282: $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
283: }
284: my $vgrlink;
285: if ($viewgrades) {
286: $vgrlink=&Apache::loncommon::submlink('Submissions',
287: $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb);
288: }
289: #figure out at what position this needs to print
290: my $thisindex=$idx;
291: if ($ENV{'environment.threadeddiscussion'}) {
292: $thisindex=$origindex.substr('00'.$replies[$depth[$idx]],-2,2);
293: }
294: $alldiscussion{$thisindex}=$idx;
295: $index[$idx]=$thisindex;
296: my $spansize = 2;
297: if ($showonlyunread && $prevread > $posttime) {
298: $notshown{$idx} = 1;
299: } else {
300: if ($prevread > 0 && $prevread <= $posttime) {
301: $newitem{$idx} = 1;
302: $discussionitems[$idx] .= '
303: <p><table border="0" width="100%">
304: <tr><td align="left"><font color="#FF0000"><b>NEW</b></font></td>';
305: } else {
306: $newitem{$idx} = 0;
307: $discussionitems[$idx] .= '
308: <p><table border="0" width="100%">
309: <tr><td align="left"> </td>';
310: }
311: $discussionitems[$idx] .= '<td align ="left"> '.
312: '<b>'.$subject.'</b> '.
313: $sender.'</b> '.$vgrlink.' ('.
314: localtime($posttime).')</td></tr>'.
315: '</table><blockquote>'.$message.'</blockquote></p>';
316: }
317: }
318: }
319: }
320: }
321:
322: my $discussion='';
323:
324: my $function = &Apache::loncommon::get_users_function();
325: my $color = &Apache::loncommon::designparm($function.'.tabbg',
326: $ENV{'user.domain'});
327: my %lt = &Apache::lonlocal::texthash(
328: 'cuse' => 'Current settings for this discussion',
329: 'allposts' => 'All posts',
330: 'unread' => 'New posts only',
331: 'ondisp' => 'Once displayed',
332: 'onmark' => 'Once marked read',
333: 'disa' => 'Posts to be displayed',
334: 'npce' => 'Posts cease to be marked "NEW"',
335: 'chgt' => 'Change to ',
336: );
337:
338: my $currdisp = $lt{'allposts'};
339: my $currmark = $lt{'onmark'};
340: my $dispchange = $lt{'unread'};
341: my $markchange = $lt{'ondisp'};
342: my $displink = '/adm/feedback?onlyunread='.$ressymb;
343: my $marklink = '/adm/feedback?markondisp='.$ressymb;
344:
345: if ($markondisp) {
346: $currmark = $lt{'ondisp'};
347: $markchange = $lt{'onmark'};
348: $marklink = '/adm/feedback?markonread='.$ressymb;
349: if ($newpostsflag) {
350: $marklink .= '&previous='.$prevread;
351: }
352: }
353:
354: if ($showonlyunread) {
355: $currdisp = $lt{'unread'};
356: $dispchange = $lt{'allposts'};
357: $displink = '/adm/feedback?allposts='.$ressymb;
358: }
359:
360: if ($newpostsflag) {
361: $displink .= '&previous='.$prevread;
362: }
363:
364: if ($visible) {
365: # Print the discusssion
366: if ($outputtarget ne 'tex') {
367: $discussion.='<table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
368: my $colspan=$maxdepth+1;
369: $discussion .= '<tr bgcolor="#FFFFFF"><td colspan="'.$colspan.'" valign="top">'.
370: '<table border="0" bgcolor="#FFFFFF" width="100%" cellspacing="2" cellpadding="2">'.
371: '<tr><td align="left"><b>'.$lt{'cuse'}.'</b></td><td> </td><td align="right"><b>'.$lt{'chgt'}.'</b></td></tr>'.
372: '<tr><td>'.$lt{'disa'}.': <i>'.$currdisp.'</i></td><td> </td><td align="right"><a href="'.$displink.'">'.$dispchange.'</a></td></tr>'.
373: '<tr><td>'.$lt{'npce'}.': <i>'.$currmark.'</i></td><td> </td><td align="right"><a href="'.$marklink.'">'.$markchange.'</a></td></tr>'.
374: '</table></td></tr>'.
375: '<tr><td bgcolor="#DDDDBB" colspan="'.$colspan.'">'.
376: '<table border="0" width="100%" bgcolor="#DDDDBB"><tr>';
377: if ($visible>2) {
378: $discussion.='<td align="left">'.
379: '<a href="/adm/feedback?threadedon='.$ressymb;
380: if ($newpostsflag) {
381: $discussion .= '&previous='.$prevread;
382: }
383: $discussion .='">'.&mt('Threaded View').'</a> '.
384: '<a href="/adm/feedback?threadedoff='.$ressymb;
385: if ($newpostsflag) {
386: $discussion .= '&previous='.$prevread;
387: }
388: $discussion .='">'.&mt('Chronological View').'</a> </td>';
389: }
390: if ($newpostsflag) {
391: if (!$markondisp) {
392: $discussion .='<td align="right"><a href="/adm/feedback?markread='.$ressymb.'">'.&mt('Mark new posts as read').'</a> ';
393: } else {
394: $discussion .= '<td> </td>';
395: }
396: } else {
397: $discussion .= '<td> </td>';
398: }
399: $discussion .= '</tr></table></td></tr>';
400: } else {
401: $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.
402: '\textbf{DISCUSSIONS}\makebox[2 cm][b]{\hrulefill}'.
403: '\vskip 0 mm\noindent\textbf{'.$lt{'cuse'}.'}:\vskip 0 mm'.
404: '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'.
405: '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}';
406: }
407: my $numhidden = keys %notshown;
408: if ($numhidden > 0) {
409: my $colspan = $maxdepth+1;
410: $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
411: '<a href="/adm/feedback?allposts='.$ressymb;
412: if ($newpostsflag) {
413: $discussion .= '&previous='.$prevread;
414: }
415: $discussion .= '">'.&mt('Show all posts').'</a> '.&mt('to display').' '.
416: $numhidden.' '.&mt('previously viewed posts').
417: '<br/></td></tr>';
418: }
419: foreach (sort { $a <=> $b } keys %alldiscussion) {
420: unless ($notshown{$alldiscussion{$_}} eq '1') {
421: if ($outputtarget ne 'tex') {
422: $discussion.="\n<tr>";
423: } else {
424: $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}';
425: }
426: my $thisdepth=$depth[$alldiscussion{$_}];
427: if ($outputtarget ne 'tex') {
428: for (1..$thisdepth) {
429: $discussion.='<td> </td>';
430: }
431: }
432: my $colspan=$maxdepth-$thisdepth+1;
433: if ($outputtarget ne 'tex') {
434: $discussion.='<td bgcolor="'.$bgcols[$newitem{$alldiscussion{$_}}].'" colspan="'.$colspan.'">'.
435: $discussionitems[$alldiscussion{$_}].
436: '</td></tr>';
437: } else {
438: #cleanup block
439: $discussionitems[$alldiscussion{$_}]=~s/<table([^>]*)>/<table TeXwidth="90 mm">/;
440: $discussionitems[$alldiscussion{$_}]=~s/<tr([^>]*)><td([^>]*)>/<tr><td TeXwidth="20 mm" align="left">/;
441: my $threadinsert='';
442: if ($thisdepth > 0) {
443: $threadinsert='<br /><strong>Reply: '.$thisdepth.'</strong>';
444: }
445: $discussionitems[$alldiscussion{$_}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;
446: $discussionitems[$alldiscussion{$_}]=~s/<a([^>]+)>(Hide|Delete|Reply|Submissions)<\/a>//g;
447: $discussionitems[$alldiscussion{$_}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;
448: $discussion.=&Apache::lonxml::xmlparse('','tex',$discussionitems[$alldiscussion{$_}]);
449: }
450: }
451: }
452: if ($outputtarget ne 'tex') {
453: $discussion.='</table><br /><br />';
454: }
455: }
456: if ($discussiononly) {
457: $discussion.=(<<ENDDISCUSS);
458: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
459: <input type="submit" name="discuss" value="Post Discussion" />
460: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
461: <input type="hidden" name="symb" value="$ressymb" />
462: <input type="hidden" name="sendit" value="true" />
463: <br />
464: <font size="1">Note: in anonymous discussion, your name is visible only to
465: course faculty</font><br />
466: <b>Title:</b> <input type="text" name="subject" value="" size="30" /><br /><br />
467: <textarea name="comment" cols="80" rows="14" wrap="hard"></textarea>
468: <p>
469: Attachment (128 KB max size): <input type="file" name="attachment" />
470: </p>
471: </form>
472: ENDDISCUSS
473: if ($outputtarget ne 'tex') {
474: $discussion.=&generate_preview_button();
475: }
476: } else {
477: if (&discussion_open($status) &&
478: &Apache::lonnet::allowed('pch',
479: $ENV{'request.course.id'}.
480: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
481: if ($outputtarget ne 'tex') {
482: $discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
483: $symb.':::" '.$target.'>'.
484: '<img src="/adm/lonMisc/chat.gif" border="0" />'.
485: &mt('Post Discussion').'</a></td></tr></table>';
486: }
487: }
488: }
489: return $discussion;
490: }
491:
492: sub mail_screen {
493: my ($r,$feedurl,$options) = @_;
494: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
495: '','onLoad="window.focus();"');
496: my $title=&Apache::lonnet::gettitle($feedurl);
497: if (!$title) { $title = $feedurl; }
498: my $quote='';
499: my $subject = '';
500: my $prevtag = '';
501: if ($ENV{'form.replydisc'}) {
502: my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
503: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
504: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
505: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
506: unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
507: my $message=$contrib{$idx.':message'};
508: $message=~s/\n/\<br \/\>/g;
509: $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
510: if ($idx > 0) {
511: $subject = 'Re: '.$contrib{$idx.':subject'};
512: }
513: }
514: if ($ENV{'form.previous'}) {
515: $prevtag = '<input type="hidden" name="previous" value="'.$ENV{'form.previous'}.'" />';
516: }
517: }
518: my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
519: my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
520: my $onsubmit='';
521: if ((&Apache::lonhtmlcommon::htmlareabrowser()) &&
522: (!&Apache::lonhtmlcommon::htmlareablocked())) {
523: $onsubmit='document.mailform.onsubmit();';
524: }
525: my $send=&mt('Send');
526: $r->print(<<ENDDOCUMENT);
527: <html>
528: <head>
529: <title>The LearningOnline Network with CAPA</title>
530: <meta http-equiv="pragma" content="no-cache"></meta>
531: $htmlheader
532: <script type="text/javascript">
533: //<!--
534: function gosubmit() {
535: var rec=0;
536: if (typeof(document.mailform.elements.author)!="undefined") {
537: if (document.mailform.elements.author.checked) {
538: rec=1;
539: }
540: }
541: if (typeof(document.mailform.elements.question)!="undefined") {
542: if (document.mailform.elements.question.checked) {
543: rec=1;
544: }
545: }
546: if (typeof(document.mailform.elements.course)!="undefined") {
547: if (document.mailform.elements.course.checked) {
548: rec=1;
549: }
550: }
551: if (typeof(document.mailform.elements.policy)!="undefined") {
552: if (document.mailform.elements.policy.checked) {
553: rec=1;
554: }
555: }
556: if (typeof(document.mailform.elements.discuss)!="undefined") {
557: if (document.mailform.elements.discuss.checked) {
558: rec=1;
559: }
560: }
561: if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
562: if (document.mailform.elements.anondiscuss.checked) {
563: rec=1;
564: }
565: }
566:
567: if (rec) {
568: $onsubmit
569: document.mailform.submit();
570: } else {
571: alert('Please check a feedback type.');
572: }
573: }
574: //-->
575: </script>
576: </head>
577: $bodytag
578: <h2><tt>$title</tt></h2>
579: <form action="/adm/feedback" method="post" name="mailform"
580: enctype="multipart/form-data">
581: $prevtag
582: <input type="hidden" name="postdata" value="$feedurl" />
583: <input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
584: Please check at least one of the following feedback types:
585: $options<hr />
586: $quote
587: <p>My question/comment/feedback:</p>
588: <p>
589: $latexHelp
590: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
591: <p>
592: <textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">
593: </textarea></p>
594: <p>
595: Attachment (128 KB max size): <input type="file" name="attachment" />
596: </p>
597: <p>
598: <input type="hidden" name="sendit" value="1" />
599: <input type="button" value="$send" onClick='gosubmit();' />
600: </p>
601: </form>
602: ENDDOCUMENT
603: $r->print(&generate_preview_button().
604: &Apache::lonhtmlcommon::htmlareaselectactive('comment').
605: '</body></html>');
606: }
607:
608: sub fail_redirect {
609: my ($r,$feedurl) = @_;
610: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
611: $r->print (<<ENDFAILREDIR);
612: <html>
613: <head><title>Feedback not sent</title>
614: <meta http-equiv="pragma" content="no-cache" />
615: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
616: </head>
617: <body bgcolor="#FFFFFF">
618: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
619: <b>Sorry, no recipients ...</b>
620: </body>
621: </html>
622: ENDFAILREDIR
623: }
624:
625: sub redirect_back {
626: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous) = @_;
627: my $prevtag = '';
628: my $qrystr = '';
629: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
630: if ($previous > 0) {
631: $qrystr = 'previous='.$previous;
632: if ($feedurl =~ /\?register=1/) {
633: $feedurl .= '&'.$qrystr;
634: } else {
635: $feedurl .= '?'.$qrystr;
636: }
637: $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
638: }
639: $r->print (<<ENDREDIR);
640: <html>
641: <head>
642: <title>Feedback sent</title>
643: <meta http-equiv="pragma" content="no-cache" />
644: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
645: </head>
646: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
647: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
648: $typestyle
649: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
650: <font color="red">$status</font>
651: <form name="reldt" action="$feedurl" target="loncapaclient">
652: $prevtag
653: </form>
654: </body>
655: </html>
656: ENDREDIR
657: }
658:
659: sub no_redirect_back {
660: my ($r,$feedurl) = @_;
661: $r->print (<<ENDNOREDIR);
662: <html>
663: <head><title>Feedback not sent</title>
664: <meta http-equiv="pragma" content="no-cache" />
665: ENDNOREDIR
666:
667: if ($feedurl!~/^\/adm\/feedback/) {
668: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
669: }
670:
671: $r->print (<<ENDNOREDIRTWO);
672: </head>
673: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
674: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
675: <b>Sorry, no feedback possible on this resource ...</b>
676: </body>
677: </html>
678: ENDNOREDIRTWO
679: }
680:
681: sub screen_header {
682: my ($feedurl) = @_;
683: my $msgoptions='';
684: my $discussoptions='';
685: unless ($ENV{'form.replydisc'}) {
686: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
687: $msgoptions=
688: '<p><input type="checkbox" name="author" /> '.
689: &mt('Feedback to resource author').'</p>';
690: }
691: if (&feedback_available(1)) {
692: $msgoptions.=
693: '<br /><input type="checkbox" name="question" /> '.
694: &mt('Question about resource content');
695: }
696: if (&feedback_available(0,1)) {
697: $msgoptions.=
698: '<br /><input type="checkbox" name="course" /> '.
699: &mt('Question/Comment/Feedback about course content');
700: }
701: if (&feedback_available(0,0,1)) {
702: $msgoptions.=
703: '<br /><input type="checkbox" name="policy" /> '.
704: &mt('Question/Comment/Feedback about course policy');
705: }
706: }
707: if ($ENV{'request.course.id'}) {
708: if (&discussion_open() &&
709: &Apache::lonnet::allowed('pch',
710: $ENV{'request.course.id'}.
711: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
712: $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
713: ($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
714: &mt('Contribution to course discussion of resource');
715: $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
716: &mt('Anonymous contribution to course discussion of resource').
717: ' <i>('.&mt('name only visible to course faculty').')</i>';
718: }
719: }
720: if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
721: if ($discussoptions) {
722: $discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
723: return $msgoptions.$discussoptions;
724: }
725:
726: sub resource_output {
727: my ($feedurl) = @_;
728: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
729: $usersaw=~s/\<body[^\>]*\>//gi;
730: $usersaw=~s/\<\/body\>//gi;
731: $usersaw=~s/\<html\>//gi;
732: $usersaw=~s/\<\/html\>//gi;
733: $usersaw=~s/\<head\>//gi;
734: $usersaw=~s/\<\/head\>//gi;
735: $usersaw=~s/action\s*\=/would_be_action\=/gi;
736: return $usersaw;
737: }
738:
739: sub clear_out_html {
740: my ($message,$override)=@_;
741: unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
742: my $cid=$ENV{'request.course.id'};
743: if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
744: ($override)) {
745: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
746: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
747: # <SUP>
748: my %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
749: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
750: M=>1, SUB=>1, SUP=>1, SPAN=>1,
751: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
752:
753: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
754: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
755: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
756: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
757: } else {
758: $message=~s/\</\<\;/g;
759: $message=~s/\>/\>\;/g;
760: }
761: return $message;
762: }
763:
764: sub assemble_email {
765: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
766: my $email=<<"ENDEMAIL";
767: Refers to <a href="$feedurl">$feedurl</a>
768:
769: $message
770: ENDEMAIL
771: my $citations=<<"ENDCITE";
772: <h2>Previous attempts of student (if applicable)</h2>
773: $prevattempts
774: <br /><hr />
775: <h2>Original screen output (if applicable)</h2>
776: $usersaw
777: <h2>Correct Answer(s) (if applicable)</h2>
778: $useranswer
779: ENDCITE
780: return ($email,$citations);
781: }
782:
783: sub secapply {
784: my $rec=shift;
785: my $defaultflag=shift;
786: $rec=~s/\s+//g;
787: $rec=~s/\@/\:/g;
788: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
789: if ($sections) {
790: foreach (split(/\;/,$sections)) {
791: if (($_ eq $ENV{'request.course.sec'}) ||
792: ($defaultflag && ($_ eq '*'))) {
793: return $adr;
794: }
795: }
796: } else {
797: return $rec;
798: }
799: return '';
800: }
801:
802: sub decide_receiver {
803: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
804: my $typestyle='';
805: my %to=();
806: if ($ENV{'form.author'}||$author) {
807: $typestyle.='Submitting as Author Feedback<br>';
808: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
809: $to{$2.':'.$1}=1;
810: }
811: if ($ENV{'form.question'}||$question) {
812: $typestyle.='Submitting as Question<br>';
813: foreach (split(/\,/,
814: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
815: ) {
816: my $rec=&secapply($_,$defaultflag);
817: if ($rec) { $to{$rec}=1; }
818: }
819: }
820: if ($ENV{'form.course'}||$course) {
821: $typestyle.='Submitting as Comment<br />';
822: foreach (split(/\,/,
823: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
824: ) {
825: my $rec=&secapply($_,$defaultflag);
826: if ($rec) { $to{$rec}=1; }
827: }
828: }
829: if ($ENV{'form.policy'}||$policy) {
830: $typestyle.='Submitting as Policy Feedback<br />';
831: foreach (split(/\,/,
832: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
833: ) {
834: my $rec=&secapply($_,$defaultflag);
835: if ($rec) { $to{$rec}=1; }
836: }
837: }
838: if ((scalar(%to) eq '0') && (!$defaultflag)) {
839: ($typestyle,%to)=
840: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
841: }
842: return ($typestyle,%to);
843: }
844:
845: sub feedback_available {
846: my ($question,$course,$policy)=@_;
847: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
848: return scalar(%to);
849: }
850:
851: sub send_msg {
852: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
853: my $status='';
854: my $sendsomething=0;
855: foreach (keys %to) {
856: if ($_) {
857: my $declutter=&Apache::lonnet::declutter($feedurl);
858: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
859: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
860: $attachmenturl)=~/ok/) {
861: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
862: } else {
863: $sendsomething++;
864: }
865: }
866: }
867:
868: my %record=&Apache::lonnet::restore('_feedback');
869: my ($temp)=keys %record;
870: unless ($temp=~/^error\:/) {
871: my %newrecord=();
872: $newrecord{'resource'}=$feedurl;
873: $newrecord{'subnumber'}=$record{'subnumber'}+1;
874: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
875: $status.='<br />'.&mt('Not registered').'<br />';
876: }
877: }
878:
879: return ($status,$sendsomething);
880: }
881:
882: sub adddiscuss {
883: my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
884: my $status='';
885: if (&discussion_open() &&
886: &Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
887: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
888:
889: my %contrib=('message' => $email,
890: 'sendername' => $ENV{'user.name'},
891: 'senderdomain' => $ENV{'user.domain'},
892: 'screenname' => $ENV{'environment.screenname'},
893: 'plainname' => $ENV{'environment.firstname'}.' '.
894: $ENV{'environment.middlename'}.' '.
895: $ENV{'environment.lastname'}.' '.
896: $ENV{'enrironment.generation'},
897: 'attachmenturl'=> $attachmenturl,
898: 'subject' => $subject);
899: if ($ENV{'form.replydisc'}) {
900: $contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
901: }
902: if ($anon) {
903: $contrib{'anonymous'}='true';
904: }
905: if (($symb) && ($email)) {
906: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
907: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
908: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
909: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
910: my %storenewentry=($symb => time);
911: $status.='<br />'.&mt('Updating discussion time').': '.
912: &Apache::lonnet::put('discussiontimes',\%storenewentry,
913: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
914: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
915: }
916: my %record=&Apache::lonnet::restore('_discussion');
917: my ($temp)=keys %record;
918: unless ($temp=~/^error\:/) {
919: my %newrecord=();
920: $newrecord{'resource'}=$symb;
921: $newrecord{'subnumber'}=$record{'subnumber'}+1;
922: $status.='<br />'.&mt('Registering').': '.
923: &Apache::lonnet::cstore(\%newrecord,'_discussion');
924: }
925: } else {
926: $status.='Failed.';
927: }
928: return $status.'<br />';
929: }
930:
931: # ----------------------------------------------------------- Preview function
932:
933: sub show_preview {
934: my $r=shift;
935: my $message=&clear_out_html($ENV{'form.comment'});
936: $message=~s/\n/\<br \/\>/g;
937: $message=&Apache::lontexconvert::msgtexconverted($message);
938: my $subject=&clear_out_html($ENV{'form.subject'});
939: $subject=~s/\n/\<br \/\>/g;
940: $subject=&Apache::lontexconvert::msgtexconverted($subject);
941: $r->print('<table border="2"><tr><td>'.
942: '<b>Subject:</b> '.$subject.'<br /><br />'.
943: $message.'</td></tr></table>');
944: }
945:
946: sub generate_preview_button {
947: my $pre=&mt("Show Preview");
948: return(<<ENDPREVIEW);
949: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
950: <input type="hidden" name="subject">
951: <input type="hidden" name="comment" />
952: <input type="button" value="$pre"
953: onClick="document.mailform.onsubmit();this.form.comment.value=document.mailform.comment.value;this.form.subject.value=document.mailform.subject.value;this.form.submit();" />
954: </form>
955: ENDPREVIEW
956: }
957:
958: sub handler {
959: my $r = shift;
960: if ($r->header_only) {
961: &Apache::loncommon::content_type($r,'text/html');
962: $r->send_http_header;
963: return OK;
964: }
965:
966: # --------------------------- Get query string for limited number of parameters
967:
968: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
969: ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff','onlyunread','allposts','previous','markread','markonread','markondisp']);
970:
971: if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
972: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
973:
974: &Apache::loncommon::content_type($r,'text/html');
975: $r->send_http_header;
976: my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
977: my $ressymb = $symb;
978: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
979: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
980: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
981: }
982:
983: my %discinfo = ();
984: my $lastkey = $ressymb.'_lastread';
985: my $ondispkey = $ressymb.'_markondisp';
986: if ($ENV{'form.markondisp'}) {
987: $discinfo{$lastkey} = time;
988: $discinfo{$ondispkey} = 1;
989: } elsif ($ENV{'form.markonread'}) {
990: if ( defined($ENV{'previous'}) ) {
991: $discinfo{$lastkey} = $ENV{'previous'};
992: }
993: $discinfo{$ondispkey} = 0;
994: }
995: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
996: if ($ENV{'form.markondisp'}) {
997: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
998: } else {
999: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$ENV{'form.previous'});
1000: }
1001: return OK;
1002: } elsif (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'})) {
1003: # ----------------------------------------------------------------- Modify display setting for this discussion
1004: &Apache::loncommon::content_type($r,'text/html');
1005: $r->send_http_header;
1006: my $symb=$ENV{'form.allposts'}?$ENV{'form.allposts'}:$ENV{'form.onlyunread'};
1007: my $ressymb = $symb;
1008: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1009: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1010: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1011: }
1012: my %discinfo = ();
1013: if ($ENV{'form.allposts'}) {
1014: $discinfo{$ressymb.'_showonlyunread'} = 0;
1015: } elsif ($ENV{'form.onlyunread'}) {
1016: $discinfo{$ressymb.'_showonlyunread'} = 1;
1017: }
1018: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1019: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$ENV{'form.previous'});
1020: return OK;
1021: } elsif ($ENV{'form.markread'}) {
1022: # ----------------------------------------------------------------- Mark new posts as read
1023: &Apache::loncommon::content_type($r,'text/html');
1024: $r->send_http_header;
1025: my $symb=$ENV{'form.markread'};
1026: my $ressymb = $symb;
1027: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1028: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1029: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1030: }
1031: my %discinfo = ();
1032: my $lastkey = $ressymb.'_lastread';
1033: $discinfo{$lastkey} = time;
1034: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1035: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
1036: return OK;
1037: } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1038: # ----------------------------------------------------------------- Hide/unhide
1039: &Apache::loncommon::content_type($r,'text/html');
1040: $r->send_http_header;
1041:
1042: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
1043:
1044: my ($symb,$idx)=split(/\:\:\:/,$entry);
1045: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1046:
1047: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
1048: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1049: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1050:
1051:
1052: my $currenthidden=$contrib{'hidden'};
1053:
1054: if ($ENV{'form.hide'}) {
1055: $currenthidden.='.'.$idx.'.';
1056: } else {
1057: $currenthidden=~s/\.$idx\.//g;
1058: }
1059: my %newhash=('hidden' => $currenthidden);
1060:
1061: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
1062: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1063: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1064:
1065: &redirect_back($r,&Apache::lonnet::clutter($url),
1066: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1067: } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1068: &Apache::loncommon::content_type($r,'text/html');
1069: $r->send_http_header;
1070: if ($ENV{'form.threadedon'}) {
1071: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
1072: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
1073: } else {
1074: &Apache::lonnet::del('environment',['threadeddiscussion']);
1075: &Apache::lonnet::delenv('environment\.threadeddiscussion');
1076: }
1077: my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
1078: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1079: &redirect_back($r,&Apache::lonnet::clutter($url),
1080: &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1081: } elsif ($ENV{'form.deldisc'}) {
1082: # --------------------------------------------------------------- Hide for good
1083: &Apache::loncommon::content_type($r,'text/html');
1084: $r->send_http_header;
1085:
1086: my $entry=$ENV{'form.deldisc'};
1087:
1088: my ($symb,$idx)=split(/\:\:\:/,$entry);
1089: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1090:
1091: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
1092: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1093: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1094:
1095:
1096: my $currentdeleted=$contrib{'deleted'};
1097:
1098: $currentdeleted.='.'.$idx.'.';
1099:
1100: my %newhash=('deleted' => $currentdeleted);
1101:
1102: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
1103: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1104: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1105:
1106: &redirect_back($r,&Apache::lonnet::clutter($url),
1107: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1108: } elsif ($ENV{'form.preview'}) {
1109: # -------------------------------------------------------- User wants a preview
1110: $r->content_type('text/html');
1111: $r->send_http_header;
1112: &show_preview($r);
1113: } else {
1114: # ------------------------------------------------------------- Normal feedback
1115: my $feedurl=$ENV{'form.postdata'};
1116: $feedurl=~s/^http\:\/\///;
1117: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
1118: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1119: $feedurl=~s/\?.+$//;
1120:
1121: my $symb;
1122: if ($ENV{'form.replydisc'}) {
1123: $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
1124: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1125: $feedurl=&Apache::lonnet::clutter($url);
1126: } else {
1127: $symb=&Apache::lonnet::symbread($feedurl);
1128: }
1129: unless ($symb) {
1130: $symb=$ENV{'form.symb'};
1131: if ($symb) {
1132: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1133: $feedurl=&Apache::lonnet::clutter($url);
1134: }
1135: }
1136: my $goahead=1;
1137: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1138: unless ($symb) { $goahead=0; }
1139: }
1140: # backward compatibility (bulltin boards used to be 'wrapped')
1141: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1142: $feedurl=~s|^/adm/wrapper||;
1143: }
1144: if ($goahead) {
1145: # Go ahead with feedback, no ambiguous reference
1146: &Apache::loncommon::content_type($r,'text/html');
1147: $r->send_http_header;
1148:
1149: if (
1150: (
1151: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
1152: )
1153: ||
1154: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1155: ||
1156: ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1157: ) {
1158: # --------------------------------------------------- Print login screen header
1159: unless ($ENV{'form.sendit'}) {
1160: my $options=&screen_header($feedurl);
1161: if ($options) {
1162: &mail_screen($r,$feedurl,$options);
1163: } else {
1164: &fail_redirect($r,$feedurl);
1165: }
1166: } else {
1167:
1168: # Get previous user input
1169: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1170: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1171: $ENV{'request.course.id'});
1172:
1173: # Get output from resource
1174: my $usersaw=&resource_output($feedurl);
1175:
1176: # Get resource answer (need to allow student to view grades for this to work)
1177: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1178: my $useranswer=&Apache::loncommon::get_student_answers(
1179: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1180: $ENV{'request.course.id'});
1181: &Apache::lonnet::delenv('allowed.vgr');
1182: # Get attachments, if any, and not too large
1183: my $attachmenturl='';
1184: if ($ENV{'form.attachment.filename'}) {
1185: unless (length($ENV{'form.attachment'})>131072) {
1186: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1187: }
1188: }
1189: # Filter HTML out of message (could be nasty)
1190: my $message=&clear_out_html($ENV{'form.comment'});
1191:
1192: # Assemble email
1193: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1194: $usersaw,$useranswer);
1195:
1196: # Who gets this?
1197: my ($typestyle,%to) = &decide_receiver($feedurl);
1198:
1199: # Actually send mail
1200: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
1201: $attachmenturl,%to);
1202:
1203: # Discussion? Store that.
1204:
1205: my $numpost=0;
1206: if ($ENV{'form.discuss'}) {
1207: my $subject = &clear_out_html($ENV{'form.subject'});
1208: $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1209: $numpost++;
1210: }
1211:
1212: if ($ENV{'form.anondiscuss'}) {
1213: my $subject = &clear_out_html($ENV{'form.subject'});
1214: $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1215: $numpost++;
1216: }
1217:
1218:
1219: # Receipt screen and redirect back to where came from
1220: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1221:
1222: }
1223: } else {
1224: # Unable to give feedback
1225: &no_redirect_back($r,$feedurl);
1226: }
1227: } else {
1228: # Ambiguous Problem Resource
1229: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1230: &Apache::lonnet::cleanenv();
1231: }
1232: $r->internal_redirect('/adm/ambiguous');
1233: }
1234: }
1235: return OK;
1236: }
1237:
1238: 1;
1239: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>