File:
[LON-CAPA] /
loncom /
interface /
lonpickcode.pm
Revision
1.4:
download - view:
text,
annotated -
select for diffs
Tue May 4 14:17:18 2004 UTC (21 years ago) by
albertel
Branches:
MAIN
CVS tags:
version_1_3_X,
version_1_3_3,
version_1_3_2,
version_1_3_1,
version_1_3_0,
version_1_2_X,
version_1_2_99_1,
version_1_2_99_0,
version_1_2_1,
version_1_2_0,
version_1_1_99_5,
version_1_1_99_4,
version_1_1_99_3,
version_1_1_99_2,
version_1_1_99_1,
version_1_1_99_0,
HEAD
- move more of pickcode in grades.pm where it probebly belongs
- print which papers use the paticular code
- add another set of options for handling the case of inccorect CODE,
find the set of closest matches and present them as possible choices
- make the validatepass passing actually work, so we don't redo all of
the finished passes each time we handle an error.
- in the case of duplicated CODEs when expecting announce the paper
that previously use the CODE
# The LearningOnline Network
# Pick a CODE from the list of possible CODEs
#
# $Id: lonpickcode.pm,v 1.4 2004/05/04 14:17:18 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
package Apache::lonpickcode;
use strict;
use Apache::Constants qw(:common);
use Apache::loncommon();
use Apache::grades();
use Apache::lonlocal;
sub get_code_freq {
my ($r)=@_;
my %codes;
my %scantron_config=
&Apache::grades::get_scantron_config($ENV{'form.scantron_format'});
$r->rflush();
my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
for (my $i=0;$i<=$scanlines->{'count'};$i++) {
my $line=&Apache::grades::scantron_get_line($scanlines,$i);
if ($line=~/^[\s\cz]*$/) { next; }
my $scan_record=
&Apache::grades::scantron_parse_scanline($line,$i,
\%scantron_config,
$scan_data,1);
push(@{$codes{$$scan_record{'scantron.CODE'}}},$$scan_record{'scantron.PaperID'});
}
return %codes;
}
sub handler {
my $r = shift;
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK if $r->header_only;
$r->print(<<ENDDOCUMENT);
<html>
<head>
<title>The LearningOnline Network with CAPA</title>
</head>
ENDDOCUMENT
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['curCODE','scantron_selectfile',
'form','scantron_format',
'scantron_CODElist']);
if (!($ENV{'request.course.id'}) &&
(&Apache::lonnet::allowed('usc',$ENV{'request.course.id'}))) {
$r->print('<body>Access not allowed.</body>');
return OK;
}
$r->print(&Apache::loncommon::bodytag("Selecting a CODE"));
$r->print(<<ENDSCRIPT);
<script>
function gochoose(newcode) {
opener.document.$ENV{'form.form'}.scantron_CODE_selectedvalue.value=newcode;
var slct=opener.document.$ENV{'form.form'}.scantron_CODE_resolution;
var i;
for (i=0;i<slct.length;i++) {
if (slct[i].value=='use_found') { slct[i].checked=true; }
}
self.close();
}
</script>
ENDSCRIPT
$r->print("<p>The CODE on the paper is <tt><b>".$ENV{'form.curCODE'}.
"</b></tt>. Please Select a new one.</p>\n".'<form>');
my %codes=&Apache::grades::get_codes();
my %code_freq=&get_code_freq($r);
my $num_matches=length($ENV{'form.curCODE'});
for (my $i=$num_matches;$i>=0;$i--) {
my $to_print="<p> CODEs with $i matches</p>";
$to_print.='<table border="1"><tr><td></td><td>CODE</td><td>exams using this CODE</td>';
my $print;
foreach my $code (sort(keys(%codes))) {
if (&Apache::grades::num_matches($ENV{'form.curCODE'},$code) != $i) { next; }
$print=1;
my ($count,$list);
if (!ref($code_freq{$code})) {
$count=0;
} else {
$count=scalar(@{$code_freq{$code}});
$list=' - '.join(', ',@{$code_freq{$code}});
}
$to_print.='<tr><td>'.
'<input type="button" value="'.&mt('Select').
'" onClick="gochoose(\''.$code.'\')" /></td>'.
'<td><tt>'.$code.'</tt></td><td>'.$count.
$list.'</td></tr>';
delete($codes{$code});
}
$to_print.='</table>';
if ($print) { $r->print($to_print); }
}
$r->print('</form></body></html>');
return OK;
}
1;
__END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>