1: # The LearningOnline Network
2: # Evaluate
3: #
4: # $Id: lonevaluate.pm,v 1.26 2008/11/21 20:17:11 jms Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29:
30:
31: package Apache::lonevaluate;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::Constants qw(:common);
36: use Apache::loncommon();
37: use Apache::lonenc();
38: use Apache::lonlocal;
39: use LONCAPA();
40:
41: sub handler {
42: my $r = shift;
43: &Apache::loncommon::content_type($r,'text/html');
44: &Apache::loncommon::no_cache($r);
45:
46: $r->send_http_header;
47: return OK if $r->header_only;
48:
49: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
50: my $feedurl=$env{'form.postdata'};
51: $feedurl=~s/^http\:\/\///;
52: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
53: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
54:
55: $feedurl=&Apache::lonnet::declutter($feedurl);
56:
57: my $title=&Apache::lonnet::gettitle($feedurl);
58: my $showurl=&Apache::lonenc::check_encrypt($feedurl);
59:
60: my ($rdomain,$rauth)=($feedurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\//);
61:
62: my $prefix=$env{'user.name'}.'@'.$env{'user.domain'}.'___'.
63: $feedurl.'___';
64:
65: my @items=('correct','helpful','depth','clear','technical','comments',
66: 'timestamp');
67:
68: my @retrieve=map{ $prefix.$_ } @items;
69:
70: my %currenteval=
71: &Apache::lonnet::get('nohist_resevaldata',\@retrieve,$rdomain,$rauth);
72:
73: my $already=($currenteval{$prefix.'timestamp'} ne '');
74:
75: $env{'form.timestamp'}=time;
76:
77: my $warning='';
78:
79: if ($env{'form.submiteval'} eq 'true') {
80: # ------------------------------------------------ User is submitting something
81: my $complete=1;
82: foreach my $item (@items) {
83: if ($env{'form.'.$item}) {
84: $currenteval{$prefix.$item}=$env{'form.'.$item};
85: } elsif ($item ne 'comments') {
86: $complete=0;
87: }
88: }
89: if ($complete) {
90: my $showurl=&Apache::lonenc::check_encrypt(&Apache::lonnet::clutter($feedurl));
91: my $js =<<ENDJS;
92: <script type="text/javascript">
93: function goback() {
94: if ((window.name=='loncapaclient')) {
95: window.location='$showurl';
96: } else {
97: self.close();
98: }
99: }
100: </script>
101: ENDJS
102:
103: my $start_page =
104: &Apache::loncommon::start_page('Evaluate Resource',$js);
105: $r->print('
106: '.$start_page.'
107: <h1>'.&mt('Thank you for your input!').'</h1>
108: ');
109: $r->print(&mt('Saving feedback: [_1]',
110: &Apache::lonnet::put('nohist_resevaldata',\%currenteval,$rdomain,$rauth)));
111: unless ($already) {
112: $r->print('<br />'.&mt('Logging first evaluation'));
113: }
114: $r->print(
115: '<script type="text/javascript">setTimeout("goback()",2000);</script>'.&Apache::loncommon::end_page());
116: return OK;
117: } else {
118: $warning=&mt('Please fill out all fields below');
119: }
120:
121: }
122:
123: # ---------------------------------------------------------- Dial in old values
124: my $dialold='';
125: my $oldcomments='';
126:
127: foreach my $item (@items) {
128: unless ($item eq 'comments') {
129: unless (($item eq 'timestamp') ||
130: (!defined($currenteval{$prefix.$item}))) {
131: $dialold.=
132: 'document.evaluation.'.$item.'.selectedIndex='.
133: $currenteval{$prefix.$item}.";\n";
134: }
135: } else {
136: $oldcomments=$currenteval{$prefix.$item};
137: }
138: }
139: # ------------------------------------------------------- Print out eval screen
140: my %lt=&Apache::lonlocal::texthash('a' => 'Strongly Disagree',
141: 'b' => 'Disagree',
142: 'c' => 'Neutral',
143: 'd' => 'Agree',
144: 'e' => 'Strongly Agree',);
145: my $standardoptions='';
146: $standardoptions = (<<ENDOPTIONS);
147: <option value="0">-</option>
148: <option value="1">$lt{'a'}</option>
149: <option value="2">$lt{'b'}</option>
150: <option value="3">$lt{'c'}</option>
151: <option value="4">$lt{'d'}</option>
152: <option value="5">$lt{'e'}</option>
153: ENDOPTIONS
154:
155: my $start_page = &Apache::loncommon::start_page('Evaluate Resource');
156: my $end_page = &Apache::loncommon::end_page();
157:
158: %lt=&Apache::lonlocal::texthash(
159: 'pleaserank' => 'Please rank the following criteria:',
160: 'correct' => 'The material appears to be correct',
161: 'helpful' => 'The material is helpful',
162: 'depth' => 'The material is covered with sufficient depth',
163: 'clear' => 'The material is presented in a clear way',
164: 'technical' => 'The resource is technically correct (loads fast enough, does not produce errors, links work, etc)',
165: 'comments' => 'Any comments?',
166: 'submit' => 'Submit Evaluation',
167: );
168: $r->print(<<ENDDOCUMENT);
169: $start_page
170: <h2><tt>$title</tt></h2><br /><br />
171: <h3><font color="red">$warning</font></h3>
172: $lt{'pleaserank'}<br />
173: <form method="post" name="evaluation" action="/adm/evaluate">
174: <input type="hidden" name="submiteval" value="true" />
175: <input type="hidden" name="postdata" value="$showurl" />
176: <hr />
177: $lt{'correct'}
178: <br /><select name="correct">
179: $standardoptions
180: </select>
181: <hr />
182: $lt{'helpful'}
183: <br /><select name="helpful">
184: $standardoptions
185: </select>
186: <hr />
187: $lt{'depth'}
188: <br /><select name="depth">
189: $standardoptions
190: </select>
191: <hr />
192: $lt{'clear'}
193: <br /><select name="clear">
194: $standardoptions
195: </select>
196: <hr />
197: $lt{'technical'}
198: <br /><select name="technical">
199: $standardoptions
200: </select>
201: <hr />
202: $lt{'comments'}
203: <br /><textarea name="comments" cols="40" rows="5">$oldcomments</textarea>
204: <script type="text/javascript">$dialold</script>
205: <br /><input type="submit" value="$lt{'submit'}" />
206: </form>
207: $end_page
208: ENDDOCUMENT
209: return OK;
210: }
211:
212: 1;
213: __END__
214:
215: =pod
216:
217: =head1 NAME
218:
219: Apache::lonevaluate.pm
220:
221: =head1 SYNOPSIS
222:
223: Handles evaluation.
224:
225: This is part of the LearningOnline Network with CAPA project
226: described at http://www.lon-capa.org.
227:
228: =head1 OVERVIEW
229:
230: None
231:
232: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>