1: # The LearningOnline Network
2: # Feedback
3: #
4: # $Id: lonfeedback.pm,v 1.73.2.1 2004/02/18 20:33:49 albertel 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;
38:
39: sub list_discussion {
40: my ($mode,$status,$symb)=@_;
41: my $discussiononly=0;
42: if ($mode eq 'board') { $discussiononly=1; }
43: unless ($ENV{'request.course.id'}) { return ''; }
44: my $crs='/'.$ENV{'request.course.id'};
45: if ($ENV{'request.course.sec'}) {
46: $crs.='_'.$ENV{'request.course.sec'};
47: }
48: $crs=~s/\_/\//g;
49: unless ($symb) {
50: $symb=&Apache::lonnet::symbread();
51: }
52: unless ($symb) { return ''; }
53: my $seeid=&Apache::lonnet::allowed('rin',$crs);
54: my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
55: && ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/));
56: my @discussionitems=();
57: # backward compatability (bulltein boards used to be 'wrapped')
58: my $ressymb=$symb;
59: if ($mode eq 'board') {
60: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
61: }
62: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
63: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
64: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
65: my $visible=0;
66: my @depth=();
67: my @original=();
68: my @index=();
69: my @replies=();
70: my %alldiscussion=();
71: my $maxdepth=0;
72:
73: my $target='';
74: unless ($ENV{'browser.interface'} eq 'textual' ||
75: $ENV{'environment.remote'} eq 'off' ) {
76: $target='target="LONcom"';
77: }
78: if ($contrib{'version'}) {
79: for (my $id=1;$id<=$contrib{'version'};$id++) {
80: my $idx=$id;
81: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
82: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
83: my $origindex='0.';
84: if (($contrib{$idx.':replyto'}) && ($ENV{'environment.threadeddiscussion'})) {
85: # this is a follow-up message
86: $original[$idx]=$original[$contrib{$idx.':replyto'}];
87: $depth[$idx]=$depth[$contrib{$idx.':replyto'}]+1;
88: $origindex=$index[$contrib{$idx.':replyto'}];
89: if ($depth[$idx]>$maxdepth) { $maxdepth=$depth[$idx]; }
90: } else {
91: # this is an original message
92: $original[$idx]=0;
93: $depth[$idx]=0;
94: }
95: if ($replies[$depth[$idx]]) {
96: $replies[$depth[$idx]]++;
97: } else {
98: $replies[$depth[$idx]]=1;
99: }
100: unless ((($hidden) && (!$seeid)) || ($deleted)) {
101: $visible++;
102: my $message=$contrib{$idx.':message'};
103: $message=~s/\n/\<br \/\>/g;
104: $message=&Apache::lontexconvert::msgtexconverted($message);
105: if ($contrib{$idx.':attachmenturl'}) {
106: my ($fname,$ft)
107: =($contrib{$idx.':attachmenturl'}=~/\/(\w+)\.(\w+)$/);
108: $message.='<p>'.&mt('Attachment').': <a href="'.
109: &Apache::lonnet::tokenwrapper(
110: $contrib{$idx.':attachmenturl'}).
111: '"><tt>'.$fname.'.'.$ft.'</tt></a></p>';
112: }
113: if ($message) {
114: if ($hidden) {
115: $message='<font color="#888888">'.$message.'</font>';
116: }
117: my $screenname=&Apache::loncommon::screenname(
118: $contrib{$idx.':sendername'},
119: $contrib{$idx.':senderdomain'});
120: my $plainname=&Apache::loncommon::nickname(
121: $contrib{$idx.':sendername'},
122: $contrib{$idx.':senderdomain'});
123:
124: my $sender=&mt('Anonymous');
125: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
126: $sender=&Apache::loncommon::aboutmewrapper(
127: $plainname,
128: $contrib{$idx.':sendername'},
129: $contrib{$idx.':senderdomain'}).' ('.
130: $contrib{$idx.':sendername'}.' at '.
131: $contrib{$idx.':senderdomain'}.')';
132: if ($contrib{$idx.':anonymous'}) {
133: $sender.=' ['.&mt('anonymous').'] '.
134: $screenname;
135: }
136: if ($seeid) {
137: if ($hidden) {
138: $sender.=' <a href="/adm/feedback?unhide='.
139: $ressymb.':::'.$idx.'">'.&mt('Make Visible').'</a>';
140: } else {
141: $sender.=' <a href="/adm/feedback?hide='.
142: $ressymb.':::'.$idx.'">'.&mt('Hide').'</a>';
143: }
144: $sender.=' <a href="/adm/feedback?deldisc='.
145: $ressymb.':::'.$idx.'">'.&mt('Delete').'</a>';
146: }
147: } else {
148: if ($screenname) {
149: $sender='<i>'.$screenname.'</i>';
150: }
151: }
152: if (&Apache::lonnet::allowed('pch',
153: $ENV{'request.course.id'}.
154: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
155: $sender.=' <a href="/adm/feedback?replydisc='.
156: $ressymb.':::'.$idx.'" '.$target.'>'.&mt('Reply').'</a>';
157: }
158: my $vgrlink;
159: if ($viewgrades) {
160: $vgrlink=&Apache::loncommon::submlink('Submissions',
161: $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb);
162: }
163: #figure out at what position this needs to print
164: my $thisindex=$idx;
165: if ($ENV{'environment.threadeddiscussion'}) {
166: $thisindex=$origindex.substr('00'.$replies[$depth[$idx]],-2,2);
167: }
168: $alldiscussion{$thisindex}=$idx;
169: $index[$idx]=$thisindex;
170: $discussionitems[$idx]='<p><b>'.$sender.'</b> '.$vgrlink.' ('.
171: localtime($contrib{$idx.':timestamp'}).
172: '):<blockquote>'.$message.
173: '</blockquote></p>';
174: }
175: }
176: }
177: }
178: my $discussion='';
179: if ($visible) {
180: # Print a the discusssion
181: $discussion.='<table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
182: if ($visible>2) {
183: my $colspan=$maxdepth+1;
184: $discussion.='<tr><td bgcolor="DDDDBB" colspan="'.$colspan.'">'.
185: '<a href="/adm/feedback?threadedon='.$symb.'">'.&mt('Threaded View').'</a> '.
186: '<a href="/adm/feedback?threadedoff='.$symb.'">'.&mt('Chronological View').'</a>'.
187: '</td></tr>';
188: }
189:
190: foreach (sort { $a <=> $b } keys %alldiscussion) {
191: $discussion.="\n<tr>";
192: my $thisdepth=$depth[$alldiscussion{$_}];
193: for (1..$thisdepth) {
194: $discussion.='<td> </td>';
195: }
196: my $colspan=$maxdepth-$thisdepth+1;
197: $discussion.="<td bgcolor='#CCCCCC' colspan='".$colspan."'>".$discussionitems[$alldiscussion{$_}].
198: "</td></tr>";
199: }
200: $discussion.='</table>';
201: }
202: if ($discussiononly) {
203: $discussion.=(<<ENDDISCUSS);
204: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
205: <input type="submit" name="discuss" value="Post Discussion" />
206: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
207: <input type="hidden" name="symb" value="$ressymb" />
208: <input type="hidden" name="sendit" value="true" />
209: <br />
210: <font size="1">Note: in anonymous discussion, your name is visible only to
211: course faculty</font><br />
212: <textarea name="comment" cols="60" rows="10" wrap="hard"></textarea>
213: <p>
214: Attachment (128 KB max size): <input type="file" name="attachment" />
215: </p>
216: </form>
217: ENDDISCUSS
218: $discussion.=&generate_preview_button();
219: }
220: return $discussion;
221: }
222:
223: sub mail_screen {
224: my ($r,$feedurl,$options) = @_;
225: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
226: '','onLoad="window.focus();"');
227: my $title=&Apache::lonnet::gettitle($feedurl);
228: if (!$title) { $title = $feedurl; }
229: my $quote='';
230: if ($ENV{'form.replydisc'}) {
231: my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
232: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
233: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
234: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
235: unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
236: my $message=$contrib{$idx.':message'};
237: $message=~s/\n/\<br \/\>/g;
238: $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
239: }
240: }
241: my $latexHelp = Apache::loncommon::helpLatexCheatsheet();
242: $r->print(<<ENDDOCUMENT);
243: <html>
244: <head>
245: <title>The LearningOnline Network with CAPA</title>
246: <meta http-equiv="pragma" content="no-cache"></meta>
247: <script type="text/javascript">
248: //<!--
249: function gosubmit() {
250: var rec=0;
251: if (typeof(document.mailform.elements.author)!="undefined") {
252: if (document.mailform.elements.author.checked) {
253: rec=1;
254: }
255: }
256: if (typeof(document.mailform.elements.question)!="undefined") {
257: if (document.mailform.elements.question.checked) {
258: rec=1;
259: }
260: }
261: if (typeof(document.mailform.elements.course)!="undefined") {
262: if (document.mailform.elements.course.checked) {
263: rec=1;
264: }
265: }
266: if (typeof(document.mailform.elements.policy)!="undefined") {
267: if (document.mailform.elements.policy.checked) {
268: rec=1;
269: }
270: }
271: if (typeof(document.mailform.elements.discuss)!="undefined") {
272: if (document.mailform.elements.discuss.checked) {
273: rec=1;
274: }
275: }
276: if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
277: if (document.mailform.elements.anondiscuss.checked) {
278: rec=1;
279: }
280: }
281:
282: if (rec) {
283: document.mailform.submit();
284: } else {
285: alert('Please check a feedback type.');
286: }
287: }
288: //-->
289: </script>
290: </head>
291: $bodytag
292: <h2><tt>$title</tt></h2>
293: <form action="/adm/feedback" method="post" name="mailform"
294: enctype="multipart/form-data">
295: <input type="hidden" name="postdata" value="$feedurl" />
296: <input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
297: Please check at least one of the following feedback types:
298: $options<hr />
299: $quote
300: <p>My question/comment/feedback:</p>
301: <p>
302: $latexHelp
303: <textarea name="comment" cols="60" rows="10" wrap="hard">
304: </textarea></p>
305: <p>
306: Attachment (128 KB max size): <input type="file" name="attachment" />
307: </p>
308: <p>
309: <input type="hidden" name="sendit" value="1" />
310: <input type="button" value="Send Feedback" onClick='gosubmit();' />
311: </p>
312: </form>
313: ENDDOCUMENT
314: $r->print(&generate_preview_button().'</body></html>');
315: }
316:
317: sub fail_redirect {
318: my ($r,$feedurl) = @_;
319: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
320: $r->print (<<ENDFAILREDIR);
321: <html>
322: <head><title>Feedback not sent</title>
323: <meta http-equiv="pragma" content="no-cache" />
324: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
325: </head>
326: <body bgcolor="#FFFFFF">
327: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
328: <b>Sorry, no recipients ...</b>
329: </body>
330: </html>
331: ENDFAILREDIR
332: }
333:
334: sub redirect_back {
335: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status) = @_;
336: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
337: $r->print (<<ENDREDIR);
338: <html>
339: <head>
340: <title>Feedback sent</title>
341: <meta http-equiv="pragma" content="no-cache" />
342: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
343: </head>
344: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
345: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
346: $typestyle
347: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
348: <font color="red">$status</font>
349: <form name="reldt" action="$feedurl" target="loncapaclient">
350: </form>
351: </body>
352: </html>
353: ENDREDIR
354: }
355:
356: sub no_redirect_back {
357: my ($r,$feedurl) = @_;
358: $r->print (<<ENDNOREDIR);
359: <html>
360: <head><title>Feedback not sent</title>
361: <meta http-equiv="pragma" content="no-cache" />
362: ENDNOREDIR
363:
364: if ($feedurl!~/^\/adm\/feedback/) {
365: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
366: }
367:
368: $r->print (<<ENDNOREDIRTWO);
369: </head>
370: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
371: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
372: <b>Sorry, no feedback possible on this resource ...</b>
373: </body>
374: </html>
375: ENDNOREDIRTWO
376: }
377:
378: sub screen_header {
379: my ($feedurl) = @_;
380: my $msgoptions='';
381: my $discussoptions='';
382: unless ($ENV{'form.replydisc'}) {
383: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
384: $msgoptions=
385: '<p><input type="checkbox" name="author" /> '.
386: &mt('Feedback to resource author').'</p>';
387: }
388: if (&feedback_available(1)) {
389: $msgoptions.=
390: '<br /><input type="checkbox" name="question" /> '.
391: &mt('Question about resource content');
392: }
393: if (&feedback_available(0,1)) {
394: $msgoptions.=
395: '<br /><input type="checkbox" name="course" /> '.
396: &mt('Question/Comment/Feedback about course content');
397: }
398: if (&feedback_available(0,0,1)) {
399: $msgoptions.=
400: '<br /><input type="checkbox" name="policy" /> '.
401: &mt('Question/Comment/Feedback about course policy');
402: }
403: }
404: if ($ENV{'request.course.id'}) {
405: if (&Apache::lonnet::allowed('pch',
406: $ENV{'request.course.id'}.
407: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
408: $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" /> '.
409: &mt('Contribution to course discussion of resource');
410: $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
411: &mt('Anonymous contribution to course discussion of resource').
412: ' <i>('.&mt('name only visible to course faculty').')</i>';
413: }
414: }
415: if ($msgoptions) { $msgoptions='<h2>'.&mt('Sending Messages').'</h2>'.$msgoptions; }
416: if ($discussoptions) {
417: $discussoptions='<h2>'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
418: return $msgoptions.$discussoptions;
419: }
420:
421: sub resource_output {
422: my ($feedurl) = @_;
423: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
424: $usersaw=~s/\<body[^\>]*\>//gi;
425: $usersaw=~s/\<\/body\>//gi;
426: $usersaw=~s/\<html\>//gi;
427: $usersaw=~s/\<\/html\>//gi;
428: $usersaw=~s/\<head\>//gi;
429: $usersaw=~s/\<\/head\>//gi;
430: $usersaw=~s/action\s*\=/would_be_action\=/gi;
431: return $usersaw;
432: }
433:
434: sub clear_out_html {
435: my ($message,$override)=@_;
436: my $cid=$ENV{'request.course.id'};
437: if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
438: ($override)) {
439: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
440: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG>
441: my %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
442: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
443: M=>1);
444:
445: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
446: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
447: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
448: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
449: } else {
450: $message=~s/\</\<\;/g;
451: $message=~s/\>/\>\;/g;
452: }
453: return $message;
454: }
455:
456: sub assemble_email {
457: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
458: my $email=<<"ENDEMAIL";
459: Refers to <a href="$feedurl">$feedurl</a>
460:
461: $message
462: ENDEMAIL
463: my $citations=<<"ENDCITE";
464: <h2>Previous attempts of student (if applicable)</h2>
465: $prevattempts
466: <br /><hr />
467: <h2>Original screen output (if applicable)</h2>
468: $usersaw
469: <h2>Correct Answer(s) (if applicable)</h2>
470: $useranswer
471: ENDCITE
472: return ($email,$citations);
473: }
474:
475: sub secapply {
476: my $rec=shift;
477: my $defaultflag=shift;
478: $rec=~s/\s+//g;
479: $rec=~s/\@/\:/g;
480: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
481: if ($sections) {
482: foreach (split(/\;/,$sections)) {
483: if (($_ eq $ENV{'request.course.sec'}) ||
484: ($defaultflag && ($_ eq '*'))) {
485: return $adr;
486: }
487: }
488: } else {
489: return $rec;
490: }
491: return '';
492: }
493:
494: sub decide_receiver {
495: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
496: my $typestyle='';
497: my %to=();
498: if ($ENV{'form.author'}||$author) {
499: $typestyle.='Submitting as Author Feedback<br>';
500: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
501: $to{$2.':'.$1}=1;
502: }
503: if ($ENV{'form.question'}||$question) {
504: $typestyle.='Submitting as Question<br>';
505: foreach (split(/\,/,
506: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
507: ) {
508: my $rec=&secapply($_,$defaultflag);
509: if ($rec) { $to{$rec}=1; }
510: }
511: }
512: if ($ENV{'form.course'}||$course) {
513: $typestyle.='Submitting as Comment<br />';
514: foreach (split(/\,/,
515: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
516: ) {
517: my $rec=&secapply($_,$defaultflag);
518: if ($rec) { $to{$rec}=1; }
519: }
520: }
521: if ($ENV{'form.policy'}||$policy) {
522: $typestyle.='Submitting as Policy Feedback<br />';
523: foreach (split(/\,/,
524: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
525: ) {
526: my $rec=&secapply($_,$defaultflag);
527: if ($rec) { $to{$rec}=1; }
528: }
529: }
530: if ((scalar(%to) eq '0') && (!$defaultflag)) {
531: ($typestyle,%to)=
532: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
533: }
534: return ($typestyle,%to);
535: }
536:
537: sub feedback_available {
538: my ($question,$course,$policy)=@_;
539: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
540: return scalar(%to);
541: }
542:
543: sub send_msg {
544: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
545: my $status='';
546: my $sendsomething=0;
547: foreach (keys %to) {
548: if ($_) {
549: my $declutter=&Apache::lonnet::declutter($feedurl);
550: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
551: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
552: $attachmenturl)=~/ok/) {
553: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
554: } else {
555: $sendsomething++;
556: }
557: }
558: }
559:
560: my %record=&Apache::lonnet::restore('_feedback');
561: my ($temp)=keys %record;
562: unless ($temp=~/^error\:/) {
563: my %newrecord=();
564: $newrecord{'resource'}=$feedurl;
565: $newrecord{'subnumber'}=$record{'subnumber'}+1;
566: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
567: $status.='<br />'.&mt('Not registered').'<br />';
568: }
569: }
570:
571: return ($status,$sendsomething);
572: }
573:
574: sub adddiscuss {
575: my ($symb,$email,$anon,$attachmenturl)=@_;
576: my $status='';
577: if (&Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
578: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
579:
580: my %contrib=('message' => $email,
581: 'sendername' => $ENV{'user.name'},
582: 'senderdomain' => $ENV{'user.domain'},
583: 'screenname' => $ENV{'environment.screenname'},
584: 'plainname' => $ENV{'environment.firstname'}.' '.
585: $ENV{'environment.middlename'}.' '.
586: $ENV{'environment.lastname'}.' '.
587: $ENV{'enrironment.generation'},
588: 'attachmenturl'=> $attachmenturl);
589: if ($ENV{'form.replydisc'}) {
590: $contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
591: }
592: if ($anon) {
593: $contrib{'anonymous'}='true';
594: }
595: if (($symb) && ($email)) {
596: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
597: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
598: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
599: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
600: my %storenewentry=($symb => time);
601: $status.='<br />'.&mt('Updating discussion time').': '.
602: &Apache::lonnet::put('discussiontimes',\%storenewentry,
603: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
604: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
605: }
606: my %record=&Apache::lonnet::restore('_discussion');
607: my ($temp)=keys %record;
608: unless ($temp=~/^error\:/) {
609: my %newrecord=();
610: $newrecord{'resource'}=$symb;
611: $newrecord{'subnumber'}=$record{'subnumber'}+1;
612: $status.='<br />'.&mt('Registering').': '.
613: &Apache::lonnet::cstore(\%newrecord,'_discussion');
614: }
615: } else {
616: $status.='Failed.';
617: }
618: return $status.'<br />';
619: }
620:
621: # ----------------------------------------------------------- Preview function
622:
623: sub show_preview {
624: my $r=shift;
625: my $message=&clear_out_html($ENV{'form.comment'});
626: $message=~s/\n/\<br \/\>/g;
627: $message=&Apache::lontexconvert::msgtexconverted($message);
628: $r->print('<table border="2"><tr><td>'.
629: $message.'</td></tr></table>');
630: }
631:
632: sub generate_preview_button {
633: my $pre=&mt("Show Preview");
634: return(<<ENDPREVIEW);
635: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
636: <input type="hidden" name="comment" />
637: <input type="button" value="$pre"
638: onClick="this.form.comment.value=document.mailform.comment.value;this.form.submit();" />
639: </form>
640: ENDPREVIEW
641: }
642:
643: sub handler {
644: my $r = shift;
645: if ($r->header_only) {
646: &Apache::loncommon::content_type($r,'text/html');
647: $r->send_http_header;
648: return OK;
649: }
650:
651: # --------------------------- Get query string for limited number of parameters
652:
653: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
654: ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff']);
655:
656: if (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
657: # ----------------------------------------------------------------- Hide/unhide
658: &Apache::loncommon::content_type($r,'text/html');
659: $r->send_http_header;
660:
661: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
662:
663: my ($symb,$idx)=split(/\:\:\:/,$entry);
664: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
665:
666: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
667: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
668: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
669:
670:
671: my $currenthidden=$contrib{'hidden'};
672:
673: if ($ENV{'form.hide'}) {
674: $currenthidden.='.'.$idx.'.';
675: } else {
676: $currenthidden=~s/\.$idx\.//g;
677: }
678: my %newhash=('hidden' => $currenthidden);
679:
680: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
681: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
682: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
683:
684: &redirect_back($r,&Apache::lonnet::clutter($url),
685: &mt('Changed discussion status').'<br />','0','0');
686: } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
687: &Apache::loncommon::content_type($r,'text/html');
688: $r->send_http_header;
689: if ($ENV{'form.threadedon'}) {
690: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
691: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
692: } else {
693: &Apache::lonnet::del('environment',['threadeddiscussion']);
694: &Apache::lonnet::delenv('environment\.threadeddiscussion');
695: }
696: my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
697: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
698: &redirect_back($r,&Apache::lonnet::clutter($url),
699: &mt('Changed discussion view mode').'<br />','0','0');
700: } elsif ($ENV{'form.deldisc'}) {
701: # --------------------------------------------------------------- Hide for good
702: &Apache::loncommon::content_type($r,'text/html');
703: $r->send_http_header;
704:
705: my $entry=$ENV{'form.deldisc'};
706:
707: my ($symb,$idx)=split(/\:\:\:/,$entry);
708: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
709:
710: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
711: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
712: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
713:
714:
715: my $currentdeleted=$contrib{'deleted'};
716:
717: $currentdeleted.='.'.$idx.'.';
718:
719: my %newhash=('deleted' => $currentdeleted);
720:
721: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
722: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
723: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
724:
725: &redirect_back($r,&Apache::lonnet::clutter($url),
726: &mt('Changed discussion status').'<br />','0','0');
727: } elsif ($ENV{'form.preview'}) {
728: # -------------------------------------------------------- User wants a preview
729: $r->content_type('text/html');
730: $r->send_http_header;
731: &show_preview($r);
732: } else {
733: # ------------------------------------------------------------- Normal feedback
734: my $feedurl=$ENV{'form.postdata'};
735: $feedurl=~s/^http\:\/\///;
736: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
737: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
738: $feedurl=~s/\?.+$//;
739:
740: my $symb;
741: if ($ENV{'form.replydisc'}) {
742: $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
743: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
744: $feedurl=&Apache::lonnet::clutter($url);
745: } else {
746: $symb=&Apache::lonnet::symbread($feedurl);
747: }
748: unless ($symb) {
749: $symb=$ENV{'form.symb'};
750: if ($symb) {
751: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
752: $feedurl=&Apache::lonnet::clutter($url);
753: }
754: }
755: my $goahead=1;
756: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
757: unless ($symb) { $goahead=0; }
758: }
759: # backward compatability (bulltein boards used to be 'wrapped')
760: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
761: $feedurl=~s|^/adm/wrapper||;
762: }
763: if ($goahead) {
764: # Go ahead with feedback, no ambiguous reference
765: &Apache::loncommon::content_type($r,'text/html');
766: $r->send_http_header;
767:
768: if (
769: (
770: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
771: )
772: ||
773: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
774: ||
775: ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
776: ) {
777: # --------------------------------------------------- Print login screen header
778: unless ($ENV{'form.sendit'}) {
779: my $options=&screen_header($feedurl);
780: if ($options) {
781: &mail_screen($r,$feedurl,$options);
782: } else {
783: &fail_redirect($r,$feedurl);
784: }
785: } else {
786:
787: # Get previous user input
788: my $prevattempts=&Apache::loncommon::get_previous_attempt(
789: $symb,$ENV{'user.name'},$ENV{'user.domain'},
790: $ENV{'request.course.id'});
791:
792: # Get output from resource
793: my $usersaw=&resource_output($feedurl);
794:
795: # Get resource answer (need to allow student to view grades for this to work)
796: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
797: my $useranswer=&Apache::loncommon::get_student_answers(
798: $symb,$ENV{'user.name'},$ENV{'user.domain'},
799: $ENV{'request.course.id'});
800: &Apache::lonnet::delenv('allowed.vgr');
801: # Get attachments, if any, and not too large
802: my $attachmenturl='';
803: if ($ENV{'form.attachment.filename'}) {
804: unless (length($ENV{'form.attachment'})>131072) {
805: $attachmenturl=&Apache::lonnet::userfileupload('attachment');
806: }
807: }
808: # Filter HTML out of message (could be nasty)
809: my $message=&clear_out_html($ENV{'form.comment'});
810:
811: # Assemble email
812: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
813: $usersaw,$useranswer);
814:
815: # Who gets this?
816: my ($typestyle,%to) = &decide_receiver($feedurl);
817:
818: # Actually send mail
819: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
820: $attachmenturl,%to);
821:
822: # Discussion? Store that.
823:
824: my $numpost=0;
825: if ($ENV{'form.discuss'}) {
826: $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl);
827: $numpost++;
828: }
829:
830: if ($ENV{'form.anondiscuss'}) {
831: $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl);
832: $numpost++;
833: }
834:
835:
836: # Receipt screen and redirect back to where came from
837: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status);
838:
839: }
840: } else {
841: # Unable to give feedback
842: &no_redirect_back($r,$feedurl);
843: }
844: } else {
845: # Ambiguous Problem Resource
846: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
847: &Apache::lonnet::cleanenv();
848: }
849: $r->internal_redirect('/adm/ambiguous');
850: }
851: }
852: return OK;
853: }
854:
855: 1;
856: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>