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