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