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