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