Annotation of loncom/interface/lonfeedback.pm, revision 1.9
1.1 www 1: # The LearningOnline Network
2: # Feedback
3: #
4: # (Internal Server Error Handler
5: #
6: # (Login Screen
7: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
8: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
9: #
10: # 3/1/1 Gerd Kortemeyer)
11: #
1.5 www 12: # 3/1,2/3,2/5,2/6,2/8 Gerd Kortemeyer
1.7 albertel 13: # 2/9 Guy Albertelli
1.8 www 14: # 2/10 Gerd Kortemeyer
1.9 ! albertel 15: # 2/13 Guy Albertelli
1.7 albertel 16:
1.1 www 17: package Apache::lonfeedback;
18:
19: use strict;
20: use Apache::Constants qw(:common);
1.3 www 21: use Apache::lonmsg();
1.9 ! albertel 22: use Apache::loncommon();
1.1 www 23:
1.6 albertel 24: sub mail_screen {
25: my ($r,$feedurl,$options) = @_;
26: $r->print(<<ENDDOCUMENT);
1.1 www 27: <html>
28: <head>
29: <title>The LearningOnline Network with CAPA</title>
1.7 albertel 30: <meta http-equiv="pragma" content="no-cache"></meta>
1.5 www 31: <script>
32: function gosubmit() {
33: var rec=0;
34: if (document.mailform.elements.author!=undefined) {
35: if (document.mailform.elements.author.checked) {
36: rec=1;
37: }
38: }
39: if (document.mailform.elements.question!=undefined) {
40: if (document.mailform.elements.question.checked) {
41: rec=1;
42: }
43: }
44: if (document.mailform.elements.course!=undefined) {
45: if (document.mailform.elements.course.checked) {
46: rec=1;
47: }
48: }
49: if (document.mailform.elements.policy!=undefined) {
50: if (document.mailform.elements.policy.checked) {
51: rec=1;
52: }
53: }
54:
55: if (rec) {
56: document.mailform.submit();
57: } else {
58: alert('Please check a feedback type.');
59: }
60: }
61: </script>
1.1 www 62: </head>
1.5 www 63: <body bgcolor="#FFFFFF" onLoad="window.focus();">
1.2 www 64: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.1 www 65: <h1>Feedback</h1>
1.2 www 66: <h2><tt>$feedurl</tt></h2>
1.5 www 67: <form action="/adm/feedback" method=post name=mailform>
1.2 www 68: <input type=hidden name=postdata value="$feedurl">
1.5 www 69: Please check at least one of the following feedback types:
1.2 www 70: $options<hr>
71: My question/comment/feedback:<p>
72: <textarea name=comment cols=60 rows=10>
73: </textarea><p>
1.5 www 74: <input type=hidden name=sendit value=1>
75: <input type=button value="Send Feedback" onClick='gosubmit();'></input>
1.2 www 76: </form>
1.1 www 77: </body>
78: </html>
79: ENDDOCUMENT
1.6 albertel 80: }
81:
82: sub fail_redirect {
83: my ($r,$feedurl) = @_;
84: $r->print (<<ENDFAILREDIR);
1.5 www 85: <head><title>Feedback not sent</title>
1.7 albertel 86: <meta http-equiv="pragma" content="no-cache"></meta>
1.5 www 87: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
88: </head>
89: <html>
90: <body bgcolor="#FFFFFF">
1.8 www 91: <img align=right src=/adm/lonIcons/lonlogos.gif>
92: <b>Sorry, no recipients ...</b>
1.5 www 93: </body>
94: </html>
95: ENDFAILREDIR
96: }
1.4 www 97:
1.6 albertel 98: sub redirect_back {
99: my ($r,$feedurl,$typestyle,$sendsomething,$status) = @_;
100: $r->print (<<ENDREDIR);
1.3 www 101: <head>
102: <title>Feedback sent</title>
1.7 albertel 103: <meta http-equiv="pragma" content="no-cache"></meta>
1.5 www 104: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
1.2 www 105: </head>
106: <html>
107: <body bgcolor="#FFFFFF">
1.8 www 108: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.5 www 109: $typestyle
110: <b>Sent $sendsomething message(s).</b>
1.3 www 111: <font color=red>$status</font>
1.2 www 112: </body>
113: </html>
114: ENDREDIR
115: }
1.6 albertel 116:
117: sub no_redirect_back {
118: my ($r,$feedurl) = @_;
119: $r->print (<<ENDNOREDIR);
1.2 www 120: <head><title>Feedback not sent</title>
1.7 albertel 121: <meta http-equiv="pragma" content="no-cache"></meta>
122: ENDNOREDIR
123:
1.8 www 124: if ($feedurl!~/^\/adm\/feedback/) {
1.7 albertel 125: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
126: }
127:
1.8 www 128: $r->print (<<ENDNOREDIRTWO);
1.2 www 129: </head>
130: <html>
131: <body bgcolor="#FFFFFF">
1.8 www 132: <img align=right src=/adm/lonIcons/lonlogos.gif>
133: <b>Sorry, no feedback possible on this resource ...</b>
1.2 www 134: </body>
135: </html>
1.8 www 136: ENDNOREDIRTWO
1.2 www 137: }
1.6 albertel 138:
139: sub screen_header {
140: my ($feedurl) = @_;
141: my $options='';
142: if (($feedurl=~/^\/res/) && ($feedurl!~/^\/res\/adm/)) {
143: $options=
144: '<p><input type=checkbox name=author> Feedback to resource author';
145: }
146: if ($ENV{'course.'.$ENV{'request.course.id'}.'.question.email'}) {
147: $options.=
1.8 www 148: '<br><input type=checkbox name=question> Question about resource content';
1.6 albertel 149: }
150: if ($ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'}) {
151: $options.=
152: '<br><input type=checkbox name=course> '.
153: 'Question/Comment/Feedback about course content';
154: }
155: if ($ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'}) {
156: $options.=
157: '<br><input type=checkbox name=policy> '.
158: 'Question/Comment/Feedback about course policy';
159: }
160: return $options;
161: }
162:
163: sub resource_output {
164: my ($feedurl) = @_;
165: my $usersaw=&Apache::lonnet::ssi($feedurl);
166: $usersaw=~s/\<body[^\>]*\>//gi;
167: $usersaw=~s/\<\/body\>//gi;
168: $usersaw=~s/\<html\>//gi;
169: $usersaw=~s/\<\/html\>//gi;
170: $usersaw=~s/\<head\>//gi;
171: $usersaw=~s/\<\/head\>//gi;
172: $usersaw=~s/action\s*\=/would_be_action\=/gi;
173: return $usersaw;
174: }
175:
176: sub clear_out_html {
177: my $message=$ENV{'form.comment'};
178: $message=~s/\</\<\;/g;
179: $message=~s/\>/\>\;/g;
180: return $message;
181: }
182:
183: sub assemble_email {
184: my ($feedurl,$message,$prevattempts,$usersaw)=@_;
185: my $email=<<"ENDEMAIL";
186: Refers to <a href="$feedurl">$feedurl</a>
187:
188: $message
189: ENDEMAIL
190: my $citations=<<"ENDCITE";
191: <h2>Previous attempts of student (if applicable)</h2>
192: $prevattempts
193: <p><hr>
194: <h2>Original screen output (if applicable)</h2>
195: $usersaw
196: ENDCITE
197: return ($email,$citations);
198: }
199:
200: sub decide_receiver {
201: my ($feedurl) = @_;
202: my $typestyle='';
203: my %to=();
204: if ($ENV{'form.author'}) {
1.8 www 205: $typestyle.='Submitting as Author Feedback<br>';
1.6 albertel 206: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
207: $to{$2.':'.$1}=1;
208: }
209: if ($ENV{'form.question'}) {
1.8 www 210: $typestyle.='Submitting as Question<br>';
1.6 albertel 211: map {
212: $to{$_}=1;
213: } split(/\,/,
214: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'});
215: }
216: if ($ENV{'form.course'}) {
1.8 www 217: $typestyle.='Submitting as Comment<br>';
1.6 albertel 218: map {
219: $to{$_}=1;
220: } split(/\,/,
221: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'});
222: }
223: if ($ENV{'form.policy'}) {
1.8 www 224: $typestyle.='Submitting as Policy Feedback<br>';
1.6 albertel 225: map {
226: $to{$_}=1;
227: } split(/\,/,
228: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'});
229: }
230: return ($typestyle,%to);
231: }
232:
233: sub send_msg {
234: my ($feedurl,$email,$citations,%to)=@_;
235: my $status='';
236: my $sendsomething=0;
237: map {
238: if ($_) {
1.8 www 239: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
240: 'Feedback '.$feedurl,$email,$citations) eq 'ok') {
1.6 albertel 241: $status.='<br>Error sending message to '.$_.'<br>';
242: } else {
243: #$status.='<br>Message sent to '.$_.'<br>';
244: $sendsomething++;
245: }
246: }
247: } keys %to;
248: return ($status,$sendsomething);
249: }
250:
251: sub handler {
252: my $r = shift;
1.8 www 253: if ($r->header_only) {
254: $r->content_type('text/html');
255: $r->send_http_header;
256: return OK;
257: }
1.6 albertel 258:
259: my $feedurl=$ENV{'form.postdata'};
260: $feedurl=~s/^http\:\/\///;
261: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
262: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.8 www 263:
264: my $symb=&Apache::lonnet::symbread($feedurl);
265: my $goahead=1;
266: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
267: unless ($symb) { $goahead=0; }
268: }
269:
270: if ($goahead) {
271: # Go ahead with feedback, no ambiguous reference
272: $r->content_type('text/html');
273: $r->send_http_header;
1.6 albertel 274:
1.8 www 275: if (
1.7 albertel 276: (
277: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
278: )
279: ||
280: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
281: ) {
1.6 albertel 282: # --------------------------------------------------- Print login screen header
283: unless ($ENV{'form.sendit'}) {
284: my $options=&screen_header($feedurl);
285: if ($options) {
286: &mail_screen($r,$feedurl,$options);
287: } else {
288: &fail_redirect($r,$feedurl);
289: }
290: } else {
291:
292: # Get previous user input
1.9 ! albertel 293: my $prevattempts=&Apache::loncommon::get_previous_attempt(
! 294: $symb,$ENV{'user.name'},$ENV{'user.domain'},$ENV{'user.home'},
! 295: $ENV{'request.course.id'});
1.6 albertel 296:
297: # Get output from resource
298: my $usersaw=&resource_output($feedurl);
299:
300: # Filter HTML out of message (could be nasty)
301: my $message=&clear_out_html;
302:
303: # Assemble email
1.8 www 304: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
305: $usersaw);
1.6 albertel 306:
307: # Who gets this?
308: my ($typestyle,%to) = &decide_receiver($feedurl);
309:
310: # Actually send mail
311: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,%to);
312:
313: # Receipt screen and redirect back to where came from
1.8 www 314: &redirect_back($r,$feedurl,$typestyle,$numsent,$status);
1.6 albertel 315:
316: }
1.8 www 317: } else {
1.7 albertel 318: # Unable to give feedback
1.6 albertel 319: &no_redirect_back($r,$feedurl);
1.8 www 320: }
321: } else {
322: # Ambiguous Problem Resource
323: $r->internal_redirect('/adm/ambiguous');
1.6 albertel 324: }
325: return OK;
1.1 www 326: }
327:
328: 1;
329: __END__
1.2 www 330:
331:
332:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>