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