Annotation of loncom/interface/lonfeedback.pm, revision 1.18
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.18 ! www 18: # 7/26,8/10,10/1,11/5,11/6 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>
1.16 www 86: <textarea name=comment cols=60 rows=10 wrap=hard>
1.2 www 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: $sendsomething++;
267: }
268: }
1.18 ! www 269: } keys %to;
! 270:
! 271: my %record=&Apache::lonnet::restore('_feedback');
! 272: my ($temp)=keys %record;
! 273: unless ($temp=~/^error\:/) {
! 274: my %newrecord=();
! 275: $newrecord{'resource'}=$feedurl;
! 276: $newrecord{'subnumber'}=$record{'subnumber'}+1;
! 277: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
! 278: $status.='<br>Not registered<br>';
! 279: }
! 280: }
! 281:
1.6 albertel 282: return ($status,$sendsomething);
283: }
284:
1.13 www 285: sub adddiscuss {
1.14 www 286: my ($symb,$email,$anon)=@_;
1.13 www 287: my $status='';
288: my %contrib=('message' => $email,
289: 'sendername' => $ENV{'user.name'},
290: 'senderdomain' => $ENV{'user.domain'});
1.14 www 291: if ($anon) {
292: $contrib{'anonymous'}='true';
293: }
1.13 www 294: if (($symb) && ($email)) {
1.14 www 295: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1.13 www 296: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
297: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17 www 298: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13 www 299: }
1.17 www 300: my %record=&Apache::lonnet::restore('_discussion');
301: my ($temp)=keys %record;
302: unless ($temp=~/^error\:/) {
303: my %newrecord=();
304: $newrecord{'resource'}=$symb;
305: $newrecord{'subnumber'}=$record{'subnumber'}+1;
306: $status.=' '.&Apache::lonnet::cstore(\%newrecord,'_discussion');
307: }
308: return $status.'<br>';
1.13 www 309: }
310:
1.6 albertel 311: sub handler {
312: my $r = shift;
1.8 www 313: if ($r->header_only) {
314: $r->content_type('text/html');
315: $r->send_http_header;
316: return OK;
317: }
1.15 www 318:
319: # --------------------------- Get query string for limited number of parameters
320:
321: map {
322: my ($name, $value) = split(/=/,$_);
323: $value =~ tr/+/ /;
324: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
325: if (($name eq 'hide') || ($name eq 'unhide')) {
326: unless ($ENV{'form.'.$name}) {
327: $ENV{'form.'.$name}=$value;
328: }
329: }
330: } (split(/&/,$ENV{'QUERY_STRING'}));
331:
332: if (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
333: # ----------------------------------------------------------------- Hide/unhide
334: $r->content_type('text/html');
335: $r->send_http_header;
336:
337: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
338:
339: my ($symb,$idx)=split(/\:\:\:/,$entry);
340: my ($map,$ind,$url)=split(/\_\_\_/,$symb);
341:
342: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
343: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
344: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
345:
346:
347: my $currenthidden=$contrib{'hidden'};
348:
349: if ($ENV{'form.hide'}) {
350: $currenthidden.='.'.$idx.'.';
351: } else {
352: $currenthidden=~s/\.$idx\.//g;
353: }
354: my %newhash=('hidden' => $currenthidden);
355:
356: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
357: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
358: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
359:
360: &redirect_back($r,'/res/'.$url,'Changed discussion status<p>','0');
361:
362:
363: } else {
364: # ------------------------------------------------------------- Normal feedback
1.6 albertel 365: my $feedurl=$ENV{'form.postdata'};
366: $feedurl=~s/^http\:\/\///;
367: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
368: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.8 www 369:
370: my $symb=&Apache::lonnet::symbread($feedurl);
371: my $goahead=1;
372: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
373: unless ($symb) { $goahead=0; }
374: }
375:
376: if ($goahead) {
377: # Go ahead with feedback, no ambiguous reference
378: $r->content_type('text/html');
379: $r->send_http_header;
1.6 albertel 380:
1.8 www 381: if (
1.7 albertel 382: (
383: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
384: )
385: ||
386: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
387: ) {
1.6 albertel 388: # --------------------------------------------------- Print login screen header
389: unless ($ENV{'form.sendit'}) {
390: my $options=&screen_header($feedurl);
391: if ($options) {
392: &mail_screen($r,$feedurl,$options);
393: } else {
394: &fail_redirect($r,$feedurl);
395: }
396: } else {
397:
398: # Get previous user input
1.9 albertel 399: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11 albertel 400: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9 albertel 401: $ENV{'request.course.id'});
1.6 albertel 402:
403: # Get output from resource
404: my $usersaw=&resource_output($feedurl);
405:
406: # Filter HTML out of message (could be nasty)
407: my $message=&clear_out_html;
408:
409: # Assemble email
1.8 www 410: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
411: $usersaw);
1.6 albertel 412:
413: # Who gets this?
414: my ($typestyle,%to) = &decide_receiver($feedurl);
415:
416: # Actually send mail
417: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,%to);
1.13 www 418:
419: # Discussion? Store that.
420:
421: if ($ENV{'form.discuss'}) {
422: $typestyle.=&adddiscuss($symb,$message);
423: }
1.6 albertel 424:
1.14 www 425: if ($ENV{'form.anondiscuss'}) {
426: $typestyle.=&adddiscuss($symb,$message,1);
427: }
428:
429:
1.6 albertel 430: # Receipt screen and redirect back to where came from
1.8 www 431: &redirect_back($r,$feedurl,$typestyle,$numsent,$status);
1.6 albertel 432:
433: }
1.8 www 434: } else {
1.7 albertel 435: # Unable to give feedback
1.6 albertel 436: &no_redirect_back($r,$feedurl);
1.8 www 437: }
438: } else {
439: # Ambiguous Problem Resource
440: $r->internal_redirect('/adm/ambiguous');
1.6 albertel 441: }
1.15 www 442: }
1.6 albertel 443: return OK;
1.1 www 444: }
445:
446: 1;
447: __END__
1.14 www 448:
1.2 www 449:
450:
451:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>