1: # The LearningOnline Network
2: # Feedback
3: #
4: # $Id: lonfeedback.pm,v 1.72 2003/11/27 09:20:39 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: # (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: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
331: $r->print (<<ENDFAILREDIR);
332: <html>
333: <head><title>Feedback not sent</title>
334: <meta http-equiv="pragma" content="no-cache" />
335: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
336: </head>
337: <body bgcolor="#FFFFFF">
338: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
339: <b>Sorry, no recipients ...</b>
340: </body>
341: </html>
342: ENDFAILREDIR
343: }
344:
345: sub redirect_back {
346: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status) = @_;
347: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
348: $r->print (<<ENDREDIR);
349: <html>
350: <head>
351: <title>Feedback sent</title>
352: <meta http-equiv="pragma" content="no-cache" />
353: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
354: </head>
355: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
356: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
357: $typestyle
358: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
359: <font color="red">$status</font>
360: <form name="reldt" action="$feedurl" target="loncapaclient">
361: </form>
362: </body>
363: </html>
364: ENDREDIR
365: }
366:
367: sub no_redirect_back {
368: my ($r,$feedurl) = @_;
369: $r->print (<<ENDNOREDIR);
370: <html>
371: <head><title>Feedback not sent</title>
372: <meta http-equiv="pragma" content="no-cache" />
373: ENDNOREDIR
374:
375: if ($feedurl!~/^\/adm\/feedback/) {
376: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
377: }
378:
379: $r->print (<<ENDNOREDIRTWO);
380: </head>
381: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
382: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
383: <b>Sorry, no feedback possible on this resource ...</b>
384: </body>
385: </html>
386: ENDNOREDIRTWO
387: }
388:
389: sub screen_header {
390: my ($feedurl) = @_;
391: my $msgoptions='';
392: my $discussoptions='';
393: unless ($ENV{'form.replydisc'}) {
394: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
395: $msgoptions=
396: '<p><input type="checkbox" name="author" /> '.
397: &mt('Feedback to resource author').'</p>';
398: }
399: if (&feedback_available(1)) {
400: $msgoptions.=
401: '<br /><input type="checkbox" name="question" /> '.
402: &mt('Question about resource content');
403: }
404: if (&feedback_available(0,1)) {
405: $msgoptions.=
406: '<br /><input type="checkbox" name="course" /> '.
407: &mt('Question/Comment/Feedback about course content');
408: }
409: if (&feedback_available(0,0,1)) {
410: $msgoptions.=
411: '<br /><input type="checkbox" name="policy" /> '.
412: &mt('Question/Comment/Feedback about course policy');
413: }
414: }
415: if ($ENV{'request.course.id'}) {
416: if (&Apache::lonnet::allowed('pch',
417: $ENV{'request.course.id'}.
418: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
419: $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" /> '.
420: &mt('Contribution to course discussion of resource');
421: $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
422: &mt('Anonymous contribution to course discussion of resource').
423: ' <i>('.&mt('name only visible to course faculty').')</i>';
424: }
425: }
426: if ($msgoptions) { $msgoptions='<h2>'.&mt('Sending Messages').'</h2>'.$msgoptions; }
427: if ($discussoptions) {
428: $discussoptions='<h2>'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
429: return $msgoptions.$discussoptions;
430: }
431:
432: sub resource_output {
433: my ($feedurl) = @_;
434: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
435: $usersaw=~s/\<body[^\>]*\>//gi;
436: $usersaw=~s/\<\/body\>//gi;
437: $usersaw=~s/\<html\>//gi;
438: $usersaw=~s/\<\/html\>//gi;
439: $usersaw=~s/\<head\>//gi;
440: $usersaw=~s/\<\/head\>//gi;
441: $usersaw=~s/action\s*\=/would_be_action\=/gi;
442: return $usersaw;
443: }
444:
445: sub clear_out_html {
446: my ($message,$override)=@_;
447: my $cid=$ENV{'request.course.id'};
448: if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
449: ($override)) {
450: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
451: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG>
452: my %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
453: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
454: M=>1);
455:
456: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
457: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
458: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
459: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
460: } else {
461: $message=~s/\</\<\;/g;
462: $message=~s/\>/\>\;/g;
463: }
464: return $message;
465: }
466:
467: sub assemble_email {
468: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
469: my $email=<<"ENDEMAIL";
470: Refers to <a href="$feedurl">$feedurl</a>
471:
472: $message
473: ENDEMAIL
474: my $citations=<<"ENDCITE";
475: <h2>Previous attempts of student (if applicable)</h2>
476: $prevattempts
477: <br /><hr />
478: <h2>Original screen output (if applicable)</h2>
479: $usersaw
480: <h2>Correct Answer(s) (if applicable)</h2>
481: $useranswer
482: ENDCITE
483: return ($email,$citations);
484: }
485:
486: sub secapply {
487: my $rec=shift;
488: my $defaultflag=shift;
489: $rec=~s/\s+//g;
490: $rec=~s/\@/\:/g;
491: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
492: if ($sections) {
493: foreach (split(/\;/,$sections)) {
494: if (($_ eq $ENV{'request.course.sec'}) ||
495: ($defaultflag && ($_ eq '*'))) {
496: return $adr;
497: }
498: }
499: } else {
500: return $rec;
501: }
502: return '';
503: }
504:
505: sub decide_receiver {
506: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
507: my $typestyle='';
508: my %to=();
509: if ($ENV{'form.author'}||$author) {
510: $typestyle.='Submitting as Author Feedback<br>';
511: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
512: $to{$2.':'.$1}=1;
513: }
514: if ($ENV{'form.question'}||$question) {
515: $typestyle.='Submitting as Question<br>';
516: foreach (split(/\,/,
517: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
518: ) {
519: my $rec=&secapply($_,$defaultflag);
520: if ($rec) { $to{$rec}=1; }
521: }
522: }
523: if ($ENV{'form.course'}||$course) {
524: $typestyle.='Submitting as Comment<br />';
525: foreach (split(/\,/,
526: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
527: ) {
528: my $rec=&secapply($_,$defaultflag);
529: if ($rec) { $to{$rec}=1; }
530: }
531: }
532: if ($ENV{'form.policy'}||$policy) {
533: $typestyle.='Submitting as Policy Feedback<br />';
534: foreach (split(/\,/,
535: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
536: ) {
537: my $rec=&secapply($_,$defaultflag);
538: if ($rec) { $to{$rec}=1; }
539: }
540: }
541: if ((scalar(%to) eq '0') && (!$defaultflag)) {
542: ($typestyle,%to)=
543: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
544: }
545: return ($typestyle,%to);
546: }
547:
548: sub feedback_available {
549: my ($question,$course,$policy)=@_;
550: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
551: return scalar(%to);
552: }
553:
554: sub send_msg {
555: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
556: my $status='';
557: my $sendsomething=0;
558: foreach (keys %to) {
559: if ($_) {
560: my $declutter=&Apache::lonnet::declutter($feedurl);
561: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
562: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
563: $attachmenturl)=~/ok/) {
564: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
565: } else {
566: $sendsomething++;
567: }
568: }
569: }
570:
571: my %record=&Apache::lonnet::restore('_feedback');
572: my ($temp)=keys %record;
573: unless ($temp=~/^error\:/) {
574: my %newrecord=();
575: $newrecord{'resource'}=$feedurl;
576: $newrecord{'subnumber'}=$record{'subnumber'}+1;
577: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
578: $status.='<br />'.&mt('Not registered').'<br />';
579: }
580: }
581:
582: return ($status,$sendsomething);
583: }
584:
585: sub adddiscuss {
586: my ($symb,$email,$anon,$attachmenturl)=@_;
587: my $status='';
588: if (&Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
589: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
590:
591: my %contrib=('message' => $email,
592: 'sendername' => $ENV{'user.name'},
593: 'senderdomain' => $ENV{'user.domain'},
594: 'screenname' => $ENV{'environment.screenname'},
595: 'plainname' => $ENV{'environment.firstname'}.' '.
596: $ENV{'environment.middlename'}.' '.
597: $ENV{'environment.lastname'}.' '.
598: $ENV{'enrironment.generation'},
599: 'attachmenturl'=> $attachmenturl);
600: if ($ENV{'form.replydisc'}) {
601: $contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
602: }
603: if ($anon) {
604: $contrib{'anonymous'}='true';
605: }
606: if (($symb) && ($email)) {
607: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
608: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
609: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
610: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
611: my %storenewentry=($symb => time);
612: $status.='<br />'.&mt('Updating discussion time').': '.
613: &Apache::lonnet::put('discussiontimes',\%storenewentry,
614: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
615: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
616: }
617: my %record=&Apache::lonnet::restore('_discussion');
618: my ($temp)=keys %record;
619: unless ($temp=~/^error\:/) {
620: my %newrecord=();
621: $newrecord{'resource'}=$symb;
622: $newrecord{'subnumber'}=$record{'subnumber'}+1;
623: $status.='<br />'.&mt('Registering').': '.
624: &Apache::lonnet::cstore(\%newrecord,'_discussion');
625: }
626: } else {
627: $status.='Failed.';
628: }
629: return $status.'<br />';
630: }
631:
632: # ----------------------------------------------------------- Preview function
633:
634: sub show_preview {
635: my $r=shift;
636: my $message=&clear_out_html($ENV{'form.comment'});
637: $message=~s/\n/\<br \/\>/g;
638: $message=&Apache::lontexconvert::msgtexconverted($message);
639: $r->print('<table border="2"><tr><td>'.
640: $message.'</td></tr></table>');
641: }
642:
643: sub generate_preview_button {
644: my $pre=&mt("Show Preview");
645: return(<<ENDPREVIEW);
646: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
647: <input type="hidden" name="comment" />
648: <input type="button" value="$pre"
649: onClick="this.form.comment.value=document.mailform.comment.value;this.form.submit();" />
650: </form>
651: ENDPREVIEW
652: }
653:
654: sub handler {
655: my $r = shift;
656: if ($r->header_only) {
657: &Apache::loncommon::content_type($r,'text/html');
658: $r->send_http_header;
659: return OK;
660: }
661:
662: # --------------------------- Get query string for limited number of parameters
663:
664: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
665: ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff']);
666:
667: if (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
668: # ----------------------------------------------------------------- Hide/unhide
669: &Apache::loncommon::content_type($r,'text/html');
670: $r->send_http_header;
671:
672: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
673:
674: my ($symb,$idx)=split(/\:\:\:/,$entry);
675: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
676:
677: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
678: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
679: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
680:
681:
682: my $currenthidden=$contrib{'hidden'};
683:
684: if ($ENV{'form.hide'}) {
685: $currenthidden.='.'.$idx.'.';
686: } else {
687: $currenthidden=~s/\.$idx\.//g;
688: }
689: my %newhash=('hidden' => $currenthidden);
690:
691: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
692: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
693: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
694:
695: &redirect_back($r,&Apache::lonnet::clutter($url),
696: &mt('Changed discussion status').'<br />','0','0');
697: } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
698: &Apache::loncommon::content_type($r,'text/html');
699: $r->send_http_header;
700: if ($ENV{'form.threadedon'}) {
701: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
702: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
703: } else {
704: &Apache::lonnet::del('environment',['threadeddiscussion']);
705: &Apache::lonnet::delenv('environment\.threadeddiscussion');
706: }
707: my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
708: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
709: &redirect_back($r,&Apache::lonnet::clutter($url),
710: &mt('Changed discussion view mode').'<br />','0','0');
711: } elsif ($ENV{'form.deldisc'}) {
712: # --------------------------------------------------------------- Hide for good
713: &Apache::loncommon::content_type($r,'text/html');
714: $r->send_http_header;
715:
716: my $entry=$ENV{'form.deldisc'};
717:
718: my ($symb,$idx)=split(/\:\:\:/,$entry);
719: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
720:
721: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
722: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
723: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
724:
725:
726: my $currentdeleted=$contrib{'deleted'};
727:
728: $currentdeleted.='.'.$idx.'.';
729:
730: my %newhash=('deleted' => $currentdeleted);
731:
732: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
733: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
734: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
735:
736: &redirect_back($r,&Apache::lonnet::clutter($url),
737: &mt('Changed discussion status').'<br />','0','0');
738: } elsif ($ENV{'form.preview'}) {
739: # -------------------------------------------------------- User wants a preview
740: &show_preview($r);
741: } else {
742: # ------------------------------------------------------------- Normal feedback
743: my $feedurl=$ENV{'form.postdata'};
744: $feedurl=~s/^http\:\/\///;
745: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
746: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
747: $feedurl=~s/\?.+$//;
748:
749: my $symb;
750: if ($ENV{'form.replydisc'}) {
751: $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
752: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
753: $feedurl=&Apache::lonnet::clutter($url);
754: } else {
755: $symb=&Apache::lonnet::symbread($feedurl);
756: }
757: unless ($symb) {
758: $symb=$ENV{'form.symb'};
759: if ($symb) {
760: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
761: $feedurl=&Apache::lonnet::clutter($url);
762: }
763: }
764: my $goahead=1;
765: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
766: unless ($symb) { $goahead=0; }
767: }
768:
769: if ($goahead) {
770: # Go ahead with feedback, no ambiguous reference
771: &Apache::loncommon::content_type($r,'text/html');
772: $r->send_http_header;
773:
774: if (
775: (
776: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
777: )
778: ||
779: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
780: ||
781: ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
782: ) {
783: # --------------------------------------------------- Print login screen header
784: unless ($ENV{'form.sendit'}) {
785: my $options=&screen_header($feedurl);
786: if ($options) {
787: &mail_screen($r,$feedurl,$options);
788: } else {
789: &fail_redirect($r,$feedurl);
790: }
791: } else {
792:
793: # Get previous user input
794: my $prevattempts=&Apache::loncommon::get_previous_attempt(
795: $symb,$ENV{'user.name'},$ENV{'user.domain'},
796: $ENV{'request.course.id'});
797:
798: # Get output from resource
799: my $usersaw=&resource_output($feedurl);
800:
801: # Get resource answer (need to allow student to view grades for this to work)
802: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
803: my $useranswer=&Apache::loncommon::get_student_answers(
804: $symb,$ENV{'user.name'},$ENV{'user.domain'},
805: $ENV{'request.course.id'});
806: &Apache::lonnet::delenv('allowed.vgr');
807: # Get attachments, if any, and not too large
808: my $attachmenturl='';
809: if ($ENV{'form.attachment.filename'}) {
810: unless (length($ENV{'form.attachment'})>131072) {
811: $attachmenturl=&Apache::lonnet::userfileupload('attachment');
812: }
813: }
814: # Filter HTML out of message (could be nasty)
815: my $message=&clear_out_html($ENV{'form.comment'});
816:
817: # Assemble email
818: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
819: $usersaw,$useranswer);
820:
821: # Who gets this?
822: my ($typestyle,%to) = &decide_receiver($feedurl);
823:
824: # Actually send mail
825: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
826: $attachmenturl,%to);
827:
828: # Discussion? Store that.
829:
830: my $numpost=0;
831: if ($ENV{'form.discuss'}) {
832: $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl);
833: $numpost++;
834: }
835:
836: if ($ENV{'form.anondiscuss'}) {
837: $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl);
838: $numpost++;
839: }
840:
841:
842: # Receipt screen and redirect back to where came from
843: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status);
844:
845: }
846: } else {
847: # Unable to give feedback
848: &no_redirect_back($r,$feedurl);
849: }
850: } else {
851: # Ambiguous Problem Resource
852: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
853: &Apache::lonnet::cleanenv();
854: }
855: $r->internal_redirect('/adm/ambiguous');
856: }
857: }
858: return OK;
859: }
860:
861: 1;
862: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>