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