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,8/10,10/1,11/5 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: if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
64: if (document.mailform.elements.anondiscuss.checked) {
65: rec=1;
66: }
67: }
68:
69: if (rec) {
70: document.mailform.submit();
71: } else {
72: alert('Please check a feedback type.');
73: }
74: }
75: </script>
76: </head>
77: <body bgcolor="#FFFFFF" onLoad="window.focus();">
78: <img align=right src=/adm/lonIcons/lonlogos.gif>
79: <h1>Feedback</h1>
80: <h2><tt>$feedurl</tt></h2>
81: <form action="/adm/feedback" method=post name=mailform>
82: <input type=hidden name=postdata value="$feedurl">
83: Please check at least one of the following feedback types:
84: $options<hr>
85: My question/comment/feedback:<p>
86: <textarea name=comment cols=60 rows=10 wrap=hard>
87: </textarea><p>
88: <input type=hidden name=sendit value=1>
89: <input type=button value="Send Feedback" onClick='gosubmit();'></input>
90: </form>
91: </body>
92: </html>
93: ENDDOCUMENT
94: }
95:
96: sub fail_redirect {
97: my ($r,$feedurl) = @_;
98: $r->print (<<ENDFAILREDIR);
99: <head><title>Feedback not sent</title>
100: <meta http-equiv="pragma" content="no-cache"></meta>
101: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
102: </head>
103: <html>
104: <body bgcolor="#FFFFFF">
105: <img align=right src=/adm/lonIcons/lonlogos.gif>
106: <b>Sorry, no recipients ...</b>
107: </body>
108: </html>
109: ENDFAILREDIR
110: }
111:
112: sub redirect_back {
113: my ($r,$feedurl,$typestyle,$sendsomething,$status) = @_;
114: $r->print (<<ENDREDIR);
115: <head>
116: <title>Feedback sent</title>
117: <meta http-equiv="pragma" content="no-cache"></meta>
118: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
119: </head>
120: <html>
121: <body bgcolor="#FFFFFF">
122: <img align=right src=/adm/lonIcons/lonlogos.gif>
123: $typestyle
124: <b>Sent $sendsomething message(s).</b>
125: <font color=red>$status</font>
126: </body>
127: </html>
128: ENDREDIR
129: }
130:
131: sub no_redirect_back {
132: my ($r,$feedurl) = @_;
133: $r->print (<<ENDNOREDIR);
134: <head><title>Feedback not sent</title>
135: <meta http-equiv="pragma" content="no-cache"></meta>
136: ENDNOREDIR
137:
138: if ($feedurl!~/^\/adm\/feedback/) {
139: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
140: }
141:
142: $r->print (<<ENDNOREDIRTWO);
143: </head>
144: <html>
145: <body bgcolor="#FFFFFF">
146: <img align=right src=/adm/lonIcons/lonlogos.gif>
147: <b>Sorry, no feedback possible on this resource ...</b>
148: </body>
149: </html>
150: ENDNOREDIRTWO
151: }
152:
153: sub screen_header {
154: my ($feedurl) = @_;
155: my $options='';
156: if (($feedurl=~/^\/res/) && ($feedurl!~/^\/res\/adm/)) {
157: $options=
158: '<p><input type=checkbox name=author> Feedback to resource author';
159: }
160: if ($ENV{'course.'.$ENV{'request.course.id'}.'.question.email'}) {
161: $options.=
162: '<br><input type=checkbox name=question> Question about resource content';
163: }
164: if ($ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'}) {
165: $options.=
166: '<br><input type=checkbox name=course> '.
167: 'Question/Comment/Feedback about course content';
168: }
169: if ($ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'}) {
170: $options.=
171: '<br><input type=checkbox name=policy> '.
172: 'Question/Comment/Feedback about course policy';
173: }
174: if ($ENV{'request.course.id'}) {
175: $options.='<br><input type=checkbox name=discuss> '.
176: '<b>Contribution to course discussion of resource</b>';
177: }
178: if ($ENV{'request.course.id'}) {
179: $options.='<br><input type=checkbox name=anondiscuss> '.
180: '<b>Anonymous contribution to course discussion of resource</b>'.
181: ' (name only visible to course faculty)';
182: }
183: return $options;
184: }
185:
186: sub resource_output {
187: my ($feedurl) = @_;
188: my $usersaw=&Apache::lonnet::ssi($feedurl);
189: $usersaw=~s/\<body[^\>]*\>//gi;
190: $usersaw=~s/\<\/body\>//gi;
191: $usersaw=~s/\<html\>//gi;
192: $usersaw=~s/\<\/html\>//gi;
193: $usersaw=~s/\<head\>//gi;
194: $usersaw=~s/\<\/head\>//gi;
195: $usersaw=~s/action\s*\=/would_be_action\=/gi;
196: return $usersaw;
197: }
198:
199: sub clear_out_html {
200: my $message=$ENV{'form.comment'};
201: $message=~s/\</\<\;/g;
202: $message=~s/\>/\>\;/g;
203: return $message;
204: }
205:
206: sub assemble_email {
207: my ($feedurl,$message,$prevattempts,$usersaw)=@_;
208: my $email=<<"ENDEMAIL";
209: Refers to <a href="$feedurl">$feedurl</a>
210:
211: $message
212: ENDEMAIL
213: my $citations=<<"ENDCITE";
214: <h2>Previous attempts of student (if applicable)</h2>
215: $prevattempts
216: <p><hr>
217: <h2>Original screen output (if applicable)</h2>
218: $usersaw
219: ENDCITE
220: return ($email,$citations);
221: }
222:
223: sub decide_receiver {
224: my ($feedurl) = @_;
225: my $typestyle='';
226: my %to=();
227: if ($ENV{'form.author'}) {
228: $typestyle.='Submitting as Author Feedback<br>';
229: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
230: $to{$2.':'.$1}=1;
231: }
232: if ($ENV{'form.question'}) {
233: $typestyle.='Submitting as Question<br>';
234: map {
235: $to{$_}=1;
236: } split(/\,/,
237: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'});
238: }
239: if ($ENV{'form.course'}) {
240: $typestyle.='Submitting as Comment<br>';
241: map {
242: $to{$_}=1;
243: } split(/\,/,
244: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'});
245: }
246: if ($ENV{'form.policy'}) {
247: $typestyle.='Submitting as Policy Feedback<br>';
248: map {
249: $to{$_}=1;
250: } split(/\,/,
251: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'});
252: }
253: return ($typestyle,%to);
254: }
255:
256: sub send_msg {
257: my ($feedurl,$email,$citations,%to)=@_;
258: my $status='';
259: my $sendsomething=0;
260: map {
261: if ($_) {
262: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
263: 'Feedback '.$feedurl,$email,$citations) eq 'ok') {
264: $status.='<br>Error sending message to '.$_.'<br>';
265: } else {
266: #$status.='<br>Message sent to '.$_.'<br>';
267: $sendsomething++;
268: }
269: }
270: } keys %to;
271: return ($status,$sendsomething);
272: }
273:
274: sub adddiscuss {
275: my ($symb,$email,$anon)=@_;
276: my $status='';
277: my %contrib=('message' => $email,
278: 'sendername' => $ENV{'user.name'},
279: 'senderdomain' => $ENV{'user.domain'});
280: if ($anon) {
281: $contrib{'anonymous'}='true';
282: }
283: if (($symb) && ($email)) {
284: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
285: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
286: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
287: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
288: }
289: my $now=time;
290: my %record=&Apache::lonnet::restore('_discussion');
291: my ($temp)=keys %record;
292: unless ($temp=~/^error\:/) {
293: my %newrecord=();
294: $newrecord{'resource'}=$symb;
295: $newrecord{'subnumber'}=$record{'subnumber'}+1;
296: $status.=' '.&Apache::lonnet::cstore(\%newrecord,'_discussion');
297: }
298: return $status.'<br>';
299: }
300:
301: sub handler {
302: my $r = shift;
303: if ($r->header_only) {
304: $r->content_type('text/html');
305: $r->send_http_header;
306: return OK;
307: }
308:
309: # --------------------------- Get query string for limited number of parameters
310:
311: map {
312: my ($name, $value) = split(/=/,$_);
313: $value =~ tr/+/ /;
314: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
315: if (($name eq 'hide') || ($name eq 'unhide')) {
316: unless ($ENV{'form.'.$name}) {
317: $ENV{'form.'.$name}=$value;
318: }
319: }
320: } (split(/&/,$ENV{'QUERY_STRING'}));
321:
322: if (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
323: # ----------------------------------------------------------------- Hide/unhide
324: $r->content_type('text/html');
325: $r->send_http_header;
326:
327: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
328:
329: my ($symb,$idx)=split(/\:\:\:/,$entry);
330: my ($map,$ind,$url)=split(/\_\_\_/,$symb);
331:
332: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
333: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
334: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
335:
336:
337: my $currenthidden=$contrib{'hidden'};
338:
339: if ($ENV{'form.hide'}) {
340: $currenthidden.='.'.$idx.'.';
341: } else {
342: $currenthidden=~s/\.$idx\.//g;
343: }
344: my %newhash=('hidden' => $currenthidden);
345:
346: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
347: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
348: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
349:
350: &redirect_back($r,'/res/'.$url,'Changed discussion status<p>','0');
351:
352:
353: } else {
354: # ------------------------------------------------------------- Normal feedback
355: my $feedurl=$ENV{'form.postdata'};
356: $feedurl=~s/^http\:\/\///;
357: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
358: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
359:
360: my $symb=&Apache::lonnet::symbread($feedurl);
361: my $goahead=1;
362: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
363: unless ($symb) { $goahead=0; }
364: }
365:
366: if ($goahead) {
367: # Go ahead with feedback, no ambiguous reference
368: $r->content_type('text/html');
369: $r->send_http_header;
370:
371: if (
372: (
373: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
374: )
375: ||
376: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
377: ) {
378: # --------------------------------------------------- Print login screen header
379: unless ($ENV{'form.sendit'}) {
380: my $options=&screen_header($feedurl);
381: if ($options) {
382: &mail_screen($r,$feedurl,$options);
383: } else {
384: &fail_redirect($r,$feedurl);
385: }
386: } else {
387:
388: # Get previous user input
389: my $prevattempts=&Apache::loncommon::get_previous_attempt(
390: $symb,$ENV{'user.name'},$ENV{'user.domain'},
391: $ENV{'request.course.id'});
392:
393: # Get output from resource
394: my $usersaw=&resource_output($feedurl);
395:
396: # Filter HTML out of message (could be nasty)
397: my $message=&clear_out_html;
398:
399: # Assemble email
400: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
401: $usersaw);
402:
403: # Who gets this?
404: my ($typestyle,%to) = &decide_receiver($feedurl);
405:
406: # Actually send mail
407: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,%to);
408:
409: # Discussion? Store that.
410:
411: if ($ENV{'form.discuss'}) {
412: $typestyle.=&adddiscuss($symb,$message);
413: }
414:
415: if ($ENV{'form.anondiscuss'}) {
416: $typestyle.=&adddiscuss($symb,$message,1);
417: }
418:
419:
420: # Receipt screen and redirect back to where came from
421: &redirect_back($r,$feedurl,$typestyle,$numsent,$status);
422:
423: }
424: } else {
425: # Unable to give feedback
426: &no_redirect_back($r,$feedurl);
427: }
428: } else {
429: # Ambiguous Problem Resource
430: $r->internal_redirect('/adm/ambiguous');
431: }
432: }
433: return OK;
434: }
435:
436: 1;
437: __END__
438:
439:
440:
441:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>