--- loncom/interface/lonpickcode.pm 2004/04/22 22:57:53 1.1 +++ loncom/interface/lonpickcode.pm 2007/10/12 20:08:38 1.13 @@ -1,7 +1,7 @@ # The LearningOnline Network # Pick a CODE from the list of possible CODEs # -# $Id: lonpickcode.pm,v 1.1 2004/04/22 22:57:53 albertel Exp $ +# $Id: lonpickcode.pm,v 1.13 2007/10/12 20:08:38 banghart Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,83 +33,128 @@ 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, \%scantron_config, $scan_data,1); - $codes{$$scan_record{'scantron.CODE'}}++; + push(@{$codes{$$scan_record{'scantron.CODE'}}},$$scan_record{'scantron.PaperID'}); } return %codes; } -sub get_codes { - my $old_name=$ENV{'form.scantron_CODElist'}; - my $cdom =$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}; - my $cnum =$ENV{'course.'.$ENV{'request.course.id'}.'.num'}; - my %result=&Apache::lonnet::get('CODEs',[$old_name],$cdom,$cnum); - my %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name}); - return %allcodes; -} - -sub num_matches { - my ($code) = @_; - my $orig=$ENV{'form.curCODE'}; - my @code=split(//,$code); - my @orig=split(//,$orig); - my $same=0; - for (my $i=0;$isend_http_header; return OK if $r->header_only; - $r->print(< - - 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'}))) { - $r->print('Access not allowed.'); + if (!($env{'request.course.id'}) && + (&Apache::lonnet::allowed('usc',$env{'request.course.id'}))) { + $r->print(&Apache::loncommon::start_page(). + &mt('Access not allowed.'). + &Apache::loncommon::end_page()); return OK; } + if ($env{'form.command'} eq 'codelist') { + &code_list($r); + $r->print(&Apache::grades::show_grading_menu_form($env{'form.symb'}, + $env{'form.url'})); + } elsif ($env{'form.command'} eq 'showcodes') { + &show_codes($r); + } else { + &picking_a_code($r); + } + $r->print(&Apache::loncommon::end_page()); + return OK; +} - $r->print(&Apache::loncommon::bodytag("Selecting a CODE")); +sub code_list { + my ($r,$context)=@_; + # $context = 0 Print page header and enclosing table + # $context = 1 No page header, print enclosing table + # $context = 2 No page header, no enclosing table + my $table_head; + my $enc_table_start; + my $enc_table_close; + + if (!$context) { + $r->print(&Apache::loncommon::start_page("View CODEs",undef, + {'no_nav_bar' => 1})); + $table_head = (''.&mt('Select a set of saved CODEs to view.').""); + } elsif ($context eq 1) { + $table_head = (''.&mt('Select another set of saved CODEs to view.').""); + $enc_table_start = '
'; + $enc_table_close = '
'; + } elsif ($context eq 2) { + $table_head = (''.&mt('Select a set of saved CODEs to view.').""); + } + $r->print("
"); + $r->print($enc_table_start); + $r->print(''); + $r->print(''); + $r->print(''); + $r->print(""); + $r->print(""); + $r->print(""); + $r->print(''); + $r->print('
'); + $r->print($table_head); + $r->print('
'); + $r->print(&Apache::grades::scantron_CODElist()); + $r->print('
'); + $r->print(""); + $r->print('
'); + $r->print($enc_table_close); # conditional + $r->print("
"); + +} + +sub show_codes { + my ($r)=@_; + $r->print(&Apache::loncommon::start_page("View CODEs",undef, + {'no_nav_bar' => 1})); + 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); + $r->print(&Apache::grades::show_grading_menu_form($env{'form.symb'}, + $env{'form.url'})); +} + +sub picking_a_code { + my ($r)=@_; + $r->print(&Apache::loncommon::start_page("Selecting a CODE",undef, + {'no_nav_bar' => 1})); $r->print(< -function gochoose(uname,udom) { - opener.document.$ENV{'form.form'}.$ENV{'form.unameelement'}.value=uname; - var slct=opener.document.$ENV{'form.form'}.$ENV{'form.udomelement'}; +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;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=&get_codes(); + my %codes=&Apache::grades::get_codes(); my %code_freq=&get_code_freq($r); - my $num_matches=&num_matches($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 $to_print="

".&mt("CODEs with [_1] matching letters",$i)."

"; + $to_print.='
CODE# of exams using this CODE
'; my $print; foreach my $code (sort(keys(%codes))) { - if (&num_matches($code) != $i) { next; } + if (&Apache::grades::num_matches($env{'form.curCODE'},$code) != $i) { next; } $print=1; - my $count=$code_freq{$code}; - if (!$count) { $count=0; } + my ($count,$list); + if (!ref($code_freq{$code})) { + $count=0; + } else { + $count=scalar(@{$code_freq{$code}}); + $list=' - '.join(', ',@{$code_freq{$code}}); + } $to_print.=''. - ''; + ''; delete($codes{$code}); } $to_print.='
CODEexams using this CODE
'. ''.$code.' '.$count. - '
'.$code.''.$count. + $list.'
'; if ($print) { $r->print($to_print); } } - $r->print('
'); - return OK; + $r->print(''); } 1;