Annotation of loncom/interface/lonfeedback.pm, revision 1.5
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.1 www 13: #
14: package Apache::lonfeedback;
15:
16: use strict;
17: use Apache::Constants qw(:common);
1.3 www 18: use Apache::lonmsg();
1.1 www 19:
20: sub handler {
21: my $r = shift;
22: $r->content_type('text/html');
23: $r->send_http_header;
24: return OK if $r->header_only;
25:
1.2 www 26: my $feedurl=$ENV{'form.postdata'};
27: $feedurl=~s/^http\:\/\///;
28: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
29: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
30:
1.5 ! www 31: if ((($feedurl=~/^\/res/) && ($feedurl!~/^\/res\/adm/))
! 32: || ($ENV{'request.course.id'})) {
1.1 www 33: # --------------------------------------------------- Print login screen header
1.2 www 34: unless ($ENV{'form.sendit'}) {
35: my $options='';
1.5 ! www 36: if (($feedurl=~/^\/res/) && ($feedurl!~/^\/res\/adm/)) {
1.2 www 37: $options=
38: '<p><input type=checkbox name=author> Feedback to resource author';
39: }
40: if ($ENV{'course.'.$ENV{'request.course.id'}.'.question.email'}) {
41: $options.=
42: '<br><input type=checkbox name=question> Question about resource content';
43: }
44: if ($ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'}) {
45: $options.=
1.5 ! www 46: '<br><input type=checkbox name=course> '.
1.2 www 47: 'Question/Comment/Feedback about course content';
48: }
49: if ($ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'}) {
50: $options.=
1.3 www 51: '<br><input type=checkbox name=policy> '.
1.2 www 52: 'Question/Comment/Feedback about course policy';
53: }
1.5 ! www 54: if ($options) {
1.2 www 55: $r->print(<<ENDDOCUMENT);
1.1 www 56: <html>
57: <head>
58: <title>The LearningOnline Network with CAPA</title>
1.5 ! www 59: <script>
! 60: function gosubmit() {
! 61: var rec=0;
! 62: if (document.mailform.elements.author!=undefined) {
! 63: if (document.mailform.elements.author.checked) {
! 64: rec=1;
! 65: }
! 66: }
! 67: if (document.mailform.elements.question!=undefined) {
! 68: if (document.mailform.elements.question.checked) {
! 69: rec=1;
! 70: }
! 71: }
! 72: if (document.mailform.elements.course!=undefined) {
! 73: if (document.mailform.elements.course.checked) {
! 74: rec=1;
! 75: }
! 76: }
! 77: if (document.mailform.elements.policy!=undefined) {
! 78: if (document.mailform.elements.policy.checked) {
! 79: rec=1;
! 80: }
! 81: }
! 82:
! 83: if (rec) {
! 84: document.mailform.submit();
! 85: } else {
! 86: alert('Please check a feedback type.');
! 87: }
! 88: }
! 89: </script>
1.1 www 90: </head>
1.5 ! www 91: <body bgcolor="#FFFFFF" onLoad="window.focus();">
1.2 www 92: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.1 www 93: <h1>Feedback</h1>
1.2 www 94: <h2><tt>$feedurl</tt></h2>
1.5 ! www 95: <form action="/adm/feedback" method=post name=mailform>
1.2 www 96: <input type=hidden name=postdata value="$feedurl">
1.5 ! www 97: Please check at least one of the following feedback types:
1.2 www 98: $options<hr>
99: My question/comment/feedback:<p>
100: <textarea name=comment cols=60 rows=10>
101: </textarea><p>
1.5 ! www 102: <input type=hidden name=sendit value=1>
! 103: <input type=button value="Send Feedback" onClick='gosubmit();'></input>
1.2 www 104: </form>
1.1 www 105: </body>
106: </html>
107: ENDDOCUMENT
1.2 www 108: } else {
1.5 ! www 109: print (<<ENDFAILREDIR);
! 110: <head><title>Feedback not sent</title>
! 111: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
! 112: </head>
! 113: <html>
! 114: <body bgcolor="#FFFFFF">
! 115: Sorry, no recipients ...
! 116: </body>
! 117: </html>
! 118: ENDFAILREDIR
! 119:
! 120: }
! 121: } else {
1.3 www 122: #
123: # Get previous user input
124: #
1.2 www 125: my $symb=&Apache::lonnet::symbread($feedurl);
126: my $prevattempts='';
127: if ($symb) {
128: my $answer=&Apache::lonnet::reply(
129: "restore:".$ENV{'user.domain'}.':'.$ENV{'user.name'}.':'.
130: $ENV{'request.course.id'}.':'.
131: &Apache::lonnet::escape($symb),
132: $ENV{'user.home'});
133: my %returnhash=();
134: map {
135: my ($name,$value)=split(/\=/,$_);
136: $returnhash{&Apache::lonnet::unescape($name)}=
137: &Apache::lonnet::unescape($value);
138: } split(/\&/,$answer);
139: my %lasthash=();
140: my $version;
141: for ($version=1;$version<=$returnhash{'version'};$version++) {
142: map {
143: $lasthash{$_}=$returnhash{$version.':'.$_};
144: } split(/\:/,$returnhash{$version.':keys'});
145: }
146: $prevattempts='<table border=2></tr><th>History</th>';
147: map {
148: $prevattempts.='<th>'.$_.'</th>';
149: } keys %lasthash;
150: for ($version=1;$version<=$returnhash{'version'};$version++) {
151: $prevattempts.='</tr><tr><th>Attempt '.$version.'</th>';
152: map {
153: $prevattempts.='<td>'.$returnhash{$version.':'.$_}.'</td>';
154: } keys %lasthash;
155: }
156: $prevattempts.='</tr><tr><th>Current</th>';
157: map {
158: $prevattempts.='<td>'.$lasthash{$_}.'</td>';
159: } keys %lasthash;
160: $prevattempts.='</tr></table>';
161: }
1.3 www 162: #
163: # Get output from resource
164: #
1.2 www 165: my $usersaw=&Apache::lonnet::ssi($feedurl);
166: $usersaw=~s/\<body[^\>]*\>//gi;
167: $usersaw=~s/\<\/body\>//gi;
168: $usersaw=~s/\<html\>//gi;
169: $usersaw=~s/\<\/html\>//gi;
170: $usersaw=~s/\<head\>//gi;
171: $usersaw=~s/\<\/head\>//gi;
172: $usersaw=~s/action\s*\=/would_be_action\=/gi;
1.3 www 173: #
174: # Filter HTML out of message (could be nasty)
175: #
176: my $message=$ENV{'form.comment'};
177: $message=~s/\</\<\;/g;
178: $message=~s/\>/\>\;/g;
179:
180: #
181: # Assemble email
182: #
183: my $email=<<"ENDEMAIL";
184: Refers to <a href="$feedurl">$feedurl</a>
1.4 www 185:
1.3 www 186: $message
1.4 www 187: ENDEMAIL
188: my $citations=<<"ENDCITE";
1.3 www 189: <h2>Previous attempts of student (if applicable)</h2>
190: $prevattempts
191: <p><hr>
192: <h2>Original screen output (if applicable)</h2>
193: $usersaw
1.4 www 194: ENDCITE
1.3 www 195: #
196: # Who gets this?
197: #
1.5 ! www 198: my $typestyle='';
1.3 www 199: my %to=();
200: if ($ENV{'form.author'}) {
1.5 ! www 201: $typestyle.='Author Feedback<br>';
1.3 www 202: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
203: $to{$2.':'.$1}=1;
204: }
205: if ($ENV{'form.question'}) {
1.5 ! www 206: $typestyle.='Question<br>';
1.3 www 207: map {
208: $to{$_}=1;
209: } split(/\,/,
210: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'});
211: }
1.5 ! www 212: if ($ENV{'form.course'}) {
! 213: $typestyle.='Comment<br>';
1.3 www 214: map {
215: $to{$_}=1;
216: } split(/\,/,
217: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'});
218: }
219: if ($ENV{'form.policy'}) {
1.5 ! www 220: $typestyle.='Policy<br>';
1.3 www 221: map {
222: $to{$_}=1;
223: } split(/\,/,
224: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'});
225: }
226: #
227: # Actually send mail
228: #
229: my $status='';
1.5 ! www 230: my $sendsomething=0;
1.3 www 231: map {
232: if ($_) {
233: unless (
234: &Apache::lonmsg::user_normal_msg(split(/\:/,$_),'Feedback '.$feedurl,
1.4 www 235: $email,$citations) eq 'ok') {
1.3 www 236: $status.='<br>Error sending message to '.$_.'<br>';
1.5 ! www 237: } else {
! 238: $sendsomething++;
! 239: }
1.3 www 240: }
1.5 ! www 241: } keys %to;
1.3 www 242: #
243: # Receipt screen and redirect back to where came from
244: #
1.2 www 245: print (<<ENDREDIR);
1.3 www 246: <head>
247: <title>Feedback sent</title>
1.5 ! www 248: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
1.2 www 249: </head>
250: <html>
251: <body bgcolor="#FFFFFF">
1.5 ! www 252: $typestyle
! 253: <b>Sent $sendsomething message(s).</b>
1.3 www 254: <font color=red>$status</font>
1.2 www 255: </body>
256: </html>
257: ENDREDIR
258: }
259: } else {
260: print (<<ENDNOREDIR);
261: <head><title>Feedback not sent</title>
1.5 ! www 262: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl">
1.2 www 263: </head>
264: <html>
265: <body bgcolor="#FFFFFF">
266: Sorry, no feedback possible on this resource ...
267: </body>
268: </html>
269: ENDNOREDIR
270: }
1.1 www 271: return OK;
272: }
273:
274: 1;
275: __END__
1.2 www 276:
277:
278:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>