Annotation of loncom/interface/lonfeedback.pm, revision 1.4
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.3 www 12: # 3/1,2/3,2/5,2/6 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:
31: if (($feedurl=~/^\/res/) || ($ENV{'request.course.id'})) {
1.1 www 32: # --------------------------------------------------- Print login screen header
1.2 www 33: unless ($ENV{'form.sendit'}) {
34: my $options='';
35: if ($feedurl=~/^\/res/) {
36: $options=
37: '<p><input type=checkbox name=author> Feedback to resource author';
38: }
39: if ($ENV{'course.'.$ENV{'request.course.id'}.'.question.email'}) {
40: $options.=
41: '<br><input type=checkbox name=question> Question about resource content';
42: }
43: if ($ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'}) {
44: $options.=
1.3 www 45: '<br><input type=checkbox name=comment> '.
1.2 www 46: 'Question/Comment/Feedback about course content';
47: }
48: if ($ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'}) {
49: $options.=
1.3 www 50: '<br><input type=checkbox name=policy> '.
1.2 www 51: 'Question/Comment/Feedback about course policy';
52: }
53: $r->print(<<ENDDOCUMENT);
1.1 www 54: <html>
55: <head>
56: <title>The LearningOnline Network with CAPA</title>
57: </head>
58: <body bgcolor="#FFFFFF">
1.2 www 59: <img align=right src=/adm/lonIcons/lonlogos.gif>
1.1 www 60: <h1>Feedback</h1>
1.2 www 61: <h2><tt>$feedurl</tt></h2>
62: <form action="/adm/feedback" method=post>
63: <input type=hidden name=postdata value="$feedurl">
64: Please check at least one of the following:
65: $options<hr>
66: My question/comment/feedback:<p>
67: <textarea name=comment cols=60 rows=10>
68: </textarea><p>
69: <input type=submit name=sendit value="Send Feedback"></input>
70: </form>
1.1 www 71: </body>
72: </html>
73: ENDDOCUMENT
1.2 www 74: } else {
1.3 www 75: #
76: # Get previous user input
77: #
1.2 www 78: my $symb=&Apache::lonnet::symbread($feedurl);
79: my $prevattempts='';
80: if ($symb) {
81: my $answer=&Apache::lonnet::reply(
82: "restore:".$ENV{'user.domain'}.':'.$ENV{'user.name'}.':'.
83: $ENV{'request.course.id'}.':'.
84: &Apache::lonnet::escape($symb),
85: $ENV{'user.home'});
86: my %returnhash=();
87: map {
88: my ($name,$value)=split(/\=/,$_);
89: $returnhash{&Apache::lonnet::unescape($name)}=
90: &Apache::lonnet::unescape($value);
91: } split(/\&/,$answer);
92: my %lasthash=();
93: my $version;
94: for ($version=1;$version<=$returnhash{'version'};$version++) {
95: map {
96: $lasthash{$_}=$returnhash{$version.':'.$_};
97: } split(/\:/,$returnhash{$version.':keys'});
98: }
99: $prevattempts='<table border=2></tr><th>History</th>';
100: map {
101: $prevattempts.='<th>'.$_.'</th>';
102: } keys %lasthash;
103: for ($version=1;$version<=$returnhash{'version'};$version++) {
104: $prevattempts.='</tr><tr><th>Attempt '.$version.'</th>';
105: map {
106: $prevattempts.='<td>'.$returnhash{$version.':'.$_}.'</td>';
107: } keys %lasthash;
108: }
109: $prevattempts.='</tr><tr><th>Current</th>';
110: map {
111: $prevattempts.='<td>'.$lasthash{$_}.'</td>';
112: } keys %lasthash;
113: $prevattempts.='</tr></table>';
114: }
1.3 www 115: #
116: # Get output from resource
117: #
1.2 www 118: my $usersaw=&Apache::lonnet::ssi($feedurl);
119: $usersaw=~s/\<body[^\>]*\>//gi;
120: $usersaw=~s/\<\/body\>//gi;
121: $usersaw=~s/\<html\>//gi;
122: $usersaw=~s/\<\/html\>//gi;
123: $usersaw=~s/\<head\>//gi;
124: $usersaw=~s/\<\/head\>//gi;
125: $usersaw=~s/action\s*\=/would_be_action\=/gi;
1.3 www 126: #
127: # Filter HTML out of message (could be nasty)
128: #
129: my $message=$ENV{'form.comment'};
130: $message=~s/\</\<\;/g;
131: $message=~s/\>/\>\;/g;
132:
133: #
134: # Assemble email
135: #
136: my $email=<<"ENDEMAIL";
137: Refers to <a href="$feedurl">$feedurl</a>
1.4 ! www 138:
1.3 www 139: $message
1.4 ! www 140: ENDEMAIL
! 141: my $citations=<<"ENDCITE";
1.3 www 142: <h2>Previous attempts of student (if applicable)</h2>
143: $prevattempts
144: <p><hr>
145: <h2>Original screen output (if applicable)</h2>
146: $usersaw
1.4 ! www 147: ENDCITE
1.3 www 148: #
149: # Who gets this?
150: #
151: my %to=();
152: if ($ENV{'form.author'}) {
153: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
154: $to{$2.':'.$1}=1;
155: }
156: if ($ENV{'form.question'}) {
157: map {
158: $to{$_}=1;
159: } split(/\,/,
160: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'});
161: }
162: if ($ENV{'form.comment'}) {
163: map {
164: $to{$_}=1;
165: } split(/\,/,
166: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'});
167: }
168: if ($ENV{'form.policy'}) {
169: map {
170: $to{$_}=1;
171: } split(/\,/,
172: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'});
173: }
174: #
175: # Actually send mail
176: #
177: my $status='';
178: map {
179: if ($_) {
180: unless (
181: &Apache::lonmsg::user_normal_msg(split(/\:/,$_),'Feedback '.$feedurl,
1.4 ! www 182: $email,$citations) eq 'ok') {
1.3 www 183: $status.='<br>Error sending message to '.$_.'<br>';
184: }
185: }
186: } keys %to;
187: #
188: # Receipt screen and redirect back to where came from
189: #
1.2 www 190: print (<<ENDREDIR);
1.3 www 191: <head>
192: <title>Feedback sent</title>
193: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$feedurl">
1.2 www 194: </head>
195: <html>
196: <body bgcolor="#FFFFFF">
197: <b>Feedback sent ...</b>
1.3 www 198: <font color=red>$status</font>
1.2 www 199: </body>
200: </html>
201: ENDREDIR
202: }
203: } else {
204: print (<<ENDNOREDIR);
205: <head><title>Feedback not sent</title>
206: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$feedurl">
207: </head>
208: <html>
209: <body bgcolor="#FFFFFF">
210: Sorry, no feedback possible on this resource ...
211: </body>
212: </html>
213: ENDNOREDIR
214: }
1.1 www 215: return OK;
216: }
217:
218: 1;
219: __END__
1.2 www 220:
221:
222:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>