Annotation of loncom/interface/lonpickcode.pm, revision 1.3
1.1 albertel 1: # The LearningOnline Network
2: # Pick a CODE from the list of possible CODEs
3: #
1.3 ! albertel 4: # $Id: lonpickcode.pm,v 1.2 2004/04/24 08:31:57 albertel Exp $
1.1 albertel 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::lonpickcode;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::loncommon();
34: use Apache::grades();
35: use Apache::lonlocal;
36:
37: sub get_code_freq {
38: my ($r)=@_;
39: my %codes;
40: my %scantron_config=
41: &Apache::grades::get_scantron_config($ENV{'form.scantron_format'});
42: $r->rflush();
43: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
44: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
45: my $line=&Apache::grades::scantron_get_line($scanlines,$i);
46: if ($line=~/^[\s\cz]*$/) { next; }
47: my $scan_record=
48: &Apache::grades::scantron_parse_scanline($line,$i,
49: \%scantron_config,
50: $scan_data,1);
51: $codes{$$scan_record{'scantron.CODE'}}++;
52:
53: }
54: return %codes;
55: }
56:
57: sub get_codes {
58: my $old_name=$ENV{'form.scantron_CODElist'};
59: my $cdom =$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
60: my $cnum =$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
61: my %result=&Apache::lonnet::get('CODEs',[$old_name],$cdom,$cnum);
62: my %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
63: return %allcodes;
64: }
65:
66: sub num_matches {
67: my ($code) = @_;
68: my $orig=$ENV{'form.curCODE'};
69: my @code=split(//,$code);
70: my @orig=split(//,$orig);
71: my $same=0;
72: for (my $i=0;$i<scalar(@code);$i++) {
73: if ($code[$i] eq $orig[$i]) { $same++; }
74: }
75: return $same;
76: }
77:
78: sub handler {
79: my $r = shift;
80: &Apache::loncommon::content_type($r,'text/html');
81: $r->send_http_header;
82: return OK if $r->header_only;
83:
84: $r->print(<<ENDDOCUMENT);
85: <html>
86: <head>
87: <title>The LearningOnline Network with CAPA</title>
88: </head>
89: ENDDOCUMENT
90:
91:
92: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
93: ['curCODE','scantron_selectfile',
94: 'form','scantron_format',
95: 'scantron_CODElist']);
96:
1.2 albertel 97: if (!($ENV{'request.course.id'}) &&
1.1 albertel 98: (&Apache::lonnet::allowed('usc',$ENV{'request.course.id'}))) {
99: $r->print('<body>Access not allowed.</body>');
100: return OK;
101: }
102:
103: $r->print(&Apache::loncommon::bodytag("Selecting a CODE"));
104: $r->print(<<ENDSCRIPT);
105: <script>
1.2 albertel 106: function gochoose(newcode) {
1.3 ! albertel 107: opener.document.$ENV{'form.form'}.scantron_CODE_selectedvalue.value=newcode;
! 108: var slct=opener.document.$ENV{'form.form'}.scantron_CODE_resolution;
1.1 albertel 109: var i;
110: for (i=0;i<slct.length;i++) {
1.2 albertel 111: if (slct[i].value=='use_found') { slct[i].checked=true; }
1.1 albertel 112: }
113: self.close();
114: }
115: </script>
116: ENDSCRIPT
117:
118:
119: $r->print("<p>The CODE on the paper is <tt><b>".$ENV{'form.curCODE'}.
120: "</b></tt>. Please Select a new one.</p>\n".'<form>');
121: my %codes=&get_codes();
122: my %code_freq=&get_code_freq($r);
123: my $num_matches=&num_matches($ENV{'form.curCODE'});
124: for (my $i=$num_matches;$i>=0;$i--) {
125: my $to_print="<p> CODEs with $i matches</p>";
126: $to_print.='<table border="1"><tr><td></td><td>CODE</td><td># of exams using this CODE</td>';
127: my $print;
128: foreach my $code (sort(keys(%codes))) {
129: if (&num_matches($code) != $i) { next; }
130: $print=1;
131: my $count=$code_freq{$code};
132: if (!$count) { $count=0; }
133: $to_print.='<tr><td>'.
134: '<input type="button" value="'.&mt('Select').
135: '" onClick="gochoose(\''.$code.'\')" /></td>'.
136: '<td><tt>'.$code.'</tt></td><td> <tt>'.$count.
137: '</tt></td></tr>';
138: delete($codes{$code});
139: }
140: $to_print.='</table>';
141: if ($print) { $r->print($to_print); }
142: }
143: $r->print('</form></body></html>');
144: return OK;
145: }
146:
147: 1;
148: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>