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