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

1.1       albertel    1: # The LearningOnline Network
                      2: # Pick a CODE from the list of possible CODEs
                      3: #
1.17    ! raeburn     4: # $Id: lonpickcode.pm,v 1.16 2013/02/01 18:46:37 bisitz 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.17    ! raeburn    42: 	&Apache::lonnet::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++) {
1.8       albertel   46: 	my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
1.1       albertel   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;
                     63: 
                     64:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     65: 					    ['curCODE','scantron_selectfile',
1.7       albertel   66: 					     'form','scantron_format','symb',
                     67: 					     'scantron_CODElist','command']);
1.1       albertel   68: 
1.6       albertel   69:     if  (!($env{'request.course.id'}) && 
                     70: 	 (&Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.9       albertel   71: 	$r->print(&Apache::loncommon::start_page().
1.16      bisitz     72: 		  '<p class="LC_error">'.&mt('Access not allowed.').'</p>'.
1.9       albertel   73: 		  &Apache::loncommon::end_page());
1.1       albertel   74:         return OK;
                     75:     }
1.7       albertel   76:     if      ($env{'form.command'} eq 'codelist') {
                     77: 	&code_list($r);
1.13      banghart   78:         $r->print(&Apache::grades::show_grading_menu_form($env{'form.symb'},
                     79: 						      $env{'form.url'}));	
1.7       albertel   80:     } elsif ($env{'form.command'} eq 'showcodes') {
                     81: 	&show_codes($r);
                     82:     } else {
                     83: 	&picking_a_code($r);
                     84:     }
1.9       albertel   85:     $r->print(&Apache::loncommon::end_page());
1.7       albertel   86:     return OK;
                     87: }
                     88: 
                     89: sub code_list {
1.13      banghart   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;
1.15      albertel   95:     my $extra_css;
1.13      banghart   96:     if (!$context) {
1.10      albertel   97: 	$r->print(&Apache::loncommon::start_page("View CODEs",undef,
                     98: 						 {'no_nav_bar' => 1}));
1.15      albertel   99: 	$table_head = &mt('Select a set of saved CODEs to view.');
1.13      banghart  100:     } elsif ($context eq 1) {
1.15      albertel  101: 	$table_head = &mt('Select another set of saved CODEs to view.');
1.13      banghart  102:     } elsif ($context eq 2) {
1.15      albertel  103:         $table_head = &mt('Select a set of saved CODEs to view.');
                    104: 	$extra_css = 'LC_scantron_action';
1.7       albertel  105:     }
1.14      albertel  106:     $r->print("<form method='post' action='/adm/pickcode' name='pickcode'>");
1.15      albertel  107:     $r->print('
                    108:      '.&Apache::loncommon::start_data_table($extra_css).'
                    109:        '.&Apache::loncommon::start_data_table_header_row());
                    110:     $r->print('<th>');
1.13      banghart  111:     $r->print($table_head);
1.15      albertel  112:     $r->print('</th>');
                    113:     $r->print('
                    114:        '.&Apache::loncommon::end_data_table_header_row().'
                    115:        '.&Apache::loncommon::start_data_table_row());
                    116:     $r->print('<td>');
1.14      albertel  117:     $r->print("<input type='submit' name='submit' value='".&mt("View:")."' /> ");
1.7       albertel  118:     $r->print(&Apache::grades::scantron_CODElist());
1.15      albertel  119:     $r->print('</td>');
                    120:     $r->print('
                    121:        '.&Apache::loncommon::end_data_table_row().'
                    122:        '.&Apache::loncommon::end_data_table());
1.7       albertel  123:     $r->print("<input type='hidden' name='command' value='showcodes' />");
                    124:     $r->print("<input type='hidden' name='symb' value='".$env{'form.symb'}."' />");
                    125:     $r->print("<input type='hidden' name='url' value='".$env{'form.url'}."' />");
                    126:     $r->print("</form>");
1.13      banghart  127:     
1.7       albertel  128: }
                    129: 
                    130: sub show_codes {
                    131:     my ($r)=@_;
1.10      albertel  132:     $r->print(&Apache::loncommon::start_page("View CODEs",undef,
                    133: 					     {'no_nav_bar' => 1}));
1.7       albertel  134:     my %codes=&Apache::grades::get_codes();
                    135:     $r->print("<h2>".$env{'form.scantron_CODElist'}."</h2>");
                    136:     $r->print('<pre>');
                    137:     foreach my $code (sort(keys(%codes))) {
                    138: 	$r->print($code."\n");
                    139:     }
                    140:     $r->print('</pre>');
                    141:     &code_list($r,1);
1.13      banghart  142:     $r->print(&Apache::grades::show_grading_menu_form($env{'form.symb'},
                    143: 						      $env{'form.url'}));
1.7       albertel  144: }
1.1       albertel  145: 
1.7       albertel  146: sub picking_a_code {
                    147:     my ($r)=@_;
1.16      bisitz    148:     my $title = 'Selecting a CODE';
                    149:     $r->print(&Apache::loncommon::start_page($title,undef,
1.10      albertel  150: 					     {'no_nav_bar' => 1}));
1.16      bisitz    151:     $r->print('<h1>'.&mt($title).'</h1>');
                    152: 
                    153:     $r->print(&Apache::lonhtmlcommon::scripttag("
1.2       albertel  154: function gochoose(newcode) {
1.6       albertel  155:     opener.document.$env{'form.form'}.scantron_CODE_selectedvalue.value=newcode;
                    156:     var slct=opener.document.$env{'form.form'}.scantron_CODE_resolution;
1.1       albertel  157:     var i;
                    158:     for (i=0;i<slct.length;i++) {
1.2       albertel  159:         if (slct[i].value=='use_found') { slct[i].checked=true; }
1.1       albertel  160:     }
                    161:     self.close();
                    162: }
1.16      bisitz    163: "));
1.1       albertel  164: 
1.16      bisitz    165:     $r->print(
                    166:         '<p>'
                    167:        .&mt('The CODE on the paper is [_1]. Please select a new one.',
                    168:                 '<tt><b>'.$env{'form.curCODE'}.'</b></tt>')
                    169:        ."</p>\n".'<form action="">'
                    170:     );
1.4       albertel  171:     my %codes=&Apache::grades::get_codes();
1.1       albertel  172:     my %code_freq=&get_code_freq($r);
1.6       albertel  173:     my $num_matches=length($env{'form.curCODE'});
1.1       albertel  174:     for (my $i=$num_matches;$i>=0;$i--) {
1.16      bisitz    175: 	my $to_print =
                    176:             '<p>'.&mt('CODEs with [_1] matching letters:',$i)."</p>\n"
                    177:            .&Apache::loncommon::start_data_table()
                    178:            .&Apache::loncommon::start_data_table_header_row()
                    179:            .'<th>&nbsp;</th>'
                    180:            .'<th>'.&mt('CODE').'</th>'
                    181:            .'<th>'.&mt('Bubblesheet Exams using this CODE').'</th>'
                    182:            .&Apache::loncommon::end_data_table_header_row();
                    183: 
1.1       albertel  184: 	my $print;
                    185: 	foreach my $code (sort(keys(%codes))) {
1.6       albertel  186: 	    if (&Apache::grades::num_matches($env{'form.curCODE'},$code) != $i) { next; }
1.1       albertel  187: 	    $print=1;
1.4       albertel  188: 	    my ($count,$list);
                    189: 	    if (!ref($code_freq{$code})) {
                    190: 		$count=0;
                    191: 	    } else {
                    192: 		$count=scalar(@{$code_freq{$code}});
                    193: 		$list=' - '.join(', ',@{$code_freq{$code}});
                    194: 	    }
1.16      bisitz    195:         $to_print .=
                    196:             &Apache::loncommon::start_data_table_row()
                    197:            .'<td><input type="button" value="'.&mt('Select')
                    198:            .'" onclick="gochoose(\''.$code.'\')" /></td>'
                    199:            .'<td><tt>'.$code.'</tt></td>'
                    200:            .'<td>'.$count.$list.'</td>'
                    201:            .&Apache::loncommon::end_data_table_row();
                    202:             delete($codes{$code});
                    203:         }
                    204:         $to_print .= &Apache::loncommon::end_data_table();
                    205:         if ($print) { $r->print($to_print); }
1.1       albertel  206:     }
1.7       albertel  207:     $r->print('</form>');
1.1       albertel  208: } 
                    209: 
                    210: 1;
                    211: __END__

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