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