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 (20 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

    1: # The LearningOnline Network
    2: # Pick a CODE from the list of possible CODEs
    3: #
    4: # $Id: lonpickcode.pm,v 1.4 2004/05/04 14:17:18 albertel Exp $
    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: 	push(@{$codes{$$scan_record{'scantron.CODE'}}},$$scan_record{'scantron.PaperID'});
   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: 
   76:     if  (!($ENV{'request.course.id'}) && 
   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>
   85: function gochoose(newcode) {
   86:     opener.document.$ENV{'form.form'}.scantron_CODE_selectedvalue.value=newcode;
   87:     var slct=opener.document.$ENV{'form.form'}.scantron_CODE_resolution;
   88:     var i;
   89:     for (i=0;i<slct.length;i++) {
   90:         if (slct[i].value=='use_found') { slct[i].checked=true; }
   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>');
  100:     my %codes=&Apache::grades::get_codes();
  101:     my %code_freq=&get_code_freq($r);
  102:     my $num_matches=length($ENV{'form.curCODE'});
  103:     for (my $i=$num_matches;$i>=0;$i--) {
  104: 	my $to_print="<p> CODEs with $i matches</p>";
  105: 	$to_print.='<table border="1"><tr><td></td><td>CODE</td><td>exams using this CODE</td>';
  106: 	my $print;
  107: 	foreach my $code (sort(keys(%codes))) {
  108: 	    if (&Apache::grades::num_matches($ENV{'form.curCODE'},$code) != $i) { next; }
  109: 	    $print=1;
  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: 	    }
  117: 	    $to_print.='<tr><td>'.
  118: 		      '<input type="button" value="'.&mt('Select').
  119: 		      '" onClick="gochoose(\''.$code.'\')" /></td>'.
  120: 		      '<td><tt>'.$code.'</tt></td><td>'.$count.
  121: 		      $list.'</td></tr>';
  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>