File:  [LON-CAPA] / loncom / interface / lonpickcode.pm
Revision 1.6: download - view: text, annotated - select for diffs
Thu Apr 7 06:56:23 2005 UTC (19 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: version_1_99_3, version_1_99_2, version_1_99_1_tmcc, version_1_99_1, version_1_99_0_tmcc, version_1_99_0, HEAD
- ENV -> env

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

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