Annotation of loncom/interface/lonfeedback.pm, revision 1.8
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.7 albertel 15:
1.1 www 16: package Apache::lonfeedback;
17:
18: use strict;
19: use Apache::Constants qw(:common);
1.3 www 20: use Apache::lonmsg();
1.1 www 21:
1.6 albertel 22: sub mail_screen {
23: my ($r,$feedurl,$options) = @_;
24: $r->print(<<ENDDOCUMENT);
1.1 www 25: <html>
26: <head>
27: <title>The LearningOnline Network with CAPA</title>
1.7 albertel 28: <meta http-equiv="pragma" content="no-cache"></meta>
1.5 www 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>
1.1 www 60: </head>
1.5 www 61: <body bgcolor="#FFFFFF" onLoad="window.focus();">
1.2 www 62: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.1 www 63: <h1>Feedback</h1>
1.2 www 64: <h2><tt>$feedurl</tt></h2>
1.5 www 65: <form action="/adm/feedback" method=post name=mailform>
1.2 www 66: <input type=hidden name=postdata value="$feedurl">
1.5 www 67: Please check at least one of the following feedback types:
1.2 www 68: $options<hr>
69: My question/comment/feedback:<p>
70: <textarea name=comment cols=60 rows=10>
71: </textarea><p>
1.5 www 72: <input type=hidden name=sendit value=1>
73: <input type=button value="Send Feedback" onClick='gosubmit();'></input>
1.2 www 74: </form>
1.1 www 75: </body>
76: </html>
77: ENDDOCUMENT
1.6 albertel 78: }
79:
80: sub fail_redirect {
81: my ($r,$feedurl) = @_;
82: $r->print (<<ENDFAILREDIR);
1.5 www 83: <head><title>Feedback not sent</title>
1.7 albertel 84: <meta http-equiv="pragma" content="no-cache"></meta>
1.5 www 85: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
86: </head>
87: <html>
88: <body bgcolor="#FFFFFF">
1.8 ! www 89: <img align=right src=/adm/lonIcons/lonlogos.gif>
! 90: <b>Sorry, no recipients ...</b>
1.5 www 91: </body>
92: </html>
93: ENDFAILREDIR
94: }
1.4 www 95:
1.6 albertel 96: sub redirect_back {
97: my ($r,$feedurl,$typestyle,$sendsomething,$status) = @_;
98: $r->print (<<ENDREDIR);
1.3 www 99: <head>
100: <title>Feedback sent</title>
1.7 albertel 101: <meta http-equiv="pragma" content="no-cache"></meta>
1.5 www 102: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
1.2 www 103: </head>
104: <html>
105: <body bgcolor="#FFFFFF">
1.8 ! www 106: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.5 www 107: $typestyle
108: <b>Sent $sendsomething message(s).</b>
1.3 www 109: <font color=red>$status</font>
1.2 www 110: </body>
111: </html>
112: ENDREDIR
113: }
1.6 albertel 114:
115: sub no_redirect_back {
116: my ($r,$feedurl) = @_;
117: $r->print (<<ENDNOREDIR);
1.2 www 118: <head><title>Feedback not sent</title>
1.7 albertel 119: <meta http-equiv="pragma" content="no-cache"></meta>
120: ENDNOREDIR
121:
1.8 ! www 122: if ($feedurl!~/^\/adm\/feedback/) {
1.7 albertel 123: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
124: }
125:
1.8 ! www 126: $r->print (<<ENDNOREDIRTWO);
1.2 www 127: </head>
128: <html>
129: <body bgcolor="#FFFFFF">
1.8 ! www 130: <img align=right src=/adm/lonIcons/lonlogos.gif>
! 131: <b>Sorry, no feedback possible on this resource ...</b>
1.2 www 132: </body>
133: </html>
1.8 ! www 134: ENDNOREDIRTWO
1.2 www 135: }
1.6 albertel 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.=
1.8 ! www 146: '<br><input type=checkbox name=question> Question about resource content';
1.6 albertel 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 {
1.8 ! www 162: my ($symb)=@_;
1.6 albertel 163: my $prevattempts='';
164: if ($symb) {
165: my $answer=&Apache::lonnet::reply(
1.8 ! www 166: "restore:".$ENV{'user.domain'}.':'.$ENV{'user.name'}.':'.
1.6 albertel 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);
1.8 ! www 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>';
1.6 albertel 185: map {
1.8 ! www 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>';
1.6 albertel 195: map {
1.8 ! www 196: $prevattempts.='<td>'.$lasthash{$_}.'</td>';
1.6 albertel 197: } keys %lasthash;
1.8 ! www 198: $prevattempts.='</tr></table>';
! 199: } else {
! 200: $prevattempts='Nothing submitted - no attempts.';
1.6 albertel 201: }
1.8 ! www 202: } else {
! 203: $prevattempts='No data.';
1.6 albertel 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'}) {
1.8 ! www 249: $typestyle.='Submitting as Author Feedback<br>';
1.6 albertel 250: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
251: $to{$2.':'.$1}=1;
252: }
253: if ($ENV{'form.question'}) {
1.8 ! www 254: $typestyle.='Submitting as Question<br>';
1.6 albertel 255: map {
256: $to{$_}=1;
257: } split(/\,/,
258: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'});
259: }
260: if ($ENV{'form.course'}) {
1.8 ! www 261: $typestyle.='Submitting as Comment<br>';
1.6 albertel 262: map {
263: $to{$_}=1;
264: } split(/\,/,
265: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'});
266: }
267: if ($ENV{'form.policy'}) {
1.8 ! www 268: $typestyle.='Submitting as Policy Feedback<br>';
1.6 albertel 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 ($_) {
1.8 ! www 283: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
! 284: 'Feedback '.$feedurl,$email,$citations) eq 'ok') {
1.6 albertel 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;
1.8 ! www 297: if ($r->header_only) {
! 298: $r->content_type('text/html');
! 299: $r->send_http_header;
! 300: return OK;
! 301: }
1.6 albertel 302:
303: my $feedurl=$ENV{'form.postdata'};
304: $feedurl=~s/^http\:\/\///;
305: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
306: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.8 ! www 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;
1.6 albertel 318:
1.8 ! www 319: if (
1.7 albertel 320: (
321: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
322: )
323: ||
324: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
325: ) {
1.6 albertel 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
1.8 ! www 337: my $prevattempts=&get_previous_attempt($symb);
1.6 albertel 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
1.8 ! www 346: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
! 347: $usersaw);
1.6 albertel 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
1.8 ! www 356: &redirect_back($r,$feedurl,$typestyle,$numsent,$status);
1.6 albertel 357:
358: }
1.8 ! www 359: } else {
1.7 albertel 360: # Unable to give feedback
1.6 albertel 361: &no_redirect_back($r,$feedurl);
1.8 ! www 362: }
! 363: } else {
! 364: # Ambiguous Problem Resource
! 365: $r->internal_redirect('/adm/ambiguous');
1.6 albertel 366: }
367: return OK;
1.1 www 368: }
369:
370: 1;
371: __END__
1.2 www 372:
373:
374:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>