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