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