Annotation of loncom/interface/lonfeedback.pm, revision 1.13
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.10 www 16: # 7/25 Gerd Kortemeyer
1.13 ! www 17: # 7/26 Guy Albertelli
! 18: # 7/26 Gerd Kortemeyer
! 19:
1.7 albertel 20:
1.1 www 21: package Apache::lonfeedback;
22:
23: use strict;
24: use Apache::Constants qw(:common);
1.3 www 25: use Apache::lonmsg();
1.9 albertel 26: use Apache::loncommon();
1.1 www 27:
1.6 albertel 28: sub mail_screen {
29: my ($r,$feedurl,$options) = @_;
30: $r->print(<<ENDDOCUMENT);
1.1 www 31: <html>
32: <head>
33: <title>The LearningOnline Network with CAPA</title>
1.7 albertel 34: <meta http-equiv="pragma" content="no-cache"></meta>
1.5 www 35: <script>
36: function gosubmit() {
37: var rec=0;
1.12 albertel 38: if (typeof(document.mailform.elements.author)!="undefined") {
1.5 www 39: if (document.mailform.elements.author.checked) {
40: rec=1;
41: }
42: }
1.12 albertel 43: if (typeof(document.mailform.elements.question)!="undefined") {
1.5 www 44: if (document.mailform.elements.question.checked) {
45: rec=1;
46: }
47: }
1.12 albertel 48: if (typeof(document.mailform.elements.course)!="undefined") {
1.5 www 49: if (document.mailform.elements.course.checked) {
50: rec=1;
51: }
52: }
1.12 albertel 53: if (typeof(document.mailform.elements.policy)!="undefined") {
1.5 www 54: if (document.mailform.elements.policy.checked) {
55: rec=1;
56: }
57: }
1.12 albertel 58: if (typeof(document.mailform.elements.discuss)!="undefined") {
1.10 www 59: if (document.mailform.elements.discuss.checked) {
60: rec=1;
61: }
62: }
1.5 www 63:
64: if (rec) {
65: document.mailform.submit();
66: } else {
67: alert('Please check a feedback type.');
68: }
69: }
70: </script>
1.1 www 71: </head>
1.5 www 72: <body bgcolor="#FFFFFF" onLoad="window.focus();">
1.2 www 73: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.1 www 74: <h1>Feedback</h1>
1.2 www 75: <h2><tt>$feedurl</tt></h2>
1.5 www 76: <form action="/adm/feedback" method=post name=mailform>
1.2 www 77: <input type=hidden name=postdata value="$feedurl">
1.5 www 78: Please check at least one of the following feedback types:
1.2 www 79: $options<hr>
80: My question/comment/feedback:<p>
81: <textarea name=comment cols=60 rows=10>
82: </textarea><p>
1.5 www 83: <input type=hidden name=sendit value=1>
84: <input type=button value="Send Feedback" onClick='gosubmit();'></input>
1.2 www 85: </form>
1.1 www 86: </body>
87: </html>
88: ENDDOCUMENT
1.6 albertel 89: }
90:
91: sub fail_redirect {
92: my ($r,$feedurl) = @_;
93: $r->print (<<ENDFAILREDIR);
1.5 www 94: <head><title>Feedback not sent</title>
1.7 albertel 95: <meta http-equiv="pragma" content="no-cache"></meta>
1.5 www 96: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
97: </head>
98: <html>
99: <body bgcolor="#FFFFFF">
1.8 www 100: <img align=right src=/adm/lonIcons/lonlogos.gif>
101: <b>Sorry, no recipients ...</b>
1.5 www 102: </body>
103: </html>
104: ENDFAILREDIR
105: }
1.4 www 106:
1.6 albertel 107: sub redirect_back {
108: my ($r,$feedurl,$typestyle,$sendsomething,$status) = @_;
109: $r->print (<<ENDREDIR);
1.3 www 110: <head>
111: <title>Feedback sent</title>
1.7 albertel 112: <meta http-equiv="pragma" content="no-cache"></meta>
1.5 www 113: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
1.2 www 114: </head>
115: <html>
116: <body bgcolor="#FFFFFF">
1.8 www 117: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.5 www 118: $typestyle
119: <b>Sent $sendsomething message(s).</b>
1.3 www 120: <font color=red>$status</font>
1.2 www 121: </body>
122: </html>
123: ENDREDIR
124: }
1.6 albertel 125:
126: sub no_redirect_back {
127: my ($r,$feedurl) = @_;
128: $r->print (<<ENDNOREDIR);
1.2 www 129: <head><title>Feedback not sent</title>
1.7 albertel 130: <meta http-equiv="pragma" content="no-cache"></meta>
131: ENDNOREDIR
132:
1.8 www 133: if ($feedurl!~/^\/adm\/feedback/) {
1.7 albertel 134: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
135: }
136:
1.8 www 137: $r->print (<<ENDNOREDIRTWO);
1.2 www 138: </head>
139: <html>
140: <body bgcolor="#FFFFFF">
1.8 www 141: <img align=right src=/adm/lonIcons/lonlogos.gif>
142: <b>Sorry, no feedback possible on this resource ...</b>
1.2 www 143: </body>
144: </html>
1.8 www 145: ENDNOREDIRTWO
1.2 www 146: }
1.6 albertel 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.=
1.8 www 157: '<br><input type=checkbox name=question> Question about resource content';
1.6 albertel 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';
1.10 www 168: }
169: if ($ENV{'request.course.id'}) {
170: $options.='<br><input type=checkbox name=discuss> '.
171: '<b>Contribution to course discussion of resource</b>';
1.6 albertel 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'}) {
1.8 www 218: $typestyle.='Submitting as Author Feedback<br>';
1.6 albertel 219: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
220: $to{$2.':'.$1}=1;
221: }
222: if ($ENV{'form.question'}) {
1.8 www 223: $typestyle.='Submitting as Question<br>';
1.6 albertel 224: map {
225: $to{$_}=1;
226: } split(/\,/,
227: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'});
228: }
229: if ($ENV{'form.course'}) {
1.8 www 230: $typestyle.='Submitting as Comment<br>';
1.6 albertel 231: map {
232: $to{$_}=1;
233: } split(/\,/,
234: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'});
235: }
236: if ($ENV{'form.policy'}) {
1.8 www 237: $typestyle.='Submitting as Policy Feedback<br>';
1.6 albertel 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 ($_) {
1.8 www 252: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
253: 'Feedback '.$feedurl,$email,$citations) eq 'ok') {
1.6 albertel 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:
1.13 ! www 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:
1.6 albertel 280: sub handler {
281: my $r = shift;
1.8 www 282: if ($r->header_only) {
283: $r->content_type('text/html');
284: $r->send_http_header;
285: return OK;
286: }
1.6 albertel 287:
288: my $feedurl=$ENV{'form.postdata'};
289: $feedurl=~s/^http\:\/\///;
290: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
291: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.8 www 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;
1.6 albertel 303:
1.8 www 304: if (
1.7 albertel 305: (
306: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
307: )
308: ||
309: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
310: ) {
1.6 albertel 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
1.9 albertel 322: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11 albertel 323: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9 albertel 324: $ENV{'request.course.id'});
1.6 albertel 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
1.8 www 333: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
334: $usersaw);
1.6 albertel 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);
1.13 ! www 341:
! 342: # Discussion? Store that.
! 343:
! 344: if ($ENV{'form.discuss'}) {
! 345: $typestyle.=&adddiscuss($symb,$message);
! 346: }
1.6 albertel 347:
348: # Receipt screen and redirect back to where came from
1.8 www 349: &redirect_back($r,$feedurl,$typestyle,$numsent,$status);
1.6 albertel 350:
351: }
1.8 www 352: } else {
1.7 albertel 353: # Unable to give feedback
1.6 albertel 354: &no_redirect_back($r,$feedurl);
1.8 www 355: }
356: } else {
357: # Ambiguous Problem Resource
358: $r->internal_redirect('/adm/ambiguous');
1.6 albertel 359: }
360: return OK;
1.1 www 361: }
362:
363: 1;
364: __END__
1.2 www 365:
366:
367:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>