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

1.1       albertel    1: # The LearningOnline Network
                      2: # Pick a CODE from the list of possible CODEs
                      3: #
1.7     ! albertel    4: # $Id: lonpickcode.pm,v 1.6 2005/04/07 06:56:23 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;
1.6       albertel   36: use Apache::lonnet;
1.1       albertel   37: 
                     38: sub get_code_freq {
                     39:     my ($r)=@_;
                     40:     my %codes;
                     41:     my %scantron_config=
1.6       albertel   42: 	&Apache::grades::get_scantron_config($env{'form.scantron_format'});
1.1       albertel   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);
1.4       albertel   52: 	push(@{$codes{$$scan_record{'scantron.CODE'}}},$$scan_record{'scantron.PaperID'});
1.1       albertel   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;
1.5       albertel   63:     my $html=&Apache::lonxml::xmlbegin();
1.1       albertel   64:     $r->print(<<ENDDOCUMENT);
1.5       albertel   65: $html
1.1       albertel   66:   <head>
                     67:     <title>The LearningOnline Network with CAPA</title>
                     68:   </head>
                     69: ENDDOCUMENT
                     70: 
                     71:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     72: 					    ['curCODE','scantron_selectfile',
1.7     ! albertel   73: 					     'form','scantron_format','symb',
        !            74: 					     'scantron_CODElist','command']);
1.1       albertel   75: 
1.6       albertel   76:     if  (!($env{'request.course.id'}) && 
                     77: 	 (&Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.1       albertel   78: 	$r->print('<body>Access not allowed.</body>');
                     79:         return OK;
                     80:     }
1.7     ! albertel   81:     if      ($env{'form.command'} eq 'codelist') {
        !            82: 	&code_list($r);
        !            83:     } elsif ($env{'form.command'} eq 'showcodes') {
        !            84: 	&show_codes($r);
        !            85:     } else {
        !            86: 	&picking_a_code($r);
        !            87:     }
        !            88:     $r->print('</body></html>');
        !            89:     return OK;
        !            90: }
        !            91: 
        !            92: sub code_list {
        !            93:     my ($r,$secondview)=@_;
        !            94:     if (!$secondview) {
        !            95: 	$r->print(&Apache::loncommon::bodytag("View CODEs"));
        !            96: 	$r->print("<p>".&mt('Select a set of saved CODEs to view.')."</p>");
        !            97:     } else {
        !            98: 	$r->print("<p>".&mt('Select another set of saved CODEs to view.')."</p>");
        !            99:     }
        !           100:     $r->print("<form method='POST' action='/adm/pickcode' name='pickcode'>");
        !           101:     $r->print(&Apache::grades::scantron_CODElist());
        !           102:     $r->print("<input type='hidden' name='command' value='showcodes' />");
        !           103:     $r->print("<input type='hidden' name='symb' value='".$env{'form.symb'}."' />");
        !           104:     $r->print("<input type='hidden' name='url' value='".$env{'form.url'}."' />");
        !           105:     $r->print("<input type='submit' name='submit' value='".&mt("View")."' />");
        !           106:     $r->print("</form>");
        !           107:     $r->print(&Apache::grades::show_grading_menu_form($env{'form.symb'},
        !           108: 						      $env{'form.url'}));
        !           109: }
        !           110: 
        !           111: sub show_codes {
        !           112:     my ($r)=@_;
        !           113:     $r->print(&Apache::loncommon::bodytag("View CODEs"));
        !           114:     my %codes=&Apache::grades::get_codes();
        !           115:     $r->print("<h2>".$env{'form.scantron_CODElist'}."</h2>");
        !           116:     $r->print('<pre>');
        !           117:     foreach my $code (sort(keys(%codes))) {
        !           118: 	$r->print($code."\n");
        !           119:     }
        !           120:     $r->print('</pre>');
        !           121:     &code_list($r,1);
        !           122: }
1.1       albertel  123: 
1.7     ! albertel  124: sub picking_a_code {
        !           125:     my ($r)=@_;
1.1       albertel  126:     $r->print(&Apache::loncommon::bodytag("Selecting a CODE"));
                    127:     $r->print(<<ENDSCRIPT);
                    128: <script>
1.2       albertel  129: function gochoose(newcode) {
1.6       albertel  130:     opener.document.$env{'form.form'}.scantron_CODE_selectedvalue.value=newcode;
                    131:     var slct=opener.document.$env{'form.form'}.scantron_CODE_resolution;
1.1       albertel  132:     var i;
                    133:     for (i=0;i<slct.length;i++) {
1.2       albertel  134:         if (slct[i].value=='use_found') { slct[i].checked=true; }
1.1       albertel  135:     }
                    136:     self.close();
                    137: }
                    138: </script>
                    139: ENDSCRIPT
                    140: 
                    141: 
1.6       albertel  142:     $r->print("<p>The CODE on the paper is <tt><b>".$env{'form.curCODE'}.
1.1       albertel  143: 	      "</b></tt>. Please Select a new one.</p>\n".'<form>');
1.4       albertel  144:     my %codes=&Apache::grades::get_codes();
1.1       albertel  145:     my %code_freq=&get_code_freq($r);
1.6       albertel  146:     my $num_matches=length($env{'form.curCODE'});
1.1       albertel  147:     for (my $i=$num_matches;$i>=0;$i--) {
                    148: 	my $to_print="<p> CODEs with $i matches</p>";
1.4       albertel  149: 	$to_print.='<table border="1"><tr><td></td><td>CODE</td><td>exams using this CODE</td>';
1.1       albertel  150: 	my $print;
                    151: 	foreach my $code (sort(keys(%codes))) {
1.6       albertel  152: 	    if (&Apache::grades::num_matches($env{'form.curCODE'},$code) != $i) { next; }
1.1       albertel  153: 	    $print=1;
1.4       albertel  154: 	    my ($count,$list);
                    155: 	    if (!ref($code_freq{$code})) {
                    156: 		$count=0;
                    157: 	    } else {
                    158: 		$count=scalar(@{$code_freq{$code}});
                    159: 		$list=' - '.join(', ',@{$code_freq{$code}});
                    160: 	    }
1.1       albertel  161: 	    $to_print.='<tr><td>'.
                    162: 		      '<input type="button" value="'.&mt('Select').
                    163: 		      '" onClick="gochoose(\''.$code.'\')" /></td>'.
1.4       albertel  164: 		      '<td><tt>'.$code.'</tt></td><td>'.$count.
                    165: 		      $list.'</td></tr>';
1.1       albertel  166: 	    delete($codes{$code});
                    167: 	}
                    168: 	$to_print.='</table>';
                    169: 	if ($print) { $r->print($to_print); }
                    170:     }
1.7     ! albertel  171:     $r->print('</form>');
1.1       albertel  172: } 
                    173: 
                    174: 1;
                    175: __END__

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