Annotation of loncom/interface/lonfeedback.pm, revision 1.15
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
1.14 www 18: # 7/26,8/10 Gerd Kortemeyer
1.13 www 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.14 www 63: if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
64: if (document.mailform.elements.anondiscuss.checked) {
65: rec=1;
66: }
67: }
1.5 www 68:
69: if (rec) {
70: document.mailform.submit();
71: } else {
72: alert('Please check a feedback type.');
73: }
74: }
75: </script>
1.1 www 76: </head>
1.5 www 77: <body bgcolor="#FFFFFF" onLoad="window.focus();">
1.2 www 78: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.1 www 79: <h1>Feedback</h1>
1.2 www 80: <h2><tt>$feedurl</tt></h2>
1.5 www 81: <form action="/adm/feedback" method=post name=mailform>
1.2 www 82: <input type=hidden name=postdata value="$feedurl">
1.5 www 83: Please check at least one of the following feedback types:
1.2 www 84: $options<hr>
85: My question/comment/feedback:<p>
86: <textarea name=comment cols=60 rows=10>
87: </textarea><p>
1.5 www 88: <input type=hidden name=sendit value=1>
89: <input type=button value="Send Feedback" onClick='gosubmit();'></input>
1.2 www 90: </form>
1.1 www 91: </body>
92: </html>
93: ENDDOCUMENT
1.6 albertel 94: }
95:
96: sub fail_redirect {
97: my ($r,$feedurl) = @_;
98: $r->print (<<ENDFAILREDIR);
1.5 www 99: <head><title>Feedback not sent</title>
1.7 albertel 100: <meta http-equiv="pragma" content="no-cache"></meta>
1.5 www 101: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
102: </head>
103: <html>
104: <body bgcolor="#FFFFFF">
1.8 www 105: <img align=right src=/adm/lonIcons/lonlogos.gif>
106: <b>Sorry, no recipients ...</b>
1.5 www 107: </body>
108: </html>
109: ENDFAILREDIR
110: }
1.4 www 111:
1.6 albertel 112: sub redirect_back {
113: my ($r,$feedurl,$typestyle,$sendsomething,$status) = @_;
114: $r->print (<<ENDREDIR);
1.3 www 115: <head>
116: <title>Feedback sent</title>
1.7 albertel 117: <meta http-equiv="pragma" content="no-cache"></meta>
1.5 www 118: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
1.2 www 119: </head>
120: <html>
121: <body bgcolor="#FFFFFF">
1.8 www 122: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.5 www 123: $typestyle
124: <b>Sent $sendsomething message(s).</b>
1.3 www 125: <font color=red>$status</font>
1.2 www 126: </body>
127: </html>
128: ENDREDIR
129: }
1.6 albertel 130:
131: sub no_redirect_back {
132: my ($r,$feedurl) = @_;
133: $r->print (<<ENDNOREDIR);
1.2 www 134: <head><title>Feedback not sent</title>
1.7 albertel 135: <meta http-equiv="pragma" content="no-cache"></meta>
136: ENDNOREDIR
137:
1.8 www 138: if ($feedurl!~/^\/adm\/feedback/) {
1.7 albertel 139: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
140: }
141:
1.8 www 142: $r->print (<<ENDNOREDIRTWO);
1.2 www 143: </head>
144: <html>
145: <body bgcolor="#FFFFFF">
1.8 www 146: <img align=right src=/adm/lonIcons/lonlogos.gif>
147: <b>Sorry, no feedback possible on this resource ...</b>
1.2 www 148: </body>
149: </html>
1.8 www 150: ENDNOREDIRTWO
1.2 www 151: }
1.6 albertel 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.=
1.8 www 162: '<br><input type=checkbox name=question> Question about resource content';
1.6 albertel 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';
1.10 www 173: }
174: if ($ENV{'request.course.id'}) {
175: $options.='<br><input type=checkbox name=discuss> '.
176: '<b>Contribution to course discussion of resource</b>';
1.6 albertel 177: }
1.14 www 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: }
1.6 albertel 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'}) {
1.8 www 228: $typestyle.='Submitting as Author Feedback<br>';
1.6 albertel 229: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
230: $to{$2.':'.$1}=1;
231: }
232: if ($ENV{'form.question'}) {
1.8 www 233: $typestyle.='Submitting as Question<br>';
1.6 albertel 234: map {
235: $to{$_}=1;
236: } split(/\,/,
237: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'});
238: }
239: if ($ENV{'form.course'}) {
1.8 www 240: $typestyle.='Submitting as Comment<br>';
1.6 albertel 241: map {
242: $to{$_}=1;
243: } split(/\,/,
244: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'});
245: }
246: if ($ENV{'form.policy'}) {
1.8 www 247: $typestyle.='Submitting as Policy Feedback<br>';
1.6 albertel 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 ($_) {
1.8 www 262: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
263: 'Feedback '.$feedurl,$email,$citations) eq 'ok') {
1.6 albertel 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:
1.13 www 274: sub adddiscuss {
1.14 www 275: my ($symb,$email,$anon)=@_;
1.13 www 276: my $status='';
277: my %contrib=('message' => $email,
278: 'sendername' => $ENV{'user.name'},
279: 'senderdomain' => $ENV{'user.domain'});
1.14 www 280: if ($anon) {
281: $contrib{'anonymous'}='true';
282: }
1.13 www 283: if (($symb) && ($email)) {
1.14 www 284: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1.13 www 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: '<br>';
289: }
290: return $status;
291: }
292:
1.6 albertel 293: sub handler {
294: my $r = shift;
1.8 www 295: if ($r->header_only) {
296: $r->content_type('text/html');
297: $r->send_http_header;
298: return OK;
299: }
1.15 ! www 300:
! 301: # --------------------------- Get query string for limited number of parameters
! 302:
! 303: map {
! 304: my ($name, $value) = split(/=/,$_);
! 305: $value =~ tr/+/ /;
! 306: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
! 307: if (($name eq 'hide') || ($name eq 'unhide')) {
! 308: unless ($ENV{'form.'.$name}) {
! 309: $ENV{'form.'.$name}=$value;
! 310: }
! 311: }
! 312: } (split(/&/,$ENV{'QUERY_STRING'}));
! 313:
! 314: if (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
! 315: # ----------------------------------------------------------------- Hide/unhide
! 316: $r->content_type('text/html');
! 317: $r->send_http_header;
! 318:
! 319: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
! 320:
! 321: my ($symb,$idx)=split(/\:\:\:/,$entry);
! 322: my ($map,$ind,$url)=split(/\_\_\_/,$symb);
! 323:
! 324: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
! 325: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
! 326: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
! 327:
! 328:
! 329: my $currenthidden=$contrib{'hidden'};
! 330:
! 331: if ($ENV{'form.hide'}) {
! 332: $currenthidden.='.'.$idx.'.';
! 333: } else {
! 334: $currenthidden=~s/\.$idx\.//g;
! 335: }
! 336: my %newhash=('hidden' => $currenthidden);
! 337:
! 338: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
! 339: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
! 340: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
! 341:
! 342: &redirect_back($r,'/res/'.$url,'Changed discussion status<p>','0');
! 343:
! 344:
! 345: } else {
! 346: # ------------------------------------------------------------- Normal feedback
1.6 albertel 347: my $feedurl=$ENV{'form.postdata'};
348: $feedurl=~s/^http\:\/\///;
349: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
350: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.8 www 351:
352: my $symb=&Apache::lonnet::symbread($feedurl);
353: my $goahead=1;
354: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
355: unless ($symb) { $goahead=0; }
356: }
357:
358: if ($goahead) {
359: # Go ahead with feedback, no ambiguous reference
360: $r->content_type('text/html');
361: $r->send_http_header;
1.6 albertel 362:
1.8 www 363: if (
1.7 albertel 364: (
365: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
366: )
367: ||
368: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
369: ) {
1.6 albertel 370: # --------------------------------------------------- Print login screen header
371: unless ($ENV{'form.sendit'}) {
372: my $options=&screen_header($feedurl);
373: if ($options) {
374: &mail_screen($r,$feedurl,$options);
375: } else {
376: &fail_redirect($r,$feedurl);
377: }
378: } else {
379:
380: # Get previous user input
1.9 albertel 381: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11 albertel 382: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9 albertel 383: $ENV{'request.course.id'});
1.6 albertel 384:
385: # Get output from resource
386: my $usersaw=&resource_output($feedurl);
387:
388: # Filter HTML out of message (could be nasty)
389: my $message=&clear_out_html;
390:
391: # Assemble email
1.8 www 392: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
393: $usersaw);
1.6 albertel 394:
395: # Who gets this?
396: my ($typestyle,%to) = &decide_receiver($feedurl);
397:
398: # Actually send mail
399: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,%to);
1.13 www 400:
401: # Discussion? Store that.
402:
403: if ($ENV{'form.discuss'}) {
404: $typestyle.=&adddiscuss($symb,$message);
405: }
1.6 albertel 406:
1.14 www 407: if ($ENV{'form.anondiscuss'}) {
408: $typestyle.=&adddiscuss($symb,$message,1);
409: }
410:
411:
1.6 albertel 412: # Receipt screen and redirect back to where came from
1.8 www 413: &redirect_back($r,$feedurl,$typestyle,$numsent,$status);
1.6 albertel 414:
415: }
1.8 www 416: } else {
1.7 albertel 417: # Unable to give feedback
1.6 albertel 418: &no_redirect_back($r,$feedurl);
1.8 www 419: }
420: } else {
421: # Ambiguous Problem Resource
422: $r->internal_redirect('/adm/ambiguous');
1.6 albertel 423: }
1.15 ! www 424: }
1.6 albertel 425: return OK;
1.1 www 426: }
427:
428: 1;
429: __END__
1.14 www 430:
1.2 www 431:
432:
433:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>