Annotation of loncom/interface/lonpickcode.pm, revision 1.4

1.1       albertel    1: # The LearningOnline Network
                      2: # Pick a CODE from the list of possible CODEs
                      3: #
1.4     ! albertel    4: # $Id: lonpickcode.pm,v 1.3 2004/04/24 09:01:52 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);
1.4     ! albertel   51: 	push(@{$codes{$$scan_record{'scantron.CODE'}}},$$scan_record{'scantron.PaperID'});
1.1       albertel   52: 
                     53:     }
                     54:     return %codes;
                     55: }
                     56: 
                     57: sub handler {
                     58:     my $r = shift;
                     59:     &Apache::loncommon::content_type($r,'text/html');
                     60:     $r->send_http_header;
                     61:     return OK if $r->header_only;
                     62: 
                     63:     $r->print(<<ENDDOCUMENT);
                     64: <html>
                     65:   <head>
                     66:     <title>The LearningOnline Network with CAPA</title>
                     67:   </head>
                     68: ENDDOCUMENT
                     69: 
                     70: 
                     71:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     72: 					    ['curCODE','scantron_selectfile',
                     73: 					     'form','scantron_format',
                     74: 					     'scantron_CODElist']);
                     75: 
1.2       albertel   76:     if  (!($ENV{'request.course.id'}) && 
1.1       albertel   77: 	 (&Apache::lonnet::allowed('usc',$ENV{'request.course.id'}))) {
                     78: 	$r->print('<body>Access not allowed.</body>');
                     79:         return OK;
                     80:     }
                     81: 
                     82:     $r->print(&Apache::loncommon::bodytag("Selecting a CODE"));
                     83:     $r->print(<<ENDSCRIPT);
                     84: <script>
1.2       albertel   85: function gochoose(newcode) {
1.3       albertel   86:     opener.document.$ENV{'form.form'}.scantron_CODE_selectedvalue.value=newcode;
                     87:     var slct=opener.document.$ENV{'form.form'}.scantron_CODE_resolution;
1.1       albertel   88:     var i;
                     89:     for (i=0;i<slct.length;i++) {
1.2       albertel   90:         if (slct[i].value=='use_found') { slct[i].checked=true; }
1.1       albertel   91:     }
                     92:     self.close();
                     93: }
                     94: </script>
                     95: ENDSCRIPT
                     96: 
                     97: 
                     98:     $r->print("<p>The CODE on the paper is <tt><b>".$ENV{'form.curCODE'}.
                     99: 	      "</b></tt>. Please Select a new one.</p>\n".'<form>');
1.4     ! albertel  100:     my %codes=&Apache::grades::get_codes();
1.1       albertel  101:     my %code_freq=&get_code_freq($r);
1.4     ! albertel  102:     my $num_matches=length($ENV{'form.curCODE'});
1.1       albertel  103:     for (my $i=$num_matches;$i>=0;$i--) {
                    104: 	my $to_print="<p> CODEs with $i matches</p>";
1.4     ! albertel  105: 	$to_print.='<table border="1"><tr><td></td><td>CODE</td><td>exams using this CODE</td>';
1.1       albertel  106: 	my $print;
                    107: 	foreach my $code (sort(keys(%codes))) {
1.4     ! albertel  108: 	    if (&Apache::grades::num_matches($ENV{'form.curCODE'},$code) != $i) { next; }
1.1       albertel  109: 	    $print=1;
1.4     ! albertel  110: 	    my ($count,$list);
        !           111: 	    if (!ref($code_freq{$code})) {
        !           112: 		$count=0;
        !           113: 	    } else {
        !           114: 		$count=scalar(@{$code_freq{$code}});
        !           115: 		$list=' - '.join(', ',@{$code_freq{$code}});
        !           116: 	    }
1.1       albertel  117: 	    $to_print.='<tr><td>'.
                    118: 		      '<input type="button" value="'.&mt('Select').
                    119: 		      '" onClick="gochoose(\''.$code.'\')" /></td>'.
1.4     ! albertel  120: 		      '<td><tt>'.$code.'</tt></td><td>'.$count.
        !           121: 		      $list.'</td></tr>';
1.1       albertel  122: 	    delete($codes{$code});
                    123: 	}
                    124: 	$to_print.='</table>';
                    125: 	if ($print) { $r->print($to_print); }
                    126:     }
                    127:     $r->print('</form></body></html>');
                    128:     return OK;
                    129: } 
                    130: 
                    131: 1;
                    132: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>