--- loncom/interface/lonpickcode.pm 2004/05/04 14:17:18 1.4 +++ loncom/interface/lonpickcode.pm 2005/12/20 18:54:54 1.8 @@ -1,7 +1,7 @@ # 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 $ +# $Id: lonpickcode.pm,v 1.8 2005/12/20 18:54:54 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,16 +33,17 @@ use Apache::Constants qw(:common); use Apache::loncommon(); use Apache::grades(); use Apache::lonlocal; +use Apache::lonnet; sub get_code_freq { my ($r)=@_; my %codes; my %scantron_config= - &Apache::grades::get_scantron_config($ENV{'form.scantron_format'}); + &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); + my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i); if ($line=~/^[\s\cz]*$/) { next; } my $scan_record= &Apache::grades::scantron_parse_scanline($line,$i, @@ -59,32 +60,75 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK if $r->header_only; - + my $html=&Apache::lonxml::xmlbegin(); $r->print(< +$html The LearningOnline Network with CAPA ENDDOCUMENT - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['curCODE','scantron_selectfile', - 'form','scantron_format', - 'scantron_CODElist']); + 'form','scantron_format','symb', + 'scantron_CODElist','command']); - if (!($ENV{'request.course.id'}) && - (&Apache::lonnet::allowed('usc',$ENV{'request.course.id'}))) { + if (!($env{'request.course.id'}) && + (&Apache::lonnet::allowed('usc',$env{'request.course.id'}))) { $r->print('Access not allowed.'); return OK; } + if ($env{'form.command'} eq 'codelist') { + &code_list($r); + } elsif ($env{'form.command'} eq 'showcodes') { + &show_codes($r); + } else { + &picking_a_code($r); + } + $r->print(''); + return OK; +} + +sub code_list { + my ($r,$secondview)=@_; + if (!$secondview) { + $r->print(&Apache::loncommon::bodytag("View CODEs")); + $r->print("

".&mt('Select a set of saved CODEs to view.')."

"); + } else { + $r->print("

".&mt('Select another set of saved CODEs to view.')."

"); + } + $r->print("
"); + $r->print(&Apache::grades::scantron_CODElist()); + $r->print(""); + $r->print(""); + $r->print(""); + $r->print(""); + $r->print("
"); + $r->print(&Apache::grades::show_grading_menu_form($env{'form.symb'}, + $env{'form.url'})); +} +sub show_codes { + my ($r)=@_; + $r->print(&Apache::loncommon::bodytag("View CODEs")); + my %codes=&Apache::grades::get_codes(); + $r->print("

".$env{'form.scantron_CODElist'}."

"); + $r->print('
');
+    foreach my $code (sort(keys(%codes))) {
+	$r->print($code."\n");
+    }
+    $r->print('
'); + &code_list($r,1); +} + +sub picking_a_code { + my ($r)=@_; $r->print(&Apache::loncommon::bodytag("Selecting a CODE")); $r->print(< function gochoose(newcode) { - opener.document.$ENV{'form.form'}.scantron_CODE_selectedvalue.value=newcode; - var slct=opener.document.$ENV{'form.form'}.scantron_CODE_resolution; + 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;iprint("

The CODE on the paper is ".$ENV{'form.curCODE'}. + $r->print("

The CODE on the paper is ".$env{'form.curCODE'}. ". Please Select a new one.

\n".'
'); my %codes=&Apache::grades::get_codes(); my %code_freq=&get_code_freq($r); - my $num_matches=length($ENV{'form.curCODE'}); + my $num_matches=length($env{'form.curCODE'}); for (my $i=$num_matches;$i>=0;$i--) { my $to_print="

CODEs with $i matches

"; $to_print.=''; my $print; foreach my $code (sort(keys(%codes))) { - if (&Apache::grades::num_matches($ENV{'form.curCODE'},$code) != $i) { next; } + if (&Apache::grades::num_matches($env{'form.curCODE'},$code) != $i) { next; } $print=1; my ($count,$list); if (!ref($code_freq{$code})) { @@ -124,8 +168,7 @@ ENDSCRIPT $to_print.='
CODEexams using this CODE
'; if ($print) { $r->print($to_print); } } - $r->print('
'); - return OK; + $r->print(''); } 1;