File:  [LON-CAPA] / loncom / interface / lonpickcode.pm
Revision 1.14: download - view: text, annotated - select for diffs
Tue Nov 13 01:14:11 2007 UTC (16 years, 7 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- xhtml
- some small layout changes

    1: # The LearningOnline Network
    2: # Pick a CODE from the list of possible CODEs
    3: #
    4: # $Id: lonpickcode.pm,v 1.14 2007/11/13 01:14:11 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,$scan_data,$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: 
   64:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   65: 					    ['curCODE','scantron_selectfile',
   66: 					     'form','scantron_format','symb',
   67: 					     'scantron_CODElist','command']);
   68: 
   69:     if  (!($env{'request.course.id'}) && 
   70: 	 (&Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
   71: 	$r->print(&Apache::loncommon::start_page().
   72: 		  &mt('Access not allowed.').
   73: 		  &Apache::loncommon::end_page());
   74:         return OK;
   75:     }
   76:     if      ($env{'form.command'} eq 'codelist') {
   77: 	&code_list($r);
   78:         $r->print(&Apache::grades::show_grading_menu_form($env{'form.symb'},
   79: 						      $env{'form.url'}));	
   80:     } elsif ($env{'form.command'} eq 'showcodes') {
   81: 	&show_codes($r);
   82:     } else {
   83: 	&picking_a_code($r);
   84:     }
   85:     $r->print(&Apache::loncommon::end_page());
   86:     return OK;
   87: }
   88: 
   89: sub code_list {
   90:     my ($r,$context)=@_;
   91:     # $context = 0 Print page header and enclosing table
   92:     # $context = 1 No page header, print enclosing table
   93:     # $context = 2 No page header, no enclosing table
   94:     my $table_head;
   95:     my $enc_table_start;
   96:     my $enc_table_close;
   97:     
   98:     if (!$context) {
   99: 	$r->print(&Apache::loncommon::start_page("View CODEs",undef,
  100: 						 {'no_nav_bar' => 1}));
  101: 	$table_head = ('<b>'.&mt('Select a set of saved CODEs to view.')."</b>");
  102:     } elsif ($context eq 1) {
  103: 	$table_head = ('<b>'.&mt('Select another set of saved CODEs to view.')."</b>");
  104: 	$enc_table_start = '<table width="100%"><tr><td bgcolor="#777777">';
  105: 	$enc_table_close = '</tr></td></table>';
  106:     } elsif ($context eq 2) {
  107:         $table_head = ('<b>'.&mt('Select a set of saved CODEs to view.')."</b>");
  108:     }
  109:     $r->print("<form method='post' action='/adm/pickcode' name='pickcode'>");
  110:     $r->print($enc_table_start);
  111:     $r->print('<table width="100%">');
  112:     $r->print('<tr><td bgcolor="#e6ffff">');
  113:     $r->print($table_head);
  114:     $r->print('</td></tr>');
  115:     $r->print('<tr><td bgcolor="#ffffe6">');
  116:     $r->print("<input type='submit' name='submit' value='".&mt("View:")."' /> ");
  117:     $r->print(&Apache::grades::scantron_CODElist());
  118:     $r->print('</td></tr>');
  119:     $r->print('</table>');
  120:     $r->print($enc_table_close); # conditional
  121:     $r->print("<input type='hidden' name='command' value='showcodes' />");
  122:     $r->print("<input type='hidden' name='symb' value='".$env{'form.symb'}."' />");
  123:     $r->print("<input type='hidden' name='url' value='".$env{'form.url'}."' />");
  124:     $r->print("</form>");
  125:     
  126: }
  127: 
  128: sub show_codes {
  129:     my ($r)=@_;
  130:     $r->print(&Apache::loncommon::start_page("View CODEs",undef,
  131: 					     {'no_nav_bar' => 1}));
  132:     my %codes=&Apache::grades::get_codes();
  133:     $r->print("<h2>".$env{'form.scantron_CODElist'}."</h2>");
  134:     $r->print('<pre>');
  135:     foreach my $code (sort(keys(%codes))) {
  136: 	$r->print($code."\n");
  137:     }
  138:     $r->print('</pre>');
  139:     &code_list($r,1);
  140:     $r->print(&Apache::grades::show_grading_menu_form($env{'form.symb'},
  141: 						      $env{'form.url'}));
  142: }
  143: 
  144: sub picking_a_code {
  145:     my ($r)=@_;
  146:     $r->print(&Apache::loncommon::start_page("Selecting a CODE",undef,
  147: 					     {'no_nav_bar' => 1}));
  148:     $r->print(<<ENDSCRIPT);
  149: <script>
  150: function gochoose(newcode) {
  151:     opener.document.$env{'form.form'}.scantron_CODE_selectedvalue.value=newcode;
  152:     var slct=opener.document.$env{'form.form'}.scantron_CODE_resolution;
  153:     var i;
  154:     for (i=0;i<slct.length;i++) {
  155:         if (slct[i].value=='use_found') { slct[i].checked=true; }
  156:     }
  157:     self.close();
  158: }
  159: </script>
  160: ENDSCRIPT
  161: 
  162: 
  163:     $r->print("<p>The CODE on the paper is <tt><b>".$env{'form.curCODE'}.
  164: 	      "</b></tt>. Please Select a new one.</p>\n".'<form>');
  165:     my %codes=&Apache::grades::get_codes();
  166:     my %code_freq=&get_code_freq($r);
  167:     my $num_matches=length($env{'form.curCODE'});
  168:     for (my $i=$num_matches;$i>=0;$i--) {
  169: 	my $to_print="<p>".&mt("CODEs with [_1] matching letters",$i)."</p>";
  170: 	$to_print.='<table border="1"><tr><td></td><td>CODE</td><td>exams using this CODE</td>';
  171: 	my $print;
  172: 	foreach my $code (sort(keys(%codes))) {
  173: 	    if (&Apache::grades::num_matches($env{'form.curCODE'},$code) != $i) { next; }
  174: 	    $print=1;
  175: 	    my ($count,$list);
  176: 	    if (!ref($code_freq{$code})) {
  177: 		$count=0;
  178: 	    } else {
  179: 		$count=scalar(@{$code_freq{$code}});
  180: 		$list=' - '.join(', ',@{$code_freq{$code}});
  181: 	    }
  182: 	    $to_print.='<tr><td>'.
  183: 		      '<input type="button" value="'.&mt('Select').
  184: 		      '" onClick="gochoose(\''.$code.'\')" /></td>'.
  185: 		      '<td><tt>'.$code.'</tt></td><td>'.$count.
  186: 		      $list.'</td></tr>';
  187: 	    delete($codes{$code});
  188: 	}
  189: 	$to_print.='</table>';
  190: 	if ($print) { $r->print($to_print); }
  191:     }
  192:     $r->print('</form>');
  193: } 
  194: 
  195: 1;
  196: __END__

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