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